CinemaPerformersController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\admin\controller\life;
  3. use app\admin\validate\life\CinemaPerformersValidate;
  4. use app\model\CinemaPerformers as CinemaPerformersModel;
  5. use app\controller\Curd;
  6. use support\exception\BusinessException;
  7. use support\Request;
  8. use support\Response;
  9. class CinemaPerformersController extends Curd
  10. {
  11. const PERFORMERS_TYPE = [
  12. 1 => '导演',
  13. 2 => '演员'
  14. ];
  15. public function __construct()
  16. {
  17. $this->model = new CinemaPerformersModel();
  18. $this->validate = true;
  19. $this->validateClass = new CinemaPerformersValidate();
  20. }
  21. /**
  22. * @Desc 人员列表
  23. * @Author Gorden
  24. * @Date 2024/3/21 9:11
  25. *
  26. * @param Request $request
  27. * @return Response
  28. * @throws BusinessException
  29. */
  30. public function select(Request $request): Response
  31. {
  32. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  33. $where['performers_is_del'] = 0;
  34. $query = $this->doSelect($where, $field, $order);
  35. return $this->doFormat($query, $format, $limit);
  36. }
  37. protected function afterQuery($items)
  38. {
  39. foreach ($items as &$item) {
  40. $item->performers_type_text = self::PERFORMERS_TYPE[$item->performers_type];
  41. $item->performers_img = getenv("STORAGE_DOMAIN") . $item->performers_img;
  42. }
  43. return $items;
  44. }
  45. /**
  46. * @Desc 新增数据处理
  47. * @Author Gorden
  48. * @Date 2024/3/21 8:59
  49. *
  50. * @param Request $request
  51. * @return array
  52. * @throws \support\exception\BusinessException
  53. */
  54. protected function insertInput(Request $request): array
  55. {
  56. $data = $this->inputFilter($request->post());
  57. $data['performers_img'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['performers_img']);
  58. return $data;
  59. }
  60. /**
  61. * @Desc 更新数据处理
  62. * @Author Gorden
  63. * @Date 2024/3/21 9:02
  64. *
  65. * @param Request $request
  66. * @return array
  67. * @throws BusinessException
  68. */
  69. protected function updateInput(Request $request): array
  70. {
  71. $primary_key = $this->model->getKeyName();
  72. $id = $request->post($primary_key);
  73. $data = $this->inputFilter($request->post());
  74. $data['performers_img'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['performers_img']);
  75. // 验证是否存在
  76. $model = $this->model->find($id);
  77. if (!$model) {
  78. throw new BusinessException('记录不存在', 2);
  79. }
  80. unset($data[$primary_key]);
  81. return [$id, $data];
  82. }
  83. }