def generate_order(request): goods_list = request.GET.get("goods_list") good_list = goods_list.split("#") ''' 生成订单 移除购物车数据 将购物车数据添加到商品订单中 ''' username = request.session.get("username") user = UserModel.objects.get(u_name=username) order = Order() order.o_user = user order.save() # 移除数据 for good in good_list: ordergoods = OrderGoods() ordergoods.o_order = order cart_obj = CartModel.objects.get(pk=good) ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data = { "status": "200", "msg": "ok", "order_id": order.id, } return JsonResponse(data=data)
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 make_order(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(user=request.user) order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.o_goods_price = cart_obj.c_goods.price ordergoods.save() cart_obj.delete() data = { 'status': 200, 'msg': 'order success', 'order_id': order.id, } return JsonResponse(data=data)
def make_order(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() order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() # 从购物车中删除 cart_obj.delete() address_obj = Address.objects.filter(a_user=request.user).filter( a_using=True).first() order_address_obj = OrderAddress() order_address_obj.oa_address = address_obj order_address_obj.oa_order = order order_address_obj.save() data = { "status": 200, "msg": "ok", "order_id": order.id, } return JsonResponse(data)
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 doOrder(req): print('this is a doOrder') user = req.user address = user.address_set.filter(choose=True).first() message = req.POST.get('message') money = req.POST.get('money') try: order = Order(user=user, address=address, money=money, message=message, orderId=random.randrange(1111111, 100000000)) order.save() cart = req.user.cart_set.filter(isChoose=True) for c in cart: OrderDetail(order=order, goodsImg=c.goods.productimg, goodsName=c.goods.productname, price=c.goods.price, num=c.num, total=math.ceil(eval(c.goods.price) * c.num)).save() req.user.cart_set.filter(isChoose=True).delete() except Exception as e: print(e) return redirect(reverse('App:cart'))
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 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 make_order(request): order = Order() order.o_user = request.user order.o_price = get_total_price( Cart.objects.filter(c_user=request.user).filter(c_is_select=True)) order.save() cart_list = Cart.objects.filter(c_user=request.user).filter( c_is_select=True) for cart in cart_list: ordergoods = OrderGoods() ordergoods.og_order = order ordergoods.og_goods = cart.c_goods ordergoods.og_goods_num = cart.c_goods_nums ordergoods.save() cart.delete() data = {'status': 200, 'msg': 'ok', 'orderid': order.id} return JsonResponse(data=data)
def post(self): """ 下单 用户 排挡(目前没有) 电影 movieapi 大厅 None 定义一个表 大厅类型 座位类型(0,0) (0,1) 1 - 16 if 一排就是五个位置 0 1 2 3 4 6 7 8 9 11 12 13 14 """ u_token = request.form.get("u_token") mp = request.form.get("mp") seats = request.form.get("seats") order = Order() order.o_user = cache.get(u_token) order.o_movie_plan = mp order.save() seat_list = seats.split("#") for seats_positon in seat_list: ticket = Ticket() ticket.t_order = order.id ticket.t_seat = int(seats_positon) ticket.save() # 将订单放入缓存中并限定过期时间 order_list = cache.get(mp) if not order_list: order_list.append(order.id) cache.set(mp, order_list) data = {"returnCode": "0", "returnValue": order.id} return data
def doOrder(req): # 拿到传递过来的留言 message = req.POST.get('message') #保存生成订单 orderObj = Order(user=req.user, address=req.user.address_set.filter(state=True).first(), money=req.POST.get('money'), message=message, orderId=time.strftime('%y%m%d%H%M%s')) orderObj.save() #保存订单详情 carData = req.user.car_set.filter(isChoose=True) for car in carData: OrderDetail(order=orderObj, goodsImg=car.goods.productimg, goodsName=car.goods.productname, price=car.goods.price, num=car.num, total=car.num * eval(car.goods.price)).save() return redirect(reverse('App:car'))
def make_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_select=True) order = Order(o_user=request.user, o_price=get_total_price()) order.save() for cart in carts: ordergoods = OrderGoods(o_order=order, o_goods=cart.c_goods, o_goods_num=cart.c_goods_num) ordergoods.save() cart.delete() data = { 'status': 200, 'msg': '下单', 'order_id': order.id, } return JsonResponse(data)
def make_order(request): cartlist = request.GET.get("cartlist") cart_list = cartlist.split("#") order = Order() user_id = request.session.get('user_id') order.o_user_id = user_id order.o_total_price = get_total_price(user_id) order.save() for cart_id in cart_list: ordergoods = OrderGoods() cart_obj = Cart.objects.get(pk=cart_id) ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_order_id = order.id ordergoods.o_goods_id = cart_obj.c_goods_id ordergoods.save() cart_obj.delete() data = { "msg": "ok", "orderid": order.id, "status": "200", } return JsonResponse(data)
def make_order(request): user = request.user carts = Cart.objects.filter(c_user=user).filter(c_is_selected=True) # 生成订单 order = Order() order.o_user = user order.o_price = total_price(user) order.save() # 订单和商品级联 for cart in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods = cart.c_good ordergoods.o_goods_num = cart.c_goods_num ordergoods.save() cart.delete() data = { 'status': 700, '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 make_order(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() order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods = cart_obj.c_goods ordergoods.o_goods_nums = cart_obj.c_goods_num ordergoods.save() data = { "status": 200, "msg": "ok", "order_id": order.id } return JsonResponse(data=data)
def create_order(request): carts = Cart.objects.filter(c_user=request.user).filter(c_is_selected=True) order = Order() order.o_user = request.user order.o_price = get_total_price() # get it again at backend order.save() # create order from selected in cart for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() # removed cart obj data = { 'status': 200, 'msg': 'ok', 'order_id': order.id, } return JsonResponse(data=data)
def post(self, request, *args, **kwargs): 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(self.request) order.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data = {"status": 200, "msg": 'ok', "data": {'order_id': order.id}} return Response(data)
def make_order(request): # 构建订单地址对象 a_id = request.GET.get("a_id") address = Address.objects.filter(pk=a_id).first() orderAddress = OrderAddress() orderAddress.o_address = address 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() order.save() order = Order.objects.all().last() orderAddress.o_order = order orderAddress.save() for cart_obj in carts: ordergoods = OrderGoods() ordergoods.o_order = order ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_goods = cart_obj.c_goods ordergoods.save() cart_obj.delete() data = {"status": 200, "msg": 'ok', 'order_id': order.id} return JsonResponse(data)
def post(self, request, *args, **kwargs): token = request.POST.get('token') # 未登录 if token == None or token == "null": return Response({"status": 901, "msg": "未登录"}) u_id = cache.get(token) user = User.objects.get(pk=u_id) cart = request.POST.get("cart") if cart: o_addr = request.POST.get("addr_id") o_note = request.POST.get("o_note") cartfoods = Cart.objects.filter(c_user=user).filter(is_select=1) if cartfoods: try: order = Order() order.o_user = user order.o_addr = o_addr order.o_note = o_note order.o_id = get_order_id(user) order.o_price = get_total_price(user) order.o_points = get_total_points(user) order.save() for food in cartfoods: orderfood = OrderFoods() orderfood.o_user_order = order orderfood.o_foods_id = food.c_foods_id orderfood.o_foods_num = food.c_foods_num orderfood.save() food.delete() return Response({"status": 200, "order_id": order.id}) except Exception as e: print(e) Response({"status": 901, "msg": "信息填写有误"}) else: return Response({"status": 901, "msg": "没有商品被选中或刷新再试"}) return Response({"status": 200, "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)
def make_order(request): cartlist = request.GET.get('cartlist') cart_list = cartlist.split('#') order = Order() user_id = request.session.get('user_id') order.o_user_id = user_id order.o_total_price = get_total_price(user_id) order.save() for cart_id in cart_list: ordergoods = OrderGoods() cart_obj = Cart.objects.get(pk=cart_id) ordergoods.o_goods_num = cart_obj.c_goods_num ordergoods.o_order_id = order.id ordergoods.o_goods_id = cart_obj.c_goods_id ordergoods.save() cart_obj.delete() data = { 'msg': 'ok', 'orderid': order.id, 'status': '200', } return JsonResponse(data)
def shopping(request): if request.GET.get('pid'): product = Product.objects.get(pid=request.GET.get('pid')) if request.user.orders and product.order: if request.GET.get('deletepid'): order = product.order product = Product.objects.get(order_id=order.id) product.order_id = None product.save() order.delete() if request.user.orders.first(): object_list = [ Product.objects.filter(status=1, is_delete=0, type=0, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=1, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=2, inventory__gt=0), [ i.products.first() for i in Order.objects.filter( order_status=1, user_id=request.user.uid) ], [ int( sum([ i.products.first().price * i.productnum for i in Order.objects.filter( order_status=1, user_id=request.user.uid) ])) - request.user.score / 10, len([ i.products.first() for i in Order.objects.filter( order_status=1, user_id=request.user.uid) ]), request.user.score / 10 ] ] return render(request, 'shopping.html', locals()) else: return redirect(reverse('app:index')) order = product.order order.productnum += int(request.GET.get('num')) order.save() print([ i.products.first().price * i.productnum for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ]) object_list = [ Product.objects.filter(status=1, is_delete=0, type=0, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=1, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=2, inventory__gt=0), # Product.objects.filter(order=order.id)[0] [ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ], [ int( sum([ i.products.first().price * i.productnum for i in Order.objects.filter( order_status=1, user_id=request.user.uid) ])) - request.user.score / 10, len([ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ]), request.user.score / 10 ] ] return render(request, 'shopping.html', locals()) order = Order() order.user_id = request.user order.create_time = datetime.now() order.order_status = 1 order.productnum = request.GET.get('num') order.total = int(product.price) * int(request.GET.get('num')) order.save() product.order = order product.save() object_list = [ Product.objects.filter(status=1, is_delete=0, type=0, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=1, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=2, inventory__gt=0), # Product.objects.filter(order=order.id)[0] [ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ], [ int( sum([ i.products.first().price * i.productnum for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ])) - request.user.score / 10, len([ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ]), request.user.score / 10 ] ] return render(request, 'shopping.html', locals()) else: print(1111111111111111111) object_list = [ Product.objects.filter(status=1, is_delete=0, type=0, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=1, inventory__gt=0), Product.objects.filter(status=1, is_delete=0, type=2, inventory__gt=0), # Product.objects.filter(order=order.id)[0] [ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ], [ int( sum([ i.products.first().price * i.productnum for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ])) - request.user.score / 10, len([ i.products.first() for i in Order.objects.filter(order_status=1, user_id=request.user.uid) ]), request.user.score / 10 ] ] return render(request, 'shopping.html', locals())
def post(self): # 只要能进来的,就代表用户登录状态有效,并且用户有权限进行次操作 # 直接书写操作即可 # u_token = request.form.get("u_token") # # if u_token: # # user_id = cache.get(u_token) # # if user_id: # # user = User.query.get(user_id) # # if user.check_permission(models.PERMISSION_MODIFCATION): # return {"msg": "post ok"} # else: # abort(403, message="你没有权限访问此模块") # else: # abort(401, message="用户状态失效") # else: # abort(401, message="用户未登录") """ 下单 用户 排挡(目前还没有) 电影 大厅 没有 定义一个表 大厅类型 座位 (0,0) (0,1) 1 - 16 一排就是五个位置 0 1 2 3 4 6 7 8 9 11 12 13 14 """ u_token = request.form.get("u_token") mp = request.form.get("mp") seats = request.form.get("seats") order = Order() order.o_user = cache.get(u_token) order.o_movie_plan = mp order.save() seat_list = seats.split("#") for seat_position in seat_list: ticket = Ticket() ticket.t_order = order.id ticket.t_seat = int(seat_position) ticket.save() order_list = cache.get(mp) if not order_list: order_list.append(order.id) # 将订单放到缓存中 cache.set(mp, order_list) data = {"returnCode": "0", "returnValue": order.id} return data