title = '系统管理后台'; $auth = AdminService::instance()->apply(true); $this->menus = MenuService::instance()->getTree(); if (empty($this->menus) && !$auth->isLogin()) { $this->redirect('@admin/login'); } else { $this->fetch(); } } /** * 后台环境信息 */ public function main() { $notice = Db::name('store_notice')->where('is_deleted','=',0)->order('create_at','DESC')->limit(3)->select(); $activity = Db::name('store_activity')->where('is_deleted','=',0)->order('id','DESC')->limit(1)->find(); $activity['content'] = strip_tags(htmlspecialchars_decode($activity['content'])); $member_count = Db::name('store_member')->count('id'); $sta_week = date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y"))); //2020-03-09 00:00:00 $end_week = date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+7,date("Y"))); //2020-03-09 00:00:00 $weeek_regiz = Db::name('store_member')->whereBetween('create_at',[$sta_week,$end_week])->count(); $member_rz = Db::name('store_member')->where('vip_level','=',1)->count('id'); $activity_count= Db::name('store_activity')->where('is_deleted','=',0)->count(); $forum_count = Db::name('store_emotional_counseling')->where('is_deleted','=',0)->count(); $examine_count = Db::name('store_examine')->where('status','=',1)->count(); $examine_forum =Db::name('store_forum')->where('status','=',1)->count(); $examine_report =Db::name('store_report')->where('status','=',1)->count(); $no_emotion = Db::name('store_emotional_counseling')->where('is_deleted','=',0)->where('status','=',1)->count(); $nan_count = Db::name('store_member')->where('sex',1)->count('id'); $nv_count = Db::name('store_member')->where('sex',2)->count('id'); //男女学历统计 $a1 = Db::name('store_member')->where('sex',1)->where('education','=','高中')->count(); $b1= Db::name('store_member')->where('sex',2)->where('education','=','高中')->count(); $a2 = Db::name('store_member')->where('sex',1)->where('education','=','大专')->count(); $b2= Db::name('store_member')->where('sex',2)->where('education','=','大专')->count(); $a3 = Db::name('store_member')->where('sex',1)->where('education','=','本科')->count(); $b3= Db::name('store_member')->where('sex',2)->where('education','=','本科')->count(); $a4 = Db::name('store_member')->where('sex',1)->where('education','=','研究生')->count(); $b4= Db::name('store_member')->where('sex',2)->where('education','=','研究生')->count(); $a5 = Db::name('store_member')->where('sex',1)->where('education','=','博士')->count(); $b5= Db::name('store_member')->where('sex',2)->where('education','=','博士')->count(); $working = Db::name('store_work_nature') ->alias('w') ->join('store_member m','w.id=m.nature') ->field('w.id,w.name,count(*) count') ->where('w.is_deleted','=',0) ->group('m.nature') ->order('count desc') ->limit(10) ->select(); $nature = []; $nature_count_nan = []; $nature_count_nv = []; foreach ($working as $k=>$v){ $nature[$k] ="'".$working[$k]['name']."'"; $nature_count_nan[$k] = Db::name('store_member')->where('sex',1)->where('nature',$working[$k]['id'])->count(); $nature_count_nv[$k] = Db::name('store_member')->where('sex',2)->where('nature',$working[$k]['id'])->count(); } $nature = implode(',',$nature); $nature_count_nan = implode(',',$nature_count_nan); $nature_count_nv = implode(',',$nature_count_nv); $sale =[['min'=>20,'max'=>22],['min'=>23,'max'=>25],['min'=>26,'max'=>28],['min'=>29,'max'=>31],['min'=>32,'max'=>34],['min'=>35,'max'=>37],['min'=>38,'max'=>40],['min'=>41,'max'=>43],['min'=>44,'max'=>46],['min'=>47,'max'=>49],['min'=>50,'max'=>52],['min'=>53,'max'=>55],['min'=>56,'max'=>58],['min'=>59,'max'=>61],['min'=>62,'max'=>64]]; $age_count_nan = []; $age_count_nv = []; foreach ($sale as $k1=>$v1){ $where = []; $where[] = ['age', 'between', [$sale[$k1]['min'], $sale[$k1]['max']]]; $age_count_nan[$k1] = Db::name('store_member')->where('sex',1)->where($where)->count(); $age_count_nv[$k1] = Db::name('store_member')->where('sex',2)->where($where)->count(); } // die; // print_r($age_count_nv);print_r($age_count_nan); $age_count_nan = implode(',',$age_count_nan); $age_count_nv = implode(',',$age_count_nv); $this->fetch('main', [ 'member_count'=>$member_count, 'member_rz'=>$member_rz, 'activity_count'=>$activity_count, 'forum_count'=>$forum_count, 'examine_count'=>$examine_count, 'examine_forum'=>$examine_forum, 'examine_report'=>$examine_report, 'no_emotion'=>$no_emotion, 'nan_count'=>$nan_count, 'nv_count'=>$nv_count, 'activity'=>$activity, 'notice'=>$notice, 'nature'=>$nature, 'nature_count_nan'=>$nature_count_nan, 'nature_count_nv'=>$nature_count_nv, 'age_count_nan'=>$age_count_nan, 'age_count_nv'=>$age_count_nv, 'gaozhong' => "['高中',$a1,$b1]", 'dazhuan' => "['大专',$a2,$b2]", 'benke' => "['本科',$a3,$b3]", 'shuoshi' => "['硕士',$a4,$b4]", 'boshi' => "['博士',$a5,$b5]", 'count'=>$weeek_regiz ]); } public function tongji(){ $this->fetch('tongji'); } /** * 修改密码 * @login true * @param integer $id * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function pass($id) { $this->applyCsrfToken(); if (intval($id) !== intval(session('user.id'))) { $this->error('只能修改当前用户的密码!'); } if (!AdminService::instance()->isLogin()) { $this->error('需要登录才能操作哦!'); } if ($this->request->isGet()) { $this->verify = true; $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]); } else { $data = $this->_input([ 'password' => $this->request->post('password'), 'repassword' => $this->request->post('repassword'), 'oldpassword' => $this->request->post('oldpassword'), ], [ 'oldpassword' => 'require', 'password' => 'require|min:4', 'repassword' => 'require|confirm:password', ], [ 'oldpassword.require' => '旧密码不能为空!', 'password.require' => '登录密码不能为空!', 'password.min' => '登录密码长度不能少于4位有效字符!', 'repassword.require' => '重复密码不能为空!', 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!', ]); $user = Db::name('SystemUser')->where(['id' => $id])->find(); if (md5($data['oldpassword']) !== $user['password']) { $this->error('旧密码验证失败,请重新输入!'); } if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) { $this->success('密码修改成功,下次请使用新密码登录!', ''); } else { $this->error('密码修改失败,请稍候再试!'); } } } /** * 修改用户资料 * @login true * @param integer $id 会员ID * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function info($id = 0) { if (!AdminService::instance()->isLogin()) { $this->error('需要登录才能操作哦!'); } $this->applyCsrfToken(); if (intval($id) === intval(session('user.id'))) { $this->_form('SystemUser', 'admin@user/form', 'id', [], ['id' => $id]); } else { $this->error('只能修改登录用户的资料!'); } } /** * 清理运行缓存 * @auth true */ public function clearRuntime() { try { Console::call('clear'); Console::call('xclean:session'); $this->success('清理运行缓存成功!'); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $e) { $this->error("清理运行缓存失败,{$e->getMessage()}"); } } /** * 压缩发布系统 * @auth true */ public function buildOptimize() { try { Console::call('optimize:route'); Console::call('optimize:schema'); Console::call('optimize:autoload'); Console::call('optimize:config'); $this->success('压缩发布成功!'); } catch (HttpResponseException $exception) { throw $exception; } catch (\Exception $e) { $this->error("压缩发布失败,{$e->getMessage()}"); } } }