BuyLogic.lua 12 KB

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