| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | # Author renyupeng# coding=utf-8# @Time    : 2024/1/4 上午9:55# @Site    : # @File    : PromoterOrderList.py# @Software: PyCharm# @contact: renyupeng@c-top.com.cn# @Tel 1501435553import jsonimport timefrom datetime import datetime, timedeltafrom math import ceilimport requestsfrom utils.mysql_helper import batch_insertProfrom utils.mysql_utils_pro import MysqlProUtilsfrom utils.send_wechat_msg import SendWechatMsgclass 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"]        print(data)        total_num = data["total"]        page = ceil(total_num / 200)        for i in range(page+1):            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=200 * i, offset=200 * (i - 1))                response = requests.request("GET", url, headers=headers, data=payload)                print(json.loads(response.text))                if json.loads(response.text)["result"] != 1:                    SendWechatMsg().send_data(json.loads(response.text))                    continue                else:                    total_list = json.loads(response.text)["data"]["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"]                            for item in dataInfo["cpsOrderProductViewList"]:                                item_id = item["itemId"]                                item_title = item["itemTitle"]                                reserve_price = dataInfo["orderTradeAmount"]                                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)
 |