BuyLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 MaiDianDefine = require("MaiDian.MaiDianDefine")
  44. local MainDianLogic = require("MaiDian.MaiDianLogic")
  45. BUY_CODE_NORMAL = 0 -- 正常调平台的充值接口
  46. BUY_CODE_WX_KEFU = 1 -- 微信小程序客服充值接口
  47. cmd = {}
  48. function initAfterHot()
  49. BuyExcel = require("excel.buy").buy
  50. TopupExcel = require("excel.buy").topup
  51. end
  52. local function GetFirstMark(human)
  53. if not human.db.nFirstBuy then
  54. human.db.nFirstBuy = 0
  55. return false
  56. end
  57. return human.db.nFirstBuy == 0 and false or true
  58. end
  59. local function SetFirstMark(human, nValue)
  60. human.db.nFirstBuy = nValue
  61. end
  62. -- 是否首次购买
  63. function getIsFirst(human,id)
  64. if not human.db.buy or
  65. not human.db.buy[id] then
  66. return true
  67. end
  68. end
  69. -- 购买次数
  70. function getBuyCnt(human,id)
  71. if not human.db.buy or
  72. not human.db.buy[id] then
  73. return 0
  74. end
  75. local cnt = human.db.buy[id].cnt or 0
  76. return cnt
  77. end
  78. -- 双倍购买次数
  79. function getDoubleBuyCnt(human,id)
  80. if not human.db.buy or
  81. not human.db.buy[id] then
  82. return 0
  83. end
  84. local cnt = human.db.buy[id].doubleCnt or 0
  85. return cnt
  86. end
  87. -- 真实价格 某些商品首次购买比较便宜
  88. function getRealPrice(human, buyID, region)
  89. region = human.region or "CN"
  90. local buyConf = BuyExcel[buyID]
  91. if not buyConf then return 0 end
  92. return buyConf[region]
  93. end
  94. -- 封装BuyItem结构体
  95. function fontBuyItem(human, net, buyID)
  96. local conf = BuyExcel[buyID]
  97. net.buyID = buyID
  98. local region = human.region or "CN"
  99. net.region = region
  100. net.cost = getRealPrice(human, buyID, region)
  101. net.icon = conf.icon
  102. net.name = conf.name
  103. net.isFirst = getIsFirst(human, buyID) and 1 or 0
  104. local giveZuanshi = tonumber(conf.desc)
  105. if giveZuanshi then
  106. if net.isFirst == 1 then
  107. net.desc = tostring(giveZuanshi * 3)
  108. else
  109. net.desc = tostring(giveZuanshi)
  110. end
  111. else
  112. net.desc = conf.desc
  113. end
  114. net.doubleCnt = conf.doubleCnt
  115. local actDouble = YunYingLogic.onCallBack(human,"getDoubleCnt", buyID, true)
  116. net.actDoubleCnt = actDouble or 0
  117. net.useDoubleCnt = getDoubleBuyCnt(human, buyID)
  118. net.buyCnt = getBuyCnt(human, buyID)
  119. net.vipExp = conf.vipExp
  120. net.yuanjia = conf.oCN
  121. net.zhekou = conf.zhekou
  122. end
  123. -------------------------------- cmd开始 ----------------------------------
  124. -- 充值-元宝
  125. function cmd.topup(human, buyConf, isFirst, buyCnt)
  126. local args = buyConf.args
  127. local id = args[1]
  128. local config = TopupExcel[id]
  129. local cnt = config.cnt * 2
  130. local doubleCnt = buyConf.doubleCnt
  131. local actDouble = YunYingLogic.onCallBack(human,"getDoubleCnt", config.buyID, true)
  132. if actDouble > 0 then
  133. YunYingLogic.onCallBack(human,"buyCall",config.buyID)
  134. cnt = cnt * 2
  135. else
  136. YunYingLogic.onCallBack(human,"touchSingleReach",config.buyID)
  137. --首冲双倍
  138. if buyCnt < doubleCnt then
  139. cnt = cnt * 2
  140. human.db.buy[config.buyID].doubleCnt = human.db.buy[config.buyID].doubleCnt + 1
  141. end
  142. end
  143. ObjHuman.addZuanshi(human, cnt, "buyTopup")
  144. BagLogic.sendItemGetList(human, {{ItemDefine.ITEM_ZUANSHI_ID, cnt}}, "buyTopup")
  145. TopupLogic.query(human)
  146. end
  147. -- 充值-每日礼包
  148. function cmd.dailyLibao(human, buyConf)
  149. local id = buyConf.args[1]
  150. DailyLibaoLogic.buyLibao(human, id)
  151. end
  152. -- 充值-每周礼包
  153. function cmd.weekLibao(human, buyConf)
  154. local id = buyConf.args[1]
  155. RichangLibaoLogic.buyLibao(human, RichangLibaoLogic.LIBAOTYPE_WEEK, id, RichangLibaoLogic.RMB_BUY)
  156. end
  157. -- 充值-每月礼包
  158. function cmd.monthLibao(human, buyConf)
  159. local id = buyConf.args[1]
  160. RichangLibaoLogic.buyLibao(human, RichangLibaoLogic.LIBAOTYPE_MONTH, id, RichangLibaoLogic.RMB_BUY)
  161. end
  162. -- 成长礼包
  163. function cmd.giftPack(human, buyConf)
  164. local id = buyConf.args[1]
  165. GiftPackLogic.buyLibao(human, id)
  166. end
  167. -- 充值-特权商店
  168. function cmd.tequanShop(human, buyConf)
  169. local id = buyConf.args[1]
  170. TequanShopLogic.buyLibao(human, id, TequanShopLogic.COST_RMB)
  171. end
  172. -- 发公会红包
  173. function cmd.unionRedbag(human,buyConf)
  174. UnionRedBagLogic.sendRedBagCallBack(human,buyConf.args[1])
  175. end
  176. -- 限时抢购
  177. function cmd.limitBuy(human, buyConf)
  178. LimitBuy.buy(human, buyConf.args[1])
  179. end
  180. function cmd.customize(human,buyConf)
  181. ActCustomizeLogic.onBuyCustomize(human,buyConf.args[1])
  182. end
  183. -- 开服好礼
  184. function cmd.openServer(human,buyConf)
  185. OpenServerGiftLogic.buyGift(human,buyConf.args[1])
  186. end
  187. -- 月卡
  188. function cmd.monthCard(human,buyConf)
  189. MonthCard.buyMonthCard(human,buyConf.args[1])
  190. end
  191. --
  192. function cmd.heroGrowUp(human, buyConf)
  193. HeroGrowUp.buyKing(human)
  194. end
  195. function cmd.limitMangHe(human, buyConf)
  196. LimitMangHeLogic.buy(human, buyConf.id)
  197. end
  198. function cmd.overflowFund(human,buyConf)
  199. OverflowFundLogic.onBuy(human,buyConf.args[1])
  200. end
  201. function cmd.xiLianGift(human, buyConf)
  202. MoshouLogic.xlianGiftBuy(human, buyConf.id)
  203. end
  204. function cmd.heroSkin(human,buyConf)
  205. local buyId = buyConf.id
  206. return HeroSkinLogic.buy(human,buyId)
  207. end
  208. function cmd.gift(human,buyConf)
  209. local buyId = buyConf.id
  210. for id,cfg in pairs(GiftExcel) do
  211. if cfg.buyID == buyId then
  212. GiftLogic.buy(human,id)
  213. break
  214. end
  215. end
  216. end
  217. function cmd.warOrder(human,buyConf)
  218. local buyId = buyConf.id
  219. for _,cfg in pairs(OrderExcel.desc) do
  220. if cfg.buyId == buyId then
  221. WarOrderLogic.warOrderUnlock(human,cfg.type)
  222. break
  223. end
  224. end
  225. end
  226. -------------------------------- cmd结束 ----------------------------------
  227. function checkBuy(human, ret)
  228. local buyID = ret.id
  229. local buyConf = BuyExcel[buyID]
  230. if buyConf then
  231. return true
  232. end
  233. ret.result = 8
  234. ret.err = buyID..":buy config not exist"
  235. end
  236. function isArgOK(human,buyID,region,money)
  237. local buyConf = BuyExcel[buyID]
  238. if not (buyConf and buyConf[region]) then
  239. return
  240. end
  241. --海外微端统计,会传转换后的美元值,增加多一层判断
  242. if PfLogic.isHaiwaiWeiduan(human) then
  243. if money == buyConf["US"] then
  244. return true
  245. end
  246. end
  247. local checkMoney = getRealPrice(human, buyID, region)
  248. if money ~= checkMoney then
  249. return
  250. end
  251. return true
  252. end
  253. --直购
  254. function buy(human, arg, nolog)
  255. local buyID
  256. if type(arg) == "table" then
  257. buyID = arg.buyID
  258. else
  259. buyID = arg
  260. end
  261. local buyConf = BuyExcel[buyID]
  262. local isFirst = getIsFirst(human, buyID)
  263. local cnt = getBuyCnt(human, buyID)
  264. local buyDB = human.db.buy
  265. buyDB[buyID] = buyDB[buyID] or {upTime = {}, cnt=0}
  266. buyDB[buyID].upTime[#buyDB[buyID].upTime + 1] = os.time()
  267. buyDB[buyID].cnt = buyDB[buyID].cnt or 0
  268. buyDB[buyID].cnt = buyDB[buyID].cnt + 1
  269. buyDB[buyID].doubleCnt = buyDB[buyID].doubleCnt or 0
  270. if cmd[buyConf.cmd] then
  271. cmd[buyConf.cmd](human, buyConf, isFirst, buyDB[buyID].doubleCnt)
  272. else
  273. YunYingLogic.onBuy(human, buyConf, isFirst, cnt)
  274. end
  275. -- 增加VIP经验
  276. if buyConf.vipExp > 0 then
  277. VipLogic.addExp(human, buyConf.vipExp)
  278. end
  279. if not nolog and type(arg) == "table" and arg.order ~= "transaction_id1"then
  280. 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 "")
  281. end
  282. if type(arg) == "table" then
  283. afterCharge(human, arg, buyID, buyConf)
  284. end
  285. if false == GetFirstMark(human) then
  286. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_BUY, {nValue = buyID})
  287. SetFirstMark(human, 1)
  288. end
  289. end
  290. function afterCharge(human,oJsonInput, buyID, buyConf)
  291. --local price = oJsonInput.topupMoney
  292. local buyConf = BuyExcel[buyID]
  293. local price = oJsonInput.price or buyConf.CN
  294. if price and price > 0 then
  295. TopupLogic.clacTopupAcount(human, price, buyID)
  296. local msgRet = Msg.gc.GC_NOTICE_DADIAN
  297. msgRet.type = 1
  298. msgRet.param = oJsonInput.price * 100
  299. msgRet.param2 = tonumber(oJsonInput.buyID)
  300. Msg.send(msgRet,human.fd)
  301. end
  302. end
  303. --直充
  304. function charge(human,oJsonInput)
  305. local gold = oJsonInput.gold
  306. local money = oJsonInput.money
  307. local region = oJsonInput.region
  308. local buyID = oJsonInput.buyID
  309. if buyID and BuyExcel[buyID] then
  310. oJsonInput.id = buyID
  311. buy(human,oJsonInput,true)
  312. else
  313. --直充档次表没有对应配置的话直接给请求中要求的元宝
  314. ObjHuman.addZuanshi(human, gold, "buyTopup")
  315. end
  316. if oJsonInput.order ~= 'transaction_id1' then
  317. 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)
  318. end
  319. end
  320. function onLogin(human)
  321. if not human.db.buyOrder then return end
  322. for k,v in ipairs(human.db.buyOrder) do
  323. if v.cmd == "charge" then
  324. buy(human,v)
  325. elseif v.cmd == "deliver" then
  326. charge(human,v)
  327. end
  328. end
  329. human.db.buyOrder = nil
  330. end
  331. -- 判断能不能直购
  332. function checkCanBuy(human, buyID)
  333. local buyConf = BuyExcel[buyID]
  334. if not buyConf then return end
  335. local price = getRealPrice(human, buyID, "CN")
  336. if price and not FcmLogic.checkCanBuy(human, price) then
  337. return
  338. end
  339. if SceneHandler.canCharge(human) ~= true then
  340. return Broadcast.sendErr(human, Lang.CHARGE_CLOSE_TIP)
  341. end
  342. local msgRet = Msg.gc.GC_BUY_CHECK
  343. msgRet.buyCode = BUY_CODE_NORMAL
  344. if PfLogic.isFKW(human) then
  345. -- 方块玩微信小程序的正式服 ios下走客服充值
  346. if human.isIOS == 1 then
  347. msgRet.buyCode = BUY_CODE_WX_KEFU
  348. end
  349. elseif PfLogic.isKunTang(human) then
  350. -- 坤堂微信小程序的正式服 ios和安卓都走客服充值
  351. msgRet.buyCode = BUY_CODE_WX_KEFU
  352. end
  353. fontBuyItem(human, msgRet.buyItem, buyID)
  354. Msg.send(msgRet, human.fd)
  355. end