FilmRepository.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 $page
  32. * @param $limit
  33. * @param $startDate
  34. * @param $endDate
  35. * @param $with
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getFilmByStartEndDate($page, $limit, $startDate, $endDate, $with = [])
  42. {
  43. $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
  44. $where = [['publish_date', '<=', $endDate], ['publish_date', '>', $startDate]];
  45. return $this->dao->where($where)->when($with, function ($query) use ($with) {
  46. $query->with($with);
  47. })->when($page && $limit, function ($query) use ($page, $limit) {
  48. $query->page($page, $limit);
  49. })->field([$field])->order('hots desc')->select()->toArray();
  50. }
  51. /**
  52. * @param $page
  53. * @param $limit
  54. * @param $type
  55. * @param $with
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function getFilm($page, $limit, $type = 0, $film_name = '', $with = [])
  62. {
  63. $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
  64. $time = strtotime(date('Y-m-d'));
  65. if (empty($type)) {
  66. $where = [['publish_date', '<=', $time]];
  67. } else {
  68. $where = [['publish_date', '>', $time]];
  69. }
  70. if ($film_name) $where[] = ['film_name', 'like', '%' . $film_name . '%'];
  71. $film_list = $this->dao->where($where)->when($with, function ($query) use ($with) {
  72. $query->with($with);
  73. })->when($page && $limit, function ($query) use ($page, $limit) {
  74. $query->page($page, $limit);
  75. })->field([$field])->order('hots desc')->select()->toArray();
  76. foreach ($film_list as $key => $value) {
  77. $film_list[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
  78. $film_list[$key]['director'] = json_decode($value['director'], true);
  79. $film_list[$key]['actors'] = json_decode($value['actors'], true);
  80. $film_list[$key]['actors_name'] = !empty($film_list[$key]['actors']) ? implode(',', array_column($film_list[$key]['actors'], 'sc_name')) : '';
  81. $film_list[$key]['director_name'] = !empty($film_list[$key]['director']) ? implode(',', array_column($film_list[$key]['director'], 'sc_name')) : '';
  82. }
  83. $count = $this->dao->where($where)->when($with, function ($query) use ($with) {
  84. $query->with($with);
  85. })->field([$field])->count();
  86. return compact('film_list', 'count');
  87. }
  88. }