BuyLogic.lua 13 KB

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