|
@@ -78,7 +78,7 @@ class UnicomComboView(View):
|
|
|
@classmethod
|
|
|
def user_combo_query(cls, user_id, request_dict, response):
|
|
|
"""
|
|
|
- 查询套餐流量列表或者正在使用流量详情
|
|
|
+ 查询套餐流量列表与正在使用流量详情
|
|
|
@param user_id:
|
|
|
@param request_dict:
|
|
|
@param response:
|
|
@@ -98,70 +98,78 @@ class UnicomComboView(View):
|
|
|
today = datetime.datetime.today()
|
|
|
year = today.year
|
|
|
month = today.month
|
|
|
- if q_type == 'combo':
|
|
|
+ combo_order_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid, status=1, is_del=False) \
|
|
|
+ .values('iccid', 'status', 'combo__status', 'combo__combo_name', 'combo__combo_type',
|
|
|
+ 'combo__flow_total', 'combo__remark', 'combo__expiration_days', 'combo__expiration_type',
|
|
|
+ 'year', 'month', 'flow_total_usage', 'expire_time', 'activation_time')
|
|
|
+ if combo_order_qs.exists():
|
|
|
+ combo_order = combo_order_qs.first()
|
|
|
+ flow_details = {
|
|
|
+ 'iccid': iccid,
|
|
|
+ 'status': combo_order['status'],
|
|
|
+ 'comboName': combo_order['combo__combo_name'],
|
|
|
+ 'comboType': combo_order['combo__combo_type'],
|
|
|
+ 'flowTotal': combo_order['combo__flow_total'],
|
|
|
+ 'comboRemark': combo_order['combo__remark'],
|
|
|
+ 'expirationDays': combo_order['combo__expiration_days'],
|
|
|
+ 'expirationType': combo_order['combo__expiration_type'],
|
|
|
+ 'flowTotalUsage': combo_order['flow_total_usage'],
|
|
|
+ 'activationTime': combo_order['activation_time'],
|
|
|
+ 'expireTime': combo_order['expire_time'],
|
|
|
+ 'year': combo_order['year'],
|
|
|
+ 'month': combo_order['month'],
|
|
|
+ }
|
|
|
+ if flow_details['year'] == year and flow_details['month'] == month:
|
|
|
+ month_flow = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
+ # 当月流量减去 套餐激活时用量
|
|
|
+ month_flow = month_flow - float(flow_details['flowTotalUsage'])
|
|
|
+ flow = flow_details['flowTotal'] - month_flow
|
|
|
+ flow_details['usableFlow'] = flow
|
|
|
+ else:
|
|
|
+ now_month_flow = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
+ last_month_flow = unicom_api.get_flow_usage_total(flow_details['year'], flow_details['month'],
|
|
|
+ iccid)
|
|
|
+ flow = now_month_flow + last_month_flow - float(flow_details['flowTotalUsage'])
|
|
|
+ flow_details['usableFlow'] = flow_details['flowTotal'] - flow
|
|
|
+
|
|
|
+ flow_details['usableFlow'] = \
|
|
|
+ flow_details['flowTotal'] if flow_details['usableFlow'] <= 0 else flow_details['usableFlow']
|
|
|
+ flow_details['usableFlow'] = Decimal(flow_details['usableFlow']).quantize(Decimal('0.00'))
|
|
|
+ flow_details.pop('flowTotalUsage')
|
|
|
cls.update_combo_order_sort(iccid)
|
|
|
- combo_list = []
|
|
|
- combo_order_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid, is_del=False) \
|
|
|
- .values('iccid', 'status', 'combo__combo_name', 'combo__flow_total',
|
|
|
- 'combo__remark', 'combo__expiration_days', 'combo__expiration_type', 'flow_total_usage',
|
|
|
- 'expire_time').order_by('sort', 'created_time')
|
|
|
- for item in combo_order_qs:
|
|
|
- combo_list.append({
|
|
|
- 'iccid': iccid,
|
|
|
- 'comboName': item['combo__combo_name'],
|
|
|
- 'flowTotal': item['combo__flow_total'],
|
|
|
- 'comboRemark': item['combo__remark'],
|
|
|
- 'expirationDays': item['combo__expiration_days'],
|
|
|
- 'expirationType': item['combo__expiration_type'],
|
|
|
- 'expireTime': item['expire_time'],
|
|
|
- })
|
|
|
- return response.json(0, combo_list)
|
|
|
-
|
|
|
- elif q_type == 'usage':
|
|
|
- combo_order_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid, status=1, is_del=False) \
|
|
|
- .values('iccid', 'status', 'combo__status', 'combo__combo_name', 'combo__combo_type',
|
|
|
- 'combo__flow_total', 'combo__remark', 'combo__expiration_days', 'combo__expiration_type',
|
|
|
- 'year', 'month', 'flow_total_usage', 'expire_time')
|
|
|
- if combo_order_qs.exists():
|
|
|
- combo_order = combo_order_qs.first()
|
|
|
- flow_details = {
|
|
|
- 'iccid': iccid,
|
|
|
- 'comboName': combo_order['combo__combo_name'],
|
|
|
- 'comboType': combo_order['combo__combo_type'],
|
|
|
- 'flowTotal': combo_order['combo__flow_total'],
|
|
|
- 'comboRemark': combo_order['combo__remark'],
|
|
|
- 'expirationDays': combo_order['combo__expiration_days'],
|
|
|
- 'expirationType': combo_order['combo__expiration_type'],
|
|
|
- 'year': combo_order['year'],
|
|
|
- 'month': combo_order['month'],
|
|
|
- 'flowTotalUsage': combo_order['flow_total_usage'],
|
|
|
- 'expireTime': combo_order['expire_time'],
|
|
|
- }
|
|
|
- if flow_details['year'] == year and flow_details['month'] == month:
|
|
|
- month_flow = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
- # 当月流量减去 套餐激活时用量
|
|
|
- month_flow = month_flow - float(flow_details['flowTotalUsage'])
|
|
|
- flow = flow_details['flowTotal'] - month_flow
|
|
|
- flow_details['usableFlow'] = flow
|
|
|
- else:
|
|
|
- now_month_flow = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
- last_month_flow = unicom_api.get_flow_usage_total(flow_details['year'], flow_details['month'],
|
|
|
- iccid)
|
|
|
- flow = now_month_flow + last_month_flow - float(flow_details['flowTotalUsage'])
|
|
|
- flow_details['usableFlow'] = flow_details['flowTotal'] - flow
|
|
|
-
|
|
|
- flow_details['usableFlow'] = \
|
|
|
- flow_details['flowTotal'] if flow_details['usableFlow'] <= 0 else flow_details['usableFlow']
|
|
|
- flow_details['usableFlow'] = Decimal(flow_details['usableFlow']).quantize(Decimal('0.00'))
|
|
|
- flow_details.pop('flowTotalUsage')
|
|
|
- return response.json(0, flow_details)
|
|
|
- return response.json(0)
|
|
|
+ flow_details['comboList'] = cls.get_combo_order_list(iccid)
|
|
|
+ return response.json(0, flow_details)
|
|
|
except Exception as e:
|
|
|
print(e.args)
|
|
|
ex = traceback.format_exc()
|
|
|
print(ex)
|
|
|
return response.json(177, ex)
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def get_combo_order_list(cls, iccid):
|
|
|
+ """
|
|
|
+ 查询套餐列表
|
|
|
+ @param iccid:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ combo_list = []
|
|
|
+ combo_order_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid, is_del=False) \
|
|
|
+ .values('iccid', 'status', 'combo__combo_name', 'combo__flow_total',
|
|
|
+ 'combo__remark', 'combo__expiration_days', 'combo__expiration_type', 'flow_total_usage',
|
|
|
+ 'expire_time').order_by('sort', 'created_time')
|
|
|
+ for item in combo_order_qs:
|
|
|
+ combo_list.append({
|
|
|
+ 'iccid': iccid,
|
|
|
+ 'status': item['status'],
|
|
|
+ 'comboName': item['combo__combo_name'],
|
|
|
+ 'flowTotal': item['combo__flow_total'],
|
|
|
+ 'comboRemark': item['combo__remark'],
|
|
|
+ 'expirationDays': item['combo__expiration_days'],
|
|
|
+ 'expirationType': item['combo__expiration_type'],
|
|
|
+ 'expireTime': item['expire_time'],
|
|
|
+ })
|
|
|
+ return combo_list
|
|
|
+
|
|
|
@classmethod
|
|
|
def update_combo_order_sort(cls, iccd):
|
|
|
"""
|