setName('cinema_sched')->setDescription('电影-影院场次列表'); } protected function execute(Input $input, Output $output) { try { /** @var CinemaRepository $cinema */ $cinema = app()->make(CinemaRepository::class); $result = $cinema->getLocalCinema($this->page, $this->limit, '', '', [], [], 0); /** @var FilmRepository $filmRepository */ $filmRepository = app()->make(FilmRepository::class); $filmResult = $filmRepository->getFilm($this->page, $this->limit); foreach ($result['cinema_list'] as $key => $value) { foreach ($filmResult['film_list'] as $subKey => $subValue) { $this->doCinemaSched($subValue, $value); } } } catch (\Exception $exception) { var_dump($exception->getMessage(), $exception->getFile(), $exception->getLine()); } } /** * 电影-获取影院场次列表 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function doCinemaSched($film, $cinema) { /** @var MovieRepository $cinema_filmRepository */ $cinema_filmRepository = app()->make(MovieRepository::class); $cinema_sched = $cinema_filmRepository->getCinemaSched($film['film_sign'], $cinema['cinema_sign']); if (isset($cinema_sched['code']) && ($cinema_sched['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) { $this->createCinemaSched($cinema_sched['data']['list'], $cinema); } } /** * 设置影院场次 * * @param $list * @param $cinema * @return void * @throws \think\db\exception\DbException */ private function createCinemaSched($list, $cinema) { foreach ($list as $key => $value) { $params = [ 'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'film_name' => $value['film_name'], 'show_date' => strtotime(date('Y') . '-' . $value['show_date']), 'show_time' => trim($value['show_time']), 'cinema_sign' => $cinema['cinema_sign'], 'cinema_name' => $cinema['cinema_name'], 'address' => $cinema['address'], 'longitude' => $cinema['longitude'], 'latitude' => $cinema['latitude'], 'hall_sign' => $value['hall_sign'], 'hall_name' => $value['hall_name'], 'stop_sell_time' => $value['stop_sell_time'], 'cost_price' => $value['cost_price'], 'channel_price' => json_encode($value['channel_price'], JSON_FORCE_OBJECT) ]; $where = [ 'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'cinema_sign' => $value['cinema_sign'] ]; $model = Db::name('movie_cinema_sched')->where($where)->find(); if (empty($model)) { $params['create_time'] = time(); Db::name('movie_cinema_sched')->insert($params); } else { $params['update_time'] = time(); Db::name('movie_cinema_sched')->where('id', $model['id'])->update($params); } } } }