BuyLogic.lua 11 KB

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