|
@@ -4,11 +4,12 @@
|
|
|
# @Email : Guanhailogn@asj6.wecom.work
|
|
|
# @File : UnicomManageController.py
|
|
|
# @Software: PyCharm
|
|
|
+import time
|
|
|
|
|
|
from django.db import transaction
|
|
|
-from django.views import View
|
|
|
+from django.views.generic.base import View
|
|
|
|
|
|
-from Model.models import UnicomComboOrderInfo, UnicomCombo, UnicomDeviceInfo, Pay_Type
|
|
|
+from Model.models import UnicomDeviceInfo, UnicomCombo, Pay_Type, UnicomComboOrderInfo, Device_User
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
|
|
|
|
|
@@ -27,119 +28,152 @@ class UnicomComboView(View):
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
response = ResponseObject()
|
|
|
print(request)
|
|
|
- # 编辑套餐信息
|
|
|
- if operation == 'get/info':
|
|
|
+ # 获取套餐详细表
|
|
|
+ if operation == 'get/deta/info':
|
|
|
return self.get_unicom_info(request_dict, response)
|
|
|
- # 获取套餐表
|
|
|
+ # 获取支付类型
|
|
|
elif operation == 'get/pay':
|
|
|
- return self.get_pay_type(request_dict, response)
|
|
|
- # 编辑卡套餐
|
|
|
+ return self.get_pay_type(response)
|
|
|
+ # 添加和编辑卡套餐
|
|
|
elif operation == 'edit/combo':
|
|
|
return self.edit_combo(request_dict, response)
|
|
|
- # 新增套餐
|
|
|
- elif operation == 'add/combo':
|
|
|
- return self.add_combo(response, request_dict)
|
|
|
+ # 获取卡用户信息
|
|
|
+ elif operation == 'get/user':
|
|
|
+ return self.get_user_combo(request_dict, response)
|
|
|
# 获取设备套餐信息
|
|
|
elif operation == 'order/info':
|
|
|
- return self.get_order_info(response, request_dict)
|
|
|
- # 获取用户信息
|
|
|
- elif operation == 'user/info':
|
|
|
- return self.get_user_info(response, request_dict)
|
|
|
+ return self.get_order_info(request_dict, response)
|
|
|
+ # 统计4G套餐
|
|
|
+ elif operation == 'getComboDataList':
|
|
|
+ return self.combo_order_list(request_dict, response)
|
|
|
+ # 删除卡套餐
|
|
|
+ elif operation == 'dele/combo/info':
|
|
|
+ return self.dele_combo_info(request_dict, response)
|
|
|
|
|
|
@staticmethod
|
|
|
- def get_user_info(response, request_dict):
|
|
|
- pass
|
|
|
-
|
|
|
- @staticmethod
|
|
|
- def get_order_info(response, request_dict):
|
|
|
- serial_no = request_dict.get('serialNo', None)
|
|
|
- if not all([serial_no]):
|
|
|
+ def get_user_combo(request_dict, response):
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
+ if not all([pageNo, [pageSize]]):
|
|
|
return response.json(444)
|
|
|
- get_info_qs = UnicomDeviceInfo.objects.filter(serial_no=serial_no).values('iccid')
|
|
|
- iccid = get_info_qs[0]['iccid']
|
|
|
- combo_info_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid).values()
|
|
|
- if not combo_info_qs.exists():
|
|
|
- return response.json(173)
|
|
|
+ page = int(pageNo)
|
|
|
+ line = int(pageSize)
|
|
|
+ get_info_qs = UnicomComboOrderInfo.objects.filter().values(
|
|
|
+ 'iccid', 'activation_time', 'expire_time', 'status',
|
|
|
+ 'combo__combo_name',
|
|
|
+ 'combo__pay_type__payment',
|
|
|
+ 'combo__price'
|
|
|
+ )[(page - 1) * line:page * line]
|
|
|
+ total = get_info_qs.count()
|
|
|
try:
|
|
|
- combo_list = []
|
|
|
- for combo_info in combo_info_qs:
|
|
|
- combo_list.append(combo_info)
|
|
|
- return response.json(0, combo_list)
|
|
|
+ res_list = []
|
|
|
+ for item in get_info_qs:
|
|
|
+ res = {
|
|
|
+ 'userID': '',
|
|
|
+ 'phone': '',
|
|
|
+ 'userEmail': '',
|
|
|
+ 'serialNo': '',
|
|
|
+ 'loginTime': '',
|
|
|
+ 'iccid': '',
|
|
|
+ 'openTime': '',
|
|
|
+ 'endTime': '',
|
|
|
+ 'status': '',
|
|
|
+ 'comboName': '',
|
|
|
+ 'payType': '',
|
|
|
+ 'price': ''
|
|
|
+
|
|
|
+ }
|
|
|
+ iccid = item['iccid']
|
|
|
+ res['iccid'] = iccid
|
|
|
+ res['openTime'] = item['activation_time']
|
|
|
+ res['endTime'] = item['expire_time']
|
|
|
+ res['status'] = item['status']
|
|
|
+ res['comboName'] = item['combo__combo_name']
|
|
|
+ res['payType'] = item['combo__pay_type__payment']
|
|
|
+ res['price'] = item['combo__price']
|
|
|
+ serial_no_qs = UnicomDeviceInfo.objects.filter(iccid=iccid).values('serial_no')
|
|
|
+ # serial_no = serial_no_qs[0]['serial_no']
|
|
|
+ res['serialNo'] = serial_no_qs.first()['serial_no']
|
|
|
+ user_id_qs = UnicomDeviceInfo.objects.filter(iccid=iccid).values('user_id')
|
|
|
+ user_id = user_id_qs[0]['user_id']
|
|
|
+ if user_id_qs.exists():
|
|
|
+ user_info_qs = Device_User.objects.filter(userID=user_id).values(
|
|
|
+ 'userEmail', 'data_joined',
|
|
|
+ 'phone')
|
|
|
+ res['userID'] = user_id
|
|
|
+ res['loginTime'] = user_info_qs.first()['data_joined'].strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ res['userEmail'] = user_info_qs.first()['userEmail']
|
|
|
+ res['phone'] = user_info_qs.first()['phone']
|
|
|
+ res_list.append(res)
|
|
|
+ return response.json(0, {'list': res_list, 'total': total})
|
|
|
except Exception as e:
|
|
|
- return response.json(500, e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
- @classmethod
|
|
|
- def edit_combo(cls, request_dict, response):
|
|
|
+ @staticmethod
|
|
|
+ def get_order_info(request_dict, response):
|
|
|
"""
|
|
|
-
|
|
|
+ 获取卡套餐信息
|
|
|
+ @param request_dict:
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
"""
|
|
|
- combo_id = request_dict.get('comboID', None)
|
|
|
- package_id = request_dict.get('packageId', None)
|
|
|
- combo_name = request_dict.get('comboName', None)
|
|
|
- status = request_dict.get('status', None)
|
|
|
- combo_type = request_dict.get('comboType', None)
|
|
|
- flow_total = request_dict.get('flowTotal', None)
|
|
|
- expiration_days = request_dict.get('expirationDays', None)
|
|
|
- expiration_type = request_dict.get('expirationType', None)
|
|
|
- pay_type = request_dict.get('payType', None)
|
|
|
- price = request_dict.get('price', None)
|
|
|
- remark = request_dict.get('remark', None)
|
|
|
- updated_time = request_dict.get('updatedTime', None)
|
|
|
- created_time = request_dict.get('createdTime', None)
|
|
|
- is_show = request_dict.get('show', None)
|
|
|
-
|
|
|
- if not all([combo_id]):
|
|
|
+ serial_no = request_dict.get('serialNo', None)
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
+ if not all([pageSize, pageNo]):
|
|
|
return response.json(444)
|
|
|
- UnicomCombo.objects.filter(id=combo_id).values()
|
|
|
+ # else:
|
|
|
+ page = int(pageNo)
|
|
|
+ line = int(pageSize)
|
|
|
+
|
|
|
+ # 参考云端获取设备套餐信息(代码逻辑)
|
|
|
+ # 参考云端多情况(条件)下的查询,返回结果
|
|
|
|
|
|
try:
|
|
|
- with transaction.atomic():
|
|
|
- re_data = {
|
|
|
- 'package_id': package_id,
|
|
|
- 'combo_name': combo_name,
|
|
|
- 'status': status,
|
|
|
- 'combo_type': combo_type,
|
|
|
- 'flow_total': flow_total,
|
|
|
- 'expiration_days': expiration_days,
|
|
|
- 'expiration_type': expiration_type,
|
|
|
- 'price': price,
|
|
|
- 'remark': remark,
|
|
|
- 'updated_time': updated_time,
|
|
|
- 'created_time': created_time,
|
|
|
- 'is_show': is_show
|
|
|
- }
|
|
|
- UnicomCombo.objects.filter(id=combo_id).update(**re_data)
|
|
|
- UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
|
|
|
- # UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
|
|
|
- return response.json(0)
|
|
|
+ get_info_qs = UnicomDeviceInfo.objects.filter().values('iccid')
|
|
|
+ iccid = get_info_qs[0]['iccid']
|
|
|
+ if serial_no:
|
|
|
+ get_info_qs = get_info_qs.filter(serial_no__contains=serial_no).values('iccid')
|
|
|
+ iccid = get_info_qs[0]['iccid']
|
|
|
+
|
|
|
+ if not get_info_qs.exists():
|
|
|
+ return response.json(0, [])
|
|
|
+ combo_info_qs = UnicomComboOrderInfo.objects.filter(iccid=iccid).values()
|
|
|
|
|
|
+ combo_info_qs = combo_info_qs.values()
|
|
|
+ combo_info_qs = combo_info_qs.order_by('-created_time')
|
|
|
+ combo_info_qs = combo_info_qs[(page - 1) * line:page * line]
|
|
|
+ total = combo_info_qs.count()
|
|
|
+ return response.json(0, {'list': list(combo_info_qs), 'total': total})
|
|
|
except Exception as e:
|
|
|
+ print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
- @staticmethod
|
|
|
- def add_combo(response, request_dict):
|
|
|
+ @classmethod
|
|
|
+ def edit_combo(cls, request_dict, response):
|
|
|
"""
|
|
|
- 新增卡套餐
|
|
|
+ 添加和编辑卡套餐
|
|
|
"""
|
|
|
- combo_id = request_dict.get('ID', None)
|
|
|
+ combo_id = request_dict.get('comboID', None)
|
|
|
package_id = request_dict.get('packageId', None)
|
|
|
combo_name = request_dict.get('comboName', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
combo_type = request_dict.get('comboType', None)
|
|
|
flow_total = request_dict.get('flowTotal', None)
|
|
|
expiration_days = request_dict.get('expirationDays', None)
|
|
|
- expiration_type = request_dict.get('expirationDays', None)
|
|
|
+ expiration_type = request_dict.get('expirationType', None)
|
|
|
pay_type = request_dict.get('payType', None)
|
|
|
price = request_dict.get('price', None)
|
|
|
remark = request_dict.get('remark', None)
|
|
|
updated_time = request_dict.get('updatedTime', None)
|
|
|
created_time = request_dict.get('createdTime', None)
|
|
|
is_show = request_dict.get('show', None)
|
|
|
- pageNo = request_dict.get('pageNO', None)
|
|
|
- pageSize = request_dict.get('pageSize', None)
|
|
|
+ add = request_dict.get('add', None)
|
|
|
|
|
|
- if not all([pageNo, pageSize]):
|
|
|
+ if not all([add]):
|
|
|
return response.json(444)
|
|
|
+ UnicomCombo.objects.filter(id=combo_id).values()
|
|
|
+
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
re_data = {
|
|
@@ -156,9 +190,13 @@ class UnicomComboView(View):
|
|
|
'created_time': created_time,
|
|
|
'is_show': is_show
|
|
|
}
|
|
|
- UnicomCombo.objects.filter(id=combo_id).update(**re_data)
|
|
|
- UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
|
|
|
- UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
|
|
|
+ if add == 1:
|
|
|
+ UnicomCombo.objects.filter(id=combo_id).update(**re_data)
|
|
|
+ UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
|
|
|
+ else:
|
|
|
+ UnicomCombo.objects.filter(id=combo_id).update(**re_data)
|
|
|
+ UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
|
|
|
+ UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
|
|
|
return response.json(0)
|
|
|
|
|
|
except Exception as e:
|
|
@@ -207,21 +245,12 @@ class UnicomComboView(View):
|
|
|
return response.json(177, repr(e))
|
|
|
|
|
|
@classmethod
|
|
|
- def get_pay_type(cls, request_dict, response):
|
|
|
+ def get_pay_type(cls, response):
|
|
|
"""
|
|
|
- 获取套餐表
|
|
|
- @param request_dict:
|
|
|
+ 获取支付类型
|
|
|
@param response:
|
|
|
@return:
|
|
|
"""
|
|
|
- combo_id = request_dict.get('comboID', None)
|
|
|
-
|
|
|
- if not all([combo_id]):
|
|
|
- return response.json(444)
|
|
|
-
|
|
|
- combo_id_qs = UnicomCombo.objects.filter(id=combo_id).values('pay_type')
|
|
|
- if combo_id_qs.exists():
|
|
|
- pass
|
|
|
pay_type_qs = Pay_Type.objects.all().values('id', 'payment')
|
|
|
if not pay_type_qs.exists():
|
|
|
return response.json(444)
|
|
@@ -233,3 +262,62 @@ class UnicomComboView(View):
|
|
|
return response.json(0, pay_type_list)
|
|
|
except Exception as e:
|
|
|
return response.json(500, e)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def dele_combo_info(cls, request_doct, response):
|
|
|
+ pass
|
|
|
+
|
|
|
+ def combo_order_list(self, request_dict, response):
|
|
|
+ year = request_dict.get('year', None)
|
|
|
+ Jan = int(time.mktime(time.strptime(year + '-1-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Feb = int(time.mktime(time.strptime(year + '-2-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Mar = int(time.mktime(time.strptime(year + '-3-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Apr = int(time.mktime(time.strptime(year + '-4-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ May = int(time.mktime(time.strptime(year + '-5-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Jun = int(time.mktime(time.strptime(year + '-6-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Jul = int(time.mktime(time.strptime(year + '-7-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Aug = int(time.mktime(time.strptime(year + '-8-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Sep = int(time.mktime(time.strptime(year + '-9-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Oct = int(time.mktime(time.strptime(year + '-10-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Nov = int(time.mktime(time.strptime(year + '-11-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Dec = int(time.mktime(time.strptime(year + '-12-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+ Jan_next = int(time.mktime(time.strptime(str(int(year) + 1) + '-1-1 00:00:00', "%Y-%m-%d %H:%M:%S")))
|
|
|
+
|
|
|
+ list_data = []
|
|
|
+ unicom_combo_qs = UnicomCombo.objects.filter().values('id', 'combo_type', 'combo_name')
|
|
|
+
|
|
|
+ if not unicom_combo_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ try:
|
|
|
+ for unicom_combo in unicom_combo_qs:
|
|
|
+ name = unicom_combo['combo_name']
|
|
|
+ combo_order = UnicomComboOrderInfo.objects.filter(combo_id=unicom_combo['id'])
|
|
|
+ if not combo_order.exists():
|
|
|
+ continue
|
|
|
+ Jan_count = combo_order.filter(created_time__range=[Jan, Feb]).count()
|
|
|
+ Feb_count = combo_order.filter(created_time__range=[Feb, Mar]).count()
|
|
|
+ Mar_count = combo_order.filter(created_time__range=[Mar, Apr]).count()
|
|
|
+ Apr_count = combo_order.filter(created_time__range=[Apr, May]).count()
|
|
|
+ May_count = combo_order.filter(created_time__range=[May, Jun]).count()
|
|
|
+ Jun_count = combo_order.filter(created_time__range=[Jun, Jul]).count()
|
|
|
+ Jul_count = combo_order.filter(created_time__range=[Jul, Aug]).count()
|
|
|
+ Aug_count = combo_order.filter(created_time__range=[Aug, Sep]).count()
|
|
|
+ Sep_count = combo_order.filter(created_time__range=[Sep, Oct]).count()
|
|
|
+ Oct_count = combo_order.filter(created_time__range=[Oct, Nov]).count()
|
|
|
+ Nov_count = combo_order.filter(created_time__range=[Nov, Dec]).count()
|
|
|
+ Dec_count = combo_order.filter(created_time__range=[Dec, Jan_next]).count()
|
|
|
+ data = [Jan_count, Feb_count, Mar_count, Apr_count, May_count, Jun_count, Jul_count, Aug_count,
|
|
|
+ Sep_count,
|
|
|
+ Oct_count, Nov_count, Dec_count]
|
|
|
+
|
|
|
+ cloud_data = {
|
|
|
+ 'name': name,
|
|
|
+ 'type': 'line',
|
|
|
+ 'data': data,
|
|
|
+ }
|
|
|
+ list_data.append(cloud_data)
|
|
|
+
|
|
|
+ return response.json(0, {'list': list_data})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|