package svc import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "time" ) func PlayletBase(c *gin.Context) { playletBase := GetSysCfgStr("playlet_base") var res = md.PlayletBaseData{ Reward: gjson.Get(playletBase, "reward").String(), Total: gjson.Get(playletBase, "total").String(), FirstCount: gjson.Get(playletBase, "first_count").String(), SecondCount: gjson.Get(playletBase, "second_count").String(), Leave: gjson.Get(playletBase, "total").String(), Sum: "0.00", CoinName: "活跃值", } user := GetUser(c) //剩余次数 NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db) total, _ := NewPlayletTotalDb.GetPlayletTotal(utils.Int64ToStr(user.Id), time.Now().Format("20060102")) if total != nil { res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - total.Total) if utils.StrToInt(res.Leave) < 0 { res.Leave = "0" } } NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() NewUserVirtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) coin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.PersonEggPointsCoinId) if coin != nil { res.Sum = coin.Amount } e.OutSuc(c, res, nil) return } func PlayletReward(c *gin.Context) { var args md.PlayletRewardRequest if err := c.ShouldBindJSON(&args); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } eg := db.Db playletBase := GetSysCfgStr("playlet_base") sess := eg.NewSession() defer sess.Close() sess.Begin() user := GetUser(c) NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db) total, _ := NewPlayletTotalDb.GetPlayletTotalSess(sess, utils.Int64ToStr(user.Id), time.Now().Format("20060102")) if total == nil { total = &model.PlayletTotal{ Uid: int(user.Id), Date: utils.StrToInt(time.Now().Format("20060102")), Time: time.Now(), } insert, err := sess.Insert(total) if insert == 0 || err != nil { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) return } } Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - total.Total if Leave-1 < 0 { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "今天已领取完")) return } total.Total++ update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total) if update == 0 || err2 != nil { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) return } sess.Commit() ch, err := rabbit.Cfg.Pool.GetChannel() if err == nil { defer ch.Release() NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ Kind: "add", Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), CoinId: eggData.PersonEggPointsCoinId, Uid: user.Id, Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()), }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) if err != nil { ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ Kind: "add", Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), CoinId: eggData.PersonEggPointsCoinId, Uid: user.Id, Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()), }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) } } e.OutSuc(c, "success", nil) return }