|
@@ -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]范围内的随机整数 |
|
|
|
|
|
} |