shopmgr.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. package shop
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/redis"
  5. "bet24.com/servers/common"
  6. "bet24.com/servers/coreservice/giftpack"
  7. "bet24.com/servers/coreservice/monthlycard"
  8. activityservice "bet24.com/servers/micros/activityservice/proto"
  9. badge "bet24.com/servers/micros/badge/proto"
  10. dotservice "bet24.com/servers/micros/dotservice/proto"
  11. giftservice "bet24.com/servers/micros/giftservice/proto"
  12. highlyprofitable "bet24.com/servers/micros/highly_profitable/proto"
  13. inventory "bet24.com/servers/micros/item_inventory/proto"
  14. item "bet24.com/servers/micros/item_inventory/proto"
  15. money "bet24.com/servers/micros/money/proto"
  16. notification "bet24.com/servers/micros/notification/proto"
  17. task "bet24.com/servers/micros/task/proto"
  18. userlabel "bet24.com/servers/micros/userlabel/proto"
  19. waterPool "bet24.com/servers/micros/waterpool/proto"
  20. //user "bet24.com/servers/micros/userservices/proto"
  21. "encoding/json"
  22. "fmt"
  23. "sort"
  24. "strconv"
  25. "strings"
  26. "sync"
  27. "time"
  28. vipservice "bet24.com/servers/micros/userservices/proto"
  29. )
  30. type shopmgr struct {
  31. lock *sync.RWMutex
  32. //exchangeRateList []*exchangeRate
  33. firstChargeList []*Shop_Item
  34. shopList map[string]*Shop_Item
  35. }
  36. func newShopMgr() *shopmgr {
  37. obj := new(shopmgr)
  38. obj.lock = &sync.RWMutex{}
  39. obj.shopList = make(map[string]*Shop_Item)
  40. //obj.loadExchangeRate()
  41. obj.loadShopList()
  42. log.Debug("shop manager running")
  43. return obj
  44. }
  45. /*
  46. // 先加载汇率
  47. func (this *shopmgr) loadExchangeRate() {
  48. list := getExchangeRate()
  49. if list == nil {
  50. log.Error("shopmgr.loadExchangeRate is empty ...")
  51. }
  52. this.lock.Lock()
  53. defer this.lock.Unlock()
  54. this.exchangeRateList = list
  55. }
  56. */
  57. func (this *shopmgr) loadShopList() {
  58. time.AfterFunc(2*time.Minute, this.loadShopList)
  59. // 商城列表
  60. list := getShopList()
  61. this.firstChargeList = []*Shop_Item{}
  62. this.lock.Lock()
  63. this.shopList = make(map[string]*Shop_Item)
  64. for _, v := range list {
  65. if v.Bonus > 0 {
  66. bonus := float64(v.Bonus) / 100
  67. // 实际给的道具
  68. for j := 0; j < len(v.Extra); j++ {
  69. v.Extra[j].Count = int(float64(v.Extra[j].Count) * bonus)
  70. }
  71. }
  72. this.shopList[v.ProductId] = v
  73. if v.ShopType == ShopType_FirstCharge {
  74. this.firstChargeList = append(this.firstChargeList, v)
  75. }
  76. }
  77. this.lock.Unlock()
  78. }
  79. func (this *shopmgr) getShopList(userId, shopType int) []*Shop_Item {
  80. var list []*Shop_Item
  81. isAllow := this.isFirstChargeAllow(userId)
  82. this.lock.RLock()
  83. for _, v := range this.shopList {
  84. if v.ShopType != shopType && shopType != 0 {
  85. continue
  86. }
  87. if v.ShopType == ShopType_FirstCharge && !isAllow {
  88. continue
  89. }
  90. // 苹果多渠道产品不下发
  91. if PayType_RMB == v.PayType && strings.Contains(v.ProductId, "BL_") {
  92. continue
  93. }
  94. if v.ShopType == ShopType_FirstCharge {
  95. str, ret := redis.String_Get(fmt.Sprintf("%d:%s", userId, v.ProductId))
  96. if ret && str != "" {
  97. v.Status = 2
  98. } else {
  99. v.Status = 0
  100. }
  101. }
  102. list = append(list, v)
  103. }
  104. this.lock.RUnlock()
  105. // changePrice带锁,所以需要在锁外处理
  106. for k, v := range list {
  107. // list[k] = this.changePrice(userId, v)
  108. list[k] = this.getSavingPotAmount(userId, v)
  109. }
  110. sort.Slice(list, func(i, j int) bool {
  111. if list[i].ShopType == list[j].ShopType && list[i].ShopType == ShopType_Diamond {
  112. return list[i].Price < list[j].Price
  113. }
  114. return list[i].ProductId < list[j].ProductId
  115. })
  116. return list
  117. }
  118. func (this *shopmgr) getUserPrice(userId int, price float64) float64 {
  119. return price
  120. /*
  121. uInfo := user.GetUserInfo(userId)
  122. currency := ""
  123. if uInfo != nil {
  124. currency = uInfo.Currency
  125. }
  126. return this.getLocalPrice(currency, price)
  127. */
  128. }
  129. /*
  130. func (this *shopmgr) getLocalPrice(currency string, basePrice float64) float64 {
  131. if currency == "" {
  132. return basePrice
  133. }
  134. info := this.exchangeRateInfo(currency)
  135. if info == nil {
  136. return basePrice
  137. }
  138. return info.Rate * basePrice
  139. }
  140. */
  141. func (this *shopmgr) getProduct(userId int, productId string) *Shop_Item {
  142. this.lock.RLock()
  143. si, ok := this.shopList[productId]
  144. this.lock.RUnlock()
  145. if !ok {
  146. return nil
  147. }
  148. //return si
  149. //return this.changePrice(userId, si)
  150. return this.getSavingPotAmount(userId, si)
  151. }
  152. // 获取存钱罐数据
  153. func (this *shopmgr) getSavingPotAmount(userId int, shopItem *Shop_Item) *Shop_Item {
  154. if shopItem.PayType != PayType_RMB || shopItem.ShopType != ShopType_SavingPot {
  155. return shopItem
  156. }
  157. // 存钱罐
  158. amount := activityservice.GetUserSavingPotBuyAmount(userId, shopItem.ProductId == "1300001")
  159. if amount <= 0 && shopItem.ProductId != "1300001" {
  160. return shopItem
  161. }
  162. items := make([]item.ItemPack, len(shopItem.Extra))
  163. copy(items, shopItem.Extra)
  164. // 追加存钱罐
  165. for i := 0; i < len(items); i++ {
  166. if items[i].ItemId != item.Item_Gold {
  167. continue
  168. }
  169. if shopItem.ProductId != "1300001" {
  170. items[i].Count = amount
  171. } else {
  172. items[i].Count += amount
  173. }
  174. break
  175. }
  176. cpyItem := &Shop_Item{
  177. ProductId: shopItem.ProductId,
  178. ProductName: shopItem.ProductName,
  179. Price: shopItem.Price,
  180. ShowPrice: shopItem.ShowPrice,
  181. PayType: shopItem.PayType,
  182. ShopType: shopItem.ShopType,
  183. IsHot: shopItem.IsHot,
  184. Bonus: shopItem.Bonus,
  185. Extra: items,
  186. Status: shopItem.Status,
  187. Sort: shopItem.Sort,
  188. AnimationType: shopItem.AnimationType,
  189. UserType: shopItem.UserType,
  190. IsBottom: shopItem.IsBottom,
  191. }
  192. return cpyItem
  193. }
  194. /*
  195. func (this *shopmgr) changePrice(userId int, shopItem *Shop_Item) *Shop_Item {
  196. if userId <= 0 || shopItem.PayType != PayType_RMB {
  197. return shopItem
  198. }
  199. // 需要转换价格
  200. // 获取
  201. uInfo := user.GetUserInfo(userId)
  202. currency := ""
  203. if uInfo != nil {
  204. currency = uInfo.Currency
  205. }
  206. items := make([]item.ItemPack, len(shopItem.Extra))
  207. copy(items, shopItem.Extra)
  208. cpyItem := &Shop_Item{
  209. ProductId: shopItem.ProductId,
  210. ProductName: shopItem.ProductName,
  211. Price: shopItem.Price,
  212. ShowPrice: shopItem.ShowPrice,
  213. PayType: shopItem.PayType,
  214. ShopType: shopItem.ShopType,
  215. IsHot: shopItem.IsHot,
  216. Bonus: shopItem.Bonus,
  217. Extra: items,
  218. Status: shopItem.Status,
  219. /*Sort: shopItem.Sort,
  220. AnimationType: shopItem.AnimationType,
  221. UserType: shopItem.UserType,
  222. IsBottom: shopItem.IsBottom,* /
  223. }
  224. cpyItem.Price = this.getLocalPrice(currency, cpyItem.Price)
  225. cpyItem.ShowPrice = this.getLocalPrice(currency, cpyItem.ShowPrice)
  226. return cpyItem
  227. }
  228. */
  229. func (this *shopmgr) exchangeInBulk(userId int, productIds []string) (int, string) {
  230. ret := 0
  231. msg := ""
  232. totalDiamond := 0
  233. var items []item.ItemPack
  234. totalGold := 0
  235. for _, v := range productIds {
  236. product := this.getProduct(userId, v)
  237. if product == nil {
  238. msg = fmt.Sprintf("userId=%d Product信息(%s)Not Exist", userId, v)
  239. log.Error("shop.exchange %s ", msg)
  240. return ret, msg
  241. }
  242. if product.ShopType < ShopType_Gold || product.ShopType >= ShopType_Max {
  243. msg = fmt.Sprintf("userId=%d Product(%s) Invalid", userId, v)
  244. log.Error("shop.exchange %s", msg)
  245. return ret, msg
  246. }
  247. if product.PayType == PayType_Diamond {
  248. totalDiamond += int(product.Price)
  249. } else if product.PayType == PayType_Gold {
  250. totalGold += int(product.Price)
  251. } else {
  252. msg = fmt.Sprintf("userId=%d Product信息(%s)Invalid", userId, v)
  253. log.Error("shop.exchange %s ", msg)
  254. return ret, msg
  255. }
  256. items = append(items, product.Extra...)
  257. }
  258. items = item.GroupItems(items)
  259. remark := "批量兑换"
  260. //扣钻石
  261. if totalDiamond > 0 {
  262. if money.ReduceChip(userId, totalDiamond, common.LOGTYPE_EXCHANGE_GOLD, "shop", "exchangeGoldInBulk", "") != 1 {
  263. msg = fmt.Sprintf("userId=%d not enough diamond need %d", userId, totalDiamond)
  264. log.Release("shop.exchangeInBulk %s ", msg)
  265. return ret, msg
  266. }
  267. }
  268. if totalGold > 0 {
  269. if !money.ReduceMoney(userId, totalGold, common.LOGTYPE_EXCHANGE_GOLD, "shop", "exchangeGoldInBulk", "") {
  270. msg = fmt.Sprintf("userId=%d not enough gold need %d", userId, totalGold)
  271. log.Release("shop.exchangeInBulk %s ", msg)
  272. if totalDiamond > 0 {
  273. money.GiveChip(userId, totalDiamond, common.LOGTYPE_EXCHANGE_GOLD, "shop", "exchangeGoldInBulk return", "")
  274. }
  275. return ret, msg
  276. }
  277. }
  278. //加道具
  279. if success := inventory.AddItems(userId, items, remark, common.LOGTYPE_EXCHANGE_GOLD); !success {
  280. ret = 0
  281. msg = fmt.Sprintf("exchange gold failure")
  282. log.Debug("shop.exchangeInBulk userId=%d product=%v %s,加道具失败", userId, items, msg)
  283. return ret, msg
  284. }
  285. d, _ := json.Marshal(items)
  286. notification.AddNotification(userId, notification.Notification_Exchange, string(d))
  287. task.DoTaskAction(userId, task.TaskAction_exchange_item, 1, task.TaskScope{})
  288. ret = 1
  289. msg = "Success"
  290. return ret, msg
  291. }
  292. func (this *shopmgr) sendFirstChargeItem(userId int, productId string) (int, string) {
  293. key := fmt.Sprintf("%d:%s", userId, productId)
  294. data, success := redis.String_Get(key)
  295. if !success || data == "" {
  296. return 0, ""
  297. }
  298. var resp item.ItemFirstCharge
  299. err := json.Unmarshal([]byte(data), &resp)
  300. if err != nil {
  301. return 0, ""
  302. }
  303. nowDayIndex := common.GetNowDayIndex()
  304. diffDay := nowDayIndex - resp.BuyDayIndex
  305. if diffDay <= 0 {
  306. return 0, ""
  307. }
  308. var items []item.ItemPack
  309. for i := 0; i < len(resp.Items); i++ {
  310. if diffDay >= resp.Items[i].Day {
  311. items = append(items, resp.Items[i])
  312. }
  313. }
  314. if len(items) == 0 {
  315. return 0, ""
  316. }
  317. count := item.GetItemExtraCount(items, item.Item_Chip)
  318. badge.DoAction(userId, badge.Action_Recharge, count, badge.Scope{})
  319. //购买, 通知客户端
  320. d, _ := json.Marshal(notification.NotificationRecharge{
  321. RetCode: 0,
  322. Items: items,
  323. ProductId: productId,
  324. ShopType: resp.ShopType,
  325. BasePrice: resp.BasePrice,
  326. IsRefresh: diffDay >= 2,
  327. IsGift: false,
  328. })
  329. inventory.AddItems(userId, items, "充值成功", common.LOGTYPE_SHOPBUY)
  330. notification.AddNotification(userId, notification.Notification_Recharge, string(d))
  331. if diffDay >= 2 {
  332. redis.String_SetEx(key, "", 1)
  333. } else {
  334. var returnValue item.ItemFirstCharge
  335. returnValue.BasePrice = resp.BasePrice
  336. returnValue.BuyDayIndex = resp.BuyDayIndex
  337. returnValue.ProductId = resp.ProductId
  338. returnValue.ShopType = resp.ShopType
  339. for n := 0; n < len(resp.Items); n++ {
  340. if resp.Items[n].Day > 1 {
  341. returnValue.Items = append(returnValue.Items, resp.Items[n])
  342. }
  343. }
  344. value, _ := json.Marshal(returnValue)
  345. redis.String_Set(key, string(value))
  346. }
  347. return 1, "Success"
  348. }
  349. func (this *shopmgr) exchange(userId int, productId string) (int, string) {
  350. ret := 0
  351. msg := ""
  352. product := this.getProduct(userId, productId)
  353. if product == nil {
  354. msg = fmt.Sprintf("userId=%d Product信息(%s)Not Exist", userId, productId)
  355. log.Error("shop.exchange %s ", msg)
  356. return ret, msg
  357. }
  358. if product.ShopType < ShopType_Gold || product.ShopType >= ShopType_Max {
  359. msg = fmt.Sprintf("userId=%d Product(%s) Invalid", userId, productId)
  360. log.Error("shop.exchange %s", msg)
  361. return ret, msg
  362. }
  363. if product.PayType != PayType_Diamond && product.PayType != PayType_Gold {
  364. msg = fmt.Sprintf("userId=%d Product信息(%s)Invalid", userId, productId)
  365. log.Error("shop.exchange %s ", msg)
  366. return ret, msg
  367. }
  368. remark := "钻石兑换"
  369. price := int(product.Price)
  370. if product.PayType == PayType_Gold {
  371. remark = "金币兑换"
  372. if !money.ReduceMoney(userId, price, common.LOGTYPE_EXCHANGE_GOLD, "shop", "exchangeGold", "") {
  373. msg = fmt.Sprintf("userId=%d not enough gold", userId)
  374. log.Release("shop.exchange %s ", msg)
  375. return ret, msg
  376. }
  377. // 徽章进度
  378. badge.DoAction(userId, badge.Action_PropConsumeGold, price, badge.Scope{})
  379. } else {
  380. //扣钻石
  381. if money.ReduceChip(userId, price, common.LOGTYPE_EXCHANGE_GOLD, "shop", "exchangeGold", "") != 1 {
  382. msg = fmt.Sprintf("userId=%d not enough chip", userId)
  383. log.Release("shop.exchange %s ", msg)
  384. return ret, msg
  385. }
  386. }
  387. //加道具
  388. if success := inventory.AddItems(userId, product.Extra, remark, common.LOGTYPE_EXCHANGE_GOLD); !success {
  389. ret = 0
  390. msg = fmt.Sprintf("exchange gold failure")
  391. log.Debug("shop.exchange userId=%d product=%+v %s,加道具失败", userId, product, msg)
  392. return ret, msg
  393. }
  394. d, _ := json.Marshal(product.Extra)
  395. notification.AddNotification(userId, notification.Notification_Exchange, string(d))
  396. task.DoTaskAction(userId, task.TaskAction_exchange_item, 1, task.TaskScope{})
  397. ret = 1
  398. msg = "Success"
  399. return ret, msg
  400. }
  401. func (this *shopmgr) recharge(userId int, productId string) (int, string) {
  402. ret, msg := 0, "购买失败"
  403. product := this.getProduct(userId, productId)
  404. if product == nil {
  405. msg = fmt.Sprintf("userId=%d, Product信息(%s)Not Exist", userId, productId)
  406. log.Error("shop.recharge %s ", msg)
  407. return ret, msg
  408. }
  409. log.Debug("shopmgr.recharge userId=%d productId=%s ==>%+v", userId, productId, product)
  410. if product.ShopType < ShopType_Gold || product.ShopType >= ShopType_Max {
  411. msg = fmt.Sprintf("userId=%d Product(%s) Invalid", userId, productId)
  412. log.Error("shop.recharge %s", msg)
  413. return ret, msg
  414. }
  415. if product.PayType != PayType_RMB {
  416. msg = fmt.Sprintf("Product信息(%s)不允许充值", productId)
  417. log.Error("shop.recharge 支付 PayType(%d), %s ", product.PayType, msg)
  418. return ret, msg
  419. }
  420. // 获取金币
  421. _, amount := money.GetMoney(userId)
  422. //道具
  423. var items []item.ItemPack
  424. switch product.ShopType {
  425. case ShopType_GrowthGift: // 购买新手礼包
  426. this.sendNotification(userId, ret, productId, items, product, false)
  427. activityservice.BuyGiftPackage(userId, productId)
  428. return 1, "购买成功"
  429. case ShopType_VipPackage: // 购买vip礼包
  430. this.sendNotification(userId, ret, productId, items, product, false)
  431. vipservice.BuyPackage(userId, productId)
  432. return 1, "购买成功"
  433. case ShopType_RechargeGift: //充值礼包
  434. items = giftpack.BuyGiftPack(userId, productId)
  435. if items == nil {
  436. ret = 0
  437. log.Debug("shop.recharge userId=%d product=%+v %s,购买礼包失败", userId, product, msg)
  438. return ret, msg
  439. }
  440. /*case ShopType_GrowthGift: //成长礼包
  441. if ret, msg, items = giftpack.BuyGrowthPack(userId, productId); ret != 1 {
  442. ret = 0
  443. log.Debug("shop.recharge userId=%d product=%+v %s,购买成长礼包失败", userId, product, msg)
  444. return ret, msg
  445. }*/
  446. case ShopType_MonthlyCard: //购买月卡
  447. if productId == monthlycard.Month_ProductId {
  448. if ret, items = monthlycard.BuyMonth(userId); ret != 1 {
  449. ret = 0
  450. log.Debug("shop.recharge userId=%d product=%+v %s,购买月卡失败", userId, product, msg)
  451. return ret, msg
  452. }
  453. } else if productId == monthlycard.Week_ProductId {
  454. if ret, items = monthlycard.BuyWeek(userId); ret != 1 {
  455. ret = 0
  456. log.Debug("shop.recharge userId=%d product=%+v %s,购买周卡失败", userId, product, msg)
  457. return ret, msg
  458. }
  459. }
  460. case ShopType_Diamond, ShopType_FirstCharge: // 钻石、首充礼包
  461. if !this.isFirstChargeBuy(userId) && ShopType_FirstCharge == product.ShopType {
  462. return ret, msg
  463. }
  464. tempItems := []item.ItemPack{}
  465. if product.ShopType == ShopType_FirstCharge {
  466. for i := 0; i < len(product.Extra); i++ {
  467. if product.Extra[i].Day == 0 {
  468. tempItems = append(tempItems, product.Extra[i])
  469. }
  470. }
  471. } else {
  472. tempItems = append(tempItems, product.Extra...)
  473. }
  474. // 徽章进度
  475. count := item.GetItemExtraCount(tempItems, item.Item_Chip)
  476. badge.DoAction(userId, badge.Action_Recharge, count, badge.Scope{})
  477. fallthrough
  478. default:
  479. if product.ShopType == ShopType_SavingPot { // 存钱罐
  480. if product.Extra[0].Count <= 0 {
  481. return ret, msg
  482. }
  483. success := activityservice.SavingPotBuy(userId, product.ProductId == "1300001")
  484. if !success {
  485. return ret, msg
  486. }
  487. } else if product.ShopType == ShopType_HighlyProfitable { // 一本万利
  488. highlyprofitable.ActivationHighlyProfitableNotification(userId)
  489. }
  490. remark := "充值成功"
  491. if product.ShopType == ShopType_FirstCharge {
  492. var firstCharge item.ItemFirstCharge
  493. firstCharge.BuyDayIndex = common.GetNowDayIndex()
  494. firstCharge.BasePrice = product.Price
  495. firstCharge.ProductId = product.ProductId
  496. firstCharge.ShopType = ShopType_FirstCharge
  497. key := fmt.Sprintf("%d:%s", userId, productId)
  498. for i := 0; i < len(product.Extra); i++ {
  499. if product.Extra[i].Day == 0 {
  500. items = append(items, product.Extra[i])
  501. } else {
  502. firstCharge.Items = append(firstCharge.Items, product.Extra[i])
  503. }
  504. }
  505. if len(firstCharge.Items) > 0 {
  506. value, _ := json.Marshal(firstCharge)
  507. redis.String_Set(key, string(value))
  508. }
  509. } else {
  510. items = append(items, product.Extra...)
  511. }
  512. isGift := false
  513. // 如果是赠送礼物,则由礼物系统发放道具给对方
  514. if !giftservice.CheckGiftCharge(userId, productId) {
  515. //加道具
  516. if success := inventory.AddItems(userId, items, remark, common.LOGTYPE_SHOPBUY); !success {
  517. ret = 0
  518. msg = fmt.Sprintf("充值失败")
  519. log.Debug("shop.recharge userId=%d product=%+v %s,充值钻石失败", userId, product, msg)
  520. return ret, msg
  521. }
  522. } else {
  523. log.Release("giftservice.CheckGiftCharge %d,%s", userId, productId)
  524. isGift = true
  525. }
  526. this.sendNotification(userId, ret, productId, items, product, isGift)
  527. }
  528. go func() {
  529. price := int(product.Price + 0.5)
  530. // 充值触发
  531. payTrigger(userId, productId, product.ShopType, price)
  532. //user.AddPoint(userId, price)
  533. // 新版vip添加点数,触发升级
  534. vipservice.AddVipPoint(userId, price)
  535. task.DoTaskAction(userId, task.TaskAction_pay, price, task.TaskScope{})
  536. // 触发用户标签
  537. userlabel.TriggerEvent(userId, userlabel.Type_Charge, userlabel.Scope{
  538. GoldAmount: amount,
  539. PayPrice: product.Price,
  540. IsDiscount: product.ShowPrice > product.Price,
  541. Num: 1,
  542. })
  543. // 打点统计
  544. dotservice.AddDot(userId, dotservice.DotScope{
  545. Scene: dotservice.Scene_Shop,
  546. Action: dotservice.Action_Complete,
  547. Extra: productId,
  548. })
  549. // 等级礼包
  550. if product.ShopType == ShopType_LevelRewards {
  551. activityservice.UpdateUserInfoToLevelRewards(userId)
  552. }
  553. // 加个人奖池
  554. waterPool.GrantUserNewWaterPool(userId, price*10000, "充值")
  555. }()
  556. ret = 1
  557. msg = "购买成功"
  558. return ret, msg
  559. }
  560. // 发送通知
  561. func (this *shopmgr) sendNotification(userId, ret int, productId string, items []item.ItemPack, product *Shop_Item, isGift bool) {
  562. //购买, 通知客户端
  563. d, _ := json.Marshal(notification.NotificationRecharge{
  564. RetCode: ret,
  565. Items: items,
  566. ProductId: productId,
  567. ShopType: product.ShopType,
  568. BasePrice: product.Price,
  569. IsRefresh: product.Bonus > 0 || product.ShopType == ShopType_SavingPot,
  570. IsGift: isGift,
  571. })
  572. notification.AddNotification(userId, notification.Notification_Recharge, string(d))
  573. }
  574. func isDouble(userId int, productId string) bool {
  575. fp := getFirstPurchase(userId)
  576. for _, v := range fp {
  577. if v.productId == productId {
  578. return v.value
  579. }
  580. }
  581. return false
  582. }
  583. func (this *shopmgr) isFirstChargeBuy(userId int) bool {
  584. if len(this.firstChargeList) == 0 {
  585. return false
  586. }
  587. fp := getFirstPurchase(userId)
  588. for _, v := range fp {
  589. if v.value { // 没有购买过
  590. continue
  591. }
  592. // 已经购买过,并且属于首充ID
  593. for _, v2 := range this.firstChargeList {
  594. if v.productId == v2.ProductId {
  595. return false
  596. }
  597. }
  598. }
  599. return true
  600. }
  601. func (this *shopmgr) isFirstChargeAllow(userId int) bool {
  602. if len(this.firstChargeList) == 0 {
  603. return false
  604. }
  605. fp := getFirstPurchase(userId)
  606. for _, v := range fp {
  607. if v.value { // 没有购买过
  608. continue
  609. }
  610. // 已经购买过,并且属于首充ID
  611. for _, v2 := range this.firstChargeList {
  612. if v.productId == v2.ProductId {
  613. str, ret := redis.String_Get(fmt.Sprintf("%d:%s", userId, v2.ProductId))
  614. if !ret || str == "" {
  615. return false
  616. }
  617. }
  618. }
  619. }
  620. return true
  621. }
  622. /*
  623. // 充值记录
  624. func (this *shopmgr) getRechargeList(userId, shopType int) []*rechargeInfo {
  625. return getRechargeList(userId, shopType)
  626. }
  627. // 币种列表
  628. func (this *shopmgr) getExchangeRateList() []*exchangeRate {
  629. this.lock.RLock()
  630. defer this.lock.RUnlock()
  631. return this.exchangeRateList
  632. }
  633. // 获取币种信息,传空信息的话,默认选择一个币种
  634. func (this *shopmgr) exchangeRateInfo(currency string) *exchangeRate {
  635. this.lock.RLock()
  636. defer this.lock.RUnlock()
  637. for _, v := range this.exchangeRateList {
  638. if currency == "" {
  639. return v
  640. }
  641. if v.Currency == currency {
  642. return v
  643. }
  644. }
  645. return nil
  646. }
  647. */
  648. func (this *shopmgr) dump(param1, param2 string) {
  649. log.Release("-------------------------------")
  650. log.Release("shopmgr.dump %s", param1)
  651. defer func() {
  652. log.Release("+++++++++++++++++++++++++++++++")
  653. log.Release("")
  654. }()
  655. shopType, err := strconv.Atoi(param1)
  656. if err != nil {
  657. for i := ShopType_Gold; i < ShopType_Max; i++ {
  658. shopList := this.getShopList(0, i)
  659. if len(shopList) == 0 {
  660. continue
  661. }
  662. log.Release(" Type[%d]:", i)
  663. for _, v := range shopList {
  664. this.dumpShopItem(v)
  665. }
  666. }
  667. } else {
  668. shopList := this.getShopList(0, shopType)
  669. for _, v := range shopList {
  670. this.dumpShopItem(v)
  671. }
  672. }
  673. }
  674. func (this *shopmgr) dumpShopItem(si *Shop_Item) {
  675. price := fmt.Sprintf("%v", si.Price)
  676. showPrice := fmt.Sprintf("%v", si.ShowPrice)
  677. /*if si.PayType == PayType_RMB {
  678. this.lock.RLock()
  679. for _, v := range this.exchangeRateList {
  680. if price == "" {
  681. price = fmt.Sprintf("%s[%.1f]", v.Currency, v.Rate*si.Price)
  682. showPrice = fmt.Sprintf("%s[%.1f]", v.Currency, v.Rate*si.ShowPrice)
  683. } else {
  684. price = fmt.Sprintf("%s,%s[%.1f]", price, v.Currency, v.Rate*si.Price)
  685. showPrice = fmt.Sprintf("%s,%s[%.1f]", showPrice, v.Currency, v.Rate*si.ShowPrice)
  686. }
  687. }
  688. this.lock.RUnlock()
  689. }*/
  690. log.Release(" ProductId[%s],Name[%s],Price[%.1f],PayType[%d],ShopType[%d],IsHot[%d],Bonus[%d],Items:%v",
  691. si.ProductId, si.ProductName, si.Price, si.PayType, si.ShopType, si.IsHot, si.Bonus, si.Extra)
  692. log.Release(" Price:[%s],ShowPrice[%s]", price, showPrice)
  693. log.Release("")
  694. }