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
956f2471
Commit
956f2471
authored
Sep 02, 2018
by
周尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复卡券批处理因时间格式导致的错误
暂时关闭门店日统计的批处理检查以规避mysql连接错误问题
parent
df4029a7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
589 additions
and
517 deletions
+589
-517
nginx/conf/nginx.conf
nginx/conf/nginx.conf
+1
-0
nginx/lua/luabiz/node_card.lua
nginx/lua/luabiz/node_card.lua
+1
-1
nginx/lua/luabiz/node_ticket.lua
nginx/lua/luabiz/node_ticket.lua
+1
-1
nginx/lua/luabiz/settle.lua
nginx/lua/luabiz/settle.lua
+13
-6
nginx/lua/luabiz/tk_sdt.lua
nginx/lua/luabiz/tk_sdt.lua
+573
-509
No files found.
nginx/conf/nginx.conf
View file @
956f2471
...
@@ -18,6 +18,7 @@ http {
...
@@ -18,6 +18,7 @@ http {
include
mime.types
;
include
mime.types
;
default_type
application/octet-stream
;
default_type
application/octet-stream
;
log_format
main
#log_format main "'$remote_addr - $remote_user [$time_local] "$request" '
#log_format main "'$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
# '"$http_user_agent" "$http_x_forwarded_for"';
...
...
nginx/lua/luabiz/node_card.lua
View file @
956f2471
...
@@ -39,7 +39,7 @@ local function card_sql(db_st, total_time)
...
@@ -39,7 +39,7 @@ local function card_sql(db_st, total_time)
-- DELETE invalid rows
-- DELETE invalid rows
-- local sql_delete = [[DELETE FROM node_card WHERE (card_status != 0 AND card_status !=1) or now() > card_exp]]
-- local sql_delete = [[DELETE FROM node_card WHERE (card_status != 0 AND card_status !=1) or now() > card_exp]]
local
sql_update
=
[[UPDATE node_card SET card_status = 8 WHERE now() > card_exp]]
local
sql_update
=
string.format
(
[[UPDATE node_card SET card_status = 8 WHERE %d > card_exp]]
,
os.date
(
"%Y%m%d"
))
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_update
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_update
)
ngx
.
log
(
ngx
.
NOTICE
,
sql_update
)
ngx
.
log
(
ngx
.
NOTICE
,
sql_update
)
if
not
res
then
if
not
res
then
...
...
nginx/lua/luabiz/node_ticket.lua
View file @
956f2471
...
@@ -36,7 +36,7 @@ local function ticket_sql(db_st, total_time)
...
@@ -36,7 +36,7 @@ local function ticket_sql(db_st, total_time)
-- DELETE invalid rows
-- DELETE invalid rows
-- local sql_delete = [[DELETE FROM node_ticket WHERE (ticket_status != 0 AND ticket_status !=1) or now() > ticket_exp]]
-- local sql_delete = [[DELETE FROM node_ticket WHERE (ticket_status != 0 AND ticket_status !=1) or now() > ticket_exp]]
local
sql_update
=
[[UPDATE node_ticket SET ticket_status = 8 WHERE now() > ticket_exp]]
local
sql_update
=
string.format
(
[[UPDATE node_ticket SET ticket_status = 8 WHERE %d > ticket_exp]]
,
os.date
(
"%Y%m%d"
))
ngx
.
log
(
ngx
.
NOTICE
,
sql_update
)
ngx
.
log
(
ngx
.
NOTICE
,
sql_update
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_update
)
local
res
,
err
,
errcode
,
sqlstate
=
db
:
query
(
sql_update
)
if
not
res
then
if
not
res
then
...
...
nginx/lua/luabiz/settle.lua
View file @
956f2471
local
SETTLE
=
{}
-- Settle modules
-- Settle modules
local
zx_base
=
loadmod
(
'zx_base'
)
local
zx_base
=
loadmod
(
'zx_base'
)
-- local node_asb = loadmod('node_asb')
-- local node_asb = loadmod('node_asb')
...
@@ -26,7 +27,7 @@ local tk_sync = loadmod('tk_sync')
...
@@ -26,7 +27,7 @@ local tk_sync = loadmod('tk_sync')
local
delay
=
5
-- delaytime
local
delay
=
5
-- delaytime
local
interval_time
=
'0
10
0'
-- time to run, here is 12:00 for each day
local
interval_time
=
'0
03
0'
-- time to run, here is 12:00 for each day
-- local settledate = "2018-08-16"
-- local settledate = "2018-08-16"
local
settledate
=
os.date
(
'%Y-%m-%d'
,
os.time
())
local
settledate
=
os.date
(
'%Y-%m-%d'
,
os.time
())
local
settletime
=
zx_base
:
date2time
(
settledate
)
local
settletime
=
zx_base
:
date2time
(
settledate
)
...
@@ -58,10 +59,17 @@ handler = function(premature, interval_time, settletime)
...
@@ -58,10 +59,17 @@ handler = function(premature, interval_time, settletime)
-- node_smsvip: run()
-- node_smsvip: run()
-- node_vipacct: run()
-- node_vipacct: run()
tk_sync
:
run
()
-- tk_sync: run()
node_card
:
run
(
settletime
)
-- node_card: run(settletime)
node_ticket
:
run
(
settletime
)
-- node_ticket: run(settletime)
tk_sdt
:
run
(
settletime
)
-- tk_sdt: run(settletime)
local
handle
=
io.popen
(
"curl localhost:8080/settle"
)
if
handle
then
handle
:
close
()
end
-- reset interval_time
-- reset interval_time
interval_time
=
tostring
(
tonumber
(
interval_time
)
-
1
)
interval_time
=
tostring
(
tonumber
(
interval_time
)
-
1
)
...
@@ -85,7 +93,6 @@ if ngx.worker.id() == 1 then
...
@@ -85,7 +93,6 @@ if ngx.worker.id() == 1 then
end
end
end
end
local
SETTLE
=
{}
function
SETTLE
.
run
()
function
SETTLE
.
run
()
local
args
=
ngx
.
req
.
get_uri_args
()
local
args
=
ngx
.
req
.
get_uri_args
()
local
t
local
t
...
...
nginx/lua/luabiz/tk_sdt.lua
View file @
956f2471
...
@@ -22,7 +22,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -22,7 +22,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
-- 新建mysql连接
-- 新建mysql连接
local
db_biz
,
err
=
mysql
:
new
()
local
db_biz
,
err
=
mysql
:
new
()
if
not
db_biz
then
if
not
db_biz
then
ngx
.
log
(
ngx
.
ERR
,
"failed to instantiate mysql: "
,
err
)
zx_base
:
log
(
"S"
,
"failed to instantiate mysql: "
,
err
)
return
false
return
false
end
end
...
@@ -40,14 +40,14 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -40,14 +40,14 @@ local function sdt_sql(tk_biz, tk_control, total_time)
charset
=
'utf8'
charset
=
'utf8'
}
}
if
not
ok
then
if
not
ok
then
ngx
.
log
(
ngx
.
ERR
,
json
.
encode
(
tk_biz
),
":"
,
err
,
errcode
,
sqlstate
)
zx_base
:
log
(
"S"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
errcode
,
sqlstate
)
return
return
end
end
-- 新建mysql连接
-- 新建mysql连接
local
db_control
,
err
=
mysql
:
new
()
local
db_control
,
err
=
mysql
:
new
()
if
not
db_control
then
if
not
db_control
then
ngx
.
log
(
ngx
.
ERR
,
"failed to instantiate mysql: "
,
err
)
zx_base
:
log
(
"S"
,
"failed to instantiate mysql: "
,
err
)
return
false
return
false
end
end
...
@@ -65,18 +65,19 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -65,18 +65,19 @@ local function sdt_sql(tk_biz, tk_control, total_time)
charset
=
'utf8'
charset
=
'utf8'
}
}
if
not
ok
then
if
not
ok
then
ngx
.
log
(
ngx
.
ERR
,
json
.
encode
(
tk_control
),
":"
,
err
,
errcode
,
sqlstate
)
zx_base
:
log
(
"S"
,
json
.
encode
(
tk_control
),
":"
,
err
,
errcode
,
sqlstate
)
return
return
end
end
-- GET shop_map_id list
-- GET shop_map_id list
local
shops
local
shops
local
sql_select
=
'SELECT DISTINCT shop_map_id FROM node_saleorder UNION SELECT DISTINCT shop_map_id FROM node_rchg;'
-- local sql_select = 'SELECT DISTINCT shop_map_id FROM node_saleorder UNION SELECT DISTINCT shop_map_id FROM node_rchg;'
local
sql_select
=
'SELECT mer_map_id, shop_map_id FROM tk_shop'
shops
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
sql_select
)
shops
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
sql_select
)
ngx
.
log
(
ngx
.
NOTICE
,
sql_select
)
ngx
.
log
(
ngx
.
NOTICE
,
sql_select
)
if
not
shops
then
if
not
shops
then
ngx
.
log
(
ngx
.
ERR
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
zx_base
:
log
(
"S"
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
return
end
end
...
@@ -89,9 +90,26 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -89,9 +90,26 @@ local function sdt_sql(tk_biz, tk_control, total_time)
shop
=
shops
[
i
]
shop
=
shops
[
i
]
-- -- CHECK if exists
-- local sql_do = string.format(
-- [[SELECT * FROM tk_sdt WHERE DATE(total_date) = DATE('%s') ]]..
-- [[AND shop_map_id = %s]],
-- os.date('%Y%m%d',os.time()),
-- tostring(shop.shop_map_id))
-- res, err, errcode, sqlstate = db_biz:query(sql_do)
-- if not res then
-- zx_base:log("S", "failed to connect:", json.encode(tk_biz), ":", err, ":", errcode, ":", sqlstate, ".")
-- zx_base:log("S", sql_do)
-- return
-- end
-- if #res ~= 0 then
-- ngx.log(ngx.NOTICE, shop['shop_map_id'], " finished already")
-- break
-- end
-- GET summary
-- GET summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT op_map_id, mer_map_id, sh
op_map_id, city_county_id, ]]
..
[[SELECT
op_map_id, city_county_id, ]]
..
[[IFNULL(COUNT(*), 0) t_order_cnt, ]]
..
[[IFNULL(COUNT(*), 0) t_order_cnt, ]]
..
[[IFNULL(SUM(amt_pay), 0) t_order_amt, ]]
..
[[IFNULL(SUM(amt_pay), 0) t_order_amt, ]]
..
[[IFNULL(SUM(amt_profit), 0) t_order_profit, ]]
..
[[IFNULL(SUM(amt_profit), 0) t_order_profit, ]]
..
...
@@ -107,6 +125,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -107,6 +125,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[1])
-- GET online records
-- GET online records
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -119,6 +138,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -119,6 +138,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[2])
-- GET VIP/NOVIP records
-- GET VIP/NOVIP records
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -131,6 +151,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -131,6 +151,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[3])
-- GET MS records
-- GET MS records
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -143,120 +164,135 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -143,120 +164,135 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[4])
-- GET 0000-0900 order
-- GET 0000-0900 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_0009, IFNULL(SUM(amt_pay), 0) time_amt_0009 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_0009, IFNULL(SUM(amt_pay), 0) time_amt_0009 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d000000'
,
total_time
),
os.date
(
'%Y%m%d000000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d090000'
,
total_time
))
os.date
(
'%Y%m%d090000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[5])
-- GET 0900-1100 order
-- GET 0900-1100 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_0911, IFNULL(SUM(amt_pay), 0) time_amt_0911 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_0911, IFNULL(SUM(amt_pay), 0) time_amt_0911 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d090000'
,
total_time
),
os.date
(
'%Y%m%d090000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d110000'
,
total_time
))
os.date
(
'%Y%m%d110000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[6])
-- GET 1100-1300 order
-- GET 1100-1300 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1113, IFNULL(SUM(amt_pay), 0) time_amt_1113 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1113, IFNULL(SUM(amt_pay), 0) time_amt_1113 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d110000'
,
total_time
),
os.date
(
'%Y%m%d110000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d130000'
,
total_time
))
os.date
(
'%Y%m%d130000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[7])
-- GET 1300-1500 order
-- GET 1300-1500 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1315, IFNULL(SUM(amt_pay), 0) time_amt_1315 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1315, IFNULL(SUM(amt_pay), 0) time_amt_1315 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d130000'
,
total_time
),
os.date
(
'%Y%m%d130000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d150000'
,
total_time
))
os.date
(
'%Y%m%d150000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[8])
-- GET 1500-1700 order
-- GET 1500-1700 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1517, IFNULL(SUM(amt_pay), 0) time_amt_1517 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1517, IFNULL(SUM(amt_pay), 0) time_amt_1517 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d150000'
,
total_time
),
os.date
(
'%Y%m%d150000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d170000'
,
total_time
))
os.date
(
'%Y%m%d170000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[9])
-- GET 1700-1900 order
-- GET 1700-1900 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1719, IFNULL(SUM(amt_pay), 0) time_amt_1719 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1719, IFNULL(SUM(amt_pay), 0) time_amt_1719 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d170000'
,
total_time
),
os.date
(
'%Y%m%d170000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d190000'
,
total_time
))
os.date
(
'%Y%m%d190000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[10])
-- GET 1900-2100 order
-- GET 1900-2100 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1921, IFNULL(SUM(amt_pay), 0) time_amt_1921 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_1921, IFNULL(SUM(amt_pay), 0) time_amt_1921 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d190000'
,
total_time
),
os.date
(
'%Y%m%d190000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d210000'
,
total_time
))
os.date
(
'%Y%m%d210000'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[11])
-- GET 2100-2400 order
-- GET 2100-2400 order
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(*), 0) time_cnt_2124, IFNULL(SUM(amt_pay), 0) time_amt_2124 ]]
..
[[SELECT IFNULL(COUNT(*), 0) time_cnt_2124, IFNULL(SUM(amt_pay), 0) time_amt_2124 ]]
..
[[FROM node_saleorder ]]
..
[[FROM node_saleorder ]]
..
[[WHERE shop_map_id = %s ]]
..
[[WHERE shop_map_id = %s ]]
..
[[AND order_status = 0 ]]
..
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
[[AND `create_time` > '%s' AND `create_time` < '%s'; ]]
,
tostring
(
shop
.
shop_map_id
),
tostring
(
shop
.
shop_map_id
),
os.date
(
'%Y%m%d210000'
,
total_time
),
os.date
(
'%Y%m%d210000'
,
total_time
-
24
*
60
*
60
),
os.date
(
'%Y%m%d235959'
,
total_time
))
os.date
(
'%Y%m%d235959'
,
total_time
-
24
*
60
*
60
))
)
)
-- ngx.log(ngx.NOTICE, sql[12])
-- get VIP cnt
-- get VIP cnt
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(vip_map_id
), 0) t_vip_cnt ]]
..
[[SELECT IFNULL(COUNT(DISTINCT(vip_map_id)
), 0) t_vip_cnt ]]
..
[[FROM node_vipacct ]]
..
[[FROM node_vipacct ]]
..
[[WHERE shop_map_id IN ]]
..
[[WHERE DATE(create_time) <= %s ]]
..
[[(SELECT shop_map_id FROM tk_shop ]]
..
[[AND mer_map_id = ]]
..
[[WHERE shop_grp_id IN ]]
..
[[(SELECT mer_map_id FROM tk_shop WHERE shop_map_id = %s);]]
,
[[(SELECT shop_grp_id FROM node_shopgrp ]]
..
os.date
(
'%Y%m%d'
,
total_time
-
24
*
60
*
60
),
[[WHERE mer_map_id = (SELECT mer_map_id FROM tk_shop WHERE shop_map_id = %s)));]]
,
tostring
(
shop
[
'shop_map_id'
]))
tostring
(
shop
[
'shop_map_id'
]))
)
)
-- ngx.log(ngx.NOTICE, sql[13])
-- GET VIP new cnt
-- GET VIP new cnt
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
[[SELECT IFNULL(COUNT(vip_map_id
), 0) t_vip_newcnt ]]
..
[[SELECT IFNULL(COUNT(DISTINCT(vip_map_id)
), 0) t_vip_newcnt ]]
..
[[FROM node_vipacct ]]
..
[[FROM node_vipacct ]]
..
[[WHERE DATE(create_time) = DATE('%s') ]]
..
[[WHERE DATE(create_time) = DATE('%s') ]]
..
[[AND shop_map_id IN ]]
..
[[AND mer_map_id = ]]
..
[[(SELECT shop_map_id FROM tk_shop ]]
..
[[(SELECT mer_map_id FROM tk_shop WHERE shop_map_id = %s);]]
,
[[WHERE shop_grp_id IN ]]
..
[[(SELECT shop_grp_id FROM node_shopgrp ]]
..
[[WHERE mer_map_id = (SELECT mer_map_id FROM tk_shop WHERE shop_map_id = %s)));]]
,
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
[
'shop_map_id'
]))
tostring
(
shop
[
'shop_map_id'
]))
)
)
-- ngx.log(ngx.NOTICE, sql[14])
-- GET charge summary
-- GET charge summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -267,6 +303,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -267,6 +303,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[15])
-- GET cash summary
-- GET cash summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -278,6 +315,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -278,6 +315,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[16])
-- GET WeiXin summary
-- GET WeiXin summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -289,6 +327,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -289,6 +327,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[17])
-- GET AliPay summary
-- GET AliPay summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -300,6 +339,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -300,6 +339,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[18])
-- GET bank summary
-- GET bank summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -311,6 +351,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -311,6 +351,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[19])
-- GET vipcard summary
-- GET vipcard summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -322,6 +363,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -322,6 +363,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[20])
-- GET othpay summary
-- GET othpay summary
table.insert
(
sql
,
string.format
(
table.insert
(
sql
,
string.format
(
...
@@ -333,11 +375,11 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -333,11 +375,11 @@ local function sdt_sql(tk_biz, tk_control, total_time)
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
os.date
(
"%Y%m%d"
,
total_time
-
24
*
60
*
60
),
tostring
(
shop
.
shop_map_id
))
tostring
(
shop
.
shop_map_id
))
)
)
-- ngx.log(ngx.NOTICE, sql[21])
ngx
.
log
(
ngx
.
NOTICE
,
sql
[
1
])
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
table.concat
(
sql
))
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
table.concat
(
sql
))
if
not
res
then
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
zx_base
:
log
(
"S"
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
return
end
end
...
@@ -345,31 +387,48 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -345,31 +387,48 @@ local function sdt_sql(tk_biz, tk_control, total_time)
for
k
,
v
in
pairs
(
res
[
1
])
do
for
k
,
v
in
pairs
(
res
[
1
])
do
shop
[
k
]
=
v
shop
[
k
]
=
v
end
end
-- else
-- break
end
ngx
.
log
(
ngx
.
NOTICE
,
string.format
(
"================ TK_SDT [%s - %s] =========="
,
tostring
(
shop
[
'shop_map_id'
]),
os.date
(
"%Y%m%d"
,
total_time
)))
for
k
,
v
in
pairs
(
shop
)
do
ngx
.
log
(
ngx
.
NOTICE
,
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
end
end
local
j
=
2
local
j
=
2
while
err
==
"again"
do
while
err
==
"again"
do
ngx
.
log
(
ngx
.
NOTICE
,
sql
[
j
])
-- repeat
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
read_result
()
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
read_result
()
if
not
res
then
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"bad result #"
,
j
,
": "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
zx_base
:
log
(
"S"
,
"bad sql: "
,
sql
[
j
])
zx_base
:
log
(
"S"
,
"bad result #"
,
j
,
": "
,
err
,
": "
,
errcode
,
": "
,
sqlstate
,
"."
)
return
ngx
.
exit
(
500
)
return
ngx
.
exit
(
500
)
end
end
ngx
.
log
(
ngx
.
NOTICE
,
string.format
(
"================ TK_SDT [%s - %s] =========="
,
tostring
(
shop
[
'shop_map_id'
]),
os.date
(
"%Y%m%d"
,
total_time
)))
for
k
,
v
in
pairs
(
shop
)
do
ngx
.
log
(
ngx
.
NOTICE
,
string.format
(
"%-32s : %s"
,
k
,
tostring
(
v
)))
end
if
#
res
~=
0
then
if
#
res
~=
0
then
for
k
,
v
in
pairs
(
res
[
1
])
do
for
k
,
v
in
pairs
(
res
[
1
])
do
shop
[
k
]
=
v
shop
[
k
]
=
v
end
end
j
=
j
+
1
j
=
j
+
1
end
end
-- until(err ~= "again")
end
end
-- SET total_date
-- SET total_date
shop
[
'total_date'
]
=
zx_base
:
tonumber
(
os.date
(
'%Y%m%d'
,
total_time
))
shop
[
'total_date'
]
=
zx_base
:
tonumber
(
os.date
(
'%Y%m%d'
,
total_time
))
-- INSERT INTO tk_sdt
local
str
=
zx_base
:
sql_concate
(
'duplicate'
,
'tk_sdt'
,
shop
)
-- Convert type
-- Convert type
shop
[
'op_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'op_map_id'
])
shop
[
'op_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'op_map_id'
])
shop
[
'mer_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'mer_map_id'
])
shop
[
'mer_map_id'
]
=
zx_base
:
tonumber
(
shop
[
'mer_map_id'
])
...
@@ -391,6 +450,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -391,6 +450,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
shop
[
't_order_profit'
]
=
zx_base
:
tonumber
(
shop
[
't_order_profit'
])
shop
[
't_order_profit'
]
=
zx_base
:
tonumber
(
shop
[
't_order_profit'
])
shop
[
't_order_profit_per'
]
=
zx_base
:
tonumber
(
shop
[
't_order_profit_per'
])
shop
[
't_order_profit_per'
]
=
zx_base
:
tonumber
(
shop
[
't_order_profit_per'
])
shop
[
't_vip_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_vip_cnt'
])
shop
[
't_vip_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_vip_cnt'
])
-- shop['vip_cnt'] = zx_base:tonumber(shop['vip_cnt'])
shop
[
't_vip_newcnt'
]
=
zx_base
:
tonumber
(
shop
[
't_vip_newcnt'
])
shop
[
't_vip_newcnt'
]
=
zx_base
:
tonumber
(
shop
[
't_vip_newcnt'
])
shop
[
't_charge_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_charge_cnt'
])
shop
[
't_charge_cnt'
]
=
zx_base
:
tonumber
(
shop
[
't_charge_cnt'
])
shop
[
't_charge_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_charge_amt'
])
shop
[
't_charge_amt'
]
=
zx_base
:
tonumber
(
shop
[
't_charge_amt'
])
...
@@ -466,31 +526,35 @@ local function sdt_sql(tk_biz, tk_control, total_time)
...
@@ -466,31 +526,35 @@ local function sdt_sql(tk_biz, tk_control, total_time)
shop
[
't_order_avg_price'
]
=
0
shop
[
't_order_avg_price'
]
=
0
shop
[
't_order_profit_per'
]
=
0
shop
[
't_order_profit_per'
]
=
0
else
else
shop
[
't_order_avg_price'
]
=
shop
[
't_order_amt'
]
/
shop
[
't_order_cnt'
]
-- shop['t_order_avg_price'] = shop['t_order_amt'] / (shop['vip_cnt'] + shop['t_order_novip_cnt'] - 1)
shop
[
't_order_profit_per'
]
=
shop
[
't_order_profit'
]
/
shop
[
't_order_amt'
]
*
10000
shop
[
't_order_avg_price'
]
=
math.floor
(
shop
[
't_order_amt'
]
/
shop
[
't_order_cnt'
])
shop
[
't_order_profit_per'
]
=
math.floor
(
shop
[
't_order_profit'
]
/
shop
[
't_order_amt'
]
*
10000
)
end
end
if
shop
[
't_order_cnt'
]
==
0
then
-- if shop['t_order_cnt'] == 0 and shop['t_vip_newcnt'] == 0 and shop['t_vip_cnt'] == 0 then
break
-- break
end
-- end
-- INSERT INTO tk_sdt
local
str
=
zx_base
:
sql_concate
(
'duplicate'
,
'tk_sdt'
,
shop
)
-- INSERT INTO tk_biz database
-- INSERT INTO tk_biz database
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
str
)
res
,
err
,
errcode
,
sqlstate
=
db_biz
:
query
(
str
)
ngx
.
log
(
ngx
.
NOTICE
,
str
)
ngx
.
log
(
ngx
.
NOTICE
,
str
)
if
not
res
then
if
not
res
then
ngx
.
log
(
ngx
.
ERR
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
zx_base
:
log
(
"S"
,
"failed to query:"
,
json
.
encode
(
tk_biz
),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
return
return
end
end
-- INSERT INTO tk_control database
--
-- INSERT INTO tk_control database
res
,
err
,
errcode
,
sqlstate
=
db_control
:
query
(
str
)
--
res, err, errcode, sqlstate = db_control:query(str)
ngx
.
log
(
ngx
.
NOTICE
,
str
)
--
ngx.log(ngx.NOTICE, str)
if
not
res
then
--
if not res then
ngx
.
log
(
ngx
.
ERR
,
"failed to query:"
,
json
.
encode
(
tk_control
),
-- zx_base:log("S"
, "failed to query:", json.encode(tk_control),
":"
,
err
,
":"
,
errcode
,
":"
,
sqlstate
,
"."
)
--
":", err, ":", errcode, ":", sqlstate, ".")
return
-- --
return
end
--
end
-- table.insert(shops, shop)
-- table.insert(shops, shop)
...
...
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