Ejemplo n.º 1
0
 def get(self, request):
     try:
         json_data = request.GET.get('data')
         data = json.loads(json_data)
     except Exception:
         return JsonError("解析失败")
     if data:
         if data.get("delete_id"):
             model.GoodPackage.objects.filter(id=data['delete_id']).delete()
             return JsonSuccess("删除成功")
         instance = model.Good.objects.filter(id=data['good_id']).first()
         if not instance:
             return JsonError("未知商品")
         form = CreateOtherPackageForm(data)
         if form.is_valid():
             if valid_package(instance, data):
                 package = form.save(commit=False)
                 package.one_package_id = data['good_id']
                 package.quantify_id = data['quantify_id']
                 package.save()
                 ret = {"package_id": package.id}
                 return JsonSuccess("添加成功", data=ret)
             else:
                 return JsonError("包装价格不能低于成本价")
         else:
             for key in form.errors:
                 return JsonError(form.errors[key][0])
         return JsonError("提交数据有误")
Ejemplo n.º 2
0
 def post(self, request):
     try:
         json_data = request.body
         data = json.loads(json_data)
     except Exception:
         return JsonError("解析失败")
     if not data:
         return JsonError("无效数据")
     exam_batch = data
     user = request.user
     # 权限判断
     if not user or not user.shop:
         return JsonError("没有入库权限")
     examine_status = exam_batch['examine_status']
     if examine_status == -1:
         result = self.get_data(exam_batch['batch_number'])
         return JsonSuccess("", data=result)
     if examine_status == 1:
         self.update_stock_data(exam_batch)
     exam_query_set = model.ExamineStockRecord.objects.filter(
         batch_number=exam_batch['batch_number']).first()
     exam_query_set.examine_status = examine_status
     exam_query_set.examine_person = user.username
     exam_query_set.examine_time = timezone.now()
     exam_query_set.stock_status = 1 if examine_status else 0
     exam_query_set.stock_time = timezone.now()
     exam_query_set.save()
     return JsonSuccess("操作成功")
Ejemplo n.º 3
0
 def post(self, request):
     user = request.user
     ret = []
     shop_id = self.get_arg('shop_id')
     operator_id = self.get_arg('person_id')
     start_time = str1datetime(self.get_arg('start_time'))
     end_time = str1datetime(self.get_arg('end_time'))
     query_kwargs = {}
     if not start_time or not end_time or not shop_id or not operator_id:
         return JsonError("请正确输入")
     query_kwargs['create_time__range'] = [start_time, end_time]
     if shop_id[0] != -1:
         query_kwargs['shop_id'] = shop_id[0]
     if operator_id[0] != -1:
         query_kwargs['operator_id'] = operator_id[0]
     query_set = GoodOrder.objects.filter(**query_kwargs)
     format = '%m-%d %H:%M:%S' if start_time and end_time and (end_time - start_time).days > 0 else '%H:%M:%S'
     for data in query_set:
         ret.append({
             'serial_number': data.serial_number,
             'operate_type': data.operate_type,
             'number': data.number,
             'text': self.format_text(data.serial_number),
             'discount_price': data.discount_price,
             'operator': data.operator.username,
             'create_time': data.create_time.strftime(format),
             'detail_create_time': data.create_time.strftime('%Y-%m-%d %H:%M:%S')
         })
     return JsonSuccess("成功", data=ret)
Ejemplo n.º 4
0
 def post(self, request):
     try:
         data = json.loads(request.body)
     except Exception:
         data = json.loads(request.body.decode("utf-8"))
     username = data.get('username')
     password = data.get('password')
     # next_url = request.GET.get('next') or resolve_url("admin")
     # if user.is_active is false then can't use authenticate() to validate
     user = authenticate(username=username, password=password)
     if user is not None:
         login(request, user)
         ret = {'username': username}
         token = redis_get(username)
         if not token:
             token = get_token()
             redis_db.setex(username, token, 30000)
         session_id = request.session.session_key
         ret['token'] = token
         ret['session_id'] = session_id
         ret['avator'] = user.avatar.name if user.avatar else ''
         return JsonSuccess('登录成功', **ret)
     user = XYUser.objects.filter(username=username).first()
     if not user:
         return JsonError('用户名未注册')
     if user.is_active is False:
         return JsonError('账号未激活')
     return JsonError('账号密码不正确')
Ejemplo n.º 5
0
    def post(self, request):
        try:
            json_data = request.body
            data = json.loads(json_data)
        except Exception:
            return JsonError("解析失败")
        record = data.get('list')
        if not record:
            return JsonError("无效数据")
        batch_num = batch_number()
        user = request.user
        # 权限判断
        if not user or not user.shop:
            return JsonError("没有入库权限")
        for item in record:
            form = CreateStockRecordForm(item)
            if form.is_valid():
                stock_record = form.save(commit=False)
                stock_record.batch_number = batch_num
                stock_record.operator = user.username
                stock_record.shop_id = user.shop.id
                stock_record.good_id = item.get('good_id')
                stock_record.save()
            else:
                print(form.errors)

        model.ExamineStockRecord.objects.create(
            batch_number=batch_num,
            total_price=data.get('total_price'),
            shop_id=user.shop.id,
            stock_genre=data.get('stock_genre') or 1,
            operator=user.username)
        notice_manager("sys_message", "你有审批任务啦")
        return JsonSuccess("入库提交成功")
Ejemplo n.º 6
0
 def get(self, request):
     keyword = request.GET.get('data')
     if not keyword:
         return JsonError("keyword不能为空")
     good_sets = model.Good.objects.filter(
         Q(bar_id__contains=keyword) | Q(name__contains=keyword)).all()[:10]
     package_sets = model.GoodPackage.objects.filter(
         Q(bar_id__contains=keyword) | Q(name__contains=keyword)).all()[:10]
     if not good_sets and not package_sets:
         return JsonError("暂无结果")
     data = []
     for item in good_sets:
         data.append({
             'name': item.name,
             'bar_id': item.bar_id,
             'good_id': item.id,
             'package_number': 1,
             'sale_price': '%.2f' % item.sale_price,
             'quantify': item.quantify_name
         })
     for item in package_sets:
         data.append({
             'name': item.name,
             'bar_id': item.bar_id,
             'good_id': item.good_id,
             'package_number': item.package_number,
             'sale_price': '%.2f' % item.sale_price,
             'quantify': item.quantify_name
         })
     return JsonSuccess("查询成功", data=data[:8])
Ejemplo n.º 7
0
 def get(self, request):
     bar_id = request.GET.get('data')
     instance = model.Good.objects.filter(bar_id=bar_id).first()
     if not instance:
         instance = model.GoodPackage.objects.filter(bar_id=bar_id).first()
         if not instance:
             return JsonError("商品不存在,是否创建商品")
         sale_price = instance.sale_price
         good_id = instance.good_id
         package_number = instance.package_number
     else:  # 单包装查询是否有门店售价
         good_id = instance.id
         pack_good = model.GoodStock.objects.filter(good_id=good_id).first()
         package_number = 1
         if pack_good and pack_good.stock_sale_price:
             sale_price = pack_good.stock_sale_price
         else:
             sale_price = instance.sale_price
     data = {
         'name': instance.name,
         'bar_id': bar_id,
         'good_id': good_id,
         'number': 1,
         'package_number': package_number,
         'sale_price': sale_price,
         'subtotal': sale_price
     }
     return JsonSuccess("查询成功", data=data)
Ejemplo n.º 8
0
 def get(self, request):
     bar_id = request.GET.get('data')
     instance = model.Good.objects.filter(bar_id=bar_id).first()
     if not instance:
         instance = model.GoodPackage.objects.filter(bar_id=bar_id).first()
         if not instance:
             return JsonError("商品不存在,是否创建商品")
         package_number = instance.package_number
         buy_price = instance.one_package.buy_price * package_number
     else:
         package_number = 1
         buy_price = instance.buy_price
     data = {
         "good_id":
         instance.good_id
         if hasattr(instance, 'one_package') else instance.id,
         "bar_id":
         bar_id,
         "name":
         instance.name,
         "quantify":
         instance.quantify.name if instance.quantify else "-",
         "package_number":
         package_number,
         "buy_price":
         buy_price,
         "number":
         1
     }
     return JsonSuccess("获取商品成功", data=data)
Ejemplo n.º 9
0
 def get(self, request):
     user = request.user
     fast_report = request.GET.get('fast_report')
     query_kwargs = {}
     if not user:
         return
     if fast_report:
         import datetime
         # 获取当前时间
         now = datetime.datetime.now()
         # 获取今天零点
         zeroToday = now - datetime.timedelta(hours=now.hour, minutes=now.minute, seconds=now.second, microseconds=now.microsecond)
         # 获取23:59:59
         lastToday = zeroToday + datetime.timedelta(hours=23, minutes=59, seconds=59)
         query_kwargs['shop_id'] = user.shop
         query_kwargs['create_time__range'] = [zeroToday, lastToday]
     query_set = GoodOrder.objects.filter(
         operate_type='sale',
         sale_status='finish',
         **query_kwargs
     ).all()
     total_sale = 0
     total_profit = 0
     sales_favour = 0
     for data in query_set:
         total_sale += data.discount_price
         total_profit += data.profit
         sales_favour += data.pre_sale_price - data.discount_price
     data = {
         'total_sale': total_sale,
         'total_profit': total_profit,
         'sales_discount': total_profit/total_sale*100 if total_profit > 0 else 0,
         'sales_favour': sales_favour
     }
     return JsonSuccess("success", data=data)
Ejemplo n.º 10
0
 def get(self, request):
     query_data = model.Supplier.objects.all()
     if query_data:
         ret = []
         for em in query_data:
             ret.append({'value': em.id, 'label': em.name})
         return JsonSuccess("请求成功", data=ret)
     return JsonError('没有权限')
Ejemplo n.º 11
0
 def get(self, request):
     quantify = request.GET.get('data')
     query_set = model.Quantify.objects.filter(name=quantify).first()
     if query_set:
         return JsonError('单位"%s"已存在' % query_set)
     new = model.Quantify.objects.create(name=quantify)
     ret = {'current_id': new.id, 'quantify_list': query_quantify()}
     return JsonSuccess("添加成功", data=ret)
Ejemplo n.º 12
0
 def get(self, request):
     user = request.user
     if user.has_perm('boss'):
         print(user)
     query_set = XYUser.objects.filter(is_active=True, is_staff=True).all()
     ret = [{'value': -1, 'label': '全部'}]
     for data in query_set:
         ret.append({'value': data.id, 'label': data.username})
     return JsonSuccess("员工列表", data=ret)
Ejemplo n.º 13
0
 def get(self, request):
     query_data = model.Genre.objects.all()
     if query_data:
         parent_genre = []
         for em in query_data:
             if em.level == 0:
                 parent_genre.append(em)
         data = genre_display(parent_genre)
         return JsonSuccess("请求成功", data=data)
     return JsonError('没有数据', data=[])
Ejemplo n.º 14
0
 def get(self, request):
     user = request.user
     token = request.COOKIES.get("token")
     db_token = redis_get(user.username)
     # if not db_token or db_token != token:
     #     logout(request)
     #     return JsonReLogin('需要身份验证')
     if user.is_staff:
         data = self.get_data()
         return JsonSuccess("请求成功", data=data)
     return JsonForbid('没有权限')
Ejemplo n.º 15
0
 def get(self, request):
     try:
         json_data = request.GET.get('data')
         data = json.loads(json_data)
     except Exception:
         return JsonError("解析失败")
     query_set = model.GoodPackage.objects.filter(one_package_id=data).all()
     if not query_set:
         return JsonSuccess("没有数据")
     ret = []
     for data in query_set:
         ret.append({
             'id': data.id,
             'bar_id': data.bar_id,
             'name': data.name,
             'quantify': data.quantify.name if data.quantify else "-",
             'quantify_id': data.quantify.id if data.quantify else None,
             'package_number': data.number,
             'sale_price': data.sale_price
         })
     return JsonSuccess("成功", data=ret)
Ejemplo n.º 16
0
 def post(self, request):
     username = self.get_arg('username').strip()
     password = self.get_arg('password')
     user = XYUser.objects.filter(username=username).first()
     if user:
         return JsonError("用户名已存在")
     if not self.valid_password(password):
         return JsonError("输入的密码不合法")
     user = XYUser.objects.create(username=username)
     user.set_password(password)
     user.save()
     return JsonSuccess("注册成功")
Ejemplo n.º 17
0
 def post(self, request):
     user = request.user
     if not user.shop:
         return JsonError("无对应门店数据")
     self.shop_id = user.shop.id
     goods_data = self.get_arg('goods_data')
     order_data = self.get_arg('order_data')
     serial_number = 'XY' + batch_number()
     buy_price_total = 0
     for data in goods_data:
         stock_instance = GoodStock.objects.filter(
             good_id=data['good_id'], shop_id=self.shop_id).first()
         good_instance = Good.objects.filter(id=data['good_id']).first()
         if not good_instance:
             return JsonError("无效数据")
         if not stock_instance:
             stock_instance = self.pre_sale(data, good_instance)
         stock_instance.number = stock_instance.number - data[
             'number'] * data['package_number']
         stock_instance.save()
         buy_price_total += stock_instance.stock_buy_price * data['number']
         form = GoodOperateRecordForm(data)
         one_profit = data['sale_price'] - stock_instance.stock_buy_price
         profit = one_profit * data['number']
         if form.is_valid():
             instance = form.save(commit=False)
             instance.serial_number = serial_number
             instance.good_id = data['good_id']
             instance.quantify = good_instance.quantify or '-'
             instance.stock_buy_price = stock_instance.stock_buy_price
             instance.profit = profit
             instance.discount_profit = round(
                 one_profit / data['sale_price'] * 100, 2)
             instance.operator = user
             instance.shop = user.shop
             instance.save()
     print(order_data)
     discount_profit = round((order_data['discMoney'] - buy_price_total) /
                             order_data['discMoney'] * 100, 2)
     GoodOrder.objects.create(serial_number=serial_number,
                              number=order_data['totalNumber'],
                              buy_price_total=round(buy_price_total, 2),
                              pre_sale_price=order_data['sumMoney'],
                              discount_price=order_data['discMoney'],
                              discount=order_data['discount'],
                              profit=round(
                                  order_data['discMoney'] - buy_price_total,
                                  2),
                              discount_profit=discount_profit,
                              operator=user,
                              shop=user.shop)
     return JsonSuccess("结算成功")
Ejemplo n.º 18
0
 def get(self, request):
     user = request.user
     user_data = {'value': user.shop.id, 'label': user.shop.name}
     if user.has_perm('Web.boss'):
         shops = model.Shop.objects.all()
         ret = [{'value': '', 'label': '全部'}]
         for shop in shops:
             ret.append({'value': shop.id, 'label': shop.name})
         result = {
             'shop_data': ret,
             'user_data': [user.shop.id],
             'identity': 'boos'
         }
         return JsonSuccess("门店列表", data=result)
     elif user.has_perm('Web.manager'):
         ret = {
             'shop_data': [user_data],
             'user_data': [user.shop.id],
             'identity': 'manager'
         }
         return JsonSuccess("门店列表", data=ret)
     return JsonError("没有权限")
Ejemplo n.º 19
0
 def get(self, request):
     import time
     json_data = request.GET.get('data')
     data = json.loads(json_data)
     if data['del_list']:
         for good in data.get('del_list'):
             try:
                 model.Good.objects.filter(id=good['id']).delete()
             except Exception as e:
                 print([item.name for item in e.protected_objects])
                 notice_manager("sys", "你有审批任务啦")
                 return JsonError("删除失败", data=self.full_data())
         return JsonSuccess("删除成功", data=self.full_data())
     return JsonError("请选择需要删除的商品")
Ejemplo n.º 20
0
 def post(self, request):
     try:
         json_data = request.body
         data = json.loads(json_data)
     except Exception:
         return JsonError("解析失败")
     if not data:
         return JsonError("无效数据")
     query_args = []
     query_kwargs = {}
     keyword = data.get('searchValue')
     current = data.get('currentPage')
     shop_id = data['shopSelected'].pop() if data['shopSelected'] else None
     genre_id = data['genreSelected'].pop(
     ) if data['genreSelected'] else None
     if keyword:
         query_args.append(
             Q(good__name__contains=keyword)
             | Q(good__bar_id__contains=keyword))
     if shop_id != -1:
         query_kwargs['shop_id'] = shop_id
     if genre_id:
         query_kwargs['good__genre_id'] = genre_id
     query_set = model.GoodStock.objects.filter(*query_args, **query_kwargs)
     ret = []
     for data in query_set:
         ret.append({
             'good_name':
             data.good.name,
             'bar_id':
             data.good.bar_id,
             'shop_name':
             data.shop.name,
             'number':
             data.number,
             'quantify':
             data.good_quantify,
             'stock_buy_price':
             round(data.stock_buy_price, 2),
             'stock_sale_price':
             round(
                 data.good.sale_price
                 if not data.stock_sale_price else data.stock_sale_price, 2)
         })
     return JsonSuccess("",
                        data=ret[(current - 1) * 15:current * 15],
                        total=len(ret))
Ejemplo n.º 21
0
 def get(self, request):
     json_data = request.GET.get('data')
     data = json.loads(json_data)
     good_id = data.get('id')
     is_exise = model.Good.objects.filter(bar_id=data.get('bar_id')).first()
     if is_exise and is_exise.id != good_id:
         return JsonError("该条码商品已存在")
     instance = model.Good.objects.filter(id=good_id).first()
     if instance:
         form = CreateGoodForm(data, instance=instance)
     else:
         form = CreateGoodForm(data)
     if form.is_valid():
         good = form.save(commit=False)
         good.supplier_id = data.get('supplier_id')
         good.quantify_id = data.get('quantify_id')
         good.genre_id = data['genre_id'][-1] if data['genre_id'] else None
         good.save()
         return JsonSuccess("保存成功")
     return JsonError("提交数据有误")
Ejemplo n.º 22
0
 def get(self, request):
     serial_number = self.get_arg('data')
     query_set = GoodOperateRecord.objects.filter(serial_number=serial_number).all()
     ret = []
     for item in query_set:
         ret.append({
             'serial_number': item.serial_number,
             'good_id': item.good.id,
             'bar_id': item.bar_id,
             'name': item.name,
             'quantify': item.quantify,
             'number': item.number,
             'sale_price': round(item.sale_price*item.number, 2),
             'operate_type': item.operate_type,
             'sale_status': item.sale_status,
             'operate_name': item.operator.username,
             'shop_name': item.shop.name,
             'create_time': item.create_time
         })
     return JsonSuccess("成功", data=ret)
Ejemplo n.º 23
0
 def get(self, request):
     json_data = request.GET.get('data')
     data = json.loads(json_data)
     print(data)
     form_data = data['form']
     package_data = data['package_data']
     bar_id = form_data.get('bar_id')
     obj = model.Good.objects.filter(bar_id=bar_id).first()
     if obj:
         return JsonError("商品已存在")
     form = CreateGoodForm(form_data)
     if form.is_valid():
         good = form.save(commit=False)
         good.supplier_id = form_data['supplier_id']
         good.quantify_id = form_data['quantify_id']
         good.genre_id = form_data['genre_id'][-1] if form_data[
             'genre_id'] else None
         try:
             good.save()
         except Exception:
             return JsonError("新建失败")
         good_id = form.instance.id
         for em in package_data:
             package_form = CreateOtherPackageForm(em)
             if not package_form.is_valid():
                 return JsonError(package_form.errors)
             if not valid_package(good, em):
                 good.delete()
                 return JsonError("包装价格不能低于成本价")
             other_package = package_form.save(commit=False)
             other_package.one_package_id = good_id
             other_package.quantify_id = em['quantify_id']
             other_package.save()
         return JsonSuccess("创建成功", id=good_id)
     else:
         for key in form.errors:
             return JsonError(form.errors[key][0])
     return JsonError("提交数据有误")
Ejemplo n.º 24
0
 def get(self, request):
     user = request.user
     if user:
         if user.has_perm('boss'):
             tasks = model.ExamineStockRecord.objects.filter(
                 examine_status=-1)
         elif user.has_perm('manager'):
             tasks = model.ExamineStockRecord.objects.filter(
                 examine_status=-1, shop=user.shop)
         else:
             return JsonError("无权操作")
         ret = []
         for task in tasks:
             result = {
                 'batch_number': task.batch_number,
                 'shop': task.shop_name,
                 'examine_status': task.examine_status,
                 'examine_display': task.get_examine_status_display(),
                 'stock_genre': task.get_stock_genre_display()
             }
             ret.append(result)
         return JsonSuccess("获取成功", data=ret)
     return JsonError("无权操作")
Ejemplo n.º 25
0
 def get(self, request):
     data = query_quantify()
     return JsonSuccess("请求成功", data=data)
Ejemplo n.º 26
0
 def get(self, request):
     logout(request)
     return JsonSuccess("退出成功")
Ejemplo n.º 27
0
 def get(self, request):
     # __import__("pdb").set_trace()
     return JsonSuccess("成功")