|
|
@@ -32,18 +32,42 @@ class CinemaSchedCommand extends Command
|
|
32
|
32
|
$cinema = app()->make(CinemaRepository::class);
|
|
33
|
33
|
// 获取影院列表
|
|
34
|
34
|
$result = $cinema->getLocalCinema($this->page, $this->limit, '', '', [], [], 0);
|
|
|
35
|
+ $cinema_sign_list = $cinemainfo = [];
|
|
|
36
|
+ foreach ($result['cinema_list'] as $subKey => $cinema) {
|
|
|
37
|
+ $cinema_sign_list[] = $cinema['cinema_sign'];
|
|
|
38
|
+ $cinemainfo[$cinema['cinema_sign']] = $cinema;
|
|
|
39
|
+ }
|
|
35
|
40
|
|
|
36
|
41
|
/** @var FilmRepository $filmRepository */
|
|
37
|
42
|
$filmRepository = app()->make(FilmRepository::class);
|
|
38
|
43
|
// 获取{2个月内}已上映影片列表
|
|
39
|
44
|
$filmResult = $filmRepository->getFilmByStartEndDate($this->page, $this->limit, strtotime('-2 month', $date), $date);
|
|
|
45
|
+ if ($filmResult && $cinema_sign_list) {
|
|
|
46
|
+ foreach ($filmResult as $key => $film) {
|
|
|
47
|
+ // 获取排片影院
|
|
|
48
|
+// $scheduledCinema = Db::name('movie_cinema_sched')
|
|
|
49
|
+// ->where('film_sign', $film['film_sign'])->where('show_date', '>=', $date)
|
|
|
50
|
+// ->whereIn('cinema_sign', $cinema_sign_list)
|
|
|
51
|
+// ->field('film_sign,cinema_sign')->group('cinema_sign')->select();
|
|
|
52
|
+// $diffUnscheduledCinema = !empty($scheduledCinema) ?
|
|
|
53
|
+// array_diff($cinema_sign_list, array_column($scheduledCinema->toArray(), 'cinema_sign', 'cinema_sign')) : $cinema_sign_list;
|
|
|
54
|
+// $this->batchInsertUnscheduledCinema($film, $cinemainfo, $diffUnscheduledCinema);
|
|
40
|
55
|
|
|
41
|
|
- foreach ($filmResult as $key => $film) {
|
|
42
|
|
- foreach ($result['cinema_list'] as $subKey => $cinema) {
|
|
43
|
|
- // 是否未排片 @todo 影院未排片,不请求第三方接口获取排片场次
|
|
44
|
|
- if (!($this->isUnscheduledFilm($film['film_sign'], $cinema['cinema_sign']))) {
|
|
45
|
|
- $this->doCinemaSched($film, $cinema);
|
|
|
56
|
+ $diffUnscheduledCinema = [];
|
|
|
57
|
+ // 获取是否存在未排片影院记录 @todo 影院未排片,不请求第三方接口获取排片场次
|
|
|
58
|
+ $unscheduledCinema = Db::name('movie_cinema_unsched')->where('film_sign', $film['film_sign'])->whereIn('cinema_sign', $cinema_sign_list)
|
|
|
59
|
+ ->field('film_sign,cinema_sign')->select();
|
|
|
60
|
+ // 从总的影院、未排片影院中取出差异数据,得到排片影院
|
|
|
61
|
+ $diffScheduledCinema = !empty($unscheduledCinema) ? array_diff($cinema_sign_list, array_column($unscheduledCinema->toArray(), 'cinema_sign')) : $cinema_sign_list;
|
|
|
62
|
+ // 将{影片和排片影院}调用第三方获取排片场次
|
|
|
63
|
+ foreach ($diffScheduledCinema as $cinemaKey => $cinemaSignValue) {
|
|
|
64
|
+ $res = $this->doCinemaSched($film, $cinemainfo[$cinemaSignValue]);
|
|
|
65
|
+ if (!$res) {
|
|
|
66
|
+ $diffUnscheduledCinema[] = $cinemaSignValue;
|
|
|
67
|
+ }
|
|
46
|
68
|
}
|
|
|
69
|
+ // 未排片影院批量插入
|
|
|
70
|
+ if ($diffUnscheduledCinema) $this->batchInsertUnscheduledCinema($film, $cinemainfo, $diffUnscheduledCinema);
|
|
47
|
71
|
}
|
|
48
|
72
|
}
|
|
49
|
73
|
} catch (\Exception $exception) {
|
|
|
@@ -52,24 +76,36 @@ class CinemaSchedCommand extends Command
|
|
52
|
76
|
}
|
|
53
|
77
|
|
|
54
|
78
|
/**
|
|
55
|
|
- * 是否未排片
|
|
|
79
|
+ * 批量插入未排片影院
|
|
56
|
80
|
*
|
|
57
|
|
- * @param $film_sign
|
|
58
|
|
- * @param $cinema_sign
|
|
59
|
|
- * @return bool
|
|
|
81
|
+ * @param $film
|
|
|
82
|
+ * @param $cinemainfo
|
|
|
83
|
+ * @param $diffUnscheduledCinema
|
|
|
84
|
+ * @return void
|
|
60
|
85
|
*/
|
|
61
|
|
- private function isUnscheduledFilm($film_sign = '', $cinema_sign = '')
|
|
|
86
|
+ private function batchInsertUnscheduledCinema($film, $cinemainfo, $diffUnscheduledCinema)
|
|
62
|
87
|
{
|
|
63
|
|
- $count = Db::name('movie_cinema_unsched')->where(['film_sign' => $film_sign, 'cinema_sign' => $cinema_sign])->count();
|
|
64
|
|
- return $count > 0;
|
|
|
88
|
+ $data = [];
|
|
|
89
|
+
|
|
|
90
|
+ foreach ($diffUnscheduledCinema as $key => $value) {
|
|
|
91
|
+ $data[] = [
|
|
|
92
|
+ 'film_sign' => $film['film_sign'],
|
|
|
93
|
+ 'film_name' => $film['film_name'],
|
|
|
94
|
+ 'cinema_sign' => $cinemainfo[$value]['cinema_sign'],
|
|
|
95
|
+ 'cinema_name' => $cinemainfo[$value]['cinema_name'],
|
|
|
96
|
+ 'create_time' => time()
|
|
|
97
|
+ ];
|
|
|
98
|
+ }
|
|
|
99
|
+ if ($data) Db::name('movie_cinema_unsched')->insertAll($data);
|
|
65
|
100
|
}
|
|
66
|
101
|
|
|
67
|
102
|
/**
|
|
68
|
|
- * 电影-获取影院场次列表
|
|
69
|
|
- * @return void
|
|
70
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
103
|
+ * 电影-获取影院场次列表
|
|
|
104
|
+ *
|
|
|
105
|
+ * @param $film
|
|
|
106
|
+ * @param $cinema
|
|
|
107
|
+ * @return array|mixed|string
|
|
71
|
108
|
* @throws \think\db\exception\DbException
|
|
72
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
73
|
109
|
*/
|
|
74
|
110
|
private function doCinemaSched($film, $cinema)
|
|
75
|
111
|
{
|
|
|
@@ -80,10 +116,9 @@ class CinemaSchedCommand extends Command
|
|
80
|
116
|
if (!empty($cinema_sched)) {
|
|
81
|
117
|
// 写入排片场次数据
|
|
82
|
118
|
$this->createCinemaSched($cinema_sched, $cinema);
|
|
83
|
|
- } else {
|
|
84
|
|
- // 写入未排片影院
|
|
85
|
|
- $this->createUnschedCinema($film, $cinema);
|
|
86
|
119
|
}
|
|
|
120
|
+
|
|
|
121
|
+ return $cinema_sched;
|
|
87
|
122
|
}
|
|
88
|
123
|
|
|
89
|
124
|
/**
|
|
|
@@ -131,23 +166,4 @@ class CinemaSchedCommand extends Command
|
|
131
|
166
|
}
|
|
132
|
167
|
}
|
|
133
|
168
|
}
|
|
134
|
|
-
|
|
135
|
|
- /**
|
|
136
|
|
- * 记录未排片影院
|
|
137
|
|
- *
|
|
138
|
|
- * @param $film
|
|
139
|
|
- * @param $cinema
|
|
140
|
|
- * @return void
|
|
141
|
|
- */
|
|
142
|
|
- private function createUnschedCinema($film, $cinema)
|
|
143
|
|
- {
|
|
144
|
|
- $params = [
|
|
145
|
|
- 'film_sign' => $film['film_sign'],
|
|
146
|
|
- 'film_name' => $film['film_name'],
|
|
147
|
|
- 'cinema_sign' => $cinema['cinema_sign'],
|
|
148
|
|
- 'cinema_name' => $cinema['cinema_name'],
|
|
149
|
|
- 'create_time' => time()
|
|
150
|
|
- ];
|
|
151
|
|
- Db::name('movie_cinema_unsched')->insert($params);
|
|
152
|
|
- }
|
|
153
|
169
|
}
|