ApiController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\admin\validate\sys_manage\ApiValidate;
  4. use app\controller\Curd;
  5. use app\model\SysApi;
  6. use app\model\SysSerial;
  7. use support\Request;
  8. use support\Response;
  9. class ApiController extends Curd
  10. {
  11. public function __construct()
  12. {
  13. $this->model = new SysApi();
  14. $this->validate = true;
  15. $this->validateClass = new ApiValidate();
  16. }
  17. public function select(Request $request): Response
  18. {
  19. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  20. $order = $request->get('order', 'desc');
  21. $field = $field ?? 'api_addtimes';
  22. $query = $this->doSelect($where, $field, $order);
  23. return $this->doFormat($query, $format, $limit);
  24. }
  25. protected function insertInput(Request $request): array
  26. {
  27. $data = $this->inputFilter($request->post());
  28. $data['api_id'] = "AP" . date('ymdH') . random_string(6, 'up');
  29. $data['api_extend_json'] = $data['api_extend_json'] ?? '{}';
  30. $data['api_request_json'] = $data['api_request_json'] ?? '{}';
  31. $data['api_response_json'] = $data['api_response_json'] ?? '{}';
  32. return $data;
  33. }
  34. }