local account_amonut_map = {} --账户余额 local CMD = {} --转账 functionCMD.transfer(from_account, to_account, num) local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
ifnot skynet.call(".control_service", 'lua', 'control', from_account, num) then returnfalse end
local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[from_account] = amonut - num account_amonut_map[to_account] = to_amonut + num
returntrue end
control_service.lua
1 2 3 4 5
local CMD = {} --分控查询 默认允许 functionCMD.control(account, num) returntrue end
local queue = require"skynet.queue"() local account_amonut_map = {} --账户余额 local CMD = {} --转账 functionCMD.transfer(from_account, to_account, num) return queue(function() local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
ifnot skynet.call(".control_service", 'lua', 'control', from_account, num) then returnfalse end
local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[from_account] = amonut - num account_amonut_map[to_account] = to_amonut + num
local g_transfering = {} local queue = require"skynet.queue"() local account_amonut_map = {} --账户余额 local CMD = {} --转账 localfunctiontransfer(from_account, to_account, num) local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
ifnot skynet.call(".control_service", 'lua', 'control', from_account, num) then returnfalse end
local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[from_account] = amonut - num account_amonut_map[to_account] = to_amonut + num
returntrue end
functionCMD.transfer(from_account, to_account, num) if g_transfering[from_account] then returnfalse end g_transfering[from_account] = true local ret = transfer(from_account, to_account, num) g_transfering[from_account] = false
local account_amonut_map = {} --账户余额 local CMD = {} --转账 functionCMD.transfer(from_account, to_account, num) local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
account_amonut_map[from_account] = amonut - num ifnot skynet.call(".control_service", 'lua', 'control', from_account, num) then account_amonut_map[from_account] = amonut + num returnfalse end
local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[to_account] = to_amonut + num
local account_amonut_map = {} --账户余额 local CMD = {} --转账 functionCMD.transfer(from_account, to_account, num) local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
ifnot skynet.call(".control_service", 'lua', 'control', from_account, num) then returnfalse end
amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
account_amonut_map[from_account] = amonut + num local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[to_account] = to_amonut + num
local account_amonut_map = {} --账户余额 local CMD = {} --转账 functionCMD.transfer(from_account, to_account, num) local amonut = account_amonut_map[from_account] or0 if amonut < num then returnfalse--余额不足 end
skynet.send(".control_service", 'lua', 'control', from_account, num) end
--回调消息处理 functionCMD.transfer_callback(ret) ifnot ret thenreturnend
account_amonut_map[from_account] = amonut + num local to_amonut = account_amonut_map[to_account] or0 account_amonut_map[to_account] = to_amonut + num