Esempio n. 1
0
def addtoCrat(request):
    #session查询,查询是否登陆
    user_id = request.session.get('user_id')

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

    if user_id:
        goodsid = request.GET.get('goodsid')

        #联合主键查询
        carts = AxfCart.objects.filter(c_user_id=user_id).filter(
            c_goods_id=goodsid)

        if carts.count() > 0:
            cart = carts.first()
            cart.c_goods_num = cart.c_goods_num + 1
        else:
            cart = AxfCart()
            cart.c_goods_id = goodsid
            cart.c_user_id = user_id

        cart.save()

        data['c_goods_num'] = cart.c_goods_num

        return JsonResponse(data=data)

    else:
        data['msg'] = '未登录'
        data['status'] = 201
        return JsonResponse(data=data)
Esempio n. 2
0
def subtoCart(request):
    user_id = request.session.get('user_id')

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

    if user_id:
        goodsid = request.GET.get('goodis2')
        carts = AxfCart.objects.filter(c_goods_id=goodsid).filter(
            c_user_id=user_id)

        if carts.count() > 0:
            cart = carts.first()
            if cart.c_goods_num > 0:
                cart.c_goods_num = cart.c_goods_num - 1
            else:
                pass
        else:
            cart = AxfCart()
            cart.c_goods_id = goodsid
            cart.c_user_id = user_id
        cart.save()

        data['c_goods_num'] = cart.c_goods_num
        return JsonResponse(data=data)
    else:
        data['status'] = 201
        return JsonResponse(data=data)
Esempio n. 3
0
def addToCart(request):
    user_id = request.session.get('user_id')
    data = {}
    if user_id:
        good_id = request.GET.get('good_id')
        carts = AxfCart.objects.filter(c_goods_id=good_id)
        if carts.exists():
            cart = carts.first()
            cart.c_goods_num = cart.c_goods_num + 1
            cart.c_is_select = True

        else:

            cart = AxfCart()
            cart.c_user_id = user_id
            cart.c_goods_id = good_id
        cart.save()

        data['status'] = 200
        data['msg'] = '添加成功'
        data['c_goods_num'] = cart.c_goods_num
    else:
        data['status'] = 201
        data['msg'] = '未登录'

    return JsonResponse(data=data)
Esempio n. 4
0
def subToCart(request):
    g_id = request.GET.get('g_id')

    u_id = request.session['user_id']
    carts = AxfCart.objects.filter(c_goods_id=g_id).filter(c_user_id=u_id)

    if carts.count() > 1:
        cart = AxfCart()
        cart.c_user_id = u_id
        cart.c_goods_id = g_id
    else:
        cart = carts.first()
        cart.c_goods_num = cart.c_goods_num - 1

    cart.delete()

    data = {'status': 200, 'msg': 'ok', 'c_goods_num': cart.c_goods_num}
    return JsonResponse(data=data)
Esempio n. 5
0
def addToCart(request):
    # 获取session中的user_id
    user_id = request.session.get('user_id')
    data = {'msg': 'ok', 'status': 200}
    # 判断是否登录
    if user_id:
        # 获取goodsid
        goodsid = request.GET.get('goodsid')
        # user_id和goodsid联合查询
        carts = AxfCart.objects.filter(c_user_id=user_id).filter(
            c_goods_id=goodsid)
        if carts.count() > 0:
            cart = carts.first()
            cart.c_goods_num = cart.c_goods_num + 1
        else:
            cart = AxfCart()
            cart.c_goods_id = goodsid
            cart.c_user_id = user_id
        cart.save()
        data['c_goods_num'] = cart.c_goods_num
    else:
        data['msg'] = '未登录'
        data['status'] = 201
    return JsonResponse(data=data)