From d69a103291945286a58e6682b2ca34560fcfd580 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Wed, 22 May 2024 15:54:45 +0800 Subject: [PATCH] update --- rule/micro_applications/enum/happy_orchard.go | 3 + .../happy_orchard_user_waters.go | 65 +++++++++++++++++++ rule/micro_applications/md/happy_orchard.go | 3 + 3 files changed, 71 insertions(+) diff --git a/rule/micro_applications/enum/happy_orchard.go b/rule/micro_applications/enum/happy_orchard.go index b78216d..bd30d0f 100644 --- a/rule/micro_applications/enum/happy_orchard.go +++ b/rule/micro_applications/enum/happy_orchard.go @@ -91,6 +91,7 @@ const ( DealUserWatersKindForBrowsingInterface = "browsing_interface" DealUserWatersKindForPlayGoldenEggGame = "play_golden_egg_game" DealUserWatersKindForPlayRaffleGame = "play_raffle_game" + DealUserWatersKindForUpgradeReward = "upgrade_reward" ) func (kind DealUserWatersKind) String() string { @@ -113,6 +114,8 @@ func (kind DealUserWatersKind) String() string { return "玩金蛋奖励" case DealUserWatersKindForPlayRaffleGame: return "玩抽奖游戏奖励" + case DealUserWatersKindForUpgradeReward: + return "升级奖励" default: return "未知" } diff --git a/rule/micro_applications/happy_orchard_user_waters.go b/rule/micro_applications/happy_orchard_user_waters.go index 3b251e8..69746ed 100644 --- a/rule/micro_applications/happy_orchard_user_waters.go +++ b/rule/micro_applications/happy_orchard_user_waters.go @@ -131,6 +131,17 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err return } break + case enum.DealUserWatersKindForUpgradeReward: + var req *md.DealUserWatersKindForUpgradeRewardReq + err = json.Unmarshal(zhios_order_relate_utils.Serialize(args), &req) + if err != nil { + return + } + err = handelUpgradeReward(engine, *req, *happyOrchardBasicSetting) + if err != nil { + return + } + break } return @@ -637,6 +648,60 @@ func handelBrowsingInterface(engine *xorm.Engine, req md.DealUserWatersKindForBr return session.Commit() } +func handelUpgradeReward(engine *xorm.Engine, req md.DealUserWatersKindForUpgradeRewardReq, basicSetting models.HappyOrchardBasicSetting) (err error) { + now := time.Now() + + //1、获取基础设置中的 "升级奖励" 数据 + rewardWatersValue := basicSetting.UpgradeRewardWaterDroplet //奖励水滴值 + + 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.DealUserWatersKindForUpgradeReward).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") diff --git a/rule/micro_applications/md/happy_orchard.go b/rule/micro_applications/md/happy_orchard.go index a3595da..82b6e2d 100644 --- a/rule/micro_applications/md/happy_orchard.go +++ b/rule/micro_applications/md/happy_orchard.go @@ -70,3 +70,6 @@ type DealUserWatersKindForPlayGoldenEggGame struct { type DealUserWatersKindForPlayRaffleGame struct { Uid int `json:"uid"` //用户id } +type DealUserWatersKindForUpgradeRewardReq struct { + Uid int `json:"uid"` //用户id +}