BaseController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\base\controller;
  3. use app\common\base\request\BaseRequest;
  4. use think\Controller;
  5. /**
  6. * 后台控制器基类
  7. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  8. */
  9. abstract class BaseController
  10. {
  11. private $_request = null;
  12. private $_params = [];
  13. private $_token = null;
  14. protected $needToken = true;
  15. // 初始化
  16. public function __construct() {
  17. $this->beforeInit();
  18. $this->zskkInit();
  19. $this->afterInit();
  20. }
  21. protected function beforeInit() {}
  22. protected function afterInit() {}
  23. protected function zskkInit() {
  24. $this->beforeSetRequest();
  25. $this->mountRequest();
  26. $this->afterSetRequest();
  27. }
  28. protected function setToken($token) {
  29. $this->_token = $token;
  30. }
  31. protected function getToken() {
  32. return $this->_token;
  33. }
  34. protected function setParams($params) {
  35. $this->_params = $params;
  36. }
  37. protected function getParams() {
  38. return $this->_params;
  39. }
  40. protected function getRequest() {
  41. return $this->_request;
  42. }
  43. protected function setRequest($request) {
  44. $this->_request = $request;
  45. }
  46. protected abstract function checkToken();
  47. protected abstract function success($data);
  48. protected abstract function mountRequest();
  49. protected abstract function beforeSetRequest();
  50. protected abstract function afterSetRequest();
  51. }