family 1 рік тому
батько
коміт
905293821b

+ 105 - 0
app/command/MovieCinemaCommand.php

@@ -0,0 +1,105 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\common\repositories\movie\CinemaRepository;
6
+use app\common\repositories\movie\MovieRepository;
7
+use crmeb\services\ApiResponseService;
8
+use think\console\Command;
9
+use think\console\Input;
10
+use think\console\Output;
11
+use think\facade\Db;
12
+
13
+class MovieCinemaCommand extends Command
14
+{
15
+    protected function configure()
16
+    {
17
+        // 指令配置
18
+        $this->setName('movie-cinema')->setDescription('电影-获取影院列表');
19
+    }
20
+
21
+    protected function execute(Input $input, Output $output)
22
+    {
23
+        $this->doMovieCinema();
24
+    }
25
+
26
+    /**
27
+     * 电影-获取影院列表
28
+     * @return void
29
+     * @throws \think\db\exception\DataNotFoundException
30
+     * @throws \think\db\exception\DbException
31
+     * @throws \think\db\exception\ModelNotFoundException
32
+     */
33
+    private function doMovieCinema()
34
+    {
35
+        $page = 1;
36
+        $limit = 100;
37
+
38
+        /** @var MovieRepository $movieRepository */
39
+        $movieRepository = app()->make(MovieRepository::class);
40
+        $cinemaLists = $movieRepository->getCinema($page, $limit);
41
+
42
+        if (isset($cinemaLists['code']) && ($cinemaLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
43
+            $this->createMovieCinema($cinemaLists['data']['list']);
44
+
45
+            $data = $cinemaLists['data'];
46
+            $totalPages = $data['paging']['pages'] ?? 0;
47
+            for ($index = ($page + 1); $index <= $totalPages; $index++) {
48
+                $cinemaLists = $movieRepository->getCinema($index, $limit);
49
+                if (isset($cinemaLists['code']) && ($cinemaLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
50
+                    $this->createMovieCinema($cinemaLists['data']['list']);
51
+                    sleep(1);
52
+                }
53
+            }
54
+        }
55
+    }
56
+
57
+    /**
58
+     * 电影-影院列表
59
+     *
60
+     * @param $list
61
+     * @return void
62
+     * @throws \think\db\exception\DataNotFoundException
63
+     * @throws \think\db\exception\DbException
64
+     * @throws \think\db\exception\ModelNotFoundException
65
+     */
66
+    private function createMovieCinema($list)
67
+    {
68
+        $cinema_signList = array_column($list, 'cinema_sign');
69
+
70
+        $localCinema_nameLists = Db::name('movie_cinema')->whereIn('cinema_sign', $cinema_signList)->field('id,cinema_sign,cinema_name,address,tel')->select();
71
+        $localCinema_nameLists = !empty($localCinema_nameLists) ? array_reduce($localCinema_nameLists->toArray(), function ($carry, $item) {
72
+            $carry[$item['cinema_sign']] = [
73
+                'id' => $item['id'], 'cinema_sign' => $item['cinema_sign'], 'cinema_name' => $item['cinema_name'],
74
+                'address' => $item['address'], 'tel' => $item['tel']
75
+            ];
76
+            return $carry;
77
+        }, []) : [];
78
+
79
+        foreach ($list as $key => $value) {
80
+            $params = [
81
+                'cinema_sign' => $value['cinema_sign'],
82
+                'cinema_name' => $value['cinema_name'],
83
+                'address' => $value['address'],
84
+                'tel' => trim($value['tel']),
85
+                'longitude' => $value['longitude'],
86
+                'latitude' => $value['latitude'],
87
+                'city_sign' => $value['city_sign'],
88
+                'city_name' => $value['city_name'],
89
+                'area_sign' => $value['area_sign'],
90
+                'area_name' => $value['area_name']
91
+            ];
92
+            if (!isset($localCinema_nameLists[$value['cinema_sign']])) {
93
+                $params['create_time'] = time();
94
+                Db::name('movie_cinema')->insert($params);
95
+            } else {
96
+                $localCinema_name = $localCinema_nameLists[$value['cinema_sign']];
97
+                if (md5($value['cinema_sign'] . $value['cinema_name'] . $value['address'] . $value['tel'])
98
+                    != md5($localCinema_name['cinema_sign'] . $localCinema_name['cinema_name'] . $localCinema_name['address'] . $localCinema_name['tel'])) {
99
+                    $params['update_time'] = time();
100
+                    Db::name('movie_cinema')->where('id', $localCinema_name['id'])->update($params);
101
+                }
102
+            }
103
+        }
104
+    }
105
+}

+ 135 - 0
app/command/MovieCityAreaCommand.php

@@ -0,0 +1,135 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\common\repositories\movie\MovieRepository;
6
+use crmeb\services\ApiResponseService;
7
+use think\console\Command;
8
+use think\console\Input;
9
+use think\console\Output;
10
+use think\facade\Db;
11
+
12
+class MovieCityAreaCommand extends Command
13
+{
14
+    protected function configure()
15
+    {
16
+        // 指令配置
17
+        $this->setName('movie-city-area')->setDescription('电影-城市列表');
18
+    }
19
+
20
+    protected function execute(Input $input, Output $output)
21
+    {
22
+        $this->doMovieCity();
23
+        $this->doMovieCityArea();
24
+    }
25
+
26
+    /**
27
+     * 电影-城市-分区列表
28
+     * @return void
29
+     * @throws \think\db\exception\DataNotFoundException
30
+     * @throws \think\db\exception\DbException
31
+     * @throws \think\db\exception\ModelNotFoundException
32
+     */
33
+    private function doMovieCity()
34
+    {
35
+        $page = 1;
36
+        $limit = 100;
37
+
38
+        /** @var MovieRepository $movieRepository */
39
+        $movieRepository = app()->make(MovieRepository::class);
40
+        $movieCityLists = $movieRepository->getMovieCity($page, $limit);
41
+
42
+        if (isset($movieCityLists['code']) && ($movieCityLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
43
+            $this->createMovieCity($movieCityLists['data']['list']);
44
+
45
+            $data = $movieCityLists['data'];
46
+            $totalPages = $data['paging']['pages'] ?? 0;
47
+            for ($index = ($page + 1); $index <= $totalPages; $index++) {
48
+                $movieCityLists = $movieRepository->getMovieCity($index, $limit);
49
+                if (isset($movieCityLists['code']) && ($movieCityLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
50
+                    $this->createMovieCity($movieCityLists['data']['list']);
51
+                    sleep(1);
52
+                }
53
+            }
54
+        }
55
+    }
56
+
57
+    /**
58
+     * 电影-城市列表
59
+     *
60
+     * @param $list
61
+     * @return void
62
+     * @throws \think\db\exception\DataNotFoundException
63
+     * @throws \think\db\exception\DbException
64
+     * @throws \think\db\exception\ModelNotFoundException
65
+     */
66
+    private function createMovieCity($list)
67
+    {
68
+        $city_signList = array_column($list, 'city_sign');
69
+
70
+        $localCityLists = Db::name('movie_city')->whereIn('city_sign', $city_signList)->field('id,city_sign,city_name')->select();
71
+        $localCityLists = !empty($localCityLists) ? array_reduce($localCityLists->toArray(), function ($carry, $item) {
72
+            $carry[$item['city_sign']] = ['id' => $item['id'], 'city_sign' => $item['city_sign'], 'city_name' => $item['city_name']];
73
+            return $carry;
74
+        }, []) : [];
75
+
76
+        foreach ($list as $key => $value) {
77
+            $params = [
78
+                'city_sign' => $value['city_sign'],
79
+                'city_name' => $value['city_name'],
80
+                'initial' => $value['initial'],
81
+            ];
82
+            if (!isset($localCityLists[$value['city_sign']])) {
83
+                $params['create_time'] = time();
84
+                Db::name('movie_city')->insert($params);
85
+            } else {
86
+                if (md5($value['city_sign'] . $value['city_name']) != md5($localCityLists[$value['city_sign']]['city_name'])) {
87
+                    $params['update_time'] = time();
88
+                    Db::name('movie_city')->where('id', $localCityLists[$value['city_sign']]['id'])->update($params);
89
+                }
90
+            }
91
+        }
92
+    }
93
+
94
+    /**
95
+     * 电影-城市分区列表
96
+     *
97
+     * @return void
98
+     * @throws \think\db\exception\DataNotFoundException
99
+     * @throws \think\db\exception\DbException
100
+     * @throws \think\db\exception\ModelNotFoundException
101
+     */
102
+    private function doMovieCityArea()
103
+    {
104
+        /** @var MovieRepository $movieRepository */
105
+        $movieRepository = app()->make(MovieRepository::class);
106
+
107
+        $localCityLists = Db::name('movie_city')->field('id,city_sign,city_name')->select();
108
+        foreach ($localCityLists as $key => $value) {
109
+            $movieAreaLists = $movieRepository->getMovieArea($value['city_sign']);
110
+            if (isset($movieAreaLists['code']) && ($movieAreaLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE) && !empty($movieAreaLists['data']['list'])) {
111
+                foreach ($movieAreaLists['data']['list'] as $maKey => $maValue) {
112
+                    $params = [
113
+                        'parent_id' => $value['id'],
114
+                        'city_sign' => $value['city_sign'],
115
+                        'city_name' => $value['city_name'],
116
+                        'area_code' => $maValue['area_code'],
117
+                        'area_name' => $maValue['area_name']
118
+                    ];
119
+                    $city_area = Db::name('movie_city_area')->where(['parent_id' => $value['id'], 'city_sign' => $value['city_sign'], 'area_code' => $maValue['area_code']])->find();
120
+                    if (empty($city_area)) {
121
+                        $params['create_time'] = time();
122
+                        Db::name('movie_city_area')->insert($params);
123
+                    } else {
124
+                        if (md5($maValue['area_code'] . $maValue['area_name']) != md5($city_area['area_code'] . $city_area['area_name'])) {
125
+                            $params['update_time'] = time();
126
+                            Db::name('movie_city_area')->where('id', $city_area['id'])->update($params);
127
+                        }
128
+                    }
129
+                }
130
+                sleep(1);
131
+            }
132
+        }
133
+    }
134
+
135
+}

+ 108 - 0
app/command/MovieFilmCommand.php

@@ -0,0 +1,108 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\common\repositories\movie\MovieRepository;
6
+use crmeb\services\ApiResponseService;
7
+use think\console\Command;
8
+use think\console\Input;
9
+use think\console\Output;
10
+use think\facade\Db;
11
+
12
+class MovieFilmCommand extends Command
13
+{
14
+    protected function configure()
15
+    {
16
+        // 指令配置
17
+        $this->setName('movie-film')->setDescription('电影-获取影片列表');
18
+    }
19
+
20
+    protected function execute(Input $input, Output $output)
21
+    {
22
+        $this->doMovieFilm();
23
+    }
24
+
25
+    /**
26
+     * 电影-获取影片列表
27
+     * @return void
28
+     * @throws \think\db\exception\DataNotFoundException
29
+     * @throws \think\db\exception\DbException
30
+     * @throws \think\db\exception\ModelNotFoundException
31
+     */
32
+    private function doMovieFilm()
33
+    {
34
+        $page = 1;
35
+        $limit = 50;
36
+
37
+        /** @var MovieRepository $movieRepository */
38
+        $movieRepository = app()->make(MovieRepository::class);
39
+        $filmLists = $movieRepository->getFilm($page, $limit);
40
+
41
+        if (isset($filmLists['code']) && ($filmLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
42
+            $this->createMovieFilm($filmLists['data']['list']);
43
+
44
+            $data = $filmLists['data'];
45
+            $totalPages = $data['paging']['pages'] ?? 0;
46
+            for ($index = ($page + 1); $index <= $totalPages; $index++) {
47
+                $filmLists = $movieRepository->getFilm($index, $limit);
48
+                if (isset($filmLists['code']) && ($filmLists['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
49
+                    $this->createMovieFilm($filmLists['data']['list']);
50
+                    sleep(1);
51
+                }
52
+            }
53
+        }
54
+    }
55
+
56
+    /**
57
+     * 电影-获取影片列表
58
+     *
59
+     * @param $list
60
+     * @return void
61
+     * @throws \think\db\exception\DataNotFoundException
62
+     * @throws \think\db\exception\DbException
63
+     * @throws \think\db\exception\ModelNotFoundException
64
+     */
65
+    private function createMovieFilm($list)
66
+    {
67
+        $film_signList = array_column($list, 'film_sign');
68
+
69
+        $localFilm_nameLists = Db::name('movie_film')->whereIn('film_sign', $film_signList)->field('id,film_sign,film_name,publish_date')->select();
70
+        $localFilm_nameLists = !empty($localFilm_nameLists) ? array_reduce($localFilm_nameLists->toArray(), function ($carry, $item) {
71
+            $carry[$item['film_sign']] = [
72
+                'id' => $item['id'], 'film_sign' => $item['film_sign'], 'film_name' => $item['film_name'], 'publish_date' => $item['publish_date']
73
+            ];
74
+            return $carry;
75
+        }, []) : [];
76
+
77
+        foreach ($list as $key => $value) {
78
+            $params = [
79
+                'film_sign' => $value['film_sign'],
80
+                'film_name' => $value['film_name'],
81
+                'publish_date' => strtotime($value['publish_date']),
82
+                'language' => trim($value['language']),
83
+                'type' => $value['type'],
84
+                'duration' => $value['duration'],
85
+                'version' => $value['version'],
86
+                'grade' => $value['grade'],
87
+                'hots' => $value['hots'],
88
+                'cover_img' => $value['cover_img'],
89
+                'video' => $value['video'],
90
+                'detail_img' => json_encode($value['detail_img'], JSON_FORCE_OBJECT),
91
+                'director' => json_encode($value['director'], JSON_FORCE_OBJECT),
92
+                'actors' => json_encode($value['actors'], JSON_FORCE_OBJECT),
93
+                'intro' => $value['intro']
94
+            ];
95
+            if (!isset($localFilm_nameLists[$value['film_sign']])) {
96
+                $params['create_time'] = time();
97
+                Db::name('movie_film')->insert($params);
98
+            } else {
99
+                $localFilm_name = $localFilm_nameLists[$value['film_sign']];
100
+                if (md5($value['film_sign'] . $value['film_name'] . $value['publish_date'])
101
+                    != md5($localFilm_name['film_sign'] . $localFilm_name['film_name'] . $localFilm_name['publish_date'])) {
102
+                    $params['update_time'] = time();
103
+                    Db::name('movie_film')->where('id', $localFilm_name['id'])->update($params);
104
+                }
105
+            }
106
+        }
107
+    }
108
+}

+ 0 - 1
app/common/dao/movie/order/MovieOrderDao.php

@@ -44,7 +44,6 @@ class MovieOrderDao extends BaseDao
44 44
      */
45 45
     public function search(array $where, $sysDel = 0)
46 46
     {
47
-
48 47
         return MovieOrder::getDB()
49 48
             ->when(($sysDel !== null), function ($query) use ($sysDel) {
50 49
                 $query->where('is_system_del', $sysDel);

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

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

+ 28 - 0
app/common/model/movie/city/City.php

@@ -0,0 +1,28 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020/6/1
7
+ *
8
+ *
9
+ */
10
+
11
+namespace app\common\model\movie\city;
12
+
13
+
14
+use app\common\model\BaseModel;
15
+
16
+class City extends BaseModel
17
+{
18
+
19
+    public static function tablePk(): ?string
20
+    {
21
+        return 'id';
22
+    }
23
+
24
+    public static function tableName(): string
25
+    {
26
+        return 'movie_city';
27
+    }
28
+}

+ 35 - 0
app/common/model/movie/film/Film.php

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

+ 82 - 0
app/common/repositories/movie/CinemaRepository.php

@@ -0,0 +1,82 @@
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\dao\movie\order\MovieOrderDao;
11
+use app\common\model\movie\cinema\Cinema;
12
+use app\common\repositories\BaseRepository;
13
+use think\facade\Db;
14
+
15
+/**
16
+ * Class CinemaRepository
17
+ * @package app\common\repositories\movie
18
+ * @author xaboy
19
+ * @mixin MovieOrderDao
20
+ */
21
+class CinemaRepository extends BaseRepository
22
+{
23
+    protected $dao;
24
+
25
+    /**
26
+     * ProductRepository constructor.
27
+     * @param Cinema $dao
28
+     */
29
+    public function __construct(Cinema $dao)
30
+    {
31
+        $this->dao = $dao;
32
+    }
33
+
34
+    /**
35
+     * @param $page
36
+     * @param $limit
37
+     * @param $longitude
38
+     * @param $latitude
39
+     * @param $where
40
+     * @param $with
41
+     * @param $order
42
+     * @return array
43
+     * @throws \think\db\exception\DataNotFoundException
44
+     * @throws \think\db\exception\DbException
45
+     * @throws \think\db\exception\ModelNotFoundException
46
+     */
47
+    public function getLocalCinema($page, $limit, $longitude, $latitude, $where = [], $with = [], $order = 1)
48
+    {
49
+        $field = 'cinema_sign,cinema_name,address,tel,city_sign,city_name,area_sign,area_name';
50
+
51
+        $result = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {
52
+            $query->with($with);
53
+        })->when($latitude && $longitude, function ($query) use ($field, $longitude, $latitude) {
54
+            $query->field([$field, $this->distance($latitude, $longitude)]);
55
+        })->when($page && $limit, function ($query) use ($page, $limit) {
56
+            $query->page($page, $limit);
57
+        })->when(!is_null($order), function ($query) use ($order) {
58
+            if ($order == 1) {//距离最近
59
+                $query->order('distance asc');
60
+            } else {//最新需求
61
+                $query->order('create_time desc');
62
+            }
63
+        })->field([$field])->select()->toArray();
64
+        foreach ($result as $key => $value) {
65
+            $result[$key]['distance'] = round($value['distance'] / 1000, 2);
66
+        }
67
+
68
+        return $result;
69
+    }
70
+
71
+    /**
72
+     * 经纬度排序计算
73
+     * @param string $latitude
74
+     * @param string $longitude
75
+     * @return string
76
+     */
77
+    private function distance(string $latitude, string $longitude)
78
+    {
79
+        return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) 
80
+        + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
81
+    }
82
+}

+ 11 - 11
app/common/repositories/movie/DouHuoMallFilmApiRequest.php

@@ -14,7 +14,7 @@ class DouHuoMallFilmApiRequest
14 14
     private static $path = 'http://wmh5.douhuomall.com';
15 15
     private static $app_id = 'YS3a8ab661406e47bb86';
16 16
     private static $app_secret = '41d8b8e1dd9a454a1abc4534297e33c3';
17
-    private static $mobile = '16630402568';
17
+    private static $mobile = '17855366921';
18 18
 
19 19
     private static $successCode = 200;
20 20
     private static $douHuoMallFilmAccessTokenCache = 'DouHuoMallFilmAccessToken';
@@ -63,7 +63,7 @@ class DouHuoMallFilmApiRequest
63 63
     {
64 64
         $url = '/openapi/Movie/getCity';
65 65
         $body = [
66
-            'Access-Token' => self::get_access_token(),
66
+            'access_token' => self::get_access_token(),
67 67
             'page' => $page,
68 68
             'limit' => $limit
69 69
         ];
@@ -82,7 +82,7 @@ class DouHuoMallFilmApiRequest
82 82
     {
83 83
         $url = '/openapi/Movie/getArea';
84 84
         $body = [
85
-            'Access-Token' => self::get_access_token(),
85
+            'access_token' => self::get_access_token(),
86 86
             'city_sign' => $city_sign
87 87
         ];
88 88
 
@@ -102,7 +102,7 @@ class DouHuoMallFilmApiRequest
102 102
     {
103 103
         $url = '/openapi/Movie/getCinema';
104 104
         $body = [
105
-            'Access-Token' => self::get_access_token(),
105
+            'access_token' => self::get_access_token(),
106 106
             'page' => $page,
107 107
             'limit' => $limit
108 108
         ];
@@ -125,7 +125,7 @@ class DouHuoMallFilmApiRequest
125 125
     {
126 126
         $url = '/openapi/Movie/getFilm';
127 127
         $body = [
128
-            'Access-Token' => self::get_access_token(),
128
+            'access_token' => self::get_access_token(),
129 129
             'page' => $page,
130 130
             'limit' => $limit
131 131
         ];
@@ -148,7 +148,7 @@ class DouHuoMallFilmApiRequest
148 148
     {
149 149
         $url = '/openapi/Movie/getFilmSched';
150 150
         $body = [
151
-            'Access-Token' => self::get_access_token(),
151
+            'access_token' => self::get_access_token(),
152 152
             'page' => $page,
153 153
             'limit' => $limit,
154 154
             'film_sign' => $film_sign,
@@ -171,7 +171,7 @@ class DouHuoMallFilmApiRequest
171 171
     {
172 172
         $url = '/openapi/Movie/getCinemaSched';
173 173
         $body = [
174
-            'Access-Token' => self::get_access_token(),
174
+            'access_token' => self::get_access_token(),
175 175
             'film_sign' => $film_sign,
176 176
             'cinema_sign' => $cinema_sign
177 177
         ];
@@ -191,7 +191,7 @@ class DouHuoMallFilmApiRequest
191 191
     {
192 192
         $url = '/openapi/Movie/getSchedSeat';
193 193
         $body = [
194
-            'Access-Token' => self::get_access_token(),
194
+            'access_token' => self::get_access_token(),
195 195
             'relation_id' => $relation_id,
196 196
             'sched_sign' => $sched_sign
197 197
         ];
@@ -211,7 +211,7 @@ class DouHuoMallFilmApiRequest
211 211
     {
212 212
         $url = '/openapi/Movie/submitOrder';
213 213
         $body = [
214
-            'Access-Token' => self::get_access_token(),
214
+            'access_token' => self::get_access_token(),
215 215
             'channel_type' => $channel_type,
216 216
             'sched_sign' => $sched_sign,
217 217
             'third_order' => $third_order,
@@ -234,7 +234,7 @@ class DouHuoMallFilmApiRequest
234 234
     {
235 235
         $url = '/openapi/Movie/confirmOrder';
236 236
         $body = [
237
-            'Access-Token' => self::get_access_token(),
237
+            'access_token' => self::get_access_token(),
238 238
             'third_order' => $third_order,
239 239
             'order_price' => $order_price
240 240
         ];
@@ -253,7 +253,7 @@ class DouHuoMallFilmApiRequest
253 253
     {
254 254
         $url = '/openapi/Movie/getOrderInfo';
255 255
         $body = [
256
-            'Access-Token' => self::get_access_token(),
256
+            'access_token' => self::get_access_token(),
257 257
             'third_order' => $third_order
258 258
         ];
259 259
 

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

@@ -0,0 +1,82 @@
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\dao\movie\order\MovieOrderDao;
11
+use app\common\model\movie\film\Film;
12
+use app\common\repositories\BaseRepository;
13
+
14
+/**
15
+ * Class FilmRepository
16
+ * @package app\common\repositories\movie
17
+ * @author xaboy
18
+ * @mixin MovieOrderDao
19
+ */
20
+class FilmRepository extends BaseRepository
21
+{
22
+    protected $dao;
23
+
24
+    /**
25
+     * ProductRepository constructor.
26
+     * @param Film $dao
27
+     */
28
+    public function __construct(Film $dao)
29
+    {
30
+        $this->dao = $dao;
31
+    }
32
+
33
+    /**
34
+     * @param $page
35
+     * @param $limit
36
+     * @param $type
37
+     * @param $with
38
+     * @return array
39
+     * @throws \think\db\exception\DataNotFoundException
40
+     * @throws \think\db\exception\DbException
41
+     * @throws \think\db\exception\ModelNotFoundException
42
+     */
43
+    public function getFilm($page, $limit, $type = 0, $with = [])
44
+    {
45
+        $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
46
+
47
+        $time = strtotime(date('Y-m-d'));
48
+        if (empty($type)) {
49
+            $where = [['publish_date', '<=', $time]];
50
+        } else {
51
+            $where = [['publish_date', '>', $time]];
52
+        }
53
+
54
+        $result = $this->dao->where($where)->when($with, function ($query) use ($with) {
55
+            $query->with($with);
56
+        })->when($page && $limit, function ($query) use ($page, $limit) {
57
+            $query->page($page, $limit);
58
+        })->field([$field])->order('publish_date acs')->select()->toArray();
59
+
60
+        foreach ($result as $key => $value) {
61
+            $result[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
62
+            $result[$key]['director'] = json_decode($value['director'], true);
63
+            $result[$key]['actors'] = json_decode($value['actors'], true);
64
+            $result[$key]['actors_name'] = !empty($result[$key]['actors']) ? implode(',', array_column($result[$key]['actors'], 'sc_name')) : '';
65
+            $result[$key]['director_name'] = !empty($result[$key]['director']) ? implode(',', array_column($result[$key]['director'], 'sc_name')) : '';
66
+        }
67
+
68
+        return $result;
69
+    }
70
+
71
+    /**
72
+     * 经纬度排序计算
73
+     * @param string $latitude
74
+     * @param string $longitude
75
+     * @return string
76
+     */
77
+    private function distance(string $latitude, string $longitude)
78
+    {
79
+        return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) 
80
+        + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
81
+    }
82
+}

+ 20 - 0
app/common/repositories/movie/MovieRepository.php

@@ -273,4 +273,24 @@ class MovieRepository extends BaseRepository
273 273
         if (!empty($result) && ($result['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) return $result['data'];
274 274
         throw new ValidateException('订单不存在');
275 275
     }
276
+
277
+    /**
278
+     * @return array
279
+     * @throws \think\db\exception\DataNotFoundException
280
+     * @throws \think\db\exception\DbException
281
+     * @throws \think\db\exception\ModelNotFoundException
282
+     */
283
+    public function getLocalMovieCity()
284
+    {
285
+        $city_name = [];
286
+
287
+        $city = Db::name('movie_city')->field('city_sign,city_name,initial')->where('is_show', 1)->order('id asc')->select();
288
+        foreach ($city as $key => $value) {
289
+            $city_name[$value['initial']][] = ['city_sign' => $value['city_sign'], 'city_name' => $value['city_name']];
290
+        }
291
+
292
+        $initial = !empty($city) ? array_values(array_column($city->toArray(), 'initial', 'initial')) : [];
293
+
294
+        return compact('city_name', 'initial');
295
+    }
276 296
 }

+ 17 - 12
app/controller/api/movie/Movie.php

@@ -7,6 +7,8 @@
7 7
 
8 8
 namespace app\controller\api\movie;
9 9
 
10
+use app\common\repositories\movie\CinemaRepository;
11
+use app\common\repositories\movie\FilmRepository;
10 12
 use app\common\repositories\movie\MovieRepository;
11 13
 use app\common\repositories\system\groupData\GroupDataRepository;
12 14
 use app\controller\merchant\user\User;
@@ -41,11 +43,7 @@ class Movie extends BaseController
41 43
      */
42 44
     public function getMovieCity()
43 45
     {
44
-        [$page, $limit] = $this->getPage();
45
-        $initial = $this->request->param('initial', '');
46
-        $city_name = $this->request->param('city_name', '');
47
-
48
-        return app('json')->success($this->repository->getMovieCity($page, $limit, $initial, $city_name));
46
+        return app('json')->success($this->repository->getLocalMovieCity());
49 47
     }
50 48
 
51 49
     /**
@@ -69,10 +67,16 @@ class Movie extends BaseController
69 67
     public function getCinema()
70 68
     {
71 69
         [$page, $limit] = $this->getPage();
72
-        $city_sign = $this->request->param('city_sign', '');
73
-        $area_sign = $this->request->param('area_sign', '');
74
-
75
-        return app('json')->success($this->repository->getCinema($page, $limit, $city_sign, $area_sign));
70
+        $cinema_name = $this->request->param('cinema_name', '');// 影院名称
71
+        $longitude = $this->request->param('longitude', '');// 经度
72
+        $latitude = $this->request->param('latitude', '');// 纬度
73
+        if (empty($longitude)) return app('json')->fail('请授权应用开启定位');
74
+        if (empty($latitude)) return app('json')->fail('请授权应用开启定位');
75
+        $where = !empty($cinema_name) ? ['cinema_name' => $cinema_name] : [];
76
+
77
+        /** @var CinemaRepository $cinemaRepository */
78
+        $cinemaRepository = app()->make(CinemaRepository::class);
79
+        return app('json')->success($cinemaRepository->getLocalCinema($page, $limit, $longitude, $latitude, $where));
76 80
     }
77 81
 
78 82
     /**
@@ -83,10 +87,11 @@ class Movie extends BaseController
83 87
     public function getFilm()
84 88
     {
85 89
         [$page, $limit] = $this->getPage();
86
-        $cinema_sign = $this->request->param('cinema_sign', '');
87
-        $film_sign = $this->request->param('film_sign', '');
90
+        $type = $this->request->param('type', 0);//热映:0:正在热映,1:即将上映
88 91
 
89
-        return app('json')->success($this->repository->getFilm($page, $limit, $cinema_sign, $film_sign));
92
+        /** @var FilmRepository $filmRepository */
93
+        $filmRepository = app()->make(FilmRepository::class);
94
+        return app('json')->success($filmRepository->getFilm($page, $limit, $type));
90 95
     }
91 96
 
92 97
     /**

+ 4 - 1
config/console.php

@@ -21,6 +21,9 @@ return [
21 21
         'ln:user_bill' => 'app\command\test\ln\UserBill',
22 22
         'ln:import_user_cxb' => 'app\command\test\ln\ImportUser2',
23 23
 //        'great_life_order_independent_account' => 'app\command\GreatLifeOrderIndependentAccount',
24
-//        'commercial-\_area_order_independent_account' => 'app\command\CommercialAreaOrderIndependentAccount'
24
+//        'commercial-\_area_order_independent_account' => 'app\command\CommercialAreaOrderIndependentAccount',
25
+        'movie_city_area' => 'app\command\MovieCityAreaCommand',
26
+        'movie_cinema' => 'app\command\MovieCinemaCommand',
27
+        'movie_film' => 'app\command\MovieFilmCommand'
25 28
     ],
26 29
 ];