BuyLogic.lua 16 KB

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