TravelSchedulingController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\admin\controller\life;
  3. use support\exception\BusinessException;
  4. use support\Request;
  5. use app\admin\validate\life\TravelSchedulingValidate;
  6. use app\controller\Curd;
  7. use app\model\TravelScheduling;
  8. use support\Response;
  9. class TravelSchedulingController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new TravelScheduling();
  14. $this->validate = true;
  15. $this->validateClass = new TravelSchedulingValidate();
  16. }
  17. /**
  18. * @Desc 列表
  19. * @Author Gorden
  20. * @Date 2024/3/5 14:20
  21. *
  22. * @param Request $request
  23. * @return Response
  24. * @throws BusinessException
  25. */
  26. public function select(Request $request): Response
  27. {
  28. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  29. $order = $request->get('order', 'desc');
  30. $field = $field ?? 'line_add_time';
  31. $where['line_is_del'] = 0;
  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/5 14:14
  39. *
  40. * @param Request $request
  41. * @return array
  42. * @throws \support\exception\BusinessException
  43. */
  44. protected function insertInput(Request $request): array
  45. {
  46. $data = $this->inputFilter($request->post());
  47. $data['week'] = chinese_week(date('w',strtotime($data['day'])));
  48. return $data;
  49. }
  50. /**
  51. * @Desc 过滤更新参数
  52. * @Author Gorden
  53. * @Date 2024/3/5 14:15
  54. *
  55. * @param Request $request
  56. * @return array
  57. * @throws BusinessException
  58. */
  59. protected function updateInput(Request $request): array
  60. {
  61. $primary_key = $this->model->getKeyName();
  62. $id = $request->post($primary_key);
  63. $data = $this->inputFilter($request->post());
  64. $data['week'] = chinese_week(date('w',strtotime($data['day'])));
  65. $model = $this->model->find($id);
  66. if (!$model) {
  67. throw new BusinessException('记录不存在', 2);
  68. }
  69. unset($data[$primary_key]);
  70. return [$id, $data];
  71. }
  72. /**
  73. * @Desc 删除
  74. * @Author Gorden
  75. * @Date 2024/3/5 14:18
  76. *
  77. * @param Request $request
  78. * @return Response
  79. * @throws BusinessException
  80. */
  81. public function delete(Request $request): Response
  82. {
  83. $ids = $this->deleteInput($request);
  84. $this->doSoftDelete($ids, ['is_del' => 1]);
  85. return json_success('success');
  86. }
  87. }