|
@@ -4,10 +4,12 @@
|
|
# @Email : Guanhailogn@asj6.wecom.work
|
|
# @Email : Guanhailogn@asj6.wecom.work
|
|
# @File : UnicomManageController.py
|
|
# @File : UnicomManageController.py
|
|
# @Software: PyCharm
|
|
# @Software: PyCharm
|
|
|
|
+import datetime
|
|
import hashlib
|
|
import hashlib
|
|
import json
|
|
import json
|
|
import time
|
|
import time
|
|
import uuid
|
|
import uuid
|
|
|
|
+from decimal import Decimal
|
|
|
|
|
|
import openpyxl
|
|
import openpyxl
|
|
import requests
|
|
import requests
|
|
@@ -85,6 +87,8 @@ class UnicomManageControllerView(View):
|
|
return self.create_package_cdk(request_dict, response)
|
|
return self.create_package_cdk(request_dict, response)
|
|
elif operation == 'resetCardPackage':
|
|
elif operation == 'resetCardPackage':
|
|
return self.reset_card_package(request, request_dict, response)
|
|
return self.reset_card_package(request, request_dict, response)
|
|
|
|
+ elif operation == 'getPackageDetails':
|
|
|
|
+ return self.get_package_details(request_dict, response)
|
|
else:
|
|
else:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
|
|
|
|
@@ -307,16 +311,7 @@ class UnicomManageControllerView(View):
|
|
col_names = [desc[0] for desc in cursor.description]
|
|
col_names = [desc[0] for desc in cursor.description]
|
|
for item in data_obj:
|
|
for item in data_obj:
|
|
order_dict = dict(zip(col_names, item))
|
|
order_dict = dict(zip(col_names, item))
|
|
- if order_dict['status'] == 1:
|
|
|
|
- total_flow = UnicomObjeect.current_sim_traffic_usage_details(order_dict['iccid']) # 4G总值
|
|
|
|
- total_flow = int(total_flow)
|
|
|
|
- flow_total_usage = order_dict['flow_total_usage'] # 激活时当月已用流量
|
|
|
|
- if flow_total_usage == '': # 判断数值是否为空
|
|
|
|
- flow_total_usage = 0
|
|
|
|
- flow_total_usage = float(flow_total_usage)
|
|
|
|
- order_dict['using_total'] = total_flow - flow_total_usage
|
|
|
|
- else:
|
|
|
|
- order_dict['using_total'] = 0
|
|
|
|
|
|
+ order_dict['using_total'] = 0
|
|
result_list.append(order_dict)
|
|
result_list.append(order_dict)
|
|
return response.json(0, {'orderList': result_list, 'total': total})
|
|
return response.json(0, {'orderList': result_list, 'total': total})
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -744,3 +739,91 @@ class UnicomManageControllerView(View):
|
|
# 取哈希值的前8位,并将其转换为大写字母
|
|
# 取哈希值的前8位,并将其转换为大写字母
|
|
code = sha1.hexdigest()[:8].upper()
|
|
code = sha1.hexdigest()[:8].upper()
|
|
return code
|
|
return code
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_package_details(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 根据序列号获取套餐包列表
|
|
|
|
+ """
|
|
|
|
+ serial_number = request_dict.get('serialNumber', None)
|
|
|
|
+ if not serial_number:
|
|
|
|
+ return response.json(444)
|
|
|
|
+ ud_qs = UnicomDeviceInfo.objects.filter(serial_no=serial_number) \
|
|
|
|
+ .values('iccid', 'card_type')
|
|
|
|
+ package_list = []
|
|
|
|
+ if not ud_qs.exists():
|
|
|
|
+ return response.json(0, {'packageList': package_list})
|
|
|
|
+ iccid = ud_qs[0]['iccid']
|
|
|
|
+ card_type = ud_qs[0]['card_type']
|
|
|
|
+ if card_type == 0:
|
|
|
|
+ o_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid) \
|
|
|
|
+ .values('status', 'flow_total_usage', 'flow_exceed', 'activation_time', 'expire_time',
|
|
|
|
+ 'combo__combo_name', 'combo__flow_total', 'updated_time') \
|
|
|
|
+ .order_by('created_time')
|
|
|
|
+ if not o_qs:
|
|
|
|
+ return response.json(0, {'packageList': package_list})
|
|
|
|
+ return response.json(0, {'package_list': cls.get_unicom_package_list(iccid, o_qs)})
|
|
|
|
+ if card_type == 1:
|
|
|
|
+ data = {'iccid': iccid, 'operator': 3}
|
|
|
|
+ return response.json(0, {'package_list': cls.get_wx_package_list(**data)})
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_unicom_package_list(iccid, o_qs):
|
|
|
|
+ package_list = []
|
|
|
|
+ unicom_api = UnicomObjeect()
|
|
|
|
+ for i, item in enumerate(o_qs):
|
|
|
|
+ package_status = item['status']
|
|
|
|
+ flow_total = item['combo__flow_total']
|
|
|
|
+ flow_total_usage = float(unicom_api.get_flow_usage_total(iccid))
|
|
|
|
+ activate_flow = float(item['flow_total_usage']) if item['flow_total_usage'] else 0
|
|
|
|
+ used = 0
|
|
|
|
+ if package_status == 1:
|
|
|
|
+ used = flow_total_usage - activate_flow # 已用流量
|
|
|
|
+ elif package_status == 2:
|
|
|
|
+ index = i + 1
|
|
|
|
+ if index < len(o_qs) and o_qs[index]['flow_total_usage']:
|
|
|
|
+ package_used_flow = float(o_qs[i + 1]['flow_total_usage'])
|
|
|
|
+ used = package_used_flow - activate_flow
|
|
|
|
+ else:
|
|
|
|
+ used = flow_total_usage - activate_flow
|
|
|
|
+ status_dict = {0: "待使用", 1: "使用中", 2: "已失效"}
|
|
|
|
+ status = status_dict.get(item['status'])
|
|
|
|
+ package_list.append({
|
|
|
|
+ 'status': status,
|
|
|
|
+ 'flowTotal': flow_total,
|
|
|
|
+ 'used': Decimal(used).quantize(Decimal('0.00')),
|
|
|
|
+ 'activationTime': datetime.datetime.fromtimestamp(item['activation_time']).strftime(
|
|
|
|
+ '%Y-%m-%d %H:%M:%S'),
|
|
|
|
+ 'expireTime': datetime.datetime.fromtimestamp(item['expire_time']).strftime('%Y-%m-%d %H:%M:%S'),
|
|
|
|
+ 'updatedTime': datetime.datetime.fromtimestamp(item['updated_time']).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
+ })
|
|
|
|
+ return package_list
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_wx_package_list(**data):
|
|
|
|
+ """
|
|
|
|
+ 获取五兴套餐订购记录
|
|
|
|
+ @param data: iccid,operator
|
|
|
|
+ @return: 订购记录结果
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ package_list = []
|
|
|
|
+ wx_tech = WXTechObject()
|
|
|
|
+ result = wx_tech.get_package_order_record(**data)
|
|
|
|
+ if not result:
|
|
|
|
+ return package_list
|
|
|
|
+ status_dict = {0: "待使用", 1: "使用中", 2: "已完成", 3: "已退订", 4: "已失效", 5: "已删除"}
|
|
|
|
+ for item in result['data']:
|
|
|
|
+ used_flow = float(item['flowTotal']) - float(item['flowRemain'])
|
|
|
|
+ package_list.append({
|
|
|
|
+ 'status': status_dict.get(int(item['state'])),
|
|
|
|
+ 'flowTotal': item['flowTotal'],
|
|
|
|
+ 'used': Decimal(used_flow).quantize(Decimal('0.00')),
|
|
|
|
+ 'activationTime': item['startDate'],
|
|
|
|
+ 'expireTime': item['endDate'],
|
|
|
|
+ 'updatedTime': ''
|
|
|
|
+ })
|
|
|
|
+ return package_list
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(repr(e))
|
|
|
|
+ return []
|