scripts/bi/vas_day_flow.py

62 lines
2.0 KiB
Python

import time
from lib.all import *
import datetime
# 日流水
class S:
def __init__(self):
self.mysql_db_vas = Mysql(
"rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com", 3306, "vas", "root", "Wishpal2024"
)
self.mysql_db_bi = Mysql(
"172.31.37.71", 3306, "bi", "root", "Wishpal@2023"
)
def __del__(self):
self.mysql_db_vas.close()
self.mysql_db_bi.close()
def get_day_flow(self):
st = get_today_zero_time()
et = st + 86400
sql = '''select sum(pay_amount) flow from vas_order where ct>={} and ct<{} and order_status in (1,2);'''.format(st, et)
rows = self.mysql_db_vas.query(sql)
flow = 0
if len(rows) > 0:
flow = safe_get_int(rows[0], "flow")
sql_except = '''select sum(pay_amount) flow from vas_order where ct>={} and ct<{} and order_status in (1,2) and product_id in ('outer_raven');'''.format(st, et)
rows_except = self.mysql_db_vas.query(sql_except)
flow_except = 0
if len(rows_except) > 0:
flow_except = safe_get_int(rows_except[0], "flow")
print("flow: {}, flow_except: {}".format(flow, flow_except))
return flow - flow_except
def update_day_flow(self, flow):
t = get_today_zero_time()
dt = datetime.datetime.fromtimestamp(t)
formatted_dt = dt.strftime('%Y-%m-%d 00:00:00')
sql_q = "select * from vas_day_flow where pdate='{}'".format(get_time_str_by_ts(t))
rows = self.mysql_db_bi.query(sql_q)
if len(rows) > 0:
sql_u = "update vas_day_flow set flow=%s where pdate=%s"
return self.mysql_db_bi.exec(sql_u, (flow, formatted_dt))
else:
sql_i = "insert into vas_day_flow (pdate, flow) values (%s,%s)"
return self.mysql_db_bi.exec(sql_i, (formatted_dt, flow))
def proc(self):
flow = self.get_day_flow()
self.update_day_flow(flow)
print(flow)
s = S()
s.proc()