123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\admin\controller\life;
- use app\admin\validate\life\CinemaValidate;
- use app\controller\Curd;
- use app\model\Cinema as CinemaModel;
- use app\model\CinemaIlk;
- use app\model\CinemaPerformers;
- use support\exception\BusinessException;
- use support\Request;
- use support\Response;
- class CinemaController extends Curd
- {
- public function __construct()
- {
- $this->model = new CinemaModel();
- $this->validate = true;
- $this->validateClass = new CinemaValidate();
- }
- /**
- * @Desc 影片列表
- * @Author Gorden
- * @Date 2024/2/26 13:42
- *
- * @param Request $request
- * @return Response
- * @throws \support\exception\BusinessException
- */
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- $where['cinema_is_del'] = 0;
- $order = $request->get('order', 'desc');
- $field = $field ?? 'cinema_addTime';
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- /**
- * @Desc 查询后数据处理
- * @Author Gorden
- * @Date 2024/3/21 14:13
- *
- * @param $items
- * @return void
- */
- public function afterQuery($items)
- {
- foreach ($items as &$item) {
- $item->cinema_img = !empty($item->cinema_img) ? getenv('STORAGE_DOMAIN') . $item->cinema_img : '';
- $item->cinema_video = !empty($item->cinema_video) ? getenv('STORAGE_DOMAIN') . $item->cinema_video : '';
- $item->cinema_time = !empty($item->cinema_time) ? date('Y-m-d H:i:s', strtotime($item->cinema_time)) : '';
- $item->cinema_label = !empty($item->cinema_label) ? explode(',', $item->cinema_label) : [];
- $item->cinema_director = !empty($item->cinema_director) ? array_map('intval', explode(',', $item->cinema_director)) : '';
- $item->cinema_star = !empty($item->cinema_star) ? array_map('intval', explode(',', $item->cinema_star)) : '';
- $item->cinema_performers = !empty($item->cinema_performers) ? array_map('intval', explode(',', $item->cinema_performers)) : '';
- $item->cinema_mold = !empty($item->cinema_mold) ? array_map('intval', explode(',', $item->cinema_mold)) : '';
- if (!empty($item->cinema_director)) {
- $cinemaDirector = CinemaPerformers::whereIn('performers_id', $item->cinema_director)->pluck('performers_name');
- if ($cinemaDirector) {
- $cinemaDirector = $cinemaDirector->toArray();
- $item->cinemaDirector = implode(',', $cinemaDirector);
- }
- }
- if (!empty($item->cinema_star)) {
- $cinemaStar = CinemaPerformers::whereIn('performers_id', $item->cinema_star)->pluck('performers_name');
- if ($cinemaStar) {
- $cinemaStar = $cinemaStar->toArray();
- $item->cinemaStar = implode(",", $cinemaStar);
- }
- }
- if (!empty($item->cinema_performers)) {
- $cinemaPerformers = CinemaPerformers::whereIn('performers_id', $item->cinema_performers)->pluck('performers_name');
- if ($cinemaPerformers) {
- $cinemaPerformers = $cinemaPerformers->toArray();
- $item->cinemaPerformers = implode(',', $cinemaPerformers);
- }
- }
- if (!empty($item->cinema_mold)) {
- $cinemaIlk = CinemaIlk::whereIn('ilk_id', $item->cinema_mold)->pluck('ilk_name');
- if ($cinemaIlk) {
- $cinemaIlk = $cinemaIlk->toArray();
- $item->cinemaIlk = implode(',', $cinemaIlk);
- }
- }
- }
- return $items;
- }
- /**
- * @Desc 新增数据处理
- * @Author Gorden
- * @Date 2024/3/21 14:11
- *
- * @param Request $request
- * @return array
- * @throws \support\exception\BusinessException
- */
- protected function insertInput(Request $request): array
- {
- $data = $this->inputFilter($request->post());
- if (!empty($data['cinema_img'])) {
- $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_img']);
- }
- if (!empty($data['cinema_video'])) {
- $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_video']);
- }
- return $data;
- }
- protected function updateInput(Request $request): array
- {
- $primary_key = $this->model->getKeyName();
- $id = $request->post($primary_key);
- $data = $this->inputFilter($request->post());
- $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_img']);
- $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'), '', $data['cinema_video']);
- $model = $this->model->find($id);
- if (!$model) {
- throw new BusinessException('记录不存在', 2);
- }
- unset($data[$primary_key]);
- return [$id, $data];
- }
- /**
- * @Desc 影片软删除
- * @Author Gorden
- * @Date 2024/2/26 13:43
- *
- * @param Request $request
- * @return Response
- * @throws \support\exception\BusinessException
- */
- public function delete(Request $request): Response
- {
- $ids = $this->deleteInput($request);
- $this->doSoftDelete($ids, ['cinema_is_del' => 1]);
- return json_success('success');
- }
- }
|