ApiLogic.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. local LuaMongo = _G.lua_mongo
  2. local Config = require("Config")
  3. local Log = require("common.Log")
  4. local Util = require("common.Util")
  5. local Log = require("common.Log")
  6. local ObjHuman = require("core.ObjHuman")
  7. local BuyLogic = require("topup.BuyLogic")
  8. local RoleDBLogic = require("role.RoleDBLogic")
  9. local ReportManager = require("platform.ReportManager")
  10. local Lang = require("common.Lang")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local BuyExcel = require("excel.buy").buy
  13. local Msg = require("core.Msg")
  14. --[[
  15. result:
  16. 1:充值成功
  17. 2:用户不存在
  18. 3:验证错误
  19. 4:订单号已存在
  20. 5:参数有错
  21. 6:参数不全
  22. 7:请求过时
  23. 8:其他原因
  24. --]]
  25. DAY_PAY_NONAGE_1 = 50
  26. DAY_PAY_NONAGE_2 = 100
  27. MONTH_PAY_NONAGE_1 = 200
  28. MONTH_PAY_NONAGE_2 = 400
  29. DELIVER_CODE_HIS = DELIVER_CODE_HIS or {}
  30. function deliver(oJsonInput,ret)
  31. --oJsonInput.type = tonumber(oJsonInput.type)
  32. oJsonInput.id = tonumber(oJsonInput.id)
  33. oJsonInput.buyID = oJsonInput.buyID or oJsonInput.id
  34. oJsonInput.cnt = tonumber(oJsonInput.cnt)
  35. oJsonInput.money = tonumber(oJsonInput.money)
  36. oJsonInput.price = oJsonInput.money
  37. ret.account = oJsonInput.account
  38. ret.serverTag = oJsonInput.serverTag
  39. ret.order = oJsonInput.order
  40. --ret.type = oJsonInput.type
  41. ret.id = oJsonInput.id
  42. ret.buyID = ret.buyID or ret.id
  43. ret.cnt = oJsonInput.cnt
  44. ret.money = oJsonInput.money
  45. ret.price = oJsonInput.price
  46. --ret.region = oJsonInput.region
  47. ret.err = ""
  48. if not (ret.account and ret.order and ret.id and ret.cnt and ret.serverTag and oJsonInput.channelID) then -- and ret.type and ret.region
  49. ret.result = 6
  50. ret.err = "param empty"
  51. return ret
  52. end
  53. if DELIVER_CODE_HIS[oJsonInput.order] then
  54. ret.result = 4
  55. ret.err = "order double"
  56. return ret
  57. end
  58. DELIVER_CODE_HIS[oJsonInput.order] = os.time()
  59. -- local human = ObjHuman.onlineAccount[ret.account]
  60. local uTag = RoleDBLogic.Generateuuid(oJsonInput.channelID, ret.account, ret.serverTag)
  61. local human = ObjHuman.onlineNewUniqueTag[uTag]
  62. local online = true
  63. if not human then
  64. local humanDb = RoleDBLogic.loadRole(uTag)
  65. human = {}
  66. human.db = humanDb
  67. online = false
  68. if not humanDb then
  69. ret.result = 2
  70. ret.err = "account not exist"
  71. return ret
  72. end
  73. end
  74. if not BuyLogic.checkBuy(human,ret) then
  75. ret.result = 8
  76. ret.err = "check buy fail"
  77. return ret
  78. end
  79. oJsonInput.cmd = "deliver"
  80. if online and human.db.middleFlag == nil then
  81. if Config.IS_DEBUG then
  82. BuyLogic.buy(human,ret)
  83. else
  84. local pcallRet, pcallErr = pcall(BuyLogic.buy, human,ret)
  85. if not pcallRet then
  86. --Log.write(Log.LOGID_ERR_PCALL, "BuyLogic.buy err=" .. human.db.account, pcallErr)
  87. Log.write(Log.LOGID_ERR_PCALL, "BuyLogic.buy err=" .. human.db.newUniqueTag, pcallErr)
  88. ret.result = -1
  89. ret.err = pcallErr
  90. return Broadcast.sendErr(human, "BuyLogic.buy "..Lang.PCALL_ERR)
  91. end
  92. end
  93. else
  94. human.db.buyOrder = human.db.buyOrder or {}
  95. human.db.buyOrder[#human.db.buyOrder + 1] = Util.copyTable(oJsonInput)
  96. end
  97. RoleDBLogic.saveRole(human.db)
  98. ret.result = 1
  99. --Log.write(Log.LOGID_OSS_DELIVER, human.db._id, human.db.account, human.db.name, human.db.lv,oJsonInput.order,oJsonInput.money,oJsonInput.type,oJsonInput.id,oJsonInput.cnt,online and 1 or 0,oJsonInput.region)
  100. Log.write(Log.LOGID_OSS_DELIVER, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv,oJsonInput.order,oJsonInput.money,oJsonInput.type,oJsonInput.id,oJsonInput.cnt,online and 1 or 0,oJsonInput.region)
  101. return ret
  102. end
  103. --[[
  104. 1:充值成功
  105. 2:用户不存在
  106. 3:验证错误
  107. 4:订单号已存在
  108. 5:充值元宝数量有错
  109. 6:参数不全
  110. 7:请求过时
  111. 8:参数错误
  112. -1:未知错误
  113. --]]
  114. CHARGE_CODE_HIS = CHARGE_CODE_HIS or {}
  115. --如果后续用到该接口时,需要参照deliver修改用到account的地方
  116. function charge(oJsonInput,ret)
  117. oJsonInput.gold = tonumber(oJsonInput.gold)
  118. oJsonInput.money = tonumber(oJsonInput.money)
  119. oJsonInput.buyID = tonumber(oJsonInput.buyID)
  120. ret.account = oJsonInput.account
  121. ret.order = oJsonInput.order
  122. ret.gold = oJsonInput.gold
  123. ret.money = oJsonInput.money
  124. ret.region = oJsonInput.region
  125. ret.appid = oJsonInput.appid or ""
  126. ret.err = ""
  127. if not (ret.account and ret.order and ret.gold and ret.money and ret.region) then
  128. ret.result = 6
  129. ret.err = "param empty"
  130. return
  131. end
  132. if CHARGE_CODE_HIS[oJsonInput.order] then
  133. ret.result = 4
  134. ret.err = "order double"
  135. return
  136. end
  137. local human = ObjHuman.onlineAccount[ret.account]
  138. local online = true
  139. if not human then
  140. local humanDb = RoleDBLogic.loadRole(oJsonInput.account)
  141. human = {}
  142. human.db = humanDb
  143. online = false
  144. if not humanDb then
  145. ret.result = 2
  146. ret.err = "account not exist"
  147. return
  148. end
  149. end
  150. local topupMoney = 0
  151. local buyConf = oJsonInput.buyID and BuyExcel[oJsonInput.buyID]
  152. if oJsonInput.buyID == 3 then
  153. if human.db.fundFlag ~= nil then
  154. ret.result = 5
  155. ret.err = "funds cannot be bought multiple times"
  156. return
  157. end
  158. end
  159. if not BuyLogic.isArgOK(human,oJsonInput.buyID,ret.region,ret.money) then
  160. ret.result = 5
  161. ret.err = "money not fix config"
  162. return
  163. end
  164. CHARGE_CODE_HIS[oJsonInput.order] = os.time()
  165. oJsonInput.cmd = "charge"
  166. local price = 0
  167. if ret.money ~= 0 then
  168. price = ret.money
  169. else
  170. price = buyConf["CN"][1]
  171. end
  172. oJsonInput.topupMoney = price
  173. human.db.buyHis = human.db.buyHis or {}
  174. human.db.buyHis[#human.db.buyHis + 1] = {buyID = oJsonInput.buyID or 0,money = ret.money,gold = ret.gold,upTime = os.time()}
  175. if online and human.db.middleFlag == nil then
  176. if Config.IS_DEBUG then
  177. BuyLogic.charge(human,oJsonInput)
  178. else
  179. local pcallRet, pcallErr = pcall(BuyLogic.charge, human,oJsonInput)
  180. if not pcallRet then
  181. Log.write(Log.LOGID_ERR_PCALL, "BuyLogic.charge err=" .. human.db.account, pcallErr)
  182. ret.result = -1
  183. ret.err = pcallErr
  184. return Broadcast.sendErr(human, "BuyLogic.charge "..Lang.PCALL_ERR)
  185. end
  186. end
  187. else
  188. human.db.buyOrder = human.db.buyOrder or {}
  189. human.db.buyOrder[#human.db.buyOrder + 1] = Util.copyTable(oJsonInput)
  190. end
  191. RoleDBLogic.saveRole(human.db)
  192. ret.result = 1
  193. if ret.order ~= 'transaction_id1' then
  194. Log.write(Log.LOGID_OSS_PAY, human.db._id, human.db.account, human.db.name, human.db.lv,ret.order,oJsonInput.buyID or 0,oJsonInput.amt or ret.money,ret.gold,online and 1 or 0,ret.region)
  195. end
  196. local orderExt = {['orderID'] = oJsonInput.order, ['amount'] = oJsonInput.money}
  197. if oJsonInput.ext then
  198. local extData = Json.Decode(oJsonInput.ext)
  199. orderExt.OrderNO = extData.OrderNO
  200. orderExt.GoodsCode = extData.GoodsCode
  201. end
  202. orderExt.PayPurchaseType = buyConf.cmd == "topup" and 0 or 3
  203. orderExt.ItemCode = oJsonInput.buyID
  204. orderExt.ItemName = buyConf.name
  205. orderExt.Amount = 1
  206. orderExt.CurrencyCode = "KRW"
  207. orderExt.TotalPrice = oJsonInput.money
  208. orderExt.PayToolCode = 1
  209. orderExt.ReceiveMemberID = oJsonInput.account
  210. orderExt.Balance = human.db.zuanshi
  211. orderExt.PayResultType = 1
  212. orderExt.PayResultMessage = "success"
  213. ReportManager.charge(human, orderExt)
  214. end