scripts/vas/calc_coins.py

53 lines
1.6 KiB
Python

from lib.all import *
mysql_db_vas = Mysql(
"rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com", 3306, "vas", "root", "Wishpal2024"
)
# mid充值数
mid_charge_map = dict()
mid_charge_list = mysql_db_vas.query('''
select mid, sum(coins) total_coins from vas_order
where order_status>0 and product_id in ('h5_custom_coin', 'h5_coin_500', 'h5_coin_1000', 'h5_coin_3000', 'h5_coin_5000', 'h5_coin_8000', 'h5_coin_10000', 'h5_coin_15000', 'h5_coin_18000', 'h5_coin_20000', 'h5_contact_wechat')
group by mid
''')
for item in mid_charge_list:
mid = safe_get_int(item, "mid")
total_coins = safe_get_int(item, "total_coins")
mid_charge_map[mid] = total_coins
# mid消费
mid_consume_map = dict()
mid_consume_list = mysql_db_vas.query('''
select mid, sum(coins) total_coins from vas_coin_order
where order_status>0
group by mid
''')
for item in mid_consume_list:
mid = safe_get_int(item, "mid")
total_coins = safe_get_int(item, "total_coins")
mid_consume_map[mid] = total_coins
# mid钱包
# mid消费
mid_wallet_map = dict()
mid_wallet_list = mysql_db_vas.query('''
select id, sum(coins) total_coins from vas_wallet
where coins>0
group by id
''')
for item in mid_wallet_list:
mid = safe_get_int(item, "id")
total_coins = safe_get_int(item, "total_coins")
mid_wallet_map[mid] = total_coins
mids = list(set(
list(mid_charge_map.keys()) + list(mid_consume_map.keys()) + list(mid_wallet_map.keys())
))
for mid in mids:
charge = safe_get_int(mid_charge_map, mid)
consume = safe_get_int(mid_consume_map, mid)
wallet = safe_get_int(mid_wallet_map, mid)
if charge != consume + wallet:
print(mid, charge, consume, wallet)