BuyLogic.lua 13 KB

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