BuyLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. -----------------------------------------
  2. -- 直购
  3. -----------------------------------------
  4. local BuyExcel = require("excel.buy").buy
  5. local TopupExcel = require("excel.buy").topup
  6. local presentExcel = require("excel.present")
  7. local Log = require("common.Log")
  8. local Lang = require("common.Lang")
  9. local Msg = require("core.Msg")
  10. local ObjHuman = require("core.ObjHuman")
  11. local BagLogic = require("bag.BagLogic")
  12. local FcmLogic = require("fcm.FcmLogic")
  13. local PfLogic = require("platform.PfLogic")
  14. local FundLogic = require("present.FundLogic")
  15. local DailyLibaoLogic = require("present.DailyLibaoLogic")
  16. local RichangLibaoLogic = require("present.RichangLibaoLogic")
  17. local TequanShopLogic = require("present.TequanShopLogic")
  18. local TopupLogic = require("topup.TopupLogic")
  19. local VipLogic = require("vip.VipLogic")
  20. local SceneHandler = require("scene.Handler")
  21. local UnionRedBagLogic = require("union.UnionRedBagLogic")
  22. local LimitBuy = require("present.LimitBuy")
  23. local ActCustomizeLogic = require("present.ActCustomizeLogic")
  24. local OpenServerGiftLogic = require("present.OpenServerGiftLogic")
  25. local MonthCard = require("present.MonthCard")
  26. local GiftPackLogic = require("present.GiftPackLogic")
  27. local PremiumGiftLogic = require("absAct.PremiumGiftLogic")
  28. local LimitMangHeLogic = require("present.LimitMangHeLogic")
  29. local Broadcast = require("broadcast.Broadcast")
  30. local MangHeLogic = require("absAct.MangHeLogic")
  31. local HeroGrowUp = require("absAct.HeroGrowUp")
  32. local ItemDefine = require("bag.ItemDefine")
  33. local OverflowFundLogic = require("present.OverflowFundLogic")
  34. local AbsWeeklyCardLogic = require("absAct.AbsWeeklyCardLogic")
  35. local YunYingLogic = require("yunying.YunYingLogic")
  36. local DoubleChargeLogic = require("absAct.DoubleChargeLogic")
  37. local MoshouLogic = require("moshou.MoshouLogic")
  38. local HeroSkinLogic = require("present.HeroSkinLogic")
  39. BUY_CODE_NORMAL = 0 -- 正常调平台的充值接口
  40. BUY_CODE_WX_KEFU = 1 -- 微信小程序客服充值接口
  41. cmd = {}
  42. function initAfterHot()
  43. BuyExcel = require("excel.buy").buy
  44. TopupExcel = require("excel.buy").topup
  45. end
  46. -- 是否首次购买
  47. function getIsFirst(human,id)
  48. if not human.db.buy or
  49. not human.db.buy[id] then
  50. return true
  51. end
  52. end
  53. -- 购买次数
  54. function getBuyCnt(human,id)
  55. if not human.db.buy or
  56. not human.db.buy[id] then
  57. return 0
  58. end
  59. local cnt = human.db.buy[id].cnt or 0
  60. return cnt
  61. end
  62. -- 双倍购买次数
  63. function getDoubleBuyCnt(human,id)
  64. if not human.db.buy or
  65. not human.db.buy[id] then
  66. return 0
  67. end
  68. local cnt = human.db.buy[id].doubleCnt or 0
  69. return cnt
  70. end
  71. -- 真实价格 某些商品首次购买比较便宜
  72. function getRealPrice(human, buyID, region)
  73. region = human.region or "CN"
  74. local buyConf = BuyExcel[buyID]
  75. if not buyConf then return 0 end
  76. return buyConf[region]
  77. end
  78. -- 封装BuyItem结构体
  79. function fontBuyItem(human, net, buyID)
  80. local conf = BuyExcel[buyID]
  81. net.buyID = buyID
  82. local region = human.region or "CN"
  83. net.region = region
  84. net.cost = getRealPrice(human, buyID, region)
  85. net.icon = conf.icon
  86. net.name = conf.name
  87. net.isFirst = getIsFirst(human, buyID) and 1 or 0
  88. local giveZuanshi = tonumber(conf.desc)
  89. if giveZuanshi then
  90. if net.isFirst == 1 then
  91. net.desc = tostring(giveZuanshi * 3)
  92. else
  93. net.desc = tostring(giveZuanshi)
  94. end
  95. else
  96. net.desc = conf.desc
  97. end
  98. net.doubleCnt = conf.doubleCnt
  99. local actDouble = YunYingLogic.onCallBack(human,"getDoubleCnt", buyID, true)
  100. net.actDoubleCnt = actDouble or 0
  101. net.useDoubleCnt = getDoubleBuyCnt(human, buyID)
  102. net.buyCnt = getBuyCnt(human, buyID)
  103. net.vipExp = conf.vipExp
  104. net.yuanjia = conf.oCN
  105. net.zhekou = conf.zhekou
  106. end
  107. -------------------------------- cmd开始 ----------------------------------
  108. -- 充值-元宝
  109. function cmd.topup(human, buyConf, isFirst, buyCnt)
  110. local args = buyConf.args
  111. local id = args[1]
  112. local config = TopupExcel[id]
  113. local cnt = config.cnt * 2
  114. local doubleCnt = buyConf.doubleCnt
  115. local actDouble = YunYingLogic.onCallBack(human,"getDoubleCnt", config.buyID, true)
  116. if actDouble > 0 then
  117. YunYingLogic.onCallBack(human,"buyCall",config.buyID)
  118. cnt = cnt * 2
  119. else
  120. YunYingLogic.onCallBack(human,"touchSingleReach",config.buyID)
  121. --首冲双倍
  122. if buyCnt < doubleCnt then
  123. cnt = cnt * 2
  124. human.db.buy[config.buyID].doubleCnt = human.db.buy[config.buyID].doubleCnt + 1
  125. end
  126. end
  127. ObjHuman.addZuanshi(human, cnt, "buyTopup")
  128. BagLogic.sendItemGetList(human, {{ItemDefine.ITEM_ZUANSHI_ID, cnt}}, "buyTopup")
  129. TopupLogic.query(human)
  130. end
  131. -- 充值-每日礼包
  132. function cmd.dailyLibao(human, buyConf)
  133. local id = buyConf.args[1]
  134. DailyLibaoLogic.buyLibao(human, id)
  135. end
  136. -- 充值-每周礼包
  137. function cmd.weekLibao(human, buyConf)
  138. local id = buyConf.args[1]
  139. RichangLibaoLogic.buyLibao(human, RichangLibaoLogic.LIBAOTYPE_WEEK, id, RichangLibaoLogic.RMB_BUY)
  140. end
  141. -- 充值-每月礼包
  142. function cmd.monthLibao(human, buyConf)
  143. local id = buyConf.args[1]
  144. RichangLibaoLogic.buyLibao(human, RichangLibaoLogic.LIBAOTYPE_MONTH, id, RichangLibaoLogic.RMB_BUY)
  145. end
  146. -- 成长礼包
  147. function cmd.giftPack(human, buyConf)
  148. local id = buyConf.args[1]
  149. GiftPackLogic.buyLibao(human, id)
  150. end
  151. -- 充值-特权商店
  152. function cmd.tequanShop(human, buyConf)
  153. local id = buyConf.args[1]
  154. TequanShopLogic.buyLibao(human, id, TequanShopLogic.COST_RMB)
  155. end
  156. -- 发公会红包
  157. function cmd.unionRedbag(human,buyConf)
  158. UnionRedBagLogic.sendRedBagCallBack(human,buyConf.args[1])
  159. end
  160. -- 限时抢购
  161. function cmd.limitBuy(human, buyConf)
  162. LimitBuy.buy(human, buyConf.args[1])
  163. end
  164. function cmd.customize(human,buyConf)
  165. ActCustomizeLogic.onBuyCustomize(human,buyConf.args[1])
  166. end
  167. -- 开服好礼
  168. function cmd.openServer(human,buyConf)
  169. OpenServerGiftLogic.buyGift(human,buyConf.args[1])
  170. end
  171. -- 月卡
  172. function cmd.monthCard(human,buyConf)
  173. MonthCard.buyMonthCard(human,buyConf.args[1])
  174. end
  175. --
  176. function cmd.heroGrowUp(human, buyConf)
  177. HeroGrowUp.buyKing(human)
  178. end
  179. function cmd.limitMangHe(human, buyConf)
  180. LimitMangHeLogic.buy(human, buyConf.id)
  181. end
  182. function cmd.overflowFund(human,buyConf)
  183. OverflowFundLogic.onBuy(human,buyConf.args[1])
  184. end
  185. function cmd.xiLianGift(human, buyConf)
  186. MoshouLogic.xlianGiftBuy(human, buyConf.id)
  187. end
  188. function cmd.heroSkin(human,buyConf)
  189. local buyId = buyConf.id
  190. return HeroSkinLogic.buy(human,buyId)
  191. end
  192. -------------------------------- cmd结束 ----------------------------------
  193. function checkBuy(human, ret)
  194. local buyID = ret.id
  195. local buyConf = BuyExcel[buyID]
  196. if buyConf then
  197. return true
  198. end
  199. ret.result = 8
  200. ret.err = buyID..":buy config not exist"
  201. end
  202. function isArgOK(human,buyID,region,money)
  203. local buyConf = BuyExcel[buyID]
  204. if not (buyConf and buyConf[region]) then
  205. return
  206. end
  207. --海外微端统计,会传转换后的美元值,增加多一层判断
  208. if PfLogic.isHaiwaiWeiduan(human) then
  209. if money == buyConf["US"] then
  210. return true
  211. end
  212. end
  213. local checkMoney = getRealPrice(human, buyID, region)
  214. if money ~= checkMoney then
  215. return
  216. end
  217. return true
  218. end
  219. --直购
  220. function buy(human, arg, nolog)
  221. local buyID
  222. if type(arg) == "table" then
  223. buyID = arg.buyID
  224. else
  225. buyID = arg
  226. end
  227. local buyConf = BuyExcel[buyID]
  228. local isFirst = getIsFirst(human, buyID)
  229. local cnt = getBuyCnt(human, buyID)
  230. local buyDB = human.db.buy
  231. buyDB[buyID] = buyDB[buyID] or {upTime = {}, cnt=0}
  232. buyDB[buyID].upTime[#buyDB[buyID].upTime + 1] = os.time()
  233. buyDB[buyID].cnt = buyDB[buyID].cnt or 0
  234. buyDB[buyID].cnt = buyDB[buyID].cnt + 1
  235. buyDB[buyID].doubleCnt = buyDB[buyID].doubleCnt or 0
  236. if cmd[buyConf.cmd] then
  237. cmd[buyConf.cmd](human, buyConf, isFirst, buyDB[buyID].doubleCnt)
  238. else
  239. YunYingLogic.onBuy(human, buyConf, isFirst, cnt)
  240. end
  241. -- 增加VIP经验
  242. if buyConf.vipExp > 0 then
  243. VipLogic.addExp(human, buyConf.vipExp)
  244. end
  245. if not nolog and type(arg) == "table" and arg.order ~= "transaction_id1"then
  246. Log.write(Log.LOGID_OSS_PAY, human.db._id, human.db.account, human.db.name, human.db.lv,arg.order or "" ,buyID or 0,arg.amt or arg.money or 0,arg.gold or 0,2,arg.region or "")
  247. end
  248. if type(arg) == "table" then
  249. afterCharge(human, arg, buyID, buyConf)
  250. end
  251. end
  252. function afterCharge(human,oJsonInput, buyID, buyConf)
  253. --local price = oJsonInput.topupMoney
  254. local buyConf = BuyExcel[buyID]
  255. local price = oJsonInput.price or buyConf.CN
  256. if price and price > 0 then
  257. TopupLogic.clacTopupAcount(human, price, buyID)
  258. local msgRet = Msg.gc.GC_NOTICE_DADIAN
  259. msgRet.type = 1
  260. msgRet.param = oJsonInput.price * 100
  261. msgRet.param2 = tonumber(oJsonInput.buyID)
  262. Msg.send(msgRet,human.fd)
  263. end
  264. end
  265. --直充
  266. function charge(human,oJsonInput)
  267. local gold = oJsonInput.gold
  268. local money = oJsonInput.money
  269. local region = oJsonInput.region
  270. local buyID = oJsonInput.buyID
  271. if buyID and BuyExcel[buyID] then
  272. oJsonInput.id = buyID
  273. buy(human,oJsonInput,true)
  274. else
  275. --直充档次表没有对应配置的话直接给请求中要求的元宝
  276. ObjHuman.addZuanshi(human, gold, "buyTopup")
  277. end
  278. if oJsonInput.order ~= 'transaction_id1' then
  279. Log.write(Log.LOGID_OSS_PAY, human.db._id, human.db.account, human.db.name, human.db.lv,oJsonInput.order,buyID or 0,oJsonInput.amt or oJsonInput.money,oJsonInput.gold,2,oJsonInput.region)
  280. end
  281. end
  282. function onLogin(human)
  283. if not human.db.buyOrder then return end
  284. for k,v in ipairs(human.db.buyOrder) do
  285. if v.cmd == "charge" then
  286. buy(human,v)
  287. elseif v.cmd == "deliver" then
  288. charge(human,v)
  289. end
  290. end
  291. human.db.buyOrder = nil
  292. end
  293. -- 判断能不能直购
  294. function checkCanBuy(human, buyID)
  295. local buyConf = BuyExcel[buyID]
  296. if not buyConf then return end
  297. local price = getRealPrice(human, buyID, "CN")
  298. if price and not FcmLogic.checkCanBuy(human, price) then
  299. return
  300. end
  301. if SceneHandler.canCharge(human) ~= true then
  302. return Broadcast.sendErr(human, Lang.CHARGE_CLOSE_TIP)
  303. end
  304. local msgRet = Msg.gc.GC_BUY_CHECK
  305. msgRet.buyCode = BUY_CODE_NORMAL
  306. if PfLogic.isFKW(human) then
  307. -- 方块玩微信小程序的正式服 ios下走客服充值
  308. if human.isIOS == 1 then
  309. msgRet.buyCode = BUY_CODE_WX_KEFU
  310. end
  311. elseif PfLogic.isKunTang(human) then
  312. -- 坤堂微信小程序的正式服 ios和安卓都走客服充值
  313. msgRet.buyCode = BUY_CODE_WX_KEFU
  314. end
  315. fontBuyItem(human, msgRet.buyItem, buyID)
  316. Msg.send(msgRet, human.fd)
  317. end