pay.lua 2.1 KB

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