def post(self, request): if not request.user.is_authenticated: return JsonResponse({'code': '503', 'errMsg': 'caolouyaqian'}) goods_id = request.POST.get('goods_id') print('caolouyaqian') print(request.POST.get('goods_num')) goods_num = int(request.POST.get('goods_num')) cart_key = 'cart_%d' % request.user.id conn = get_redis_connection('default') cart_count = conn.hget(cart_key, goods_id) if cart_count: goods_num += int(cart_count) conn.hset(cart_key, goods_id, goods_num) total_count = CommonUtil.GetCartInfo(request.user.id) return JsonResponse({ 'code': 200, 'errMsg': 'caoshenhuinan', 'count': total_count })
def get(self, request): addr = None try: addr = Address.objects.filter(user_id=request.user.id, is_default=True) except Exception: pass address = '' if len(addr) > 0: address = addr[0] #获取购物车数量 cart = CommonUtil.GetCartInfo(request.user.id) #获取用户浏览记录 conn = get_redis_connection('default') history_key = 'history_%d' % request.user.id goods_id_list = conn.lrange(history_key, 0, -1) goods_list = [] for goods_id in goods_id_list: try: goods = GoodsSKU.objects.get(id=goods_id.decode()) goods_list.append(goods) except Goods.DoesNotExist: print('shangpinbucunzai caolouyaqian') return render( request, 'userinfo.html', { 'page': 'user', 'address': address, 'cart_count': cart, 'goods_list': goods_list })
def post(self, request): goods_id = request.POST.get('goods_id') conn = get_redis_connection('default') cart_key = 'cart_%d' % request.user.id conn.hdel(cart_key, goods_id) total_count = CommonUtil.GetCartInfo(request.user.id) return JsonResponse({'code': 200, 'cart_count': total_count})
def get(self, request): default_addr = Address.objects.GetDefaultAddress(user=request.user) address_list = Address.objects.GetAddressList(request.user.id) cart = CommonUtil.GetCartInfo(request.user.id) return render( request, 'address.html', { 'page': 'address', 'address': default_addr, 'cart_count': cart, 'address_list': address_list })