123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package orchard
- ////购买祈福
- //func OrchardPayBlessing(c *gin.Context) {
- // rsp := &OrchardRsp{Status: constant.STATUSOK, Msg: "done"}
- // defer func() {
- // c.JSON(200, rsp)
- // }()
- // user := ctx.GetUser(c)
- // req := &OrchardParam{}
- // if err := c.ShouldBind(req); err != nil {
- // log.Printf("userid: %v ,type不能为空 \n", user.ID)
- // rsp.Status = constant.STATUS99
- // rsp.Msg = "type不能为空"
- // return
- // }
- //RETRY:
- // unix := time.Now().Unix()
- // lockRedisKey := fmt.Sprintf("orchard_%v_lock", user.ID)
- // lock := rds.Redis.SetNX(lockRedisKey, unix, 0).Val()
- // if lock {
- // if req.BlessingId < 0 || req.BlessingId > 3 {
- // log.Printf("userid: %v ,type不能为空 \n", user.ID)
- // rsp.Status = constant.STATUS99
- // rds.Redis.Del(lockRedisKey)
- // rsp.Msg = "type不能为空"
- // return
- // }
- // userId := fmt.Sprintf("%v", user.ID)
- // orchardTree := &orchard.OrchardTree{}
- // orchardTree.FindOne(userId)
- // awards := make(map[int32]int64)
- // awards[17] = -orchard.OrchardConf.BlessingList[req.BlessingId-1].CostDiamond
- // if !propsrv.OpDataXX(user, "task", awards, []string{"orchard_blessing", fmt.Sprintf("%v", req.BlessingId)}, 1) {
- // rsp.Status = constant.STATUS99
- // rsp.Msg = "购买失败"
- // rds.Redis.Del(lockRedisKey)
- // return
- // }
- //
- // switch req.BlessingId {
- // case 1:
- // orchardTree.WealthGod = addOrchardDurationTime(orchardTree.WealthGod)
- // case 2:
- // orchardTree.Laojun = addOrchardDurationTime(orchardTree.Laojun)
- // case 3:
- // orchardTree.LuckyCat = addOrchardDurationTime(orchardTree.LuckyCat)
- //
- // }
- // db := tools.NewConn(orchard.MysqlExtDb).Begin()
- // defer db.Rollback()
- // timeNow := time.Now().Unix()
- // dbFruit := tools.NewConn(orchard.MysqlExtDb)
- // if req.BlessingId == 2 {
- // var openTimes int64 = 0
- // orchardFruitList := []orchard.OrchardFruit{}
- // dbFruit.Where("is_accelerate = 0 and open_time > ? ", timeNow).Order("open_time asc").Find(&orchardFruitList)
- // for i := range orchardFruitList {
- // orchardFruitList[i].OpenTime = timeNow + (orchardFruitList[i].OpenTime-timeNow)/100*orchard.OrchardConf.BlessingList[1].UpdatedRate
- // orchardFruitList[i].IsAccelerate = 1
- // openTimes = orchardFruitList[i].OpenTime
- // if err := db.Save(orchardFruitList[i]).Error; err != nil {
- // log.Println(err, userId)
- // rsp.Status = constant.STATUS99
- // rsp.Msg = "购买失败"
- // rds.Redis.Del(lockRedisKey)
- // return
- // }
- // }
- // orchardTree.OpenTime = openTimes
- //
- // //} else if req.BlessingId == 1 {
- // // orchardFruitList := []orchard.OrchardFruit{}
- // // dbFruit.Where("is_increase = 0 and open_time > ? ", timeNow).Order("open_time asc").Find(&orchardFruitList)
- // // for i := range orchardFruitList {
- // // orchardFruitList[i].Number = orchardFruitList[i].Number / 100 * orchard.OrchardConf.BlessingList[0].UpdatedRate
- // // orchardFruitList[i].IsIncrease = 1
- // // dbFruit.Save(orchardFruitList[i])
- // // }
- // }
- // if req.BlessingId == 1 {
- // orchardFruitList := []orchard.OrchardFruit{}
- // dbFruit.Where("is_increase = 0 and create_time <= ? and open_time > ? ", orchardTree.WealthGod, timeNow).Find(&orchardFruitList)
- // for i := range orchardFruitList {
- // orchardFruitList[i].Number = orchardFruitList[i].Number / 100 * orchard.OrchardConf.BlessingList[0].UpdatedRate
- // orchardFruitList[i].IsIncrease = 1
- // if err := db.Save(orchardFruitList[i]).Error; err != nil {
- // log.Println(err, userId)
- // rsp.Status = constant.STATUS99
- // rsp.Msg = "购买失败"
- // rds.Redis.Del(lockRedisKey)
- // return
- // }
- // }
- // }
- // if err := db.Save(&orchardTree).Error; err != nil {
- // log.Println(err, userId)
- // rsp.Status = constant.STATUS99
- // rsp.Msg = "购买失败"
- // rds.Redis.Del(lockRedisKey)
- // return
- // }
- // var wealthGod, laojun, luckyCat int64
- // if orchardTree.WealthGod > timeNow {
- // wealthGod = orchardTree.WealthGod - timeNow
- // }
- // if orchardTree.Laojun > timeNow {
- // laojun = orchardTree.Laojun - timeNow
- // }
- // if orchardTree.LuckyCat > timeNow {
- // luckyCat = orchardTree.LuckyCat - timeNow
- // }
- //
- // rds.Redis.Del(lockRedisKey)
- // db.Commit()
- // orchard.ReloadDataOrchardUserInfo(userId)
- // userInfo := &orchard.OrchardUserInfo{}
- // if req.WaterId == 2 {
- // userInfo.GetData(userId)
- // rsp.Data = struct {
- // WealthGod int64 `json:"wealth_god"`
- // Laojun int64 `json:"laojun"`
- // LuckyCat int64 `json:"lucky_cat"`
- // orchard.OrchardUserInfo
- // }{
- // wealthGod,
- // laojun,
- // luckyCat,
- // *userInfo,
- // }
- // } else {
- // rsp.Data = struct {
- // WealthGod int64 `json:"wealth_god"`
- // Laojun int64 `json:"laojun"`
- // LuckyCat int64 `json:"lucky_cat"`
- // orchard.OrchardUserInfo
- // }{
- // WealthGod: wealthGod,
- // Laojun: laojun,
- // LuckyCat: luckyCat,
- // }
- // }
- //
- // } else {
- // nxValue := rds.Redis.Get(lockRedisKey).Val()
- // nxUnixValue, _ := strconv.ParseInt(nxValue, 10, 64)
- // if time.Now().Unix()-nxUnixValue > 5 {
- // rds.Redis.Del(lockRedisKey)
- // goto RETRY
- // }
- // rsp.Msg = "请勿重新请求"
- // rsp.Status = constant.STATUS99
- // }
- //}
|