|
@@ -14,6 +14,7 @@ from Model.models import UnicomDeviceInfo, UnicomCombo, Pay_Type, UnicomComboOrd
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
from Service.CommonService import CommonService
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
|
|
|
|
|
|
class UnicomManageControllerView(View):
|
|
@@ -30,35 +31,45 @@ class UnicomManageControllerView(View):
|
|
|
|
|
|
def validation(self, request_dict, request, operation):
|
|
|
response = ResponseObject()
|
|
|
- print(request)
|
|
|
- # 获取套餐详细表
|
|
|
- if operation == 'get/deta/info':
|
|
|
- return self.get_unicom_info(request_dict, response)
|
|
|
# 获取支付类型
|
|
|
- elif operation == 'get/pay':
|
|
|
+ if operation == 'get/pay':
|
|
|
return self.get_pay_type(response)
|
|
|
- # 添加和编辑卡套餐
|
|
|
- elif operation == 'edit/combo':
|
|
|
- return self.edit_combo(request_dict, response)
|
|
|
- # 统计4G套餐
|
|
|
- elif operation == 'getComboDataList':
|
|
|
- return self.static_info(request_dict, response)
|
|
|
- # 删除卡套餐
|
|
|
- elif operation == 'dele/combo/info':
|
|
|
- return self.combo_order_info(request_dict, response)
|
|
|
- # 获取/筛选用户信息
|
|
|
- elif operation == 'filter/user':
|
|
|
- return self.get_user_info(request_dict, response)
|
|
|
- # 充值流量
|
|
|
- elif operation == 'getFlowPackages':
|
|
|
- return self.get_flow_packages(request_dict, response)
|
|
|
- # 获取 / 筛选4G流量卡订单信息
|
|
|
- elif operation == 'query-order':
|
|
|
- return self.query_4G_user_order(request_dict, response)
|
|
|
- elif operation == 'sim-info':
|
|
|
- return self.get_iccid_info(request_dict, response)
|
|
|
+ # 获取套餐类型
|
|
|
+ elif operation == 'combo/type':
|
|
|
+ return self.get_unicom_combo_type(response)
|
|
|
else:
|
|
|
- return response.json(0)
|
|
|
+ tko = TokenObject(
|
|
|
+ request.META.get('HTTP_AUTHORIZATION'),
|
|
|
+ returntpye='pc')
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ response.lang = tko.lang
|
|
|
+ userID = tko.userID
|
|
|
+ # 获取套餐详细表
|
|
|
+ if operation == 'get/deta/info':
|
|
|
+ return self.get_unicom_info(request_dict, response)
|
|
|
+ # 添加和编辑卡套餐
|
|
|
+ elif operation == 'edit/combo':
|
|
|
+ return self.edit_combo(request_dict, response)
|
|
|
+ # 统计4G套餐
|
|
|
+ elif operation == 'getComboDataList':
|
|
|
+ return self.static_info(request_dict, response)
|
|
|
+ # 删除卡套餐
|
|
|
+ elif operation == 'dele/combo/info':
|
|
|
+ return self.combo_order_info(request_dict, response)
|
|
|
+ # 获取/筛选用户信息
|
|
|
+ elif operation == 'filter/user':
|
|
|
+ return self.get_user_info(request_dict, response)
|
|
|
+ # 充值流量
|
|
|
+ elif operation == 'getFlowPackages':
|
|
|
+ return self.get_flow_packages(request_dict, response)
|
|
|
+ # 获取/筛选4G流量卡订单信息
|
|
|
+ elif operation == 'query-order':
|
|
|
+ return self.query_4G_user_order(request_dict, response)
|
|
|
+ elif operation == 'sim-info':
|
|
|
+ return self.get_iccid_info(request_dict, response)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
|
|
|
def get_user_info(self, request_dict, response):
|
|
|
"""
|
|
@@ -79,7 +90,6 @@ class UnicomManageControllerView(View):
|
|
|
|
|
|
if not all({pageNo, pageSize}):
|
|
|
return response.json(444)
|
|
|
-
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
|
|
@@ -248,21 +258,11 @@ class UnicomManageControllerView(View):
|
|
|
combo_type = int(combo_type)
|
|
|
is_show = int(is_show)
|
|
|
sort = int(sort)
|
|
|
+ nowTime = int(time.time())
|
|
|
|
|
|
- if combo_type == 1:
|
|
|
- combo_type_qs = UnicomCombo.objects.filter(combo_type=1, is_del=False)
|
|
|
- if combo_type_qs.exists():
|
|
|
- if combo_id:
|
|
|
- combo_id = int(combo_id)
|
|
|
- combo_id_qs = combo_type_qs.first().id
|
|
|
- if combo_id != combo_id_qs:
|
|
|
- return response.json(174)
|
|
|
- else:
|
|
|
- return response.json(174)
|
|
|
- unicom_combo_qs = UnicomCombo.objects.all()
|
|
|
-
|
|
|
- try:
|
|
|
- with transaction.atomic():
|
|
|
+ # 判断是编辑还是添加
|
|
|
+ with transaction.atomic():
|
|
|
+ try:
|
|
|
re_data = {
|
|
|
'combo_name': combo_name,
|
|
|
'status': status,
|
|
@@ -276,19 +276,20 @@ class UnicomManageControllerView(View):
|
|
|
'is_show': is_show,
|
|
|
'virtual_price': virtualPrice,
|
|
|
}
|
|
|
- if unicom_combo_qs.filter(id=combo_id).exists():
|
|
|
- re_data['updated_time'] = int(time.time())
|
|
|
- UnicomCombo.objects.filter(id=combo_id).update(**re_data)
|
|
|
- UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
|
|
|
+ if combo_id:
|
|
|
+ combo_type_qs = UnicomCombo.objects.filter(id=combo_id)
|
|
|
+ if not combo_type_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ re_data['updated_time'] = nowTime
|
|
|
+ combo_type_qs.filter(id=combo_id).update(**re_data)
|
|
|
+ combo_type_qs.get(id=combo_id).pay_type.set(pay_type)
|
|
|
else:
|
|
|
re_data['updated_time'] = int(time.time())
|
|
|
re_data['created_time'] = int(time.time())
|
|
|
UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
|
|
|
return response.json(0)
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- return response.json(500)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@staticmethod
|
|
|
def get_unicom_info(request_dict, response):
|
|
@@ -302,20 +303,22 @@ class UnicomManageControllerView(View):
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
if not all([pageNo, pageSize]):
|
|
|
return response.json(444)
|
|
|
+ elif pageNo and pageSize:
|
|
|
+ pass
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
try:
|
|
|
combo_qs = UnicomCombo.objects.filter(is_del=False) \
|
|
|
- .order_by('sort').values('id', 'status', 'combo_name',
|
|
|
- 'flow_total', 'combo_type',
|
|
|
- 'expiration_days',
|
|
|
- 'expiration_type', 'price', 'is_unlimited',
|
|
|
- 'updated_time', 'created_time',
|
|
|
- 'remark', 'is_show', 'sort', 'virtual_price')[
|
|
|
- (page - 1) * line:page * line]
|
|
|
+ .values('id', 'status', 'combo_name',
|
|
|
+ 'flow_total', 'combo_type',
|
|
|
+ 'expiration_days',
|
|
|
+ 'expiration_type', 'price', 'is_unlimited',
|
|
|
+ 'updated_time', 'created_time',
|
|
|
+ 'remark', 'is_show', 'sort', 'virtual_price').order_by('sort')
|
|
|
if not combo_qs.exists():
|
|
|
return response.json(0, [])
|
|
|
total = combo_qs.count()
|
|
|
+ combo_qs = combo_qs[(page - 1) * line:page * line]
|
|
|
combo_list = []
|
|
|
for item in combo_qs:
|
|
|
# 获取支付方式列表
|
|
@@ -341,7 +344,8 @@ class UnicomManageControllerView(View):
|
|
|
})
|
|
|
return response.json(0, {'list': combo_list, 'total': total})
|
|
|
except Exception as e:
|
|
|
- return response.json(177, repr(e))
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
@classmethod
|
|
|
def get_pay_type(cls, response):
|
|
@@ -352,14 +356,26 @@ class UnicomManageControllerView(View):
|
|
|
"""
|
|
|
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_list.append(pay_type)
|
|
|
- return response.json(0, pay_type_list)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, e)
|
|
|
+ return response.json(0, [])
|
|
|
+ pay_type_list = []
|
|
|
+ for pay_type in pay_type_qs:
|
|
|
+ pay_type_list.append(pay_type)
|
|
|
+ return response.json(0, pay_type_list)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_unicom_combo_type(cls, response):
|
|
|
+ """
|
|
|
+ 获取赠送套餐
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ unicom_combo_qs = UnicomCombo.objects.filter(combo_type=2, status=0).values('id', 'combo_name')
|
|
|
+ if not unicom_combo_qs.exists():
|
|
|
+ return response.json(0, [])
|
|
|
+ combo_list = []
|
|
|
+ for combo in unicom_combo_qs:
|
|
|
+ combo_list.append(combo)
|
|
|
+ return response.json(0, combo_list)
|
|
|
|
|
|
@classmethod
|
|
|
def combo_order_info(cls, request_dict, response):
|
|
@@ -373,14 +389,11 @@ class UnicomManageControllerView(View):
|
|
|
|
|
|
if not combo_id:
|
|
|
return response.json(444)
|
|
|
- try:
|
|
|
- combo_qs = UnicomCombo.objects.filter(id=combo_id)
|
|
|
- if combo_qs.exists():
|
|
|
- combo_qs.update(is_del=True)
|
|
|
- return response.json(0)
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return response.json(500, repr(e))
|
|
|
+ combo_qs = UnicomCombo.objects.filter(id=combo_id)
|
|
|
+ # 只修改默认状态
|
|
|
+ if combo_qs.exists():
|
|
|
+ combo_qs.update(is_del=True)
|
|
|
+ return response.json(0)
|
|
|
|
|
|
def static_info(self, request_dict, response):
|
|
|
"""
|
|
@@ -451,7 +464,7 @@ class UnicomManageControllerView(View):
|
|
|
@comboType request_dict:套餐类型
|
|
|
@serialNo request_dict:序列号
|
|
|
@param response: 响应对象
|
|
|
- @param return:
|
|
|
+ @return:
|
|
|
"""
|
|
|
userId = request_dict.get('userId', None)
|
|
|
serialNo = request_dict.get('serialNo', None)
|
|
@@ -460,36 +473,43 @@ class UnicomManageControllerView(View):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
while transaction.atomic():
|
|
|
- combo_info_qs = UnicomCombo.objects.filter(id=comboId, combo_type=2, status=0, is_del=False) \
|
|
|
- .values('id', 'combo_name', 'price', 'virtual_price', 'remark', 'combo_type').order_by('sort')
|
|
|
- if not combo_info_qs.exists():
|
|
|
- return response.json(173)
|
|
|
+ combo_info_qs = UnicomCombo.objects.filter(id=comboId, combo_type=2, status=0) \
|
|
|
+ .values('id', 'combo_name', 'price', 'virtual_price', 'remark', 'combo_type')
|
|
|
unicom_device_info_qs = UnicomDeviceInfo.objects.filter(serial_no=serialNo,
|
|
|
user_id=userId).values \
|
|
|
- ('user_id', 'iccid', 'serial_no')
|
|
|
- if not unicom_device_info_qs.exists():
|
|
|
+ ('iccid')
|
|
|
+ if not unicom_device_info_qs.exists() or not combo_info_qs.exists():
|
|
|
return response.json(173)
|
|
|
+ combo_info_qs = combo_info_qs.first()
|
|
|
+ unicom_device_info_qs = unicom_device_info_qs.first()
|
|
|
n_time = int(time.time())
|
|
|
- icc_id = unicom_device_info_qs[0]['iccid']
|
|
|
- serial_no = unicom_device_info_qs[0]['serial_no']
|
|
|
- order_id = CommonService.createOrderID()
|
|
|
- unicom_combo = UnicomComboView.create_combo_order_info(order_id=order_id, activate_type=1, iccid=icc_id,
|
|
|
+ order_id = CommonService.createOrderID() # 生成订单号
|
|
|
+ # 赠送套餐下个月生效
|
|
|
+ unicom_combo = UnicomComboView.create_combo_order_info(order_id=order_id, activate_type=1,
|
|
|
+ iccid=unicom_device_info_qs['iccid'],
|
|
|
combo_id=comboId)
|
|
|
if unicom_combo is False:
|
|
|
return response.json(178)
|
|
|
- # 获取套餐信息
|
|
|
- combo_info_vo = combo_info_qs[0]
|
|
|
- c_time = n_time
|
|
|
- # 根据序列号获取UID
|
|
|
- uid = CommonService.query_uid_with_serial(serial_no)
|
|
|
rank_id, ai_rank_id = UnicomComboView.get_cloud_or_ai_combo() # 生成订单必须添加该字段
|
|
|
- order_dict = {'orderID': order_id, 'UID': uid, 'rank_id': rank_id, 'ai_rank_id': ai_rank_id,
|
|
|
- 'userID_id': userId, 'desc': combo_info_vo['combo_name'], 'payType': 10,
|
|
|
- 'payTime': c_time, 'price': combo_info_vo['price'], 'addTime': c_time,
|
|
|
- 'updTime': c_time, 'status': 1,
|
|
|
- 'unify_combo_id': str(combo_info_vo['id']), 'order_type': 2,
|
|
|
- 'store_meal_name': combo_info_vo['combo_name']
|
|
|
- }
|
|
|
+ uid = CommonService.query_uid_with_serial(serialNo) # 获取序列号或UID
|
|
|
+ # 获取套餐信息
|
|
|
+ order_dict = {
|
|
|
+ 'orderID': order_id,
|
|
|
+ 'UID': uid,
|
|
|
+ 'rank_id': rank_id,
|
|
|
+ 'ai_rank_id': ai_rank_id,
|
|
|
+ 'userID_id': userId,
|
|
|
+ 'desc': combo_info_qs['combo_name'],
|
|
|
+ 'payType': 10,
|
|
|
+ 'payTime': n_time,
|
|
|
+ 'price': combo_info_qs['price'],
|
|
|
+ 'addTime': n_time,
|
|
|
+ 'updTime': n_time,
|
|
|
+ 'status': 1,
|
|
|
+ 'unify_combo_id': str(combo_info_qs['id']),
|
|
|
+ 'order_type': 2,
|
|
|
+ 'store_meal_name': combo_info_qs['combo_name']
|
|
|
+ }
|
|
|
Order_Model.objects.create(**order_dict)
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|