Beispiel #1
0
def update():
    flightId = request.form.get("flightId")
    if (flightId is None):
        return ResData.paramEmpty(flightId)
    flight = Flight.query.filter(Flight.flightId == flightId).first()

    startingPlace = request.form.get('startingPlace')
    endPlace = request.form.get('endPlace')
    startTime = request.form.get('startTime')
    endTime = request.form.get('endTime')
    flightNumber = request.form.get('flightNumber')
    price = request.form.get('price')
    flightName = request.form.get('flightName')
    number = request.form.get('number')

    flight.startingPlace = startingPlace
    flight.endPlace = endPlace
    flight.startTime = startTime
    flight.endTime = endTime
    flight.flightNumber = flightNumber
    flight.price = price
    flight.flightName = flightName
    flight.number = number

    db.session.add(flight)
    db.session.commit()
    return ResData.success(None)
Beispiel #2
0
def update():
    userName = request.cookies.get('username')
    #userName=request.form.get('userName')
    password = request.form.get('password')
    nickName = request.form.get('nickName')
    sex = request.form.get('sex')
    location = request.form.get('location')
    pic = request.form.get('pic')
    type = request.form.get('type')

    user = User.query.filter(User.userName == userName).first()
    if (user is None):
        return ResData.fail()
    if (password is not None):
        user.password = password
    if (nickName is not None):
        user.nickName = nickName
    if (sex is not None):
        user.sex = sex
    if (location is not None):
        user.location = location
    if (pic is not None):
        user.pic = pic
    if (type is not None):
        user.type = type
    db.session.add(user)
    db.session.commit()
    return ResData.success(None)
Beispiel #3
0
def update():
    hotelId = request.form.get("hotelId")
    if (hotelId is None):
        return ResData.paramEmpty(hotelId)
    hotel = Hotel.query.filter(Hotel.hotelId == hotelId).first()

    address = request.form.get('address')
    hotelName = request.form.get('hotelName')
    price = request.form.get('price')
    score = request.form.get('score')
    number = request.form.get('number')
    hotelId = request.form.get('hotelId')
    introduction = request.form.get('introduction')
    pic = request.form.get('pic')

    hotel.address = address
    hotel.hotelName = hotelName
    hotel.price = price
    hotel.score = score
    hotel.number = number
    hotel.hotelId = hotelId
    hotel.introduction = introduction
    hotel.pic = pic

    db.session.add(hotel)
    db.session.commit()
    return ResData.success(None)
Beispiel #4
0
def delete():
    hotelId = request.form.get('hotelId')
    if (hotelId is None):
        return ResData.paramEmpty(hotelId)
    hotel = Hotel.query.filter(Hotel.hotelId == hotelId).first()
    db.session.delete(hotel)
    db.session.commit()
    return ResData.success(None)
Beispiel #5
0
def delete():
    flightId = request.form.get('flightId')
    if (flightId is None):
        return ResData.paramEmpty(flightId)
    flight = Flight.query.filter(Flight.flightId == flightId).first()
    db.session.delete(flight)
    db.session.commit()
    return ResData.success(None)
Beispiel #6
0
def delete():
    postRecordId = request.form.get('postRecordId')
    if (postRecordId is None):
        return ResData.paramEmpty(postRecordId)
    postRecord = PostRecord.query.filter(
        PostRecord.postId == postRecordId).first()
    db.session.delete(postRecord)
    db.session.commit()
    return ResData.success(None)
Beispiel #7
0
def login():
    userName = request.form.get('userName')
    password = request.form.get('password')
    user = User.query.filter(User.userName == userName,
                             User.password == password).first()
    if (user is None):
        return ResData.fail(userName)
    res = make_response(ResData.success(user.to_json()))
    res.set_cookie('username', userName)
    return res
Beispiel #8
0
def queryAll():
    userName = request.cookies.get('username')
    if(userName is None):
        return ResData.needLogin(userName)
    coupons = Coupon.query.filter(Coupon.username==userName).all()
    couponList = []
    for one in coupons:
        couponList.append(one.to_json())
    couponsJson = {"coupons": couponList}
    res = make_response(ResData.success(couponsJson))
    return res
Beispiel #9
0
def queryByPostRecordId():
    postRecordId = request.form.get('postRecordId')
    if (postRecordId is None):
        return ResData.paramEmpty(postRecordId)
    postRecord = PostRecord.query.filter(
        PostRecord.postId == postRecordId).first()
    res = postRecord.to_json()
    replys = querReplyByPostRecordId(postRecordId)
    postRecordList = []
    for one in replys:
        postRecordList.append(one.to_json())
    res["postRecords"] = postRecordList
    return make_response(ResData.success(res))
Beispiel #10
0
def queryUserBuyRecord():
    username = request.cookies.get('username')
    userBuyRecords = UserBuyRecord.query.filter(
        UserBuyRecord.userName == username).all()
    hotelList = []
    landscapeList = []
    flightList = []
    for userBuyRecord in userBuyRecords:
        if (operator.eq(userBuyRecord.productType, 'hotel')):
            hotels = Hotel.query.filter(
                Hotel.hotelId == userBuyRecord.productId).all()
            for hotel in hotels:
                hotelList.append(hotel.to_json())
        if (operator.eq(userBuyRecord.productType, 'landscape')):
            landscapes = Landscape.query.filter(
                Landscape.landscapeId == userBuyRecord.productId).all()
            for landscape in landscapes:
                landscapeList.append(landscape.to_json())
        if (operator.eq(userBuyRecord.productType, 'flight')):
            flights = Flight.query.filter(
                Flight.flightId == userBuyRecord.productId).all()
            for flight in flights:
                flightList.append(flight.to_json())
    resultJson = {
        "landscapes": landscapeList,
        "flights": flightList,
        "hotels": hotelList
    }
    return make_response(ResData.success(resultJson))
Beispiel #11
0
def raiders():
    username = request.cookies.get('username')
    user = User.query.filter(User.userName == username).first()
    userlocation = user.location.split('-', 2)
    landscapes = Landscape.query.filter().all()
    landscapeslist = []
    for one in landscapes:
        addresslist = one.address.split('-', 2)
        if (addresslist[0] == userlocation[0]
                and addresslist[1] == userlocation[1]):
            landscapeslist.append(one.to_json())

    flights = Flight.query.filter().all()
    flightList = []
    for one in flights:
        endPlacelist = one.endPlace.split('-', 2)
        if (endPlacelist[0] == userlocation[0]
                and endPlacelist[1] == userlocation[1]):
            flightList.append(one.to_json())

    hotels = Hotel.query.filter().all()
    hotellist = []
    for one in hotels:
        addresslist = one.address.split('-', 2)
        if (addresslist[0] == userlocation[0]
                and addresslist[1] == userlocation[1]):
            hotellist.append(one.to_json())

    resultJson = {
        "landscapes": landscapeslist,
        "flights": flightList,
        "hotels": hotellist
    }
    return make_response(ResData.success(resultJson))
Beispiel #12
0
def search():
    userName = request.cookies.get('username')
    if(userName is None):
        return ResData.needLogin(userName)
    couponId = request.form.get('couponId')#优惠券Id

    couponByUser=Coupon.query.filter(Coupon.couponId == couponId,Coupon.username == userName).first()
    if(couponByUser != None):
        res = {"code": "333", "data": ""}
        return jsonify(res)
    coupon = Coupon.query.filter(Coupon.couponId == couponId).first()
    coupon.username=userName
    db.session.add(coupon)
    db.session.commit()
    res = make_response(ResData.success(""))
    return res
Beispiel #13
0
def insert():
    userName = request.cookies.get('username')
    if (userName is None):
        return ResData.needLogin(userName)
    postContent = request.form.get('postContent')
    postTitle = request.form.get('postTitle')
    postPic = request.form.get('postPic')

    postRecord = PostRecord()
    postRecord.postContent = postContent
    postRecord.postTitle = postTitle
    postRecord.postPic = postPic
    postRecord.postBy = userName
    postRecord.postTime = Utils.getCurrentTimeStr("")
    db.session.add(postRecord)
    db.session.commit()
    return ResData.success(None)
Beispiel #14
0
def queryAll():
    flights = Flight.query.filter().all()
    flightList = []
    for one in flights:
        flightList.append(one.to_json())
    flightsJson = {"flights": flightList}
    res = make_response(ResData.success(flightsJson))
    return res
Beispiel #15
0
def queryAll():
    hotels = Hotel.query.filter().all()
    hotellist = []
    for one in hotels:
        hotellist.append(one.to_json())
    flightsJson = {"hotels": hotellist}
    res = make_response(ResData.success(flightsJson))
    return res
Beispiel #16
0
def search():
    address = request.form.get('address')
    hotels = Hotel.query.filter(Hotel.address == address).all()
    flightList = []
    for one in hotels:
        flightList.append(one.to_json())
    flightsJson = {"hotels": flightList}
    res = make_response(ResData.success(flightsJson))
    return res
Beispiel #17
0
def buy():
    flightId = request.form.get('flightId')
    userName = request.cookies.get('username')
    if (userName is None):
        return ResData.needLogin(flightId)
    if (flightId is None):
        return ResData.paramEmpty(flightId)
    flight = Flight.query.filter(Flight.flightId == flightId).first()
    flight.number = flight.number - 1

    userBuyRecord = UserBuyRecord()
    userBuyRecord.productId = flightId
    userBuyRecord.productType = "flight"
    userBuyRecord.userName = userName

    db.session.add(flight)
    db.session.add(userBuyRecord)
    db.session.commit()
    return ResData.success(None)
Beispiel #18
0
def reply():
    userName = request.cookies.get('username')
    if (userName is None):
        return ResData.needLogin(userName)

    replyContent = request.form.get('replyContent')  #回复内容
    replyPostId = request.form.get('replyPostId')  #回复帖子的id
    postPic = request.form.get('postPic')  #回复的图片
    replyTime = Utils.getCurrentTimeStr("")

    reply = Reply()
    reply.replyBy = userName
    reply.replyContent = replyContent
    reply.replyPostId = replyPostId
    reply.postPic = postPic
    reply.replyTime = replyTime
    db.session.add(reply)
    db.session.commit()
    return ResData.success(None)
Beispiel #19
0
def buy():
    userName = request.cookies.get('username')
    if (userName is None):
        return ResData.needLogin(userName)
    hotelId = request.form.get('hotelId')
    if (hotelId is None):
        return ResData.paramEmpty(hotelId)
    hotel = Hotel.query.filter(Hotel.hotelId == hotelId).first()
    Hotel.number = Hotel.number - 1

    userBuyRecord = UserBuyRecord()
    userBuyRecord.productId = hotelId
    userBuyRecord.productType = "hotel"
    userBuyRecord.userName = userName

    db.session.add(hotel)
    db.session.add(userBuyRecord)
    db.session.commit()
    return ResData.success(None)
Beispiel #20
0
def queryAll():
    postRecords = PostRecord.query.all()
    postRecordList = []
    for one in postRecords:
        count = querReplyCountByPostRecordId(one.postId)
        post = one.to_json()
        post['replyCount'] = count
        postRecordList.append(post)
    postRecordsJson = {"postRecords": postRecordList}
    res = make_response(ResData.success(postRecordsJson))
    return res
Beispiel #21
0
def initSql():
    PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p)
                                     )
    p = os.path.realpath(__file__)
    cur_path = os.path.dirname(os.path.realpath(__file__))
    print(cur_path)
    path = cur_path + '\sql\init.sql'
    f = open(path, "r", encoding='UTF-8')
    txt = f.read()
    sql = "INSERT INTO `post_record` (`postBy`, `postContent`, `postTitle`, `postTime`, `postPic`) VALUES ('admin', '官方网址:http://yuilibrary.com/YUI Editor 是雅虎的 YUI 包中的一个可视化HTML编辑器组件。', '土耳其三日游', '2019-05-12 14:45:01', NULL);"
    data_query = db.session.execute(sql)
    db.session.commit()
    return ResData.success(None)
Beispiel #22
0
def search():
    startingPlace = request.form.get('startingPlace')
    endPlace = request.form.get('endPlace')
    startTime = request.form.get('startTime')
    flights = Flight.query.filter(Flight.startingPlace == startingPlace,
                                  Flight.endPlace == endPlace,
                                  Flight.startTime == startTime).all()
    flightList = []
    for one in flights:
        flightList.append(one.to_json())
    flightsJson = {"flights": flightList}
    res = make_response(ResData.success(flightsJson))
    return res
Beispiel #23
0
def send():
    username = request.cookies.get('username')
    user = User.query.filter(User.userName == username).first()
    userlocation = user.location.split('-', 2)
    landscapes = Landscape.query.filter().all()
    landscapeslist = []
    for one in landscapes:
        addresslist = one.address.split('-', 2)
        if (addresslist[0] == userlocation[0]
                and addresslist[1] == userlocation[1]):
            landscapeslist.append(one.to_json())
    landscapesJson = {"landscapes": landscapeslist}
    return make_response(ResData.success(landscapesJson))
Beispiel #24
0
def insert():
    address = request.form.get('address')
    hotelName = request.form.get('hotelName')
    price = request.form.get('price')
    score = request.form.get('score')
    number = request.form.get('number')
    introduction = request.form.get('introduction')
    pic = request.form.get('pic')
    hotel = Hotel()
    hotel.address = address
    hotel.hotelName = hotelName
    hotel.price = price
    hotel.score = score
    hotel.number = number
    hotel.introduction = introduction
    hotel.pic = pic
    db.session.add(hotel)
    db.session.commit()
    return ResData.success(None)
Beispiel #25
0
def insert():
    startingPlace = request.form.get('startingPlace')
    endPlace = request.form.get('endPlace')
    startTime = request.form.get('startTime')
    endTime = request.form.get('endTime')
    flightNumber = request.form.get('flightNumber')
    price = request.form.get('price')
    flightName = request.form.get('flightName')
    number = request.form.get('number')
    flight = Flight()
    flight.startingPlace = startingPlace
    flight.endPlace = endPlace
    flight.startTime = startTime
    flight.endTime = endTime
    flight.flightNumber = flightNumber
    flight.price = price
    flight.flightName = flightName
    flight.number = number
    db.session.add(flight)
    db.session.commit()
    return ResData.success(None)
Beispiel #26
0
def queryByCouponId():
    couponId = request.form.get('couponId')#优惠券Id
    coupon = Coupon.query.filter(Coupon.couponId==couponId).first()
    return ResData.success(coupon.to_json())