Просмотр исходного кода

调用第三方接口获取影片场次列表

family 1 год назад
Родитель
Сommit
d9aea40620

+ 52 - 0
app/common/repositories/movie/CinemaSchedRepository.php

@@ -100,6 +100,58 @@ class CinemaSchedRepository extends BaseRepository
100 100
     }
101 101
 
102 102
     /**
103
+     * 获取影片场次列表
104
+     *
105
+     * @param $cinema_sign
106
+     * @param $film_sign
107
+     * @param $show_date
108
+     * @param $show_time
109
+     * @return array
110
+     * @throws \think\db\exception\DataNotFoundException
111
+     * @throws \think\db\exception\DbException
112
+     * @throws \think\db\exception\ModelNotFoundException
113
+     */
114
+    public function getCinemaFilmSchedNew($film_sign, $cinema_sign)
115
+    {
116
+        /** @var FilmRepository $filmRepository */
117
+        $filmRepository = app()->make(FilmRepository::class);
118
+        $filminfo = $filmRepository->getFilmInfo($film_sign);
119
+        if (empty($filminfo)) throw new \Exception('影片不存在');
120
+
121
+        /** @var CinemaRepository $cinemaRepository */
122
+        $cinemaRepository = app()->make(CinemaRepository::class);
123
+        $cinemainfo = $cinemaRepository->getCinemaInfo($cinema_sign);
124
+
125
+        // 获取排片场次
126
+        /** @var MovieRepository $movieRepository */
127
+        $movieRepository = app()->make(MovieRepository::class);
128
+        $cinema_sched = $movieRepository->getCinemaSched($film_sign, $cinema_sign);
129
+
130
+        // 排片日期
131
+        $show_date = array_keys($cinema_sched);
132
+        // 场次列表
133
+        foreach ($cinema_sched as $date => &$cinema_schedValue) {
134
+            foreach ($cinema_schedValue as $key => $value) {
135
+                $cinema_schedValue[$key]['cinema_sign'] = $cinemainfo->cinema_sign;
136
+                $cinema_schedValue[$key]['cinema_name'] = $cinemainfo->cinema_name;
137
+                $cinema_schedValue[$key]['end_time'] = date('H:i', (strtotime($value['show_time']) + $filminfo['duration'] * 60));
138
+                $cinema_schedValue[$key]['film'] = [
139
+                    'film_sign' => $filminfo->film_sign,
140
+                    'publish_date' => date('Y-m-d', $filminfo->publish_date),
141
+                    'language' => $filminfo->language,
142
+                    'type' => $filminfo->type,
143
+                    'duration' => $filminfo->duration,
144
+                    'version' => $filminfo->version
145
+                ];
146
+                unset($cinema_schedValue[$key]['channel_price']);
147
+                unset($cinema_schedValue[$key]['cost_price']);
148
+            }
149
+        }
150
+
151
+        return compact('show_date', 'cinema_sched');
152
+    }
153
+
154
+    /**
103 155
      * @param $page
104 156
      * @param $limit
105 157
      * @param $cinema_sign

+ 14 - 0
app/common/repositories/movie/FilmRepository.php

@@ -31,6 +31,20 @@ class FilmRepository extends BaseRepository
31 31
     }
32 32
 
33 33
     /**
34
+     * 获取电影信息
35
+     *
36
+     * @param $film_sign
37
+     * @return Film|array|\think\Model|null
38
+     * @throws \think\db\exception\DataNotFoundException
39
+     * @throws \think\db\exception\DbException
40
+     * @throws \think\db\exception\ModelNotFoundException
41
+     */
42
+    public function getFilmInfo($film_sign)
43
+    {
44
+        return $this->dao->where('film_sign', $film_sign)->find();
45
+    }
46
+
47
+    /**
34 48
      * 根据开始、结束日期获取影片
35 49
      *
36 50
      * @param $page

+ 14 - 10
app/controller/api/movie/Movie.php

@@ -141,21 +141,25 @@ class Movie extends BaseController
141 141
      */
142 142
     public function getCinemaFilmSched()
143 143
     {
144
-        [$page, $limit] = $this->getPage();
145
-        $cinema_sign = $this->request->param('cinema_sign', '');
146
-        $film_sign = $this->request->param('film_sign', '');
144
+        try {
145
+//            [$page, $limit] = $this->getPage();
146
+            $cinema_sign = $this->request->param('cinema_sign', '');
147
+            $film_sign = $this->request->param('film_sign', '');
147 148
 //        $longitude = $this->request->param('longitude', '');// 经度
148 149
 //        $latitude = $this->request->param('latitude', '');// 纬度
149
-        $show_date = $this->request->param('show_date', '');
150
+//        $show_date = $this->request->param('show_date', '');
150 151
 
151
-        if (empty($cinema_sign)) return app('json')->fail('请选择观影影院');
152
-        if (empty($film_sign)) return app('json')->fail('请选择观影影片');
152
+            if (empty($cinema_sign)) return app('json')->fail('请选择观影影院');
153
+            if (empty($film_sign)) return app('json')->fail('请选择观影影片');
153 154
 //        if (empty($longitude) || empty($latitude)) return app('json')->fail('请授权应用开启定位');
154
-        if (empty($show_date)) return app('json')->fail('请选择观影日期');
155
+//        if (empty($show_date)) return app('json')->fail('请选择观影日期');
155 156
 
156
-        /** @var CinemaSchedRepository $cinemaSchedRepository */
157
-        $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
158
-        return app('json')->success($cinemaSchedRepository->getCinemaFilmSched($page, $limit, $cinema_sign, $film_sign, $show_date, date('H:i')));
157
+            /** @var CinemaSchedRepository $cinemaSchedRepository */
158
+            $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
159
+            return app('json')->success($cinemaSchedRepository->getCinemaFilmSchedNew($film_sign, $cinema_sign));
160
+        } catch (\Exception $exception) {
161
+            return app('json')->fail($exception->getMessage());
162
+        }
159 163
     }
160 164
 
161 165
     /**