CinemaController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller\life;
  3. use app\admin\validate\life\CinemaValidate;
  4. use app\controller\Curd;
  5. use app\model\Cinema as CinemaModel;
  6. use support\exception\BusinessException;
  7. use support\Request;
  8. use support\Response;
  9. class CinemaController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new CinemaModel();
  14. $this->validate = true;
  15. $this->validateClass = new CinemaValidate();
  16. }
  17. /**
  18. * @Desc 影片列表
  19. * @Author Gorden
  20. * @Date 2024/2/26 13:42
  21. *
  22. * @param Request $request
  23. * @return Response
  24. * @throws \support\exception\BusinessException
  25. */
  26. public function select(Request $request): Response
  27. {
  28. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  29. $where['cinema_is_del'] = 0;
  30. $query = $this->doSelect($where, $field, $order);
  31. return $this->doFormat($query, $format, $limit);
  32. }
  33. /**
  34. * @Desc 查询后数据处理
  35. * @Author Gorden
  36. * @Date 2024/3/21 14:13
  37. *
  38. * @param $items
  39. * @return void
  40. */
  41. public function afterQuery($items)
  42. {
  43. foreach ($items as &$item){
  44. $item->cinema_img = getenv('STORAGE_DOMAIN').$item->cinema_img;
  45. $item->cinema_video = getenv('STORAGE_DOMAIN').$item->cinema_video;
  46. $item->cinema_time = date('Y-m-d H:i:s',strtotime($item->cinema_time));
  47. $item->cinema_label = !empty($item->cinema_label) ? explode(',',$item->cinema_label) : '';
  48. $item->cinema_mold = !empty($item->cinema_mold) ? explode(',',$item->cinema_mold) : '';
  49. $item->cinema_director = !empty($item->cinema_director) ? array_map('intval',explode(',',$item->cinema_director)) : '';
  50. $item->cinema_star = !empty($item->cinema_star) ? array_map('intval',explode(',',$item->cinema_star)) : '';
  51. $item->cinema_performers = !empty($item->cinema_performers) ? array_map('intval',explode(',',$item->cinema_performers)) : '';
  52. }
  53. return $items;
  54. }
  55. /**
  56. * @Desc 新增数据处理
  57. * @Author Gorden
  58. * @Date 2024/3/21 14:11
  59. *
  60. * @param Request $request
  61. * @return array
  62. * @throws \support\exception\BusinessException
  63. */
  64. protected function insertInput(Request $request): array
  65. {
  66. $data = $this->inputFilter($request->post());
  67. $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['cinema_img']);
  68. $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['cinema_video']);
  69. return $data;
  70. }
  71. protected function updateInput(Request $request): array
  72. {
  73. $primary_key = $this->model->getKeyName();
  74. $id = $request->post($primary_key);
  75. $data = $this->inputFilter($request->post());
  76. $data['cinema_img'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['cinema_img']);
  77. $data['cinema_video'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['cinema_video']);
  78. $model = $this->model->find($id);
  79. if (!$model) {
  80. throw new BusinessException('记录不存在', 2);
  81. }
  82. unset($data[$primary_key]);
  83. return [$id, $data];
  84. }
  85. /**
  86. * @Desc 影片软删除
  87. * @Author Gorden
  88. * @Date 2024/2/26 13:43
  89. *
  90. * @param Request $request
  91. * @return Response
  92. * @throws \support\exception\BusinessException
  93. */
  94. public function delete(Request $request): Response
  95. {
  96. $ids = $this->deleteInput($request);
  97. $this->doSoftDelete($ids, ['cinema_is_del' => 1]);
  98. return json_success('success');
  99. }
  100. }