def get_order(): house_id = request.form.get('house_id') begin_date = request.form.get('start_date') end_date = request.form.get('end_date') if not all([house_id, begin_date, end_date]): return jsonify(status_code.PARAMS_ERROR) x = (datetime.strptime(end_date, '%Y-%m-%d') - datetime.strptime(begin_date, '%Y-%m-%d')).days # 如果开始时间大于结束时间. 进行判断 返回参数错误 if x < 0: return jsonify(status_code.END_TIME_IS_ERROR) days = x + 1 house_price = House.query.filter_by(id=house_id).first().price amout = days * house_price # 创建订单 order = Order() order.user_id = session['user_id'] order.house_id = house_id order.begin_date = begin_date order.end_date = end_date order.days = days order.house_price = house_price order.amout = amout try: order.add_update() return jsonify(status_code.SUCCESS) except: return jsonify(status_code.DATABASE_ERROR)
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 order(): # 接收参数 dict = request.form house_id = int(dict.get('house_id')) start_date = datetime.strptime(dict.get('start_date'), '%Y-%m-%d') end_date = datetime.strptime(dict.get('end_date'), '%Y-%m-%d') # 验证有效性 if not all([house_id, start_date, end_date]): return jsonify(status_code.PARAMS_ERROR) if start_date > end_date: return jsonify(status_code.ORDER_START_END_TIME_ERROR) # 查询房屋对象 try: house = House.query.get(house_id) except: return jsonify(status_code.DATABASE_ERROR) # 创建订单对象 order = Order() order.user_id = session['user_id'] order.house_id = house_id order.begin_date = start_date order.end_date = end_date order.days = (end_date - start_date).days + 1 order.house_price = house.price order.amount = order.days * order.house_price try: order.add_update() except: return jsonify(status_code.DATABASE_ERROR) # 返回信息 return jsonify(code=status_code.OK)
def create_order(): begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d') end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d') house_id = request.form.get('house_id') user_id = session['user_id'] if not all([begin_date, end_date]): return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL) if begin_date > end_date: return jsonify(status_code.ORDER_BEGIN_DATA_GT_END_DATE_ERROR) house = House.query.get(house_id) 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 = house.price order.amount = order.days * order.house_price order.add_update() return jsonify(status_code.SUCCESS)
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 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 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 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 post_order(): order_dict = request.form house_id = order_dict.get('house_id') start_time = datetime.strptime(order_dict.get('start_time'), '%Y-%m-%d') end_time = datetime.strptime(order_dict.get('end_time'), '%Y-%m-%d') if not all([house_id, start_time, end_time]): return jsonify(status_code.PARAMS_ERROR) if start_time > end_time: return jsonify(status_code.ORDER_START_TIME_GT_END_TIME) house = House.query.get(house_id) order = Order() order.user_id = session['user_id'] order.house_id = house_id order.begin_date = start_time order.end_date = end_time order.house_price = house.price order.days = (end_time - start_time).days + 1 order.amount = order.days * order.house_price try: order.add_update() return jsonify(code=status_code.OK) except Exception as e: return jsonify(status_code.DATABASE_ERROR)
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 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 get_order(id): """ 提交我的订单 """ user_id = session['user_id'] begin_date = datetime.datetime.strptime(request.form.get('start_date'), '%Y-%m-%d') end_date = datetime.datetime.strptime(request.form.get('end_date'), '%Y-%m-%d') times = end_date - begin_date days = times.days + 1 house = House.query.get(id) price = house.price amount = days * price order = Order() order.user_id = user_id order.house_id = id order.begin_date = begin_date order.end_date = end_date order.days = days order.house_price = price order.amount = amount order.add_update() return jsonify(code=status_code.OK)
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 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 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)
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 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 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 create_order(): if request.method == "POST": house_id = request.form.get('house_id') # 对前端传过来的时间值进行处理成可以做加法运算的 print(request.form.get('begin_date')) begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d') end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d') print(begin_date, end_date) user_id = session['user_id'] # 验证是否有填写时间 if not all([begin_date, end_date]): return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL) # 验证初始时间是否大于结束时间 if 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(code=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() data = {"order_id": order.id, "order_amount": order.amount} print(data) return jsonify(code=status_code.ok, data=data) else: id = request.args.get('id') amount = request.args.get('amount') print(id, amount) return render_template('order_success.html', data={ 'id': id, 'amount': amount })
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 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 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 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 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 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)