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)
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': '用户登录后再操作'})
def genetateorder(request): token = request.session.get("token") user = User.objects.get(token=token) carts = Cart.objects.filter(user=user).filter(isselect=True) if carts.exists(): # 生成訂單 order = Order() order.user = user order.identifier = generate_identifier() order.save() # 訂單商品 # 獲取用戶的購物車 for cart in carts: orderbook = Orderbook() orderbook.order = order orderbook.book = cart.book orderbook.number = cart.number orderbook.price = cart.price orderbook.save() # 從購物車中刪除,數據存入了orderbook cart.delete() data = {"msg": "下單成功", "status": 1, "identifier": order.identifier} return JsonResponse(data) else: data = { "msg": "下單失敗,請先選中商品", "status": -1, } return JsonResponse(data)
def makeOrder(request): data = {'status': '200'} username = request.session.get('username') user = User.objects.filter(u_username=username).first() good_id_list = request.GET.get('good_id_list').split('#') order = Order() order.user = user order.save() for id in good_id_list: cart_my = Cart.objects.filter(pk=id).first() cart_my.cart_belong = True cart_my.cart_order = order cart_my.save() data['order_id'] = order.id return JsonResponse(data)
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":"下单成功"})
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)