User.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\popupshop\controller;
  9. use app\common\controller\Manage;
  10. use app\common\model\SystemUser;
  11. use app\common\model\SystemUserLevel;
  12. use app\popupshop\model\Agent;
  13. use think\facade\Request;
  14. use think\facade\Validate;
  15. class User extends Manage
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. $this->assign('pathMaps', [['name'=>'代理管理','url'=>'javascript:;']]);
  21. }
  22. /**
  23. * 代理管理
  24. */
  25. public function agent(){
  26. $view['list'] = Agent::where(['member_miniapp_id' => $this->member_miniapp_id])->order('id desc')->paginate(20);;
  27. return view()->assign($view);
  28. }
  29. /**
  30. * 会员列表
  31. */
  32. public function select(){
  33. if(request()->isAjax()){
  34. $ids = Request::param('ids/s');
  35. if(empty($ids)){
  36. return json(['code'=>0,'msg'=>'请选择要添加代理的用户']);
  37. }
  38. $result = Agent::add($this->member_miniapp_id,(array)ids($ids,true));
  39. if($result){
  40. return json(['code'=>302,'msg'=>'代理用户添加成功','data' =>[]]);
  41. }else{
  42. return json(['code'=>0,'msg'=>'代理用户添加操作失败']);
  43. }
  44. }else{
  45. $keyword = Request::param('keyword');
  46. $condition = [];
  47. if(!empty($keyword)){
  48. $condition['phone_uid'] = $keyword;
  49. }
  50. $condition['is_lock'] = 0;
  51. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  52. $view['list'] = Agent::selects($condition);
  53. $view['keyword'] = $keyword;
  54. return view()->assign($view);
  55. }
  56. }
  57. /**
  58. * 编辑用户
  59. * @access public
  60. */
  61. public function agentedit(){
  62. if(request()->isAjax()){
  63. $data = [
  64. 'id' => Request::param('id/d'),
  65. 'rebate' => Request::param('rebate/d'),
  66. ];
  67. $result = Agent::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $data['id']])->update(['rebate' =>$data['rebate']]);
  68. if(!$result){
  69. return json(['code'=>0,'msg'=>'操作失败']);
  70. }else{
  71. return json(['code'=>200,'msg'=>'操作成功','url' => url('user/agent')]);
  72. }
  73. }else{
  74. $id = Request::param('id/d');
  75. $view['agent'] = Agent::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->find();
  76. if(!$view['agent']){
  77. return $this->error("404 NOT FOUND");
  78. }
  79. $view['info'] = SystemUser::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $view['agent']['user_id']])->find();
  80. $view['user_number'] = SystemUserLevel::where(['parent_id' => $view['agent']['user_id']])->count();
  81. return view()->assign($view);
  82. }
  83. }
  84. //删除
  85. public function agentdelete(){
  86. $result = Agent::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => Request::param('id/d',0)])->delete();
  87. if($result){
  88. return json(['code'=>200,'msg'=>'操作成功']);
  89. }else{
  90. return json(['code'=>403,'msg'=>'删除失败']);
  91. }
  92. }
  93. }