Эх сурвалжийг харах

定制客户模块 后台管理

linhaohong 1 жил өмнө
parent
commit
539781229e

+ 66 - 2
AdminController/DeviceManagementController.py

@@ -6,8 +6,9 @@ import time
 
 import oss2
 import requests
+from django.core.paginator import Paginator
 from django.db import transaction
-from django.db.models import Q, F
+from django.db.models import Q, F, Sum
 from django.forms.models import model_to_dict
 from django.views.generic.base import View
 
@@ -17,7 +18,8 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_
 from Ansjer.config import SERVER_DOMAIN_TEST, SERVER_DOMAIN_CN, SERVER_DOMAIN_US, SERVER_DOMAIN_EUR
 from Model.models import Device_Info, UidSetModel, LogModel, UID_Bucket, Unused_Uid_Meal, StsCrdModel, \
     VodHlsModel, ExperienceContextModel, DeviceTypeModel, UidUserModel, ExperienceAiModel, AiService, \
-    AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, UIDCompanySerialModel, UidPushModel
+    AppBundle, App_Info, AppDeviceType, DeviceNameLanguage, UIDCompanySerialModel, UidPushModel, \
+    CustomCustomerOrderInfo, CustomCustomerDevice
 from Object.AWS.AmazonS3Util import AmazonS3Util
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -96,6 +98,8 @@ class DeviceManagement(View):
                 return self.get_app_name_list(response)
             elif operation == 'callAddAppDeviceType':  # 可选服添加app设备类型数据并上传图标
                 return self.call_add_app_device_type(request_dict, response, request)
+            elif operation == 'getCustomerDeviceList':  # 查询扫码添加设备列表
+                return self.get_customer_device_list(request_dict, response)
             else:
                 return response.json(444, 'operation')
 
@@ -1218,3 +1222,63 @@ class DeviceManagement(View):
         except Exception as e:
             LOGGER.error(f'查询设备信息异常: errLine: {e.__traceback__.tb_lineno}, errMsg: {repr(e)}')
             return response.json(5)
+
+    @staticmethod
+    def get_customer_device_list(request_dict, response):
+        """
+        查询扫码添加设备列表
+        :param request_dict:
+        :param response:
+        :return:
+        """
+        order_number = request_dict.get('orderNumber')
+        name = request_dict.get('name')
+        email = request_dict.get('email')
+        page = int(request_dict.get('pageNo', 1))
+        page_size = int(request_dict.get('pageSize', 10))
+
+        try:
+            # 构建查询条件
+            custom_customer_qs = CustomCustomerOrderInfo.objects.all()
+
+            if order_number:
+                custom_customer_qs = custom_customer_qs.filter(order_number__icontains=order_number)
+            if name:
+                custom_customer_qs = custom_customer_qs.filter(name__icontains=name)
+            if email:
+                custom_customer_qs = custom_customer_qs.filter(email__icontains=email)
+
+            # 获取所需的ID和数量
+            c_id_list = custom_customer_qs.values_list("id", flat=True)
+            total_quantity = custom_customer_qs.aggregate(total_quantity=Sum('quantity'))['total_quantity']
+
+            # 查询设备列表
+            customer_device_qs = CustomCustomerDevice.objects.filter(id__in=c_id_list).order_by('-created_time')
+
+            # 分页处理
+            paginator = Paginator(customer_device_qs, page_size)
+            customer_device_page = paginator.get_page(page)
+
+            # 构建设备列表
+            customer_device_list = []
+            for device in customer_device_page.object_list:
+                customer_device_list.append({
+                    'id': device.id,
+                    'serialNumber': device.serial_number,
+                    'uid': device.uid,
+                    'deviceType': device.type,
+                    'fullCode': device.full_code,
+                    'addTime': device.created_time,
+                })
+
+            # 构造返回数据
+            data = {
+                'total': paginator.count,
+                'orderDeviceQuantity': total_quantity or 0,  # 防止为None
+                'list': customer_device_list,  # 当前页的记录列表
+            }
+
+            return response.json(0, data)
+
+        except Exception as e:
+            return response.json(500, f'error_line:{e.__traceback__.tb_lineno}, error_msg:{repr(e)}')

+ 100 - 1
AdminController/UserManageController.py

@@ -3,6 +3,7 @@ import time
 import oss2
 import requests
 from django.contrib.auth.hashers import make_password, check_password  # 对密码加密模块
+from django.core.paginator import Paginator
 from django.db import transaction
 from django.db.models import Q
 from django.utils.decorators import method_decorator
@@ -15,7 +16,7 @@ from Ansjer.config import SERVER_DOMAIN, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECR
     AWS_SECRET_ACCESS_KEY, AWS_SES_ACCESS_REGION, DETECT_PUSH_DOMAINS
 from Controller.CheckUserData import DataValid, RandomStr
 from Model.models import Device_User, Role, UserExModel, CountryModel, MenuModel, FeedBackModel, StatResModel, \
-    SysMassModel, App_Info, SysMsgModel, DeviceSuperPassword, CustomizedPush, DeviceTypeModel
+    SysMassModel, App_Info, SysMsgModel, DeviceSuperPassword, CustomizedPush, DeviceTypeModel, CustomCustomerOrderInfo
 from Object.AWS.AmazonS3Util import AmazonS3Util
 from Object.ApschedulerObject import ApschedulerObject
 from Object.RedisObject import RedisObject
@@ -321,6 +322,12 @@ class UserManagement(View):
                 return self.addOrEditCustomizedPush(request, request_dict, response)
             elif operation == 'delCustomizedPush':  # 删除定制推送
                 return self.delCustomizedPush(request_dict, response)
+            if operation == 'getCustomCustomerList':  # 查詢定制客户信息
+                return self.get_custom_customer_list(request_dict, response)
+            elif operation == 'addCustomCustomer':  # 添加定制客户信息接口
+                return self.add_custom_customer(request_dict, response)
+            elif operation == 'delCustomCustomer':  # 查询定制客户设备列表
+                return self.del_custom_customer(request_dict, response)
             else:
                 return response.json(414)
 
@@ -1106,3 +1113,95 @@ class UserManagement(View):
             return response.json(0, {'list': device_type_list})
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
+    @staticmethod
+    def get_custom_customer_list(request_dict, response):
+        """
+        查询定制客户信息
+        :param request_dict:
+        :param response:
+        :return:
+        """
+        order_number = request_dict.get('orderNumber', None)
+        name = request_dict.get('name', None)
+        email = request_dict.get('email', None)
+        page = request_dict.get('pageNo', 1)
+        page_size = request_dict.get('pageSize', 10)
+        try:
+            # 初始化查询集
+            custom_customer_qs = CustomCustomerOrderInfo.objects.all()
+
+            if order_number:
+                custom_customer_qs = custom_customer_qs.filter(order_number__icontains=order_number)
+            if name:
+                custom_customer_qs = custom_customer_qs.filter(name__icontains=name)
+            if email:
+                custom_customer_qs = custom_customer_qs.filter(email__icontains=email)
+
+            paginator = Paginator(custom_customer_qs.order_by('id'), page_size)
+            customers = paginator.page(page)
+
+            customer_list = []
+            for customer in customers.object_list:
+                customer_list.append({
+                    'cId': customer.id,
+                    'orderNumber': customer.order_number,
+                    'name': customer.name,
+                    'email': customer.email,
+                    'countryId': customer.country_id,
+                    'quantity': customer.quantity,
+                    'createdTime': customer.created_time,
+                })
+
+            # 返回分页结果
+            data = {
+                'total': paginator.count,
+                'list': list(customer_list),  # 当前页的记录列表
+            }
+
+            return response.json(0, data)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
+    @staticmethod
+    def add_custom_customer(request_dict, response):
+        """
+        添加定制客户生产编号信息
+        :param request_dict: 请求字典
+        :param response: 响应对象
+        :return: 响应对象
+        """
+        order_number = request_dict.get('orderNumber', None)
+        name = request_dict.get('name', None)
+        quantity = int(request_dict.get('quantity', 0))
+        email = request_dict.get('email', None)
+        country_code = request_dict.get('countryCode', "en")
+
+        if not all([order_number, name, email, quantity]):
+            return response.json(444)
+
+        custom_customer_qs = CustomCustomerOrderInfo.objects.filter(order_number=order_number)
+        if custom_customer_qs.exists():
+            return response.json(174)
+
+        try:
+            country_code = country_code.upper()
+            country_qs = CountryModel.objects.filter(country_code=country_code)
+            country_id = 0
+            if country_qs.exists():
+                country_id = country_qs.first().id
+            CustomCustomerOrderInfo.objects.create(
+                order_number=order_number,
+                name=name,
+                email=email,
+                country_id=country_id,
+                quantity=quantity,
+                created_time=int(time.time()),
+            )
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+
+    @staticmethod
+    def del_custom_customer(request_dict, response):
+        pass

+ 0 - 37
Controller/CustomCustomer/CustomCustomerController.py

@@ -26,8 +26,6 @@ class CustomCustomerView(View):
         response = ResponseObject(language)
         if operation == 'getCustomCustomer':  # APP查詢定制客户信息
             return self.get_custom_customer(request_dict, response)
-        elif operation == 'addCustomCustomer':  # 添加定制客户信息接口
-            return self.add_custom_customer(request_dict, response)
         elif operation == 'addCustomerDevice':  # 定制客户设备扫码添加接口
             return self.add_customer_device(request_dict, response)
         elif operation == 'getCustomerDeviceCount':  # 查询定制客户已扫码添加设备数量接口
@@ -61,41 +59,6 @@ class CustomCustomerView(View):
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
-    @staticmethod
-    def add_custom_customer(request_dict, response):
-        """
-        添加定制客户信息
-        :param request_dict: 请求字典
-        :param response: 响应对象
-        :return: 响应对象
-        """
-        order_number = request_dict.get('orderNumber', None)
-        name = request_dict.get('name', None)
-        quantity = int(request_dict.get('quantity', 0))
-        email = request_dict.get('email', '')
-        country_id = request_dict.get('countryId', 0)
-
-        if not all([order_number, name, quantity]):
-            return response.json(444)
-
-        custom_customer_qs = CustomCustomerOrderInfo.objects.filter(order_number=order_number)
-        if custom_customer_qs.exists():
-            return response.json(174)
-
-        try:
-            CustomCustomerOrderInfo.objects.create(
-                order_number=order_number,
-                name=name,
-                email=email,
-                country_id=country_id,
-                quantity=quantity,
-                created_time=int(time.time()),
-                updated_time=int(time.time())
-            )
-            return response.json(0)
-        except Exception as e:
-            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-
     def add_customer_device(self, request_dict, response):
         """
         定制客户设备扫码添加接口