1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * 字段授权控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-02
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\FieldGrantLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class FieldGrant extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission'=>[''],
  24. 'allow'=>['index', 'update']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. }
  33. /**
  34. * 字段授权列表
  35. *
  36. * @param FieldGrantLogic $fieldGrantLogic
  37. * @return \think\response\Json
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public function index(FieldGrantLogic $fieldGrantLogic)
  43. {
  44. $data = $fieldGrantLogic->index($this->param);
  45. return resultArray(['data' => $data]);
  46. }
  47. /**
  48. * 更新授权信息
  49. *
  50. * @param FieldGrantLogic $fieldGrantLogic
  51. * @return \think\response\Json
  52. * @throws \think\Exception
  53. * @throws \think\exception\PDOException
  54. */
  55. public function update(FieldGrantLogic $fieldGrantLogic)
  56. {
  57. if (empty($this->param['grant_id'])) return resultArray(['error' => '缺少授权ID!']);
  58. if (empty($this->param['content'])) return resultArray(['error' => '缺少授权数据!']);
  59. $status = $fieldGrantLogic->update($this->param['grant_id'], $this->param['content']);
  60. if ($status === false) {
  61. return resultArray(['error' => '更新授权信息失败!']);
  62. }
  63. return resultArray(['data' => '更新授权信息成功!']);
  64. }
  65. }