Beispiel #1
0
def generateorder(request):
    token = request.session.get('token')
    if token:
        user = User.objects.get(token=token)
        # 生成订单
        order = Order()
        order.user = user
        order.number = str(uuid.uuid5(uuid.uuid4(), 'order'))
        order.save()

        carts = Cart.objects.filter(user=user).filter(isselect=True)
        for cart in carts:
            # 订单商品
            orderGoods = OrderGoods()
            orderGoods.order = order
            orderGoods.shop = cart.shop
            orderGoods.number = cart.number
            orderGoods.save()

            # 移除购物车
            cart.delete()

        responseData = {
            'status': '1',
            'msg': '订单生成成功(未付款)!',
            'orderid': order.id
        }
        print('###########')
        print(order.id)

        return JsonResponse(responseData)

    else:
        return JsonResponse({'msg': '用户登录后再操作'})
    def post(self):
        list_ = []
        parse = parser.parse_args()
        staff_id = parse.get('staff_id')
        number = parse.get('number')
        price = parse.get('price')
        address = parse.get('address')
        phone = parse.get('phone')
        consignee = parse.get('consignee')

        datetime_now = datetime.datetime.now()
        date_stamp = str(int(time.mktime(datetime_now.timetuple())))
        data_microsecond = str("%06d" % datetime_now.microsecond)
        date_stamp = date_stamp + data_microsecond

        order = Order()
        order.order_no = date_stamp
        order.price = price
        order.user_id = staff_id
        order.number = number
        order.address = address
        order.phone = phone
        order.consignee = consignee
        db.session.add(order)
        db.session.commit()

        point = Point.query.filter(Point.staff_id == staff_id).first()
        orders = Order.query.filter(Order.user_id == staff_id).all()
        if orders:
            for order in orders:
                list_.append(order.price)
            prices = sum(list_)
            print(prices)
            point.sumprice = prices
            print(point.sumprice)
            db.session.commit()
        else:
            pass

        return jsonify({'msg': '添加成功'})
Beispiel #3
0
def generateorder(request):
    token = request.session.get('token')
    user = User.objects.get(token=token)

    order = Order()
    order.user = user
    order.number = str(uuid.uuid5(uuid.uuid4(), 'order'))
    order.save()

    carts = Cart.objects.filter(user=user).filter(isselect=True)

    for cart in carts:
        # print(cart.id)
        orderGoods = OrderGoods()

        orderGoods.order = order
        orderGoods.goods = cart.goods
        orderGoods.number = cart.number
        orderGoods.save()

        cart.delete()

    response_data = {'status': '1', 'msg': '订单生成成功(未付款)', 'orderid': order.id}
    return JsonResponse(response_data)