BuyLogic.lua 16 KB

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