Beispiel #1
0
def generateorder(request):
    tel= request.COOKIES.get('tel')
    user = User.objects.get(tel=tel)

    # 生成订单
    order = Order()
    order.user = user
    order.identifier = str(int(time.time())) + str(random.randrange(10000,100000))
    order.save()

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

        cart.delete()

    responseData = {
        'msg': '订单生成成功',
        'status': 1,
        'identifier': order.identifier
    }

    return JsonResponse(responseData)
Beispiel #2
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': '用户登录后再操作'})
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)