User.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 用户管理
  7. */
  8. namespace app\fastshop\controller;
  9. use app\common\controller\Manage;
  10. use app\common\model\SystemUserLevel;
  11. use think\facade\Validate;
  12. class User extends Manage
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. if(!model('auth')->getAuth($this->user->id,4)){
  18. $this->error('无权限,你非【订单管理员】');
  19. }
  20. $this->assign('pathMaps', [['name'=>'用户管理','url'=>'javascript:;']]);
  21. }
  22. /**
  23. * 会员列表
  24. */
  25. public function index($types = 0){
  26. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  27. $condition['is_lock'] = $types ? 1 : 0;
  28. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  29. $search = [];
  30. if(!empty($keyword)){
  31. if(Validate::mobile($keyword)){
  32. $search['phone_uid'] = $keyword;
  33. }else{
  34. $search[] = ["nickname","like","%{$keyword}%"];
  35. }
  36. }
  37. $view['keyword'] = input('get.keyword');
  38. $view['list'] = model('SystemUser')->where($condition)->where($search)->order('id desc')->paginate(20,false,['query'=>['types'=>$types]]);
  39. $view['types'] = $types;
  40. return view()->assign($view);
  41. }
  42. /**
  43. * 会员列表
  44. */
  45. public function select(){
  46. if(request()->isAjax()){
  47. $ids = input('post.ids/s');
  48. if(empty($ids)){
  49. return json(['code'=>0,'msg'=>'请选择要添加代理的用户']);
  50. }
  51. $result = model('Agent')->add($this->member_miniapp_id,ids($ids,true));
  52. if($result){
  53. return json(['code'=>302,'msg'=>'代理用户添加成功','data' =>[]]);
  54. }else{
  55. return json(['code'=>0,'msg'=>'代理用户添加操作失败']);
  56. }
  57. }else{
  58. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  59. $condition['is_lock'] = 0;
  60. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  61. if(!empty($keyword)){
  62. $condition['phone_uid'] = $keyword;
  63. }
  64. $view['keyword'] = input('get.keyword');
  65. $view['list'] = model('Agent')->selects($condition);
  66. return view()->assign($view);
  67. }
  68. }
  69. /**
  70. * 代理管理
  71. */
  72. public function agent(){
  73. $keyword = trim(input('get.keyword','','htmlspecialchars'));
  74. $condition['fastshop_agent.member_miniapp_id'] = $this->member_miniapp_id;
  75. if(!empty($keyword)){
  76. $condition['system_user.phone_uid'] = $keyword;
  77. }
  78. $view['keyword'] = input('get.keyword');
  79. $view['list'] = model('Agent')->lists($condition);
  80. return view()->assign($view);
  81. }
  82. /**
  83. * 编辑用户
  84. * @access public
  85. */
  86. public function edit(){
  87. if(request()->isAjax()){
  88. $data = [
  89. 'id' => input('post.id/d'),
  90. 'password' => input('post.password/s'),
  91. 'safepassword' => input('post.safepassword/s'),
  92. ];
  93. $updata = [];
  94. if ($data['safepassword']) {
  95. $validate = $this->validate($data, 'User.safepassword');
  96. if (true !== $validate) {
  97. return json(['code'=>0,'msg'=>$validate]);
  98. }
  99. $updata['safe_password'] = password_hash(md5($data['safepassword']),PASSWORD_DEFAULT);
  100. }
  101. if($data['password']){
  102. $updata['password'] = password_hash(md5($data['password']),PASSWORD_DEFAULT);
  103. }
  104. if(empty($data['password']) && empty($data['password'])){
  105. return json(['code'=>0,'msg'=>'操作失败']);
  106. }
  107. $result = model('SystemUser')->edit($updata,$data['id']);
  108. if(!$result){
  109. return json(['code'=>0,'msg'=>'操作失败']);
  110. }else{
  111. return json(['code'=>200,'msg'=>'操作成功','url' => url('user/index')]);
  112. }
  113. }else{
  114. $id = input('id/d');
  115. $view['info'] = model('SystemUser')->get(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id]);
  116. if(!$view['info']){
  117. return $this->error("404 NOT FOUND");
  118. }
  119. return view('edit',$view);
  120. }
  121. }
  122. /**
  123. * 编辑用户
  124. * @access public
  125. */
  126. public function agentedit(){
  127. if(request()->isAjax()){
  128. $data = [
  129. 'id' => input('post.id/d'),
  130. 'rebate' => input('post.rebate/d'),
  131. ];
  132. $result = model('Agent')->where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $data['id']])->update(['rebate' =>$data['rebate']]);
  133. if(!$result){
  134. return json(['code'=>0,'msg'=>'操作失败']);
  135. }else{
  136. return json(['code'=>200,'msg'=>'操作成功','url' => url('user/agent')]);
  137. }
  138. }else{
  139. $id = input('id/d');
  140. $view['agent'] = model('Agent')->get(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id]);
  141. if(!$view['agent']){
  142. return $this->error("404 NOT FOUND");
  143. }
  144. $view['info'] = model('SystemUser')->get(['member_miniapp_id' => $this->member_miniapp_id,'id' => $view['agent']['user_id']]);
  145. $view['user_number'] = model('SystemUserLevel')->where(['parent_id' => $view['agent']['user_id']])->count();
  146. return view()->assign($view);
  147. }
  148. }
  149. /**
  150. * 锁定
  151. * @param integer $id 用户ID
  152. */
  153. public function islock(int $id){
  154. $result = model('SystemUser')->lock($id);
  155. if(!$result){
  156. return json(['code'=>0,'message'=>'操作失败']);
  157. }else{
  158. return json(['code'=>200,'message'=>'操作成功']);
  159. }
  160. }
  161. //删除
  162. public function agentdelete(){
  163. $id = input('get.id/d');
  164. $result = model('Agent')->where(['member_miniapp_id' => $this->member_miniapp_id,'id' =>$id])->delete();
  165. if($result){
  166. return json(['code'=>200,'msg'=>'操作成功']);
  167. }else{
  168. return json(['code'=>403,'msg'=>'删除失败']);
  169. }
  170. }
  171. /**
  172. * 伞下
  173. */
  174. public function pyramid(int $id){
  175. $view['pathMaps'] = [['name'=>'用户管理','url'=>url('passport.user/index')],['name'=>'伞下用户','url'=>'javascript:;']];
  176. $view['uid'] = $id;
  177. $view['people_num'] = SystemUserLevel::where(['parent_id' => $id])->count();
  178. $config = model('Config')->where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  179. $allmoney = 0;
  180. if($config->reward_types == 1){
  181. $uid = SystemUserLevel::where(['parent_id' => $id])->column('user_id');
  182. $uid[] = $id;
  183. $allmoney = Model('BankAll')->where(['uid' => $uid])->sum('account');
  184. }
  185. $view['config'] = $config;
  186. $view['allmoney'] = $allmoney;
  187. return view()->assign($view);
  188. }
  189. }