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
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
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)
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)
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)
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)