setName('cinema_film_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 ($filmResult['film_list'] as $key => $film) { foreach ($result['cinema_list'] as $subKey => $cinema) { $this->doCinemaSched($film, $cinema); } } } 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']); $this->createCinemaSched($cinema_sched, $cinema); } /** * 设置影院场次 * * @param $list * @param $cinema * @return void * @throws \think\db\exception\DbException */ private function createCinemaSched($list, $cinema) { foreach ($list as $key => $sched) { foreach ($sched as $subKey => $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' => strtotime($value['stop_sell_time']), 'price' => $value['price'], // 销售价 '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' => $params['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); } } } } }