renyupeng пре 1 година
родитељ
комит
be860f4fb4

+ 47 - 0
FastDistributionSpider/Handler.py

@@ -0,0 +1,47 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2024/1/8 下午1:58
+# @Site    : 
+# @File    : Handler.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import argparse
+import time
+from datetime import datetime, timedelta
+
+from FastDistributionSpider.PlatformClipOrderList import PlatformClipOrderList
+from FastDistributionSpider.PromoterOrderList import PromoterOrderList
+from utils.platform_cookie_update import platform_cookie_update
+
+
+class Handler:
+    @staticmethod
+    def get_args():
+        parser = argparse.ArgumentParser(description='')
+        parser.add_argument('-num', type=int, default=None, help="TX_DT")
+        args = parser.parse_args()
+        num = args.num
+        return num
+
+    @staticmethod
+    def request_plat():
+        num = Handler.get_args()
+        today = datetime.today()
+        enddate = int(time.time()*1000)
+        yesterday = (today - timedelta(days=num))
+        startdate = int(yesterday.timestamp()*1000)
+        cookie_one = platform_cookie_update.get_one_cookie_handler()
+        for cooikes in cookie_one:
+            cooike = cooikes[0]
+            name = cooikes[1]
+            PromoterOrderList.HandlerRequest(startdate, enddate, cooike, name)
+        cookie_two = platform_cookie_update.get_two_cookie_handler()
+        for childcookie in cookie_two:
+            cooike = childcookie[0]
+            name = childcookie[1]
+            PlatformClipOrderList.HandlerRequest(startdate, enddate, cooike, name)
+
+
+if __name__ == '__main__':
+    Handler.request_plat()

+ 130 - 0
FastDistributionSpider/PlatformClipOrderList.py

@@ -0,0 +1,130 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2024/1/4 上午9:55
+# @Site    : 
+# @File    : PlatformClipOrderList.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import datetime
+import json
+from math import ceil
+from time import sleep
+
+import requests
+
+from utils.mysql_helper import batch_insertPro
+from utils.mysql_utils_pro import MysqlProUtils
+
+
+class PlatformClipOrderList:
+    def __int__(self):
+        self.conn = MysqlProUtils()
+
+    @staticmethod
+    def HandlerRequest(startDate, endDate, cookie, name):
+        url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/clip/order/list?offset=0&limit=1&searchDelivered=0&orderCreateTimeStart={start_date}&orderCreateTimeEnd={end_date}&status=0".format(
+            start_date=startDate, end_date=endDate)
+        print(url)
+
+        payload = {}
+        headers = {
+            'Cookie': cookie,
+            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
+            'Accept': '*/*',
+            'Host': 'cps.kwaixiaodian.com',
+            'Connection': 'keep-alive'
+        }
+
+        response = requests.request("GET", url, headers=headers, data=payload)
+        data = json.loads(response.text)["data"]
+        print(data)
+        total_num = data["total"]
+        page = ceil(total_num / 200)
+        for i in range(page):
+            if i != 0:
+                print(i)
+                url = "https://cps.kwaixiaodian.com/gateway/distribute/platform/clip/order/list?offset={offset}&limit={total_num}&searchDelivered=0&orderCreateTimeStart={start_date}&orderCreateTimeEnd={end_date}&status=0".format(
+                    start_date=startDate, end_date=endDate, total_num=20 * i, offset=20 * (i - 1))
+                rep = requests.request("GET", url, headers=headers, data=payload)
+                if json.loads(rep.text)["result"] != 1:
+                    return
+                else:
+                    total_list = json.loads(rep.text)["data"]["list"]
+                    print(total_list)
+                    dataInfoList = []
+                    try:
+                        for dataInfo in total_list:
+                            print(dataInfo)
+                            oid = dataInfo["oid"]
+                            order_status = dataInfo["status"]
+                            order_create_time = dataInfo["orderCreateTime"]
+                            send_status = dataInfo["sendStatus"]
+                            settlement_biz_type = dataInfo["settlementBizType"]
+                            settlement_biz_type_desc = dataInfo["settlementBizTypeDesc"]
+                            send_time = dataInfo["sendTime"]
+                            recv_time = dataInfo["recvTime"]
+                            order_amount = dataInfo["orderTradeAmount"]
+                            regimental_promotion_rate = None
+                            share_rate = dataInfo["shareRate"]
+                            base_amount = dataInfo["baseAmount"]
+                            clip_user_id = dataInfo["clipUserId"]
+                            mcn_settlement_amount = dataInfo["settlementAmount"]
+                            for item in dataInfo["itemList"]:
+                                item_id = item["itemId"]
+                                item_title = item["itemTitle"]
+                                reserve_price = item["price"]
+                                image_url = item["itemPicUrl"]
+                                seller_id = item["sellerId"]
+                                promotion_id = None
+                                promotion_nick_name = None
+                                clip_nick_name = name
+                                activity_id = None
+                                pay_amount = item["paymentFee"]
+                                service_amount = item["serviceAmount"]
+                                commission_rate = item["commissionRate"]
+                                regimental_promotion_amount = None
+                                total_regimental_settle_amount = None
+                                mcn_promotion_amount = item["estimatedIncome"]
+                                stat_date = datetime.datetime.fromtimestamp(order_create_time / 1000).strftime("%Y%m%d")
+                                stat_hour = datetime.datetime.fromtimestamp(order_create_time / 1000).strftime("%H")
+                                account_type = 2
+                                dataItem = {
+                                    "oid": oid,
+                                    "order_status": order_status,
+                                    "order_create_time": order_create_time,
+                                    "send_status": send_status,
+                                    "settlement_biz_type": settlement_biz_type,
+                                    "settlement_biz_type_desc": settlement_biz_type_desc,
+                                    "send_time": send_time,
+                                    "recv_time": recv_time,
+                                    "order_amount": order_amount,
+                                    "regimental_promotion_rate": regimental_promotion_rate,
+                                    "share_rate": share_rate,
+                                    "base_amount": base_amount,
+                                    "item_id": item_id,
+                                    "item_title": item_title,
+                                    "reserve_price": reserve_price,
+                                    "image_url": image_url,
+                                    "seller_id": seller_id,
+                                    "promotion_id": promotion_id,
+                                    "promotion_nick_name": promotion_nick_name,
+                                    "clip_user_id": clip_user_id,
+                                    "clip_nick_name": clip_nick_name,
+                                    "activity_id": activity_id,
+                                    "pay_amount": pay_amount,
+                                    "service_amount": service_amount,
+                                    "commission_rate": commission_rate,
+                                    "regimental_promotion_amount": regimental_promotion_amount,
+                                    "total_regimental_settle_amount": total_regimental_settle_amount,
+                                    "mcn_promotion_amount": mcn_promotion_amount,
+                                    "mcn_settlement_amount": mcn_settlement_amount,
+                                    "stat_date": stat_date,
+                                    "stat_hour": stat_hour,
+                                    "account_type": account_type
+                                }
+                                dataInfoList.append(dataItem)
+                        batch_insertPro(item_list=dataInfoList, table_name='jy_order_list')
+                        sleep(3)
+                    except Exception as e:
+                        print(e)

+ 124 - 0
FastDistributionSpider/PromoterOrderList.py

@@ -0,0 +1,124 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2024/1/4 上午9:55
+# @Site    : 
+# @File    : PromoterOrderList.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import json
+import time
+from datetime import datetime, timedelta
+from math import ceil
+import requests
+
+from utils.mysql_helper import batch_insertPro
+from utils.mysql_utils_pro import MysqlProUtils
+
+
+class PromoterOrderList:
+    conn = MysqlProUtils()
+
+    @staticmethod
+    def HandlerRequest(startDate, endDate, cookie, name):
+        url = "https://cps.kwaixiaodian.com/distribute/pc/promoter/order/list?offset=0&limit=1&startTime={startDate}&endTime={endDate}&cpsType=0&status=0&searchDelivered=0".format(
+            startDate=startDate, endDate=endDate)
+
+        payload = {}
+        headers = {
+            'Cookie': cookie,
+            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
+            'Accept': '*/*',
+            'Host': 'cps.kwaixiaodian.com',
+            'Connection': 'keep-alive'
+        }
+
+        response = requests.request("GET", url, headers=headers, data=payload)
+        data = json.loads(response.text)["data"]
+        total_num = data["total"]
+        page = ceil(total_num / 200)
+        for i in range(page):
+            if i != 0:
+                url = "https://cps.kwaixiaodian.com/distribute/pc/promoter/order/list?offset={offset}&limit={total_num}&startTime={startDate}&endTime={endDate}&cpsType=0&status=0&searchDelivered=0".format(
+                    startDate=startDate, endDate=endDate, total_num=20 * i, offset=20 * (i - 1))
+                response = requests.request("GET", url, headers=headers, data=payload)
+                print(json.loads(response.text))
+                if json.loads(response.text)["result"] != 1:
+                    return
+                else:
+                    total_list = json.loads(response.text)["data"]["list"]
+                    dataInfoList = []
+                    try:
+                        for dataInfo in total_list:
+                            oid = dataInfo["oid"]
+                            order_status = dataInfo["status"]
+                            order_create_time = dataInfo["orderCreateTime"]
+                            send_status = dataInfo["sendStatus"]
+                            settlement_biz_type = dataInfo["settlementBizType"]
+                            settlement_biz_type_desc = dataInfo["settlementBizTypeDesc"]
+                            send_time = dataInfo["sendTime"]
+                            recv_time = dataInfo["recvTime"]
+                            order_amount = dataInfo["orderTradeAmount"]
+                            regimental_promotion_rate = None
+                            share_rate = dataInfo["shareRate"]
+                            base_amount = dataInfo["baseAmount"]
+                            for item in dataInfo["cpsOrderProductViewList"]:
+                                item_id = item["itemId"]
+                                item_title = item["itemTitle"]
+                                reserve_price = None
+                                image_url = item["itemPicUrl"]
+                                seller_id = item["sellerId"]
+                                promotion_id = None
+                                promotion_nick_name = None
+                                clip_user_id = item["distributorId"]
+                                clip_nick_name = name
+                                activity_id = None
+                                pay_amount = item["paymentFee"]
+                                service_amount = item["serviceAmount"]
+                                commission_rate = item["commissionRate"]
+                                regimental_promotion_amount = None
+                                total_regimental_settle_amount = None
+                                mcn_promotion_amount = item["estimatedIncome"]
+                                mcn_settlement_amount = item["finalEstimatedIncome"]
+                                stat_date = datetime.fromtimestamp(order_create_time / 1000).strftime("%Y%m%d")
+                                stat_hour = datetime.fromtimestamp(order_create_time / 1000).strftime("%H")
+                                account_type = 2
+                                dataItem = {
+                                    "oid": oid,
+                                    "order_status": order_status,
+                                    "order_create_time": order_create_time,
+                                    "send_status": send_status,
+                                    "settlement_biz_type": settlement_biz_type,
+                                    "settlement_biz_type_desc": settlement_biz_type_desc,
+                                    "send_time": send_time,
+                                    "recv_time": recv_time,
+                                    "order_amount": order_amount,
+                                    "regimental_promotion_rate": regimental_promotion_rate,
+                                    "share_rate": share_rate,
+                                    "base_amount": base_amount,
+                                    "item_id": item_id,
+                                    "item_title": item_title,
+                                    "reserve_price": reserve_price,
+                                    "image_url": image_url,
+                                    "seller_id": seller_id,
+                                    "promotion_id": promotion_id,
+                                    "promotion_nick_name": promotion_nick_name,
+                                    "clip_user_id": clip_user_id,
+                                    "clip_nick_name": clip_nick_name,
+                                    "activity_id": activity_id,
+                                    "pay_amount": pay_amount,
+                                    "service_amount": service_amount,
+                                    "commission_rate": commission_rate,
+                                    "regimental_promotion_amount": regimental_promotion_amount,
+                                    "total_regimental_settle_amount": total_regimental_settle_amount,
+                                    "mcn_promotion_amount": mcn_promotion_amount,
+                                    "mcn_settlement_amount": mcn_settlement_amount,
+                                    "stat_date": stat_date,
+                                    "stat_hour": stat_hour,
+                                    "account_type": account_type
+                                }
+                                dataInfoList.append(dataItem)
+                        batch_insertPro(item_list=dataInfoList, table_name='jy_order_list')
+                        time.sleep(3)
+                    except Exception as e:
+                        print(e)

+ 24 - 0
utils/platform_cookie_update.py

@@ -0,0 +1,24 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2024/1/4 上午10:16
+# @Site    : 
+# @File    : platform_cookie_update.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+from utils.mysql_utils import MysqlUtils
+
+
+class platform_cookie_update:
+    @staticmethod
+    def get_one_cookie_handler():
+        sql = "select cookie,user_name  " \
+              "from kwai_promoter.platform_supply_chain_cookie where status =0 and level_staus =1"
+        result = MysqlUtils().QueryAll(sql)
+        return result
+    @staticmethod
+    def get_two_cookie_handler():
+        sql = "select cookie,user_name  from " \
+              "kwai_promoter.platform_supply_chain_cookie where status =0 and level_staus =2"
+        result = MysqlUtils().QueryAll(sql)
+        return result