|
@@ -20,12 +20,12 @@ from django.db.models import Q, Sum, Count
|
|
|
from django.views import View
|
|
|
|
|
|
from Ansjer.config import USED_SERIAL_REDIS_LIST, UNUSED_SERIAL_REDIS_LIST, CONFIG_INFO, CONFIG_US, \
|
|
|
- RESET_REGION_ID_SERIAL_REDIS_LIST, LOGGER, PAYPAL_CRD
|
|
|
+ RESET_REGION_ID_SERIAL_REDIS_LIST, LOGGER, PAYPAL_CRD, CONFIG_EUR
|
|
|
from Model.models import Device_User, Device_Info, UidSetModel, UID_Bucket, Unused_Uid_Meal, Order_Model, StsCrdModel, \
|
|
|
VodHlsModel, ExperienceContextModel, AiService, VodHlsSummary, VideoPlaybackTimeModel, DeviceUserSummary, \
|
|
|
CountryModel, DeviceTypeModel, OrdersSummary, DeviceInfoSummary, CompanySerialModel, \
|
|
|
CloudLogModel, UidCloudStorageCount, UserExModel, DeviceDomainRegionModel, VodHlsTag, VodHlsTagType, \
|
|
|
- Store_Meal, Lang, VodBucketModel, UnicomComboOrderInfo, UnicomDeviceInfo, AbnormalOrder
|
|
|
+ Store_Meal, Lang, VodBucketModel, UnicomComboOrderInfo, UnicomDeviceInfo, AbnormalOrder, DailyReconciliation
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
@@ -35,6 +35,7 @@ from Service.VodHlsService import SplitVodHlsObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
from Object.WechatPayObject import WechatPayObject
|
|
|
from Object.AliPayObject import AliPayObject
|
|
|
+from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
|
|
|
class CronDelDataView(View):
|
|
@@ -1232,6 +1233,8 @@ class CronComparedDataView(View):
|
|
|
return self.compared_wechat_order(response)
|
|
|
elif operation == 'AlipayOrder': # 定时对比阿里订单
|
|
|
return self.compared_alipay_order(response)
|
|
|
+ elif operation == 'AnsjerOrder': # 定时对比后台订单
|
|
|
+ return self.compared_ansjer_order(response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -1263,7 +1266,13 @@ class CronComparedDataView(View):
|
|
|
@staticmethod
|
|
|
def thread_compared_pyapal_order(order_list):
|
|
|
now_time = int(time.time())
|
|
|
+ now = datetime.datetime.now()
|
|
|
+ midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
|
|
+ timestamp = midnight.timestamp()
|
|
|
+ count = len(order_list)
|
|
|
+ total = 0
|
|
|
for item in order_list:
|
|
|
+ total += item['transaction_info']['transaction_amount']['value']
|
|
|
trade_no = item['transaction_info']['transaction_id']
|
|
|
if item['transaction_info']['transaction_event_code'] == 'T1107':
|
|
|
trade_no = item['transaction_info']['paypal_reference_id']
|
|
@@ -1298,6 +1307,12 @@ class CronComparedDataView(View):
|
|
|
if result['result_code'] != 0 or not result['result']['is_exist']:
|
|
|
# 如果响应结果为空,记录在数据库
|
|
|
AbnormalOrder.objects.create(**order_dict)
|
|
|
+ daily_reconciliation = DailyReconciliation.objects.filter(time=timestamp)
|
|
|
+ if daily_reconciliation.exists():
|
|
|
+ daily_reconciliation.update(paypal_num=count, paypal_total=total, upd_time=now_time)
|
|
|
+ else:
|
|
|
+ DailyReconciliation.objects.create(paypal_num=count, paypal_total=total, time=timestamp,
|
|
|
+ creat_time=now_time, upd_time=now_time)
|
|
|
|
|
|
@staticmethod
|
|
|
def compared_wechat_order(response):
|
|
@@ -1393,4 +1408,69 @@ class CronComparedDataView(View):
|
|
|
'meal_name': order['商品名称'].replace('\t', ''),
|
|
|
'username': order['对方账户'].replace('\t', ''),
|
|
|
}
|
|
|
- AbnormalOrder.objects.create(**order_dict)
|
|
|
+ AbnormalOrder.objects.create(**order_dict)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def compared_ansjer_order(response):
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ start_date = today - datetime.timedelta(days=2)
|
|
|
+ start_date = datetime.datetime(start_date.year, start_date.month, start_date.day)
|
|
|
+ end_date = start_date + datetime.timedelta(days=1)
|
|
|
+ start_date_stamp = int(start_date.timestamp())
|
|
|
+ end_date_stamp = int(end_date.timestamp())
|
|
|
+ try:
|
|
|
+ order_qs = Order_Model.objects.filter(status=1, payType=1, payTime__gte=start_date_stamp,
|
|
|
+ payTime__lt=end_date_stamp).values('trade_no', 'price', 'payTime')
|
|
|
+ if CONFIG_INFO == CONFIG_EUR:
|
|
|
+ return response.json(0, list(order_qs))
|
|
|
+ thread = threading.Thread(target=CronComparedDataView.thread_compared_ansjer_order,
|
|
|
+ args=(list(order_qs), start_date))
|
|
|
+ thread.start()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('CronComparedDataView.compared_paypal_order, errLine:{}, errMsg:{}'.format(
|
|
|
+ e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def thread_compared_ansjer_order(order_list, start_time):
|
|
|
+ while True:
|
|
|
+ response = requests.get('https://www.zositeche.com/cron/compared/AnsjerOrder')
|
|
|
+ if response.status_code == 200:
|
|
|
+ result = response.json()
|
|
|
+ if result['result_code'] == 0:
|
|
|
+ eur_order_list = result['result']
|
|
|
+ break
|
|
|
+ begin_date = datetime.datetime(start_time.year, start_time.month, 1)
|
|
|
+ start_timestamp = int(start_time.timestamp())
|
|
|
+ end_date = begin_date + relativedelta(months=1)
|
|
|
+ now_time = int(time.time())
|
|
|
+ more_order_list = []
|
|
|
+ total = 0
|
|
|
+ all_order_list = order_list + eur_order_list
|
|
|
+ count = len(all_order_list)
|
|
|
+
|
|
|
+ for index, order in enumerate(all_order_list):
|
|
|
+ total += order['price']
|
|
|
+ if all_order_list.index(order) != index:
|
|
|
+ more_order_list.append(order['trade_no'])
|
|
|
+ continue
|
|
|
+ data = (
|
|
|
+ ('start_date', '{}-{}-01T00:00:00-0700'.format(begin_date.year, begin_date.month)),
|
|
|
+ ('end_date', '{}-{}-01T00:00:00-0700'.format(end_date.year, end_date.month)),
|
|
|
+ ('transaction_id', order['trade_no']),
|
|
|
+ ('fields', 'all'),
|
|
|
+ ('page_size', '100'),
|
|
|
+ ('page', '1'),
|
|
|
+ )
|
|
|
+ paypal_order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(
|
|
|
+ data)
|
|
|
+ if not paypal_order_list['transaction_details']:
|
|
|
+ more_order_list.append(order['trade_no'])
|
|
|
+ trade_nos = ','.join(more_order_list)
|
|
|
+ daily_reconciliation = DailyReconciliation.objects.filter(time=start_timestamp)
|
|
|
+ if daily_reconciliation.exists():
|
|
|
+ daily_reconciliation.update(ansjer_total=total, ansjer_num=count, trade_nos=trade_nos, upd_time=now_time)
|
|
|
+ else:
|
|
|
+ DailyReconciliation.objects.create(trade_nos=trade_nos, ansjer_total=total, ansjer_num=count,
|
|
|
+ time=start_timestamp, crete_time=now_time, upd_time=now_time)
|