SupplierAdmin.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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\supplier\system;
  12. use app\controller\supplier\AuthController;
  13. use app\services\supplier\LoginServices;
  14. use app\services\supplier\SystemSupplierServices;
  15. use app\services\system\admin\SystemAdminServices;
  16. use think\facade\{App};
  17. /**
  18. * Class SystemAdmin
  19. * @package app\controller\admin\v1\setting
  20. */
  21. class SupplierAdmin extends AuthController
  22. {
  23. /**
  24. * @var LoginServices|null
  25. */
  26. protected $services = NUll;
  27. /**
  28. * @var SystemAdminServices|null
  29. */
  30. protected $adminServices = NUll;
  31. /**
  32. * SystemAdmin constructor.
  33. * @param App $app
  34. * @param SystemSupplierServices $services
  35. * @param SystemAdminServices $adminServices
  36. */
  37. public function __construct(App $app, SystemSupplierServices $services, SystemAdminServices $adminServices)
  38. {
  39. parent::__construct($app);
  40. $this->services = $services;
  41. $this->adminServices = $adminServices;
  42. }
  43. /**
  44. * 显示管理员资源列表
  45. *
  46. * @return \think\Response
  47. */
  48. public function index()
  49. {
  50. $where = [
  51. 'is_del' => 1,
  52. 'admin_type' => 4,
  53. 'relation_id' => $this->supplierId,
  54. 'level' => 1
  55. ];
  56. return $this->success($this->adminServices->getAdminList($where));
  57. }
  58. /**
  59. * 创建表单
  60. * @return mixed
  61. * @throws \FormBuilder\Exception\FormBuilderException
  62. */
  63. public function create()
  64. {
  65. return $this->success($this->adminServices->createForm(0, '/admin'));
  66. }
  67. /**
  68. * 保存管理员
  69. * @return mixed
  70. */
  71. public function save()
  72. {
  73. $data = $this->request->postMore([
  74. ['account', ''],
  75. ['phone', ''],
  76. ['conf_pwd', ''],
  77. ['pwd', ''],
  78. ['real_name', ''],
  79. ['phone', ''],
  80. ['roles', []],
  81. ['status', 0],
  82. ['head_pic', ''],
  83. ]);
  84. $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_save');
  85. $data['admin_type'] = 4;
  86. $data['relation_id'] = $this->supplierId;
  87. if ($this->adminServices->create($data)) {
  88. return $this->success('添加成功');
  89. } else {
  90. return $this->fail('添加失败');
  91. }
  92. }
  93. /**
  94. * 显示编辑资源表单页.
  95. *
  96. * @param int $id
  97. * @return \think\Response
  98. */
  99. public function edit(int $id)
  100. {
  101. if (!$id) {
  102. return $this->fail('管理员信息读取失败');
  103. }
  104. return $this->success($this->adminServices->updateForm(0, (int)$id, '/admin/'));
  105. }
  106. /**
  107. * 更新管理员
  108. * @param int $id
  109. * @return mixed
  110. */
  111. public function update(int $id)
  112. {
  113. $data = $this->request->postMore([
  114. ['account', ''],
  115. ['phone', ''],
  116. ['conf_pwd', ''],
  117. ['pwd', ''],
  118. ['real_name', ''],
  119. ['phone', ''],
  120. ['roles', []],
  121. ['status', 0],
  122. ['head_pic', ''],
  123. ]);
  124. $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'supplier_update');
  125. if ($this->adminServices->save($id, $data)) {
  126. return $this->success('修改成功');
  127. } else {
  128. return $this->fail('修改失败');
  129. }
  130. }
  131. /**
  132. * 管理员详情
  133. * @param int $id
  134. * @return mixed
  135. */
  136. public function read(int $id)
  137. {
  138. $info = $this->adminServices->get($id);
  139. if (!$info) {
  140. return $this->fail('获取失败');
  141. }
  142. return $this->success($info->toArray());
  143. }
  144. /**
  145. * 删除管理员
  146. * @param int $id
  147. * @return void
  148. */
  149. public function delete(int $id)
  150. {
  151. if (!$id) {
  152. return $this->fail('删除失败,缺少参数');
  153. }
  154. if ($this->adminServices->update($id, ['is_del' => 1, 'status' => 0])) {
  155. return $this->success('删除成功!');
  156. } else {
  157. return $this->fail('删除失败');
  158. }
  159. }
  160. /**
  161. * 修改状态
  162. * @param $id
  163. * @param $status
  164. * @return mixed
  165. */
  166. public function set_status($id, $status)
  167. {
  168. $this->adminServices->update((int)$id, ['status' => $status]);
  169. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  170. }
  171. }