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.goods = cart.goods orderGoods.number = cart.number orderGoods.save() # 移除 cart.delete() responseData = { 'status': '1', 'msg': '', 'orderid': order.id } return JsonResponse(responseData) else: return JsonResponse({'msg':'用户登录后再操作'})
def generateorder(request): token = request.session.get('token') user = User.objects.get(token=token) order = Order() order.user = user order.identifier = generate_identifier() order.save() shopcars = Shopcar.objects.filter(user=user).filter(is_select=True) for shopcar in shopcars: ordergoods = OrderGoods() ordergoods.order = order ordergoods.goods = shopcar.goods ordergoods.number = shopcar.num ordergoods.save() shopcar.delete() data = { 'msg': '下单成功', 'status': 1, 'orderid': order.id, } return JsonResponse(data)
def generateorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) # 订单 order = Order() order.user = user order.identifier = generate_identifier() order.save() # 订单商品(购物车中选中) carts = user.cart_set.filter(isselect=True) for cart in carts: orderGoods = OrderGoods() orderGoods.order = order orderGoods.goods = cart.goods orderGoods.number = cart.number orderGoods.save() # 购物车中移除 cart.delete() # response_data = { # 'msg': '生成订单', # 'status': 1, # 'identifier': order.identifier # } # # return JsonResponse(response_data) return render(request, 'order/orderdetail.html', context={'order': order})
def createorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) carts = user.cart_set.filter(isselect='True') if carts.exists(): order = Order() order.user = user order.identifier = create_identifier() order.save() for cart in carts: ordergoods = OrderGoods() ordergoods.order = order ordergoods.goods = cart.goods ordergoods.num = cart.number ordergoods.total = float(cart.goods.price[1:]) * int(cart.number) ordergoods.save() cart.delete() # 商家订单 customerorder = Customerorder() customerorder.user = cart.goods.publish.user customerorder.order = order customerorder.save() return render(request, 'order/order.html', context={'order': order}) return redirect('app:cart')
def generateorder(request): token = request.session.get('token') user = User.objects.get(token=token) # 生成订单 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)
def order(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) cart = Car.objects.filter(user_id=userid) # 订单 order = Order() order.user = user order.identifier = generate_identifier() order.save() # 订单商品(购物车中选中) carts = cart.filter(isselect=1) for cart in carts: orderGoods = OrderGoods() orderGoods.order = order orderGoods.goods = cart.goods orderGoods.number = cart.number orderGoods.save() # 购物车中移除 cart.delete() return render(request, 'order.html', context={'order': order})
def generateorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) # 筛选出勾选的购物车 carts = user.cart_set.filter(isselect=0) # 订单创建 order = Order() order.user = user order.identifier = generate_identifier() order.save() for cart in carts: global orderGoods orderGoods = OrderGoods() orderGoods.goods = cart.goods orderGoods.order = order orderGoods.number = cart.number cart.delete() orderGoods.save() data = { 'orders': order, 'orderGoods': orderGoods, } return render(request, 'orderdetial.html', context=data)
def generateorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) order = Order() order.user = user order.identifier = generate_identifier() order.save() carts = user.cart_set.filter(isselect=True) # 创建订单商品表 for cart in carts: orderGoods = OrderGoods() orderGoods.order = order orderGoods.goods = cart.goods orderGoods.number = cart.number orderGoods.save() cart.delete() return render(request, 'order/orderdetail.html', context={ 'order': order, 'user': user })
def generateorder(request): token = request.session.get('token') if token: user = User.objects.get(userToken=token) # 生成订单 order = Order() order.user = user order.number = 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.goods = cart.goods orderGoods.number = cart.number orderGoods.save() # 移除购物处 cart.delete() # 商品 销量和库存处理 responseData = { 'status': '1', 'msg': '订单生成成功(为付款)', 'orderid': order.id, } return JsonResponse(responseData) else: return JsonResponse({'msg': '登陆后操作'})
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: ordergoods = OrderGoods() ordergoods.order = order ordergoods.goods = cart.goods ordergoods.number = cart.number ordergoods.save() # 移除购物车 cart.delete() # 销售量增加 库存减少 responseData = { 'msg':'订单生成成功(未付款)', 'status':1, 'orderid':order.id } return JsonResponse(responseData)
def buy_immediatly(request): token=request.session.get('token') userid=cache.get(token) goodsid=request.GET.get('goodsid') number=request.GET.get('number') user=User.objects.get(pk=userid) goods=Goods.objects.get(pk=goodsid) order=Order() order.user=user order.identifier=generate_identifier() order.save() print('5555555555555555555') ordergoods=OrderGoods() ordergoods.order=order ordergoods.goods=goods ordergoods.number=number print(ordergoods.number) ordergoods.save() print(666666666666666) return JsonResponse({'msg':'connect success','status':1})
def generateorder(request): token = request.session.get('token') user = User.objects.get(token=token) # 生成订单 order = Order() order.user = user order.identifier = generate_identifier() order.save() # 订单商品 【选中的商品,即isselect】 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() data = {'msg': '下单成功', 'status': 1, 'identifier': order.identifier} return JsonResponse(data)
def generateorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) order = Order() order.user = user order.identifier = generate_identifier() order.save() carts = user.cart_set.all() for cart in carts: if cart.goods.isselect: ordergoods = OrderGoods() ordergoods.order = order ordergoods.goods = cart.goods ordergoods.number = cart.number ordergoods.save() cart.delete() response_data = { 'msg': '生成订单成功', 'status': 1, } return JsonResponse(response_data)
def generateorder(request): token = request.session.get('token') userid = cache.get(token) user = User.objects.get(pk=userid) order = Order() order.user = user order.identifier = generate_identifier() order.save() carts = user.cart_set.filter(isselect=True) if carts: allpay = 0 for cart in carts: price = cart.goods.price num = cart.number totalprice = price*num allpay += totalprice orderGoods = OrderGoods() orderGoods.order = order orderGoods.goods = cart.goods orderGoods.number = cart.number orderGoods.save() cart.delete() return render(request, 'orderdetail.html', context={'order':order, 'allpay':allpay}) else: print('not_select_goods') return HttpResponse('您没有选择商品')
def makeorder(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(request.user) order.save() for cart in carts: ordergoods = OrderGoods() ordergoods.o_order_id = order.id ordergoods.o_goods_id = cart.c_goods_id ordergoods.o_goods_num = cart.c_goods_num ordergoods.save() cart.delete() # 生成订单后删除购物车数据 data = { 'status': 200, 'msg': 'ok', 'orderid': order.id } return JsonResponse(data=data)
def createOrder(request): userid = request.session.get("user_id") user = UserModel.objects.filter(pk=userid).first() order = OrderModel() order.o_num = str(uuid.uuid4()) order.o_user = user order.o_status = 1 order.save() cartidList = request.GET.get("selectArray").split("#") carts = CartModel.objects.filter(id__in=cartidList) for cart in carts: orderGoods = OrderGoods() orderGoods.og_order = order orderGoods.og_goods = cart.c_goods orderGoods.og_num = cart.c_num orderGoods.save() cart.delete() data = { "code": 200, "ordernum": order.o_num, } return JsonResponse(data)
def genOrder(request): # 获取 token = request.session.get('token') userid = cache.get(token) money=request.GET.get('money') # print(money) response_data ={ 'user': None } if userid: user = User.objects.get(pk=userid) response_data['user_status'] = 1 order=Order() order.user = user order.identifier = generateOrderNo() order.money=money order.save() carts = user.cart_set.filter(isselect=True) for cart in carts: ordergoods=OrderGoods() ordergoods.order=order ordergoods.goods=cart.goods ordergoods.number=cart.num ordergoods.save() cart.delete() # carts = user.cart_set.all() # cart=Cart.objects.filter(user=user) # goods=cart.goods # response_data['carts']=carts return JsonResponse(response_data) # return render(request,'myOrder.html',context=response_data) else: return redirect('app:login')