Browse Source

优化掌中云,花生的订单查询接口

zwg 4 years ago
parent
commit
b76d49d4fd
4 changed files with 816 additions and 823 deletions
  1. 641 641
      dgp/get_data_hourly.py
  2. 74 72
      dgp/tests/check_order.py
  3. 73 59
      dgp/tests/check_order_new.py
  4. 28 51
      dgp/tests/demo/test.py

+ 641 - 641
dgp/get_data_hourly.py

@@ -6,95 +6,97 @@ Created on Thu Jun  4 15:06:05 2020
 @author: chencong
 """
 
-import requests
-import hashlib
-import time
-from urllib import parse
 import datetime
+import hashlib
 import json
 import math
-import pymysql
 import random
+import smtplib
+import time
+from email.mime.text import MIMEText
+from urllib import parse
+
+import pymysql
+import requests
 from apscheduler.schedulers.blocking import BlockingScheduler
+
 import account_list as al
 import token_list as tl
-import smtplib
-from email.mime.text import MIMEText
 
 
 def md5value(s):
-	md5 = hashlib.md5()
-	md5.update(s.encode("utf-8"))
-	return md5.hexdigest()
+    md5 = hashlib.md5()
+    md5.update(s.encode("utf-8"))
+    return md5.hexdigest()
 
 
 def get_yuewen_order(st, et):
-	t = ()
-	time1 = time.time()
-	url = 'https://open.yuewen.com/cpapi/wxRecharge/querychargelog'
-	version = 1
-	secert_list = al.yuewen_account_list
-	for secert in secert_list:
-		start_time = st
-		end_time = et
-		email = secert[0]
-		appsecert = secert[1]
-		for i in range((et - st) // 86400 + 1):
-			timestamp = int(time.time())
-			s = ''
-			page = 1
-			order_status = 2
-			data = {
-				'email': email,
-				'version': version,
-				'timestamp': timestamp,
-				'start_time': start_time,
-				'end_time': end_time,
-				'page': page,
-				'order_status': order_status
-			}
-			# 'last_min_id':last_min_id,
-			# 'last_max_id':last_max_id,
-			# 'total_count':total_count,
-			# 'last_page':last_page}
-			sorted_data = sorted(data.items())
-			for k, v in sorted_data:
-				s = s + str(k) + str(v)
-
-			sign = md5value(appsecert + s).upper()
-
-			data1 = {
-				'email': email,
-				'version': version,
-				'timestamp': timestamp,
-				'start_time': start_time,
-				'end_time': end_time,
-				'page': page,
-				'order_status': order_status,
-				'sign': sign
-			}
-			list1 = requests.get(url=url, params=data1)
-			total_count = list1.json()['data']['total_count']
-			last_min_id = list1.json()['data']['min_id']
-			last_max_id = list1.json()['data']['max_id']
-			last_page = list1.json()['data']['page']
-
-			if total_count > 0:
-				for x in list1.json()['data']['list']:
-					y = {}
-					dtime = datetime.datetime.strptime(x['order_time'], "%Y-%m-%d %H:%M:%S")
-					y['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
-					y['platform'] = '阅文'
-					y['channel'] = x['app_name']
-					y['from_novel'] = x['book_name']
-					y['user_id'] = x['openid']
-					y['stage'] = ''
-					y['channel_id'] = 0
-					y['order_time'] = x['order_time']
-					y['amount'] = x['amount']
-					y['reg_time'] = x['reg_time']
-					y['order_id'] = x['order_id']
-					"""
+    t = ()
+    time1 = time.time()
+    url = 'https://open.yuewen.com/cpapi/wxRecharge/querychargelog'
+    version = 1
+    secert_list = al.yuewen_account_list
+    for secert in secert_list:
+        start_time = st
+        end_time = et
+        email = secert[0]
+        appsecert = secert[1]
+        for i in range((et - st) // 86400 + 1):
+            timestamp = int(time.time())
+            s = ''
+            page = 1
+            order_status = 2
+            data = {
+                'email': email,
+                'version': version,
+                'timestamp': timestamp,
+                'start_time': start_time,
+                'end_time': end_time,
+                'page': page,
+                'order_status': order_status
+            }
+            # 'last_min_id':last_min_id,
+            # 'last_max_id':last_max_id,
+            # 'total_count':total_count,
+            # 'last_page':last_page}
+            sorted_data = sorted(data.items())
+            for k, v in sorted_data:
+                s = s + str(k) + str(v)
+
+            sign = md5value(appsecert + s).upper()
+
+            data1 = {
+                'email': email,
+                'version': version,
+                'timestamp': timestamp,
+                'start_time': start_time,
+                'end_time': end_time,
+                'page': page,
+                'order_status': order_status,
+                'sign': sign
+            }
+            list1 = requests.get(url=url, params=data1)
+            total_count = list1.json()['data']['total_count']
+            last_min_id = list1.json()['data']['min_id']
+            last_max_id = list1.json()['data']['max_id']
+            last_page = list1.json()['data']['page']
+
+            if total_count > 0:
+                for x in list1.json()['data']['list']:
+                    y = {}
+                    dtime = datetime.datetime.strptime(x['order_time'], "%Y-%m-%d %H:%M:%S")
+                    y['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
+                    y['platform'] = '阅文'
+                    y['channel'] = x['app_name']
+                    y['from_novel'] = x['book_name']
+                    y['user_id'] = x['openid']
+                    y['stage'] = ''
+                    y['channel_id'] = 0
+                    y['order_time'] = x['order_time']
+                    y['amount'] = x['amount']
+                    y['reg_time'] = x['reg_time']
+                    y['order_id'] = x['order_id']
+                    """
                     del x['app_name']
                     del x['order_status']
                     del x['order_type']
@@ -107,61 +109,61 @@ def get_yuewen_order(st, et):
                     del x['report_status']
                     if y['order_time'] != time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(et)):
                     """
-					y = sorted(y.items(), key=lambda item: item[0])
-					y = dict(y)
-					y = tuple(y.values())
-					t = t + ((y),)
-
-			if total_count > 100:
-				for page in range(2, math.ceil(total_count / 100) + 1):
-					data = {
-						'email': email,
-						'version': version,
-						'timestamp': timestamp,
-						'start_time': start_time,
-						'end_time': end_time,
-						'page': page,
-						'last_min_id': last_min_id,
-						'last_max_id': last_max_id,
-						'total_count': total_count,
-						'last_page': last_page,
-						'order_status': order_status
-					}
-					sorted_data = sorted(data.items())
-					s1 = ''
-					for k, v in sorted_data:
-						s1 = s1 + str(k) + str(v)
-						sign = md5value(appsecert + s1).upper()
-						data2 = {
-							'email': email,
-							'version': version,
-							'timestamp': timestamp,
-							'start_time': start_time,
-							'end_time': end_time,
-							'page': page,
-							'last_min_id': last_min_id,
-							'last_max_id': last_max_id,
-							'total_count': total_count,
-							'last_page': last_page,
-							'order_status': order_status,
-							'sign': sign
-						}
-					list2 = requests.get(url=url, params=data2)
-					for x in list2.json()['data']['list']:
-						y = {}
-						dtime = datetime.datetime.strptime(x['order_time'], "%Y-%m-%d %H:%M:%S")
-						y['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
-						y['platform'] = '阅文'
-						y['channel'] = x['app_name']
-						y['from_novel'] = x['book_name']
-						y['user_id'] = x['openid']
-						y['stage'] = ''
-						y['channel_id'] = 0
-						y['order_time'] = x['order_time']
-						y['amount'] = x['amount']
-						y['reg_time'] = x['reg_time']
-						y['order_id'] = x['order_id']
-						"""
+                    y = sorted(y.items(), key=lambda item: item[0])
+                    y = dict(y)
+                    y = tuple(y.values())
+                    t = t + ((y),)
+
+            if total_count > 100:
+                for page in range(2, math.ceil(total_count / 100) + 1):
+                    data = {
+                        'email': email,
+                        'version': version,
+                        'timestamp': timestamp,
+                        'start_time': start_time,
+                        'end_time': end_time,
+                        'page': page,
+                        'last_min_id': last_min_id,
+                        'last_max_id': last_max_id,
+                        'total_count': total_count,
+                        'last_page': last_page,
+                        'order_status': order_status
+                    }
+                    sorted_data = sorted(data.items())
+                    s1 = ''
+                    for k, v in sorted_data:
+                        s1 = s1 + str(k) + str(v)
+                        sign = md5value(appsecert + s1).upper()
+                        data2 = {
+                            'email': email,
+                            'version': version,
+                            'timestamp': timestamp,
+                            'start_time': start_time,
+                            'end_time': end_time,
+                            'page': page,
+                            'last_min_id': last_min_id,
+                            'last_max_id': last_max_id,
+                            'total_count': total_count,
+                            'last_page': last_page,
+                            'order_status': order_status,
+                            'sign': sign
+                        }
+                    list2 = requests.get(url=url, params=data2)
+                    for x in list2.json()['data']['list']:
+                        y = {}
+                        dtime = datetime.datetime.strptime(x['order_time'], "%Y-%m-%d %H:%M:%S")
+                        y['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
+                        y['platform'] = '阅文'
+                        y['channel'] = x['app_name']
+                        y['from_novel'] = x['book_name']
+                        y['user_id'] = x['openid']
+                        y['stage'] = ''
+                        y['channel_id'] = 0
+                        y['order_time'] = x['order_time']
+                        y['amount'] = x['amount']
+                        y['reg_time'] = x['reg_time']
+                        y['order_id'] = x['order_id']
+                        """
                         del x['report_status']
                         del x['app_name']
                         del x['order_status']
@@ -174,72 +176,72 @@ def get_yuewen_order(st, et):
                         del x['book_name']
                         if y['order_time'] != time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(et)):
                         """
-						y = sorted(y.items(), key=lambda item: item[0])
-						y = dict(y)
-						y = tuple(y.values())
-						t = t + ((y),)
+                        y = sorted(y.items(), key=lambda item: item[0])
+                        y = dict(y)
+                        y = tuple(y.values())
+                        t = t + ((y),)
 
-					total_count = list2.json()['data']['total_count']
-					last_min_id = list2.json()['data']['min_id']
-					last_max_id = list2.json()['data']['max_id']
-					last_page = list2.json()['data']['page']
+                    total_count = list2.json()['data']['total_count']
+                    last_min_id = list2.json()['data']['min_id']
+                    last_max_id = list2.json()['data']['max_id']
+                    last_page = list2.json()['data']['page']
 
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_yuewen_order:', len(t), 'cost_minutes:', cost_time)
-	return t
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_yuewen_order:', len(t), 'cost_minutes:', cost_time)
+    return t
 
 
 def get_zhangdu_order(st, et):
-	time1 = time.time()
-	secert_list = al.zhangdu_account_list
-	t = ()
-	url = 'https://api.zhangdu520.com/channel/getorder'
-
-	for item in secert_list:  # 分渠道
-		uid = item[0]
-		appsecert = item[1]
-		channel = item[2]
-		timestamp = int(time.time())
-		sign = md5value(str(uid) + '&' + appsecert + '&' + str(timestamp))
-		page = 1
-		starttime = st
-		endtime = et
-		for x in range((et - st) // 86400 + 1):  # 分时段
-			Params = {'uid': uid,
-					  'timestamp': timestamp,
-					  'sign': sign,
-					  'starttime': starttime,
-					  'endtime': endtime
-					  }
-			list1 = requests.get(url=url, params=Params)
-			pageCount = list1.json()['data']['pageCount']
-			if pageCount > 0:
-				for a in range(1, pageCount + 1):  # 分页
-					page = a
-					Params = {
-						'uid': uid,
-						'timestamp': timestamp,
-						'sign': sign,
-						'starttime': starttime,
-						'endtime': endtime,
-						'page': page
-					}
-					list2 = requests.get(url=url, params=Params).json()['data']['list']
-					for b in list2:
-						c = {}
-						c['channel_id'] = uid
-						c['order_id'] = str(b['orderno'])
-						c['order_time'] = b['ctime']
-						c['user_id'] = b['openid']
-						c['platform'] = '掌读'
-						c['channel'] = channel
-						c['stage'] = ''
-						c['from_novel'] = ''
-						c['reg_time'] = b['regtime']
-						c['date'] = ((int(b['ctime']) + 8 * 3600) // 86400) * 86400 - 8 * 3600
-						c['amount'] = b['amount']
-
-						"""
+    time1 = time.time()
+    secert_list = al.zhangdu_account_list
+    t = ()
+    url = 'https://api.zhangdu520.com/channel/getorder'
+
+    for item in secert_list:  # 分渠道
+        uid = item[0]
+        appsecert = item[1]
+        channel = item[2]
+        timestamp = int(time.time())
+        sign = md5value(str(uid) + '&' + appsecert + '&' + str(timestamp))
+        page = 1
+        starttime = st
+        endtime = et
+        for x in range((et - st) // 86400 + 1):  # 分时段
+            Params = {'uid': uid,
+                      'timestamp': timestamp,
+                      'sign': sign,
+                      'starttime': starttime,
+                      'endtime': endtime
+                      }
+            list1 = requests.get(url=url, params=Params)
+            pageCount = list1.json()['data']['pageCount']
+            if pageCount > 0:
+                for a in range(1, pageCount + 1):  # 分页
+                    page = a
+                    Params = {
+                        'uid': uid,
+                        'timestamp': timestamp,
+                        'sign': sign,
+                        'starttime': starttime,
+                        'endtime': endtime,
+                        'page': page
+                    }
+                    list2 = requests.get(url=url, params=Params).json()['data']['list']
+                    for b in list2:
+                        c = {}
+                        c['channel_id'] = uid
+                        c['order_id'] = str(b['orderno'])
+                        c['order_time'] = b['ctime']
+                        c['user_id'] = b['openid']
+                        c['platform'] = '掌读'
+                        c['channel'] = channel
+                        c['stage'] = ''
+                        c['from_novel'] = ''
+                        c['reg_time'] = b['regtime']
+                        c['date'] = ((int(b['ctime']) + 8 * 3600) // 86400) * 86400 - 8 * 3600
+                        c['amount'] = b['amount']
+
+                        """
                         del b['openid']
                         del b['regtime']
                         del b['ip']
@@ -251,89 +253,89 @@ def get_zhangdu_order(st, et):
                         del b['source']
                         del b['sourceid']
                         """
-						if b['status'] == '1' and int(c['order_time']) < et:
-							del b['status']
-							x = sorted(c.items(), key=lambda item: item[0])
-							x = dict(x)
-							x = tuple(x.values())
-							t = t + ((x),)
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_zhangdu_order:', len(t), 'cost_minutes:', cost_time)
-	return t
+                        if b['status'] == '1' and int(c['order_time']) < et:
+                            del b['status']
+                            x = sorted(c.items(), key=lambda item: item[0])
+                            x = dict(x)
+                            x = tuple(x.values())
+                            t = t + ((x),)
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_zhangdu_order:', len(t), 'cost_minutes:', cost_time)
+    return t
 
 
 def get_huasheng_order(st, et):
-	time1 = time.time()
-	apikey_list = al.huasheng_account_list
-	url = 'https://vip.rlcps.cn/api/getMerchants'
-	t = ()
-	for key in apikey_list:  # 获取每个vip账号下的channel_id
-		apiKEY = key[0]
-		apiSecurity = key[1]
-		stage = key[2]
-		timestamp = str(int(time.time()))
-		sign = md5value(apiKEY + timestamp + apiSecurity).upper()
-		data = {'apiKey': apiKEY,
-				'apiSecurity': apiSecurity,
-				'timestamp': timestamp,
-				'sign': sign
-				}
-		list0 = requests.post(url, data).json()
-		for merchant in list0['data']:
-			merchant_id = merchant['merchant_id']
-			merchant_name = merchant['merchant_name']
-			url1 = 'https://vip.rlcps.cn/api/orderList'
-			start_time = st
-
-			for i in range((et - st) // 86400 + 1):
-				date = time.strftime("%Y-%m-%d", time.localtime(start_time))
-				sign = md5value(apiKEY + date + str(merchant_id) + timestamp + apiSecurity).upper()
-				page = 1
-				data1 = {
-					'apiKey': apiKEY,
-					'apiSecurity': apiSecurity,
-					'timestamp': timestamp,
-					'date': date,
-					'merchant_id': merchant_id,
-					'sign': sign,
-					'page': page
-				}
-				list1 = requests.post(url1, data1).json()
-
-				if 'data' in list1.keys() and len(list1['data']) > 0:
-					for i in range(int(math.ceil(list1['count'] / 500))):
-						data2 = {
-							'apiKey': apiKEY,
-							'apiSecurity': apiSecurity,
-							'timestamp': timestamp,
-							'date': date,
-							'merchant_id': merchant_id,
-							'sign': sign,
-							'page': page
-						}
-						list2 = requests.post(url1, data2).json()
-
-						for x in list2['data']:
-							if x['order_status'] == 1:
-								t1 = time.strptime(x['pay_at'], "%Y-%m-%d %H:%M:%S")
-								ts = int(time.mktime(t1))
-
-								if ts >= st and ts < et:
-									y = {}
-									# dtime = datetime.datetime.strptime(x['pay_at'],"%Y-%m-%d")
-									# y['date']= ((int(time.mktime(dtime.timetuple()))+8*3600)//86400)*86400-8*3600
-									y['order_id'] = x['trans_id']
-									y['order_time'] = x['pay_at']
-									y['reg_time'] = x['join_at']
-									y['date'] = (start_time + 8 * 3600) // 86400 * 86400 - 8 * 3600
-									y['channel'] = merchant_name
-									y['channel_id'] = merchant_id
-									y['from_novel'] = x['book_name']
-									y['platform'] = '花生'
-									y['stage'] = stage
-									y['user_id'] = x['openid']
-									y['amount'] = x['amount']
-									"""
+    time1 = time.time()
+    apikey_list = al.huasheng_account_list
+    url = 'https://vip.rlcps.cn/api/getMerchants'
+    t = ()
+    for key in apikey_list:  # 获取每个vip账号下的channel_id
+        apiKEY = key[0]
+        apiSecurity = key[1]
+        stage = key[2]
+        timestamp = str(int(time.time()))
+        sign = md5value(apiKEY + timestamp + apiSecurity).upper()
+        data = {'apiKey': apiKEY,
+                'apiSecurity': apiSecurity,
+                'timestamp': timestamp,
+                'sign': sign
+                }
+        list0 = requests.post(url, data).json()
+        for merchant in list0['data']:
+            merchant_id = merchant['merchant_id']
+            merchant_name = merchant['merchant_name']
+            url1 = 'https://vip.rlcps.cn/api/orderList'
+            start_time = st
+
+            for i in range((et - st) // 86400 + 1):
+                date = time.strftime("%Y-%m-%d", time.localtime(start_time))
+                sign = md5value(apiKEY + date + str(merchant_id) + timestamp + apiSecurity).upper()
+                page = 1
+                data1 = {
+                    'apiKey': apiKEY,
+                    'apiSecurity': apiSecurity,
+                    'timestamp': timestamp,
+                    'date': date,
+                    'merchant_id': merchant_id,
+                    'sign': sign,
+                    'page': page
+                }
+                list1 = requests.post(url1, data1).json()
+
+                if 'data' in list1.keys() and len(list1['data']) > 0:
+                    for i in range(int(math.ceil(list1['count'] / 500))):
+                        data2 = {
+                            'apiKey': apiKEY,
+                            'apiSecurity': apiSecurity,
+                            'timestamp': timestamp,
+                            'date': date,
+                            'merchant_id': merchant_id,
+                            'sign': sign,
+                            'page': page
+                        }
+                        list2 = requests.post(url1, data2).json()
+
+                        for x in list2['data']:
+                            if x['order_status'] == 1:
+                                t1 = time.strptime(x['pay_at'], "%Y-%m-%d %H:%M:%S")
+                                ts = int(time.mktime(t1))
+
+                                if ts >= st and ts < et:
+                                    y = {}
+                                    # dtime = datetime.datetime.strptime(x['pay_at'],"%Y-%m-%d")
+                                    # y['date']= ((int(time.mktime(dtime.timetuple()))+8*3600)//86400)*86400-8*3600
+                                    y['order_id'] = x['trans_id']
+                                    y['order_time'] = x['pay_at']
+                                    y['reg_time'] = x['join_at']
+                                    y['date'] = (start_time + 8 * 3600) // 86400 * 86400 - 8 * 3600
+                                    y['channel'] = merchant_name
+                                    y['channel_id'] = merchant_id
+                                    y['from_novel'] = x['book_name']
+                                    y['platform'] = '花生'
+                                    y['stage'] = stage
+                                    y['user_id'] = x['openid']
+                                    y['amount'] = x['amount']
+                                    """
                                     del x['order_num']
                                     del x['book_name']
                                     del x['trans_id']
@@ -350,90 +352,90 @@ def get_huasheng_order(st, et):
 
                                     if y['order_time'] != time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(et)):
                                     """
-									y = sorted(y.items(), key=lambda item: item[0])
-									y = dict(y)
-									y = tuple(y.values())
-									t = t + ((y),)
+                                    y = sorted(y.items(), key=lambda item: item[0])
+                                    y = dict(y)
+                                    y = tuple(y.values())
+                                    t = t + ((y),)
 
-						page = page + 1
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_huasheng_order:', len(t), 'cost_minutes:', cost_time)
-	return t
+                        page = page + 1
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_huasheng_order:', len(t), 'cost_minutes:', cost_time)
+    return t
 
 
 def get_zzy_order(st, et):
-	time1 = time.time()
-	API_list = al.zzy_account_list
-	r = ()
-
-	for x in API_list:
-		my_key = x[0]
-		secert = x[1]
-		stage = x[2]
-		my_sign = md5value(secert + 'key=' + my_key)
-		url = 'https://openapi.818tu.com/partners/channel/channels/list?'
-		parameter = 'key=' + my_key + '&sign=' + my_sign
-		channel_list = requests.get(url + parameter)  # 获取子渠道列表
-
-		if 'data' in channel_list.json().keys():
-			items = channel_list.json()['data']['items']
-		elif len(x) > 3:
-			my_key = x[3]
-			secert = x[4]
-			my_sign = md5value(secert + 'key=' + my_key)
-			url = 'https://openapi.818tu.com/partners/channel/channels/list?'
-			parameter = 'key=' + my_key + '&sign=' + my_sign
-			channel_list = requests.get(url + parameter)
-			items = channel_list.json()['data']['items']
-		else:
-			print(channel_list.json())
-			items = []
-
-		if items != []:
-			for item in items:  # 获取channel_id 后逐个拉取历史orders
-				channel_id = item['id']
-				channel = item['nickname']
-				status = str(1)
-				per_page = str(1000)
-				limit_time = et
-				get_time = st
-				lt = parse.urlencode({'created_at[lt]': limit_time})
-				gt = parse.urlencode({'created_at[gte]': get_time})
-				url_1 = 'https://openapi.818tu.com/partners/channel/orders/list?'
-				my_sign_1 = md5value(secert + 'channel_id=' + str(
-					channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + my_key + '&per_page=' + per_page + '&status=' + status)
-				parameter_1 = 'channel_id=' + str(
-					channel_id) + '&' + gt + '&' + lt + '&per_page=' + per_page + '&status=' + status + '&key=' + my_key + '&sign=' + my_sign_1
-				orders = requests.get(url_1 + parameter_1)
-				t = orders.json()['data']['count'] // int(per_page) + 1
-				for page in range(1, t + 1):
-					my_sign_2 = md5value(secert + 'channel_id=' + str(
-						channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + my_key + '&page=' + str(
-						page) + '&per_page=' + per_page + '&status=' + status)
-					parameter_2 = 'channel_id=' + str(channel_id) + '&' + gt + '&' + lt + '&page=' + str(
-						page) + '&per_page=' + per_page + '&status=' + status + '&key=' + my_key + '&sign=' + my_sign_2
-					orders_1 = requests.get(url_1 + parameter_2)
-					b = orders_1.json()['data']['items']
-
-					for a in b:
-						c = {}
-						c['user_id'] = str(a['member']['openid'])
-						c['channel'] = channel
-						c['reg_time'] = a['member']['created_at']
-						c['channel_id'] = channel_id
-						c['amount'] = round(a['price'] / 100, 2)
-						c['order_id'] = str(a['id'])
-						c['order_time'] = a['created_at']
-						c['platform'] = '掌中云'
-						dtime = datetime.datetime.strptime(a['created_at'][0:10], "%Y-%m-%d")
-						c['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
-						c['stage'] = stage
-
-						if str(a['from_novel_id']) != 'None':
-							c['from_novel'] = a['from_novel']['title']
-						else:
-							c['from_novel'] = 'None'
-						"""
+    time1 = time.time()
+    API_list = al.zzy_account_list
+    r = ()
+
+    for x in API_list:
+        my_key = x[0]
+        secert = x[1]
+        stage = x[2]
+        my_sign = md5value(secert + 'key=' + my_key)
+        url = 'https://openapi.818tu.com/partners/channel/channels/list?'
+        parameter = 'key=' + my_key + '&sign=' + my_sign
+        channel_list = requests.get(url + parameter)  # 获取子渠道列表
+
+        if 'data' in channel_list.json().keys():
+            items = channel_list.json()['data']['items']
+        elif len(x) > 3:
+            my_key = x[3]
+            secert = x[4]
+            my_sign = md5value(secert + 'key=' + my_key)
+            url = 'https://openapi.818tu.com/partners/channel/channels/list?'
+            parameter = 'key=' + my_key + '&sign=' + my_sign
+            channel_list = requests.get(url + parameter)
+            items = channel_list.json()['data']['items']
+        else:
+            print(channel_list.json())
+            items = []
+
+        if items != []:
+            for item in items:  # 获取channel_id 后逐个拉取历史orders
+                channel_id = item['id']
+                channel = item['nickname']
+                status = str(1)
+                per_page = str(1000)
+                limit_time = et
+                get_time = st
+                lt = parse.urlencode({'created_at[lt]': limit_time})
+                gt = parse.urlencode({'created_at[gte]': get_time})
+                url_1 = 'https://openapi.818tu.com/partners/channel/orders/list?'
+                my_sign_1 = md5value(secert + 'channel_id=' + str(
+                    channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + my_key + '&per_page=' + per_page + '&status=' + status)
+                parameter_1 = 'channel_id=' + str(
+                    channel_id) + '&' + gt + '&' + lt + '&per_page=' + per_page + '&status=' + status + '&key=' + my_key + '&sign=' + my_sign_1
+                orders = requests.get(url_1 + parameter_1)
+                t = orders.json()['data']['count'] // int(per_page) + 1
+                for page in range(1, t + 1):
+                    my_sign_2 = md5value(secert + 'channel_id=' + str(
+                        channel_id) + '&created_at[gte]=' + get_time + '&created_at[lt]=' + limit_time + '&key=' + my_key + '&page=' + str(
+                        page) + '&per_page=' + per_page + '&status=' + status)
+                    parameter_2 = 'channel_id=' + str(channel_id) + '&' + gt + '&' + lt + '&page=' + str(
+                        page) + '&per_page=' + per_page + '&status=' + status + '&key=' + my_key + '&sign=' + my_sign_2
+                    orders_1 = requests.get(url_1 + parameter_2)
+                    b = orders_1.json()['data']['items']
+
+                    for a in b:
+                        c = {}
+                        c['user_id'] = str(a['member']['openid'])
+                        c['channel'] = channel
+                        c['reg_time'] = a['member']['created_at']
+                        c['channel_id'] = channel_id
+                        c['amount'] = round(a['price'] / 100, 2)
+                        c['order_id'] = str(a['id'])
+                        c['order_time'] = a['created_at']
+                        c['platform'] = '掌中云'
+                        dtime = datetime.datetime.strptime(a['created_at'][0:10], "%Y-%m-%d")
+                        c['date'] = ((int(time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
+                        c['stage'] = stage
+
+                        if str(a['from_novel_id']) != 'None':
+                            c['from_novel'] = a['from_novel']['title']
+                        else:
+                            c['from_novel'] = 'None'
+                        """
                         del[a['member']]
                         del[a['referral_link_id']]
                         del[a['id']]
@@ -445,339 +447,337 @@ def get_zzy_order(st, et):
                         del a['price']
                         del a['agent_uid']
                         """
-						x = sorted(c.items(), key=lambda item: item[0])
-						x = dict(x)
-						x = tuple(x.values())
-						r = r + ((x),)
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_zzy_order:', len(r), 'cost_minutes:', cost_time)
-	return r
+                        x = sorted(c.items(), key=lambda item: item[0])
+                        x = dict(x)
+                        x = tuple(x.values())
+                        r = r + ((x),)
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_zzy_order:', len(r), 'cost_minutes:', cost_time)
+    return r
 
 
 def get_ysg_order(st, et):
-	time1 = time.time()
-	key_list = al.ysg_account_list
-	url = 'https://novel.youshuge.com/v2/open/orders'
-	o = ()
-	for key in key_list:
-		host_name = key[0]
-		channel_id = key[1]
-		secert_key = key[2]
-		channel = key[3]
-		stage = key[4]
-		timestamp = int(time.time())
-		start_date = time.strftime("%Y-%m-%d", time.localtime(st))
-		end_date = time.strftime("%Y-%m-%d", time.localtime(et + 86400))
-		page = 1
-		str1 = 'channel_id=' + str(channel_id) + '&end_date=' + end_date + '&host_name=' + host_name + '&page=' + str(
-			page) + '&pay_status=1' + '&start_date=' + start_date + '&time=' + str(timestamp) + '&key=' + secert_key
-		sign = md5value(str1).upper()
-		data = {
-			'sign': sign,
-			'host_name': host_name,
-			'time': timestamp,
-			'channel_id': channel_id,
-			'page': page,
-			'pay_status': 1,
-			'start_date': start_date,
-			'end_date': end_date
-		}
-		r = requests.post(url, data).json()
-
-		if 'data' in r.keys():
-			if len(r['data']) > 0:
-				for i in range((r['data'][0]['count'] - 1) // 100 + 1):
-					timestamp = int(time.time())
-					str1 = 'channel_id=' + str(
-						channel_id) + '&end_date=' + end_date + '&host_name=' + host_name + '&page=' + str(
-						page) + '&pay_status=1' + '&start_date=' + start_date + '&time=' + str(
-						timestamp) + '&key=' + secert_key
-					sign = md5value(str1).upper()
-					data2 = {
-						'sign': sign,
-						'host_name': host_name,
-						'time': timestamp,
-						'channel_id': channel_id,
-						'page': page,
-						'pay_status': 1,
-						'start_date': start_date,
-						'end_date': end_date
-					}
-					r2 = requests.post(url, data2).json()
-
-					if 'data' in r2.keys():
-						if len(r2['data']) > 0:
-							for x in r2['data']:
-								t1 = time.strptime(x['create_time'], "%Y-%m-%d %H:%M:%S")
-								ts = int(time.mktime(t1))
-								if ts >= st and ts < et:
-									y = {}
-									y['order_id'] = x['order_num']
-									y['amount'] = round(int(x['price']) / 100, 2)
-									y['order_time'] = x['create_time']
-									y['channel'] = channel
-									y['from_novel'] = x['book_name']
-									y['stage'] = stage
-									y['user_id'] = x['openid']
-									y['channel_id'] = channel_id
-									dtime = datetime.datetime.strptime(x['create_time'][0:10], "%Y-%m-%d")
-									y['date'] = ((int(
-										time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
-									y['platform'] = '悠书阁'
-									y['reg_time'] = x['reg_time']
-
-									y = sorted(y.items(), key=lambda item: item[0])
-									y = dict(y)
-									y = tuple(y.values())
-									o = o + ((y),)
-					page = page + 1
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_ysg_order:', len(o), 'cost_minutes:', cost_time)
-	return o
+    time1 = time.time()
+    key_list = al.ysg_account_list
+    url = 'https://novel.youshuge.com/v2/open/orders'
+    o = ()
+    for key in key_list:
+        host_name = key[0]
+        channel_id = key[1]
+        secert_key = key[2]
+        channel = key[3]
+        stage = key[4]
+        timestamp = int(time.time())
+        start_date = time.strftime("%Y-%m-%d", time.localtime(st))
+        end_date = time.strftime("%Y-%m-%d", time.localtime(et + 86400))
+        page = 1
+        str1 = 'channel_id=' + str(channel_id) + '&end_date=' + end_date + '&host_name=' + host_name + '&page=' + str(
+            page) + '&pay_status=1' + '&start_date=' + start_date + '&time=' + str(timestamp) + '&key=' + secert_key
+        sign = md5value(str1).upper()
+        data = {
+            'sign': sign,
+            'host_name': host_name,
+            'time': timestamp,
+            'channel_id': channel_id,
+            'page': page,
+            'pay_status': 1,
+            'start_date': start_date,
+            'end_date': end_date
+        }
+        r = requests.post(url, data).json()
+
+        if 'data' in r.keys():
+            if len(r['data']) > 0:
+                for i in range((r['data'][0]['count'] - 1) // 100 + 1):
+                    timestamp = int(time.time())
+                    str1 = 'channel_id=' + str(
+                        channel_id) + '&end_date=' + end_date + '&host_name=' + host_name + '&page=' + str(
+                        page) + '&pay_status=1' + '&start_date=' + start_date + '&time=' + str(
+                        timestamp) + '&key=' + secert_key
+                    sign = md5value(str1).upper()
+                    data2 = {
+                        'sign': sign,
+                        'host_name': host_name,
+                        'time': timestamp,
+                        'channel_id': channel_id,
+                        'page': page,
+                        'pay_status': 1,
+                        'start_date': start_date,
+                        'end_date': end_date
+                    }
+                    r2 = requests.post(url, data2).json()
+
+                    if 'data' in r2.keys():
+                        if len(r2['data']) > 0:
+                            for x in r2['data']:
+                                t1 = time.strptime(x['create_time'], "%Y-%m-%d %H:%M:%S")
+                                ts = int(time.mktime(t1))
+                                if ts >= st and ts < et:
+                                    y = {}
+                                    y['order_id'] = x['order_num']
+                                    y['amount'] = round(int(x['price']) / 100, 2)
+                                    y['order_time'] = x['create_time']
+                                    y['channel'] = channel
+                                    y['from_novel'] = x['book_name']
+                                    y['stage'] = stage
+                                    y['user_id'] = x['openid']
+                                    y['channel_id'] = channel_id
+                                    dtime = datetime.datetime.strptime(x['create_time'][0:10], "%Y-%m-%d")
+                                    y['date'] = ((int(
+                                        time.mktime(dtime.timetuple())) + 8 * 3600) // 86400) * 86400 - 8 * 3600
+                                    y['platform'] = '悠书阁'
+                                    y['reg_time'] = x['reg_time']
+
+                                    y = sorted(y.items(), key=lambda item: item[0])
+                                    y = dict(y)
+                                    y = tuple(y.values())
+                                    o = o + ((y),)
+                    page = page + 1
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_ysg_order:', len(o), 'cost_minutes:', cost_time)
+    return o
 
 
 def daily_reports_get(access_token, account_id, level, fields):
-	interface = 'daily_reports/get'
-	url = 'https://api.e.qq.com/v1.1/' + interface
+    interface = 'daily_reports/get'
+    url = 'https://api.e.qq.com/v1.1/' + interface
 
-	common_parameters = {
-		'access_token': access_token,
-		'timestamp': int(time.time()),
-		'nonce': str(time.time()) + str(random.randint(0, 999999)),
-	}
+    common_parameters = {
+        'access_token': access_token,
+        'timestamp': int(time.time()),
+        'nonce': str(time.time()) + str(random.randint(0, 999999)),
+    }
 
-	parameters = {
-		"account_id": account_id,
-		"level": level,
-		"date_range":
-			{
-				"start_date": time.strftime("%Y-%m-%d", time.localtime()),
-				"end_date": time.strftime("%Y-%m-%d", time.localtime())
-			},
-		"page": 1,
-		"page_size": 1000,
-		"fields": fields
-	}
+    parameters = {
+        "account_id": account_id,
+        "level": level,
+        "date_range":
+            {
+                "start_date": time.strftime("%Y-%m-%d", time.localtime()),
+                "end_date": time.strftime("%Y-%m-%d", time.localtime())
+            },
+        "page": 1,
+        "page_size": 1000,
+        "fields": fields
+    }
 
-	parameters.update(common_parameters)
+    parameters.update(common_parameters)
 
-	for k in parameters:
-		if type(parameters[k]) is not str:
-			parameters[k] = json.dumps(parameters[k])
+    for k in parameters:
+        if type(parameters[k]) is not str:
+            parameters[k] = json.dumps(parameters[k])
 
-	r = requests.get(url, params=parameters)
+    r = requests.get(url, params=parameters)
 
-	return r.json()
+    return r.json()
 
 
 def get_daily_vx():
-	token_list_v = tl.token_list_vx
-	t = ()
-	time1 = time.time()
-
-	for y in token_list_v:
-		c = daily_reports_get(y[2], y[0], "REPORT_LEVEL_ADVERTISER_WECHAT", (
-		'date', 'cost', 'view_count', 'valid_click_count', 'ctr', 'official_account_follow_rate', 'order_amount',
-		'order_roi', 'order_count', 'order_rate', 'order_unit_price', 'web_order_cost', 'first_day_order_amount',
-		'first_day_order_count'))
-		if 'data' in c.keys():
-			for d in c['data']['list']:
-				d['account_id'] = y[0]
-				x = tuple(d.values())
-				t = t + ((x),)
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_daily_vx:', len(t), 'cost_minutes:', cost_time)
-
-	return t
+    token_list_v = tl.token_list_vx
+    t = ()
+    time1 = time.time()
+
+    for y in token_list_v:
+        c = daily_reports_get(y[2], y[0], "REPORT_LEVEL_ADVERTISER_WECHAT", (
+            'date', 'cost', 'view_count', 'valid_click_count', 'ctr', 'official_account_follow_rate', 'order_amount',
+            'order_roi', 'order_count', 'order_rate', 'order_unit_price', 'web_order_cost', 'first_day_order_amount',
+            'first_day_order_count'))
+        if 'data' in c.keys():
+            for d in c['data']['list']:
+                d['account_id'] = y[0]
+                x = tuple(d.values())
+                t = t + ((x),)
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_daily_vx:', len(t), 'cost_minutes:', cost_time)
+
+    return t
 
 
 def get_daily_qq():
-	token_list_q = tl.token_list_qq
-	t = ()
-	time1 = time.time()
+    token_list_q = tl.token_list_qq
+    t = ()
+    time1 = time.time()
 
-	for x in token_list_q:
-		a = daily_reports_get(x[2], x[0], "REPORT_LEVEL_ADVERTISER", (
-		'date', 'view_count', 'valid_click_count', 'ctr', 'cpc', 'cost', 'web_order_count', 'web_order_rate',
-		'web_order_cost', 'follow_count', 'order_amount', 'order_roi', 'platform_page_view_count',
-		'web_commodity_page_view_count', 'from_follow_uv'))
-		for b in a['data']['list']:
-			b['account_id'] = x[0]
-			y = tuple(b.values())
-			t = t + ((y),)
-	cost_time = round((time.time() - time1) / 60, 1)
-	print('get_qq_order:', len(t), 'cost_minutes:', cost_time)
+    for x in token_list_q:
+        a = daily_reports_get(x[2], x[0], "REPORT_LEVEL_ADVERTISER", (
+            'date', 'view_count', 'valid_click_count', 'ctr', 'cpc', 'cost', 'web_order_count', 'web_order_rate',
+            'web_order_cost', 'follow_count', 'order_amount', 'order_roi', 'platform_page_view_count',
+            'web_commodity_page_view_count', 'from_follow_uv'))
+        for b in a['data']['list']:
+            b['account_id'] = x[0]
+            y = tuple(b.values())
+            t = t + ((y),)
+    cost_time = round((time.time() - time1) / 60, 1)
+    print('get_qq_order:', len(t), 'cost_minutes:', cost_time)
 
-	return t
+    return t
 
 
 def mysql_insert_order(data):
-	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
-	cursor = db.cursor()
-	time1 = time.time()
-	# sql = 'insert ignore into quchen_text.order (amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
-	sql = 'replace into quchen_text.order(amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
-	try:
-		cursor.executemany(sql, data)
-		db.commit()
-		cost_time = round((time.time() - time1) / 60, 1)
-		print('insert_order access', len(data), 'cost_minutes:', cost_time)
-	except:
-		db.rollback()
-		print('insert_order defeat')
+    db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
+    cursor = db.cursor()
+    time1 = time.time()
+    # sql = 'insert ignore into quchen_text.order (amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
+    sql = 'replace into quchen_text.order(amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
+    try:
+        cursor.executemany(sql, data)
+        db.commit()
+        cost_time = round((time.time() - time1) / 60, 1)
+        print('insert_order access', len(data), 'cost_minutes:', cost_time)
+    except:
+        db.rollback()
+        print('insert_order defeat')
 
 
 def mysql_insert_daily_vx(data):
-	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
-	cursor = db.cursor()
-	time1 = time.time()
-	sql1 = 'delete from daily_vx where date = %s'
-	sql2 = 'insert ignore into daily_vx (date,cost,view_count,valid_click_count,ctr,official_account_follow_rate,order_amount,order_roi,order_count,order_rate,order_unit_price,web_order_cost,first_day_order_amount,first_day_order_count,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
-	try:
-		cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime())))
-		db.commit()
-		print('clear_daily_vx access')
-	except:
-		print('clear_daily_vx defeat')
-	try:
-		cursor.executemany(sql2, data)
-		db.commit()
-		cost_time = round((time.time() - time1) / 60, 1)
-		print('insert_daily_vx access', len(data), 'cost_minutes:', cost_time)
-	except:
-		db.rollback()
-		print('insert_daily_vx defeat')
+    db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
+    cursor = db.cursor()
+    time1 = time.time()
+    sql1 = 'delete from daily_vx where date = %s'
+    sql2 = 'insert ignore into daily_vx (date,cost,view_count,valid_click_count,ctr,official_account_follow_rate,order_amount,order_roi,order_count,order_rate,order_unit_price,web_order_cost,first_day_order_amount,first_day_order_count,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
+    try:
+        cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime())))
+        db.commit()
+        print('clear_daily_vx access')
+    except:
+        print('clear_daily_vx defeat')
+    try:
+        cursor.executemany(sql2, data)
+        db.commit()
+        cost_time = round((time.time() - time1) / 60, 1)
+        print('insert_daily_vx access', len(data), 'cost_minutes:', cost_time)
+    except:
+        db.rollback()
+        print('insert_daily_vx defeat')
 
 
 def mysql_insert_daily_qq(data):
-	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
-	cursor = db.cursor()
-	time1 = time.time()
-	sql1 = 'delete from daily_qq where date = %s'
-	sql2 = 'insert ignore into daily_qq (date,view_count,valid_click_count,ctr,cpc,cost,web_order_count,web_order_rate,web_order_cost,follow_count,order_amount,order_roi,platform_page_view_count,web_commodity_page_view_count,from_follow_uv,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
-	try:
-		cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime())))
-		db.commit()
-		print('clear_daily_qq access')
-	except:
-		print('clear_daily_qq defeat')
-	try:
-		cursor.executemany(sql2, data)
-		db.commit()
-		cost_time = round((time.time() - time1) / 60, 1)
-		print('insert_daily_qq access', len(data), 'cost_minutes:', cost_time)
-	except:
-		db.rollback()
-		print('insert_daily_qq defeat')
+    db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
+    cursor = db.cursor()
+    time1 = time.time()
+    sql1 = 'delete from daily_qq where date = %s'
+    sql2 = 'insert ignore into daily_qq (date,view_count,valid_click_count,ctr,cpc,cost,web_order_count,web_order_rate,web_order_cost,follow_count,order_amount,order_roi,platform_page_view_count,web_commodity_page_view_count,from_follow_uv,account_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
+    try:
+        cursor.execute(sql1, str(time.strftime("%Y-%m-%d", time.localtime())))
+        db.commit()
+        print('clear_daily_qq access')
+    except:
+        print('clear_daily_qq defeat')
+    try:
+        cursor.executemany(sql2, data)
+        db.commit()
+        cost_time = round((time.time() - time1) / 60, 1)
+        print('insert_daily_qq access', len(data), 'cost_minutes:', cost_time)
+    except:
+        db.rollback()
+        print('insert_daily_qq defeat')
 
 
 def send_waring_email():
-	msg_Sender = '2091961210@qq.cm'  # 发送方邮箱
-	msg_code = 'ylltzynbshmufdeh'  # 发送方邮箱的授权码
-	msg_Receiver = '2091961210@qq.cm'  # 收件人邮箱
-
-	subject = "数据库未按时更新"  # 主题
-	content = "数据库未按时更新"  # 正文
-	msg = MIMEText(content, _charset="utf-8")
-	msg['Subject'] = subject
-	msg['From'] = msg_Sender
-	msg['To'] = msg_Receiver
-	try:
-		s = smtplib.SMTP_SSL("smtp.qq.com", 465)  # 邮件服务器及端口号
-		s.login(msg_Sender, msg_code)
-		s.sendmail(msg_Sender, msg_Receiver, msg.as_string())
-		print("发送成功")
-	except Exception as e:
-		print("发送失败", e)
-	finally:
-		s.quit()
+    msg_Sender = '2091961210@qq.cm'  # 发送方邮箱
+    msg_code = 'ylltzynbshmufdeh'  # 发送方邮箱的授权码
+    msg_Receiver = '2091961210@qq.cm'  # 收件人邮箱
+
+    subject = "数据库未按时更新"  # 主题
+    content = "数据库未按时更新"  # 正文
+    msg = MIMEText(content, _charset="utf-8")
+    msg['Subject'] = subject
+    msg['From'] = msg_Sender
+    msg['To'] = msg_Receiver
+    try:
+        s = smtplib.SMTP_SSL("smtp.qq.com", 465)  # 邮件服务器及端口号
+        s.login(msg_Sender, msg_code)
+        s.sendmail(msg_Sender, msg_Receiver, msg.as_string())
+        print("发送成功")
+    except Exception as e:
+        print("发送失败", e)
+    finally:
+        s.quit()
 
 
 def update_check():
-	st_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
-	et_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600)
-	# et_unix = et_unix - 1
-
-	st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
-	et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
-
-	db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
-	cursor = db.cursor()
-	sql4 = "select platform,round(max(if(platform='掌读',order_time,unix_timestamp(order_time))),0) from quchen_text.order where date=%s and platform not in ('阳光','悠书阁')  group by platform "
-	data = (int((time.time() + 8 * 3600) // 86400 * 86400 - 8 * 3600))
-	try:
-		cursor.execute(sql4, data)
-		db.commit()
-		x = cursor.fetchall()
-		print('access', x)
-	except:
-		db.rollback()
-		print('defeat', x)
-	zzy = x[0][1] // 3600 * 3600
-	zhangdu = x[1][1] // 3600 * 3600
-	huasheng = x[2][1] // 3600 * 3600
-	yuewen = x[3][1] // 3600 * 3600
-	if zzy < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
-		mysql_insert_order(get_zzy_order(st_dt, et_dt))
-	if zhangdu < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
-		mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
-	if huasheng < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
-		mysql_insert_order(get_huasheng_order(st_unix, et_unix))
-	if yuewen < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
-		mysql_insert_order(get_yuewen_order(st_unix, et_unix - 1))
-
-	try:
-		cursor.execute(sql4, data)
-		db.commit()
-		z = cursor.fetchall()
-		print('access', z)
-	except:
-		db.rollback()
-		print('defeat', z)
-	a = []
-	for k in x:
-		a.append(k[1])
-	y = min(a) // 3600 * 3600
-
-	if y < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
-		send_waring_email()
+    st_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
+    et_unix = int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600)
+    # et_unix = et_unix - 1
+
+    st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
+    et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
+
+    db = pymysql.connect('rm-bp1c9cj79872tx3aaro.mysql.rds.aliyuncs.com', 'superc', 'Cc719199895', 'quchen_text')
+    cursor = db.cursor()
+    sql4 = "select platform,round(max(if(platform='掌读',order_time,unix_timestamp(order_time))),0) from quchen_text.order where date=%s and platform not in ('阳光','悠书阁')  group by platform "
+    data = (int((time.time() + 8 * 3600) // 86400 * 86400 - 8 * 3600))
+    try:
+        cursor.execute(sql4, data)
+        db.commit()
+        x = cursor.fetchall()
+        print('access', x)
+    except:
+        db.rollback()
+        print('defeat', x)
+    zzy = x[0][1] // 3600 * 3600
+    zhangdu = x[1][1] // 3600 * 3600
+    huasheng = x[2][1] // 3600 * 3600
+    yuewen = x[3][1] // 3600 * 3600
+    if zzy < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
+        mysql_insert_order(get_zzy_order(st_dt, et_dt))
+    if zhangdu < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
+        mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
+    if huasheng < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
+        mysql_insert_order(get_huasheng_order(st_unix, et_unix))
+    if yuewen < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
+        mysql_insert_order(get_yuewen_order(st_unix, et_unix - 1))
+
+    try:
+        cursor.execute(sql4, data)
+        db.commit()
+        z = cursor.fetchall()
+        print('access', z)
+    except:
+        db.rollback()
+        print('defeat', z)
+    a = []
+    for k in x:
+        a.append(k[1])
+    y = min(a) // 3600 * 3600
+
+    if y < int((time.time() + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600):
+        send_waring_email()
 
 
 def start_order_job():
-	st_unix_time = time.time()
-	st_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
-	et_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600)
-	# et_unix = et_unix - 1
-	st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
-	et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
-	print(st_dt, et_dt)
-	mysql_insert_order(get_yuewen_order(st_unix, et_unix))
-	mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
-	mysql_insert_order(get_ysg_order(st_unix, et_unix))
-	mysql_insert_order(get_zzy_order(st_dt, et_dt))
-	mysql_insert_order(get_huasheng_order(st_unix, et_unix))
-	update_check()
+    st_unix_time = time.time()
+    st_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
+    et_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600)
+    # et_unix = et_unix - 1
+    st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
+    et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
+    print(st_dt, et_dt)
+    mysql_insert_order(get_yuewen_order(st_unix, et_unix))
+    mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
+    mysql_insert_order(get_ysg_order(st_unix, et_unix))
+    mysql_insert_order(get_zzy_order(st_dt, et_dt))
+    mysql_insert_order(get_huasheng_order(st_unix, et_unix))
+    update_check()
 
 
 def start_cost_job():
-	st_unix_time = time.time()
-	st_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
-	et_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600)
-	# et_unix = et_unix - 1
-	st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
-	et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
-	print(st_dt, et_dt)
-	mysql_insert_daily_vx(get_daily_vx())
-	mysql_insert_daily_qq(get_daily_qq())
+    st_unix_time = time.time()
+    st_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600 - 3600)
+    et_unix = int((st_unix_time + 8 * 3600) // 3600 * 3600 - 8 * 3600)
+    # et_unix = et_unix - 1
+    st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
+    et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
+    print(st_dt, et_dt)
+    mysql_insert_daily_vx(get_daily_vx())
+    mysql_insert_daily_qq(get_daily_qq())
 
 
 start_order_time = '2020-09-28 18:10:00'
 start_cost_time = '2020-09-28 18:35:00'
 
 if __name__ == '__main__':
-	scheduler = BlockingScheduler()
-	scheduler.add_job(start_order_job, 'interval', max_instances=10, hours=1, start_date=start_order_time)
-	scheduler.add_job(start_cost_job, 'interval', max_instances=10, hours=1, start_date=start_cost_time)
-	scheduler.start()
-
-
+    scheduler = BlockingScheduler()
+    scheduler.add_job(start_order_job, 'interval', max_instances=10, hours=1, start_date=start_order_time)
+    scheduler.add_job(start_cost_job, 'interval', max_instances=10, hours=1, start_date=start_cost_time)
+    scheduler.start()

+ 74 - 72
dgp/tests/check_order.py

@@ -358,6 +358,7 @@ def get_huasheng_order_task(st, et, account, merchant):
     start_time = st
 
     for i in range((et - st) // 86400):
+        print('查询天数', i)
         page = 1
         date = time.strftime("%Y-%m-%d", time.localtime(start_time))
         sign = md5value(apiKEY + date + str(merchant_id) + timestamp + apiSecurity).upper()
@@ -374,6 +375,7 @@ def get_huasheng_order_task(st, et, account, merchant):
 
         if 'data' in list1.keys() and len(list1['data']) > 0:
             for i in range(int(math.ceil(list1['count'] / 500))):
+                print('查询页面', i)
                 data2 = {
                     'apiKey': apiKEY,
                     'apiSecurity': apiSecurity,
@@ -635,7 +637,7 @@ def mysql_insert_order(data):
         print('数据为空,不执行数据库操作!')
     else:
         sql = 'replace into quchen_text.`order_zwg` (amount,channel,channel_id,date,from_novel,order_id,order_time,platform,reg_time,stage,user_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
-        connect = MySQLConnection('test')
+        connect = MySQLConnection()
         try:
             num = connect.batch(sql, data)
             # 提交
@@ -649,7 +651,7 @@ def mysql_insert_order(data):
 # 获取各平台的订单数量
 def mysql_select_platform_order_count(date):
     sql = 'SELECT platform, COUNT(1) AS num FROM quchen_text.`order_zwg` WHERE date = %s GROUP BY platform'
-    connect = MySQLConnection('test')
+    connect = MySQLConnection()
     platform_order_count = []
     try:
         platform_order_count = connect.query(sql, date)
@@ -662,7 +664,6 @@ def mysql_select_platform_order_count(date):
 
 def start_all_job():
     start_exec_seconds = date_util.getCurrentSecondTime()
-    platform_order_num_list = mysql_select_platform_order_count(date_util.getYesterdayStartTime())
 
     st_unix = date_util.getYesterdayStartTime()
     et_unix = date_util.getTodayStartTime()
@@ -670,78 +671,79 @@ def start_all_job():
     print('查询开始时间:', st_unix, date_util.getSecondsToDatetime(st_unix))
     print('查询结束时间:', et_unix, date_util.getSecondsToDatetime(et_unix))
 
-    # order_list = get_yuewen_order(st_unix, et_unix)
-    # mysql_insert_order(order_list)
-
-    if len(platform_order_num_list) == 0:
-        print('本地库中没有任何数据,现在全平台补全')
-        mysql_insert_order(get_zzy_order(st_unix, et_unix))
-        mysql_insert_order(get_yuewen_order(st_unix, et_unix))
-        mysql_insert_order(get_huasheng_order(st_unix, et_unix))
-        mysql_insert_order(get_ysg_order(st_unix, et_unix))
-        mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
-    else:
-        platform_list = ['阅文','悠书阁','掌读','掌中云','花生']
-        for platform_order_num in platform_order_num_list:
-            platform = str(platform_order_num['platform'])
-            num = int(platform_order_num['num'])
-            platform_list.remove(platform)
-
-            if platform == '阅文':
-                order_list = get_yuewen_order(st_unix, et_unix)
-                if len(order_list) != num:
-                    print('阅文数据实际订单和已经入库数据差异:', len(order_list) - num)
-                    mysql_insert_order(order_list)
-            elif platform == '悠书阁':
-                order_list = get_ysg_order(st_unix, et_unix)
-                if len(order_list) != num:
-                    print('悠书阁数据实际订单和已经入库数据差异:', len(order_list) - num)
-                    mysql_insert_order(order_list)
-            elif platform == '掌读':
-                order_list = get_zhangdu_order(st_unix, et_unix)
-                if len(order_list) != num:
-                    print('掌读数据实际订单和已经入库数据差异:', len(order_list) - num)
-                    mysql_insert_order(order_list)
-            elif platform == '掌中云':
-                order_list = get_zzy_order(st_unix, et_unix)
-                if len(order_list) != num:
-                    print('掌中云数据实际订单和已经入库数据差异:', len(order_list) - num)
-                    mysql_insert_order(order_list)
-            elif platform == '花生':
-                order_list = get_huasheng_order(st_unix, et_unix)
-                if len(order_list) != num:
-                    print('花生数据实际订单和已经入库数据差异:', len(order_list) - num)
-                    mysql_insert_order(order_list)
-            else:
-                print('发现未知平台数据!', platform_order_num)
-
-        for platform in platform_list:
-            if platform == '阅文':
-                print('阅文没有数据')
-                mysql_insert_order(get_yuewen_order(st_unix, et_unix))
-            elif platform == '悠书阁':
-                print('悠书阁没有数据')
-                mysql_insert_order(get_ysg_order(st_unix, et_unix))
-            elif platform == '掌读':
-                print('掌读没有数据')
-                mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
-            elif platform == '掌中云':
-                print('掌中云没有数据')
-                mysql_insert_order(get_zzy_order(st_unix, et_unix))
-            elif platform == '花生':
-                print('花生没有数据')
-                mysql_insert_order(get_huasheng_order(st_unix, et_unix))
-            else:
-                print('什么鬼平台:', platform)
+    order_list = get_huasheng_order(st_unix, et_unix)
+    mysql_insert_order(order_list)
+
+    platform_order_num_listm_list = mysql_select_platform_order_count(date_util.getYesterdayStartTime())
+    # if len(platform_order_num_list) == 0:
+    #     print('本地库中没有任何数据,现在全平台补全')
+    #     mysql_insert_order(get_zzy_order(st_unix, et_unix))
+    #     mysql_insert_order(get_yuewen_order(st_unix, et_unix))
+    #     mysql_insert_order(get_huasheng_order(st_unix, et_unix))
+    #     mysql_insert_order(get_ysg_order(st_unix, et_unix))
+    #     mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
+    # else:
+    #     platform_list = ['阅文','悠书阁','掌读','掌中云','花生']
+    #     for platform_order_num in platform_order_num_list:
+    #         platform = str(platform_order_num['platform'])
+    #         num = int(platform_order_num['num'])
+    #         platform_list.remove(platform)
+    #
+    #         if platform == '阅文':
+    #             order_list = get_yuewen_order(st_unix, et_unix)
+    #             if len(order_list) != num:
+    #                 print('阅文数据实际订单和已经入库数据差异:', len(order_list) - num)
+    #                 mysql_insert_order(order_list)
+    #         elif platform == '悠书阁':
+    #             order_list = get_ysg_order(st_unix, et_unix)
+    #             if len(order_list) != num:
+    #                 print('悠书阁数据实际订单和已经入库数据差异:', len(order_list) - num)
+    #                 mysql_insert_order(order_list)
+    #         elif platform == '掌读':
+    #             order_list = get_zhangdu_order(st_unix, et_unix)
+    #             if len(order_list) != num:
+    #                 print('掌读数据实际订单和已经入库数据差异:', len(order_list) - num)
+    #                 mysql_insert_order(order_list)
+    #         elif platform == '掌中云':
+    #             order_list = get_zzy_order(st_unix, et_unix)
+    #             if len(order_list) != num:
+    #                 print('掌中云数据实际订单和已经入库数据差异:', len(order_list) - num)
+    #                 mysql_insert_order(order_list)
+    #         elif platform == '花生':
+    #             order_list = get_huasheng_order(st_unix, et_unix)
+    #             if len(order_list) != num:
+    #                 print('花生数据实际订单和已经入库数据差异:', len(order_list) - num)
+    #                 mysql_insert_order(order_list)
+    #         else:
+    #             print('发现未知平台数据!', platform_order_num)
+    #
+    #     for platform in platform_list:
+    #         if platform == '阅文':
+    #             print('阅文没有数据')
+    #             mysql_insert_order(get_yuewen_order(st_unix, et_unix))
+    #         elif platform == '悠书阁':
+    #             print('悠书阁没有数据')
+    #             mysql_insert_order(get_ysg_order(st_unix, et_unix))
+    #         elif platform == '掌读':
+    #             print('掌读没有数据')
+    #             mysql_insert_order(get_zhangdu_order(st_unix, et_unix))
+    #         elif platform == '掌中云':
+    #             print('掌中云没有数据')
+    #             mysql_insert_order(get_zzy_order(st_unix, et_unix))
+    #         elif platform == '花生':
+    #             print('花生没有数据')
+    #             mysql_insert_order(get_huasheng_order(st_unix, et_unix))
+    #         else:
+    #             print('什么鬼平台:', platform)
 
 
     print('订单检查执行时间(秒):', date_util.getCurrentSecondTime() - start_exec_seconds)
 
 
 if __name__ == '__main__':
-    # start_all_job()
-
-    scheduler = BlockingScheduler()
-    #每天凌晨3点到4点的30分钟都执行一次
-    scheduler.add_job(start_all_job, 'cron', hour='3-4', minute='35')
-    scheduler.start()
+    start_all_job()
+    #
+    # scheduler = BlockingScheduler()
+    # #每天凌晨3点到4点的30分钟都执行一次
+    # scheduler.add_job(start_all_job, 'cron', hour='3-4', minute='35')
+    # scheduler.start()

+ 73 - 59
dgp/tests/check_order_new.py

@@ -61,6 +61,7 @@ def get_yuewen_order(st, et):
     for account in account_list:
         future = executor.submit(get_yuewen_order_task, st, et, account)
         futures.append(future)
+
     executor.shutdown(True)
 
     for future in futures:
@@ -79,7 +80,7 @@ def get_yuewen_order_task(st, et, account):
     email = account[0]
     appsecert = account[1]
 
-    for i in range(int((et - st) / 86400)):
+    for i in range((et - st) // 86400 + 1):
         end_time = min(start_time + 86400, et)
         timestamp = int(time.time())
         s = ''
@@ -318,7 +319,7 @@ def get_huasheng_order(st, et):
     total_order_list = ()
     account_list = platform_util.get_huasheng_account_list()
 
-    executor = ProcessPoolExecutor(max_workers=5)
+    executor = ProcessPoolExecutor(max_workers=10)
 
     futures = []
     for account in account_list:
@@ -361,63 +362,69 @@ def get_huasheng_order_task(st, et, account, merchant):
     stage = account[2]
     timestamp = str(int(time.time()))
 
+    order_url = 'https://vip.rlcps.cn/api/orderList'
     merchant_id = merchant['merchant_id']
     merchant_name = merchant['merchant_name']
-    order_url = 'https://vip.rlcps.cn/api/orderList'
     start_time = st
 
-    for i in range((et - st) // 86400):
+    for i in range((et - st) // 86400 + 1):
         page = 1
-        date = time.strftime("%Y-%m-%d", time.localtime(start_time))
-        sign = md5value(apiKey + date + str(merchant_id) + timestamp + apiSecurity).upper()
-        order_params = {
-            'apiKey': apiKey,
-            'apiSecurity': apiSecurity,
-            'timestamp': timestamp,
-            'date': date,
-            'merchant_id': merchant_id,
-            'sign': sign,
-            'page': page
-        }
-        list1 = requests.post(order_url, order_params).json()
+        limit = 500
+
+        while True:
+            date = time.strftime("%Y-%m-%d", time.localtime(start_time))
+            sign = md5value(apiKey + date + str(merchant_id) + timestamp + apiSecurity).upper()
+            order_params = {
+                'apiKey': apiKey,
+                'apiSecurity': apiSecurity,
+                'timestamp': timestamp,
+                'date': date,
+                'merchant_id': merchant_id,
+                'sign': sign,
+                'page': page,
+                'limit': limit
+            }
+            response_result_json = requests.post(order_url, order_params).json()
+
+            if 'data' not in response_result_json.keys() or len(response_result_json['data']) == 0:
+                print('花生账号【{key}】, 渠道【{merchant_id}:{merchant_name}】本次请求数据为空,响应报文【{result}】'
+                      .format(key=apiKey, merchant_id=merchant_id, merchant_name=merchant_name, result=response_result_json))
+
+            total_count = response_result_json['count']
+            order_item_list = response_result_json['data']
+
+            for order_item in order_item_list:
+                if order_item['order_status'] == 1:#1为已支付
+                    order = {}
+                    ##dtime = datetime.datetime.strptime(order_item['pay_at'],"%Y-%m-%d")
+                    ##order['date']= ((int(time.mktime(dtime.timetuple()))+8*3600)//86400)*86400-8*3600
+                    order['user_id'] = order_item['openid']
+                    order['order_id'] = order_item['trans_id']
+                    order['order_time'] = order_item['pay_at']
+                    order['reg_time'] = order_item['join_at']
+                    #TODO 花生的时间需要统一
+                    order['date'] = (start_time + 8 * 3600) // 86400 * 86400 - 8 * 3600
+                    order['channel'] = merchant_name
+                    order['channel_id'] = merchant_id
+                    order['platform'] = '花生'
+                    order['stage'] = stage
+                    order['from_novel'] = order_item['book_name']
+                    order['amount'] = order_item['amount']
+
+                    order = sorted(order.items(), key=lambda item: item[0])
+                    order = dict(order)
+                    order = tuple(order.values())
+                    order_list = order_list + ((order),)
+
+            if int(page) >= math.ceil(total_count / int(limit)):
+                break
+
+            # print('花生账号【{key}】, 渠道【{merchant_id}:{merchant_name}】当前页【{page}】,本次查询订单数【{total_count}】,即将查询下一页'
+            #       .format(key=apiKey, merchant_id=merchant_id, merchant_name=merchant_name, page=page, total_count=total_count))
 
-        if 'data' in list1.keys() and len(list1['data']) > 0:
-            for i in range(int(math.ceil(list1['count'] / 500))):
-                data2 = {
-                    'apiKey': apiKey,
-                    'apiSecurity': apiSecurity,
-                    'timestamp': timestamp,
-                    'date': date,
-                    'merchant_id': merchant_id,
-                    'sign': sign,
-                    'page': page
-                }
-                list2 = requests.post(order_url, data2).json()
-
-                for x in list2['data']:
-                    if x['order_status'] == 1:
-                        y = {}
-                        ##dtime = datetime.datetime.strptime(x['pay_at'],"%Y-%m-%d")
-                        ##y['date']= ((int(time.mktime(dtime.timetuple()))+8*3600)//86400)*86400-8*3600
-                        y['user_id'] = x['openid']
-                        y['order_id'] = x['trans_id']
-                        y['order_time'] = x['pay_at']
-                        y['reg_time'] = x['join_at']
-                        y['date'] = (start_time + 8 * 3600) // 86400 * 86400 - 8 * 3600
-                        y['channel'] = merchant_name
-                        y['channel_id'] = merchant_id
-                        y['platform'] = '花生'
-                        y['stage'] = stage
-                        y['from_novel'] = x['book_name']
-                        y['amount'] = x['amount']
-
-                        y = sorted(y.items(), key=lambda item: item[0])
-                        y = dict(y)
-                        y = tuple(y.values())
-                        order_list = order_list + ((y),)
-                page = page + 1
+            page = page + 1
 
-        start_time = start_time + 86400
+        start_time = start_time + 86400 #天数加1
 
     return order_list
 
@@ -439,8 +446,8 @@ def get_zzy_order(st, et):
         key = account[0]
         secert = account[1]
         sign = md5value(secert + 'key=' + key)
-        parameter = 'key=' + key + '&sign=' + sign
-        response_result_json = requests.get(url + parameter).json()# 获取子渠道列表
+        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))
@@ -486,9 +493,9 @@ def get_zzy_order_task(st, et, account, channel):
 
     while True:
         sign = md5value(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)
-        parameter = 'channel_id=' + str(channel_id) + '&' + gte + '&' + lt + '&page=' + str(page) + '&per_page=' + per_page + '&status=' + status + '&key=' + key + '&sign=' + sign
+        params = 'channel_id=' + str(channel_id) + '&' + gte + '&' + lt + '&page=' + str(page) + '&per_page=' + per_page + '&status=' + status + '&key=' + key + '&sign=' + sign
 
-        response_result_json = requests.get(order_url + parameter).json()
+        response_result_json = requests.get(order_url + params).json()
 
         if 'data' not in response_result_json.keys():
             print('掌中云账号【{key}】, 渠道【{channel_id}:{channel_name}】本次请求数据为空,响应报文【{result}】'
@@ -516,6 +523,7 @@ def get_zzy_order_task(st, et, account, channel):
                 order['from_novel'] = order_item['from_novel']['title']
             else:
                 order['from_novel'] = 'None'
+
             x = sorted(order.items(), key=lambda item: item[0])
             x = dict(x)
             x = tuple(x.values())
@@ -524,8 +532,9 @@ def get_zzy_order_task(st, et, account, channel):
         if int(page) >= math.ceil(total_count / int(per_page)):
             break
 
-        print('掌中云账号【{key}】, 渠道【{channel_id}:{channel_name}】当前页【{page}】,本次查询订单数【{total_count}】,即将查询下一页'
-              .format(key=key, channel_id=channel_id, channel_name=channel_name, page=page, total_count=total_count))
+        # print('掌中云账号【{key}】, 渠道【{channel_id}:{channel_name}】当前页【{page}】,本次查询订单数【{total_count}】,即将查询下一页'
+        #       .format(key=key, channel_id=channel_id, channel_name=channel_name, page=page, total_count=total_count))
+
         page = int(page) + 1
 
     return order_list
@@ -685,10 +694,15 @@ def start_all_job():
     st_unix = date_util.getYesterdayStartTime()
     et_unix = date_util.getTodayStartTime()
 
+    st_unix = 1601136000 #2020/9/27 0:0:0
+    et_unix = 1601308800 #2020/9/29 0:0:0
+
+
+
     print('查询开始时间:', st_unix, date_util.getSecondsToDatetime(st_unix))
     print('查询结束时间:', et_unix, date_util.getSecondsToDatetime(et_unix))
 
-    order_list = get_zzy_order(st_unix, et_unix)
+    order_list = get_yuewen_order(st_unix, et_unix)
     mysql_insert_order(order_list)
 
     # platform_order_num_list = mysql_select_platform_order_count(date_util.getYesterdayStartTime())

+ 28 - 51
dgp/tests/demo/test.py

@@ -43,57 +43,34 @@ a = 10817
 if __name__ == '__main__':
     log = LoggerService.logger_file('../test.log', 'abcd')
 
-    print(int(time.time()))
-    print(date_util.getCurrentSecondTime())
-
-    # print(date_util.getYesterdayStartTime(), platform_util.get_zhangzhongyun_format_time(date_util.getYesterdayStartTime()))
-
-    request_time_stamp = time.time()
-    st_unix = int((request_time_stamp + 8 * 3600) // 86400 * 86400 - 8 * 3600 - 86400)  # 昨天开始时间
-    et_unix = int((request_time_stamp + 8 * 3600) // 86400 * 86400 - 8 * 3600)  # 昨天结束时间==(今天开始时间-1)
-    st_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(st_unix)) + '+08:00'
-    et_dt = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(et_unix)) + '+08:00'
-    print(st_unix, st_dt)
-    print(et_unix, et_dt)
-
-    et_unix = et_unix - 1
-    print('========')
-    print((et_unix - st_unix))
-    timespace = 90 * 3600 * 24
-    print(timespace)
-    print((et_unix - st_unix) // timespace + 1)
-    for x in range((et_unix - st_unix) // timespace + 1):  # 分时段
-        print('x=', x)
-
-    print((et_unix - st_unix) / 86400 + 1)
-    for i in range(int((et_unix - st_unix) / 86400 + 1)):
-        print('i=', i)
-    for y in range(1):  # 分时段
-        print('y=', y)
-
-# print('时间转换')
-# print(date_util.getYesterdayStartTime(), date_util.getSecondsToDatetime(date_util.getYesterdayStartTime()))
-# print(date_util.getYesterdayEndTime(), date_util.getSecondsToDatetime(date_util.getYesterdayEndTime()))
-# print(date_util.getTodayStartTime(), date_util.getSecondsToDatetime(date_util.getTodayStartTime()))
-#
-# print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(date_util.getYesterdayStartTime())))
-# print(date_util.getCurrentSecondTime())
-# print(date_util.getSecondsToDatetime())
-# print(date_util.getSecondsToDatetime(date_util.getYesterdayStartTime()))
-# print(date_util.getSecondsToDatetime(date_util.getYesterdayStartTime(), "%Y-%m-%d %H:%M:%S"))
-
-    sql = "select * from quchen_text.order where date=1601136000 and platform = '悠书阁'"
-    connect = MySQLConnection()
-    try:
-        page = 1
-        size = 50
-        pagination = connect.listByPage(sql, page, size)
-        print(pagination)
-    except Exception as e:
-        log.exception(e)
-    finally:
-        # 关闭数据库连接
-        connect.close()
+    st_unix = date_util.getYesterdayStartTime()
+    et_unix = date_util.getTodayStartTime()
+
+    et_unix = 1601136000
+    et_unix = 1601139600
+
+    print(1.4)
+    print(int(1.4))
+    for i in range(int((et_unix - st_unix) // 86400)):
+        print('i', i)
+
+    for i in range((et_unix - st_unix) // 86400):
+        print('i', i)
+
+    # sql = "select * from quchen_text.order where date=1601136000 and platform = '悠书阁'"
+    # connect = MySQLConnection()
+    # try:
+    #     page = 1
+    #     size = 50
+    #     pagination = connect.listByPage(sql, page, size)
+    #     print(pagination)
+    # except Exception as e:
+    #     log.exception(e)
+    # finally:
+    #     # 关闭数据库连接
+    #     connect.close()
+
+
 
     # scheduler = BlockingScheduler()
     #