CollegeTeacherController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\controller\life;
  3. use app\admin\validate\life\CollegeTeacherValidate;
  4. use app\controller\Curd;
  5. use app\model\CollegeTeacher as TeacherModel;
  6. use support\exception\BusinessException;
  7. use support\Request;
  8. use support\Response;
  9. class CollegeTeacherController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new TeacherModel();
  14. $this->validate = true;
  15. $this->validateClass = new CollegeTeacherValidate();
  16. }
  17. /**
  18. * @Desc 教师列表
  19. * @Author Gorden
  20. * @Date 2024/2/26 14:55
  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['teacher_is_del'] = 0;
  30. $order = $request->get('order', 'desc');
  31. $field = $field ?? 'teacher_addTime';
  32. $query = $this->doSelect($where, $field, $order);
  33. return $this->doFormat($query, $format, $limit);
  34. }
  35. /**
  36. * @Desc
  37. * @Author Gorden
  38. * @Date 2024/3/20 11:55
  39. *
  40. * @param $items
  41. * @return mixed
  42. */
  43. protected function afterQuery($items)
  44. {
  45. foreach ($items as &$item){
  46. $item->teacher_img = getenv("STORAGE_DOMAIN").$item->teacher_img;
  47. }
  48. return $items;
  49. }
  50. /**
  51. * @Desc
  52. * @Author Gorden
  53. * @Date 2024/3/20 11:55
  54. *
  55. * @param Request $request
  56. * @return array
  57. * @throws \support\exception\BusinessException
  58. */
  59. protected function insertInput(Request $request): array
  60. {
  61. $data = $this->inputFilter($request->post());
  62. $data['teacher_img'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['teacher_img']);
  63. return $data;
  64. }
  65. protected function updateInput(Request $request): array
  66. {
  67. $primary_key = $this->model->getKeyName();
  68. $id = $request->post($primary_key);
  69. $data = $this->inputFilter($request->post());
  70. $model = $this->model->find($id);
  71. if (!$model) {
  72. throw new BusinessException('记录不存在', 2);
  73. }
  74. $data['teacher_img'] = str_replace(getenv('STORAGE_DOMAIN'),'',$data['teacher_img']);
  75. unset($data[$primary_key]);
  76. return [$id, $data];
  77. }
  78. /**
  79. * @Desc 删除教师
  80. * @Author Gorden
  81. * @Date 2024/2/26 14:55
  82. *
  83. * @param Request $request
  84. * @return Response
  85. * @throws \support\exception\BusinessException
  86. */
  87. public function delete(Request $request): Response
  88. {
  89. $ids = $this->deleteInput($request);
  90. $this->doSoftDelete($ids, ['teacher_is_del' => 1]);
  91. return json_success('success');
  92. }
  93. }