Base.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace plugin\admin\app\controller;
  3. use support\Model;
  4. use support\Response;
  5. /**
  6. * 基础控制器
  7. */
  8. class Base
  9. {
  10. /**
  11. * @var Model
  12. */
  13. protected $model = null;
  14. /**
  15. * 无需登录及鉴权的方法
  16. * @var array
  17. */
  18. protected $noNeedLogin = [];
  19. /**
  20. * 需要登录无需鉴权的方法
  21. * @var array
  22. */
  23. protected $noNeedAuth = [];
  24. /**
  25. * 数据限制
  26. * null 不做限制,任何管理员都可以查看该表的所有数据
  27. * auth 管理员能看到自己以及自己的子管理员插入的数据
  28. * personal 管理员只能看到自己插入的数据
  29. * @var string
  30. */
  31. protected $dataLimit = null;
  32. /**
  33. * 数据限制字段
  34. */
  35. protected $dataLimitField = 'admin_id';
  36. /**
  37. * 返回格式化json数据
  38. *
  39. * @param int $code
  40. * @param string $msg
  41. * @param array $data
  42. * @return Response
  43. */
  44. protected function json(int $code, string $msg = 'ok', array $data = []): Response
  45. {
  46. return json(['code' => $code, 'data' => $data, 'msg' => $msg]);
  47. }
  48. protected function success(string $msg = '成功', array $data = []): Response
  49. {
  50. return $this->json(0, $msg, $data);
  51. }
  52. protected function fail(string $msg = '失败', array $data = []): Response
  53. {
  54. return $this->json(1, $msg, $data);
  55. }
  56. }