pay.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --[[
  2. Descripttion:支付统计
  3. version:
  4. Author: Neo,Huang
  5. Date: 2023-11-15 22:34:35
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2023-11-15 23:57:03
  8. --]]
  9. local code = require("code")
  10. local gameConst = require("const.gameConst")
  11. local util_user = require("utils.util_user")
  12. local shopAdapt = require("adapt.shopAdapt")
  13. local payData = require("data.pay")
  14. local bagData = require("data.bag")
  15. local root = class("pay", require("base.baseModule"))
  16. function root:ctor(uid)
  17. root.super.ctor(self, uid, "pay", "uid", true)
  18. self.uid = uid
  19. end
  20. function root:mysql_get_init_columns()
  21. return {
  22. uid = "int(11) NOT NULL COMMENT '用户id'",
  23. totalAmount = "int(10) DEFAULT NULL COMMENT '总支付金额(单位分)'",
  24. goodsList = "JSON COMMENT '支付商品信息列表'",
  25. dayInfo = "JSON COMMENT '当天支付商品信息'",
  26. goodsPreCustomItems = "JSON COMMENT '定制商品信息列表'",
  27. goodsPayCustomItems = "JSON COMMENT '定制商品信息列表'"
  28. }
  29. end
  30. -- 发放商品物品
  31. function root:dispatch_goods_items(role, gid)
  32. local uid = self.uid
  33. local conf = gid and shopAdapt:goods_get_info(gid)
  34. if not conf then
  35. return code.PARAMTER_ERROR
  36. end
  37. -- 获取物品
  38. local eventId = string.format("shop-pay-%s", tostring(gid))
  39. local items = payData:get_goods_pre_custom_items(uid, gid) or conf.items
  40. bagData:add_items(uid, items, eventId)
  41. -- 定制信息
  42. if payData:del_goods_pre_custom_items(uid, gid) then
  43. payData:update_goods_pay_custom_items(uid, gid, items)
  44. end
  45. -- 通知前端 - 商品发货
  46. local pack = {goodsId = gid, items = items}
  47. util_user:user_proto_notify(uid, "on_shop_buy_goods", pack)
  48. -- 事件
  49. local evtParams = {
  50. times = 1,
  51. gid = gid
  52. }
  53. evtParams.isFirstPay = payData:is_first_pay(uid)
  54. evtParams.isGoodsFirstPay = payData:is_goods_first_pay(uid, gid)
  55. if not is_empty(conf.rmb) then
  56. payData:user_add_pay(uid, gid, conf.rmb)
  57. evtParams.amount = conf.rmb
  58. evtParams.totalAmount = self:redis_get_key_info("totalAmount")
  59. end
  60. util_user:user_dispatch_event(uid, gameConst.EVENT_ID.PAY, evtParams)
  61. util_user:user_proto_notify(uid, "on_shop_pay_info", {payInfo = payData:pack_pay_info(uid)})
  62. return code.OK, {items = items}
  63. end
  64. return root