Exemple #1
0
def make_order(request):
    carts = request.GET.get('carts')
    cart_list = carts.split('#')
    print(cart_list)

    order = OrderModel()

    userid = request.session.get("user_id")

    order.o_user = UserModel.objects.get(pk=userid)

    order.save()
    # 生成订单的商品数据   从购物车中来的
    # 将购物车中的数据删除 ,在订单商品中添加移除的数据
    for cartid in cart_list:
        # 查询购物车中的数据
        cartmodel = CartModel.objects.get(pk=cartid)
        # 创建订单商品数据
        ordergoods = OrderGoods()
        # 绑定订单号
        ordergoods.o_order = order
        # 订单商品数据的商品个数
        ordergoods.o_goods_num = cartmodel.c_goods_num
        # 订单商品中的商品
        ordergoods.o_goods = cartmodel.c_goods
        ordergoods.save()
        cartmodel.delete()
    data = {
        'msg':'ok',
        'status':'200',
        'order':order.id,
    }
    return JsonResponse(data)
Exemple #2
0
def generate_order(request):

    selects = request.GET.get("selects")

    select_list = selects.split("#")

    user_id = request.session.get("user_id")

    data = {
        "msg": "ok",
        "status": "200",
    }

    # 先生成一个订单
    order = OrderModel()
    order.user_id = user_id
    order.o_num = str(uuid.uuid4())
    order.save()

    # 要生成订单商品信息
    for select_obj in select_list:
        order_goods = OrderGoodsModel()
        cart_object = CartModel.objects.get(pk=select_obj)
        order_goods.goods_id = cart_object.goods_id
        order_goods.goods_num = cart_object.c_num
        order_goods.order_id = order.id
        order_goods.save()
        cart_object.delete()

    data["order_id"] = order.id
    # 移除购物车中的数据

    return JsonResponse(data=data)
Exemple #3
0
def make_order(request):
    carts = request.GET.get('carts')

    cart_list = carts.split('#')

    print(cart_list)

    order = OrderModel()

    userid = request.session.get('user_id')

    order.o_user = UserModel.objects.get(pk=userid)

    order.save()

    for cartid in cart_list:
        # 查询购物车的数据
        carmodel = CarModel.objects.get(pk=cartid)
        # 创建订单商品数据
        ordergoods = OrderGoods()
        # 生成订单号
        ordergoods.o_order = order
        # 商品个数
        ordergoods.o_goods_num = carmodel.c_goods_num
        # 商品信息
        ordergoods.o_goods = carmodel.c_goods

        ordergoods.save()

        carmodel.delete()

    data = {
        'mas': 'ok',
        'status': 200,
        'order': order.id

    }

    return JsonResponse(data)