CinemaSchedCommand.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // if ($subValue['film_sign'] == 'F6556061D4' && $value['cinema_sign'] == 'CCB622D8D8') {
  34. // }
  35. }
  36. }
  37. } catch (\Exception $exception) {
  38. var_dump($exception->getMessage(), $exception->getFile(), $exception->getLine());
  39. }
  40. }
  41. /**
  42. * 电影-获取影院场次列表
  43. * @return void
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. private function doCinemaSched($film, $cinema)
  49. {
  50. /** @var MovieRepository $cinema_filmRepository */
  51. $cinema_filmRepository = app()->make(MovieRepository::class);
  52. $cinema_sched = $cinema_filmRepository->getCinemaSched($film['film_sign'], $cinema['cinema_sign']);
  53. $this->createCinemaSched($cinema_sched, $cinema);
  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 => $sched) {
  66. foreach ($sched as $subKey => $value) {
  67. $params = [
  68. 'relation_id' => $value['relation_id'],
  69. 'sched_sign' => $value['sched_sign'],
  70. 'film_sign' => $value['film_sign'],
  71. 'film_name' => $value['film_name'],
  72. 'show_date' => strtotime(date('Y') . '-' . $value['show_date']),
  73. 'show_time' => trim($value['show_time']),
  74. 'cinema_sign' => $cinema['cinema_sign'],
  75. 'cinema_name' => $cinema['cinema_name'],
  76. 'address' => $cinema['address'],
  77. 'longitude' => $cinema['longitude'],
  78. 'latitude' => $cinema['latitude'],
  79. 'hall_sign' => $value['hall_sign'],
  80. 'hall_name' => $value['hall_name'],
  81. 'stop_sell_time' => strtotime($value['stop_sell_time']),
  82. 'price' => $value['price'], // 原价
  83. 'cost_price' => $value['cost_price'], // 销售价
  84. 'channel_price' => json_encode($value['channel_price'], JSON_FORCE_OBJECT)
  85. ];
  86. $where = [
  87. 'relation_id' => $value['relation_id'], 'sched_sign' => $value['sched_sign'], 'film_sign' => $value['film_sign'], 'cinema_sign' => $params['cinema_sign']
  88. ];
  89. $model = Db::name('movie_cinema_sched')->where($where)->find();
  90. if (empty($model)) {
  91. $params['create_time'] = time();
  92. Db::name('movie_cinema_sched')->insert($params);
  93. } else {
  94. $params['update_time'] = time();
  95. Db::name('movie_cinema_sched')->where('id', $model['id'])->update($params);
  96. }
  97. }
  98. }
  99. }
  100. }