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("此手机号已注册,请更换"); } } // 有推荐人 $params['updatetime'] = time(); 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 = $this->model->where(['id'=> $ids])->allowField(true)->update($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); } }