示例#1
0
    def get(self, request):
        """商品上下架修改"""
        sku_id = request.GET.get('sku_id', '')
        res_type = request.GET.get('res_type', '')

        if not all([sku_id, res_type]):
            return JsonResponse({'status': 1, 'msg': '参数不完整'})

        if res_type == 'down':
            good_status = 0
            msg = '下架成功'
        elif res_type == 'up':
            good_status = 1
            msg = '成功上架'
        else:
            return JsonResponse({'status': 2, 'msg': '参数错误'})

        try:
            good_obj = GoodsSKU.objects.get(sku_id=sku_id)
        except:
            return JsonResponse({'status': 3, 'msg': '没找到这个商品'})

        good_obj.status = good_status
        good_obj.save()

        logger.info('状态操作:%s > %s', sku_id, msg)

        return JsonResponse({'status': 0, 'msg': msg})
示例#2
0
    def post(self, request):
        """采购商品单项 入库"""
        data = json.loads(request.POST.get('data_dict'))
        # print(data)

        if not data.get('pur_id', '') or not data.get('sku_id', ''):
            return JsonResponse({'status': 1, 'msg': '参数错误'})

        skugood_obj = GoodsSKU.objects.filter(sku_id=data['sku_id'])
        if not skugood_obj:
            return JsonResponse({'status': 2, 'msg': '没找到该商品信息'})

        pur_good = PurchaseGoods.objects.filter(purchase__purchase_id=data['pur_id'],
                                                sku_good__sku_id=data['sku_id'],
                                                status=0)
        if not pur_good:
            return JsonResponse({'status': 3, 'msg': '没找到这条记录'})

        good_num = pur_good[0].count
        try:
            skugood_obj.update(stock=F('stock') + good_num)
            pur_good.update(status=1)
        except:
            return JsonResponse({'status': 4, 'msg': '更新失败'})
        else:
            logger.info('单品入库:入库单<%s>中 %s 库存增加了 %s', data['pur_id'], data['sku_id'], good_num)

        return JsonResponse({'status': 0, 'msg': '更新成功'})
示例#3
0
    def get(self, request):
        """采购单 入库"""
        purchase_id = request.GET.get('purchase_id', '')

        if not purchase_id:
            return JsonResponse({'status': 1, 'msg': 'id参数错误'})

        pur_order = PurchaseOrder.objects.filter(purchase_id=purchase_id)
        if not pur_order:
            return JsonResponse({'status': 2, 'msg': '没找到该订单'})

        s_save = transaction.savepoint()

        pur_obj = pur_order[0]
        for pur_good in pur_obj.purchasegoods_set.all():
            # 已入库的商品 不操作
            if pur_good.status:
                continue
            skuId = pur_good.sku_good.sku_id
            try:
                GoodsSKU.objects.filter(sku_id=skuId).update(stock=F('stock') + pur_good.count)
                pur_good.status = 1
                pur_good.save()
            except:
                transaction.savepoint_rollback(s_save)
                logger.warning('入库错误:%s 入库异常 前面数据回滚', skuId)
                return JsonResponse({'status': 3, 'msg': '更新失败'})
            else:
                logger.info('商品入库:入库单<%s>中 %s 库存增加了 %s', purchase_id, skuId, pur_good.count)

        transaction.savepoint_commit(s_save)
        pur_order.update(pur_status=2)

        return JsonResponse({'status': 0, 'msg': '更新成功'})
示例#4
0
    def post(self, request):
        """商品URL、重量、进价、货架号修改"""
        update_data = json.loads(request.POST.get('update_data', ''))

        if 'spu_id' in update_data:
            try:
                good_spu = Goods.objects.get(spu_id=update_data['spu_id'])
            except Goods.DoesNotExist:
                return JsonResponse({'status': 2, 'msg': '商品SPU错误'})

            del update_data['spu_id']
            try:
                good_spu.set_attr(update_data)
                good_spu.save()
            except:
                return JsonResponse({'status': 3, 'msg': '商品更新错误'})

            if 'buy_price' in update_data:
                GoodsSKU.objects.filter(goods=good_spu).update(
                    buy_price=update_data['buy_price'])

                logger.info('进价修改:%s 进货价更新为 %s', good_spu,
                            update_data['buy_price'])

            if 'shelf' in update_data:
                GoodsSKU.objects.filter(goods=good_spu).update(
                    shelf=update_data['shelf'])

            return JsonResponse({'status': 0, 'msg': '更新成功'})

        elif 'sku_id' in update_data:
            skuId = update_data['sku_id']
            try:
                goodsku_obj = GoodsSKU.objects.get(sku_id=skuId)
            except:
                return JsonResponse({'status': 5, 'msg': '商品sku不存在'})

            del update_data['sku_id']

            try:
                old_value = getattr(goodsku_obj, list(update_data)[0])
                goodsku_obj.set_attr(update_data)
                goodsku_obj.save()
                # 单个字典取值 key list(dict)[0] value list(dict.values())[0]
                logger.info('单品修改:%s < %s > 从 %s 变更为 %s', skuId,
                            list(update_data)[0], old_value,
                            list(update_data.values())[0])
            except:
                return JsonResponse({'status': 3, 'msg': '商品更新错误'})

            return JsonResponse({'status': 0, 'msg': '更新成功'})

        return JsonResponse({'status': 1, 'msg': '无更新参数'})
示例#5
0
    def post(self, request):
        data = json.loads(request.POST.get('update_data', ''))

        if not data.get('order_id', ''):
            return JsonResponse({'status': 1, 'msg': '参数错误'})

        try:
            OrderInfo.objects.filter(order_id=data['order_id']).update(order_desc=data['order_desc'])
        except:
            return JsonResponse({'status': 2, 'msg': '修改失败'})

        logger.info('备注修改:%s 的备注更新为 %s', data['order_id'], data['order_desc'])

        return JsonResponse({'status': 0, 'msg': '修改成功'})
示例#6
0
    def post(self, request):
        """发货:更改订单状态 库存"""
        orders_list = json.loads(request.POST.get('data_list', ''))

        if not orders_list:
            return JsonResponse({'status': 3, 'msg': '无订单参数'})

        # 根据订单 计算是否有缺货商品
        orders_obj = OrderInfo.objects.filter(order_id__in=orders_list)

        out_of_stock, orders_goods = out_of_stock_good_list(orders_obj)
        out_of_num = len(out_of_stock)
        if out_of_num > 0:
            return JsonResponse({
                'status': 1,
                'msg': str(out_of_num) + ' 件商品缺货'
            })

        un_orders = orders_obj.filter(order_status=1)
        orders_dict = waybill_order_dict(un_orders)
        # 未处理的订单 提交到平台生成运单号
        msg = make_waybill(orders_dict)
        if msg:
            return msg

        # 事务保存点
        save_id = transaction.savepoint()

        # 无缺货商品 更新库存 销量
        for good_sku in orders_goods.keys():
            try:
                GoodsSKU.objects.filter(sku_id=good_sku).update(
                    stock=F('stock') - orders_goods[good_sku],
                    sales=F('sales') + orders_goods[good_sku])
            except:
                # 更新有错误 则事务回滚到保存点
                transaction.savepoint_rollback(save_id)
                logger.warning('发货错误:%s 发货异常 前面数据回滚', good_sku)
                return JsonResponse({'status': 2, 'msg': '库存错误'})
            else:
                logger.info('发货操作:%s 库存减少了 %s', good_sku,
                            orders_goods[good_sku])

        # 提交事务
        transaction.savepoint_commit(save_id)
        order_num = orders_obj.update(order_status=2)

        return JsonResponse({'status': 0, 'msg': str(order_num) + ' 个订单发货成功'})