BuyLogic.lua 16 KB

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