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( "127.0.0.1", 3306, "metabase_bi", "metabase_bi", "Wishpal_2024" ) 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) if len(rows) > 0: return safe_get_int(rows[0], "flow") return 0 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()