|
@@ -7,69 +7,51 @@ ck = CkUtils()
|
|
|
db = MysqlUtils()
|
|
|
du = DateUtils()
|
|
|
import time
|
|
|
-def run_all(y=0):
|
|
|
- x =100000
|
|
|
-
|
|
|
- while True:
|
|
|
- print((y+1)*x)
|
|
|
-
|
|
|
- sql = f"""
|
|
|
- select channel,
|
|
|
- user_id open_id,
|
|
|
- platform platform_book_name,
|
|
|
- count(1) recharge_count,
|
|
|
- sum(amount) recharge_money,
|
|
|
- max(order_time) last_recharge_time
|
|
|
-
|
|
|
- from order where status=2
|
|
|
- group by channel,user_id,platform limit {y*x},{(y+1)*x}"""
|
|
|
- col = ['channel','open_id','platform_book_name','recharge_count','recharge_money','last_recharge_time']
|
|
|
- df = ck.getData_pd(sql,col=col)
|
|
|
- if df.empty:
|
|
|
- break
|
|
|
- # print(df)
|
|
|
- df_channel = get_qc_channel_info()
|
|
|
- result = pd.merge(df,df_channel,how='left',on='channel').fillna(0)
|
|
|
- save_data(result)
|
|
|
- y += 1
|
|
|
-
|
|
|
-def run_today():
|
|
|
- sql = f"""
|
|
|
- select channel,
|
|
|
- user_id open_id,
|
|
|
- platform platform_book_name,
|
|
|
- count(1) recharge_count,
|
|
|
- sum(amount) recharge_money,
|
|
|
- max(order_time) last_recharge_time
|
|
|
-
|
|
|
- from order where status=2 and user_id in (select distinct user_id from order where date='{du.getNow()}')
|
|
|
- group by channel,user_id,platform"""
|
|
|
- col = ['channel', 'open_id', 'platform_book_name', 'recharge_count', 'recharge_money', 'last_recharge_time']
|
|
|
- df = ck.getData_pd(sql, col=col)
|
|
|
- # print(df)
|
|
|
- df_channel = get_qc_channel_info()
|
|
|
- result = pd.merge(df, df_channel, how='left', on='channel')
|
|
|
- save_data(result)
|
|
|
-
|
|
|
|
|
|
def save_data(df):
|
|
|
table = 't_mp_fans'
|
|
|
keys = ['mp_id', 'open_id']
|
|
|
- tags = ['recharge_count', 'recharge_money', 'last_recharge_time', 'platform_book_name']
|
|
|
+ tags = ['recharge_count', 'recharge_money', 'last_recharge_time',
|
|
|
+ 'platform_book_name', 'platform_book_user_id', 'members', 'book_coin','channel_id']
|
|
|
db.zx.dfUpdate2mysql(df, table, keys, tags)
|
|
|
|
|
|
|
|
|
|
|
|
+def QiyueUserInfo():
|
|
|
+ # 书城用户信息
|
|
|
+ sql1 = """select
|
|
|
+ user_id platform_book_user_id,
|
|
|
+ open_id,
|
|
|
+ channel_id,
|
|
|
+ wechat_app_id ,
|
|
|
+ coin+free_coin book_coin,
|
|
|
+ if(vip_endtime=0,0,1) members from platform_user_info where platform='七悦'"""
|
|
|
+
|
|
|
+ df1 = db.quchen_text.getData_pd(sql1)
|
|
|
+
|
|
|
+ # 用户订单信息
|
|
|
+ sql2 = """select channel_id,
|
|
|
+ user_id open_id,
|
|
|
+ count(1) recharge_count,
|
|
|
+ sum(amount) recharge_money,
|
|
|
+ max(order_time) last_recharge_time
|
|
|
+ from order where status=2 and platform='七悦'
|
|
|
+ group by channel_id,user_id"""
|
|
|
+
|
|
|
+ df2 = ck.getData_pdv2(sql2)
|
|
|
|
|
|
-def get_qc_channel_info():
|
|
|
- sql ="""select cast(id as char) mp_id,nick_name channel from t_mp_account"""
|
|
|
- df = db.zx.getData_pd(sql)
|
|
|
- return df
|
|
|
- # print(df)
|
|
|
+ # 查询公众号在本地的id
|
|
|
+ sql3 = """select cast(id as char) mp_id,appid wechat_app_id from t_mp_account"""
|
|
|
+ df3 = db.zx.getData_pd(sql3)
|
|
|
|
|
|
+ df = df1.merge(df2,how='left',on=['channel_id','open_id']).merge(df3,how='left',on='wechat_app_id')
|
|
|
+ df['platform_book_name'] = '七悦'
|
|
|
+ print(df)
|
|
|
+ save_data(df)
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# run_today()
|
|
|
# get_qc_channel_info()
|
|
|
- run_all(10)
|
|
|
+ # run_all(19)
|
|
|
+ QiyueUserInfo()
|