ck 3 năm trước cách đây
mục cha
commit
5a42bf8e01

+ 1 - 88
app/api_data/platform_order/order_util.py

@@ -15,95 +15,8 @@ db=MysqlUtils()
 du=DateUtils()
 
 
-def get_yg_vip_channel(stage, vip_id, client_id, token):
-    url = "https://data.yifengaf.cn:443/channeldata/data/account/list"
-    nonce = ComUtils.get_random_str()
-    timestamp = int(time.time())
-    signaure = ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
-    params = {
-        "client_id": client_id,
-        "token": token,
-        "nonce": nonce,
-        "timestamp": timestamp,
-        "signaure": signaure,
-        "vip_id": vip_id,
-    }
-    headers = {"Content-Type": "application/json"}
-    r = requests.post(url=url, data=json.dumps(params), headers=headers)
-    print(r.text)
-    task_id = json.loads(r.text).get("data").get("task_id")
-    db.quchen_text.execute(
-        f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','channel')")
-
-
-def get_yg_data(stage,vip_id,client_id,token,start,end):
-    url = "https://data.yifengaf.cn:443/channeldata/data/orders/list"
-    nonce=ComUtils.get_random_str()
-    timestamp=int(time.time())
-    signaure =ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
-    params = {
-        "client_id": client_id,
-        "token": token,
-        "nonce": nonce,
-        "timestamp": timestamp,
-        "signaure": signaure,
-        "vip_id": vip_id,
-        "start_time":start,   # %Y-%m-%d %H:%i:%s:
-        "end_time":end
-    }
-    headers={"Content-Type":"application/json"}
-    r=requests.post(url=url,data=json.dumps(params),headers=headers)
-    print(r.text)
-    task_id = json.loads(r.text).get("data").get("task_id")
-    db.quchen_text.execute(f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','order')")
-
-
-def parse_yg_data(vip_id,stage):
-    url = db.quchen_text.getOne(f"select path from yangguang_path where type='channel' and vip_id={vip_id} ")
-    r = requests.get(url).text
-    channel_di={}
-    a = r.split('}')
-    for i in a[:-1]:
-        if i[-1] != '}':
-            b=json.loads(i + "}", strict=False)
 
-        else:
-            b=json.loads(i, strict=False)
-        channel_di[b["channel_id"]]=b["wx_nickname"]
-    # print(channel_di)
-    print(f'{stage} 有channel数:{len(channel_di)}')
-
-    info=db.quchen_text.getData(f"select stage,path from yangguang_path where type='order' and vip_id={vip_id}")
-    stage=info[0][0]
-    path=info[0][1]
-    text=requests.get(path).text.replace('"referral_url":,','')
-
-    insert_data=[]
-    for j in text.split("}")[:-1]:
-        if j[-1] != '}':
-            j=j+'}'
-        try:
-            di=json.loads(j, strict=False)
-        except Exception as e:
-            print(j)
-            print(e)
-
-        platform = "阳光"
-        channel_id = di["channel_id"]
-        channel=channel_di[channel_id]
-        user_id = di["openid"]
-        order_time = di["create_time"]
-        reg_time = di["user_createtime"]
-        from_novel = di["book_name"] if di['book_name'] else ''
-        amount = di["money"]
-        order_id = di["transaction_id"] if  di["transaction_id"] else di['merchant_id']
-        status = 2 if  di['state']=="完成" else 1
-        date = order_time[:10]
-        insert_data.append((date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id,status))
-    print(insert_data)
-    # exit(0)
-    print("订单数:"+ str(insert_data.__len__()))
-    save_order(insert_data)
+
 
 
 def get_hs_order_task(start, end, account):

+ 161 - 10
app/api_data/platform_order/yangguang.py

@@ -1,7 +1,10 @@
-from app.api_data.platform_order.order_util import *
 from model.DataBaseUtils import MysqlUtils
 from model.DingTalkUtils import DingTalkDecorators,DingTalkUtils
 from model.DateUtils import DateUtils
+from model import ComUtils
+import time
+import json
+import requests
 db = MysqlUtils()
 du = DateUtils()
 
@@ -34,7 +37,49 @@ def yangguang(start=None, end=None):
         get_yg_data(stage, vip_id, client_id, token, start, end)
 
     print(check())
-    parse_data()
+    parse_order_data()
+
+def get_yg_data(stage,vip_id,client_id,token,start,end):
+    url = "https://data.yifengaf.cn:443/channeldata/data/orders/list"
+    nonce=ComUtils.get_random_str()
+    timestamp=int(time.time())
+    signaure =ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
+    params = {
+        "client_id": client_id,
+        "token": token,
+        "nonce": nonce,
+        "timestamp": timestamp,
+        "signaure": signaure,
+        "vip_id": vip_id,
+        "start_time":start,   # %Y-%m-%d %H:%i:%s:
+        "end_time":end
+    }
+    headers={"Content-Type":"application/json"}
+    r=requests.post(url=url,data=json.dumps(params),headers=headers)
+    print(r.text)
+    task_id = json.loads(r.text).get("data").get("task_id")
+    db.quchen_text.execute(f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','order')")
+
+
+def get_yg_vip_channel(stage, vip_id, client_id, token):
+    url = "https://data.yifengaf.cn:443/channeldata/data/account/list"
+    nonce = ComUtils.get_random_str()
+    timestamp = int(time.time())
+    signaure = ComUtils.sha1(str(token) + str(timestamp) + str(client_id) + str(nonce))
+    params = {
+        "client_id": client_id,
+        "token": token,
+        "nonce": nonce,
+        "timestamp": timestamp,
+        "signaure": signaure,
+        "vip_id": vip_id,
+    }
+    headers = {"Content-Type": "application/json"}
+    r = requests.post(url=url, data=json.dumps(params), headers=headers)
+    print(r.text)
+    task_id = json.loads(r.text).get("data").get("task_id")
+    db.quchen_text.execute(
+        f"replace into yangguang_path(vip_id,task_id,stage,type) values ('{vip_id}','{task_id}','{stage}','channel')")
 
 
 def get_channel_info():
@@ -48,7 +93,7 @@ def get_channel_info():
         get_yg_vip_channel(stage, vip_id, client_id, token)
 
 
-def parse_data():
+def parse_order_data():
     print(111)
     accounts = get_account("阳光")
 
@@ -56,7 +101,74 @@ def parse_data():
         # print(i)
         vip_id = i[1]
         stage = i[0]
-        parse_yg_data(vip_id, stage)
+        data = parse_order(vip_id, stage)
+        save_data(data)
+
+def parse_order(vip_id,stage):
+    url = db.quchen_text.getOne(f"select path from yangguang_path where type='channel' and vip_id={vip_id} ")
+    r = requests.get(url).text
+
+    channel_di={}
+    a = r.split('}')
+    for i in a[:-1]:
+        if i[-1] != '}':
+            b=json.loads(i + "}", strict=False)
+
+        else:
+            b=json.loads(i, strict=False)
+        channel_di[b["channel_id"]]=(b["wx_nickname"],b['app_id'])
+
+    # print(channel_di)
+    print(f'{stage} 有channel数:{len(channel_di)}')
+
+    info=db.quchen_text.getData(f"select stage,path from yangguang_path where type='order' and vip_id={vip_id}")
+    stage=info[0][0]
+    path=info[0][1]
+    text=requests.get(path).text.replace('"referral_url":,','')
+    # print(text)
+
+    insert_data=[]
+    for j in text.split("}")[:-1]:
+        if j[-1] != '}':
+            j=j+'}'
+        try:
+            di=json.loads(j, strict=False)
+        except Exception as e:
+            print(j)
+            print(e)
+
+        insert_data.append((
+            di["create_time"][:10],
+            stage,
+            '阳光',
+            channel_di[di['channel_id']][0],
+            di['channel_id'],
+            di['openid'],
+            di['create_time'],
+            di['user_createtime'],
+            di['money'],
+            di.get('book_name'),
+            di['merchant_id'],
+            2 if di['state']=="完成" else 1,
+            di['user_id'],
+            channel_di[di['channel_id']][1],
+            1 if di['type'] == '书币充值' else 2,
+            di['merchant_id'],
+            di['transaction_id']
+        ))
+    # print(insert_data)
+    # exit(0)
+    print("订单数:"+ str(insert_data.__len__()))
+    save_data(insert_data)
+
+
+def save_data(data):
+    sql = """replace into ods_order(date,stage,platform,channel,channel_id,user_id,order_time,
+    reg_time,amount,from_novel,order_id,status,platform_user_id,wechat_app_id,order_type,
+    trade_no,transaction_no) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) """
+    # print(sql)
+
+    db.quchen_text.executeMany(sql,data)
 
 
 def check():
@@ -85,20 +197,59 @@ def get_account(plactform, id=None):
         new_data.append(i[0].replace('\n', '').split(","))
     return new_data
 
+def get_yg_user_info():
+    """获取阳光的用户信息"""
+    accounts = get_account("阳光")
+    # if start:
+    #     start = start + ' 00:00:00'
+    #     end = end + ' 23:59:59'
+    # else:
+    #     start = du.getTodayOrYestoday() + ' 00:00:00'
+    #     end = du.get_n_hours_ago(0)
+
+    client_id = 10008097
+    token = '2xa1d55tTPBjeEA8Ho'
+
+    if accounts.__len__() == 0:
+        return
+    else:
+        print(f"阳光账号数:{accounts.__len__()}")
+
+    for i in accounts:
+        stage = i[0]
+        vip_id = i[1]
+        print(vip_id)
+        # get_yg_vip_channel(stage, vip_id, client_id, token)
+        get_yg_data(stage, vip_id, client_id, token, start, end)
+
+    print(check())
+    # parse_data()
+
+
+
+
+
 def daily_yg():
     st = du.get_n_days(-10)
     et = du.get_n_days(-1)
     yangguang(st, et)
 
+
+
+
+
 if __name__ == '__main__':
 
     # get_channel_info()
     # exit(0)
     # yangguang('2020-09-20','2020-10-01')
-    # exit(0)
-
-    for i in du.split_date2('2020-06-28','2020-11-03',30):
-        print(i)
-        yangguang(i[0], i[1])
-
+    # # exit(0)
+    # yangguang('2021-05-28','2021-05-28')
+    # daily_yg()
+    # for i in du.split_date2('2020-06-28','2020-11-03',30):
+    #     print(i)
+    #     yangguang(i[0], i[1])
+
+    # parse_order_data()
+    yangguang()