|
|
@@ -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
|
+}
|