示例#1
0
def calculateTotal(room_id):
    query = "select payer_id from room where room_id = '%d'"
    get_table = select_one(query % room_id)
    payer_id = get_table[0]

    query = "select user_id from room_list where room_id = '%d' and user_present = 1"
    get_table = select_all(query % room_id)
    user_list = list()
    query = "select sum(food_price) from user_orderlist where room_id = '%d' and user_id = '%d' group by user_id"
    for one_table in get_table:
        user_id = one_table[0]
        if payer_id == user_id:
            continue
        price = select_one(query % (room_id, user_id))
        user_price = price[0]
        user_dic = {'user_id': user_id, 'user_price': user_price}
        user_list.append(user_dic)

    list_length = len(user_list)
    i = 0
    query = "insert into total_price (giver, taker, price, room_id) values ('%d', '%d', '%d', '%d')"
    while i < list_length:
        insert(query % (user_list[i]['user_id'], payer_id, user_list[i]['user_price'], room_id))
        i+=1

    return ""
示例#2
0
def intoTheRoom(room_id, user_id):
    query1 = "update room_list set user_present = 0 where user_id = '%d' and user_present = 1"
    insert(query1 % user_id)

    query2 = "insert into room_list values('%d', '%d', 1, 0)"
    insert(query2 % (room_id, user_id))

    return ""
示例#3
0
def save_room(room_d):
    if room_d is None:
        return "Unvalid input", 404

    query = "insert into room (ROOM_ID, LOCATION_ID, CHIEF_ID, RESTAURANT_ID, ROOM_EXIST, CREATED, ROOM_PW, ROOM_TITLE, ROOM_INWON) values (ROOM_ID_SEQ.nextval, '%d', '%d', '%d', 1, SYSDATE, '%s', '%s', '%d')"
    room_d.restaurant_id = get_restaurant_id_from_name(room_d.restaurant_name)
    insert(query % (room_d.location_id, room_d.host_id, room_d.restaurant_id, room_d.room_pw, room_d.room_title, int(room_d.room_inwon)))
    #이 부분 전체적인 수정필요.

    return ""
示例#4
0
def CompleteOrder(room_id):
    query = "select room_exist from room where room_id = '%d'"
    get_table = select_one(query % room_id)
    room_exist = get_table[0]

    if(room_exist == 0):
        return None

    query = "update room set room_exist = 0 where room_id = '%d'"
    insert(query % room_id)
    return ""
示例#5
0
def set_token(time, user):
    corrent_time = str(time)
    filehash = hashlib.md5()
    h = '%s/%s/%s' % (user[3], user[4], corrent_time)
    filehash.update(h.encode('utf-8'))
    filename = filehash.hexdigest()

    response = current_app.make_response("/")
    response.set_cookie('pr_session', value=filename)

    query = "insert into pr_session values ('%d','%s', SYSDATE)"
    insert(query % (user[0], filename))

    return response
示例#6
0
def set_room_token(time, rid, rpw, uid):
    current_time = str(time)
    filehash = hashlib.md5()
    h = '%s/%s/%s/%s' % (rid, uid, rpw, current_time)
    filehash.update(h.encode('utf-8'))
    filename = filehash.hexdigest()

    response = current_app.make_response("/")
    response.set_cookie('room_session', value = filename)

    query = "insert into room_session values ('%s', '%d', '%d', SYSDATE)"
    insert(query % (filename, int(uid), int(rid)))

    return response
示例#7
0
def save_user_menu(uid, rid, request_data):
    restaurant_id = get_restaurant_id_from_roomid(rid)
    query = "insert into user_orderlist values ('%d', '%d', '%s', '%d', '%d');"
    query2 = "select food_id from pr_food where restaurant_id = '%d' and food_name = '%s'"
    query3 = "select food_price from pr_food where food_id = '%d'"
    query4 = "delete from user_orderlist where room_id = '%d' and user_id = '%d'"
    insert(query4 % (rid, uid))
    for i in range(1, request_data[0] + 1):
        food_id = select_one(query2 % (restaurant_id, request_data[i]))
        food_price = select_one(query3 % int(food_id[0]))
        insert(
            query %
            (rid, uid, request_data[i], int(food_id[0]), int(food_price[0])))

    return ""
示例#8
0
def order_ready():
    pr_session = request.cookies.get('pr_session')
    user_id = get_id_from_db(pr_session)
#유저 id와 방 id를 가지고 RoomList에서 user_ready를 1로 바꿔주면 땡
    room_session = request.cookies.get('room_session')
    room_id = get_room_id_from_session(room_session)

    query = "select user_ready from room_list where user_present = 1 and room_id = '%d' and user_id = '%d'"
    ready = select_one(query % (room_id, user_id))

    if ready[0]:
        query2 = "update room_list set user_ready = 0 where room_id = '%d' and user_id = '%d' and user_present = 1"
        insert(query2 % (room_id, user_id))
    else:
        query2 = "update room_list set user_ready = 1 where room_id = '%d' and user_id = '%d' and user_present = 1"
        insert(query2 % (room_id, user_id))

    return jsonify(results = ready[0])
示例#9
0
def selectPayer(room_id, user_id):
    query = "update room set payer_id = '%d' where room_id = '%d'"
    insert(query% (int(user_id), room_id))
    return ""
示例#10
0
def outOfTheRoom(room_id, user_id):
    query = "update room_list set user_present = 0 where room_id = '%d'and user_id = '%d'"
    query2 = "delete from user_orderlist where room_id = '%d' and user_id = '%d'"
    insert(query % (int(room_id), int(user_id)))
    insert(query2 % (room_id, user_id))
    return ""