Admin.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace app\data\controller\user;
  3. use app\data\model\BaseUserUpgrade;
  4. use app\data\model\DataUser;
  5. use app\data\service\UserAdminService;
  6. use app\data\service\UserUpgradeService;
  7. use think\admin\Controller;
  8. /**
  9. * 普通用户管理
  10. * Class Admin
  11. * @package app\data\controller\user
  12. */
  13. class Admin extends Controller
  14. {
  15. /**
  16. * 普通用户管理
  17. * @auth true
  18. * @menu true
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\DbException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. */
  23. public function index()
  24. {
  25. // 用户等级分组
  26. [$ts, $ls] = [[], BaseUserUpgrade::items()];
  27. $ts['ta'] = ['vip' => '', 'name' => '全部用户', 'count' => 0];
  28. foreach ($ls as $k => $v) $ts["t{$k}"] = ['vip' => $k, 'name' => $v['name'], 'count' => 0,];
  29. $ts['to'] = ['vip' => '', 'name' => '其他用户', 'count' => 0];
  30. if (empty($ts['to']['count'])) unset($ts['to']);
  31. $this->total = $ts;
  32. // 设置页面标题
  33. $this->title = '普通用户管理';
  34. // 创建查询对象
  35. $query = DataUser::mQuery()->order('id desc');
  36. // 数据筛选选项
  37. $this->type = ltrim(input('type', 'ta'), 't');
  38. // 数据查询分页
  39. $query->like('phone|username|nickname#username')->equal('status')->dateBetween('create_at')->page();
  40. }
  41. /**
  42. * 数据列表处理
  43. * @param array $data
  44. */
  45. protected function _page_filter(array &$data)
  46. {
  47. // dump($data);die;
  48. }
  49. /**
  50. * 用户团队关系
  51. * @auth true
  52. * @menu true
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function teams()
  58. {
  59. // $this->title = '用户团队关系';
  60. // $map = ['pid1' => input('from', 0)];
  61. // DataUser::mQuery()->where($map)->page(false);
  62. }
  63. /**
  64. * 数据列表处理
  65. * @param array $data
  66. */
  67. protected function _teams_page_filter(array &$data)
  68. {
  69. $uids = array_unique(array_column($data, 'id'));
  70. $subCount = DataUser::mk()->whereIn('pid1', $uids)->group('pid1')->column('count(1) count', 'pid1');
  71. foreach ($data as &$vo) $vo['subCount'] = $subCount[$vo['id']] ?? 0;
  72. }
  73. /**
  74. * 永久绑定代理
  75. * @auth false
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function forever()
  81. {
  82. $map = $this->_vali(['id.require' => '用户ID不能为空!']);
  83. $user = DataUser::mk()->where($map)->find();
  84. if (empty($user) || empty($user['pid0'])) $this->error('用户不符合操作要求!');
  85. [$status, $message] = UserUpgradeService::bindAgent($user['id'], $user['pid0']);
  86. $status && sysoplog('前端用户管理', "修改用户[{$map['id']}]的代理为永久状态");
  87. empty($status) ? $this->error($message) : $this->success($message);
  88. }
  89. /**
  90. * 设为总部用户
  91. * @auth false
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. */
  96. public function unbind()
  97. {
  98. $map = $this->_vali(['id.require' => '用户ID不能为空!']);
  99. $user = DataUser::mk()->where($map)->findOrEmpty();
  100. if ($user->isEmpty()) $this->error('用户不符合操作要求!');
  101. // 修改指定用户代理数据
  102. $user->save(['pid0' => 0, 'pid1' => 0, 'pid2' => 0, 'pids' => 1, 'path' => '-', 'layer' => 1]);
  103. // 刷新用户等级及上级等级
  104. UserUpgradeService::upgrade($user['id'], true);
  105. sysoplog('前端用户管理', "设置用户[{$map['id']}]为总部用户");
  106. $this->success('设为总部用户成功!');
  107. }
  108. /**
  109. * 绑定上级代理
  110. * @auth false
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\DbException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. */
  115. public function parent()
  116. {
  117. if ($this->request->isGet()) {
  118. } else {
  119. $data = $this->_vali(['pid.require' => '待绑定代理不能为空!', 'uuid.require' => '待操作用户不能为空!']);
  120. [$status, $message] = UserUpgradeService::bindAgent($data['uuid'], $data['pid'], 2);
  121. $status && sysoplog('前端用户管理', "修改用户[{$data['uuid']}]的代理为用户[{$data['pid']}]");
  122. empty($status) ? $this->error($message) : $this->success($message);
  123. }
  124. }
  125. /**
  126. * 重算用户余额返利
  127. * @auth false
  128. */
  129. public function sync()
  130. {
  131. $this->_queue('重新计算用户余额返利', 'xdata:UserAmount');
  132. }
  133. /**
  134. * 修改用户状态
  135. * @auth true
  136. */
  137. public function state()
  138. {
  139. DataUser::mSave($this->_vali([
  140. 'status.in:0,1' => '状态值范围异常!',
  141. 'status.require' => '状态值不能为空!',
  142. ]));
  143. }
  144. }