| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /**
- * @package merchant
- * @Author: Qinii
- * @Date: 2020/5/8
- */
- namespace app\common\repositories\movie;
- use app\common\dao\movie\order\MovieOrderDao;
- use app\common\model\movie\film\Film;
- use app\common\repositories\BaseRepository;
- /**
- * Class FilmRepository
- * @package app\common\repositories\movie
- * @author xaboy
- * @mixin MovieOrderDao
- */
- class FilmRepository extends BaseRepository
- {
- protected $dao;
- /**
- * ProductRepository constructor.
- * @param Film $dao
- */
- public function __construct(Film $dao)
- {
- $this->dao = $dao;
- }
- /**
- * 获取电影信息
- *
- * @param $film_sign
- * @return Film|array|\think\Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getFilmInfo($film_sign)
- {
- return $this->dao->where('film_sign', $film_sign)->find();
- }
- /**
- * 根据开始、结束日期获取影片
- *
- * @param $page
- * @param $limit
- * @param $startDate
- * @param $endDate
- * @param $with
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getFilmByStartEndDate($page, $limit, $startDate, $endDate, $with = [])
- {
- $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
- $where = [['publish_date', '<=', $endDate], ['publish_date', '>', $startDate]];
- return $this->dao->where($where)->when($with, function ($query) use ($with) {
- $query->with($with);
- })->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->field([$field])->order('hots desc')->select()->toArray();
- }
- /**
- * @param $page
- * @param $limit
- * @param $type
- * @param $with
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getFilm($page, $limit, $type = 0, $film_name = '', $with = [])
- {
- $field = 'film_sign,film_name,publish_date,language,type,duration,version,cover_img,grade,hots,director,actors';
- $time = strtotime(date('Y-m-d'));
- if (empty($type)) {
- $where = [['publish_date', '<=', $time]];
- } else {
- $where = [['publish_date', '>', $time]];
- }
- if ($film_name) $where[] = ['film_name', 'like', '%' . $film_name . '%'];
- $film_list = $this->dao->where($where)->when($with, function ($query) use ($with) {
- $query->with($with);
- })->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })->field([$field])->order('hots desc')->select()->toArray();
- foreach ($film_list as $key => $value) {
- $film_list[$key]['publish_date'] = date('Y-m-d', $value['publish_date']);
- $film_list[$key]['director'] = json_decode($value['director'], true);
- $film_list[$key]['actors'] = json_decode($value['actors'], true);
- $film_list[$key]['actors_name'] = !empty($film_list[$key]['actors']) ? implode(',', array_column($film_list[$key]['actors'], 'sc_name')) : '';
- $film_list[$key]['director_name'] = !empty($film_list[$key]['director']) ? implode(',', array_column($film_list[$key]['director'], 'sc_name')) : '';
- }
- $count = $this->dao->where($where)->when($with, function ($query) use ($with) {
- $query->with($with);
- })->field([$field])->count();
- return compact('film_list', 'count');
- }
- }
|