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 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): 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 post(self): user_id = session['u_id'] house_id = request.form.get('house_id') price = request.form.get('price') begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d') end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d') if not all([house_id, begin_date, end_date]): return jsonify(status_code.DATA_NOT_FULL) if begin_date > end_date: return jsonify(status_code.CREATE_ORDER_END_DATA_ERROR) order = Order() order.user_id = user_id order.house_id = house_id order.begin_date = begin_date order.end_date = end_date order.days = (end_date - begin_date).days + 1 order.house_price = int(price) order.amount = order.days * order.house_price try: order.add_update() except Exception as e: return jsonify(status_code.DATABASE_ERROR) return jsonify(status_code.SUCCESS)
def roommoney(): item = session.get('user') roomid = item.get("roomid") userid = item.get('id') room = Room.query.filter(Room.roomid == roomid).first() print(item) if request.method == 'GET': return render_template('smartroom/roommoney.html', room=room) else: order = Order() order.orderid = order.query.count() + 1 if request.form.get('roommoney_lightlave') != None: order.lightcost = request.form.get('roommoney_lightlave') room.lightlave = int(room.lightlave) + int( request.form.get('roommoney_lightlave')) if request.form.get('roommoney_waterlave') != None: order.watercost = request.form.get('roommoney_waterlave') room.waterlave = int(room.waterlave) + int( request.form.get('roommoney_waterlave')) order.orderdate = datetime.now() order.id = userid db.session.add(order) db.session.add(room) db.session.commit() return render_template('smartroom/roommoney.html', room=room)
def insert(): user = User() order = Order() #dict可以获取user类当中的所有属性 print(user.__dict__) user.name = request.args.get('name') user.idcard = request.args.get('idcard') user.sex = request.args.get('sex') #Flask进行插入时默认使用事物,事先读取文件id记录 db.session().add(user) db.session.flush() order.uid = user.uid order.brand = request.args.get('brand') order.ctype = request.args.get('ctype') order.price = request.args.get('price') order.by_at = datetime.now() #提交事物使用的是session(sqlalchemy当中的session,并不是服务器中的session) try: db.session().add(user) db.session().add(order) db.session().commit() res = {"code": 200, "content": "插入成功"} except Exception as e: print(e) db.session.rollback() res = {"code": 500, "content": "插入失败"} return jsonify(res)
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 create_cust_order(customer, item_count, order_total, status): newOrder = Order(user_id=customer.id, item_count=item_count, order_total=order_total, pickup_status=status) print("Successfully Created") db.session.add(newOrder) db.session.commit() return newOrder
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 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 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 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 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 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 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() data = { "status": 200, "msg": "ok", "order_id": order.id, } return JsonResponse(data=data)
def post(self): list_ = [] parse = parser.parse_args() staff_id = parse.get('staff_id') number = parse.get('number') price = parse.get('price') address = parse.get('address') phone = parse.get('phone') consignee = parse.get('consignee') datetime_now = datetime.datetime.now() date_stamp = str(int(time.mktime(datetime_now.timetuple()))) data_microsecond = str("%06d" % datetime_now.microsecond) date_stamp = date_stamp + data_microsecond order = Order() order.order_no = date_stamp order.price = price order.user_id = staff_id order.number = number order.address = address order.phone = phone order.consignee = consignee db.session.add(order) db.session.commit() point = Point.query.filter(Point.staff_id == staff_id).first() orders = Order.query.filter(Order.user_id == staff_id).all() if orders: for order in orders: list_.append(order.price) prices = sum(list_) print(prices) point.sumprice = prices print(point.sumprice) db.session.commit() else: pass return jsonify({'msg': '添加成功'})
def saveorder(request): # 判断用户是否登录 user_id = request.session.get('_auth_user_id') if not user_id: return render(request, 'mine/login.html', {'error': '用户或者密码错误'}) else: carts = Cart.objects.all() if carts.count() == 0: return JsonResponse({"data": -1, "status": "error"}) oid = time.time() + random.randrange(1, 10000) oid = "%d" % oid o = Order.createorder(oid, user_id, 0) o.save() carts.delete() return redirect('/mine/')
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): 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 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 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 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 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 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 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 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 create_order(): house_id = request.form.get('house_id') # 对前端传过来的时间值进行处理成可以做加法运算的 begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d') end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d') user_id = session['user_id'] # 验证是否有填写时间 if not all([begin_date, end_date]): return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL) # 验证初始时间是否大于结束时间 if not begin_date < end_date: return jsonify(status_code.ORDER_BEGIN_DATA_GT_END_DATA_ERROE) # 获取房屋信息 try: house = House.query.get(house_id) except: return jsonify(status_code.DATABASE_ERROR) # 创建订单对象 order = Order() order.house_id = house_id order.end_date = end_date order.begin_date = begin_date order.user_id = user_id order.days = (end_date - begin_date).days + 1 order.house_price = house.price order.amount = order.days * order.house_price order.add_update() return jsonify(status_code.SUCCESS)