Commit 795f69fd authored by xupeng's avatar xupeng

过滤查询修改

parent 2c77d17e
...@@ -93,11 +93,11 @@ class RechargeStatement(object): ...@@ -93,11 +93,11 @@ class RechargeStatement(object):
if end_time: if end_time:
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month[0]) count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month[1])
else: else:
query_data = self.query_add_time(start_time, end_time, query) query_data = self.query_add_time(start_time, end_time, query)
count, once_res, moeny_data = self.thread_data(month_type, query_data, page, size) count, once_res, moeny_data = self.thread_data(month_type, query_data, page, size,start_time)
return count, once_res, moeny_data return count, once_res, moeny_data
def query_add_time(self, start_time, end_time, old_query): def query_add_time(self, start_time, end_time, old_query):
...@@ -138,8 +138,8 @@ class RechargeStatement(object): ...@@ -138,8 +138,8 @@ class RechargeStatement(object):
self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0 self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0
return count, once_res, moeny_data/1000 return count, once_res, moeny_data/1000
def thread_data(self, month_type, query, page, size): def thread_data(self, month_type, query, page, size,start_time):
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month) count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month)
return count, once_res, moeny_data return count, once_res, moeny_data
...@@ -168,7 +168,7 @@ class RechargeStatement(object): ...@@ -168,7 +168,7 @@ class RechargeStatement(object):
if data.end_time: if data.end_time:
query.append(f" create_time < {time_str_to_timestamp(data.end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(data.end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(data.month_type) now_month = get_month_last_month(data.month_type,data.start_time)
once_res = self.data_delcy(data.month_type, query, now_month[1]) once_res = self.data_delcy(data.month_type, query, now_month[1])
else: else:
query_data = self.query_add_time(data.start_time, data.end_time) query_data = self.query_add_time(data.start_time, data.end_time)
...@@ -240,18 +240,17 @@ class WithdrawStatement(object): ...@@ -240,18 +240,17 @@ class WithdrawStatement(object):
if end_time: if end_time:
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1]) count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1])
else: else:
query_data = self.query_add_time(start_time, end_time) query_data = self.query_add_time(start_time, end_time)
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month) count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data return count, once_res, moeny_data
def dispose_user(self, month_type, query, page, size, now_month): def dispose_user(self, month_type, query, page, size, now_month):
if month_type == 1: if month_type == 1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}" count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}"
print(count_sql)
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
sql = f'SELECT uuid,a.reference_type,a.reference_number,FROM_UNIXTIME(a.create_time,"%Y-%c-%d %h:%i:%s") as payment_time,a.amount_type FROM assets_log_{now_month} as a where {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}' sql = f'SELECT uuid,a.reference_type,a.reference_number,FROM_UNIXTIME(a.create_time,"%Y-%c-%d %h:%i:%s") as payment_time,a.amount_type FROM assets_log_{now_month} as a where {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}'
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
...@@ -263,7 +262,8 @@ class WithdrawStatement(object): ...@@ -263,7 +262,8 @@ class WithdrawStatement(object):
count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)") count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)")
query1 = (' and '.join(query[0])) query1 = (' and '.join(query[0]))
query2 = (' and '.join(query[1])) query2 = (' and '.join(query[1]))
sql = f"SELECT id,uuid,amount,amount_type FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number,amount_type FROM assets_log_{int(now_month[1])} where {query2} ORDER BY id desc limit {(int(page) - 1) * size},{size}" sql = f"SELECT id,uuid,amount,amount_type, FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number,amount_type FROM assets_log_{int(now_month[1])} where {query2} ORDER BY id desc limit {(int(page) - 1) * size},{size}"
print(sql)
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
money_sql = f"SELECT sum(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))} ) AS a " money_sql = f"SELECT sum(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))} ) AS a "
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \ moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \
...@@ -293,11 +293,11 @@ class WithdrawStatement(object): ...@@ -293,11 +293,11 @@ class WithdrawStatement(object):
if end_time: if end_time:
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1]) count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1])
else: else:
query_data = self.query_add_time(start_time, end_time) query_data = self.query_add_time(start_time, end_time)
now_month = get_month_last_month(month_type) now_month = get_month_last_month(month_type,start_time)
count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month) count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data return count, once_res, moeny_data
......
...@@ -121,15 +121,16 @@ def get_ip(): ...@@ -121,15 +121,16 @@ def get_ip():
return res return res
def get_month_last_month(month_type): def get_month_last_month(month_type,start_time):
last_month=0 last_month=0
if month_type==2: if month_type==2:
month_date = datetime.now().date() - relativedelta(months=1) month_date = datetime.now().date() - relativedelta(months=1)
last_month = month_date.strftime("%Y%m") last_month = month_date.strftime("%Y%m")
now_month =datetime.now().strftime("%Y%m") now_month =datetime.now().strftime("%Y%m")
else:
now_month= ''.join(start_time.split('-')[0:2])
return last_month,now_month return last_month,now_month
def time_format(utc_timestamp: int): def time_format(utc_timestamp: int):
days = (utc_timestamp + 3600 * 8) % 86400 days = (utc_timestamp + 3600 * 8) % 86400
hours = int(days / 3600) hours = int(days / 3600)
......
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