123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- --充值服务
- local skynet = require "skynet"
- require "skynet.manager"
- local redisdriver = require "skynet.db.redis"
- local logger = require "logger"
- local queue = require "skynet.queue"
- local asset = require "model.asset"
- local pipeline = require "pipeline"
- local synchronized = queue()
- local skynet_retpack = skynet.retpack
- local trace = logger.trace
- local recharge = {}
- local CMD = {}
- local redis
- local INDENT = "indent:"
- local KEYGEN_PAY = "%s:%s"
- local mq
- local REBATE = "rebate:"
- function recharge.refresh_data(uid,orderid)
- local key = INDENT..string.format(KEYGEN_PAY,uid,orderid)
- local flag = redis:hget(key,"flag")
- if not flag then
- key = REBATE..string.format(KEYGEN_PAY,uid,orderid)
- flag = redis:hget(key,"flag")
- end
- if flag then
- flag = tonumber(flag)
- trace("充值修改flag:%s",flag)
- if flag==1 then
- local now = os.time()
- redis:hmset(key,
- "overTime",now,
- "flag",0
- )
- end
- else
- trace("充值修改flag失败没有orderid:%s",orderid)
- end
- end
- function recharge.record_data(uid, cfid, orderid, appname, giftid)
- local key = INDENT..string.format(KEYGEN_PAY, uid, orderid)
- local now = os.time()
- redis:hmset(key,
- "uid",uid,
- "cfid",cfid,
- "orderid",orderid,
- "writeTime",now,
- "flag",1, --1未完成,0完成
- "appname", appname,
- "giftid", giftid
- )
- --test recharge
- local moneycfg = assert(asset.RechargeConfig_proto[cfid],cfid)
- local moneytype = asset.DataConfig_proto[19].data1
- local moneynum
- if moneytype == 1 then
- moneynum = moneycfg.my
- elseif moneytype == 2 then
- moneynum = moneycfg.rmb
- elseif moneytype == 3 then
- moneynum = moneycfg.tw
- end
- skynet.send(mq, "lua", "publish", uid, "recharge", cfid, orderid, moneynum, appname, giftid) -- 派发事件
- end
- function CMD.orderid_refresh(uid,orderid)
- synchronized(function()
- recharge.refresh_data(uid,orderid)--在玩家发货成功
- end)
- end
- function CMD.orderid_record(uid, cfid, orderid, appname, giftid)
- synchronized(function()
- recharge.record_data(uid, cfid, orderid, appname, giftid)--写入玩家成功支付的订单
- end)
- end
- --------------------------sy185的返利接口------------------------
- function recharge.rebate_data(uid, money, orderid, vip, gift)--写入玩家返利的订单
- local key = REBATE..string.format(KEYGEN_PAY,uid,orderid)
- local now = os.time()
- redis:hmset(key,
- "uid",uid,
- "money",money,
- "orderid",orderid,
- "writeTime",now,
- "flag",1, --1未完成,0完成
- "vip",vip, --是否加vip经验,0-不加1-加
- "gift",gift --是否amount>=5000时,额外赠送50%,0-不赠送1-赠送(满50 元额外赠送50%)
- )
- skynet.send(mq, "lua", "publish", uid, "recharge.rebate_money", money, orderid, vip, gift) -- 派发事件
- end
- function CMD.orderid_rebate(uid, cfid, orderid,vip,gift)
- synchronized(function()
- recharge.rebate_data(uid, cfid, orderid,vip,gift)--写入玩家返利的订单
- end)
- end
- --------------------------------------------------------------------
- --获取玩家充值数量
- local all_recharge = {}
- local stringify = require "stringify"
- function recharge.get_all_recharge()
- local keys = redis:keys("indent:*")
- local block = pipeline(1024)
- if next(keys) then
- for _, k in pairs(keys) do
- block.add("hmget", k, "uid","cfid")
- end
- end
- local resp = block.execute(redis, {})
- local num = 0
- for i, v in ipairs(resp) do
- assert(v.ok)
- local rs = v.out
- if rs[1] then
- local uid = rs[1]
- local cfid = rs[2]
- all_recharge[uid] = all_recharge[uid] or {}
- table.insert(all_recharge[uid],{cfid = cfid,uid = uid})
- num = num + 1
- end
- end
- -- trace("___________________________________获取玩家充值数量num:%s,all_recharge:%s",num,stringify(all_recharge))
- end
- function CMD.get_uid_recharge(uid)
- if all_recharge and all_recharge[uid] then
- return all_recharge[uid]
- end
- end
- function CMD.start()
- local conf = assert(option.redis)
- redis = redisdriver.connect(conf)
- redis:select(3)--切换到数据库db1
- mq = mq or skynet.localname(".mq")
- recharge.get_all_recharge()
- end
- skynet.init(function()
- skynet.register(".recharge")
- end)
- skynet.start(function()
- skynet.dispatch("lua", function(session, _, cmd, ...)
- local f = assert(CMD[cmd])
- if session == 0 then
- f(...)
- else
- skynet_retpack(f(...))
- end
- end)
- end)
|