| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\command;
- use app\common\repositories\movie\CinemaRepository;
- use app\common\repositories\movie\FilmRepository;
- use app\common\repositories\movie\MovieRepository;
- use crmeb\services\ApiResponseService;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- class CinemaSchedCommand extends Command
- {
- private $page = 1;
- private $limit = 1000000;
- protected function configure()
- {
- // 指令配置
- $this->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);
- }
- }
- }
- }
|