Ejemplo n.º 1
0
    def get(self, *args, **kwargs):

        # 获取用户id
        user_id = self.session.data['user_id']

        # 数据库中取数据
        ih_house_info = ihome_model('ih_house_info')
        ih_area_info = ihome_model('ih_area_info')
        try:
            ret = self.db.query(ih_house_info.hi_house_id,
                                ih_house_info.hi_title,
                                ih_house_info.hi_price,
                                ih_house_info.hi_ctime,
                                ih_area_info.ai_name,
                                ih_house_info.hi_index_image_url).\
                filter(ih_house_info.hi_user_id == user_id, ih_house_info.hi_area_id == ih_area_info.ai_area_id).all()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='查询数据库出错'))

        # 构建返回数据列表
        houses = []
        if ret:
            for i in ret:
                item = dict(
                    house_id=i.hi_house_id,
                    title=i.hi_title,
                    area_name=i.ai_name,
                    price=i.hi_price,
                    img_url=config.image_url_prefix + i.hi_index_image_url if i.hi_index_image_url else '',
                    ctime=i.hi_ctime.strftime('%Y-%m-%d %H:%M:%S'),
                )
                houses.append(item)

        self.write(dict(errno=RET.OK, errmsg='OK', houses=houses))
Ejemplo n.º 2
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        order_id = self.json_args.get('order_id')
        reject_reason = self.json_args.get('reject_reason')

        # 检测参数
        self.check_args(order_id, reject_reason)

        # 更新数据库
        ih_order_info = ihome_model('ih_order_info')
        ih_house_info = ihome_model('ih_house_info')
        try:
            self.db.query(ih_order_info). \
                filter(ih_order_info.oi_house_id.in_(self.db.query(ih_house_info.hi_house_id).
                                                     filter(ih_house_info.hi_user_id == user_id)),
                       ih_order_info.oi_status == 0,
                       ih_order_info.oi_order_id == order_id). \
                update(dict(oi_status=6, oi_comment=reject_reason), synchronize_session=False)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR,
                                   errmsg='update data error'))

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK'))
Ejemplo n.º 3
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        order_id = self.json_args.get('order_id')

        # 验证参数
        if not order_id:
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数错误'))

        # 更新数据库
        ih_order_info = ihome_model('ih_order_info')
        ih_house_info = ihome_model('ih_house_info')
        try:
            self.db.query(ih_order_info).\
                filter(ih_order_info.oi_house_id.in_(self.db.query(ih_house_info.hi_house_id).
                                                     filter(ih_house_info.hi_user_id == user_id)),
                       ih_order_info.oi_status == 0,
                       ih_order_info.oi_order_id == order_id).\
                update(dict(oi_status=3), synchronize_session=False)
            # synchronize_session=False 代表直接进行更新操作
            # synchronize_session='fetch'代表先进行一次查询,然后再进行更新操作
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR,
                                   errmsg='update data error'))

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK'))
Ejemplo n.º 4
0
    def post(self, *args, **kwargs):
        # 获取参数
        name = self.json_args.get('name')

        # 检查参数
        self.check_args(name)

        # 更新数据库
        user_id = self.session.data.get('user_id')
        ih_user_profile = ihome_model('ih_user_profile')
        item = dict(up_name=name)
        try:
            self.db.query(ih_user_profile).filter(
                ih_user_profile.up_user_id == user_id).update(item)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='保存用户昵称失败'))

        # 更新session中的name
        try:
            self.session.data['name'] = name
            self.session.save()
        except Exception as e:
            logging.error(e)

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK'))
Ejemplo n.º 5
0
    def post(self, *args, **kwargs):
        # 获取参数
        try:
            image_data = self.request.files['avatar'][0]['body']
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数错误'))
        # 检查参数
        self.check_args(image_data)

        # 上传七牛云空间
        try:
            image_name = storage(image_data)
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.THIRDERR, errmsg='头像上传七牛错误'))

        # 更新数据库
        user_id = self.session.data.get('user_id')
        ih_user_profile = ihome_model('ih_user_profile')
        item = dict(up_avatar=image_name)
        try:
            self.db.query(ih_user_profile).filter(
                ih_user_profile.up_user_id == user_id).update(item)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='保存用户头像失败'))

        # 返回数据
        self.write(
            dict(errno=RET.OK,
                 errmsg='OK',
                 data='%s%s' % (config.image_url_prefix, image_name)))
Ejemplo n.º 6
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        real_name = self.json_args.get('real_name')
        id_card = self.json_args.get('id_card')
        # 校验参数
        self.check_args(real_name, id_card)
        # 校验身份证格式
        if not re.match('^\d{17}(\d|x|X)$', id_card):
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数错误'))

        # 调用第三方网站验证身份证合法性……略过

        # 保存数据
        ih_user_profile = ihome_model('ih_user_profile')
        item = dict(up_real_name=real_name, up_id_card=id_card)
        try:
            self.db.query(ih_user_profile).filter(
                ih_user_profile.up_user_id == user_id).update(item)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='save data error'))

        # 返回结果
        self.write(dict(errno=RET.OK, errmsg='OK'))
Ejemplo n.º 7
0
    def post(self, *args, **kwargs):
        # 获取参数
        house_id = self.get_argument('house_id')
        try:
            image_data = self.request.files['house_image'][0]['body']
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数错误'))

        # 检查参数
        self.check_args(image_data)

        # 上传七牛云空间
        try:
            image_name = storage(image_data)
        except Exception as e:
            logging.error(e)
            image_name = None

        if not image_name:
            return self.write(dict(errno=RET.THIRDERR, errmsg='房屋图片上传七牛错误'))

        # 保存到数据库
        # 保存图片路径到数据库ih_house_image表,并且设置房屋的主图片(ih_house_info中的hi_index_image_url)
        # 我们将用户上传的第一张图片作为房屋的主图片
        ih_house_info = ihome_model('ih_house_info')
        ih_house_image = ihome_model('ih_house_image')
        item = dict(hi_house_id=house_id, hi_url=image_name)
        try:
            self.db.execute(ih_house_image.__table__.insert(), item)
            self.db.query(ih_house_info).\
                filter(ih_house_info.hi_house_id == house_id, ih_house_info.hi_index_image_url == None).\
                update(dict(hi_index_image_url=image_name))
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.THIRDERR, errmsg='save data error'))
        # 返回数据
        img_url = config.image_url_prefix + image_name
        self.write(dict(errno=RET.OK, errmsg='OK', url=img_url))
Ejemplo n.º 8
0
    def get(self, *args, **kwargs):
        # 没有参数,默认取销量最高的几条HOME_PAGE_MAX_HOUSES
        # 从redis中取
        try:
            ret = self.redis.get('home_page_data')
        except Exception as e:
            logging.error(e)
            ret = None
        # 如果有就直接返回,都不用loads
        if ret:
            logging.debug('hit redis')
            return self.write(ret)

        # 从数据库取数据
        ih_house_info = ihome_model('ih_house_info')
        try:
            ret = self.db.query(ih_house_info.hi_house_id,
                                ih_house_info.hi_title,
                                ih_house_info.hi_order_count,
                                ih_house_info.hi_index_image_url).\
                filter().order_by(ih_house_info.hi_order_count).\
                limit(constants.HOME_PAGE_MAX_HOUSES).all()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='get data error'))

        houses = []
        if ret:
            for i in ret:
                item = dict(
                    house_id=i.hi_house_id,
                    title=i.hi_title,
                    img_url=config.image_url_prefix + i.hi_index_image_url if i.hi_index_image_url else '',
                )
                houses.append(item)

        # 保存到redis中
        try:
            self.redis.setex('home_page_data',
                             constants.HOME_PAGE_DATA_REDIS_EXPIRE_SECOND,
                             json.dumps(dict(errno=RET.OK, errmsg='OK', houses=houses)))
        except Exception as e:
            logging.error(e)

        self.write(dict(errno=RET.OK, errmsg='OK', houses=houses))
Ejemplo n.º 9
0
    def get(self, *args, **kwargs):
        # 获取用户id
        user_id = self.session.data.get('user_id')

        # 获取用户信息
        ih_user_profile = ihome_model('ih_user_profile')
        try:
            res = self.db.query(ih_user_profile.up_name, ih_user_profile.up_mobile, ih_user_profile.up_avatar).\
                filter(ih_user_profile.up_user_id == user_id).first()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='获取用户信息失败'))

        if not res:
            return self.write(dict(errno=RET.DATAERR, errmsg='用户不存在'))
        data = dict(name=res.up_name,
                    mobile=res.up_mobile,
                    avatar=config.image_url_prefix + res.up_avatar)
        self.write(dict(errno=RET.OK, errmsg='OK', data=data))
Ejemplo n.º 10
0
    def get(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')

        # 从数据库取出数据
        ih_user_profile = ihome_model('ih_user_profile')
        try:
            ret = self.db.query(ih_user_profile.up_real_name, ih_user_profile.up_id_card).\
                filter(ih_user_profile.up_user_id == user_id).first()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR,
                                   errmsg='select data error'))

        if not ret:
            return self.write(dict(errno=RET.DATAERR, errmsg='select no data'))

        # 返回数据
        data = dict(real_name=ret.up_real_name, id_card=ret.up_id_card)
        self.write(dict(errno=RET.OK, errmsg='OK', data=data))
Ejemplo n.º 11
0
    def get(self, *args, **kwargs):
        # 从redis里面取
        try:
            ret = self.redis.get('area_info')
        except Exception as e:
            logging.error(e)
            ret = None

        if ret:
            logging.info("hit redis")
            logging.debug(ret)
            return self.write('{"errno":%s,"errmsg":"OK","data":%s}' % (RET.OK, ret))

        # redis中如果没有就从数据库中取
        ih_area_info = ihome_model("ih_area_info")
        try:
            ret = self.db.query(ih_area_info.ai_area_id, ih_area_info.ai_name).all()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='查询区域信息数据库出错'))

        if not ret:
            return self.write(dict(errno=RET.NODATA, errmsg='无区域信息'))

        data = []
        for i in ret:
            item = {
                'area_id': i.ai_area_id,
                'name': i.ai_name
            }
            data.append(item)

        # 将数据库取得的数据存入redis
        try:
            self.redis.setex('area_info', constants.AREA_INFO_EXPIRES_SECONDS, json.dumps(data))
        except Exception as e:
            logging.error(e)

        self.write(dict(errno=RET.OK, errmsg='OK', data=data))
Ejemplo n.º 12
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        order_id = self.json_args.get('order_id')
        comment = self.json_args.get('comment')

        # 验证参数
        self.check_args(order_id, comment)

        # 更新数据库
        ih_order_info = ihome_model('ih_order_info')

        try:
            self.db.query(ih_order_info).filter(
                ih_order_info.oi_user_id == user_id,
                ih_order_info.oi_order_id == order_id,
                ih_order_info.oi_status == 3).update(
                    dict(oi_comment=comment, oi_status=4))
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR,
                                   errmsg='update data error'))

        # 同步更新redis中的房屋评论信息,此处的策略是直接删除redis缓存中的该房屋数据
        try:
            ret = self.db.query(ih_order_info.oi_house_id).\
                query(ih_order_info.oi_order_id == order_id).first()

            if ret:
                try:
                    self.redis.delete('house_detail_%s' % ret.oi_house_id)
                except Exception as e:
                    logging.error(e)
        except Exception as e:
            logging.error(e)

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK'))
Ejemplo n.º 13
0
    def get(self, *args, **kwargs):
        # 获取参数
        house_id = self.get_argument('house_id')

        # 获取当前登录用户user_id
        self.get_current_user()
        user_id = self.session.data.get('user_id')

        # 验证参数
        self.check_args(house_id)

        # 从redisz中取出数据
        try:
            ret = self.redis.get('house_detail_%s' % house_id)
        except Exception as e:
            logging.error(e)
            ret = None
        if ret:
            logging.info("hit redis")
            logging.debug(ret)
            return self.write('{"errno":%s,"user_id":%s,"errmsg":"OK","data":%s}'
                              % (RET.OK, user_id, ret))

        # 数据库中取数据
        ih_house_info = ihome_model('ih_house_info')
        ih_user_profile = ihome_model('ih_user_profile')
        ih_area_info = ihome_model('ih_area_info')
        ih_house_facility = ihome_model('ih_house_facility')
        ih_house_image = ihome_model('ih_house_image')
        ih_order_info = ihome_model('ih_order_info')
        # 查询房屋基本信息
        try:
            ret = self.db.query(ih_house_info.hi_house_id,
                                ih_house_info.hi_user_id,
                                ih_house_info.hi_title,
                                ih_house_info.hi_price,
                                ih_house_info.hi_ctime,
                                ih_area_info.ai_name,
                                ih_user_profile.up_avatar,
                                ih_user_profile.up_name,
                                ih_house_info.hi_address,
                                ih_house_info.hi_room_count,
                                ih_house_info.hi_acreage,
                                ih_house_info.hi_house_unit,
                                ih_house_info.hi_capacity,
                                ih_house_info.hi_beds,
                                ih_house_info.hi_deposit,
                                ih_house_info.hi_min_days,
                                ih_house_info.hi_max_days,
                                ). \
                filter(ih_house_info.hi_house_id == house_id,
                       ih_house_info.hi_user_id == ih_user_profile.up_user_id,
                       ih_house_info.hi_area_id == ih_area_info.ai_area_id,
                       ).first()
        except Exception as e:
            logging.error(e)
            ret = None
        if not ret:
            return self.write(dict(errno=RET.DBERR, errmsg='查询数据库出错'))

        data = dict(
            price=ret.hi_price,
            title=ret.hi_title,
            user_avatar=config.image_url_prefix + ret.up_avatar if ret.up_avatar else '',
            user_id=ret.hi_user_id,
            user_name=ret.up_name,
            address=ret.hi_address,
            room_count=ret.hi_room_count,
            acreage=ret.hi_acreage,
            unit=ret.hi_house_unit,
            capacity=ret.hi_capacity,
            beds=ret.hi_beds,
            deposit=ret.hi_deposit,
            min_days=ret.hi_min_days,
            max_days=ret.hi_max_days,
        )
        # 查询房屋图片信息
        try:
            ret = self.db.query(ih_house_image.hi_url).\
                filter(ih_house_image.hi_house_id == house_id).all()
        except Exception as e:
            logging.error(e)
            ret = []
        img_list = []
        if ret:
            img_list = map(lambda x: config.image_url_prefix + str(x.hi_url), ret)
        data['images'] = img_list
        # 查询房屋设施信息
        try:
            ret = self.db.query(ih_house_facility.hf_facility_id).\
                filter(ih_house_facility.hf_house_id == house_id).all()
        except Exception as e:
            logging.error(e)
            ret = []
        facilities = []
        if ret:
            # 查询结果为[(1,), (2,), (3,), (9,), (13,), (14,), (15,), (21,), (22,), (23,)]
            # 转化成[1, 2, 3, 9, 13, 14, 15, 21, 22, 23]
            facilities = map(lambda x: x.hf_facility_id, ret)
        data['facilities'] = facilities

        # 查询房屋评论
        try:
            ret = self.db.query(ih_order_info.oi_comment,
                                ih_order_info.oi_utime,
                                ih_user_profile.up_name,
                                ih_user_profile.up_mobile).\
                filter(ih_order_info.oi_house_id == house_id,
                       ih_order_info.oi_status == 4,
                       ih_order_info.oi_user_id == ih_user_profile.up_user_id).all()
        except Exception as e:
            logging.error(e)
            ret = []
        comments = []
        if ret:
            for i in ret:
                item = dict(
                    user_name=i.up_name if i.up_name != i.up_mobile else '匿名用户',
                    ctime=datetime.datetime.strftime(i.oi_utime, '%Y-%m-%d %H:%M:%S'),
                    content=i.oi_comment
                )
                comments.append(item)
        data['comments'] = comments
        print data
        # 存入redis缓存
        try:
            self.redis.setex('house_detail_%s' % house_id, constants.HOUSE_DETAIL_EXPIRES_SECONDS, json.dumps(data))
        except Exception as e:
            logging.error(e)

        # 返回结果
        self.write(dict(errno=RET.OK, errmsg='OK', user_id=user_id, data=data))
Ejemplo n.º 14
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        # user_id = 10005
        title = self.json_args.get('title')
        price = self.json_args.get('price')
        area_id = self.json_args.get('area_id')
        address = self.json_args.get('address')
        room_count = self.json_args.get('room_count')
        acreage = self.json_args.get('acreage')
        unit = self.json_args.get('unit')
        capacity = self.json_args.get('capacity')
        beds = self.json_args.get('beds')
        deposit = self.json_args.get('deposit')
        min_days = self.json_args.get('min_days')
        max_days = self.json_args.get('max_days')
        facility = self.json_args.get('facility')

        # 验证参数
        self.check_args(title, price, area_id, address,
                        room_count, acreage, unit, capacity,
                        beds, deposit, min_days, max_days, facility)
        try:
            price = int(price)*100
            deposit = int(deposit)*100
            capacity = int(capacity)
            room_count = int(room_count)
            acreage = int(acreage)
            min_days = int(min_days)
            max_days = int(max_days)
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数错误'))

        # 数据库操作
        ih_house_info = ihome_model('ih_house_info')
        ih_house_facility = ihome_model('ih_house_facility')
        item = dict(
            hi_user_id=user_id,
            hi_title=title,
            hi_price=price,
            hi_area_id=area_id,
            hi_address=address,
            hi_room_count=room_count,
            hi_acreage=acreage,
            hi_house_unit=unit,
            hi_capacity=capacity,
            hi_beds=beds,
            hi_deposit=deposit,
            hi_min_days=min_days,
            hi_max_days=max_days,
        )
        try:
            res = self.db.execute(ih_house_info.__table__.insert(), item)
            fac = []
            for i in facility:
                tem = dict(
                    hf_house_id=res.lastrowid,
                    hf_facility_id=i
                )
                fac.append(tem)
            self.db.execute(ih_house_facility.__table__.insert(), fac)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='save data error'))

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='ok', house_id=res.lastrowid))
Ejemplo n.º 15
0
    def get(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')

        # 获取角色
        role = self.get_argument('role')

        # 检测参数
        self.check_args(role)
        # 角色必须为房东或房客
        if role not in ['custom', 'landlord']:
            return self.write(dict(errno=RET.PARAMERR, errmsg='参数有误'))

        # 查询数据库
        ih_order_info = ihome_model('ih_order_info')
        ih_house_info = ihome_model('ih_house_info')
        try:
            # 角色是用户
            if role == 'custom':
                ret = self.db.query(
                    ih_order_info.oi_order_id,
                    ih_order_info.oi_house_id,
                    ih_order_info.oi_ctime,
                    ih_order_info.oi_begin_date,
                    ih_order_info.oi_end_date,
                    ih_order_info.oi_comment,
                    ih_order_info.oi_days,
                    ih_order_info.oi_status,
                    ih_order_info.oi_amount,
                    ih_house_info.hi_title,
                    ih_house_info.hi_index_image_url,
                ).filter(
                    ih_order_info.oi_user_id == user_id,
                    ih_order_info.oi_house_id ==
                    ih_house_info.hi_house_id).all()
            else:
                # 角色是房东
                ret = self.db.query(
                    ih_order_info.oi_order_id,
                    ih_order_info.oi_house_id,
                    ih_order_info.oi_ctime,
                    ih_order_info.oi_begin_date,
                    ih_order_info.oi_end_date,
                    ih_order_info.oi_comment,
                    ih_order_info.oi_days,
                    ih_order_info.oi_status,
                    ih_order_info.oi_amount,
                    ih_house_info.hi_title,
                    ih_house_info.hi_index_image_url,
                ).filter(
                    ih_house_info.hi_user_id == user_id,
                    ih_order_info.oi_house_id ==
                    ih_house_info.hi_house_id).all()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='查询出错'))

        # 构建返回数据
        order_list = []
        if ret:
            for i in ret:
                item = dict(order_id=i.oi_order_id,
                            status=i.oi_status,
                            img_url=config.image_url_prefix +
                            str(i.hi_index_image_url),
                            title=i.hi_title,
                            ctime=i.oi_ctime.strftime('%Y-%m-%d %H:%M:%S'),
                            start_date=i.oi_begin_date.strftime('%Y-%m-%d'),
                            end_date=i.oi_end_date.strftime('%Y-%m-%d'),
                            amount=i.oi_amount,
                            days=i.oi_days,
                            comment=i.oi_comment)
                order_list.append(item)
        logging.debug(order_list)

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK', orders=order_list))
Ejemplo n.º 16
0
    def post(self, *args, **kwargs):
        # 获取参数
        user_id = self.session.data.get('user_id')
        house_id = self.json_args.get('house_id')
        start_date = self.json_args.get('start_date')
        end_date = self.json_args.get('end_date')

        # 验证参数
        self.check_args(user_id, house_id, start_date, end_date)
        # 对时间进行格式化
        start_date = datetime.strptime(start_date, '%Y-%m-%d')
        end_date = datetime.strptime(end_date, '%Y-%m-%d')
        # 开始日期不能大于结束日期
        days = int((end_date - start_date).days) + 1
        if days <= 0:
            return self.write(dict(errno=RET.PARAMERR, errmsg='日期格式错误'))

        ih_house_info = ihome_model('ih_house_info')
        ih_order_info = ihome_model('ih_order_info')

        # 判断下单是否为房东本人,如果是房东拒绝操作
        try:
            ret = self.db.query(ih_house_info.hi_user_id,
                                ih_house_info.hi_price).\
                filter(ih_house_info.hi_house_id == house_id).first()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='查询出错'))
        # 没有房屋数据
        if not ret:
            return self.write(dict(errno=RET.DATAERR, errmsg='没有数据'))
        # 预定房间是房东本人
        if ret.hi_user_id == user_id:
            return self.write(dict(errno=RET.ROLEERR, errmsg='拒绝此操作'))

        house_price = ret.hi_price

        # 判断日期内是否有订单
        # 查询数据库里当前房屋此时间段有没有订单
        try:
            ret = self.db.query(func.count('*')).filter(
                ih_order_info.oi_house_id == house_id,
                ih_order_info.oi_begin_date < end_date,
                ih_order_info.oi_end_date > start_date).scalar()
        except Exception as e:
            logging.error(e)
            return self.write({
                "errcode": RET.DBERR,
                "errmsg": "get date error"
            })
        else:
            if ret:
                return self.write(dict(errno=RET.DATAERR, errmsg='房子已租出'))

        # 更新数据
        item = dict(oi_user_id=user_id,
                    oi_house_id=house_id,
                    oi_begin_date=start_date,
                    oi_end_date=end_date,
                    oi_days=days,
                    oi_house_price=house_price,
                    oi_amount=days * house_price)
        try:
            self.db.execute(ih_order_info.__table__.insert(), item)
            self.db.commit()
        except Exception as e:
            logging.error(e)
            return self.write(dict(errno=RET.DBERR, errmsg='生成订单失败'))

        # 调用支付接口

        # 返回数据
        self.write(dict(errno=RET.OK, errmsg='OK'))