| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- <?php
- namespace app\cmgadm\controller\user;
- use app\common\controller\Backend;
- use fast\Random;
- use think\Db;
- /**
- * 会员管理
- *
- * @icon fa fa-user
- */
- class User extends Backend
- {
- protected $relationSearch = true;
- /**
- * @var \app\cmgadm\model\User
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('User');
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->with('group')
- ->where($where)
- ->where(['ct_user.status'=>['neq',0]])
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->with('group')
- ->where($where)
- ->where(['ct_user.status'=>['neq',0]])
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- function showprc()
- {
- $ids=input('ids');
- $user=get_user_data($ids);
- $this->view->assign("info",$user);
- return $this->view->fetch();
- }
- public function reallist()
- {
- //当前是否为关联查询
- $this->relationSearch = false;
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->where(['isreal'=>['gt',0]])
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where(['isreal'=>['gt',0]])
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list, "where" => $order);
- return json($result);
- }
- return $this->view->fetch('index');
- }
- function viewauto()
- {
- $ids = input('ids');
- $status=input('status');
- $info=$this->model->where(['id'=>$ids,'status'=>1])->find();
- if(!$info)
- {
- $this->error("信息不存在,或已审核");
- }else{
- if($status == 1)
- {
- $res=db('user')->where(['id'=>$ids])->update(['isreal'=>2]);
- }elseif($status == -1)
- {
- $data=[
- 'isreal'=>0,
- 'idcard'=>'',
- 'realname'=>'',
- 'idprc1'=>'',
- 'idprc2'=>'',
- ];
- $res=db('user')->where(['id'=>$ids])->update($data);
- }
- if($res)
- {
- $this->success('审核通过');
- }else{
- $this->error('审核失败');
- }
- }
- }
- public function noactivelist()
- {
- //当前是否为关联查询
- $this->relationSearch = false;
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->where(['status'=>0])
- ->order($sort, $order)
- ->count();
-
- $list = $this->model
- ->where($where)
- ->where(['status'=>0])
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list, "where" => $order);
- return json($result);
- }
- return $this->view->fetch('index');
- }
- function updatepwd()
- {
- if ($this->request->isPost()) {
- $ids=$this->request->post('id');
- $password=$this->request->post('password');
- $password2=$this->request->post('password2');
- if(empty($password) && empty($password2))
- {
- $this->error('请输入要充值得密码');
- }
- $user=db('user')->where(['id'=>$ids])->find();
- if($password)
- {
- $data['password']=getEncryptPassword($password,$user['salt']);
- }
- if($password2)
- {
- $data['password2']=getEncryptPassword($password2,$user['salt']);
- }
- $data['updatetime']=time();
- $res=db('user')->where(['id'=>$ids])->update($data);
- if($res)
- {
- $this->success('重置成功');
- }else{
- $this->error('重置失败');
- }
- }
- $ids=input('ids');
- $user=db('user')->where(['id'=>$ids])->find();
- if(empty($user))
- {
- $this->error('用户不存在,或不可用');
- }
- $this->view->assign('user',$user);
- return $this->view->fetch('updatepwd');
- }
- /* 充值
- * */
- function chongzhi()
- {
- if ($this->request->isPost()) {
- $ids=$this->request->post('id');
- $money=$this->request->post('money');
- if(empty($money))
- {
- $this->error('请输入充值金额');
- }
- if($money <= 0){
- $this->error('充值金额不正确');
- }
- $money_type=$this->request->post('money_type');
- if(empty($money_type))
- {
- $this->error('请选择要充值的币种');
- }
- $remark=$this->request->post('remark');
- $changedata=[
- 'type'=>2,
- 'money'=>$money,
- 'userid'=>$ids,
- 'relevant_userid'=>-1,
- 'remark'=>$remark==''?'':$remark,
- ];
- $res=caiwu($changedata, $money_type);
- if($res)
- {
- $this->success('充值成功');
- }else{
- $this->error('充值失败');
- }
- }
- #人,币种,备注
- $ids=input('ids');
- $user=db('user')->where(['id'=>$ids,'status'=>1])->field('id,username')->find();
- if(empty($user))
- {
- $this->error('用户不存在,或不可用');
- }
- $this->view->assign('user',$user);
- #币种
- $money_type_list=db('money_type')->where(['status'=>1])->field('identification,name')->select();
- $this->view->assign('moneytype',list_to_arr($money_type_list,'identification','name'));
- return $this->view->fetch('chongzhi');
- }
- /* 扣费
- * */
- function koufei()
- {
- if ($this->request->isPost()) {
- $ids=$this->request->post('id');
- $money=$this->request->post('money');
- if(empty($money))
- {
- $this->error('请输入充值金额');
- }
- if($money <= 0){
- $this->error('充值金额不正确');
- }
- $money_type=$this->request->post('money_type');
- if(empty($money_type))
- {
- $this->error('请选择要充值的币种');
- }
- $remark=$this->request->post('remark');
- $changedata=[
- 'type'=>3,
- 'money'=>0-$money,
- 'userid'=>$ids,
- 'relevant_userid'=>-1,
- 'remark'=>$remark==''?'':$remark,
- ];
- $res=caiwu($changedata, $money_type);
- if($res)
- {
- $this->success('扣除成功');
- }else{
- $this->error('扣除失败');
- }
- }
- #人,币种,备注
- $ids=input('ids');
- $user=db('user')->where(['id'=>$ids,'status'=>1])->field('id,username')->find();
- if(empty($user))
- {
- $this->error('用户不存在,或不可用');
- }
- $this->view->assign('user',$user);
- #币种
- $money_type_list=db('money_type')->where(['status'=>1])->field('identification,name')->select();
- $this->view->assign('moneytype',list_to_arr($money_type_list,'identification','name'));
- return $this->view->fetch('chongzhi');
- }
- /* 冻结解冻
- * */
- function setStatus()
- {
- $ids=input('ids');
- $status=input('status');
- $info=$this->model->where(['id'=>$ids])->find();
- if(empty($info))
- {
- $this->error('用户不存在,或不可用');
- }
- $res=$this->model->where(['id'=>$ids])->update(['status'=>$status]);
- if($res)
- {
- $this->success('设置完成');
- }else{
- $this->error('设置失败');
- }
- }
- public function usermessage()
- {
- //设置过滤方法
- //当前是否为关联查询
- $this->relationSearch = false;
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField'))
- {
- return $this->selectpage();
- }
- $ids=db('user_message')->where(['to_uid'=>0,'isread'=>0])->group('userid')->column('userid');
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- if(count($ids)>0)
- {
- $total = $this->model
- ->where($where)
- ->where(['status'=>1,'id'=>['in',$ids]])
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where(['status'=>1,'id'=>['in',$ids]])
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- }else{
- $total = $this->model
- ->where($where)
- ->where(['status'=>1])
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where(['status'=>1])
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- }
- $result = array("total" => $total, "rows" => $list, "where" => $order);
- return json($result);
- }
- return $this->view->fetch('index');
- }
- function viewmsg()
- {
- $ids = input('ids');
- $user=db('user')->where('id',$ids)->find();
- $map['from_uid|to_uid'] = 0;
- $map['userid']=$ids;
- $data_list=db('user_message')->where($map)->select();
- foreach ($data_list as $k=>$v)
- {
-
- if($v['from_uid'] === 0)
- {
- $data_list[$k]['fromuser']='系统';
- $data_list[$k]['flag']=0;
- }else{
- $data_list[$k]['flag']=1;
- $data_list[$k]['fromuser']=$user['username'];
- }
- }
- $this->view->assign("uid",$ids);
- db('user_message')->where(['to_uid'=>0])->update(['isread'=>1]);
- $this->view->assign("list",$data_list);
- return $this->view->fetch('viewmsg');
- }
- function usertree()
- {
- $keyword = input('keyword');
- if(!empty($keyword))
- {
- $user=$this->model->where(['username'=>$keyword])->find();
- if(empty($user))
- {
- $this->error("会员不存在");
- }else{
- $uid=$user['id'];
- }
- }else{
- $uid=1;
- }
- $this->view->assign('rootid',$uid);
- $this->view->assign('uid',0);
- $this->view->assign('keyword',$keyword);
- return $this->view->fetch('usertree');
- }
- /* 接点图 */
- function dottree()
- {
- $keyword = input('keyword');
- if(!empty($keyword))
- {
- $user_info=db("user")->where(['username'=>$keyword])->find();
- if(!empty($user_info)){
- $node_info=db("user_parent")->where(['userid'=>$user_info['id']])->find();
- }else{
- $this->error("要查询的会员不存在");
- }
- }
- if(empty($node_info)){//没有搜索显示网头
- $node_info=db("user_parent")->where(['id'=>1])->find();
- }
- $datascource['id']=strval($node_info['id']);//这里要用字符串
- $datascource['name']=$node_info['username'];
- $datascource['title']=$node_info['nickname'];
- $datascource['nums']=$node_info['cnum'];
- $datascource['relationship']['children_num']=$node_info['cnum'];
- $datascource['relationship']['parent_num']=$node_info['pid']>0?$node_info['pid']:0;
- $datascource_json=json_encode($datascource);
- $this->view->assign('datascource',$datascource_json);
- return $this->view->fetch('dottree');
- }
- function childrendot()
- {
- $res=[];
- $nid = input('nid');
- $children_list=db("user_parent")->where(['pid'=>$nid])->order('distance asc')->select();
- foreach ($children_list as $clv){
- $datascource['id']=strval($clv['id']);//这里要用字符串
- $datascource['name']=$clv['username'];
- $datascource['title']=$clv['nickname'];
- $datascource['nums']=$clv['cnum'];
- $datascource['relationship']['children_num']=$clv['cnum'];
- $datascource['relationship']['parent_num']=$clv['pid']>0?$clv['pid']:0;
- $res['children'][]=$datascource;
- }
- return $res;
- }
- function parentdot()
- {
- $res=[];
- $nid = input('nid');
- $userinfo=db("user_parent")->where(['id'=>$nid])->find();
- $parentinfo=db("user_parent")->where(['id'=>$userinfo['pid']])->find();
- $datascource['id']=strval($parentinfo['id']);//这里要用字符串
- $datascource['name']=$parentinfo['username'];
- $datascource['title']=$parentinfo['nickname'];
- $datascource['nums']=$parentinfo['cnum'];
- $datascource['relationship']['children_num']=$parentinfo['cnum'];
- $datascource['relationship']['parent_num']=$parentinfo['pid']>0?$parentinfo['pid']:0;
- return $datascource;
- }
- /* 激活数据 */
- function jihuo()
- {
- $ids = input('ids');
- $info=$this->model->where(['id'=>$ids,'status'=>0])->find();
- if($info)
- {
- db()->startTrans();
- $res1=$this->model->where('id',$ids)->update(['status'=>1]);
- if($info['refereeid']>0)
- {
- $res2=$this->model->where('id',$info['refereeid'])->setInc('referee_number',1);
- }else{
- $res2=1;
- }
- $bonusconfig=db('bonus_config')->where(['config_type'=>1,'user_level'=>$info['level']])->find();
- $res3=db('user_account')->insertGetId(['userid'=>$ids,'username'=>$info['username'],'reg_money'=>$bonusconfig['value']]);
- if($res1 && $res2 && $res3)
- {
- finance(1, $bonusconfig['value']);
- $count=db('user')->count();
- if($count>1)
- {
- #activeuser($ids);
- }
- db()->commit();
- $this->success("激活成功");
- }else{
- db()->rollback();
- $this->error("激活失败");
- }
- }else{
- $this->error("要操作的数据不存在,或已激活");
- }
-
- }
- /* 新增 */
- function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- $flag=$this->request->post('flag');
- if(empty($params['username']))
- {
- $this->error("用户名不能为空");
- }else{
- $usernameinfo=$this->model->where('username',$params['username'])->find();
- if($usernameinfo)
- {
- $this->error("此用户名已注册,请更换");
- }
- }
- if(empty($params['nickname']))
- {
- $this->error("昵称不能为空");
- }
- if(empty($params['mobile']))
- {
- $this->error("手机号不能为空");
- }else{
- if(!preg_match('/^1\d{10}$/',$params['mobile']))
- {
- $this->error('手机号格式不正确');
- }
- $mobileinfo=db('user')->where('mobile',$params['mobile'])->find();
- if($mobileinfo)
- {
- $this->error("此手机号已注册,请更换");
- }
- }
- $data = [
- 'username' => $params['username'],
- 'nickname' => $params['nickname'],
- 'mobile' => $params['mobile'],
- 'level' => 0,
- 'salt' => Random::alnum(),
- 'createtime' => time(),
- 'joinip' => request()->ip(),
- 'status' => '1',
- ];
- $data['password'] = getEncryptPassword($params['password'], $data['salt']);
- $data['password2'] =getEncryptPassword($params['password2'], $data['salt']);
- if($flag == 0)
- {
- $data['refereeid']=0;
- $data['referee_name']='';
- $data['refereeids']='0,';
- $data['tdeep']=0;
- $data['pid']=0;
- $data['parent_name']='';
- }else{
- $referee=$this->model->where(['username|mobile'=>$params['referee'],'status'=>1])->find();
- if($referee)
- {
- $data['refereeid']=$referee['id'];
- $data['referee_name']=$referee['username'];
- $data['refereeids']=$referee['refereeids'].$referee['id'].',';
- $data['tdeep']=$referee['tdeep']+1;
- }else{
- $this->error("推荐人不可用或输入的推荐编号有误");
- }
- if(config('dot_mode')==1)
- {
- $parent=$this->model->where(['username'=>$params['parent'],'status'=>1])->find();
- if($parent)
- {
- $data['pid']=$parent['id'];
- $data['parent_name']=$parent['username'];
- $pos=$params['pos'];
- }else{
- $this->error("结点人不可用或输入的或输入的编号有误");
- }
- }else{
- $data['pid']=0;
- $data['parent_name']='';
- $pos=0;
- }
- }
- $ids=$this->model->insertGetId($data);
- if($ids)
- {
- if(config('dot_mode')==1)
- {
- if($flag == 0)
- {
- $updata['userid']=$ids;
- $updata['username']=$data['username'];
- $updata['nickname']=$data['nickname'];
- $updata['pid']=0;
- $updata['distance']=1;
- $updata['position']=0;
- $updata['pids']='0,';
- $updata['system']=1;
- db('user_parent')->insertGetId($updata);
- }else{
- $upinfo=db('user_parent')->where(['userid'=>$data['pid']])->find();
- $updata['userid']=$ids;
- $updata['username']=$data['username'];
- $updata['pid']=$upinfo['id'];
- $updata['distance']=$upinfo['distance']+1;
- $updata['position']=$pos;
- $updata['nickname']=$data['nickname'];
- $updata['pids']=$upinfo['pids'].$upinfo['id'].',';
- $updata['system']=1;
- db('user_parent')->insertGetId($updata);
- db('user_parent')->where('id',$upinfo['id'])->setInc('cnum',1);
- }
- }
-
- if($data['refereeid']>0)
- {
- $res2=$this->model->where('id',$data['refereeid'])->setInc('referee_number',1);
- }
- $this->success("注册成功");
- }else{
- $this->error("注册失败");
- }
- }
- #检测推荐人
- $info=$this->model->where('id','>=','1')->find();
- if($info)
- {
- $flag=1;
- }else{
- $flag=0;
- }
-
- $this->assign("flag",$flag);
- $randStr = str_shuffle('1234567890');
- $randZm = str_shuffle('abcdefghijklmnopqrstuvwxyz');
- $username= substr($randZm,0,2).substr($randStr,0,6);//账号为7位随机数
- $this->view->assign('userlevel', build_select('row[level]', \app\cmgadm\model\Userlevel::column('id,name'), '', ['class' => 'form-control selectpicker']));
- $this->view->assign("username",$username);
- return parent::add();
- }
- /**
- * 编辑
- */
- public function edit($ids = NULL)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if(empty($params['nickname']))
- {
- $this->error("昵称不能为空");
- }
- if(empty($params['mobile']))
- {
- $this->error("手机号不能为空");
- }else{
- if(!preg_match('/^1\d{10}$/',$params['mobile']))
- {
- $this->error('手机号格式不正确');
- }
- $mobileinfo=db('user')->where('mobile',$params['mobile'])->find();
- if($mobileinfo && $mobileinfo['id'] != $ids)
- {
- $this->error("此手机号已注册,请更换");
- }
- }
- // 有推荐人
- if($params['referee']){
- $referee=$this->model->where(['username|mobile'=>$params['referee'],'status'=>1])->find();
- if($referee)
- {
- $params['refereeid']=$referee['id'];
- $params['referee_name']=$referee['username'];
- $params['refereeids']=$referee['refereeids'].$referee['id'].',';
- $params['tdeep']=$referee['tdeep']+1;
- }else{
- $this->error("推荐人不可用或输入的推荐编号有误");
- }
- }
- Db::startTrans();
- try{
- $result = $row->allowField(true)->save($params);
- if($result === false){
- Db::rollback();
- $this->error('修改失败');
- }
- if($params['refereeid']>0)
- {
- if(!$this->model->where('id',$params['refereeid'])->setInc('referee_number',1)){
- Db::rollback();
- $this->error('修改推荐关系失败');
- }
- if(!$this->model->where('id',$row['refereeid'])->setDec('referee_number',1)){
- Db::rollback();
- $this->error('修改推荐关系失败');
- }
- }
- Db::commit();
- $this->success("修改成功");
- } catch (\Exception $e){
- $this->error($e->getMessage());
- }
- }
- $row = $this->model->get($ids);
- if (!$row)
- $this->error(__('No Results were found'));
- $this->view->assign('groupList', build_select('row[group_id]', \app\cmgadm\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
- return parent::edit($ids);
- }
-
- }
|