linhaohong 1 жил өмнө
parent
commit
077d2306c2

+ 15 - 38
AdminController/CloudServiceManage/AgentCustomerController.py

@@ -80,10 +80,8 @@ class AgentCustomerView(View):
                 return self.get_customer_list(request_dict, response)
             elif operation == 'getCustomerPackageList':
                 return self.get_cumstomer_package_list(request_dict, response)
-            elif operation == 'batchAddCustomerPackage':
-                return self.batch_add_customer_package(userID, request_dict, response)
-            elif operation == 'batchDeleteCustomerPackage':
-                return self.batch_del_cumstomer_package(request_dict, response)
+            elif operation == 'batchRebindCustomerPackage':
+                return self.batch_rebind_customer_packages(userID, request_dict, response)
             elif operation == 'getAgentServicePackageList':
                 return self.get_agent_service_package_list(response)
             else:
@@ -175,7 +173,7 @@ class AgentCustomerView(View):
         page_size = int(request_dict.get('page_size', 10))
         try:
             # 查询所有有效的代理云服务套餐
-            all_packages = AgentCloudServicePackage.objects.filter(status=1).order_by('-created_time')
+            all_packages = AgentCloudServicePackage.objects.filter(status=1).order_by('type', '-created_time')
             # 创建分页对象
             paginator = Paginator(all_packages, page_size)
             # 获取请求页的数据
@@ -184,7 +182,7 @@ class AgentCustomerView(View):
             packages_list = list(packages_page.object_list.values(
                 'id', 'service_name', 'package_id', 'type',
                 'profit_type', 'cost', 'profit', 'status',
-                'created_time', 'updated_time'
+                'created_time'
             ))
             # 返回分页数据
             return response.json(0, {
@@ -378,27 +376,26 @@ class AgentCustomerView(View):
             print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    def batch_add_customer_package(self, userID, request_dict, response):
+    def batch_rebind_customer_packages(self, userID, request_dict, response):
         """
-        代理商批量绑定服务套餐
+        清空并重新绑定代理商服务套餐
         @param userID: 操作用户的ID
-        @param request_dict: 请求参数,包含代理商ID和服务套餐ID列表
+        @param request_dict: 请求参数,包含代理商ID和新的服务套餐ID列表
         @param response: 响应对象
         @return:
         """
         ac_id = request_dict.get('ac_id', None)  # 代理客户ID
-        cs_ids = json.loads(request_dict.get('cs_ids', '[]'))  # 服务套餐ID列表
+        new_cs_ids = json.loads(request_dict.get('cs_ids', '[]'))  # 新的服务套餐ID列表
 
-        # 校验输入
         if not ac_id:
             return response.json(444, 'Missing agent customer ID.')
+        if not new_cs_ids:
+            return response.json(444, 'Service package IDs are required.')
+
         try:
-            # 查询该代理客户已经绑定的服务套餐ID
-            existing_cs_ids = AgentCustomerPackage.objects.filter(ac_id=ac_id).values_list('cs_id', flat=True)
-            # 确定尚未绑定的服务套餐ID
-            new_cs_ids = [cs_id for cs_id in cs_ids if cs_id not in existing_cs_ids]
-            if not new_cs_ids:
-                return response.json(444)
+            # 删除该代理客户的所有现有绑定
+            AgentCustomerPackage.objects.filter(ac_id=ac_id).delete()
+
             # 过滤出存在且状态为有效的套餐ID
             valid_new_cs_ids = AgentCloudServicePackage.objects.filter(id__in=new_cs_ids, status=1).values_list('id',
                                                                                                                 flat=True)
@@ -415,7 +412,7 @@ class AgentCustomerView(View):
                 for cs_id in valid_new_cs_ids
             ]
 
-            # 批量创建绑定关系
+            # 批量创建新的绑定关系
             AgentCustomerPackage.objects.bulk_create(packages_to_bind)
 
             return response.json(0)
@@ -423,26 +420,6 @@ class AgentCustomerView(View):
             print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    def batch_del_cumstomer_package(self, request_dict, response):
-        """
-        代理商解绑服务套餐
-        @param request_dict: 请求参数
-        @param request_dict ac_id: 代理客户id
-        @param request_dict cs_ids: 代理套餐id表
-        @param response: 响应对象
-        @return:
-        """
-        ac_id = request_dict.get('ac_id', None)
-        cs_ids = json.loads(request_dict.get('cs_id', '[]'))
-        if ac_id is None or not cs_ids:
-            return response.json(444)
-        try:
-            AgentCustomerPackage.objects.filter(ac_id=ac_id, cs_id__in=cs_ids).delete()
-            return response.json(0)
-        except Exception as e:
-            print(e)
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-
     def get_agent_service_package_list(self, response):
         """
         查询云服务套餐列表 id + service_name