ck 4 years ago
parent
commit
9456d7be04

+ 30 - 11
app/api_data/get_order.py

@@ -3,6 +3,8 @@ from model.DataBaseUtils import MysqlUtils
 from concurrent.futures import ThreadPoolExecutor
 from model.DingTalkUtils import DingTalkUtils
 from app.api_data.platform_order.audio_qiyue import AudioQiyue
+from app.api_data.platform_order.youshuge import get_youshuge_order_task
+from app.api_data.platform_order.yuewen import get_yuewen_order_task
 
 db = MysqlUtils()
 
@@ -81,7 +83,7 @@ def huasheng(start=None, end=None, new=None):
         if not channel_data:
             continue
         else:
-            print(f"账号:{account[2]} 有channel{len(channel_data)}个")
+            print(f"花生账号:{account[2]} 有channel{len(channel_data)}个")
         for merchant in channel_data:
             executor.submit(get_huasheng_order_task, start, end, account, merchant, li)
     executor.shutdown(True)
@@ -128,7 +130,8 @@ def zhangdu(start=None, end=None, new=None):
 
 def zhangzhongyun(start=None, end=None, new=None):
     if start is None:
-        start = end = du.getNow()
+        start = du.getNow()
+        end = du.get_n_days(1)
 
     executor = ThreadPoolExecutor(max_workers=5)
     accounts = get_account("掌中云") if new is None else get_new_account('掌中云')
@@ -141,25 +144,25 @@ def zhangzhongyun(start=None, end=None, new=None):
     executor.shutdown()
 
 
-def yueweng(start=None, end=None, new=None):
+def yueweng(start=None, end=None):
     if start is None:
         start = end = du.getNow()
 
     executor = ThreadPoolExecutor(max_workers=5)
-    accounts = get_account("阅文") if new is None else get_new_account('阅文')
+    accounts = get_account("阅文")
     if len(accounts) == 0:
         return
     else:
         print(f'阅文有账号{len(accounts)}个')
     for account in accounts:
-        executor.submit(get_yueweng_order_task, start, end, account)
+        executor.submit(get_yuewen_order_task, start, end, account)
     executor.shutdown()
 
 
-def qiyueyousheng(start=None, end=None, new=None):
+def qiyueyousheng(start=None, end=None):
     if start is None:
         start = end = du.getNow()
-    accounts = get_account("七悦有声") if new is None else get_new_account('七悦有声')
+    accounts = get_account("七悦有声")
     if len(accounts) == 0:
         return
     else:
@@ -168,20 +171,34 @@ def qiyueyousheng(start=None, end=None, new=None):
         AudioQiyue().get_order(start, end, account)
 
 
+def youshuge(start=None, end=None):
+    if start is None:
+        start = end = du.getNow()
+
+    executor = ThreadPoolExecutor(max_workers=5)
+    accounts = get_account("悠书阁")
+    if len(accounts) == 0:
+        return
+    else:
+        print(f'悠书阁有账号{len(accounts)}个')
+    for account in accounts:
+        executor.submit(get_youshuge_order_task, start, end, account)
+    executor.shutdown()
+
 def hourly():
     # try:
     #     yangguang()
     # except:
     #     pass
-    st = du.get_n_days(0)
-    et = du.get_n_days(1)
 
     huasheng()
     qiyue()
     qiyueyousheng()
     wending()
     zhangdu()
-    zhangzhongyun(st, et)
+    zhangzhongyun()
+    yueweng()
+    youshuge()
 
 
 def daily():
@@ -218,4 +235,6 @@ if __name__ == '__main__':
 
     # zhangdu('2020-11-01', '2020-12-20')
 
-    zhangzhongyun('2021-04-01', '2021-04-21')
+    # zhangzhongyun('2021-04-01', '2021-04-21')
+    # youshuge()
+    yueweng()

+ 3 - 2
app/api_data/order_util.py

@@ -483,6 +483,7 @@ def get_zd_order_task(start,end,account):
 
 
 def get_zzy_order_task(start, end, account):
+
     url = 'https://inovel.818tu.com/partners/channel/channels/list?'
     key = account[0]
     secert = account[1]
@@ -574,8 +575,8 @@ def get_zzy_channel_order(start, end, account, channel):
     return order_list
 
 
-def get_yueweng_order_task(start, end, account):
-    pass
+
+
 
 if __name__ == '__main__':
     get_qiyue_order_task('2021-02-01','2021-02-19',['趣程15期','eyJpdiI6ImluVWxoRUl3VTR6QU5hamlYOFBvXC9BPT0iLCJ2YWx1ZSI6Ik5IZ0N4dm5GcmJ0Zklsd0tNZ1JVSVE9PSIsIm1hYyI6IjJjODUzMjdlZTc2ODI2ZjFmY2QyYmU5MGViYTkzOGU4MDEwZTIyODIxOTE4NzgzYTNhOGQ1YWM4OGJkMDAzMmIifQ=='])

+ 70 - 0
app/api_data/platform_order/youshuge.py

@@ -0,0 +1,70 @@
+import time
+from model.DateUtils import DateUtils
+from model.ComUtils import md5
+import requests
+from model.DataBaseUtils import MysqlUtils
+db = MysqlUtils()
+ut = DateUtils()
+
+def get_youshuge_order_task(st, et, account):
+
+    et = ut.add_days(et,1)
+    url = 'https://novel.youshuge.com/v2/open/orders'
+    host_name = account[0]
+    channel_id = int(account[1])
+    secert_key = account[2]
+    channel = account[3]
+    stage = account[4]
+    page = 1
+
+    li = []
+    while True:
+
+        timestamp = int(time.time())
+        sign = md5('channel_id=' + str(channel_id) + '&end_date=' + et + '&host_name=' + host_name + '&page='
+                   + str(page) + '&start_date=' + st + '&time=' + str(
+            timestamp) + '&key=' + secert_key).upper()
+        params = {
+            'sign': sign,
+            'host_name': host_name,
+            'time': timestamp,
+            'channel_id': channel_id,
+            'page': page,
+            'start_date': st,
+            'end_date': et
+        }
+        r = requests.post(url, params).json()
+        # print(r)
+
+        order_item_list = r['data']
+        if len(order_item_list) == 0:
+            break
+
+        for i in order_item_list:
+            li.append((i["create_time"][:10],
+                       stage,
+                       '悠书阁',
+                       channel,
+                       channel_id,
+                       i['openid'],
+                       i["create_time"],
+                       i['reg_time'],
+                       int(i['price'])/100,
+                       i['book_name'],
+                       i['order_num'],
+                       2 if i['pay_status'] == '1' else 1
+            ))
+
+        page += 1
+
+    if len(li) > 0:
+        print(f"{channel} 有订单{len(li)}")
+        db = MysqlUtils()
+        db.quchen_text.executeMany("replace into ods_order values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",li)
+
+
+if __name__ == '__main__':
+    a = "趣程15期,10696,8OC7SNCL46ZEI7JBACXFDM8CP5JM1FSL,盛德文苑,趣程15期"
+    get_youshuge_order_task('2021-01-06', '2021-05-06', a.split(','))
+
+

+ 104 - 0
app/api_data/platform_order/yuewen.py

@@ -0,0 +1,104 @@
+import time
+from model.DateUtils import DateUtils
+from model.ComUtils import md5
+import requests
+from model.DataBaseUtils import MysqlUtils
+ut = DateUtils()
+
+def get_yuewen_order_task(st, et, account):
+    """相同参数一分钟只能调用一次"""
+    email = account[0]
+    appsecert = account[1]
+
+    url = 'https://open.yuewen.com/cpapi/wxRecharge/querychargelog'
+
+    start_time = DateUtils.str_to_stamp(st)
+    # 结束时间不能超过当前的时间戳
+    if et == ut.getNow():
+        end_time = DateUtils.str_to_stamp(ut.get_n_hours_ago(), "%Y-%m-%d %H:%M:%S")
+    else:
+        end_time = DateUtils.str_to_stamp(et) + 86399
+    page = 1
+    last_min_id = ''
+    last_max_id = ''
+    total_count = ''
+    last_page = ''
+
+    li = []
+    while True:
+
+        params = {
+            'email': email,
+            'timestamp': int(time.time()),
+            'start_time': start_time,
+            'end_time': end_time,
+            'page': page,
+            'version':1
+        }
+
+        if page > 1:
+            params['last_min_id'] = last_min_id
+            params['last_max_id'] = last_max_id
+            params['total_count'] = total_count
+            params['last_page'] = last_page
+
+        sorted_data = sorted(params.items())
+        str_params = ''
+        for k, v in sorted_data:
+            str_params = str_params + str(k) + str(v)
+
+        sign = md5(appsecert + str_params).upper()
+
+        # 放入签名
+        params['sign'] = sign
+        # print(params)
+        response_result_json = requests.get(url=url, params=params).json()
+        # print(response_result_json)
+
+        # print(len(response_result_json["data"]["list"]))
+
+
+
+        response_data = response_result_json['data']
+        total_count = response_data['total_count']
+
+
+        last_min_id = response_data['min_id']
+        last_max_id = response_data['max_id']
+        last_page = response_data['page']
+        order_item_list = response_data['list']
+
+        if len(order_item_list) == 0:
+            break
+
+        for i in order_item_list:
+            order_time = i["order_time"]
+            li.append((order_time[:10],
+                       '',
+                       '阅文',
+                       i['app_name'],
+                       i['channel_id'],
+                       i['openid'],
+                       i['order_time'],
+                       i['reg_time'],
+                       i['amount'],
+                       i['book_name'],
+                       i['order_id'],
+                       i['order_status']
+            ))
+
+        if len(order_item_list) < 100:
+            break
+        else:
+            page += 1
+
+    if len(li) > 0:
+        print(f"{email} 有订单{len(li)}")
+        db = MysqlUtils()
+        db.quchen_text.executeMany("replace into ods_order values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",li)
+
+
+
+if __name__ == '__main__':
+    a = "mqud82950@163.com,74ca754515fa253c8ab790603cebc2ee"
+    get_yuewen_order_task('2021-05-06', '2021-05-06', a.split(','))

+ 8 - 0
app/etl/channel_info_snapshot.py

@@ -0,0 +1,8 @@
+"""公众号快照信息
+"""
+from model.DataBaseUtils import MysqlUtils
+
+db = MysqlUtils()
+
+def run():
+    sql = "select id,"

+ 3 - 3
app/etl/sync_to_ck_task.py

@@ -11,7 +11,7 @@ dt = DateUtils()
 
 def order_sync_ck(ymd):
     log.debug("sync order")
-    col = "date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id"
+    col = "date,stage,platform,channel,channel_id,user_id,order_time,reg_time,amount,from_novel,order_id,status"
     sql ="select * from ods_order where date='{}'".format(ymd)
     data = db.quchen_text.getData(sql)
 
@@ -70,9 +70,9 @@ def campaign_vx():
 
 
 if __name__ == '__main__':
-    # order_sync_ck('2020-11-03')
+    order_sync_ck('2021-05-06')
     # dw_order_channel_cost_sync_ck(dt.get_n_days(-2))
     # for i in dt.getDateLists('2019-03-18','2020-12-17'):
     # #     order(i)
     #     dw_order_channel_sync_ck(i)
-    print(ck.getColumns(f"dw_daily_channel_cost"))
+    # print(ck.getColumns(f"dw_daily_channel_cost"))

+ 2 - 1
model/DateUtils.py

@@ -343,4 +343,5 @@ class DateUtils:
 if __name__ == "__main__":
 
     ut = DateUtils()
-    print(DateUtils.str_to_date_str('2012-02-01',f2="%Y-%m-%dT%H:%M:%S+08:00"))
+    # print(DateUtils.str_to_date_str('2012-02-01',f2="%Y-%m-%dT%H:%M:%S+08:00"))
+    print(ut.today)