def post(self, request): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) account = serializer.validated_data.get('account') password = serializer.validated_data.get('password') try: user = UsersInfo.objects.get(account=account) except Exception as e: return CusResponse.get_response(message='用户名或密码错误', code=settings.FALSE_CODE) if user.status == 0: return CusResponse.get_response(message='该账号已被冻结,请联系管理员!') elif user and user.check_password(password): payload = jwt_payload_handler(user=user) jwt_token = jwt_encode_handler(payload=payload) _menu_list = user.roles.all().values_list('menu_list', flat=True) menu_list = [] [menu_list.extend(i) for i in _menu_list] menu_list = list(set(menu_list)) data = dict() data['token'] = jwt_token data['id'] = user.id data['username'] = user.username data['permissions'] = menu_list # 增加权限缓存逻辑 redis_conn = get_redis_connection('default') redis_conn.setex(user.id, settings.IMG_CODE_EXPIRE, json.dumps({i: True for i in menu_list})) return CusResponse.get_response(data=data) else: return CusResponse.get_response(message='用户名或密码错误')
def update(self, request, *args, **kwargs): owner_code = self.request.data.get('owner_code') channel_code = self.request.data.get('channel_code') instance = CusChaPri.objects.filter( Q(owner_code=owner_code) & Q(channel_code=channel_code)) if len(instance) < 1: if not self.request.data.get('unit_price'): return CusResponse.get_response(success=False, message='该渠道价格不能为空', code=settings.FALSE_CODE) serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return CusResponse.get_response(serializer.data) else: if not self.request.data.get('unit_price'): instance.delete() return CusResponse.get_response(success=True) else: serializer = self.get_serializer(instance[0], data=request.data) serializer.is_valid(raise_exception=True) self.perform_update(serializer) if getattr(instance, '_prefetched_objects_cache', None): instance._prefetched_objects_cache = {} return CusResponse.get_response(serializer.data)
def create(self, request, *args, **kwargs): if not self.request.data.get('code'): return CusResponse.get_response(success=False, message='缺少类型代码', code=settings.FALSE_CODE) if not self.request.data.get('name'): return CusResponse.get_response(success=False, message='缺少类型名称', code=settings.FALSE_CODE) return super().create(request, *args, **kwargs)
def create(self, request, *args, **kwargs): if not self.request.data.get('order') or not self.request.data.get( 'freight'): return CusResponse.get_response(success=False, message='缺少订单或运单', code=settings.FALSE_CODE) if not self.request.data.get('process_zh'): return CusResponse.get_response(success=False, message='缺少物流信息描述', code=settings.FALSE_CODE) return super().create(request, *args, **kwargs)
def create(self, request, *args, **kwargs): if not self.request.data.get('username'): return CusResponse.get_response(success=False, message='缺少用戶名', code=settings.FALSE_CODE) if not self.request.data.get('account'): return CusResponse.get_response(success=False, message='缺少用戶账号', code=settings.FALSE_CODE) if not self.request.data.get('password'): return CusResponse.get_response(success=False, message='缺少密码', code=settings.FALSE_CODE) if not self.request.data.get('bran'): return CusResponse.get_response(success=False, message='缺少分部id', code=settings.FALSE_CODE) if not self.request.data.get('roles'): return CusResponse.get_response(success=False, message='缺少角色id', code=settings.FALSE_CODE) return super().create(request, *args, **kwargs)
def get(self, request, *args, **kwargs): pk = self.request.query_params.get('pk') if pk and pk.isdigit(): pk = int(pk) name = self.request.query_params.get('name') try: pk_, name_ = self.queryset.values_list('pk', 'name').get(name=name) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该分部名称已存在!')
def get(self, request, *args, **kwargs): code = self.request.query_params.get('code') name = self.request.query_params.get('name') customer = self.request.query_params.get('customer') pk = self.request.query_params.get('pk') if pk and pk.isdigit(): pk = int(pk) if customer and customer.isdigit(): customer = int(customer) else: return CusResponse.get_response(success=False, message='缺客户id错误') if code and not name: try: pk_, code_ = self.queryset.values_list( 'pk', 'code').filter(customer=customer).get(code=code) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该字典值代码已存在!') elif name and not code: try: pk_, name_ = self.queryset.values_list( 'pk', 'name').filter(customer=customer).get(name=name) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该字典值名称已存在!') else: return CusResponse.get_response(success=False, message='参数有误')
def get(self, request, *args, **kwargs): pk = self.request.query_params.get('pk') if pk and pk.isdigit(): pk = int(pk) account = self.request.query_params.get('account') try: pk_, account_ = self.queryset.values_list('pk', 'account').get( account=account) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该用户账号已存在!')
def get(self, request, *args, **kwargs): """校验国家是否重复""" data1 = [{ 'county': county.values('id', 'code', 'name'), 'cities': county.cities.values('id', 'code', 'name').all() } for county in Countries.objects.prefetch_related('cities').all()] return CusResponse.get_response(data1)
def get(self, request): return CusResponse.get_response( data={ 'customers': CustomersInfo.objects.values('id', 'code', 'name').all(), 'counties': Countries.objects.values('id', 'code', 'name').all(), })
def get(self, request, *args, **kwargs): """校验字典类型是否重复""" pk = self.request.query_params.get('pk') if pk and pk.isdigit(): pk = int(pk) code = self.request.query_params.get('code') name = self.request.query_params.get('name') if code and not name: try: pk_, code_ = self.queryset.values_list('pk', 'code').get(code=code) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该类型代码已存在!') elif name and not code: try: pk_, county_name_ = self.queryset.values_list( 'pk', 'name').get(name=name) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该类型名称已存在!') else: return CusResponse.get_response(success=False, message='参数有误')
def get(self, request, *args, **kwargs): pk = kwargs.get('pk') request_user = request.user if isinstance(request_user, AnonymousUser): request_user = None modifier = request_user _kwargs = { 'password': make_password('e10adc3949ba59abbe56e057f20f883e'), 'modifier': modifier } UsersInfo.objects.filter(pk=pk).update(**_kwargs) return CusResponse.get_response(success=True, message='重置密码成功')
def get(self, request): rank_type_id = DataDictType.objects.get(code=settings.CUS_RANK).id return CusResponse.get_response( data={ 'ranks': DataDictsValue.objects.values('id', 'code', 'name').filter( status=1, type=rank_type_id), 'salesman': UsersInfo.objects.values('id', 'account', 'username').filter( ~Q(id=1) & Q(status=1)), 'services': UsersInfo.objects.values('id', 'account', 'username').filter( ~Q(id=1) & Q(status=1)), })
def post(self, request, *args, **kwargs): request_user = self.request.user if isinstance(request_user, AnonymousUser): request_user = None modifier = request_user pk = kwargs.get('pk') old_password = self.request.data.get('old_password') new_password = self.request.data.get('new_password') ensure_password = self.request.data.get('ensure_password') _kwargs = { 'password': make_password(new_password), 'modifier': modifier } instance = UsersInfo.objects.get(pk=pk) if not all([old_password, new_password, ensure_password]): return CusResponse.get_response(success=False, message='缺少毕传参数!') elif new_password != ensure_password: return CusResponse.get_response(success=False, message='确认密码与新密码不一致!') elif instance.check_password(old_password): UsersInfo.objects.filter(pk=pk).update(**_kwargs) return CusResponse.get_response(message='修改密码成功!') else: return CusResponse.get_response(success=False, message='原密码不正确')
def get(self, request, *args, **kwargs): return CusResponse.get_response(data={ 'channels': RawSQL(sql=""" select a.id, b.code, b.name from s_price a inner join s_values b on a.channel_code = b.code inner join s_types c on b.type_id = c.id where c.code = %s and b.status = 1 and a.insurance_rate is null and a.unit_price is not null """, params=[settings.TRANS_COMP]).dict_fetchall(), 'pay_types': DataDictsValue.objects.values('id', 'code', 'name').filter( type=DataDictType.objects.get(code=settings.PAY_TYPES).id, status=1), 'tran_site': CountySer(Countries.objects.all(), many=True).data })
def get(self, request, *args, **kwargs): channel_code = self.request.query_params.get('channel_code') freight = self.request.query_params.get('freight') channel = DataDictsValue.objects.get(code=channel_code) return CusResponse.get_response(data={ 'trans_company': RawSQL(sql=""" select a.id, b.code, b.name from s_price a left join s_values b on a.owner_code = b.code left join s_types c on b.type_id = c.id where c.code = %s and b.status = 1 and a.channel_code = %s """, params=[settings.TRANS_COMP, channel]).dict_fetchall(), 'select_orders': self.queryset.filter(channel=channel, freight__isnull=True) \ if not freight \ else self.queryset.filter(Q(channel=channel) & (Q(freight__isnull=True) & Q(freight=freight))) })
def create(self, request, *args, **kwargs): # 创建日志记录器 logger = logging.getLogger('django') data = [] for i in range(len(request.data.getlist('file_name'))): datum = { 'name': self.request.data.getlist('file_name')[i], 'format': self.request.data.getlist('file_content_type')[i], 'file_path': self.request.data.getlist('file_path')[i] + '.' + self.request.data.getlist('file_content_type')[i].split('/')[-1], 'md5_value': self.request.data.getlist('file_md5')[i], 'size': self.request.data.getlist('file_size')[i], } data.append(datum) os.rename(self.request.data.getlist('file_path')[i], self.request.data.getlist('file_path')[i] + '.' + self.request.data.getlist('file_content_type')[i].split('/')[-1]) serializer = self.get_serializer(data=data, many=True) serializer.is_valid(raise_exception=True) serializer.save() return CusResponse.get_response(data=serializer.data, message='文件上传成功!')
def get(self, request, *args, **kwargs): customer_code = self.request.query_params.get('customer_code') return CusResponse.get_response( data={ 'channels': CusChaPri.objects.values('id', 'channel_code', 'channel_name'). filter(owner_code=customer_code), 'pay_types': DataDictsValue.objects.values('id', 'code', 'name').filter( type__name=settings.PAY_TYPES, status=1), 'good_types': DataDictsValue.objects.values('id', 'code', 'name').filter( type__code=settings.GOOD_TYPES, status=1), 'salesman': UsersInfo.objects.values('id', 'account', 'username').filter( ~Q(id=1) & Q(status=1)).order_by('-date_joined'), 'receivers': ReceiversInfo.objects.values('id', 'code', 'name').filter( customer__code=customer_code), 'tran_site': CountySer(Countries.objects.all(), many=True).data })
def get(self, request, *args, **kwargs): """校验城市是否重复""" code = self.request.query_params.get('code') name = self.request.query_params.get('name') county = self.request.query_params.get('county') pk = self.request.query_params.get('pk') if pk and pk.isdigit(): pk = int(pk) if county and county.isdigit(): county = int(county) else: return CusResponse.get_response(success=False, message='缺少国家id错误') if code and not name: try: pk_, code_ = self.queryset.values_list( 'pk', 'code').filter(county=county).get(code=code) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该城市代码已存在!') elif name and not code: try: pk_, name_ = self.queryset.values_list( 'pk', 'name').filter(county=county).get(name=name) except Exception as e: return CusResponse.get_response(data=0) if pk == pk_: return CusResponse.get_response(data=0) else: return CusResponse.get_response(data=1, message='该城市名称已存在!') else: return CusResponse.get_response(success=False, message='参数有误')
def get(self, request, *args, **kwargs): return CusResponse.get_response(data=self.queryset.values( 'id', 'code', 'name'), message='获取客户列表成功')
def get(self, request): queryset = self.filter_queryset(self.get_queryset()) return CusResponse.get_response( data={ 'cities': queryset.values('id', 'code', 'name'), })
def get(self, request): return CusResponse.get_response(data={ 'branches': BranchesInfo.objects.values('id', 'name').filter(~Q(id=1) & Q(status=1)), 'roles': RolesInfo.objects.values('id', 'name').filter(~Q(id=1) & Q(status=1)) })