Commit 2aa571ea authored by 周尚's avatar 周尚

门店库存 [完成]

parent 211056b9
[submodule "openresty.wiki"]
path = openresty.wiki
url = 192.168.254.154:tangku7/openresty.wiki.git
......@@ -15,10 +15,12 @@
1. [ ] 异步推送
2. [-] 业务批处理
1. [ ] 库存信息类
1. [ ] 门店库存
2. [ ] 会员管理类
1. [ ] 会员账户
1. [X] 库存信息类
1. [X] 门店库存
2. [-] 会员管理类
1. [-] 会员账户
1. [X] 设置余额
2. [ ] 会员等级更新
3. [X] 营销工具
1. [X] 卡账户
2. [X] 券账户
......
local _SKU = {}
package.path = package.path..";/Users/zhoush/openresty/nginx/lua/?.lua;;"
local mysql = require("resty.mysql")
local base = require("base")
local tasks = {}
local db_conf = "tk7_dbs.json"
local function sku_sql(db_st)
local log = ngx.log
local ERR = ngx.ERR
local db, err = mysql:new()
if not db then
base:print_log("S", "[SKU]:", "failed to instantiate mysql: ", err)
return false
end
db:SET_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{
host = db_st['host'],
port = db_st['port'],
database = db_st['database'],
user = db_st['user'],
password = db_st['password'],
timeout = db_st['timeout'],
}
if not ok then
base:print_log("S", "[NODE_SKU]:", "failed to connect: ", err, ": ", errcode, " ", sqlstate)
return
end
-- DELETE invalid sku records
local sql_update = [[DELETE FROM node_sku WHERE sku_exp_flag = 9]]
local res, err, errcode, sqlstate = db:query(sql_update)
if not res then
base:print_log("S", "[NODE_SKU]:", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
base:print_log("NODE_SKU", "<SQL>", sql_update)
return
end
end
local function async(i)
local co = coroutine.wrap(
function()
sku_sql(i)
end
)
table.insert(tasks, co)
end
local function dispatch()
local i = 1
while true do
if tasks[i] == nil then
if tasks[1] == nil then
break
end
i = 1
end
local res = tasks[i]()
if not res then
table.remove(tasks, i)
else
i = i + 1
end
end
end
function _SKU.run()
local base = require('base')
local json = require('cjson')
local dbs_st = base:db_read(db_conf)
for i = 1, #dbs_st.tk_biz do
async(dbs_st.tk_biz[i])
end
dispatch()
end
return _SKU
local _VIPACCT = {}
package.path = package.path..";/Users/zhoush/openresty/nginx/lua/?.lua;;"
local mysql = require("resty.mysql")
local base = require("base")
local tasks = {}
local db_conf = "tk7_dbs.json"
local function vipacct_sql(db_st)
local log = ngx.log
local ERR = ngx.ERR
local db, err = mysql:new()
if not db then
base:print_log("S", "[VIPACCT]:", "failed to instantiate mysql: ", err)
return false
end
db:SET_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{
host = db_st['host'],
port = db_st['port'],
database = db_st['database'],
user = db_st['user'],
password = db_st['password'],
timeout = db_st['timeout'],
}
if not ok then
base:print_log("S", "[NODE_VIPACCT]:", "failed to connect: ", err, ": ", errcode, " ", sqlstate)
return
end
-- SET yesterday's balance
local sql_update = [[UPDATE node_vipacct SET `point_lbal` = `point_cbal`, `acct_lbal` = `acct_cbal`, ]]..
[[`acct_lbal` = `acct_cbal`, `count_lbal` = `count_cbal`]]
local res, err, errcode, sqlstate = db:query(sql_update)
if not res then
base:print_log("S", "[NODE_VIPACCT]:", "bad result: ", err, ": ", errcode, ": ", sqlstate, ".")
base:print_log("NODE_VIPACCT", "<SQL>", sql_update)
return
end
-- SET VIPACCT's level
end
local function async(i)
local co = coroutine.wrap(
function()
vipacct_sql(i)
end
)
table.insert(tasks, co)
end
local function dispatch()
local i = 1
while true do
if tasks[i] == nil then
if tasks[1] == nil then
break
end
i = 1
end
local res = tasks[i]()
if not res then
table.remove(tasks, i)
else
i = i + 1
end
end
end
function _VIPACCT.run()
local base = require('base')
local json = require('cjson')
local dbs_st = base:db_read(db_conf)
for i = 1, #dbs_st.tk_biz do
async(dbs_st.tk_biz[i])
end
dispatch()
end
return _VIPACCT
openresty.wiki @ 74d78be5
Subproject commit 74d78be5d737131f68f7432fb139908c9de1c333
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment