Sfoglia il codice sorgente

获取影片场次日期列表、获取影片场次列表、影院影片场次列表

family 1 anno fa
parent
commit
d26df4bdec

+ 2 - 1
app/command/CinemaSchedCommand.php

@@ -3,6 +3,7 @@
3 3
 namespace app\command;
4 4
 
5 5
 use app\common\repositories\movie\CinemaRepository;
6
+use app\common\repositories\movie\CinemaSchedRepository;
6 7
 use app\common\repositories\movie\FilmRepository;
7 8
 use app\common\repositories\movie\MovieRepository;
8 9
 use crmeb\services\ApiResponseService;
@@ -19,7 +20,7 @@ class CinemaSchedCommand extends Command
19 20
     protected function configure()
20 21
     {
21 22
         // 指令配置
22
-        $this->setName('cinema_sched')->setDescription('电影-影院场次列表');
23
+        $this->setName('cinema_film_sched')->setDescription('电影-影院场次列表');
23 24
     }
24 25
 
25 26
     protected function execute(Input $input, Output $output)

+ 35 - 0
app/common/model/movie/cinema/CinemaSched.php

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+namespace app\common\model\movie\cinema;
4
+
5
+use app\model\BaseModel;
6
+
7
+class CinemaSched extends BaseModel
8
+{
9
+    protected $name = 'movie_cinema_sched';
10
+
11
+    public static function tablePk(): ?string
12
+    {
13
+        return 'id';
14
+    }
15
+
16
+    /**
17
+     * @param $model
18
+     * @param array $where
19
+     * @return CinemaSched
20
+     */
21
+    public function search($model = null, array $where = [])
22
+    {
23
+        $model = $model ?? new self();
24
+
25
+        return $model->when(isset($where['film_sign']) && $where['film_sign'], function ($query) use ($where) {
26
+            $query->where('film_sign', $where['film_sign']);
27
+        })->when(isset($where['cinema_sign']) && $where['cinema_sign'], function ($query) use ($where) {
28
+            $query->where('cinema_sign', $where['cinema_sign']);
29
+        })->when(isset($where['show_date']) && $where['show_date'], function ($query) use ($where) {
30
+            $query->where('show_date', $where['show_date']);
31
+        })->when(isset($where['city']) && $where['city'], function ($query) use ($where) {
32
+            $query->where('city', 'like', "%{$where['city']}%");
33
+        });
34
+    }
35
+}

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

@@ -0,0 +1,144 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ * @Author: Qinii
5
+ * @Date: 2020/5/8
6
+ */
7
+
8
+namespace app\common\repositories\movie;
9
+
10
+use app\common\model\movie\cinema\CinemaSched;
11
+use app\common\repositories\BaseRepository;
12
+use think\facade\Db;
13
+
14
+/**
15
+ * Class CinemaSchedRepository
16
+ * @package app\common\repositories\movie
17
+ * @author xaboy
18
+ * @mixin CinemaSched
19
+ */
20
+class CinemaSchedRepository extends BaseRepository
21
+{
22
+    protected $dao;
23
+
24
+    /**
25
+     * ProductRepository constructor.
26
+     * @param CinemaSched $dao
27
+     */
28
+    public function __construct(CinemaSched $dao)
29
+    {
30
+        $this->dao = $dao;
31
+    }
32
+
33
+    /**
34
+     * @param $film_sign
35
+     * @return array
36
+     * @throws \think\db\exception\DataNotFoundException
37
+     * @throws \think\db\exception\DbException
38
+     * @throws \think\db\exception\ModelNotFoundException
39
+     */
40
+    public function getFilmSchedDate($film_sign)
41
+    {
42
+        $field = 'show_date';
43
+        $where = ['film_sign' => $film_sign];
44
+
45
+        $show_date = $this->dao->search(null, $where)->field([$field])->order('show_date asc')->group('show_date')->select()->toArray();
46
+        foreach ($show_date as $key => $value) {
47
+            $show_date[$key]['date'] = date('m-d', $value['show_date']);
48
+        }
49
+
50
+        return compact('show_date');
51
+    }
52
+
53
+    /**
54
+     * @param $page
55
+     * @param $limit
56
+     * @param $longitude
57
+     * @param $latitude
58
+     * @param $show_date
59
+     * @param $with
60
+     * @param $order
61
+     * @return array
62
+     * @throws \think\db\exception\DataNotFoundException
63
+     * @throws \think\db\exception\DbException
64
+     * @throws \think\db\exception\ModelNotFoundException
65
+     */
66
+    public function getFilmSched($page, $limit, $film_sign, $longitude, $latitude, $show_date, $with = [], $order = 1)
67
+    {
68
+        $field = 'cinema_sign,cinema_name,address,cost_price,longitude,latitude';
69
+        $where = ['film_sign' => $film_sign, 'show_date' => $show_date];
70
+
71
+        $cinema_sched = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {
72
+            $query->with($with);
73
+        })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) {
74
+            $query->field([$field, $this->distance($latitude, $longitude)]);
75
+        })->when($page && $limit, function ($query) use ($page, $limit) {
76
+            $query->page($page, $limit);
77
+        })->when(!is_null($order), function ($query) use ($order) {
78
+            if ($order == 1) {//距离最近
79
+                $query->order('distance asc');
80
+            } else {//播放日期
81
+                $query->order('show_date desc');
82
+            }
83
+        })->field([$field])->select()->toArray();
84
+        foreach ($cinema_sched as $key => $value) {
85
+            $cinema_sched[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00;
86
+        }
87
+
88
+        $count = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {
89
+            $query->with($with);
90
+        })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) {
91
+            $query->field([$field, $this->distance($latitude, $longitude)]);
92
+        })->count();
93
+
94
+        return compact('cinema_sched', 'count');
95
+    }
96
+
97
+    /**
98
+     * @param $page
99
+     * @param $limit
100
+     * @param $cinema_sign
101
+     * @param $film_sign
102
+     * @param $show_date
103
+     * @return array
104
+     * @throws \think\db\exception\DataNotFoundException
105
+     * @throws \think\db\exception\DbException
106
+     * @throws \think\db\exception\ModelNotFoundException
107
+     */
108
+    public function getCinemaFilmSched($page, $limit, $cinema_sign, $film_sign, $show_date)
109
+    {
110
+        $field = 'relation_id,sched_sign,film_sign,film_name,show_date,show_time,cinema_sign,cinema_name,hall_sign,hall_name,cost_price';
111
+        $where = ['cinema_sign' => $cinema_sign, 'film_sign' => $film_sign, 'show_date' => $show_date];
112
+
113
+        $cinema_sched = $this->dao->search(null, $where)
114
+            ->when($page && $limit, function ($query) use ($page, $limit) {
115
+                $query->page($page, $limit);
116
+            })->order('show_time asc')->field([$field])->select()->toArray();
117
+        foreach ($cinema_sched as $key => $value) {
118
+            $pcYanglaojinGongxian = MovieRepository::getPvYanglaojinScore($value['cost_price']);
119
+
120
+            $cinema_sched[$key]['cost_price'] = $pcYanglaojinGongxian['cost_price'];
121
+            $cinema_sched[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
122
+            $cinema_sched[$key]['pv'] = $pcYanglaojinGongxian['pv'];
123
+            $cinema_sched[$key]['score'] = $pcYanglaojinGongxian['score'];
124
+            $cinema_sched[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian'];
125
+            $cinema_sched[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00;
126
+        }
127
+
128
+        $count = $this->dao->search(null, $where)->count();
129
+
130
+        return compact('cinema_sched', 'count');
131
+    }
132
+
133
+    /**
134
+     * 经纬度排序计算
135
+     * @param string $latitude
136
+     * @param string $longitude
137
+     * @return string
138
+     */
139
+    private function distance(string $latitude, string $longitude)
140
+    {
141
+        return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) 
142
+        + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
143
+    }
144
+}

+ 25 - 9
app/common/repositories/movie/MovieRepository.php

@@ -28,10 +28,10 @@ class MovieRepository extends BaseRepository
28 28
 
29 29
     protected $dao;
30 30
 
31
-    private $premium_ratio = 0.2;//溢价比例
32
-    private $yanglaojin_ratio = 0.3;
31
+    const premium_ratio = 0.2;//溢价比例
32
+    const yanglaojin_ratio = 0.3;
33 33
 
34
-    private $pv_ratio = 0.7;
34
+    const pv_ratio = 0.7;
35 35
 
36 36
     /**
37 37
      * ProductRepository constructor.
@@ -99,13 +99,13 @@ class MovieRepository extends BaseRepository
99 99
             ? $result['data']['list'] : [];
100 100
         foreach ($cinemaSchedList as $dateDay => &$fileSchedValue) {
101 101
             foreach ($fileSchedValue as $key => $value) {
102
-                $premium = round($value['cost_price'] * $this->premium_ratio, 2);
102
+                $pcYanglaojinGongxian = static::getPvYanglaojinScore($value['cost_price']);
103 103
 
104
-                $fileSchedValue[$key]['cost_price'] = bcadd((string)$value['cost_price'], (string)$premium, 2);
105
-
106
-                $pv = bcmul((string)$premium, $this->pv_ratio, 2);
107
-                $fileSchedValue[$key]['yanglaojin'] = bcmul((string)$premium, $this->yanglaojin_ratio, 2);
108
-                $fileSchedValue[$key]['pv'] = $fileSchedValue[$key]['score'] = $fileSchedValue[$key]['gongxian'] = $pv;
104
+                $fileSchedValue[$key]['cost_price'] = $pcYanglaojinGongxian['cost_price'];
105
+                $fileSchedValue[$key]['yanglaojin'] = $pcYanglaojinGongxian['yanglaojin'];
106
+                $fileSchedValue[$key]['pv'] = $pcYanglaojinGongxian['pv'];
107
+                $fileSchedValue[$key]['score'] = $pcYanglaojinGongxian['score'];
108
+                $fileSchedValue[$key]['gongxian'] = $pcYanglaojinGongxian['gongxian'];
109 109
 
110 110
                 unset($fileSchedValue[$key]['channel_price']);
111 111
             }
@@ -315,4 +315,20 @@ class MovieRepository extends BaseRepository
315 315
 
316 316
         return compact('city_name', 'initial');
317 317
     }
318
+
319
+    /**
320
+     * 获取pv、养老金、售价、积分
321
+     *
322
+     * @param $cost_price
323
+     * @return array
324
+     */
325
+    public static function getPvYanglaojinScore($cost_price)
326
+    {
327
+        $premium = round($cost_price * self::premium_ratio, 2);
328
+        $cost_price = bcadd((string)$cost_price, (string)$premium, 2);
329
+        $pv = $gongxian = $score = bcmul((string)$premium, self::pv_ratio, 2);
330
+        $yanglaojin = bcmul((string)$premium, self::yanglaojin_ratio, 2);
331
+
332
+        return compact('premium', 'cost_price', 'pv', 'yanglaojin', 'gongxian', 'score');
333
+    }
318 334
 }

+ 52 - 6
app/controller/api/movie/Movie.php

@@ -8,6 +8,7 @@
8 8
 namespace app\controller\api\movie;
9 9
 
10 10
 use app\common\repositories\movie\CinemaRepository;
11
+use app\common\repositories\movie\CinemaSchedRepository;
11 12
 use app\common\repositories\movie\FilmRepository;
12 13
 use app\common\repositories\movie\MovieRepository;
13 14
 use app\common\repositories\system\groupData\GroupDataRepository;
@@ -95,19 +96,64 @@ class Movie extends BaseController
95 96
     }
96 97
 
97 98
     /**
98
-     * 获取影院场次列表
99
+     * 获取影片场次日期列表
99 100
      *
100 101
      * @return mixed
101 102
      */
102
-    public function getCinemaSched()
103
+    public function getFilmSchedDate()
103 104
     {
104
-        $cinema_sign = $this->request->param('cinema_sign', '');
105
-        if (empty($cinema_sign)) return app('json')->fail('请选择影院');
105
+        $film_sign = $this->request->param('film_sign', '');
106
+        if (empty($film_sign)) return app('json')->fail('请选择要观看的影片');
107
+
108
+        /** @var CinemaSchedRepository $cinemaSchedRepository */
109
+        $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
110
+        return app('json')->success($cinemaSchedRepository->getFilmSchedDate($film_sign));
111
+    }
106 112
 
113
+    /**
114
+     * 获取影片场次列表
115
+     *
116
+     * @return mixed
117
+     */
118
+    public function getFilmSched()
119
+    {
120
+        [$page, $limit] = $this->getPage();
107 121
         $film_sign = $this->request->param('film_sign', '');
108
-        if (empty($film_sign)) return app('json')->fail('请选择影片');
122
+        $longitude = $this->request->param('longitude', '');// 经度
123
+        $latitude = $this->request->param('latitude', '');// 纬度
124
+        $show_date = $this->request->param('show_date', '');
109 125
 
110
-        return app('json')->success($this->repository->getCinemaSched($film_sign, $cinema_sign));
126
+        if (empty($film_sign)) return app('json')->fail('请选择要观看的影片');
127
+        if (empty($longitude) || empty($latitude)) return app('json')->fail('请授权应用开启定位');
128
+        if (empty($show_date)) return app('json')->fail('请选择观影日期');
129
+
130
+        /** @var CinemaSchedRepository $cinemaSchedRepository */
131
+        $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
132
+        return app('json')->success($cinemaSchedRepository->getFilmSched($page, $limit, $film_sign, $longitude, $latitude, $show_date));
133
+    }
134
+
135
+    /**
136
+     * 影院影片场次列表
137
+     *
138
+     * @return mixed
139
+     */
140
+    public function getCinemaFilmSched()
141
+    {
142
+        [$page, $limit] = $this->getPage();
143
+        $cinema_sign = $this->request->param('cinema_sign', '');
144
+        $film_sign = $this->request->param('film_sign', '');
145
+//        $longitude = $this->request->param('longitude', '');// 经度
146
+//        $latitude = $this->request->param('latitude', '');// 纬度
147
+        $show_date = $this->request->param('show_date', '');
148
+
149
+        if (empty($cinema_sign)) return app('json')->fail('请选择观影影院');
150
+        if (empty($film_sign)) return app('json')->fail('请选择观影影片');
151
+//        if (empty($longitude) || empty($latitude)) return app('json')->fail('请授权应用开启定位');
152
+        if (empty($show_date)) return app('json')->fail('请选择观影日期');
153
+
154
+        /** @var CinemaSchedRepository $cinemaSchedRepository */
155
+        $cinemaSchedRepository = app()->make(CinemaSchedRepository::class);
156
+        return app('json')->success($cinemaSchedRepository->getCinemaFilmSched($page, $limit, $cinema_sign, $film_sign, $show_date));
111 157
     }
112 158
 
113 159
     /**

+ 7 - 5
route/api.php

@@ -1271,11 +1271,13 @@ Route::group('api/', function () {
1271 1271
 
1272 1272
     //电影
1273 1273
     Route::group('movie', function () {
1274
-        Route::get('city', '/getMovieCity');
1275
-        Route::get('area', '/getArea');
1276
-        Route::get('cinema', '/getCinema');
1277
-        Route::get('film', '/getFilm');
1278
-        Route::get('cinema_sched', '/getCinemaSched');
1274
+        Route::get('city', '/getMovieCity'); // 城市列表
1275
+        Route::get('area', '/getArea'); // 城区列表
1276
+        Route::get('cinema', '/getCinema'); // 影院列表
1277
+        Route::get('film', '/getFilm'); // 影片列表
1278
+        Route::get('filmsched_date', '/getFilmSchedDate'); // 影片场次日期
1279
+        Route::get('film_sched', '/getFilmSched'); // 影片场次排片影院列表
1280
+        Route::get('cinemafilm_sched', '/getCinemaFilmSched'); // 影院影片场次列表
1279 1281
         Route::get('sched_seat', '/getSchedSeat');
1280 1282
     })->prefix('api.movie.Movie');
1281 1283