AuthController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/9/22
  8. * Time: 13:37
  9. */
  10. namespace business\admin\controllers;
  11. use business\common\models\Staff;
  12. use business\common\services\AuthService;
  13. use business\common\services\BusinessService;
  14. use business\common\services\SettingService;
  15. use business\common\controllers\components\BaseController;
  16. /**
  17. * controller基类
  18. *
  19. * Author: 芸众商城 www.yunzshop.com
  20. * Date: 21/02/2017
  21. * Time: 21:20
  22. */
  23. class AuthController extends BaseController
  24. {
  25. /*
  26. * 设置成员权限
  27. */
  28. public function setStaffAuthType()
  29. {
  30. $right = BusinessService::checkBusinessRight();
  31. if ($right['identity'] < 2) {
  32. return $this->errorJson('无权设置成员权限');
  33. }
  34. }
  35. /*
  36. * 获取权限列表
  37. */
  38. public function getAuthList()
  39. {
  40. $right = BusinessService::checkBusinessRight();
  41. if ($right['identity'] < 2) {
  42. return $this->errorJson('无权操作');
  43. }
  44. $request = \request();
  45. $list = AuthService::getAuthList($request->department_id ?: 0, $request->is_leader ? 1 : 0, $request->staff_id ?: 0);
  46. if (!$list['result']) {
  47. return $this->errorJson($list['msg']);
  48. }
  49. $auth_list = $list['data'];
  50. $plugin_list = SettingService::PLUGIN_LIST;
  51. $tab_list = [
  52. ['key' => 'admin', 'name' => '基础权限'],
  53. ];
  54. foreach ($plugin_list as $k => $v) {
  55. if (app('plugins')->isEnabled($k)) $tab_list[] = $v;
  56. }
  57. if ($request->staff_id) {
  58. $staff = Staff::business()->find($request->staff_id);
  59. $right_type = $staff->right_type;
  60. } else {
  61. $right_type = 0;
  62. }
  63. return $this->successJson('成功', ['auth_list' => $auth_list, 'tab_list' => $tab_list, 'right_type' => $right_type]);
  64. }
  65. /*
  66. * 设置权限
  67. */
  68. public function setAuth()
  69. {
  70. $request = \request();
  71. $res = AuthService::setAuth($request->auth, $request->department_id ?: 0, $request->is_leader ? 1 : 0, $request->staff_id ?: 0, $request->right_type ?: 0);
  72. if (!$res['result']) {
  73. return $this->errorJson($res['msg']);
  74. }
  75. BusinessService::flush(SettingService::getBusinessId()); //清除企业缓存
  76. return $this->successJson('编辑成功');
  77. }
  78. }