UserGroup.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\user;
  12. use app\controller\admin\AuthController;
  13. use app\services\user\group\UserGroupServices;
  14. use think\facade\App;
  15. /**
  16. * 会员设置
  17. * Class UserLevel
  18. * @package app\controller\admin\v1\user
  19. */
  20. class UserGroup extends AuthController
  21. {
  22. /**
  23. * user constructor.
  24. * @param App $app
  25. * @param UserGroupServices $services
  26. */
  27. public function __construct(App $app, UserGroupServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 分组列表
  34. */
  35. public function index()
  36. {
  37. return $this->success($this->services->getGroupList('*', true));
  38. }
  39. /**
  40. * 添加/修改分组页面
  41. * @param int $id
  42. * @return string
  43. */
  44. public function add()
  45. {
  46. $data = $this->request->getMore([
  47. ['id', 0],
  48. ]);
  49. return $this->success($this->services->add((int)$data['id']));
  50. }
  51. /**
  52. *
  53. * @param int $id
  54. * @return mixed
  55. */
  56. public function save()
  57. {
  58. $data = $this->request->postMore([
  59. ['id', 0],
  60. ['group_name', ''],
  61. ]);
  62. if (!$data['group_name']) {
  63. return $this->fail('请输入分组名称');
  64. }
  65. $this->services->save((int)$data['id'], $data);
  66. return $this->success('提交成功!');
  67. }
  68. /**
  69. * 删除
  70. * @param $id
  71. * @throws \Exception
  72. */
  73. public function delete()
  74. {
  75. $data = $this->request->getMore([
  76. ['id', 0],
  77. ]);
  78. if (!$data['id']) return $this->fail('数据不存在');
  79. return $this->success($this->services->delGroup((int)$data['id']));
  80. }
  81. }