def get(self): try: args = self.parser.parse_args() # 获取城市参数 city = args.get('city') # 获取区域参数 district = args.get('district') # 获取排序参数(综合排序,按评分排序) sort = args.get('sort') # 获取当前城市的影院数据 query = Cinema.query.filter(Cinema.city == city) if district: # 判断是否有选中区域 query = query.filter(Cinema.district == district) # 影院评分排序 if sort == 1: # 降序 query = query.order_by(Cinema.score.desc()) elif sort == 2: # 升序 query.order_by(Cinema.score.asc()) cinemas = query.all() return to_response_success(data=cinemas, fields=CinemasFields.result_fields) except Exception as e: print(e) return to_response_error()
def get(self): try: # 查询轮播表信息 banners = Banner.query.filter(Banner.is_delete is False).order_by( Banner.order).all() hot_movies = Movie.query.filter(Movie.flag == 1).order_by( Movie.open_day).limit(5).offset(0).all() # hot_movies = Movies.query.filter(Movies.flag == 1).order_by(Movies.open_day).all() ready_movies = Movie.query.filter(Movie.flag == 2).order_by( Movie.open_day).limit(5).offset(0).all() # ready_movies = Movies.query.filter(Movies.flag == 2).order_by(Movies.open_day).all() hot_count = Movie.query.filter(Movie.flag == 1).count() ready_count = Movie.query.filter(Movie.flag == 2).count() get_score(hot_movies) get_score(ready_movies) data_fields = { 'banners': banners, 'hot_count': hot_count, 'ready_count': ready_count, 'hot_movies': hot_movies, 'ready_movies': ready_movies, } return to_response_success(data=data_fields, fields=MainMoviesFields.result_fields) except Exception as e: return to_response_error()
def get(self): try: city = self.parser.parse_args().get('city') city = Area.query.filter(Area.short_name == city, Area.level == 2).first() districts = Area.query.filter(Area.parent_id == city.aid, Area.level == 3).all() return to_response_success(districts, fields=CinemaAreaFields.result_fields) except: return to_response_error()
def post(self): args = self.parser.parse_args() uid = args.get('uid') movie_id = args.get('movie_id') hs_id = args.get('hs_id') seat_ids = args.get('seat_ids') ss_id = args.get('ss_id') try: # db.session.begin() # 查询座位是否可选 seats = Seats.query.filter(Seats.sid.in_(seat_ids)).all() if is_choose(seats): # 锁定座位 for seat in seats: seat.is_choose = False db.session.add_all(seats) # 生成订单号 no = product_code() # 查询票价 hs = HallScheduling.query.get(hs_id) # 计算总金额 total = hs.current_price * 2 # 生成订单 order = Order(no=no, number=2, total=total, status=1, movie_id=movie_id, hs_id=hs_id, cinema_id=1, ss_id=1, seat_id=1) # 提交订单 db.session.add(order) db.session.commit() return to_response_success( data=no, fields=OrderSuccessFields.result_fields) else: return to_response_error(status='-1', msg='座位已经被选了') except: db.session.rollback() return '失败'
def get(self): try: rantings = Rating.query.with_entities( Rating.movie_id, func.round(func.avg(Rating.score), 1).label('score'), Movie.show_name, Movie.image) \ .join(Movie, Movie.id == Rating.movie_id) \ .group_by(Rating.movie_id) \ .order_by(desc('score')) \ .limit(5).offset(0).all() data = [{ 'movie_id': ranting[0], 'score': ranting[1], 'name': ranting[2], 'image': ranting[3] } for ranting in rantings] return to_response_success(data=data, fields=MainRatingFields.result_fields) except Exception as e: return to_response_error()
def get(self): try: first = Area.query.filter(Area.status == 1, Area.level == 2) \ .with_entities(Area.first) \ .group_by(Area.first) \ .order_by(Area.first) \ .all() initial = [] for f in first: if f.first is not None: areas = Area.query.filter(Area.status == 1, Area.level == 2, Area.first == f.first).all() initial.append({'first': f.first, 'areas': areas}) return to_response_success(data=initial, fields=MainAreaFields.result_fields) except Exception as e: return to_response_error()
def get(self): cid = self.parser.parse_args().get('cid') hs_list = HallScheduling.query.filter( HallScheduling.cinema_id == cid).all() # for hs in hs_list: # print(hs.cinema.name, '\n', hs.movie.show_name, '\n', hs.hall.name) movies = [] for hs in hs_list: if hs.movie not in movies: movies.append(hs.movie) data = { 'cinema': hs_list[0].cinema, 'movies': movies, 'movie': hs_list[0].movie, 'hs_list': hs_list } return to_response_success(data=data, fields=CinemaDetailFields.result_fields)
def get(self): try: hs_id = self.parser.parse_args().get('hs_id') hs = HallScheduling.query.get(hs_id) seats = [seat.seat for seat in hs.ss_list] data_fields = { 'seats': seats, 'movie': hs.movie, 'hall': hs.hall, 'hall_scheduling': hs, } return to_response_success(data=data_fields, fields=CinemaSeatsFields.result_fields) except Exception as e: print(e) return to_response_error()
def get(self): try: goods = Goods.query.all() args = self.parse.parse_args() page = args.get('page') size = args.get('size') flag = 1 if args.get('flag') == 1 else 2 pagination = Movie.query.filter(Movie.flag == flag).paginate( page=page, per_page=size, error_out=False) get_score(pagination.items) data_fields = { 'pagination': pagination, 'movies': pagination.items, } return to_response_success(data=data_fields, fields=MoviesFields.result_fields) except Exception as e: return to_response_error()