|
@@ -14,10 +14,12 @@ from django.db import transaction
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Model.models import UnicomDeviceInfo, UnicomCombo, Pay_Type, Order_Model, Store_Meal, AiStoreMeal
|
|
|
|
|
|
+from Model.models import UnicomDeviceInfo, UnicomCombo, Pay_Type, Order_Model, Store_Meal, AiStoreMeal, \
|
|
|
|
+ UnicomComboOrderInfo
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.UnicomObject import UnicomObjeect
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
from Object.utils.PayUtil import PayService
|
|
from Object.utils.PayUtil import PayService
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
@@ -36,10 +38,13 @@ class UnicomComboView(View):
|
|
def validation(self, request_dict, request, operation):
|
|
def validation(self, request_dict, request, operation):
|
|
if operation == 'buy-notify':
|
|
if operation == 'buy-notify':
|
|
return self.package_callback_notify(request_dict, request)
|
|
return self.package_callback_notify(request_dict, request)
|
|
- elif operation == 'alipay-notify':
|
|
|
|
- pass
|
|
|
|
- elif operation == 'wechat-notify':
|
|
|
|
- pass
|
|
|
|
|
|
+ elif operation == 'test-notify':
|
|
|
|
+ order_id = request_dict.get('orderId', None)
|
|
|
|
+ activate_type = request_dict.get('activateType', 0)
|
|
|
|
+ iccid = request_dict.get('iccid', None)
|
|
|
|
+ combo_id = request_dict.get('comboId', None)
|
|
|
|
+ self.create_combo_order_info(order_id, int(activate_type), iccid, int(combo_id))
|
|
|
|
+ return HttpResponse('SUCCESS')
|
|
elif operation == 'device-queue-monitoring':
|
|
elif operation == 'device-queue-monitoring':
|
|
return self.device_queue_monitoring_push(request_dict, request)
|
|
return self.device_queue_monitoring_push(request_dict, request)
|
|
elif operation == 'device-status-change':
|
|
elif operation == 'device-status-change':
|
|
@@ -205,6 +210,7 @@ class UnicomComboView(View):
|
|
iccid = request_dict.get('iccid', None)
|
|
iccid = request_dict.get('iccid', None)
|
|
combo_id = request_dict.get('id', None)
|
|
combo_id = request_dict.get('id', None)
|
|
pay_type = request_dict.get('payType', None)
|
|
pay_type = request_dict.get('payType', None)
|
|
|
|
+ activate_type = request.get('activateType', 0)
|
|
if not all([iccid, combo_id, pay_type]):
|
|
if not all([iccid, combo_id, pay_type]):
|
|
return response.json(444)
|
|
return response.json(444)
|
|
combo_id = int(combo_id)
|
|
combo_id = int(combo_id)
|
|
@@ -234,10 +240,13 @@ class UnicomComboView(View):
|
|
'updTime': now_time,
|
|
'updTime': now_time,
|
|
'unify_combo_id': str(unicom_combo_qs['id']), 'order_type': 2,
|
|
'unify_combo_id': str(unicom_combo_qs['id']), 'order_type': 2,
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ params = 'lang=cn' + '&activateType=' + activate_type
|
|
if pay_type == 2: # 支付宝
|
|
if pay_type == 2: # 支付宝
|
|
pay_price = PayService.get_two_float(price, 2)
|
|
pay_price = PayService.get_two_float(price, 2)
|
|
notify_url = 'unicom/wap/pay/ali-notify'
|
|
notify_url = 'unicom/wap/pay/ali-notify'
|
|
- order_dict['pay_url'] = PayService.create_alipay_payment('cn', order_id, pay_price,
|
|
|
|
|
|
+
|
|
|
|
+ order_dict['pay_url'] = PayService.create_alipay_payment(params, order_id, pay_price,
|
|
unicom_combo_qs['combo_name'],
|
|
unicom_combo_qs['combo_name'],
|
|
notify_url,
|
|
notify_url,
|
|
unicom_combo_qs['remark'], response)
|
|
unicom_combo_qs['remark'], response)
|
|
@@ -245,7 +254,8 @@ class UnicomComboView(View):
|
|
elif pay_type == 3: # 微信支付
|
|
elif pay_type == 3: # 微信支付
|
|
notify_url = 'unicom/wap/pay/wechat-notify'
|
|
notify_url = 'unicom/wap/pay/wechat-notify'
|
|
ip = CommonService.get_ip_address(request)
|
|
ip = CommonService.get_ip_address(request)
|
|
- order_dict['pay_url'], sign_params = PayService.create_wechat_payment('cn', order_id, price, ip,
|
|
|
|
|
|
+ order_dict['pay_url'], sign_params = PayService.create_wechat_payment(params, order_id,
|
|
|
|
+ price, ip,
|
|
notify_url,
|
|
notify_url,
|
|
unicom_combo_qs['remark'],
|
|
unicom_combo_qs['remark'],
|
|
response)
|
|
response)
|
|
@@ -360,3 +370,82 @@ class UnicomComboView(View):
|
|
print(repr(e))
|
|
print(repr(e))
|
|
r_data = {'success': False, 'msg': '失败'}
|
|
r_data = {'success': False, 'msg': '失败'}
|
|
return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
|
|
return HttpResponse(json.dumps(r_data, ensure_ascii=False), content_type="application/json,charset=utf-8")
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def create_combo_order_info(cls, order_id, activate_type, iccid, combo_id):
|
|
|
|
+ logger = logging.getLogger('info')
|
|
|
|
+ logger.info('创建联通订单套餐信息,订单id{}'.format(order_id))
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ unicom_combo_qs = UnicomCombo.objects.filter(id=int(combo_id)).values()
|
|
|
|
+ if unicom_combo_qs.exists():
|
|
|
|
+ unicom_combo = unicom_combo_qs.first()
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ combo_order_data = {'iccid': iccid, 'status': 0, 'combo_id': int(combo_id),
|
|
|
|
+ 'updated_time': now_time,
|
|
|
|
+ 'created_time': now_time}
|
|
|
|
+ if order_id:
|
|
|
|
+ combo_order_data['order_id'] = order_id
|
|
|
|
+ # 有效期类型 1 等于自然月,0天数
|
|
|
|
+ if unicom_combo['expiration_type'] == 1:
|
|
|
|
+ # 激活类型 1=下月激活 否则等于当月激活
|
|
|
|
+ if activate_type == 1:
|
|
|
|
+ combo_order_data['next_month_activate'] = True
|
|
|
|
+ next_start_time, end_time = cls.get_next_month_data_time()
|
|
|
|
+ combo_order_data['activation_time'] = next_start_time
|
|
|
|
+ combo_order_data['expire_time'] = end_time
|
|
|
|
+ else:
|
|
|
|
+ start_time, month_end_time = cls.get_month_start_and_end_time()
|
|
|
|
+ combo_order_data['activation_time'] = start_time
|
|
|
|
+ combo_order_data['expire_time'] = month_end_time
|
|
|
|
+ combo_order_data['status'] = 1
|
|
|
|
+
|
|
|
|
+ elif unicom_combo['expiration_type'] == 0:
|
|
|
|
+ days = unicom_combo['expiration_days']
|
|
|
|
+ zero_today, end_time = cls.get_data_time(days)
|
|
|
|
+ combo_order_data['activation_time'] = zero_today
|
|
|
|
+ combo_order_data['expire_time'] = end_time
|
|
|
|
+ combo_order_data['status'] = 1
|
|
|
|
+ UnicomComboOrderInfo.objects.create(**combo_order_data)
|
|
|
|
+ logger.info('保存信息success')
|
|
|
|
+ return True
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(e)
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_next_month_data_time():
|
|
|
|
+ """
|
|
|
|
+ 获取下个月开始时间与结束时间戳
|
|
|
|
+ @return: next_start_time,end_time
|
|
|
|
+ """
|
|
|
|
+ next_month_start = LocalDateTimeUtil.get_next_month_start()
|
|
|
|
+ next_start_time, next_end_time = LocalDateTimeUtil.get_start_and_end_time(next_month_start, '%Y-%m-%d')
|
|
|
|
+ next_month_end = LocalDateTimeUtil.get_next_month_end()
|
|
|
|
+ start_time, end_time = LocalDateTimeUtil.get_start_and_end_time(next_month_end, '%Y-%m-%d')
|
|
|
|
+ return next_start_time, end_time
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_data_time(days):
|
|
|
|
+ """
|
|
|
|
+ 获取今天开始时间以及days后日期结束时间戳
|
|
|
|
+ @return: next_start_time,end_time
|
|
|
|
+ """
|
|
|
|
+ zero_today, last_today = LocalDateTimeUtil.get_today_date(True)
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ after_time = LocalDateTimeUtil.get_after_days_timestamp(now_time, days)
|
|
|
|
+ time_array = time.localtime(after_time)
|
|
|
|
+ start_time, end_time = LocalDateTimeUtil.get_start_and_end_time(time.strftime("%Y-%m-%d", time_array),
|
|
|
|
+ '%Y-%m-%d')
|
|
|
|
+ return zero_today, end_time
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_month_start_and_end_time():
|
|
|
|
+ """
|
|
|
|
+ 获取当天开始时间与当月结束时间戳
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ zero_today, last_today = LocalDateTimeUtil.get_today_date(True)
|
|
|
|
+ month_end = LocalDateTimeUtil.get_cur_month_end()
|
|
|
|
+ start_time, month_end_time = LocalDateTimeUtil.get_start_and_end_time(month_end, '%Y-%m-%d')
|
|
|
|
+ return zero_today, month_end_time
|