@loginValid
def add_cart(request):
    '\n    处理ajax 请求，添加商品到购物车 ，成功保存到数据库。\n    传入商品id，数量\n    '
    sendData = {'code': 200, 'data': ''}
    if (request.method == 'POST'):
        id = int(request.POST.get('goods_id'))
        count = int(request.POST.get('count', 1))
        goods = Goods.objects.get(id=id)
        cart = Cart()
        cart.goods_name = goods.goods_name
        cart.goods_num = count
        cart.goods_price = goods.goods_price
        cart.goods_picture = goods.goods_picture
        cart.goods_total = round((goods.goods_price * count), 3)
        cart.goods_id = goods.id
        cart.cart_user = request.COOKIES.get('user_id')
        cart.save()
        sendData['data'] = '加入购物车成功'
    else:
        sendData['code'] = 500
        sendData['data'] = '请求方式错误'
    return JsonResponse(sendData)
处理ajax 请求，添加商品到购物车 ，成功保存到数据库。
传入商品id，数量
@loginValid
def add_cart(request):
    '\n    处理ajax 请求，添加商品到购物车 ，成功保存到数据库。\n    传入商品id，数量\n    '
    sendData = {'code': 200, 'data': }
    if (request.method == 'POST'):
        id = int(request.POST.get('goods_id'))
        count = int(request.POST.get('count', 1))
        goods = Goods.objects.get(id=id)
        cart = Cart()
        cart.goods_name = goods.goods_name
        cart.goods_num = count
        cart.goods_price = goods.goods_price
        cart.goods_picture = goods.goods_picture
        cart.goods_total = round((goods.goods_price * count), 3)
        cart.goods_id = goods.id
        cart.cart_user = request.COOKIES.get('user_id')
        cart.save()
        sendData['data'] = '加入购物车成功'
    else:
        sendData['code'] = 500
        sendData['data'] = '请求方式错误'
    return JsonResponse(sendData)