Exemplo n.º 1
0
def make_order(request):
    carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True)

    order = Order()

    order.o_user = request.user

    order.o_price = get_total_price(user=request.user)

    order.save()

    for cart_obj in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.o_goods_price = cart_obj.c_goods.price
        ordergoods.save()
        cart_obj.delete()

    data = {
        'status': 200,
        'msg': 'order success',
        'order_id': order.id,
    }

    return JsonResponse(data=data)
Exemplo n.º 2
0
def make_order(request):
    carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True)

    order = Order()
    order.o_user = request.user
    order.o_price = get_total_price()
    order.save()

    for cart_obj in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.save()
        # 从购物车中删除
        cart_obj.delete()

    address_obj = Address.objects.filter(a_user=request.user).filter(
        a_using=True).first()
    order_address_obj = OrderAddress()
    order_address_obj.oa_address = address_obj
    order_address_obj.oa_order = order
    order_address_obj.save()
    data = {
        "status": 200,
        "msg": "ok",
        "order_id": order.id,
    }
    return JsonResponse(data)
Exemplo n.º 3
0
def generate_order(request):

    cart_list = request.GET.get('goods_list')

    cart_list = cart_list.split('#')

    user = UserModel.objects.get(u_name=request.session.get('username'))
    order = Order()
    order.o_user = user
    order.save()

    for cart_id in cart_list:
        ordergoods = OrderGoods()
        ordergoods.order = order

        cart_obj = CartModel.objects.get(pk=cart_id)
        ordergoods.goods_num = cart_obj.c_goods_num
        ordergoods.goods = cart_obj.c_goods

        ordergoods.save()
        cart_obj.delete()

    data={
        'status':'200',
        'msg':'ok',
        'order_id':order.id
    }
    return JsonResponse(data)
Exemplo n.º 4
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': '用户登录后再操作'})
Exemplo n.º 5
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)
Exemplo n.º 6
0
def generate_order(request):
    goods_list = request.GET.get("goods_list")
    good_list = goods_list.split("#")
    '''
        生成订单
        移除购物车数据
        将购物车数据添加到商品订单中
    '''
    username = request.session.get("username")
    user = UserModel.objects.get(u_name=username)
    order = Order()
    order.o_user = user
    order.save()

    # 移除数据
    for good in good_list:
        ordergoods = OrderGoods()
        ordergoods.o_order = order

        cart_obj = CartModel.objects.get(pk=good)
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.save()
        cart_obj.delete()

        data = {
            "status": "200",
            "msg": "ok",
            "order_id": order.id,
        }
    return JsonResponse(data=data)
Exemplo n.º 7
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)
Exemplo n.º 8
0
def make_order(request):
    order = Order()
    order.o_user = request.user
    order.o_price = get_total_price(
        Cart.objects.filter(c_user=request.user).filter(c_is_select=True))
    order.save()

    cart_list = Cart.objects.filter(c_user=request.user).filter(
        c_is_select=True)
    for cart in cart_list:
        ordergoods = OrderGoods()
        ordergoods.og_order = order
        ordergoods.og_goods = cart.c_goods
        ordergoods.og_goods_num = cart.c_goods_nums
        ordergoods.save()
        cart.delete()

    data = {'status': 200, 'msg': 'ok', 'orderid': order.id}
    return JsonResponse(data=data)
Exemplo n.º 9
0
def make_order(request):
    carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True)

    order = Order(o_user=request.user, o_price=get_total_price())

    order.save()

    for cart in carts:
        ordergoods = OrderGoods(o_order=order,
                                o_goods=cart.c_goods,
                                o_goods_num=cart.c_goods_num)
        ordergoods.save()
        cart.delete()

    data = {
        'status': 200,
        'msg': '下单',
        'order_id': order.id,
    }

    return JsonResponse(data)
Exemplo n.º 10
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)
Exemplo n.º 11
0
def make_order(request):

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

    cart_list = cartlist.split("#")

    order = Order()

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

    order.o_user_id = user_id

    order.o_total_price = get_total_price(user_id)

    order.save()

    for cart_id in cart_list:

        ordergoods = OrderGoods()

        cart_obj = Cart.objects.get(pk=cart_id)

        ordergoods.o_goods_num = cart_obj.c_goods_num

        ordergoods.o_order_id = order.id

        ordergoods.o_goods_id = cart_obj.c_goods_id

        ordergoods.save()

        cart_obj.delete()

    data = {
        "msg": "ok",
        "orderid": order.id,
        "status": "200",
    }

    return JsonResponse(data)
Exemplo n.º 12
0
def make_order(request):
    user = request.user
    carts = Cart.objects.filter(c_user=user).filter(c_is_selected=True)
    # 生成订单
    order = Order()
    order.o_user = user
    order.o_price = total_price(user)
    order.save()
    # 订单和商品级联
    for cart in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods = cart.c_good
        ordergoods.o_goods_num = cart.c_goods_num
        ordergoods.save()
        cart.delete()
    data = {
        'status': 700,
        'msg': 'ok',
        'order_id': order.id,
    }
    return JsonResponse(data)
Exemplo n.º 13
0
def addorder(request):

    cartids = request.GET.getlist("cartids")
    print(cartids)
    order = Order()
    token = request.session.get("token")
    user = User.objects.get(token=token)
    order.user = user
    order.identify = str(int(time.time()))+str(random.randrange(10000,100000))
    print("".join(order.identify.split(".")))
    order.identify = "".join(order.identify.split("."))
    order.save()
    for cartid in cartids:
        cart = Carts.objects.get(pk=cartid)
        ordergoods = OrderGoods()
        ordergoods.order = order
        ordergoods.goods = cart.goods
        ordergoods.num = cart.num
        ordergoods.save()
        cart.delete()

    return JsonResponse({"msg":"下单成功"})
Exemplo n.º 14
0
def make_order(request):
    carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True)

    order = Order()
    order.o_user = request.user
    order.o_price = get_total_price()
    order.save()

    for cart_obj in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.o_goods_nums = cart_obj.c_goods_num
        ordergoods.save()

    data = {
        "status": 200,
        "msg": "ok",
        "order_id": order.id
    }

    return JsonResponse(data=data)
Exemplo n.º 15
0
def create_order(request):

    carts = Cart.objects.filter(c_user=request.user).filter(c_is_selected=True)

    order = Order()
    order.o_user = request.user
    order.o_price = get_total_price()  # get it again at backend
    order.save()
    # create order from selected in cart
    for cart_obj in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.save()
        cart_obj.delete()  # removed cart obj

    data = {
        'status': 200,
        'msg': 'ok',
        'order_id': order.id,
    }
    return JsonResponse(data=data)
Exemplo n.º 16
0
    def post(self, request, *args, **kwargs):
        carts = Cart.objects.filter(c_user=request.user).filter(
            c_is_select=True)

        order = Order()

        order.o_user = request.user

        order.o_price = get_total_price(self.request)

        order.save()

        for cart_obj in carts:
            ordergoods = OrderGoods()
            ordergoods.o_order = order
            ordergoods.o_goods_num = cart_obj.c_goods_num
            ordergoods.o_goods = cart_obj.c_goods
            ordergoods.save()
            cart_obj.delete()

        data = {"status": 200, "msg": 'ok', "data": {'order_id': order.id}}

        return Response(data)
Exemplo n.º 17
0
def make_order(request):
    # 构建订单地址对象
    a_id = request.GET.get("a_id")

    address = Address.objects.filter(pk=a_id).first()

    orderAddress = OrderAddress()

    orderAddress.o_address = address

    carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True)

    order = Order()

    order.o_user = request.user

    order.o_price = get_total_price()

    order.save()

    order = Order.objects.all().last()

    orderAddress.o_order = order

    orderAddress.save()

    for cart_obj in carts:
        ordergoods = OrderGoods()
        ordergoods.o_order = order
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_goods = cart_obj.c_goods
        ordergoods.save()
        cart_obj.delete()

    data = {"status": 200, "msg": 'ok', 'order_id': order.id}

    return JsonResponse(data)
Exemplo n.º 18
0
def make_order(request):
    cartlist = request.GET.get('cartlist')
    cart_list = cartlist.split('#')
    order = Order()
    user_id = request.session.get('user_id')
    order.o_user_id = user_id
    order.o_total_price = get_total_price(user_id)
    order.save()

    for cart_id in cart_list:
        ordergoods = OrderGoods()
        cart_obj = Cart.objects.get(pk=cart_id)
        ordergoods.o_goods_num = cart_obj.c_goods_num
        ordergoods.o_order_id = order.id
        ordergoods.o_goods_id = cart_obj.c_goods_id
        ordergoods.save()
        cart_obj.delete()

    data = {
        'msg': 'ok',
        'orderid': order.id,
        'status': '200',
    }
    return JsonResponse(data)
Exemplo n.º 19
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)