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'); } }