auth; if (!Config::get('fastadmin.usercenter')) { $this->error(__('User center already closed')); } //监听注册登录注销的事件 Hook::add('user_login_successed', function ($user) use ($auth) { $expire = input('post.keeplogin') ? 30 * 86400 : 0; Cookie::set('uid', $user->id, $expire); Cookie::set('token', $auth->getToken(), $expire); }); Hook::add('user_register_successed', function ($user) use ($auth) { Cookie::set('uid', $user->id); Cookie::set('token', $auth->getToken()); }); Hook::add('user_delete_successed', function ($user) use ($auth) { Cookie::delete('uid'); Cookie::delete('token'); }); Hook::add('user_logout_successed', function ($user) use ($auth) { Cookie::delete('uid'); Cookie::delete('token'); }); } /** * 空的请求 * @param $name * @return mixed */ public function _empty($name) { $data = Hook::listen("user_request_empty", $name); foreach ($data as $index => $datum) { $this->view->assign($datum); } return $this->view->fetch('user/' . $name); } /** * 会员中心 */ public function index() { $info = db('user')->where(['id' => $this->auth->id])->find(); $unifo=db('user_parent')->where(['userid'=>$this->auth->id])->find(); if(empty($unifo)) { $tjinfo=db('user_parent')->where(['userid'=>$info['refereeid']])->find(); if($tjinfo) {/*上级入网*/ addtable($info); } } $total1 = 0; $total2 = 0; $total1 = db('detailed_bonus')->where(['userid' => $info['id'], 'type' => ['in', '16,17,18']])->sum('money'); $total2 = db('detailed_bonus')->where(['userid' => $info['id'], 'type' => 19])->sum('money'); $this->view->assign([ "user" => $info, 'total1' => $total1, 'total2' => $total2 ]); return $this->view->fetch(); } /* 流水 */ function detailed() { $group = input('group'); $type = input('type'); $this->view->assign('group', $group); $this->view->assign('type', $type); $this->view->assign('mate_title', get_detailed_type_text($type)); return $this->view->fetch(); } function wallet() { $user = get_user_data($this->auth->id); $this->view->assign("user", $user); $config = db('bonus_config')->where('id', 3)->find(); $this->view->assign("scc", $user['cash'] * $config['value']); $this->view->assign("price", $config['value']); return $this->view->fetch(); } function walletdetail1() { $user = get_user_data($this->auth->id); $this->view->assign("user", $user); return $this->view->fetch(); } function walletdetail2() { $user = get_user_data($this->auth->id); $this->view->assign("user", $user); return $this->view->fetch(); } /* 流水 */ function rechargerecode() { $group = input('group'); $this->view->assign('group', $group); return $this->view->fetch(); } function sharelink() { $user = get_user_data($this->auth->id); $tjurl = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/index/user/register?code=' . $user['username']; $img_url = 'http://' . $_SERVER['HTTP_HOST'] . '/getqrcode.php?t=' . $tjurl; $save_path = 'uploads/tj/'; put_file_from_url_content($img_url, $user['id'] . ".png", $save_path); $this->assign("imgurl", 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/tj/' . $user['id'] . '.png'); $this->view->assign("tjurl", $user['username']); return $this->view->fetch(); } function noticedetail() { $id = input('id'); $noticeinfo = db('article')->where(['id' => $id, 'status' => 1])->find(); if (empty($noticeinfo)) { $noticeinfo = []; } $this->view->assign('info', $noticeinfo); return $this->fetch(); } function setting() { $user = db('user')->where(['id' => $this->auth->id])->find(); $this->view->assign('user', $user); return $this->fetch(); } /*修改资料*/ function updatenickname() { $user=$this->auth->getUserinfo(); $this->view->assign("user",$user); return $this->view->fetch(); } function isreal() { return $this->view->fetch(); } function bonusdetailed() { $user=db('user')->where(['id'=>$this->auth->id])->find(); $zt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16,'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money'); $jt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20,'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money'); $manager=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18'],'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money'); //今日 $zt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16,'create_time'=>['egt',strtotime('today')]])->sum('money'); $jt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20,'create_time'=>['egt',strtotime('today')]])->sum('money'); $manager1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18'],'create_time'=>['egt',strtotime('today')]])->sum('money'); $this->view->assign([ 'user'=> $user, 'zt'=>$zt, 'jt'=>$jt, 'manager'=>$manager, 'zt1'=>$zt1, 'jt1'=>$jt1, 'manager1'=>$manager1, ]); return $this->view->fetch(); } function profile() { $user=db('user')->where(['id'=>$this->auth->id])->find(); $this->view->assign("user",$user); return $this->view->fetch(); } function roselist() { $user=get_user_data($this->auth->id); $bcf=db('bonus_config')->where(['config_type'=>13])->select(); $ones=list_to_arr($bcf,'user_level','value'); $ones[0]=0; $total=0; $list=db('rose')->where(['pid'=>$this->auth->id,'status'=>2])->select(); foreach ($list as $v) { $total+=$ones[$v['level']+1]; } $type=input('type'); $this->view->assign([ 'total'=>$total, 'type'=>$type, 'mon'=>$ones[$user['rose']] ]); return $this->view->fetch(); } function roselist1() { $user=get_user_data($this->auth->id); $bcf=db('bonus_config')->where(['config_type'=>13])->select(); $ones=list_to_arr($bcf,'user_level','value'); $ones[0]=0; $total=0; $list=db('rose')->where(['pid'=>$this->auth->id,'status'=>2])->select(); foreach ($list as $v) { $total+=$ones[$v['level']+1]; } $type=input('type'); $this->view->assign([ 'total'=>$total, 'type'=>$type, 'mon'=>$ones[$user['rose']] ]); return $this->view->fetch(); } function uprose() { $user=db('user')->where(['id'=>$this->auth->id])->find(); $this->view->assign('userinfo',$user); #上级信息 $flag=0; $unifo=db('user_parent')->where(['userid'=>$this->auth->id])->find(); $level=get_user_data($this->auth->id,'rose'); $distance=$unifo['distance']-$level-1; $puinfo=db('user_parent')->where(['id'=>['in',$unifo['pids']],'distance'=>$distance])->find(); if($puinfo) { $parentinfo=db('user')->where(['id'=>$puinfo['userid']])->find(); if($parentinfo['rose']<$level+1) { $userids=db('user_parent')->where(['id'=>['in',$unifo['pids']],'system'=>1])->column('userid'); $parentinfo=db('user')->where(['id'=>['in',$userids],'rose'=>['gt',$level]])->order('id desc')->find(); } }else{ $parentinfo=[]; } $upmoneycf=db('bonus_config')->where(['config_type'=>13,'user_level'=>$user['rose']+1])->find(); $this->view->assign([ 'user'=>$unifo, 'urose'=>$level, 'pinfo'=>$parentinfo, 'upmoney'=>$upmoneycf['value'], ]); return $this->view->fetch(); } function withdraw() { $config=db('bonus_config')->where('id',5)->find(); $this->view->assign("config",$config); $user=get_user_data($this->auth->id); $this->view->assign("user",$user); return $this->view->fetch(); } function withdrawdetaile() { return $this->view->fetch(); } function withdrawdetaile1() { return $this->view->fetch(); } function transcode() { return $this->view->fetch(); } function trans() { $user=get_user_data($this->auth->id); $this->view->assign("user",$user); $this->view->assign("money_type",input('money_type')); return $this->view->fetch(); } function userteam() { $user=db('user')->where(['id'=>$this->auth->id])->find(); $total=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%']])->count(); $total1=db('user')->where(['refereeid'=>$this->auth->id])->count(); $total2=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%'],'tdeep'=>$user['tdeep']+2])->count(); $list=db('user')->where(['refereeid'=>$this->auth->id])->select(); if(empty($list)) { $list=[]; } $this->view->assign([ "list"=>$list, "total"=>$total, "total1"=>$total1, "total2"=>$total2 ]); return $this->view->fetch(); } function sonteam() { $id=input('id'); $list=db('user')->where(['refereeid'=>$id])->select(); if(empty($list)) { $list=[]; } $this->view->assign([ "list"=>$list, 'id'=>$id ]); return $this->view->fetch(); } function funsorders() { $user=get_user_data($this->auth->id); $uids=db('user')->where(['id'=>['like','%,'.$this->auth->id.',%'],'tdeep'=>['elt',$user['tdeep']+2]])->column('id'); $total=db('trade')->where(['userid'=>['in',$uids],'status'=>3])->count(); $sum=db('trade')->where(['userid'=>['in',$uids],'status'=>3])->sum('nums'); $this->view->assign([ "total"=>$total, "sum1"=>$sum ]); return $this->view->fetch(); } function updatepwd1() { return $this->view->fetch(); } function updatepwd2() { return $this->view->fetch(); } function news() { return $this->view->fetch(); } function newdetail() { $id=input('id'); $info=db('article')->where("id",$id)->find(); $this->view->assign("info",$info); return $this->view->fetch(); } function myassets() { $user=get_user_data($this->auth->id); $this->view->assign("user",$user); $ALL=db('user_bonus1')->where("userid",$user['id'])->sum('money'); $fdCf=db('bonus_config')->where("id",22)->find(); $this->view->assign("totalFd",$ALL*$fdCf['value']); $ALLTZ=db('user_bonus1')->where("userid",$user['id'])->sum('tzmoney'); $this->view->assign("totaltz",$ALLTZ); $current_tz=db('user_bonus1')->where(["userid"=>$this->auth->id,'status'=>1])->sum('tzmoney'); $this->view->assign("tzmoney",$current_tz); $last=db('user_bonus1')->where(["userid"=>$this->auth->id])->order('id desc')->find(); if($last) { $this->view->assign("lasttime",$last['ctime']); }else{ $this->view->assign("lasttime",0); } return $this->view->fetch(); } function market() { $uid=$this->auth->id; $sock=db('user_bonus2')->where(['status'=>1,'userid'=>$uid])->sum('money'); $sockOut=db('user_bonus2')->where(['userid'=>$uid,'status'=>2])->sum('money'); $this->view->assign("sock",$sock); $this->view->assign("sockout",$sockOut); $config=db('bonus_config')->where("id",3)->find(); $this->view->assign("days",$config['cap']); return $this->view->fetch(); } /** * 注册会员 */ public function register() { $code=input('code'); if(empty($code)) { $code=''; } $myset= \app\common\model\Config::getConfigByGroup('basic'); $this->view->assign("logoimg",$myset['web_site_logo']['value']); $this->view->assign("loginbg",$myset['loginBg']['value']); $this->view->assign("register_agree", isset($myset['register_agree']['value'])? $myset['register_agree']['value']:''); $this->view->assign('code',$code); $this->view->assign("app_download1",$myset['appdowm']['value']); $this->view->assign("app_download2",$myset['appdowm_two']['value']); return $this->view->fetch(); } function allthings() { return $this->view->fetch(); } function allthings1() { return $this->view->fetch(); } function findpwd() { $myset= \app\common\model\Config::getConfigByGroup('basic'); $this->view->assign("logoimg",$myset['web_site_logo']['value']); $this->view->assign("loginbg",$myset['loginBg']['value']); return $this->view->fetch(); } function syslogin() { $uid=input('uid'); if($this->auth->direct($uid)) { $this->success(__('Logged in successful'), url('shop/index/index')); }else{ $this->error('信息有误,请重新登录'); } } public function login() { if ($this->auth->id) { $this->redirect('shop/index/index'); } if ($this->request->isPost()) { $studio = $this->request->post('studio'); $account = $this->request->post('account'); $password = $this->request->post('password'); $keeplogin = (int)$this->request->post('keeplogin'); $token = $this->request->post('__token__'); $rule = [ 'account' => 'require|length:3,50', 'password' => 'require|length:6,30', '__token__' => 'require|token', ]; $msg = [ 'account.require' => 'Account can not be empty', 'account.length' => 'Account must be 3 to 50 characters', 'password.require' => 'Password can not be empty', 'password.length' => 'Password must be 6 to 30 characters', ]; $data = [ 'account' => $account, 'password' => $password, '__token__' => $token, ]; $stuinfo=db('studio')->where(['title'=>$studio])->find(); if(empty($stuinfo)) { $this->error('商家编号输入有误'); }else{ if($stuinfo['status'] != 1) { $this->error('商家已关闭,不可登录'); } } // if (Config::get('fastadmin.login_captcha')) { // $rule['captcha'] = 'require|captcha'; // $data['captcha'] = $this->request->post('captcha'); // } $validate = new Validate($rule, [], ['account' => __('Username'), 'password' => __('Password')/*, 'captcha' => __('Captcha')*/]); $result = $validate->check($data); if (!$result) { $this->error(__($validate->getError()), null, ['token' => $this->request->token()]); return false; } if ($this->auth->login($account, $password)) { db('user')->where(['id'=>$this->auth->id])->update(['login_studio'=>$studio]); $this->success(__('Logged in successful'), url('user/index')); } else { $this->error($this->auth->getError(), null, ['token' => $this->request->token()]); } } $code=input('code'); if(empty($code)) { $code=''; } $this->view->assign('code',$code); //判断来源 $referer = $this->request->server('HTTP_REFERER'); if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host())) && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) { $url = $referer; } $myset= \app\common\model\Config::getConfigByGroup('basic'); $this->view->assign("siteName",$myset['name']['value']); $this->view->assign("logoimg",$myset['web_site_logo']['value']); $this->view->assign("loginbg",$myset['loginBg']['value']); $this->view->assign("app_download1",$myset['appdowm']['value']); $this->view->assign("app_download2",$myset['appdowm_two']['value']); return $this->view->fetch(); } function invest() { $user=get_user_data($this->auth->id); $this->view->assign("user",$user); $config=db('bonus_config')->where('id',1)->find(); $this->view->assign("config",$config); $priceconfig=db('bonus_config')->where('id',3)->find(); $this->view->assign("price",$priceconfig['value']); return $this->view->fetch(); } function myincome() { $uid=$this->auth->id; $sum1=db('detailed_bonus')->where(['userid'=>$uid,'type'=>16])->sum('money'); $sum2=db('detailed_bonus')->where(['userid'=>$uid,'type'=>17])->sum('money'); $sum3=db('detailed_bonus')->where(['userid'=>$uid,'type'=>18])->sum('money'); $sum4=db('detailed_bonus')->where(['userid'=>$uid,'type'=>19])->sum('money'); $this->view->assign("sum1",$sum1); $this->view->assign("sum2",$sum2); $this->view->assign("sum3",$sum3); $this->view->assign("sum4",$sum4); return $this->view->fetch(); } /** * 注销登录 */ public function logout() { //注销本站 db('user')->where(['id'=>$this->auth->id])->update(['login_studio'=>'']); $this->auth->logout(); $this->redirect("user/login"); } /** * 修改密码 */ public function changepwd() { if ($this->request->isPost()) { $oldpassword = $this->request->post("oldpassword"); $newpassword = $this->request->post("newpassword"); $renewpassword = $this->request->post("renewpassword"); $token = $this->request->post('__token__'); $rule = [ 'oldpassword' => 'require|length:6,30', 'newpassword' => 'require|length:6,30', 'renewpassword' => 'require|length:6,30|confirm:newpassword', '__token__' => 'token', ]; $msg = [ ]; $data = [ 'oldpassword' => $oldpassword, 'newpassword' => $newpassword, 'renewpassword' => $renewpassword, '__token__' => $token, ]; $field = [ 'oldpassword' => __('Old password'), 'newpassword' => __('New password'), 'renewpassword' => __('Renew password') ]; $validate = new Validate($rule, $msg, $field); $result = $validate->check($data); if (!$result) { $this->error(__($validate->getError()), null, ['token' => $this->request->token()]); return false; } $ret = $this->auth->changepwd($newpassword, $oldpassword); if ($ret) { $this->success(__('Reset password successful'), url('user/login')); } else { $this->error($this->auth->getError(), null, ['token' => $this->request->token()]); } } $this->view->assign('title', __('Change password')); return $this->view->fetch(); } }