CinemaSchedCommand.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\command;
  3. use app\common\repositories\movie\CinemaRepository;
  4. use app\common\repositories\movie\CinemaSchedRepository;
  5. use app\common\repositories\movie\FilmRepository;
  6. use app\common\repositories\movie\MovieRepository;
  7. use crmeb\services\ApiResponseService;
  8. use think\console\Command;
  9. use think\console\Input;
  10. use think\console\Output;
  11. use think\facade\Db;
  12. class CinemaSchedCommand extends Command
  13. {
  14. private $page = 1;
  15. private $limit = 1000000;
  16. protected function configure()
  17. {
  18. // 指令配置
  19. $this->setName('cinema_film_sched')->setDescription('电影-影院场次列表');
  20. }
  21. protected function execute(Input $input, Output $output)
  22. {
  23. try {
  24. /** @var CinemaRepository $cinema */
  25. $cinema = app()->make(CinemaRepository::class);
  26. $result = $cinema->getLocalCinema($this->page, $this->limit, '', '', [], [], 0);
  27. /** @var FilmRepository $filmRepository */
  28. $filmRepository = app()->make(FilmRepository::class);
  29. $filmResult = $filmRepository->getFilm($this->page, $this->limit);
  30. foreach ($result['cinema_list'] as $key => $value) {
  31. foreach ($filmResult['film_list'] as $subKey => $subValue) {
  32. $this->doCinemaSched($subValue, $value);
  33. }
  34. }
  35. } catch (\Exception $exception) {
  36. var_dump($exception->getMessage(), $exception->getFile(), $exception->getLine());
  37. }
  38. }
  39. /**
  40. * 电影-获取影院场次列表
  41. * @return void
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. */
  46. private function doCinemaSched($film, $cinema)
  47. {
  48. /** @var MovieRepository $cinema_filmRepository */
  49. $cinema_filmRepository = app()->make(MovieRepository::class);
  50. $cinema_sched = $cinema_filmRepository->getCinemaSched($film['film_sign'], $cinema['cinema_sign']);
  51. if (isset($cinema_sched['code']) && ($cinema_sched['code'] == ApiResponseService::DEFAULT_SUCCESS_CODE)) {
  52. $this->createCinemaSched($cinema_sched['data']['list'], $cinema);
  53. }
  54. }
  55. /**
  56. * 设置影院场次
  57. *
  58. * @param $list
  59. * @param $cinema
  60. * @return void
  61. * @throws \think\db\exception\DbException
  62. */
  63. private function createCinemaSched($list, $cinema)
  64. {
  65. foreach ($list as $key => $value) {
  66. $params = [
  67. 'relation_id' => $value['relation_id'],
  68. 'sched_sign' => $value['sched_sign'],
  69. 'film_sign' => $value['film_sign'],
  70. 'film_name' => $value['film_name'],
  71. 'show_date' => strtotime(date('Y') . '-' . $value['show_date']),
  72. 'show_time' => trim($value['show_time']),
  73. 'cinema_sign' => $cinema['cinema_sign'],
  74. 'cinema_name' => $cinema['cinema_name'],
  75. 'address' => $cinema['address'],
  76. 'longitude' => $cinema['longitude'],
  77. 'latitude' => $cinema['latitude'],
  78. 'hall_sign' => $value['hall_sign'],
  79. 'hall_name' => $value['hall_name'],
  80. 'stop_sell_time' => $value['stop_sell_time'],
  81. 'cost_price' => $value['cost_price'],
  82. 'channel_price' => json_encode($value['channel_price'], JSON_FORCE_OBJECT)
  83. ];
  84. $where = [
  85. 'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'cinema_sign' => $params['cinema_sign']
  86. ];
  87. $model = Db::name('movie_cinema_sched')->where($where)->find();
  88. if (empty($model)) {
  89. $params['create_time'] = time();
  90. Db::name('movie_cinema_sched')->insert($params);
  91. } else {
  92. $params['update_time'] = time();
  93. Db::name('movie_cinema_sched')->where('id', $model['id'])->update($params);
  94. }
  95. }
  96. }
  97. }