2024-05-08 22:40:09 +08:00
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 (
2024-07-22 11:54:48 +08:00
" 172.31.37.71 " , 3306 , " bi " , " root " , " Wishpal@2023 "
2024-05-08 22:40:09 +08:00
)
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 )
2024-08-01 20:47:11 +08:00
flow = 0
2024-05-08 22:40:09 +08:00
if len ( rows ) > 0 :
2024-08-01 20:47:11 +08:00
flow = safe_get_int ( rows [ 0 ] , " flow " )
2024-08-01 21:02:13 +08:00
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 )
2024-08-01 20:47:11 +08:00
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
2024-05-08 22:40:09 +08:00
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 ( )