|
@@ -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
|
|
@@ -14,7 +15,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
|
|
@@ -315,6 +316,10 @@ 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)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -1070,3 +1075,98 @@ 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)
|
|
|
+
|
|
|
+ # 批量查询所有相关的国家信息
|
|
|
+ country_ids = custom_customer_qs.values_list('country_id', flat=True).distinct()
|
|
|
+ country_qs = CountryModel.objects.filter(id__in=country_ids)
|
|
|
+ country_map = {country.id: country.country_name for country in country_qs}
|
|
|
+
|
|
|
+ customer_list = []
|
|
|
+ for customer in customers.object_list:
|
|
|
+ country_name = country_map.get(customer.country_id, '')
|
|
|
+ customer_list.append({
|
|
|
+ 'cId': customer.id,
|
|
|
+ 'orderNumber': customer.order_number,
|
|
|
+ 'name': customer.name,
|
|
|
+ 'email': customer.email,
|
|
|
+ 'countryName': country_name,
|
|
|
+ '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()),
|
|
|
+ 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)))
|