|
@@ -51,7 +51,6 @@ class AgentCustomerView(View):
|
|
|
if operation == 'getUnicomAndIcloud':
|
|
|
return self.get_unicom_and_icloud(response)
|
|
|
else:
|
|
|
- return response.json(444, 'operation')
|
|
|
tko = TokenObject(
|
|
|
request.META.get('HTTP_AUTHORIZATION'),
|
|
|
returntpye='pc')
|
|
@@ -61,6 +60,8 @@ class AgentCustomerView(View):
|
|
|
userID = tko.userID
|
|
|
if operation == 'getAgentServicePackage':
|
|
|
return self.get_agent_service_package(request_dict, response)
|
|
|
+ elif operation == 'addAgentServicePackage':
|
|
|
+ return self.add_agent_service_package(request_dict, response)
|
|
|
else:
|
|
|
return response.json(444, 'operation')
|
|
|
|
|
@@ -127,3 +128,48 @@ class AgentCustomerView(View):
|
|
|
# 出错时返回错误信息
|
|
|
return response.json({'error': str(e)}, status=500)
|
|
|
|
|
|
+ def add_agent_service_package(self, request_dict, response):
|
|
|
+ """
|
|
|
+ 添加代理云服务套餐
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @request_dict service_name: 代理服务名称
|
|
|
+ @request_dict package_type: 套餐类型 1:云存,2:4G
|
|
|
+ @response_dict profit_type: 利润分配类型 1:固定值,2:百分比
|
|
|
+ @response_dict cost: 成本
|
|
|
+ @response_dict profit: 利润值
|
|
|
+ @param userID: userID
|
|
|
+ @param response: 响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ service_name = request_dict.get('service_name')
|
|
|
+ package_type = int(request_dict.get('package_type', 0)) # 默认为0,确保类型安全
|
|
|
+ profit_type = int(request_dict.get('profit_type', 1)) # 默认值为1
|
|
|
+ profit = request_dict.get('profit', 0)
|
|
|
+
|
|
|
+ try:
|
|
|
+ # 1:云存, 2:4G
|
|
|
+ print(package_type)
|
|
|
+ if package_type == 1:
|
|
|
+ # 从Store_Meal查询
|
|
|
+ package = Store_Meal.objects.filter(bucket__bucket=service_name, is_show=1).first()
|
|
|
+ elif package_type == 2:
|
|
|
+ # 从UnicomCombo查询
|
|
|
+ package = UnicomCombo.objects.filter(combo_name=service_name, is_show=1, is_del=False).first()
|
|
|
+ else:
|
|
|
+ return response.json(444)
|
|
|
+ if not package:
|
|
|
+ return response.json(173)
|
|
|
+ # 创建AgentCloudServicePackage实例并保存
|
|
|
+ agent_service_package = AgentCloudServicePackage(
|
|
|
+ service_name=service_name,
|
|
|
+ package_id=package.id if package else None,
|
|
|
+ type=package_type,
|
|
|
+ profit_type=profit_type,
|
|
|
+ cost=package.price,
|
|
|
+ profit=profit,
|
|
|
+ status=1
|
|
|
+ )
|
|
|
+ agent_service_package.save()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json({'error': str(e)}, status=500)
|