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 generate_order(request): cart_list = request.GET.get('goods_list') cart_list = cart_list.split('#') user = UserModel.objects.get(u_name=request.session.get('username')) order = Order() order.o_user = user order.save() for cart_id in cart_list: ordergoods = OrderGoods() ordergoods.order = order cart_obj = CartModel.objects.get(pk=cart_id) ordergoods.goods_num = cart_obj.c_goods_num ordergoods.goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data={ 'status':'200', 'msg':'ok', '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)