|
@@ -8,10 +8,13 @@
|
|
|
# @File : CronTaskController.py
|
|
|
# @Software: PyCharm
|
|
|
import datetime
|
|
|
+import io
|
|
|
import threading
|
|
|
import time
|
|
|
+import zipfile
|
|
|
|
|
|
import requests
|
|
|
+import csv
|
|
|
from django.db import connection, connections, transaction
|
|
|
from django.db.models import Q, Sum, Count
|
|
|
from django.views import View
|
|
@@ -31,6 +34,7 @@ from Service.CommonService import CommonService
|
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
from Object.WechatPayObject import WechatPayObject
|
|
|
+from Object.AliPayObject import AliPayObject
|
|
|
|
|
|
|
|
|
class CronDelDataView(View):
|
|
@@ -1303,7 +1307,7 @@ class CronComparedDataView(View):
|
|
|
thread.start()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
- LOGGER.info('CronComparedDataView.compared_paypal_order, errLine:{}, errMsg:{}'.format(
|
|
|
+ LOGGER.info('CronComparedDataView.compared_wechat_order, errLine:{}, errMsg:{}'.format(
|
|
|
e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500)
|
|
|
|
|
@@ -1326,3 +1330,63 @@ class CronComparedDataView(View):
|
|
|
'meal_name': order['商品名称'].replace('`', ''),
|
|
|
}
|
|
|
AbnormalOrder.objects.create(**order_dict)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def compared_alipay_order(response):
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ start_date = today - datetime.timedelta(days=1)
|
|
|
+ start_date = start_date.strftime("%Y-%m-%d")
|
|
|
+ try:
|
|
|
+ ali_pay_obj = AliPayObject()
|
|
|
+ alipay = ali_pay_obj.conf()
|
|
|
+ result = alipay.server_api(
|
|
|
+ api_name='alipay.data.dataservice.bill.downloadurl.query',
|
|
|
+ biz_content={'bill_type': 'trade',
|
|
|
+ 'bill_date': start_date,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ res = requests.get(result['bill_download_url'])
|
|
|
+ zip_file = res.content
|
|
|
+ zip_data = io.BytesIO(zip_file)
|
|
|
+ data = []
|
|
|
+ with zipfile.ZipFile(zip_data, 'r') as zip_ref:
|
|
|
+ for file in zip_ref.namelist():
|
|
|
+ if '汇总' not in file.encode('cp437').decode('gbk'):
|
|
|
+ with zip_ref.open(file) as f:
|
|
|
+ reader = csv.reader(io.TextIOWrapper(f))
|
|
|
+ for row in reader:
|
|
|
+ data.append(row)
|
|
|
+ key_list = data[4]
|
|
|
+ orders = data[5:-4]
|
|
|
+ order_list = []
|
|
|
+ for item in orders:
|
|
|
+ order_list.append(dict(zip(key_list, item)))
|
|
|
+ thread = threading.Thread(target=CronComparedDataView.thread_compared_alipay_order,
|
|
|
+ args=(order_list,))
|
|
|
+ thread.start()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('CronComparedDataView.compared_alipay_order, errLine:{}, errMsg:{}'.format(
|
|
|
+ e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def thread_compared_alipay_order(order_list):
|
|
|
+ now_time = int(time.time())
|
|
|
+ for order in order_list:
|
|
|
+ order_id = order['商户订单号'].replace('\t', '')
|
|
|
+ if len(order_id) != 20:
|
|
|
+ continue
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=order_id)
|
|
|
+ if not order_qs.exists():
|
|
|
+ order_dict = {
|
|
|
+ 'trade_no': order['支付宝交易号'].replace('\t', ''),
|
|
|
+ 'order_id': order_id,
|
|
|
+ 'pay_type': 2,
|
|
|
+ 'price': order['订单金额(元)'].replace('\t', ''),
|
|
|
+ 'pay_time': int(datetime.datetime.strptime(order['完成时间'], "%Y-%m-%d %H:%M:%S").timestamp()),
|
|
|
+ 'upd_time': now_time,
|
|
|
+ 'meal_name': order['商品名称'].replace('\t', ''),
|
|
|
+ 'username': order['对方账户'].replace('\t', ''),
|
|
|
+ }
|
|
|
+ AbnormalOrder.objects.create(**order_dict)
|