Commit 64aa3750 authored by 周尚's avatar 周尚

optimize tk_sdt pay_type SQL

parent e05d23d6
......@@ -108,7 +108,7 @@ http {
location /settle {
content_by_lua_block {
-- local settle = loadmod("settle")
local settle = loadmod("luabiz.settle")
settle:run()
}
}
......
......@@ -122,6 +122,7 @@ local function sdt_sql(tk_biz, tk_control, total_time)
break
end
-- GET summary
table.insert(sql, string.format(
[[SELECT op_map_id, city_county_id, ]]..
......@@ -321,91 +322,18 @@ local function sdt_sql(tk_biz, tk_control, total_time)
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[15])
-- GET cash summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_cash_cnt, IFNULL(SUM(p.pay_amt), 0) pay_cash_amt ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND p.pay_type_id = 1 ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[16])
-- GET WeiXin summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_wx_cnt, IFNULL(SUM(p.pay_amt), 0) pay_wx_amt ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND p.pay_type_id = 2 ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[17])
-- GET AliPay summary
-- GET PAY_TYPEs summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_alipay_cnt, IFNULL(SUM(p.pay_amt), 0) pay_alipay_amt ]]..
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_tmp_cnt, IFNULL(SUM(p.pay_amt), 0) pay_tmp_amt, p.pay_type_id pay_type_id ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND p.pay_type_id = 3 ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
[[AND s.order_status = 0 ]]..
[[GROUP BY p.pay_type_id]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[18])
-- GET bank summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_bank_cnt, IFNULL(SUM(p.pay_amt), 0) pay_bank_amt ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND p.pay_type_id = 4 ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[19])
-- GET vipcard summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_vipcard_cnt, IFNULL(SUM(p.pay_amt), 0) pay_vipcard_amt ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND (p.pay_type_id = 5 OR p.pay_type_id = 6) ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[20])
-- GET othpay summary
table.insert(sql, string.format(
[[SELECT IFNULL(COUNT(p.order_no), 0) pay_othpay_cnt, IFNULL(SUM(p.pay_amt), 0) pay_othpay_amt ]]..
[[FROM node_payment p, node_saleorder s ]]..
[[WHERE p.order_no = s.order_no ]]..
[[AND DATE(p.create_time) = DATE('%s') ]]..
[[AND p.pay_type_id = 9 ]].. -- paytype
[[AND p.shop_map_id = %s ]]..
[[AND s.order_status = 0;]],
os.date("%Y%m%d", total_time-24*60*60),
tostring(shop.shop_map_id))
)
-- log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " .. sql[21])
res, err, errcode, sqlstate = db_biz:query(table.concat(sql))
log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: ", sql[1])
......@@ -433,13 +361,45 @@ local function sdt_sql(tk_biz, tk_control, total_time)
end
if #res ~= 0 then
-- GET different paytype summary
if res[1]["pay_type_id"] then
local pay_tmp_amt = res[1]["pay_tmp_amt"]
local pay_tmp_cnt = res[1]["pay_tmp_cnt"]
local paytype = res[1]["pay_type_id"]
if paytype == 1 then
shop["pay_cash_amt"] = pay_tmp_amt
shop["pay_cash_cnt"] = pay_tmp_cnt
elseif paytype == 2 then
shop["pay_wx_amt"] = pay_tmp_amt
shop["pay_wx_cnt"] = pay_tmp_cnt
elseif paytype == 3 then
shop["pay_alipay_amt"] = pay_tmp_amt
shop["pay_alipay_cnt"] = pay_tmp_cnt
elseif paytype == 4 then
shop["pay_bank_amt"] = pay_tmp_amt
shop["pay_bank_cnt"] = pay_tmp_cnt
elseif paytype == 5 or paytype == 6 then
shop["pay_vipcard_amt"] = pay_tmp_amt
shop["pay_vipcard_cnt"] = pay_tmp_cnt
elseif paytype == 9 then
shop["pay_othpay_amt"] = pay_tmp_amt
shop["pay_othpay_cnt"] = pay_tmp_cnt
end
end
for k, v in pairs(res[1]) do
if k ~= "pay_tmp_amt" and k ~= "pay_tmp_cnt" and k ~= "pay_type_id" then
shop[k] = v
end
end
j = j + 1
end
-- until(err ~= "again")
end
-- DETAIL data
log_lua:log(log_lua:__FILE__() .. ":" .. log_lua:__LINE__(), "NOTICE: " ..
string.format("================ TK_SDT [%s - %s] ==========",
tostring(shop['shop_map_id']),
......@@ -588,7 +548,6 @@ local function sdt_sql(tk_biz, tk_control, total_time)
-- return
end
-- table.insert(shops, shop)
break
end
......
......@@ -4,8 +4,8 @@ require ('luainit.db_conf')
-- custom base module
_G.zx_base = _G.zx_base or require('luabiz.zx_base')
-- settle module
_G.settle = _G.settle or require('luabiz.settle')
-- -- settle module
-- _G.settle = _G.settle or require('luabiz.settle')
-- settle detail
_G.tk_sync = _G.tk_sync or require('luabiz.tk_sync')
......
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