zhusi.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package orchard
  2. ////购买祈福
  3. //func OrchardPayBlessing(c *gin.Context) {
  4. // rsp := &OrchardRsp{Status: constant.STATUSOK, Msg: "done"}
  5. // defer func() {
  6. // c.JSON(200, rsp)
  7. // }()
  8. // user := ctx.GetUser(c)
  9. // req := &OrchardParam{}
  10. // if err := c.ShouldBind(req); err != nil {
  11. // log.Printf("userid: %v ,type不能为空 \n", user.ID)
  12. // rsp.Status = constant.STATUS99
  13. // rsp.Msg = "type不能为空"
  14. // return
  15. // }
  16. //RETRY:
  17. // unix := time.Now().Unix()
  18. // lockRedisKey := fmt.Sprintf("orchard_%v_lock", user.ID)
  19. // lock := rds.Redis.SetNX(lockRedisKey, unix, 0).Val()
  20. // if lock {
  21. // if req.BlessingId < 0 || req.BlessingId > 3 {
  22. // log.Printf("userid: %v ,type不能为空 \n", user.ID)
  23. // rsp.Status = constant.STATUS99
  24. // rds.Redis.Del(lockRedisKey)
  25. // rsp.Msg = "type不能为空"
  26. // return
  27. // }
  28. // userId := fmt.Sprintf("%v", user.ID)
  29. // orchardTree := &orchard.OrchardTree{}
  30. // orchardTree.FindOne(userId)
  31. // awards := make(map[int32]int64)
  32. // awards[17] = -orchard.OrchardConf.BlessingList[req.BlessingId-1].CostDiamond
  33. // if !propsrv.OpDataXX(user, "task", awards, []string{"orchard_blessing", fmt.Sprintf("%v", req.BlessingId)}, 1) {
  34. // rsp.Status = constant.STATUS99
  35. // rsp.Msg = "购买失败"
  36. // rds.Redis.Del(lockRedisKey)
  37. // return
  38. // }
  39. //
  40. // switch req.BlessingId {
  41. // case 1:
  42. // orchardTree.WealthGod = addOrchardDurationTime(orchardTree.WealthGod)
  43. // case 2:
  44. // orchardTree.Laojun = addOrchardDurationTime(orchardTree.Laojun)
  45. // case 3:
  46. // orchardTree.LuckyCat = addOrchardDurationTime(orchardTree.LuckyCat)
  47. //
  48. // }
  49. // db := tools.NewConn(orchard.MysqlExtDb).Begin()
  50. // defer db.Rollback()
  51. // timeNow := time.Now().Unix()
  52. // dbFruit := tools.NewConn(orchard.MysqlExtDb)
  53. // if req.BlessingId == 2 {
  54. // var openTimes int64 = 0
  55. // orchardFruitList := []orchard.OrchardFruit{}
  56. // dbFruit.Where("is_accelerate = 0 and open_time > ? ", timeNow).Order("open_time asc").Find(&orchardFruitList)
  57. // for i := range orchardFruitList {
  58. // orchardFruitList[i].OpenTime = timeNow + (orchardFruitList[i].OpenTime-timeNow)/100*orchard.OrchardConf.BlessingList[1].UpdatedRate
  59. // orchardFruitList[i].IsAccelerate = 1
  60. // openTimes = orchardFruitList[i].OpenTime
  61. // if err := db.Save(orchardFruitList[i]).Error; err != nil {
  62. // log.Println(err, userId)
  63. // rsp.Status = constant.STATUS99
  64. // rsp.Msg = "购买失败"
  65. // rds.Redis.Del(lockRedisKey)
  66. // return
  67. // }
  68. // }
  69. // orchardTree.OpenTime = openTimes
  70. //
  71. // //} else if req.BlessingId == 1 {
  72. // // orchardFruitList := []orchard.OrchardFruit{}
  73. // // dbFruit.Where("is_increase = 0 and open_time > ? ", timeNow).Order("open_time asc").Find(&orchardFruitList)
  74. // // for i := range orchardFruitList {
  75. // // orchardFruitList[i].Number = orchardFruitList[i].Number / 100 * orchard.OrchardConf.BlessingList[0].UpdatedRate
  76. // // orchardFruitList[i].IsIncrease = 1
  77. // // dbFruit.Save(orchardFruitList[i])
  78. // // }
  79. // }
  80. // if req.BlessingId == 1 {
  81. // orchardFruitList := []orchard.OrchardFruit{}
  82. // dbFruit.Where("is_increase = 0 and create_time <= ? and open_time > ? ", orchardTree.WealthGod, timeNow).Find(&orchardFruitList)
  83. // for i := range orchardFruitList {
  84. // orchardFruitList[i].Number = orchardFruitList[i].Number / 100 * orchard.OrchardConf.BlessingList[0].UpdatedRate
  85. // orchardFruitList[i].IsIncrease = 1
  86. // if err := db.Save(orchardFruitList[i]).Error; err != nil {
  87. // log.Println(err, userId)
  88. // rsp.Status = constant.STATUS99
  89. // rsp.Msg = "购买失败"
  90. // rds.Redis.Del(lockRedisKey)
  91. // return
  92. // }
  93. // }
  94. // }
  95. // if err := db.Save(&orchardTree).Error; err != nil {
  96. // log.Println(err, userId)
  97. // rsp.Status = constant.STATUS99
  98. // rsp.Msg = "购买失败"
  99. // rds.Redis.Del(lockRedisKey)
  100. // return
  101. // }
  102. // var wealthGod, laojun, luckyCat int64
  103. // if orchardTree.WealthGod > timeNow {
  104. // wealthGod = orchardTree.WealthGod - timeNow
  105. // }
  106. // if orchardTree.Laojun > timeNow {
  107. // laojun = orchardTree.Laojun - timeNow
  108. // }
  109. // if orchardTree.LuckyCat > timeNow {
  110. // luckyCat = orchardTree.LuckyCat - timeNow
  111. // }
  112. //
  113. // rds.Redis.Del(lockRedisKey)
  114. // db.Commit()
  115. // orchard.ReloadDataOrchardUserInfo(userId)
  116. // userInfo := &orchard.OrchardUserInfo{}
  117. // if req.WaterId == 2 {
  118. // userInfo.GetData(userId)
  119. // rsp.Data = struct {
  120. // WealthGod int64 `json:"wealth_god"`
  121. // Laojun int64 `json:"laojun"`
  122. // LuckyCat int64 `json:"lucky_cat"`
  123. // orchard.OrchardUserInfo
  124. // }{
  125. // wealthGod,
  126. // laojun,
  127. // luckyCat,
  128. // *userInfo,
  129. // }
  130. // } else {
  131. // rsp.Data = struct {
  132. // WealthGod int64 `json:"wealth_god"`
  133. // Laojun int64 `json:"laojun"`
  134. // LuckyCat int64 `json:"lucky_cat"`
  135. // orchard.OrchardUserInfo
  136. // }{
  137. // WealthGod: wealthGod,
  138. // Laojun: laojun,
  139. // LuckyCat: luckyCat,
  140. // }
  141. // }
  142. //
  143. // } else {
  144. // nxValue := rds.Redis.Get(lockRedisKey).Val()
  145. // nxUnixValue, _ := strconv.ParseInt(nxValue, 10, 64)
  146. // if time.Now().Unix()-nxUnixValue > 5 {
  147. // rds.Redis.Del(lockRedisKey)
  148. // goto RETRY
  149. // }
  150. // rsp.Msg = "请勿重新请求"
  151. // rsp.Status = constant.STATUS99
  152. // }
  153. //}