Member.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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\system\controller\admin;
  9. use app\common\controller\Admin;
  10. use app\common\model\SystemMember;
  11. use app\common\model\SystemMemberMiniapp;
  12. use app\common\model\SystemMemberBank;
  13. use app\common\model\SystemMemberBankBill;
  14. use app\common\event\Passport;
  15. use think\facade\Request;
  16. class Member extends Admin{
  17. public function initialize(){
  18. parent::initialize();
  19. $this->assign('pathMaps', [['name'=>'用户管理','url'=>url("system/admin.member/index")]]);
  20. }
  21. /**
  22. * 会员列表
  23. */
  24. public function index($types = 0){
  25. $keyword = $this->request->param('keyword');
  26. $condition['is_lock'] = $types ? 1 : 0;
  27. $condition['parent_id'] = 0;
  28. if(!empty($keyword)){
  29. $condition['phone_id'] = $keyword;
  30. }
  31. $view['keyword'] = $this->request->param('keyword');
  32. $view['list'] = SystemMember::where($condition)->order('id desc')->paginate(20,false,['query'=>['types'=>$types]]);
  33. $view['money'] = SystemMemberBank::sum('money');
  34. $view['lack_money'] = SystemMemberBank::sum('lack_money');
  35. $view['consume'] = SystemMemberBankBill::where(['state' => 1])->sum('money');
  36. $view['types'] = $types;
  37. return view()->assign($view);
  38. }
  39. /**
  40. * 用户列表
  41. */
  42. public function select(){
  43. $keyword = $this->request->param('keyword');
  44. $condition['is_lock'] = 0;
  45. if(!empty($keyword)){
  46. $condition['phone_id'] = $keyword;
  47. }
  48. $view['keyword'] = $this->request->param('keyword');
  49. $view['input'] = $this->request->param('input');
  50. $view['list'] = SystemMember::where($condition)->order('id desc')->paginate(20);
  51. return view()->assign($view);
  52. }
  53. /**
  54. * 会员列表
  55. */
  56. public function add(){
  57. if(request()->isAjax()){
  58. $data = [
  59. 'username' => $this->request->param('username/s'),
  60. 'login_password' => $this->request->param('password/s'),
  61. 'safe_password' => $this->request->param('safe_password/s'),
  62. 'phone_id' => $this->request->param('phone/d'),
  63. 'lock_config' => 0,
  64. ];
  65. $validate = $this->validate($data,'Member.add');
  66. if(true !== $validate){
  67. return json(['code'=>0,'msg'=>$validate]);
  68. }
  69. //判断手机号是否重复
  70. $info = SystemMember::where(['phone_id' => $data['phone_id']])->find();
  71. if(!empty($info)){
  72. return json(['code'=>0,'msg'=>'注册手机账号已存在']);
  73. }
  74. $result = SystemMember::edit($data);
  75. if(!$result){
  76. return json(['code'=>0,'msg'=>'操作失败']);
  77. }else{
  78. return json(['code'=>200,'msg'=>'操作成功','url'=>url('system/admin.member/index')]);
  79. }
  80. }else{
  81. return view();
  82. }
  83. }
  84. /**
  85. * 编辑用户
  86. */
  87. public function edit(){
  88. if(request()->isAjax()){
  89. $data = [
  90. 'id' => $this->request->param('id/d'),
  91. 'username' => $this->request->param('username/s'),
  92. 'phone_id' => $this->request->param('phone/d'),
  93. 'edit_login_password' => $this->request->param('password/s'),
  94. 'edit_safe_password' => $this->request->param('safe_password/s'),
  95. 'lock_config' => $this->request->param('lock_config/d',0),
  96. ];
  97. $validate = $this->validate($data,'Member.edit');
  98. if(true !== $validate){
  99. return json(['code'=>0,'msg'=>$validate]);
  100. }
  101. $data['login_password'] = $data['edit_login_password'];
  102. $data['safe_password'] = $data['edit_safe_password'];
  103. $result = SystemMember::edit($data);
  104. if(!$result){
  105. return json(['code'=>0,'msg'=>'操作失败']);
  106. }else{
  107. return json(['code'=>200,'msg'=>'操作成功','url'=>url('system/admin.member/index')]);
  108. }
  109. }else{
  110. $id = $this->request->param('id/d');
  111. $info = SystemMember::where(['id'=>$id])->find();
  112. if(!$info){
  113. return $this->error("404 NOT FOUND");
  114. }
  115. $view['info'] = $info;
  116. return view()->assign($view);
  117. }
  118. }
  119. /**
  120. * 检测手机号是否重复
  121. */
  122. public function isphone(){
  123. $userid = $this->request->param('id/d');
  124. $value = $this->request->param('param/s');
  125. if($userid){
  126. $result = SystemMember::where('id','<>',$userid)->where(['phone_id' => $value])->find();
  127. }else{
  128. $result = SystemMember::where(['phone_id' => $value])->find();
  129. }
  130. if($result){
  131. return json(['status'=>'n','info'=>'手机号已存在']);
  132. }else{
  133. return json(['status'=>'y','info'=>'可以使用']);
  134. }
  135. }
  136. /**
  137. * 锁定
  138. * @param integer $id 用户ID
  139. */
  140. public function islock(int $id){
  141. $result = SystemMember::lock($id);
  142. if(!$result){
  143. return json(['code'=>0,'message'=>'操作失败']);
  144. }else{
  145. return json(['code'=>200,'message'=>'操作成功']);
  146. }
  147. }
  148. /**
  149. * 管理中心
  150. * @param integer $id 用户ID
  151. */
  152. public function manage(){
  153. $uid = Request::param('uid/d',0);
  154. if($uid){
  155. $condition['member_id'] = $uid;
  156. }
  157. $id = Request::param('id/d',0);
  158. if($id){
  159. $condition['id'] = $id;
  160. }
  161. if(empty($condition)){
  162. return $this->error("参数不能为空");
  163. }
  164. Passport::clearMiniapp();
  165. Passport::setlogout();
  166. if($id){
  167. $rel = SystemMemberMiniapp::where($condition)->find();
  168. if(empty($rel)){
  169. return $this->error("当前用户未开通任何应用");
  170. }
  171. $uid = $rel->member_id;
  172. if($rel['is_lock'] == 0){
  173. Passport::setMiniapp(['member_id' => $rel['member_id'],'miniapp_id' => $rel['miniapp_id'],'member_miniapp_id' => $rel['id']]);
  174. }
  175. }
  176. $member = SystemMember::where(['id' => $uid])->find();
  177. if(empty($member) || $member['is_lock'] == 1){
  178. Passport::clearMiniapp();
  179. $this->error("帐号已被锁定,禁止管理");
  180. }
  181. Passport::setLogin($member);
  182. $this->redirect(url('system/passport.index/index'),302);
  183. }
  184. /**
  185. * 用户账单
  186. * @return void
  187. */
  188. public function bill(){
  189. $uid = Request::param('uid/d',0);
  190. $view['bank'] = SystemMemberBank::where(['member_id' =>$uid])->find();
  191. $view['consume'] = SystemMemberBankBill::where(['member_id' => $uid,'state' => 1])->sum('money');
  192. $view['list'] = SystemMemberBankBill::where(['member_id' => $uid])->order('update_time desc')->paginate(20,false,['query'=>['uid' => $uid]]);
  193. $view['pathMaps'] = [['name'=>'用户管理','url'=>'javascript:;'],['name'=>'财务管理','url'=>'javascript:;']];
  194. return view()->assign($view);
  195. }
  196. }