Exemple #1
0
 def get(self):
     args = self.parser.parse_args()
     flag = 1 if args.get('flag') == 1 else 2
     pagination = Movie.query.filter(Movie.flag == flag).paginate(
         page=args.get('page'), error_out=False)
     data = {'movies': pagination.items, 'pagination': pagination}
     return to_response_success(data=data,
                                fields=MoviesFields.result_fields)
Exemple #2
0
 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=AreaFields.result_fields)
     except:
         return to_response_error()
Exemple #3
0
 def get(self):
     try:
         cid = self.parser.parse_args().get('cid')
         hs_list = HallScheduling.query.filter(
             HallScheduling.cinema_id == cid).all()
         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)
     except Exception as e:
         return to_response_error()
Exemple #4
0
    def get(self):
        # SELECT  AVG(score) avg
        # from  rating
        # group by  movie_id
        # oder by  avg
        #    分组 统计
        # 确定表
        #  rating 表    评分
        #  movie  表     电影id  电影图片  电影的名称
        # 确定关联字段
        # id = movie_id

        # SELECT  m.id ,m.show_name,m.image,round(avg(r.score)) avg
        # FROM movie m ,rating r
        # where m.id = r.movie_id
        # group by  r.movie.id
        # order by  avg  desc

        try:
            # [()]
            # 四舍五入round()
            # 截取 truncate
            # [()]
            ratings = Rating.query. \
                with_entities(Rating.movie_id,
                              func.round(func.avg(Rating.score).label('score'), 1)
                              , Movie.image, Movie.show_name) \
                .join(Movie, Movie.id == Rating.movie_id) \
                .group_by(Rating.movie_id) \
                .order_by(desc('score')) \
                .limit(5).offset(0).all()

            data = [{
                'movie_id': rating[0],
                'score': rating[1],
                'image': rating[2],
                'show_name': rating[3],
            } for rating in ratings]
            return to_response_success(data=data,
                                       fields=RatingFields.result_fields)
        except Exception as e:
            return to_response_error()
Exemple #5
0
 def post(self):
     uid = self.parser.parse_args().get('uid')
     movie_id = self.parser.parse_args().get('movie_id')
     hs_id = self.parser.parse_args().get('hs_id')
     seat_ids = self.parser.parse_args().get('seat_ids')
     #       生成订单号
     try:
         # 查询选的座位是否可以购买
         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,
                           seat_id=1,
                           ss_id=1)
             # 保存订单
             db.session.add(order)
             db.session.commit()
             return to_response_success(data=no, fields=result_fields)
         else:
             return to_response_error(status=-1, msg='座位已被选,请重新选座')
     except Exception as e:
         print(e)
         db.session.rollback()
         return ''
Exemple #6
0
 def get(self):
     result = {}
     try:
         # 查询轮播的相关信息
         banners = Banner.query.filter(Banner.is_delete is False).order_by(
             Banner.order.desc()).all()
         hot_movies = Movie.query.filter(Movie.flag == 1).order_by(
             Movie.open_day).limit(5).offset(0).all()
         ready_movies = Movie.query.filter(Movie.flag == 2).order_by(
             Movie.open_day).limit(5).offset(0).all()
         hot_count = Movie.query.filter(Movie.flag == 1).count()
         ready_count = Movie.query.filter(Movie.flag == 2).count()
         data = {
             'banners': banners,
             'hot_movies': hot_movies,
             'ready_movies': ready_movies,
             'hot_count': hot_count,
             'ready_count': ready_count,
         }
         return to_response_success(data,
                                    fields=field.IndexFields.result_fields)
     except Exception as e:
         return to_response_error()
Exemple #7
0
 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 and district > 0:
             # 如果有选中区域   where  city=1988 and district= 989
             query = query.filter(Cinema.district == district)
         # 1 表示升序
         if sort == 1:
             # 降序
             query = query.order_by(Cinema.score.desc())
         elif sort == 2:
             # 表示升序
             query = query.order_by(Cinema.score.asc())
         cinemas = query.all()
         return to_response_success(cinemas,
                                    fields=CinemasFields.result_fields)
     except Exception as e:
         print(e)
         return to_response_error()
Exemple #8
0
    def get(self):
        hs_id = self.parser.parse_args().get('hs_id')
        hs = HallScheduling.query.get(hs_id)
        seats = [ss.seat for ss in hs.ss_list]
        data = {
            'seats': seats,
            'movie': hs.movie,
            'hall': hs.hall,
        }
        return to_response_success(data=data,
                                   fields=SeatOrderFields.result_fields)

        #
        def post(self):
            # 生成订单
            pass

        # 更新座位排期
        def put(self):
            pass

        # 删除座位
        def put(self):
            pass