UsersrolesController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\UsersRoles;
  5. class UsersrolesController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = trim(input('post.keyword', '', 'serach_in'));
  11. $status = trim(input('post.status', '', 'serach_in'));
  12. $where = [];
  13. $where['weid'] = $weid;
  14. $where['sid'] = (int) $this->sid;
  15. $where['ocid'] = (int) $this->ocid;
  16. $where['tzid'] = (int) $this->tzid;
  17. if ($status !== '') {
  18. $where['status'] = $status;
  19. }
  20. $field = 'id,pid,title,status,description';
  21. $query = UsersRoles::where($where);
  22. if (!empty($keyword)) {
  23. $query->where('title', 'like', '%' . $keyword . '%');
  24. }
  25. //UsersRoles::getsonid($this->userInfo['role_id']);
  26. $query->field($field)->order('id asc');
  27. $datalist = $query->select()->toArray();
  28. if (empty($datalist) && empty($this->sid) && empty($this->ocid) && empty($this->tzid)) {
  29. UsersRoles::datainitial();
  30. $datalist = $query->select()->toArray();
  31. }
  32. $pid = $this->userInfo['role_id'];
  33. if (!empty($pid)) {
  34. $tmppid = UsersRoles::getPid($pid);
  35. if ($tmppid == 0) {
  36. $pid = 0;
  37. }
  38. }
  39. $data['data'] = $datalist;
  40. return $this->json($data);
  41. }
  42. function listUpdate()
  43. {
  44. $data = only('id,status');
  45. if (!$data['id']) throw new ValidateException('参数错误');
  46. UsersRoles::update($data);
  47. return $this->json(['msg' => '操作成功']);
  48. }
  49. public function update()
  50. {
  51. $weid = weid();
  52. $id = $this->request->post('id');
  53. $data = input('post.');
  54. if (!in_array('Home', $data['access'])) {
  55. array_push($data['access'], 'Home');
  56. }
  57. if (!empty($data['access'])) {
  58. $data['access'] = implode(',', $data['access']);
  59. }
  60. if ($weid == 0) {
  61. $data['is_console'] = 1;
  62. } else {
  63. $data['is_console'] = 0;
  64. }
  65. if (empty($id)) {
  66. $data['weid'] = (int) $weid;
  67. $data['sid'] = (int) $this->sid;
  68. $data['ocid'] = (int) $this->ocid;
  69. $data['tzid'] = (int) $this->tzid;
  70. $res = UsersRoles::create($data);
  71. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  72. } else {
  73. UsersRoles::update($data);
  74. return $this->json(['msg' => '修改成功']);
  75. }
  76. }
  77. function getInfo()
  78. {
  79. $id = $this->request->post('id', '', 'serach_in');
  80. if (!$id) $this->error('参数错误');
  81. $res = UsersRoles::find($id);
  82. if (!empty($res)) {
  83. $res = $res->toArray();
  84. }
  85. if(!empty($res['scope'])) {
  86. $res['scope'] = explode(',', $res['scope']);
  87. }
  88. if(!empty($res['access'])) {
  89. $res['access'] = explode(',', $res['access']);
  90. }
  91. return $this->json(['data' => $res]);
  92. }
  93. function delete()
  94. {
  95. return $this->del(new UsersRoles());
  96. }
  97. function getField()
  98. {
  99. $data['pids'] = UsersRoles::getpcarray(['ocid' => $this->ocid, 'sid' => $this->sid, 'tzid' => $this->tzid]);
  100. return $this->json(['data' => $data]);
  101. }
  102. }