|
@@ -4,20 +4,15 @@
|
|
# @Email : Guanhailogn@asj6.wecom.work
|
|
# @Email : Guanhailogn@asj6.wecom.work
|
|
# @File : UnicomManageController.py
|
|
# @File : UnicomManageController.py
|
|
# @Software: PyCharm
|
|
# @Software: PyCharm
|
|
-import datetime
|
|
|
|
-import logging
|
|
|
|
-import time
|
|
|
|
|
|
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
-from django.db.models import Q
|
|
|
|
from django.views import View
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import UnicomComboOrderInfo, UnicomCombo, Order_Model, UnicomDeviceInfo
|
|
|
|
|
|
+from Model.models import UnicomComboOrderInfo, UnicomCombo, UnicomDeviceInfo, Pay_Type
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
-from Object.UnicomObject import UnicomObjeect
|
|
|
|
|
|
|
|
|
|
|
|
-class UnicomComboTaskView(View):
|
|
|
|
|
|
+class UnicomComboView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
def get(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
@@ -32,28 +27,209 @@ class UnicomComboTaskView(View):
|
|
def validation(self, request_dict, request, operation):
|
|
def validation(self, request_dict, request, operation):
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
print(request)
|
|
print(request)
|
|
- if operation == 'get/unicom/info':
|
|
|
|
|
|
+ # 编辑套餐信息
|
|
|
|
+ if operation == 'get/info':
|
|
return self.get_unicom_info(request_dict, response)
|
|
return self.get_unicom_info(request_dict, response)
|
|
|
|
+ # 获取套餐表
|
|
|
|
+ elif operation == 'get/pay':
|
|
|
|
+ return self.get_pay_type(request_dict, 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 == 'order/info':
|
|
|
|
+ return self.get_order_info(response, request_dict)
|
|
|
|
+ # 获取用户信息
|
|
|
|
+ elif operation == 'user/info':
|
|
|
|
+ return self.get_user_info(response, request_dict)
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def get_unicom_info(request_dict, response):
|
|
|
|
- combo_id = request_dict.get('comboID',None)
|
|
|
|
|
|
+ def get_user_info(response, request_dict):
|
|
|
|
+ pass
|
|
|
|
|
|
- combo_qs = UnicomCombo.objects.filter(id=combo_id).filter()
|
|
|
|
- if not combo_qs.exists():
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_order_info(response, request_dict):
|
|
|
|
+ serial_no = request_dict.get('serialNo', None)
|
|
|
|
+ if not all([serial_no]):
|
|
return response.json(444)
|
|
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)
|
|
try:
|
|
try:
|
|
combo_list = []
|
|
combo_list = []
|
|
- for combo_info in combo_qs:
|
|
|
|
- combo_qs.exists()
|
|
|
|
|
|
+ for combo_info in combo_info_qs:
|
|
combo_list.append(combo_info)
|
|
combo_list.append(combo_info)
|
|
- res = {'combo_list':combo_list}
|
|
|
|
|
|
+ return response.json(0, combo_list)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, e)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def edit_combo(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+ """
|
|
|
|
+ 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]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ UnicomCombo.objects.filter(id=combo_id).values()
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
|
|
- return (0,res)
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- return response.json(500,e)
|
|
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def add_combo(response, request_dict):
|
|
|
|
+ """
|
|
|
|
+ 新增卡套餐
|
|
|
|
+ """
|
|
|
|
+ combo_id = request_dict.get('ID', 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)
|
|
|
|
+ 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)
|
|
|
|
|
|
|
|
+ if not all([pageNo, pageSize]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ 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)
|
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def get_unicom_info(request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 获取套餐详细表
|
|
|
|
+ @param request_dict:
|
|
|
|
+ @param response:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
|
+ if not all([pageNo, pageSize]):
|
|
|
|
+ return response.json(444)
|
|
|
|
+ page = int(pageNo)
|
|
|
|
+ line = int(pageSize)
|
|
|
|
+ try:
|
|
|
|
+ combo_qs = UnicomCombo.objects.filter(is_del=False) \
|
|
|
|
+ .order_by('sort').values('id', 'combo_name',
|
|
|
|
+ 'flow_total',
|
|
|
|
+ 'expiration_days',
|
|
|
|
+ 'expiration_type', 'price',
|
|
|
|
+ 'remark')[(page - 1) * line:page * line]
|
|
|
|
+ if not combo_qs.exists():
|
|
|
|
+ return response.json(0, [])
|
|
|
|
+ total = combo_qs.count()
|
|
|
|
+ combo_list = []
|
|
|
|
+ for item in combo_qs:
|
|
|
|
+ # 获取支付方式列表
|
|
|
|
+ pay_type_qs = Pay_Type.objects.filter(unicomcombo=item['id']).values('id', 'payment')
|
|
|
|
+ combo_list.append({
|
|
|
|
+ 'id': item['id'],
|
|
|
|
+ 'comboName': item['combo_name'],
|
|
|
|
+ 'flowTotal': item['flow_total'],
|
|
|
|
+ 'expirationDays': item['expiration_days'],
|
|
|
|
+ 'expirationType': item['expiration_type'],
|
|
|
|
+ 'price': item['price'],
|
|
|
|
+ 'remark': item['remark'],
|
|
|
|
+ 'payTypes': list(pay_type_qs),
|
|
|
|
+ })
|
|
|
|
+ return response.json(0, {'list': combo_list, 'total': total})
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(177, repr(e))
|
|
|
|
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_pay_type(cls, request_dict, 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)
|
|
|
|
+ try:
|
|
|
|
+ pay_type_list = []
|
|
|
|
+ for pay_type in pay_type_qs:
|
|
|
|
+ pay_type_qs.exists()
|
|
|
|
+ pay_type_list.append(pay_type)
|
|
|
|
+ return response.json(0, pay_type_list)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, e)
|