|
@@ -37,8 +37,9 @@ class UnicomComboView(View):
|
|
|
return self.validation(request.POST, request, operation)
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
- if operation == 'buy-notify':
|
|
|
- return self.package_callback_notify(request_dict, request)
|
|
|
+ response = ResponseObject('cn')
|
|
|
+ if operation == 'query-usage-history':
|
|
|
+ return self.query_device_usage_history(request_dict, response)
|
|
|
elif operation == 'test-notify':
|
|
|
order_id = request_dict.get('orderId', None)
|
|
|
activate_type = request_dict.get('activateType', 0)
|
|
@@ -51,10 +52,8 @@ class UnicomComboView(View):
|
|
|
elif operation == 'device-status-change':
|
|
|
return self.device_status_change_push(request_dict, request)
|
|
|
elif operation == 'device-bind':
|
|
|
- response = ResponseObject('cn')
|
|
|
return self.device_add(request_dict, response)
|
|
|
elif operation == 'device-status':
|
|
|
- response = ResponseObject('cn')
|
|
|
return self.update_device_status(request_dict, response)
|
|
|
else:
|
|
|
token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
@@ -127,7 +126,7 @@ class UnicomComboView(View):
|
|
|
return response.json(173)
|
|
|
params = {'iccid': iccid, 'serial_no': serial_no, 'updated_time': n_time,
|
|
|
'created_time': n_time}
|
|
|
- cls.is_activate(iccid)
|
|
|
+ unicom_obj.change_device_to_activate(iccid)
|
|
|
UnicomDeviceInfo.objects.create(**params)
|
|
|
return response.json(0)
|
|
|
else:
|
|
@@ -156,13 +155,7 @@ class UnicomComboView(View):
|
|
|
return False
|
|
|
# 联通业务逻辑
|
|
|
unicom_api = UnicomObjeect()
|
|
|
- re_data = {'iccid': iccid}
|
|
|
- result = unicom_api.query_device_status(**re_data)
|
|
|
- res_dict = unicom_api.get_text_dict(result)
|
|
|
- # 状态不等于1(激活)时进行激活 1:激活;2:停用
|
|
|
- if res_dict['data']['status'] != 1:
|
|
|
- re_data = {"iccid": iccid, "status": 1}
|
|
|
- unicom_api.update_device_state(**re_data)
|
|
|
+ unicom_api.change_device_to_activate(iccid)
|
|
|
# 查看是否体验过免费套餐
|
|
|
experience_history_qs = UnicomComboExperienceHistory.objects.filter(iccid=iccid)
|
|
|
if not experience_history_qs.exists():
|
|
@@ -344,11 +337,22 @@ class UnicomComboView(View):
|
|
|
return rank_id, ai_rank_id
|
|
|
|
|
|
@classmethod
|
|
|
- def query_device_usage_history(cls):
|
|
|
+ def query_device_usage_history(cls, request_dict, response):
|
|
|
"""
|
|
|
查询用量历史
|
|
|
@return:
|
|
|
"""
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ year = today.year
|
|
|
+ month = today.month
|
|
|
+ year = request_dict.get('year', year)
|
|
|
+ month = request_dict.get('month', month)
|
|
|
+ iccid = request_dict.get('month', None)
|
|
|
+ if not iccid:
|
|
|
+ return response.json(444)
|
|
|
+ unicom_api = UnicomObjeect()
|
|
|
+ flow = unicom_api.get_flow_usage_total(int(year), int(month), iccid)
|
|
|
+ return response.json(0, flow)
|
|
|
|
|
|
@staticmethod
|
|
|
def package_callback_notify(request_dict, request):
|
|
@@ -487,13 +491,7 @@ class UnicomComboView(View):
|
|
|
# 联通业务逻辑
|
|
|
unicom_api = UnicomObjeect()
|
|
|
if status == 1:
|
|
|
- re_data = {'iccid': iccid}
|
|
|
- result = unicom_api.query_device_status(**re_data)
|
|
|
- res_dict = unicom_api.get_text_dict(result)
|
|
|
- # 状态不等于1(激活)时进行激活 1:激活;2:停用
|
|
|
- if res_dict and res_dict['data']['status'] != 1:
|
|
|
- re_data = {"iccid": iccid, "status": 1}
|
|
|
- unicom_api.update_device_state(**re_data)
|
|
|
+ unicom_api.change_device_to_activate(iccid)
|
|
|
flow_total_usage = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
combo_order_data['flow_total_usage'] = str(flow_total_usage)
|
|
|
UnicomComboOrderInfo.objects.create(**combo_order_data)
|
|
@@ -540,25 +538,6 @@ class UnicomComboView(View):
|
|
|
start_time, month_end_time = LocalDateTimeUtil.get_start_and_end_time(month_end, '%Y-%m-%d')
|
|
|
return zero_today, month_end_time
|
|
|
|
|
|
- @staticmethod
|
|
|
- def is_activate(iccid):
|
|
|
- """
|
|
|
- 根据iccid判断是否激活,未激活则修改为激活状态
|
|
|
- @param iccid:
|
|
|
- @return:
|
|
|
- """
|
|
|
- if iccid:
|
|
|
- unicom_api = UnicomObjeect()
|
|
|
- re_data = {'iccid': iccid}
|
|
|
- result = unicom_api.query_device_status(**re_data)
|
|
|
- res_dict = unicom_api.get_text_dict(result)
|
|
|
- # 状态不等于1(激活)时进行激活 1:激活;2:停用
|
|
|
- if res_dict['data']['status'] != 1:
|
|
|
- re_data = {"iccid": iccid, "status": 1}
|
|
|
- unicom_api.update_device_state(**re_data)
|
|
|
- return True
|
|
|
- return None
|
|
|
-
|
|
|
@classmethod
|
|
|
def get_test_sign(cls, request_dict, response):
|
|
|
"""
|