PromoterOrderList.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2024/1/4 上午9:55
  4. # @Site :
  5. # @File : PromoterOrderList.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. # @Tel 1501435553
  9. import json
  10. import time
  11. from datetime import datetime, timedelta
  12. from math import ceil
  13. import requests
  14. from utils.mysql_helper import batch_insertPro
  15. from utils.mysql_utils_pro import MysqlProUtils
  16. from utils.send_wechat_msg import SendWechatMsg
  17. class PromoterOrderList:
  18. conn = MysqlProUtils()
  19. @staticmethod
  20. def HandlerRequest(startDate, endDate, cookie, name):
  21. 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(
  22. startDate=startDate, endDate=endDate)
  23. payload = {}
  24. headers = {
  25. 'Cookie': cookie,
  26. 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
  27. 'Accept': '*/*',
  28. 'Host': 'cps.kwaixiaodian.com',
  29. 'Connection': 'keep-alive'
  30. }
  31. response = requests.request("GET", url, headers=headers, data=payload)
  32. data = json.loads(response.text)["data"]
  33. print(data)
  34. total_num = data["total"]
  35. page = ceil(total_num / 200)
  36. for i in range(page+1):
  37. if i != 0:
  38. 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(
  39. startDate=startDate, endDate=endDate, total_num=200 * i, offset=200 * (i - 1))
  40. response = requests.request("GET", url, headers=headers, data=payload)
  41. print(json.loads(response.text))
  42. if json.loads(response.text)["result"] != 1:
  43. SendWechatMsg().send_data(json.loads(response.text))
  44. continue
  45. else:
  46. total_list = json.loads(response.text)["data"]["list"]
  47. dataInfoList = []
  48. try:
  49. for dataInfo in total_list:
  50. print(dataInfo)
  51. oid = dataInfo["oid"]
  52. order_status = dataInfo["status"]
  53. order_create_time = dataInfo["orderCreateTime"]
  54. send_status = dataInfo["sendStatus"]
  55. settlement_biz_type = dataInfo["settlementBizType"]
  56. settlement_biz_type_desc = dataInfo["settlementBizTypeDesc"]
  57. send_time = dataInfo["sendTime"]
  58. recv_time = dataInfo["recvTime"]
  59. order_amount = dataInfo["orderTradeAmount"]
  60. regimental_promotion_rate = None
  61. share_rate = dataInfo["shareRate"]
  62. base_amount = dataInfo["baseAmount"]
  63. for item in dataInfo["cpsOrderProductViewList"]:
  64. item_id = item["itemId"]
  65. item_title = item["itemTitle"]
  66. reserve_price = dataInfo["orderTradeAmount"]
  67. image_url = item["itemPicUrl"]
  68. seller_id = item["sellerId"]
  69. promotion_id = None
  70. promotion_nick_name = None
  71. clip_user_id = item["distributorId"]
  72. clip_nick_name = name
  73. activity_id = None
  74. pay_amount = item["paymentFee"]
  75. service_amount = item["serviceAmount"]
  76. commission_rate = item["commissionRate"]
  77. regimental_promotion_amount = None
  78. total_regimental_settle_amount = None
  79. mcn_promotion_amount = item["estimatedIncome"]
  80. mcn_settlement_amount = item["finalEstimatedIncome"]
  81. stat_date = datetime.fromtimestamp(order_create_time / 1000).strftime("%Y%m%d")
  82. stat_hour = datetime.fromtimestamp(order_create_time / 1000).strftime("%H")
  83. account_type = 2
  84. dataItem = {
  85. "oid": oid,
  86. "order_status": order_status,
  87. "order_create_time": order_create_time,
  88. "send_status": send_status,
  89. "settlement_biz_type": settlement_biz_type,
  90. "settlement_biz_type_desc": settlement_biz_type_desc,
  91. "send_time": send_time,
  92. "recv_time": recv_time,
  93. "order_amount": order_amount,
  94. "regimental_promotion_rate": regimental_promotion_rate,
  95. "share_rate": share_rate,
  96. "base_amount": base_amount,
  97. "item_id": item_id,
  98. "item_title": item_title,
  99. "reserve_price": reserve_price,
  100. "image_url": image_url,
  101. "seller_id": seller_id,
  102. "promotion_id": promotion_id,
  103. "promotion_nick_name": promotion_nick_name,
  104. "clip_user_id": clip_user_id,
  105. "clip_nick_name": clip_nick_name,
  106. "activity_id": activity_id,
  107. "pay_amount": pay_amount,
  108. "service_amount": service_amount,
  109. "commission_rate": commission_rate,
  110. "regimental_promotion_amount": regimental_promotion_amount,
  111. "total_regimental_settle_amount": total_regimental_settle_amount,
  112. "mcn_promotion_amount": mcn_promotion_amount,
  113. "mcn_settlement_amount": mcn_settlement_amount,
  114. "stat_date": stat_date,
  115. "stat_hour": stat_hour,
  116. "account_type": account_type
  117. }
  118. dataInfoList.append(dataItem)
  119. batch_insertPro(item_list=dataInfoList, table_name='jy_order_list')
  120. time.sleep(3)
  121. except Exception as e:
  122. print(e)