示例#1
0
def house(page=1):
    # 返回格式
    result = {"code": 10000, "value": "", "msg": ""}

    if page <= 0:
        result = {"code": -10000, "value": "", "msg": "page 必须大于0"}
        return result

    sql = """select r.id,area, sha_identity,title,price,r.phone,r.post_time,start_time,end_time,house_name,position,
pre_price,floor,total_floor,has_kitchen_bath,five_year,lobby,live_room,orientation,
r.type,mark,name,u.type as utype,avatar,verify,company_name,company_addr  from room r left join user u on 
r.phone = u.phone ORDER BY r.`post_time` DESC  LIMIT {page}, {offset}""".format(
        page=(page - 1) * 10, offset=10)

    rooms = dbManager.exec_sql(sql)

    for room in rooms:
        # print(room)
        obj_room = Room()
        util.dict2obj(room, obj_room)
        # print(obj_room.phone)
        image_sql = "select name,path from image i where i.room_sha_identity ='{room_sha_identity}'".format(
            room_sha_identity=obj_room.sha_identity)

        # print(user_sql)
        if len(obj_room.title) > 32:
            room['title'] = obj_room.title[:32] + '...'

        room['post_time'] = obj_room.post_time.strftime('%Y-%m-%d')
        room['start_time'] = obj_room.start_time.strftime('%Y-%m-%d')
        room['end_time'] = obj_room.end_time.strftime('%Y-%m-%d')

        ret = dbManager.exec_sql(image_sql)
        #
        # print(ret)
        #
        room['image'] = ret

    result["value"] = rooms
    result["msg"] = "获取数据成功"

    return result
示例#2
0
def get_room_detail(sha_identity):
    result = {"code": 10000, "value": "", "msg": ""}
    sql = """
    select r.id,area, sha_identity,title,price,r.phone,r.post_time,start_time,end_time,house_name,position,
pre_price,floor,total_floor,has_kitchen_bath,five_year,lobby,live_room,orientation,
r.type,mark,name,u.type as utype,avatar,verify,company_name,company_addr  from room r left join user u on 
r.phone = u.phone where sha_identity = '{sha_identity}'
    """.format(sha_identity=sha_identity)

    # print(sql)

    room = dbManager.exec_sql(sql)[0]

    # print(room[0])

    obj_room = Room()
    util.dict2obj(room, obj_room)

    image_sql = "select name from image i where i.room_sha_identity ='{room_sha_identity}'".format(
        room_sha_identity=obj_room.sha_identity)

    room['post_time'] = obj_room.post_time.strftime('%Y-%m-%d')
    room['start_time'] = obj_room.start_time.strftime('%Y-%m-%d')
    room['end_time'] = obj_room.end_time.strftime('%Y-%m-%d')

    if obj_room.company_name != None and len(obj_room.company_name) > 10:
        room['company_name'] = obj_room.company_name[:10] + '...'

    # print("room['company_name']:" + room['company_name'])
    if room['company_name'] == None:
        room['company_name'] = ''

    ret = dbManager.exec_sql(image_sql)

    room['image'] = ret

    # print(room)

    result["value"] = room
    result["msg"] = "获取数据成功"

    return result
示例#3
0
def get_rent_house(sql, page):
    print(sql)
    result = {"code": 10000, "value": "", "msg": ""}

    if page <= 0:
        result = {"code": -10000, "value": "", "msg": "page 必须大于0"}
        return result

    rooms = dbManager.exec_sql(sql)

    for room in rooms:
        # print(room)
        obj_room = Room()
        util.dict2obj(room, obj_room)
        # print(obj_room.phone)
        image_sql = "select name from image i where i.room_sha_identity ='{room_sha_identity}'".format(
            room_sha_identity=obj_room.sha_identity)

        # print(user_sql)
        if len(obj_room.title) > 32:
            room['title'] = obj_room.title[:32] + '...'

        room['post_time'] = obj_room.post_time.strftime('%Y-%m-%d')
        room['start_time'] = obj_room.start_time.strftime('%Y-%m-%d')
        room['end_time'] = obj_room.end_time.strftime('%Y-%m-%d')

        # print("room['company_name']:"+room['company_name'])
        if room['company_name'] == None:
            room['company_name'] = ''

        ret = dbManager.exec_sql(image_sql)
        #
        # print(ret)
        #
        room['image'] = ret

    result["value"] = rooms
    result["msg"] = "获取数据成功"

    return result