Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
openresty
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tangku7
openresty
Commits
05aa372f
Commit
05aa372f
authored
Oct 16, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add CMBC settle
optimize tk_sdt code
parent
64aa3750
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
420 additions
and
37 deletions
+420
-37
nginx/lua/luabiz/cmbc_dept_dt.lua
nginx/lua/luabiz/cmbc_dept_dt.lua
+133
-0
nginx/lua/luabiz/cmbc_shop_dt.lua
nginx/lua/luabiz/cmbc_shop_dt.lua
+253
-0
nginx/lua/luabiz/settle.lua
nginx/lua/luabiz/settle.lua
+2
-0
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+20
-37
nginx/lua/luainit/db_conf.lua
nginx/lua/luainit/db_conf.lua
+8
-0
nginx/lua/luainit/mods.lua
nginx/lua/luainit/mods.lua
+4
-0
No files found.
nginx/lua/luabiz/cmbc_dept_dt.lua
0 → 100644
View file @
05aa372f
local
CMBC_DEPT_DT
=
{}
-- 加载模块
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
log_lua
=
_G
.
log_lua
or
_G
.
loadmod
(
'luabiz.log'
)
local
db_cmbc
-- cmbc database handle
-- 初始化数据库连接
-- @param table cmbc_card 民生数据库对象
-- @return true/false
local
function
BEGIN
(
cmbc_card
)
log_lua
:
BEGIN
(
"cmbc_dept_dt"
)
local
err
-- 新建mysql连接
db_cmbc
,
err
=
mysql
:
new
()
if
not
db_cmbc
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to instantiate mysql: "
,
err
)
return
false
end
-- 超时设置
db_cmbc
:
set_timeout
(
1000
)
-- 连接cmbc_card
local
ok
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
connect
{
host
=
zx_base
:
_get_addr
(
cmbc_card
[
'host'
]),
port
=
cmbc_card
[
'port'
],
database
=
cmbc_card
[
'database'
],
user
=
cmbc_card
[
'user'
],
password
=
cmbc_card
[
'password'
],
timeout
=
cmbc_card
[
'timeout'
],
charset
=
'utf8'
}
if
not
ok
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
json
.
encode
(
cmbc_card
),
":"
,
err
,
errcode
,
sqlstate
)
return
false
end
return
true
;
end
-- 清理连接句柄
-- @param nil
-- @return nil
local
function
END
()
zx_base
:
close_db
(
db_cmbc
)
log_lua
:
END
(
"cmbc_dept_dt"
)
end
-- 门店统计
-- @param nil
-- @return nil
local
function
sdt_sql
(
cmbc_card
,
total_time
)
local
sql_check
=
string.format
(
[[SELECT * FROM cmbc_dept_dt WHERE DATE(total_date) = DATE('%s') ]]
,
os.date
(
'%Y%m%d'
,
total_time
)
)
local
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
sql_check
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
sql_check
)
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to connect:"
,
json
.
encode
(
cmbc_card
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
if
#
res
~=
0
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE:"
,
"finished already"
)
return
end
-- GET dept_map_id list
local
sql_dept
=
string.format
(
[[SELECT org_map_id, dept_map_id, job_level_id, job_map_id, SUM(pay_amt) t_pay_amt, COUNT(order_no) t_pay_cnt, rchg_type ]]
..
[[FROM cmbc_rchg ]]
..
[[WHERE DATE(`update_time`) = DATE('%s')]]
..
[[GROUP BY org_map_id, dept_map_id, job_level_id, job_map_id, rchg_type;]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
)
)
local
depts
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
sql_dept
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql_dept
)
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"bad result :"
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
ngx
.
exit
(
500
)
end
for
i
=
1
,
#
depts
do
local
dept
=
depts
[
i
]
-- DETAIL data
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"================ CMBC_DEPT_DT [%s - %s] =========="
,
tostring
(
dept
[
'dept_map_id'
]),
os.date
(
"%Y%m%d"
,
total_time
)))
for
k
,
v
in
pairs
(
dept
)
do
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
end
-- SET total_date
dept
[
'total_date'
]
=
zx_base
:
tonumber
(
os.date
(
'%Y%m%d'
,
total_time
))
-- INSERT INTO cmbc_dept_dt
local
str
=
zx_base
:
sql_concate
(
'duplicate'
,
'cmbc_dept_dt'
,
dept
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
-- INSERT INTO cmbc_card database
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
str
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
cmbc_card
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
end
end
-- 跑批业务处理
-- @param nil
-- @return nil
function
CMBC_DEPT_DT
.
run
(
self
,
total_time
)
local
cmbc_card
=
dbs_st
.
cmbc_card
if
BEGIN
(
cmbc_card
)
then
sdt_sql
(
cmbc_card
,
total_time
)
end
END
()
end
return
CMBC_DEPT_DT
nginx/lua/luabiz/cmbc_shop_dt.lua
0 → 100644
View file @
05aa372f
local
CMBC_SHOP_DT
=
{}
-- 加载模块
local
mysql
=
_G
.
loadmod
(
"resty.mysql"
)
local
json
=
_G
.
loadmod
(
'cjson'
)
local
db_cmbc
-- cmbc database handle
-- 初始化数据库连接
-- @param table cmbc_card 民生数据库对象
-- @return true/false
local
function
BEGIN
(
cmbc_card
)
log_lua
:
BEGIN
(
"cmbc_shop_dt"
)
local
err
-- 新建mysql连接
db_cmbc
,
err
=
mysql
:
new
()
if
not
db_cmbc
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to instantiate mysql: "
,
err
)
return
false
end
-- 超时设置
db_cmbc
:
set_timeout
(
1000
)
-- 连接cmbc_card
local
ok
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
connect
{
host
=
zx_base
:
_get_addr
(
cmbc_card
[
'host'
]),
port
=
cmbc_card
[
'port'
],
database
=
cmbc_card
[
'database'
],
user
=
cmbc_card
[
'user'
],
password
=
cmbc_card
[
'password'
],
timeout
=
cmbc_card
[
'timeout'
],
charset
=
'utf8'
}
if
not
ok
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
json
.
encode
(
cmbc_card
),
":"
,
err
,
errcode
,
sqlstate
)
return
false
end
return
true
;
end
-- 清理连接句柄
-- @param nil
-- @return nil
local
function
END
()
zx_base
:
close_db
(
db_cmbc
)
log_lua
:
END
(
"cmbc_shop_dt"
)
end
-- 门店统计
-- @param nil
-- @return nil
local
function
sdt_sql
(
cmbc_card
,
total_time
)
-- GET shop_map_id list
local
shops
,
err
,
errcode
,
sqlstate
local
sql_shops
=
string.format
(
[[SELECT shop_map_id FROM cmbc_sale WHERE DATE(`update_time`) = DATE('%s')]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
))
shops
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
sql_shops
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
sql_shops
)
if
not
shops
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
cmbc_card
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
for
i
=
1
,
#
shops
do
local
shop
=
shops
[
i
]
local
sql
=
{}
local
res
while
true
do
-- CHECK if exists
local
sql_check
=
string.format
(
[[SELECT * FROM cmbc_shop_dt WHERE DATE(total_date) = DATE('%s') ]]
..
[[AND shop_map_id = %s ]]
,
os.date
(
'%Y%m%d'
,
total_time
),
tostring
(
shop
.
shop_map_id
))
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
sql_check
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
sql_check
)
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to connect:"
,
json
.
encode
(
cmbc_card
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
if
#
res
~=
0
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
shop
[
'shop_map_id'
]
..
"-"
..
os.date
(
"%Y%m%d"
),
" finished already"
)
break
end
-- GET summary
table.insert
(
sql
,
string.format
(
[[SELECT org_map_id, mer_map_id, district_map_id, shop_map_id, ]]
..
[[IFNULL(COUNT(*), 0) t_order_cnt, ]]
..
[[IFNULL(SUM(pay_amt), 0) t_order_amt, ]]
..
[[IFNULL(SUM(DISTINCT(user_map_id)), 0) t_user_cnt ]]
..
[[FROM cmbc_sale ]]
..
[[WHERE date(`update_time`) = date('%s') ]]
..
[[AND shop_map_id = %s ]]
..
[[GROUP BY org_map_id, mer_map_id, district_map_id, shop_map_id;]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
)
-- GET USER records
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) t_order_user_cnt, IFNULL(SUM(pay_amt), 0) t_order_user_amt ]]
..
[[FROM cmbc_sale ]]
..
[[WHERE date(`create_time`) = date('%s') ]]
..
[[AND shop_map_id = %s ]]
..
[[AND user_map_id != 0 ]]
..
[[GROUP BY org_map_id, mer_map_id, shop_map_id;]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
)
-- GET ORDER_TYPEs summary
table.insert
(
sql
,
string.format
(
[[SELECT order_type, ]]
..
[[IFNULL(COUNT(order_no), 0) t_order_tmp_cnt, ]]
..
[[IFNULL(SUM(pay_amt), 0) t_order_tmp_amt ]]
..
[[FROM cmbc_sale ]]
..
[[WHERE DATE(`update_time`) = DATE('%s') ]]
..
[[AND shop_map_id = %s ]]
..
[[GROUP BY org_map_id, mer_map_id, shop_map_id, order_type;]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
)
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
send_query
(
table.concat
(
sql
))
local
j
=
1
repeat
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
read_result
()
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql
[
j
])
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"bad result :"
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
ngx
.
exit
(
500
)
end
for
h
=
1
,
#
res
do
if
res
[
h
][
"order_type"
]
then
-- GET different ORDERTYPEs summary
local
t_order_tmp_amt
=
tonumber
(
res
[
h
][
"t_order_tmp_amt"
])
local
t_order_tmp_cnt
=
tonumber
(
res
[
h
][
"t_order_tmp_cnt"
])
local
order_type
=
res
[
h
][
"order_type"
]
if
order_type
==
1
then
shop
[
't_order_wash_cnt'
]
=
t_order_tmp_cnt
shop
[
't_order_wash_amt'
]
=
t_order_tmp_amt
elseif
order_type
==
2
then
shop
[
't_order_shop_cnt'
]
=
t_order_tmp_cnt
shop
[
't_order_shop_amt'
]
=
t_order_tmp_amt
elseif
order_type
==
3
then
shop
[
't_order_meal_cnt'
]
=
t_order_tmp_cnt
shop
[
't_order_meal_amt'
]
=
t_order_tmp_amt
end
end
for
k
,
v
in
pairs
(
res
[
h
])
do
if
k
~=
"t_order_tmp_amt"
and
k
~=
"t_order_tmp_cnt"
and
k
~=
"order_type"
then
shop
[
k
]
=
v
end
end
end
j
=
j
+
1
until
(
err
~=
"again"
)
-- end
-- SET total_date
shop
[
'total_date'
]
=
zx_base
:
tonumber
(
os.date
(
'%Y%m%d'
,
total_time
))
-- Convert type
shop
[
't_order_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_cnt'
])
shop
[
't_order_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_amt'
])
shop
[
't_order_user_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_user_cnt'
])
shop
[
't_order_user_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_user_amt'
])
shop
[
't_order_wash_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_wash_cnt'
])
shop
[
't_order_wash_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_wash_amt'
])
shop
[
't_order_shop_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_shop_cnt'
])
shop
[
't_order_shop_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_shop_amt'
])
shop
[
't_order_meal_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_meal_cnt'
])
shop
[
't_order_meal_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_order_meal_amt'
])
-- Calculate
shop
[
't_order_nouser_cnt'
]
=
shop
[
"t_order_cnt"
]
-
shop
[
't_order_user_cnt'
]
shop
[
't_order_nouser_amt'
]
=
shop
[
"t_order_amt"
]
-
shop
[
't_order_user_amt'
]
shop
[
'pay_usercard_cnt'
]
=
shop
[
't_order_cnt'
]
shop
[
'pay_usercard_amt'
]
=
shop
[
't_order_amt'
]
shop
[
'pay_wx_cnt'
]
=
0
shop
[
'pay_wx_amt'
]
=
0
shop
[
'pay_alipay_cnt'
]
=
0
shop
[
'pay_alipay_amt'
]
=
0
shop
[
'pay_othpay_cnt'
]
=
0
shop
[
'pay_othpay_amt'
]
=
0
if
shop
[
't_order_amt'
]
==
0
or
shop
[
't_order_cnt'
]
==
0
then
shop
[
't_order_avg_price'
]
=
0
else
shop
[
't_order_avg_price'
]
=
math.floor
(
shop
[
't_order_amt'
]
/
shop
[
't_order_cnt'
])
end
-- DETAIL data
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"================ CMBC_SHOP_DT [%s - %s] =========="
,
tostring
(
shop
[
'shop_map_id'
]),
os.date
(
"%Y%m%d"
,
total_time
)))
for
k
,
v
in
pairs
(
shop
)
do
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
end
if
shop
[
't_order_cnt'
]
==
0
then
break
end
-- INSERT INTO cmbc_shop_dt
local
str
=
zx_base
:
sql_concate
(
'duplicate'
,
'cmbc_shop_dt'
,
shop
)
-- INSERT INTO cmbc_card database
res
,
err
,
errcode
,
sqlstate
=
db_cmbc
:
query
(
str
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
cmbc_card
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
-- table.insert(shops, shop)
break
end
end
end
-- 跑批业务处理
-- @param nil
-- @return nil
function
CMBC_SHOP_DT
.
run
(
self
,
total_time
)
local
cmbc_card
=
dbs_st
.
cmbc_card
if
BEGIN
(
cmbc_card
)
then
sdt_sql
(
cmbc_card
,
total_time
)
end
END
()
end
return
CMBC_SHOP_DT
nginx/lua/luabiz/settle.lua
View file @
05aa372f
...
@@ -99,6 +99,8 @@ function SETTLE.run()
...
@@ -99,6 +99,8 @@ function SETTLE.run()
node_card
:
run
()
node_card
:
run
()
node_ticket
:
run
()
node_ticket
:
run
()
tk_sdt
:
run
(
t
)
tk_sdt
:
run
(
t
)
cmbc_shop_dt
:
run
(
t
)
cmbc_dept_dt
:
run
(
t
)
end
end
return
SETTLE
return
SETTLE
nginx/lua/luabiz/tk_sdt.lua
View file @
05aa372f
...
@@ -112,13 +112,13 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -112,13 +112,13 @@ local function sdt_sql(tk_biz, tk_control, total_time)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
sql_check
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
sql_check
)
if
not
res
then
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to connect:"
,
json
.
encode
(
tk_biz
),
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to connect:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
return
end
end
if
#
res
~=
0
then
if
#
res
~=
0
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
shop
[
'shop_map_id'
]
..
"-"
..
os.date
(
"%Y%m%d"
),
shop
[
'shop_map_id'
]
..
"-"
..
os.date
(
"%Y%m%d"
),
" finished already"
)
" finished already"
)
break
break
end
end
...
@@ -157,7 +157,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -157,7 +157,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
)
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[2])
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[2])
-- GET VIP
/NOVIP
records
-- GET VIP records
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) t_order_vip_cnt, IFNULL(SUM(amt_pay), 0) t_order_vip_amt ]]
..
[[SELECT IFNULL(COUNT(*), 0) t_order_vip_cnt, IFNULL(SUM(amt_pay), 0) t_order_vip_amt ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
...
@@ -287,7 +287,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -287,7 +287,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
)
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[12])
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[12])
--
get
VIP cnt
--
GET
VIP cnt
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(DISTINCT(vip_map_id)), 0) t_vip_cnt ]]
..
[[SELECT IFNULL(COUNT(DISTINCT(vip_map_id)), 0) t_vip_cnt ]]
..
[[FROM node_vipacct ]]
..
[[FROM node_vipacct ]]
..
...
@@ -335,24 +335,9 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -335,24 +335,9 @@ local function sdt_sql(tk_biz, tk_control, total_time)
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
table.concat
(
sql
))
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
send_query
(
table.concat
(
sql
))
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql
[
1
])
local
j
=
1
if
not
res
then
repeat
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
end
if
#
res
~=
0
then
for
k
,
v
in
pairs
(
res
[
1
])
do
shop
[
k
]
=
v
end
-- else
-- break
end
local
j
=
2
while
err
==
"again"
do
-- repeat
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
read_result
()
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
read_result
()
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql
[
j
])
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
,
sql
[
j
])
if
not
res
then
if
not
res
then
...
@@ -360,12 +345,12 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -360,12 +345,12 @@ local function sdt_sql(tk_biz, tk_control, total_time)
return
ngx
.
exit
(
500
)
return
ngx
.
exit
(
500
)
end
end
if
#
res
~=
0
then
for
h
=
1
,
#
res
do
-- GET different paytype summary
-- GET different paytype summary
if
res
[
1
][
"pay_type_id"
]
then
if
res
[
h
][
"pay_type_id"
]
then
local
pay_tmp_amt
=
res
[
1
][
"pay_tmp_amt"
]
local
pay_tmp_amt
=
res
[
h
][
"pay_tmp_amt"
]
local
pay_tmp_cnt
=
res
[
1
][
"pay_tmp_cnt"
]
local
pay_tmp_cnt
=
res
[
h
][
"pay_tmp_cnt"
]
local
paytype
=
res
[
1
][
"pay_type_id"
]
local
paytype
=
res
[
h
][
"pay_type_id"
]
if
paytype
==
1
then
if
paytype
==
1
then
shop
[
"pay_cash_amt"
]
=
pay_tmp_amt
shop
[
"pay_cash_amt"
]
=
pay_tmp_amt
...
@@ -388,22 +373,20 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -388,22 +373,20 @@ local function sdt_sql(tk_biz, tk_control, total_time)
end
end
end
end
for
k
,
v
in
pairs
(
res
[
h
])
do
for
k
,
v
in
pairs
(
res
[
1
])
do
if
k
~=
"pay_tmp_amt"
and
k
~=
"pay_tmp_cnt"
and
k
~=
"pay_type_id"
then
if
k
~=
"pay_tmp_amt"
and
k
~=
"pay_tmp_cnt"
and
k
~=
"pay_type_id"
then
shop
[
k
]
=
v
shop
[
k
]
=
v
end
end
end
end
j
=
j
+
1
end
end
-- until(err ~= "again")
j
=
j
+
1
end
until
(
err
~=
"again"
)
-- DETAIL data
-- DETAIL data
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"================ TK_SDT [%s - %s] =========="
,
string.format
(
"================ TK_SDT [%s - %s] =========="
,
tostring
(
shop
[
'shop_map_id'
]),
tostring
(
shop
[
'shop_map_id'
]),
os.date
(
"%Y%m%d"
,
total_time
)))
os.date
(
"%Y%m%d"
,
total_time
)))
for
k
,
v
in
pairs
(
shop
)
do
for
k
,
v
in
pairs
(
shop
)
do
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
end
end
...
@@ -535,7 +518,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -535,7 +518,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
if
not
res
then
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
tk_biz
),
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
return
end
end
...
@@ -544,7 +527,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -544,7 +527,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"NOTICE: "
..
str
)
if
not
res
then
if
not
res
then
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
tk_control
),
log_lua
:
log
(
log_lua
:
__FILE__
()
..
":"
..
log_lua
:
__LINE__
(),
"ERR: "
..
"failed to query:"
,
json
.
encode
(
tk_control
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
-- return
-- return
end
end
...
...
nginx/lua/luainit/db_conf.lua
View file @
05aa372f
...
@@ -58,6 +58,14 @@ else
...
@@ -58,6 +58,14 @@ else
database
=
"tk_biz"
,
database
=
"tk_biz"
,
timeout
=
30
timeout
=
30
}
}
},
cmbc_card
=
{
host
=
"115.29.241.68"
,
user
=
"root"
,
password
=
"xingdata"
,
port
=
3306
,
database
=
"cmbc_card"
,
timeout
=
30
}
}
}
}
end
end
nginx/lua/luainit/mods.lua
View file @
05aa372f
...
@@ -8,11 +8,15 @@ _G.zx_base = _G.zx_base or require('luabiz.zx_base')
...
@@ -8,11 +8,15 @@ _G.zx_base = _G.zx_base or require('luabiz.zx_base')
-- _G.settle = _G.settle or require('luabiz.settle')
-- _G.settle = _G.settle or require('luabiz.settle')
-- settle detail
-- settle detail
-- 唐库
_G
.
tk_sync
=
_G
.
tk_sync
or
require
(
'luabiz.tk_sync'
)
_G
.
tk_sync
=
_G
.
tk_sync
or
require
(
'luabiz.tk_sync'
)
_G
.
tk_sdt
=
_G
.
tk_sdt
or
require
(
'luabiz.tk_sdt'
)
_G
.
tk_sdt
=
_G
.
tk_sdt
or
require
(
'luabiz.tk_sdt'
)
_G
.
node_card
=
_G
.
node_card
or
require
(
'luabiz.node_card'
)
_G
.
node_card
=
_G
.
node_card
or
require
(
'luabiz.node_card'
)
_G
.
node_ticket
=
_G
.
node_ticket
or
require
(
'luabiz.node_ticket'
)
_G
.
node_ticket
=
_G
.
node_ticket
or
require
(
'luabiz.node_ticket'
)
-- CMBC 民生银行
_G
.
cmbc_shop_dt
=
_G
.
cmbc_shop_dt
or
require
(
'luabiz.cmbc_shop_dt'
)
_G
.
cmbc_dept_dt
=
_G
.
cmbc_dept_dt
or
require
(
'luabiz.cmbc_dept_dt'
)
-- logging module
-- logging module
_G
.
log_lua
=
_G
.
log_lua
or
require
(
'luabiz.log'
)
_G
.
log_lua
=
_G
.
log_lua
or
require
(
'luabiz.log'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment