Explorar el Código

影院场次列表脚本

family hace 1 año
padre
commit
876e117785

+ 106 - 0
app/command/CinemaSchedCommand.php

@@ -0,0 +1,106 @@
1
+<?php
2
+
3
+namespace app\command;
4
+
5
+use app\common\repositories\movie\CinemaRepository;
6
+use app\common\repositories\movie\FilmRepository;
7
+use app\common\repositories\movie\MovieRepository;
8
+use crmeb\services\ApiResponseService;
9
+use think\console\Command;
10
+use think\console\Input;
11
+use think\console\Output;
12
+use think\facade\Db;
13
+
14
+class CinemaSchedCommand extends Command
15
+{
16
+    private $page = 1;
17
+    private $limit = 1000000;
18
+
19
+    protected function configure()
20
+    {
21
+        // 指令配置
22
+        $this->setName('cinema_sched')->setDescription('电影-影院场次列表');
23
+    }
24
+
25
+    protected function execute(Input $input, Output $output)
26
+    {
27
+        try {
28
+            /** @var CinemaRepository $cinema */
29
+            $cinema = app()->make(CinemaRepository::class);
30
+            $result = $cinema->getLocalCinema($this->page, $this->limit, '', '', [], [], 0);
31
+
32
+            /** @var FilmRepository $filmRepository */
33
+            $filmRepository = app()->make(FilmRepository::class);
34
+            $filmResult = $filmRepository->getFilm($this->page, $this->limit);
35
+
36
+            foreach ($result['cinema_list'] as $key => $value) {
37
+                foreach ($filmResult['film_list'] as $subKey => $subValue) {
38
+                    $this->doCinemaSched($subValue, $value);
39
+                }
40
+            }
41
+        } catch (\Exception $exception) {
42
+            var_dump($exception->getMessage(), $exception->getFile(), $exception->getLine());
43
+        }
44
+    }
45
+
46
+    /**
47
+     * 电影-获取影院场次列表
48
+     * @return void
49
+     * @throws \think\db\exception\DataNotFoundException
50
+     * @throws \think\db\exception\DbException
51
+     * @throws \think\db\exception\ModelNotFoundException
52
+     */
53
+    private function doCinemaSched($film, $cinema)
54
+    {
55
+        /** @var MovieRepository $cinema_filmRepository */
56
+        $cinema_filmRepository = app()->make(MovieRepository::class);
57
+        $cinema_sched = $cinema_filmRepository->getCinemaSched($film['film_sign'], $cinema['cinema_sign']);
58
+
59
+        if (isset($cinema_sched['code']) && ($cinema_sched['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
60
+            $this->createCinemaSched($cinema_sched['data']['list'], $cinema);
61
+        }
62
+    }
63
+
64
+    /**
65
+     * 设置影院场次
66
+     *
67
+     * @param $list
68
+     * @param $cinema
69
+     * @return void
70
+     * @throws \think\db\exception\DbException
71
+     */
72
+    private function createCinemaSched($list, $cinema)
73
+    {
74
+        foreach ($list as $key => $value) {
75
+            $params = [
76
+                'relation_id' => $value['relation_id'],
77
+                'sched_sign' => $value['sched_sign'],
78
+                'film_sign' => $value['film_sign'],
79
+                'film_name' => $value['film_name'],
80
+                'show_date' => strtotime(date('Y') . '-' . $value['show_date']),
81
+                'show_time' => trim($value['show_time']),
82
+                'cinema_sign' => $cinema['cinema_sign'],
83
+                'cinema_name' => $cinema['cinema_name'],
84
+                'address' => $cinema['address'],
85
+                'longitude' => $cinema['longitude'],
86
+                'latitude' => $cinema['latitude'],
87
+                'hall_sign' => $value['hall_sign'],
88
+                'hall_name' => $value['hall_name'],
89
+                'stop_sell_time' => $value['stop_sell_time'],
90
+                'cost_price' => $value['cost_price'],
91
+                'channel_price' => json_encode($value['channel_price'], JSON_FORCE_OBJECT)
92
+            ];
93
+            $where = [
94
+                'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'cinema_sign' => $value['cinema_sign']
95
+            ];
96
+            $model = Db::name('movie_cinema_sched')->where($where)->find();
97
+            if (empty($model)) {
98
+                $params['create_time'] = time();
99
+                Db::name('movie_cinema_sched')->insert($params);
100
+            } else {
101
+                $params['update_time'] = time();
102
+                Db::name('movie_cinema_sched')->where('id', $model['id'])->update($params);
103
+            }
104
+        }
105
+    }
106
+}

+ 1 - 1
app/common/repositories/movie/CinemaRepository.php

@@ -62,7 +62,7 @@ class CinemaRepository extends BaseRepository
62 62
             }
63 63
         })->field([$field])->select()->toArray();
64 64
         foreach ($cinema_list as $key => $value) {
65
-            $cinema_list[$key]['distance'] = round($value['distance'] / 1000, 2);
65
+            $cinema_list[$key]['distance'] = isset($value['distance']) ? round($value['distance'] / 1000, 2) : 0.00;
66 66
         }
67 67
 
68 68
         $count = $this->dao->search(null, $where)->when($with, function ($query) use ($with) {

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

@@ -71,16 +71,4 @@ class FilmRepository extends BaseRepository
71 71
 
72 72
         return compact('film_list', 'count');
73 73
     }
74
-
75
-    /**
76
-     * 经纬度排序计算
77
-     * @param string $latitude
78
-     * @param string $longitude
79
-     * @return string
80
-     */
81
-    private function distance(string $latitude, string $longitude)
82
-    {
83
-        return "(round(6378137 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) 
84
-        + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
85
-    }
86 74
 }

+ 2 - 1
config/console.php

@@ -24,6 +24,7 @@ return [
24 24
 //        'commercial-\_area_order_independent_account' => 'app\command\CommercialAreaOrderIndependentAccount',
25 25
         'movie_city_area' => 'app\command\MovieCityAreaCommand',
26 26
         'movie_cinema' => 'app\command\MovieCinemaCommand',
27
-        'movie_film' => 'app\command\MovieFilmCommand'
27
+        'movie_film' => 'app\command\MovieFilmCommand',
28
+        'cinema_film_sched' => 'app\command\CinemaSchedCommand'
28 29
     ],
29 30
 ];