from lib.all import * service_name = 'fix_diamonds' log_dir = '/app/log' logger = Logger(service_name, log_dir=log_dir) class S: def __init__(self): self.mysql_db_vas = Mysql( "rm-bp11t1616a1kjvmx5.mysql.rds.aliyuncs.com", 3306, "vas", "root", "Wishpal2024" ) def __del__(self): self.mysql_db_vas.close() def get_mid_now_dias_wdias(self, mid): sql = "select * from vas_wallet where id=%d" % mid docs = self.mysql_db_vas.query(sql) if len(docs) > 0: doc = docs[0] return safe_get_int(doc, "diamonds"), safe_get_int(doc, "withdraw_diamonds") return 0, 0 # 获取mid: 钻石 def get_mid_dias(self): sql = "select mid, sum(`change`) as dias from vas_ch_income group by mid" docs = self.mysql_db_vas.query(sql) logger.Info("get_mid_dias docs: {}".format(docs)) return docs # 获取mid: 已提现的钻石 def get_mid_wdias(self): sql = "select mid, sum(`withdraw_dias`) as wdias from vas_withdraw_order group by mid" docs = self.mysql_db_vas.query(sql) logger.Info("get_mid_wdias docs: {}".format(docs)) return docs def proc(self): docs_wdias = self.get_mid_wdias() mid_wdias_map = dict() for dw in docs_wdias: mid = safe_get_int(dw, "mid") wdias = safe_get_int(dw, "wdias") mid_wdias_map[mid] = wdias docs_dias = self.get_mid_dias() for dd in docs_dias: mid = safe_get_int(dd, "mid") all_dias = safe_get_int(dd, "dias") wdias = safe_get_int(mid_wdias_map, mid) now_dias, now_wdias = self.get_mid_now_dias_wdias(mid) # logger.Info("mid:{}, 总钻石:{}, 背包钻石:{}, 钻石差:{}, 背包提现钻石:{}, 已提现钻石:{}".format(mid, all_dias, now_dias, all_dias - now_dias, now_wdias, wdias)) logger.Info("mid:{}, 背包钻石:{}, 修改后的背包钻石:{}, 背包提现钻石:{}".format(mid, all_dias, all_dias - wdias, now_wdias)) new_dias = all_dias - wdias update_sql = '''update vas_wallet set diamonds={} where id={}'''.format(new_dias, mid) logger.Info("update_sql: {}".format(update_sql)) ret = self.mysql_db_vas.exec(update_sql, ()) logger.Info("sql_ret: {}".format(ret)) s = S() s.proc()