BuyLogic.lua 17 KB

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