CinemaSchedCommand.php 4.3 KB

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