CinemaSchedCommand.php 4.0 KB

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