CinemaSchedCommand.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $result = $cinema->getLocalCinema($this->page, $this->limit, '', '', [], [], 0);
  28. /** @var FilmRepository $filmRepository */
  29. $filmRepository = app()->make(FilmRepository::class);
  30. $filmResult = $filmRepository->getFilm($this->page, $this->limit);
  31. foreach ($filmResult['film_list'] as $key => $film) {
  32. foreach ($result['cinema_list'] as $subKey => $cinema) {
  33. $this->doCinemaSched($film, $cinema);
  34. }
  35. }
  36. } catch (\Exception $exception) {
  37. var_dump($exception->getMessage(), $exception->getFile(), $exception->getLine());
  38. }
  39. }
  40. /**
  41. * 电影-获取影院场次列表
  42. * @return void
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. private function doCinemaSched($film, $cinema)
  48. {
  49. /** @var MovieRepository $cinema_filmRepository */
  50. $cinema_filmRepository = app()->make(MovieRepository::class);
  51. $cinema_sched = $cinema_filmRepository->getCinemaSched($film['film_sign'], $cinema['cinema_sign']);
  52. $this->createCinemaSched($cinema_sched, $cinema);
  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 => $sched) {
  65. foreach ($sched as $subKey => $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' => strtotime($value['stop_sell_time']),
  81. 'price' => $value['price'], // 销售价
  82. 'cost_price' => $value['cost_price'], // 原价
  83. 'channel_price' => json_encode($value['channel_price'], JSON_FORCE_OBJECT)
  84. ];
  85. $where = [
  86. 'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'cinema_sign' => $params['cinema_sign']
  87. ];
  88. $model = Db::name('movie_cinema_sched')->where($where)->find();
  89. if (empty($model)) {
  90. $params['create_time'] = time();
  91. Db::name('movie_cinema_sched')->insert($params);
  92. } else {
  93. $params['update_time'] = time();
  94. Db::name('movie_cinema_sched')->where('id', $model['id'])->update($params);
  95. }
  96. }
  97. }
  98. }
  99. }