瀏覽代碼

update

master
dengbiao 5 月之前
父節點
當前提交
ae37232c68
共有 10 個檔案被更改,包括 1344 行新增1 行删除
  1. +7
    -1
      go.mod
  2. +5
    -0
      go.sum
  3. +2
    -0
      md/block_star_chain.go
  4. +119
    -0
      rule/micro_applications/enum/happy_orchard.go
  5. +70
    -0
      rule/micro_applications/happy_orchard_basic_setting.go
  6. +41
    -0
      rule/micro_applications/happy_orchard_give_integral.go
  7. +167
    -0
      rule/micro_applications/happy_orchard_user_seed_record.go
  8. +847
    -0
      rule/micro_applications/happy_orchard_user_waters.go
  9. +14
    -0
      rule/micro_applications/init.go
  10. +72
    -0
      rule/micro_applications/md/happy_orchard.go

+ 7
- 1
go.mod 查看文件

@@ -2,8 +2,14 @@ module code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git

go 1.15

// go.mod文件中
replace (
code.fnuoos.com/go_rely_warehouse/zyos_model.git => E:/company/go_rely_warehouse/zyos_model/
)

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3 // indirect
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9
@@ -12,6 +18,6 @@ require (
github.com/syyongx/php2go v0.9.6
go.uber.org/zap v1.13.0
golang.org/x/sync v0.1.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
xorm.io/xorm v1.3.1
)

+ 5
- 0
go.sum 查看文件

@@ -2,6 +2,9 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3 h1:SPp5AswPmkDO2ML6WwGlzhIuls+/1dUfU40iOeH0dh4=
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3 h1:XmPPfEinfIm+oOn4Mu9VdA6mqg6be6DR7C+iO/Tds8I=
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3/go.mod h1:C8Cnjh+TKbSqhsbENGgVg17byUhsn6+SsSAEww0eBak=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
@@ -98,6 +101,7 @@ github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
@@ -610,6 +614,7 @@ gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=


+ 2
- 0
md/block_star_chain.go 查看文件

@@ -78,6 +78,7 @@ const (

GreenCoinDoubleChainExchangeByCoin1 = "绿色积分双链兑换账户余额-减少绿色积分"
GreenCoinDoubleChainExchangeByCoin2 = "绿色积分双链兑换账户余额-减少贡献积分"
HappyOrchardGiveIntegral = "开心农场-赠送积分"
)

const (
@@ -154,6 +155,7 @@ const (

GreenCoinDoubleChainExchangeByCoin1ForForUserVirtualCoinFlow = 170 //绿色积分双链兑换账户余额-减少绿色积分
GreenCoinDoubleChainExchangeByCoin2ForForUserVirtualCoinFlow = 171 //绿色积分双链兑换账户余额-减少贡献积分
HappyOrchardGiveIntegralForUserVirtualCoinFlow = 172 //开心农场-赠送积分

)



+ 119
- 0
rule/micro_applications/enum/happy_orchard.go 查看文件

@@ -0,0 +1,119 @@
package enum

// 奖品类型
type RewardKind int

const (
RewardKindForEntity RewardKind = iota + 1
RewardKindForVirtual
)

func (kind RewardKind) String() string {
switch kind {
case RewardKindForEntity:
return "实物商品"
case RewardKindForVirtual:
return "虚拟商品"
default:
return "未知"
}
}

type HappyOrchardBasicSettingIsOpen int

const (
HappyOrchardBasicSettingIsOpenForFalse HappyOrchardBasicSettingIsOpen = iota
HappyOrchardBasicSettingIsOpenForTrue
)

func (kind HappyOrchardBasicSettingIsOpen) String() string {
switch kind {
case HappyOrchardBasicSettingIsOpenForFalse:
return "未开启"
case HappyOrchardBasicSettingIsOpenForTrue:
return "已开启"
default:
return "未知"
}
}

type HappyOrchardUserSeedRecordState int

const (
HappyOrchardUserSeedRecordStateForPlanting HappyOrchardUserSeedRecordState = iota + 1
HappyOrchardUserSeedRecordStateForUnclaimed
HappyOrchardUserSeedRecordStateForReceived
)

func (kind HappyOrchardUserSeedRecordState) String() string {
switch kind {
case HappyOrchardUserSeedRecordStateForPlanting:
return "种植中"
case HappyOrchardUserSeedRecordStateForUnclaimed:
return "待领取"
case HappyOrchardUserSeedRecordStateForReceived:
return "已领取"
default:
return "未知"
}
}

type HappyOrchardUserAssistanceRecords int32

const (
HappyOrchardUserAssistanceRecordsForSharingAssistance HappyOrchardUserAssistanceRecords = iota + 1
HappyOrchardUserAssistanceRecordsForPlayGoldenEggGame
HappyOrchardUserSeedRecordStateForPlayRaffleGame
)

func (kind HappyOrchardUserAssistanceRecords) String() string {
switch kind {
case HappyOrchardUserAssistanceRecordsForSharingAssistance:
return "分享助力"
case HappyOrchardUserAssistanceRecordsForPlayGoldenEggGame:
return "玩金蛋游戏助力"
case HappyOrchardUserSeedRecordStateForPlayRaffleGame:
return "玩抽奖游戏助力"
default:
return "未知"
}
}

type DealUserWatersKind string

const (
DealUserWatersKindForWatering = "watering"
DealUserWatersKindForSevenDaysSign = "seven_days_sign"
DealUserWatersKindForTimerSign = "timer_sign"
DealUserWatersKindForPlaceOrderReward = "place_order_reward"
DealUserWatersKindForSharingAssistance = "sharing_assistance"
DealUserWatersKindForInvitingNewPlayers = "inviting_new_players"
DealUserWatersKindForBrowsingInterface = "browsing_interface"
DealUserWatersKindForPlayGoldenEggGame = "play_golden_egg_game"
DealUserWatersKindForPlayRaffleGame = "play_raffle_game"
)

func (kind DealUserWatersKind) String() string {
switch kind {
case DealUserWatersKindForWatering:
return "浇水"
case DealUserWatersKindForSevenDaysSign:
return "7日签到"
case DealUserWatersKindForTimerSign:
return "定时签到"
case DealUserWatersKindForPlaceOrderReward:
return "下单奖励"
case DealUserWatersKindForSharingAssistance:
return "分享助力奖励"
case DealUserWatersKindForInvitingNewPlayers:
return "邀请新玩家奖励"
case DealUserWatersKindForBrowsingInterface:
return "浏览界面奖励"
case DealUserWatersKindForPlayGoldenEggGame:
return "玩金蛋奖励"
case DealUserWatersKindForPlayRaffleGame:
return "玩抽奖游戏奖励"
default:
return "未知"
}
}

+ 70
- 0
rule/micro_applications/happy_orchard_basic_setting.go 查看文件

@@ -0,0 +1,70 @@
package micro_applications

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/md"
"encoding/json"
)

func AnalysisStageNameCustom(stageNameCustomStr string) (resp []string, err error) {
err = json.Unmarshal([]byte(stageNameCustomStr), &resp)
if err != nil {
return
}
return
}

func AnalysisSevenDaysSignRewardData(sevenDaysSignRewardDataStr string) (resp []string, err error) {
err = json.Unmarshal([]byte(sevenDaysSignRewardDataStr), &resp)
if err != nil {
return
}
return
}

func AnalysisTimerSignRewardData(timerSignRewardDataStr string) (resp md.TimerSignRewardDataStruct, err error) {
err = json.Unmarshal([]byte(timerSignRewardDataStr), &resp)
if err != nil {
return
}
return
}

func AnalysisPlaceOrderRewardData(placeOrderRewardDataStr string) (resp md.PlaceOrderRewardDataStruct, err error) {
err = json.Unmarshal([]byte(placeOrderRewardDataStr), &resp)
if err != nil {
return
}
return
}

func AnalysisSharingAssistanceRewardData(sharingAssistanceRewardDataStr string) (resp md.SharingAssistanceRewardDataStruct, err error) {
err = json.Unmarshal([]byte(sharingAssistanceRewardDataStr), &resp)
if err != nil {
return
}
return
}

func AnalysisBrowsingInterfaceRewardData(browsingInterfaceRewardDataStr string) (resp md.BrowsingInterfaceRewardDataStruct, err error) {
err = json.Unmarshal([]byte(browsingInterfaceRewardDataStr), &resp)
if err != nil {
return
}
return
}

func AnalysisPlayGoldenEggGameRewardData(playGoldenEggGameRewardDataStr string) (resp md.PlayGoldenEggGameRewardDataStruct, err error) {
err = json.Unmarshal([]byte(playGoldenEggGameRewardDataStr), &resp)
if err != nil {
return
}
return
}

func PlayRaffleGameRewardData(playRaffleGameRewardDataStr string) (resp md.PlayRaffleGameRewardDataStruct, err error) {
err = json.Unmarshal([]byte(playRaffleGameRewardDataStr), &resp)
if err != nil {
return
}
return
}

+ 41
- 0
rule/micro_applications/happy_orchard_give_integral.go 查看文件

@@ -0,0 +1,41 @@
package micro_applications

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
enum2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/enum"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"errors"
"xorm.io/xorm"
)

func HappyOrchardGiveIntegral(session *xorm.Session, records models.HappyOrchardRewardExchangeRecords, masterId string) error {
//1、判断是否是虚拟商品
if records.RewardKind != int(enum2.RewardKindForVirtual) {
return errors.New("兑换奖品类型非虚拟商品")
}

//2、获取奖品数据
db := implement.NewHappyOrchardRewardDb(session.Engine())
happyOrchardReward, err := db.GetHappyOrchardReward(records.SeedId)
if err != nil {
return err
}

//3、处理给用户虚拟积分
err = rule.DealUserCoin(session, md.DealUserCoinReq{
Kind: "add",
Mid: masterId,
Title: md.HappyOrchardGiveIntegral,
TransferType: md.HappyOrchardGiveIntegralForUserVirtualCoinFlow,
OrdId: "",
CoinId: happyOrchardReward.CoinId,
Uid: records.Uid,
Amount: float64(happyOrchardReward.Value),
})
if err != nil {
return err
}
return nil
}

+ 167
- 0
rule/micro_applications/happy_orchard_user_seed_record.go 查看文件

@@ -0,0 +1,167 @@
package micro_applications

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/enum"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/md"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
"errors"
"xorm.io/xorm"
)

// GetHappyOrchardUserSeedRecordData 获取用户种子记录对应数据
func GetHappyOrchardUserSeedRecordData(engine *xorm.Engine, record models.HappyOrchardUserSeedRecord) (resp md2.GetHappyOrchardUserSeedRecordDataResp, err error) {
//1、获取基础设置
happyOrchardBasicSettingDb := implement.NewHappyOrchardBasicSettingDb(engine)
happyOrchardBasicSetting, err := happyOrchardBasicSettingDb.GetHappyOrchardBasicSetting()
if err != nil {
return
}
if happyOrchardBasicSetting == nil {
err = errors.New("请先完善基础配置")
return
}
if happyOrchardBasicSetting.IsOpen == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("开心农场游戏暂未开启")
return
}

//2、获取种子数据
happyOrchardSeedDb := implement.NewHappyOrchardSeedDb(engine)
happyOrchardSeed, err := happyOrchardSeedDb.GetHappyOrchardSeed(record.SeedId)
if err != nil {
return
}
if happyOrchardSeed == nil {
err = errors.New("未查询到相关种子记录")
return
}

//3、判断当前种子状态
if record.State == int(enum.HappyOrchardUserSeedRecordStateForPlanting) {
//4、解析基础设置中的 "阶段自定义" 数据
stageNameCustomData, err := AnalysisStageNameCustom(happyOrchardBasicSetting.StageNameCustom)
if err != nil {
return
}
seedState, nextSeedStateWaters := getHappyOrchardUserSeedStage(record, *happyOrchardSeed)
resp.RecordPlantingStage = seedState
resp.RecordPlantingStageZh = stageNameCustomData[resp.RecordPlantingStage]
resp.RecordPlantingNextStage = resp.RecordPlantingStage + 1
resp.RecordPlantingNextStageZh = stageNameCustomData[resp.RecordPlantingNextStage]
resp.RecordPlantingNextStageNeedWaterNums = nextSeedStateWaters / happyOrchardBasicSetting.WateringEveryTimeWaterDroplet
}
resp.RecordId = record.Id
resp.RecordName = happyOrchardSeed.Name
resp.RecordState = record.State
resp.RecordStateZh = enum.HappyOrchardUserSeedRecordState(record.State).String()
resp.NowRecordWaters = record.WaterNums
resp.TotalNeedWaters = happyOrchardSeed.WaterNums

return
}

func getHappyOrchardUserSeedStage(record models.HappyOrchardUserSeedRecord, seed models.HappyOrchardSeed) (seedState int, nextSeedStateWaters int) {
seedState = -1
if record.WaterNums >= seed.NeedWatersNumForStage0 && record.WaterNums < seed.NeedWatersNumForStage1 {
seedState = 0
nextSeedStateWaters = seed.NeedWatersNumForStage1
return
}
if record.WaterNums >= seed.NeedWatersNumForStage1 && record.WaterNums < seed.NeedWatersNumForStage2 {
seedState = 1
nextSeedStateWaters = seed.NeedWatersNumForStage2
}
if record.WaterNums >= seed.NeedWatersNumForStage2 && record.WaterNums < seed.NeedWatersNumForStage3 {
seedState = 2
nextSeedStateWaters = seed.NeedWatersNumForStage3
}
if record.WaterNums >= seed.NeedWatersNumForStage3 && record.WaterNums < seed.NeedWatersNumForStage4 {
seedState = 3
nextSeedStateWaters = seed.NeedWatersNumForStage4
}
if record.WaterNums >= seed.NeedWatersNumForStage4 && record.WaterNums < seed.NeedWatersNumForStage5 {
seedState = 4
nextSeedStateWaters = seed.NeedWatersNumForStage5
}
if record.WaterNums >= seed.NeedWatersNumForStage5 {
seedState = 5
}
return
}

// UserReplaceSeed 用户替换种子
func UserReplaceSeed(engine *xorm.Engine, record models.HappyOrchardUserSeedRecord, toBeSeedId, uid int) (err error) {
//1、获取基础设置
happyOrchardBasicSettingDb := implement.NewHappyOrchardBasicSettingDb(engine)
happyOrchardBasicSetting, err := happyOrchardBasicSettingDb.GetHappyOrchardBasicSetting()
if err != nil {
return
}
if happyOrchardBasicSetting == nil {
err = errors.New("请先完善基础配置")
return
}
if happyOrchardBasicSetting.IsOpen == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("开心农场游戏暂未开启")
return
}

//2、获取 happy_orchard_user_waters 数据
happyOrchardUserWatersDb := implement.NewHappyOrchardUserWatersDb(engine)
happyOrchardUserWaters, err := happyOrchardUserWatersDb.GetHappyOrchardUserWaters(uid)
if err != nil {
return
}
if happyOrchardUserWaters == nil {
err = errors.New("未查询到相关用户数据记录")
return
}
if happyOrchardUserWaters.ReplaceSeedNums <= 0 {
err = errors.New("当前用户替换种子次数已用完")
return
}

//3、判断当前种子状态
if record.State != int(enum.HappyOrchardUserSeedRecordStateForPlanting) {
err = errors.New("当前种子状态不可替换")
return
}

//4、查找当前种子&&目标种子记录
happyOrchardSeedDb := implement.NewHappyOrchardSeedDb(engine)
nowHappyOrchardSeed, err := happyOrchardSeedDb.GetHappyOrchardSeed(record.SeedId)
if err != nil {
return
}
if nowHappyOrchardSeed == nil {
err = errors.New("未查询到相关种子记录")
return
}
toBeHappyOrchardSeed, err := happyOrchardSeedDb.GetHappyOrchardSeed(toBeSeedId)
if err != nil {
return
}
if toBeHappyOrchardSeed == nil {
err = errors.New("未查询到相关种子记录")
return
}
if nowHappyOrchardSeed.WaterNums > toBeHappyOrchardSeed.WaterNums {
err = errors.New("不支持更大水滴数种子替换成小水滴数种子")
return
}

//5、修改 happy_orchard_user_seed_record 记录 && happy_orchard_user_waters 记录
record.SeedId = toBeSeedId
happyOrchardUserWaters.ReplaceSeedNums--
happyOrchardUserSeedRecordDb := implement.NewHappyOrchardUserSeedRecordDb(engine)
_, err = happyOrchardUserSeedRecordDb.UpdateHappyOrchardUserSeedRecord(&record, "seed_id")
if err != nil {
return
}
_, err = happyOrchardUserWatersDb.UpdateHappyOrchardUserWatersBySess(uid, happyOrchardUserWaters, "replace_seed_nums")
if err != nil {
return err
}
return
}

+ 847
- 0
rule/micro_applications/happy_orchard_user_waters.go 查看文件

@@ -0,0 +1,847 @@
package micro_applications

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/enum"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/md"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_model.git/utils/logx"
"encoding/json"
"errors"
"math/rand"
"time"
"xorm.io/xorm"
)

// DealUserWaters 处理用户水滴
func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err error) {
//1、获取基础设置
happyOrchardBasicSettingDb := implement.NewHappyOrchardBasicSettingDb(engine)
happyOrchardBasicSetting, err := happyOrchardBasicSettingDb.GetHappyOrchardBasicSetting()
if err != nil {
return
}
if happyOrchardBasicSetting == nil {
err = errors.New("请先完善基础配置")
return
}
if happyOrchardBasicSetting.IsOpen == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("开心农场游戏暂未开启")
return
}

switch kind {
case enum.DealUserWatersKindForWatering:
var req *md.DealUserWatersKindForWateringReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelWatering(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForSevenDaysSign:
var req *md.DealUserWatersKindForSevenDaysSignReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelSevenDaysSign(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForTimerSign:
var req *md.DealUserWatersKindForTimerSignReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelTimerSign(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForPlaceOrderReward:
var req *md.DealUserWatersReqForPlaceOrderRewardReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelPlaceOrderReward(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForSharingAssistance:
var req *md.DealUserWatersKindForSharingAssistanceReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelSharingAssistance(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForInvitingNewPlayers:
var req *md.DealUserWatersKindForInvitingNewPlayersReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelInvitingNewPlayers(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForBrowsingInterface:
var req *md.DealUserWatersKindForBrowsingInterfaceReq
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelBrowsingInterface(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForPlayGoldenEggGame:
var req *md.DealUserWatersKindForPlayGoldenEggGame
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelPlayGoldenEggGame(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
case enum.DealUserWatersKindForPlayRaffleGame:
var req *md.DealUserWatersKindForPlayRaffleGame
err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req)
if err != nil {
return
}
err = handelPlayRaffleGame(engine, *req, *happyOrchardBasicSetting)
if err != nil {
return err
}
break
}

return
}

func handelWatering(engine *xorm.Engine, req md.DealUserWatersKindForWateringReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
now := time.Now()

//1、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}

//2、判断用户水滴是否足够
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums -= basicSetting.WateringEveryTimeWaterDroplet
if happyOrchardUserWaters.WaterNums < 0 {
_ = session.Rollback()
return errors.New("用户水滴不够")
}

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForWatering).String(),
Kind: 2,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}

return session.Commit()
}

func handelSevenDaysSign(engine *xorm.Engine, req md.DealUserWatersKindForSevenDaysSignReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
if basicSetting.IsOpenSevenDaysSign == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("7日签到未开启")
return
}

//1、解析基础设置中的 "7日签到奖励" 数据
sevenDaysSignRewardData, err := AnalysisSevenDaysSignRewardData(basicSetting.SevenDaysSignRewardData)
if err != nil {
return
}
rewardWatersValue := sevenDaysSignRewardData[req.SignNums-1] //奖励水滴值

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()

//2、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += zhios_order_relate_utils.StrToInt(rewardWatersValue)

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForSevenDaysSign).String(),
Kind: 1,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}

return session.Commit()
}

func handelTimerSign(engine *xorm.Engine, req md.DealUserWatersKindForTimerSignReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
if basicSetting.IsOpenTimerSign == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("定时签到未开启")
return
}

//1、解析基础设置中的 "定时签到奖励" 数据
timerSignRewardData, err := AnalysisTimerSignRewardData(basicSetting.TimerSignRewardData)
if err != nil {
return
}
rewardWatersValue := generateRandomInt(zhios_order_relate_utils.StrToInt(timerSignRewardData.From), zhios_order_relate_utils.StrToInt(timerSignRewardData.To)) //奖励水滴值

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
//2、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForTimerSign).String(),
Kind: 1,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}

func handelPlaceOrderReward(engine *xorm.Engine, req md.DealUserWatersReqForPlaceOrderRewardReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
if basicSetting.IsOpenPlaceOrderReward == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("下单获得奖励未开启")
return
}

//1、解析基础设置中的 "下单获得奖励" 数据
placeOrderRewardData, err := AnalysisPlaceOrderRewardData(basicSetting.PlaceOrderRewardData)
if err != nil {
return
}
rewardWatersValue := zhios_order_relate_utils.StrToInt(placeOrderRewardData.RewardValue) //奖励水滴值

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
//2、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForPlaceOrderReward).String(),
Kind: 1,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}

func handelSharingAssistance(engine *xorm.Engine, req md.DealUserWatersKindForSharingAssistanceReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
today := now.Format("2006-01-02")
if basicSetting.IsOpenSharingAssistance == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("分享助力未开启")
return
}

//1、解析基础设置中的 "分享助力奖励" 数据
sharingAssistanceRewardData, err := AnalysisSharingAssistanceRewardData(basicSetting.SharingAssistanceRewardData)
if err != nil {
return
}
helperRewardWatersValue := zhios_order_relate_utils.StrToInt(sharingAssistanceRewardData.Helper) //助力者-奖励水滴值
assistedWatersValue := zhios_order_relate_utils.StrToInt(sharingAssistanceRewardData.Assisted) //被助力者-奖励水滴值
assistUpperLimitValue := zhios_order_relate_utils.StrToInt(sharingAssistanceRewardData.AssistUpperLimit) //每日助力上限

//2、判断当日是否已达上限 happy_orchard_user_assistance_records
happyOrchardUserAssistanceRecordsDb := implement.NewHappyOrchardUserAssistanceRecordsDb(engine)
happyOrchardUserAssistanceRecords, err := happyOrchardUserAssistanceRecordsDb.GetHappyOrchardUserAssistanceRecords(req.HelperUid, int32(enum.HappyOrchardUserAssistanceRecordsForSharingAssistance))
if err != nil {
return
}
if happyOrchardUserAssistanceRecords == nil {
happyOrchardUserAssistanceRecords = &models.HappyOrchardUserAssistanceRecords{
Uid: req.AssistedUid,
Date: now.Format("2006-01-02"),
Nums: 0,
Kind: int32(enum.HappyOrchardUserAssistanceRecordsForSharingAssistance),
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
_, err = happyOrchardUserAssistanceRecordsDb.InsertHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords)
if err != nil {
return
}
} else {
if happyOrchardUserAssistanceRecords.Date != today {
happyOrchardUserAssistanceRecords.Nums = 0
happyOrchardUserAssistanceRecords.Date = today
}
}
if happyOrchardUserAssistanceRecords.Nums >= assistUpperLimitValue {
return errors.New("当日助力次数已达上限")
}

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()

//3、查找助力者 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
helperHappyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.HelperUid)
if err != nil {
_ = session.Rollback()
return
}
if helperHappyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("助力者用户数据不存在")
}
helperBeforeWaterNums := helperHappyOrchardUserWaters.WaterNums
helperHappyOrchardUserWaters.WaterNums += helperRewardWatersValue

//4、查找被助力者 happy_orchard_user_waters 数据
assistedHappyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.AssistedUid)
if err != nil {
_ = session.Rollback()
return
}
if assistedHappyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("被助力者用户数据不存在")
}
assistedBeforeWaterNums := assistedHappyOrchardUserWaters.WaterNums
assistedHappyOrchardUserWaters.WaterNums += assistedWatersValue

//5、更新助力者 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.HelperUid, helperHappyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}
//6、更新被助力者 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.AssistedUid, assistedHappyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//7、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.HelperUid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForSharingAssistance).String(),
Kind: 1,
BeforeWaterNums: helperBeforeWaterNums,
AfterWaterNums: helperHappyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.AssistedUid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForSharingAssistance).String(),
Kind: 1,
BeforeWaterNums: assistedBeforeWaterNums,
AfterWaterNums: assistedHappyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
err = session.Commit()
if err != nil {
return err
}

//8、更改 happy_orchard_user_assistance_records 数据
happyOrchardUserAssistanceRecords.Nums++
happyOrchardUserAssistanceRecordsDb.UpdateHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords, "nums", "date")
return
}

func handelInvitingNewPlayers(engine *xorm.Engine, req md.DealUserWatersKindForInvitingNewPlayersReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
if basicSetting.IsOpenInvitingNewPlayers == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("邀请新玩家未开启")
return
}

rewardWatersValue := zhios_order_relate_utils.StrToInt(basicSetting.InvitingNewPlayersRewardData)

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
//2、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForInvitingNewPlayers).String(),
Kind: 1,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}

func handelBrowsingInterface(engine *xorm.Engine, req md.DealUserWatersKindForBrowsingInterfaceReq, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
if basicSetting.IsOpenBrowsingInterface == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("浏览界面未开启")
return
}

//1、解析基础设置中的 "浏览界面奖励" 数据
browsingInterfaceRewardData, err := AnalysisBrowsingInterfaceRewardData(basicSetting.BrowsingInterfaceRewardData)
if err != nil {
return
}
rewardWatersValue := zhios_order_relate_utils.StrToInt(browsingInterfaceRewardData.RewardValue) //奖励水滴值

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()
//2、查找 happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
beforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//3、更新 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//4、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForBrowsingInterface).String(),
Kind: 1,
BeforeWaterNums: beforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}

func handelPlayGoldenEggGame(engine *xorm.Engine, req md.DealUserWatersKindForPlayGoldenEggGame, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
today := now.Format("2006-01-02")
if basicSetting.IsOpenPlayGoldenEggGame == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("玩金蛋游戏未开启")
return
}

//1、解析基础设置中的 "玩金蛋奖励" 数据
playGoldenEggGameRewardData, err := AnalysisPlayGoldenEggGameRewardData(basicSetting.PlayGoldenEggGameRewardData)
if err != nil {
return
}
rewardWatersValue := zhios_order_relate_utils.StrToInt(playGoldenEggGameRewardData.RewardValue) //奖励水滴值
rewardLimit := zhios_order_relate_utils.StrToInt(playGoldenEggGameRewardData.RewardLimit) //奖励上限

//2、判断当日是否已达上限 happy_orchard_user_assistance_records
happyOrchardUserAssistanceRecordsDb := implement.NewHappyOrchardUserAssistanceRecordsDb(engine)
happyOrchardUserAssistanceRecords, err := happyOrchardUserAssistanceRecordsDb.GetHappyOrchardUserAssistanceRecords(req.Uid, int32(enum.HappyOrchardUserAssistanceRecordsForPlayGoldenEggGame))
if err != nil {
return
}
if happyOrchardUserAssistanceRecords == nil {
happyOrchardUserAssistanceRecords = &models.HappyOrchardUserAssistanceRecords{
Uid: req.Uid,
Date: now.Format("2006-01-02"),
Nums: 0,
Kind: int32(enum.HappyOrchardUserAssistanceRecordsForPlayGoldenEggGame),
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
_, err = happyOrchardUserAssistanceRecordsDb.InsertHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords)
if err != nil {
return
}
} else {
if happyOrchardUserAssistanceRecords.Date != today {
happyOrchardUserAssistanceRecords.Nums = 0
happyOrchardUserAssistanceRecords.Date = today
}
}
if happyOrchardUserAssistanceRecords.Nums >= rewardLimit {
return errors.New("当日奖励次数已达上限")
}

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()

//3、查找happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
helperBeforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//4、更新助力者 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//5、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForPlayGoldenEggGame).String(),
Kind: 1,
BeforeWaterNums: helperBeforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
err = session.Commit()
if err != nil {
return err
}

//6、更改 happy_orchard_user_assistance_records 数据
happyOrchardUserAssistanceRecords.Nums++
happyOrchardUserAssistanceRecordsDb.UpdateHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords, "nums", "date")
return
}

func handelPlayRaffleGame(engine *xorm.Engine, req md.DealUserWatersKindForPlayRaffleGame, basicSetting models.HappyOrchardBasicSetting) (err error) {
now := time.Now()
today := now.Format("2006-01-02")
if basicSetting.IsOpenPlayRaffleGame == int(enum.HappyOrchardBasicSettingIsOpenForFalse) {
err = errors.New("玩金蛋游戏未开启")
return
}

//1、解析基础设置中的 "玩金蛋奖励" 数据
playRaffleGameRewardData, err := PlayRaffleGameRewardData(basicSetting.PlayRaffleGameRewardData)
if err != nil {
return
}
rewardWatersValue := zhios_order_relate_utils.StrToInt(playRaffleGameRewardData.RewardValue) //奖励水滴值
rewardLimit := zhios_order_relate_utils.StrToInt(playRaffleGameRewardData.RewardLimit) //奖励上限

//2、判断当日是否已达上限 happy_orchard_user_assistance_records
happyOrchardUserAssistanceRecordsDb := implement.NewHappyOrchardUserAssistanceRecordsDb(engine)
happyOrchardUserAssistanceRecords, err := happyOrchardUserAssistanceRecordsDb.GetHappyOrchardUserAssistanceRecords(req.Uid, int32(enum.HappyOrchardUserSeedRecordStateForPlayRaffleGame))
if err != nil {
return
}
if happyOrchardUserAssistanceRecords == nil {
happyOrchardUserAssistanceRecords = &models.HappyOrchardUserAssistanceRecords{
Uid: req.Uid,
Date: now.Format("2006-01-02"),
Nums: 0,
Kind: int32(enum.HappyOrchardUserSeedRecordStateForPlayRaffleGame),
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
}
_, err = happyOrchardUserAssistanceRecordsDb.InsertHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords)
if err != nil {
return
}
} else {
if happyOrchardUserAssistanceRecords.Date != today {
happyOrchardUserAssistanceRecords.Nums = 0
happyOrchardUserAssistanceRecords.Date = today
}
}
if happyOrchardUserAssistanceRecords.Nums >= rewardLimit {
return errors.New("当日奖励次数已达上限")
}

session := engine.NewSession()
session.Begin()
defer func() {
session.Close()
if err := recover(); err != nil {
_ = zhios_order_relate_logx.Error(err)
}
}()

//3、查找happy_orchard_user_waters 数据
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session)
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid)
if err != nil {
_ = session.Rollback()
return
}
if happyOrchardUserWaters == nil {
_ = session.Rollback()
return errors.New("用户数据不存在")
}
helperBeforeWaterNums := happyOrchardUserWaters.WaterNums
happyOrchardUserWaters.WaterNums += rewardWatersValue

//4、更新助力者 happy_orchard_user_waters 数据
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums")
if err != nil {
_ = session.Rollback()
return err
}

//5、新增 happy_orchard_user_waters_log 数据
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine)
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{
Uid: req.Uid,
WaterNums: basicSetting.WateringEveryTimeWaterDroplet,
Title: enum.DealUserWatersKind(enum.DealUserWatersKindForPlayRaffleGame).String(),
Kind: 1,
BeforeWaterNums: helperBeforeWaterNums,
AfterWaterNums: happyOrchardUserWaters.WaterNums,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err != nil {
_ = session.Rollback()
return err
}
err = session.Commit()
if err != nil {
return err
}

//6、更改 happy_orchard_user_assistance_records 数据
happyOrchardUserAssistanceRecords.Nums++
happyOrchardUserAssistanceRecordsDb.UpdateHappyOrchardUserAssistanceRecords(happyOrchardUserAssistanceRecords, "nums", "date")
return
}

func generateRandomInt(min, max int) int {
rand.Seed(time.Now().UnixNano()) // 初始化随机种子
return rand.Intn(max-min+1) + min // 生成[min,max]范围内的随机整数
}

+ 14
- 0
rule/micro_applications/init.go 查看文件

@@ -0,0 +1,14 @@
package micro_applications

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache"
)

func Init(redisAddr string) (err error) {
if redisAddr != "" {
cache.NewRedis(redisAddr)
}
_, err = cache.SelectDb(md.RedisDataBase)
return
}

+ 72
- 0
rule/micro_applications/md/happy_orchard.go 查看文件

@@ -0,0 +1,72 @@
package md

type PlayRaffleGameRewardDataStruct struct {
RewardLimit string `json:"reward_limit"`
RewardValue string `json:"reward_value"`
}
type PlayGoldenEggGameRewardDataStruct struct {
RewardLimit string `json:"reward_limit"`
RewardValue string `json:"reward_value"`
}
type BrowsingInterfaceRewardDataStruct struct {
BrowsingInterfaceTimes string `json:"browsing_interface_times"`
RewardValue string `json:"reward_value"`
}
type SharingAssistanceRewardDataStruct struct {
Helper string `json:"helper"`
Assisted string `json:"assisted"`
AssistUpperLimit string `json:"assist_upper_limit"`
}
type PlaceOrderRewardDataStruct struct {
Lowest string `json:"lowest"`
RewardValue string `json:"reward_value"`
}
type TimerSignRewardDataStruct struct {
From string `json:"from"`
To string `json:"to"`
}

type GetHappyOrchardUserSeedRecordDataResp struct {
RecordId int `json:"record_id"` //种子id
RecordName string `json:"record_name"` //种子名称
RecordState int `json:"record_state"` //种子状态
RecordStateZh string `json:"record_state_zh"`
RecordPlantingStage int `json:"record_planting_stage"` //种子种植阶段
RecordPlantingStageZh string `json:"record_planting_stage_zh"`
RecordPlantingNextStage int `json:"record_planting_next_stage"` //种子种植下一阶段
RecordPlantingNextStageZh string `json:"record_planting_next_stage_zh"`
RecordPlantingNextStageNeedWaterNums int `json:"record_planting_next_stage_need_water_nums"` //种子种植下一阶段需浇水次数
NowRecordWaters int `json:"now_record_waters"` //当前种子水滴数
TotalNeedWaters int `json:"total_need_waters"` //总计需要水滴数
PlantingRate float64 `json:"planting_rate"` //种植进度百分比
}

type DealUserWatersKindForWateringReq struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersKindForSevenDaysSignReq struct {
Uid int `json:"uid"` //用户id
SignNums int `json:"sign_num"` //签到天数
}
type DealUserWatersKindForTimerSignReq struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersReqForPlaceOrderRewardReq struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersKindForSharingAssistanceReq struct {
HelperUid int `json:"assistance_uid"` //助力用户id
AssistedUid int `json:"assisted_uid"` //被助力用户id
}
type DealUserWatersKindForInvitingNewPlayersReq struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersKindForBrowsingInterfaceReq struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersKindForPlayGoldenEggGame struct {
Uid int `json:"uid"` //用户id
}
type DealUserWatersKindForPlayRaffleGame struct {
Uid int `json:"uid"` //用户id
}

Loading…
取消
儲存