FilmRepository.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/8
  6. */
  7. namespace app\common\repositories\movie;
  8. use app\common\dao\movie\order\MovieOrderDao;
  9. use app\common\model\movie\film\Film;
  10. use app\common\repositories\BaseRepository;
  11. /**
  12. * Class FilmRepository
  13. * @package app\common\repositories\movie
  14. * @author xaboy
  15. * @mixin MovieOrderDao
  16. */
  17. class FilmRepository extends BaseRepository
  18. {
  19. protected $dao;
  20. /**
  21. * ProductRepository constructor.
  22. * @param Film $dao
  23. */
  24. public function __construct(Film $dao)
  25. {
  26. $this->dao = $dao;
  27. }
  28. /**
  29. * 获取电影信息
  30. *
  31. * @param $film_sign
  32. * @return Film|array|\think\Model|null
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function getFilmInfo($film_sign)
  38. {
  39. return $this->dao->where('film_sign', $film_sign)->find();
  40. }
  41. /**
  42. * 根据开始、结束日期获取影片
  43. *
  44. * @param $page
  45. * @param $limit
  46. * @param $startDate
  47. * @param $endDate
  48. * @param $with
  49. * @return array
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function getFilmByStartEndDate($page, $limit, $startDate, $endDate, $with = [])
  55. {
  56. $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
  57. $where = [['publish_date', '<=', $endDate], ['publish_date', '>', $startDate]];
  58. return $this->dao->where($where)->when($with, function ($query) use ($with) {
  59. $query->with($with);
  60. })->when($page && $limit, function ($query) use ($page, $limit) {
  61. $query->page($page, $limit);
  62. })->field([$field])->order('hots desc')->select()->toArray();
  63. }
  64. /**
  65. * @param $page
  66. * @param $limit
  67. * @param $type
  68. * @param $with
  69. * @return array
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function getFilm($page, $limit, $type = 0, $film_name = '', $with = [])
  75. {
  76. $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
  77. $time = strtotime(date('Y-m-d'));
  78. if (empty($type)) {
  79. $where = [['publish_date', '<=', $time]];
  80. } else {
  81. $where = [['publish_date', '>', $time]];
  82. }
  83. if ($film_name) $where[] = ['film_name', 'like', '%' . $film_name . '%'];
  84. $film_list = $this->dao->where($where)->when($with, function ($query) use ($with) {
  85. $query->with($with);
  86. })->when($page && $limit, function ($query) use ($page, $limit) {
  87. $query->page($page, $limit);
  88. })->field([$field])->order('hots desc')->select()->toArray();
  89. foreach ($film_list as $key => $value) {
  90. $film_list[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
  91. $film_list[$key]['director'] = json_decode($value['director'], true);
  92. $film_list[$key]['actors'] = json_decode($value['actors'], true);
  93. $film_list[$key]['actors_name'] = !empty($film_list[$key]['actors']) ? implode(',', array_column($film_list[$key]['actors'], 'sc_name')) : '';
  94. $film_list[$key]['director_name'] = !empty($film_list[$key]['director']) ? implode(',', array_column($film_list[$key]['director'], 'sc_name')) : '';
  95. }
  96. $count = $this->dao->where($where)->when($with, function ($query) use ($with) {
  97. $query->with($with);
  98. })->field([$field])->count();
  99. return compact('film_list', 'count');
  100. }
  101. }