Rules.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 规则
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\controller;
  8. use think\Hook;
  9. use think\Request;
  10. class Rules extends ApiCommon
  11. {
  12. /**
  13. * 用于判断权限
  14. * @permission 无限制
  15. * @allow 登录用户可访问
  16. * @other 其他根据系统设置
  17. **/
  18. public function _initialize()
  19. {
  20. $action = [
  21. 'permission'=>[''],
  22. 'allow'=>['index']
  23. ];
  24. Hook::listen('check_auth',$action);
  25. $request = Request::instance();
  26. $a = strtolower($request->action());
  27. if (!in_array($a, $action['permission'])) {
  28. parent::_initialize();
  29. }
  30. $m = $this->m;
  31. $c = $this->c;
  32. $a = $this->a;
  33. }
  34. public function index()
  35. {
  36. $ruleModel = model('Rule');
  37. $param = $this->param;
  38. $data = $ruleModel->getDataList($param);
  39. return resultArray(['data' => $data]);
  40. }
  41. /**
  42. * 新建规则
  43. * @param
  44. * @return
  45. */
  46. public function save()
  47. {
  48. $ruleModel = model('Rule');
  49. $param = $this->param;
  50. $data = $ruleModel->createData($param);
  51. if (!$data) {
  52. return resultArray(['error' => $ruleModel->getError()]);
  53. }
  54. return resultArray(['data' => '添加成功']);
  55. }
  56. /**
  57. * 编辑规则
  58. * @param
  59. * @return
  60. */
  61. public function update()
  62. {
  63. $ruleModel = model('Rule');
  64. $param = $this->param;
  65. $data = $ruleModel->updateDataById($param, $param['id']);
  66. if (!$data) {
  67. return resultArray(['error' => $ruleModel->getError()]);
  68. }
  69. return resultArray(['data' => '编辑成功']);
  70. }
  71. }