Pārlūkot izejas kodu

调整场次脚本,将未排片影院批量插入到:未排片影院表

family 1 gadu atpakaļ
vecāks
revīzija
a54153c01a

+ 54 - 38
app/command/CinemaSchedCommand.php

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

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

@@ -190,7 +190,7 @@ class MovieRepository extends BaseRepository
190 190
         if (json_last_error()) throw new ValidateException('锁座下单失败');
191 191
 
192 192
         $order_price = bcmul((string)$channel_sn['price'], (string)count($sched_seat), 2);
193
-        $submitOrder = DouHuoMallFilmApiRequest::submitOrder($userinfo->phone, $channel_sn['channel_type'], $params['sched_sign'], array_column($sched_seat, 'seat_sign'), $order_sn, $order_price);
193
+        $submitOrder = DouHuoMallFilmApiRequest::submitOrder($params['phone'] ?? $userinfo->phone, $channel_sn['channel_type'], $params['sched_sign'], array_column($sched_seat, 'seat_sign'), $order_sn, $order_price);
194 194
         if (!empty($submitOrder) && isset($submitOrder['code']) && ($submitOrder['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE) && isset($submitOrder['data']['plat_order'])) {
195 195
             /** @var CinemaRepository $cinemaRepository */
196 196
             $cinemaRepository = app()->make(CinemaRepository::class);