|  | @@ -8,6 +8,7 @@ from model.ComUtils import *
 | 
	
		
			
				|  |  |  import math
 | 
	
		
			
				|  |  |  from model.DateUtils import DateUtils
 | 
	
		
			
				|  |  |  import logging
 | 
	
		
			
				|  |  | +from urllib import parse
 | 
	
		
			
				|  |  |  logging.getLogger().setLevel(logging.WARNING)
 | 
	
		
			
				|  |  |  db=MysqlUtils()
 | 
	
		
			
				|  |  |  du=DateUtils()
 | 
	
	
		
			
				|  | @@ -481,5 +482,94 @@ def get_zd_order_task(start,end,account):
 | 
	
		
			
				|  |  |          save_order(order_list)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +def get_zzy_order_task(start, end, account):
 | 
	
		
			
				|  |  | +    url = 'https://inovel.818tu.com/partners/channel/channels/list?'
 | 
	
		
			
				|  |  | +    key = account[0]
 | 
	
		
			
				|  |  | +    secert = account[1]
 | 
	
		
			
				|  |  | +    stage = account[2]
 | 
	
		
			
				|  |  | +    sign = md5(secert + 'key=' + key)
 | 
	
		
			
				|  |  | +    params = 'key=' + key + '&sign=' + sign
 | 
	
		
			
				|  |  | +    response_result_json = requests.get(url + params).json()  # 获取子渠道列表
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if 'data' not in response_result_json.keys():
 | 
	
		
			
				|  |  | +        print('掌中云账号【{key}】本次请求数据异常,响应报文【{result}】'.format(key=key, result=response_result_json))
 | 
	
		
			
				|  |  | +        return
 | 
	
		
			
				|  |  | +    items = response_result_json['data']['items']
 | 
	
		
			
				|  |  | +    print(f'VIP{account[0]} 有公众号{len(items)} ')
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    total_order_list = []
 | 
	
		
			
				|  |  | +    for channel in items:
 | 
	
		
			
				|  |  | +        # 获取channel_id 后逐个拉取历史orders
 | 
	
		
			
				|  |  | +        order_list = get_zzy_channel_order(start, end, account, channel)
 | 
	
		
			
				|  |  | +        total_order_list.extend(order_list)
 | 
	
		
			
				|  |  | +    print(f"{stage} [{start}]~[{end}] 有订单{total_order_list.__len__()}")
 | 
	
		
			
				|  |  | +    if total_order_list > 0:
 | 
	
		
			
				|  |  | +        save_order(total_order_list)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def get_zzy_channel_order(start, end, account, channel):
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    get_time=DateUtils.str_to_date_str(start, f2="%Y-%m-%dT%H:%M:%S+08:00")
 | 
	
		
			
				|  |  | +    limit_time=DateUtils.str_to_date_str(end, f2="%Y-%m-%dT%H:%M:%S+08:00")
 | 
	
		
			
				|  |  | +    order_list = []
 | 
	
		
			
				|  |  | +    key = account[0]
 | 
	
		
			
				|  |  | +    secert = account[1]
 | 
	
		
			
				|  |  | +    stage = account[2]
 | 
	
		
			
				|  |  | +    order_url = 'https://openapi.818tu.com/partners/channel/orders/list?'
 | 
	
		
			
				|  |  | +    channel_id = channel['id']
 | 
	
		
			
				|  |  | +    channel_name = channel['nickname']
 | 
	
		
			
				|  |  | +    status = str(1)
 | 
	
		
			
				|  |  | +    page = str(1)
 | 
	
		
			
				|  |  | +    per_page = str(1000)
 | 
	
		
			
				|  |  | +    gte = parse.urlencode({'created_at[gte]': get_time})  # gte就是ge 大于等于开始时间
 | 
	
		
			
				|  |  | +    lt = parse.urlencode({'created_at[lt]': limit_time})  # 小于 结束时间
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    while True:
 | 
	
		
			
				|  |  | +        sign = md5(secert + 'channel_id=' + str(
 | 
	
		
			
				|  |  | +            channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + key + '&page=' + str(
 | 
	
		
			
				|  |  | +            page) + '&per_page=' + per_page + '&status=' + status)
 | 
	
		
			
				|  |  | +        params = 'channel_id=' + str(channel_id) + '&' + gte + '&' + lt + '&page=' + str(
 | 
	
		
			
				|  |  | +            page) + '&per_page=' + per_page + '&status=' + status + '&key=' + key + '&sign=' + sign
 | 
	
		
			
				|  |  | +        while True:
 | 
	
		
			
				|  |  | +            r = requests.get(order_url + params)
 | 
	
		
			
				|  |  | +            if r.status_code == 200:
 | 
	
		
			
				|  |  | +                response_result_json = r.json()
 | 
	
		
			
				|  |  | +                break
 | 
	
		
			
				|  |  | +            else:
 | 
	
		
			
				|  |  | +                time.sleep(61)
 | 
	
		
			
				|  |  | +                print("掌中云接口调用sleep 61s...")
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if 'data' not in response_result_json.keys():
 | 
	
		
			
				|  |  | +            print(f'掌中云账号【{key}】,查询时间【{start} - {end}】,渠道【{channel_name}】本次请求数据异常,响应报文【{r.text}】')
 | 
	
		
			
				|  |  | +            break
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        total_count = response_result_json['data']['count']  # 总数量
 | 
	
		
			
				|  |  | +        order_item_list = response_result_json['data']['items']  # 订单列表
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for order_item in order_item_list:
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            order_time = DateUtils.str_to_date_str(order_item['created_at'], "%Y-%m-%dT%H:%M:%S+08:00", "%Y-%m-%d %H:%M:%S")
 | 
	
		
			
				|  |  | +            order = (
 | 
	
		
			
				|  |  | +                DateUtils.str_to_stamp(order_time[:10]),
 | 
	
		
			
				|  |  | +                stage,
 | 
	
		
			
				|  |  | +                '掌中云',
 | 
	
		
			
				|  |  | +                channel_name,
 | 
	
		
			
				|  |  | +                channel_id,
 | 
	
		
			
				|  |  | +                str(order_item['member']['openid']),
 | 
	
		
			
				|  |  | +                order_item['created_at'],
 | 
	
		
			
				|  |  | +                order_item['member']['created_at'],
 | 
	
		
			
				|  |  | +                round(order_item['price'] / 100, 2),
 | 
	
		
			
				|  |  | +                order_item['from_novel']['title'] if str(order_item['from_novel_id']) != 'None' else '',
 | 
	
		
			
				|  |  | +                str(order_item['id'])
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  | +            order_list.append(order)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if int(page) >= math.ceil(total_count / int(per_page)):
 | 
	
		
			
				|  |  | +            break
 | 
	
		
			
				|  |  | +        page = int(page) + 1
 | 
	
		
			
				|  |  | +    # print(f"{channel_name}获取订单:{order_list.__len__()}")
 | 
	
		
			
				|  |  | +    return order_list
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  if __name__ == '__main__':
 | 
	
		
			
				|  |  |      get_qiyue_order_task('2021-02-01','2021-02-19',['趣程15期','eyJpdiI6ImluVWxoRUl3VTR6QU5hamlYOFBvXC9BPT0iLCJ2YWx1ZSI6Ik5IZ0N4dm5GcmJ0Zklsd0tNZ1JVSVE9PSIsIm1hYyI6IjJjODUzMjdlZTc2ODI2ZjFmY2QyYmU5MGViYTkzOGU4MDEwZTIyODIxOTE4NzgzYTNhOGQ1YWM4OGJkMDAzMmIifQ=='])
 |