CinemaPerformersController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. $order = $request->get('order', 'desc');
  35. $field = $field ?? 'performers_create_time';
  36. $query = $this->doSelect($where, $field, $order);
  37. return $this->doFormat($query, $format, $limit);
  38. }
  39. protected function afterQuery($items)
  40. {
  41. foreach ($items as &$item) {
  42. $item->performers_type_text = self::PERFORMERS_TYPE[$item->performers_type];
  43. $item->performers_img = getenv("STORAGE_DOMAIN") . $item->performers_img;
  44. }
  45. return $items;
  46. }
  47. /**
  48. * @Desc 新增数据处理
  49. * @Author Gorden
  50. * @Date 2024/3/21 8:59
  51. *
  52. * @param Request $request
  53. * @return array
  54. * @throws \support\exception\BusinessException
  55. */
  56. protected function insertInput(Request $request): array
  57. {
  58. $data = $this->inputFilter($request->post());
  59. $data['performers_img'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['performers_img']);
  60. return $data;
  61. }
  62. /**
  63. * @Desc 更新数据处理
  64. * @Author Gorden
  65. * @Date 2024/3/21 9:02
  66. *
  67. * @param Request $request
  68. * @return array
  69. * @throws BusinessException
  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['performers_img'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['performers_img']);
  77. // 验证是否存在
  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. }