BuyLogic.lua 17 KB

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