FilmRepository.php 2.5 KB

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