Initial commit,修正

This commit is contained in:
2025-07-13 19:37:38 +08:00
parent 38ce288e27
commit 65bbd06981
12384 changed files with 3985464 additions and 8 deletions
+1
View File
@@ -0,0 +1 @@
+31
View File
@@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>404-访问出错!</title>
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="//cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<style>
body{background-color:#000;color:#00ff00;}
.container{border-radius:5px;padding:20px;}
.panel{background:transparent;}
pre{background-color:#000;color:#00ff00;border:1px dashed #39ed15;}
</style>
<body >
<div class="container" style="margin-top:9%;">
<div class="panel panel-danger">
<div class="panel-heading"><h3>报错:404</h3></div>
<div class="panel-body">
<h5>您访问的页面未找到!</h5>
<p><li>如果您认为这是某个程序问题,</li></p>
<p><li>您可以通过以下方式联系网站技术方:</li></p>
<p><li>微信/QQ/钉钉: 18608981880</li></p>
<p><li>邮箱: fm453@lukegzs.com</li></p>
</div>
</div>
</div>
</body>
</html>
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace backend\assets;
use yii\web\AssetBundle;
/**
* Main backend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
'css/login.min.css',
];
public $js = [
'js/hplus.min.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
+15
View File
@@ -0,0 +1,15 @@
namespace: backend\tests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/test-local.php'
+24
View File
@@ -0,0 +1,24 @@
<?php
/**
* User: Administrator
* Date: 2016-7-5
* Time: 16:10
* Description:
*/
namespace backend\components;
use Yii;
use yii\rbac\Rule;
class ArticleRule extends Rule
{
public $name = 'article';
public function execute($user, $item, $params)
{
// 这里先设置为false,逻辑上后面再完善
return false;
}
}
+78
View File
@@ -0,0 +1,78 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-08 00:25:51
* @Last Modified by: fm453
* @Last Modified time: 2021-09-08 14:42:11
* @Email: fm453@lukegzs.com
*/
namespace backend\components;
use common\models\CLog;
use backend\models\Adminer;
use common\models\User;
use common\models\Member;
use common\models\Fans;
use common\models\CAttachment;
use common\models\CSms;
use Yii;
class Helper {
public static function hello(){
echo 'hello';
}
//历史访客数
public static function getHistoryVisNum(){
$res = CLog::find()->count();
return $res;
}
//最近一个月访问量
public static function getMonthHistoryVisNum(){
$LastMonth = strtotime("-1 month");
$res = CLog::find()->where(['>','create_time',$LastMonth])->count();
return $res;
}
//运维人员总数
public static function getAdminerCount(){
$res = Adminer::find()->count();
return $res;
}
//API接口站用户总数
public static function getApierCount(){
$res = User::find()->count();
return $res;
}
//会员数据总数
public static function getMemberCount(){
$res = Member::find()->count();
return $res;
}
//粉丝数据总数
public static function getFansCount(){
$res = Fans::find()->count();
return $res;
}
//短信统计
public static function getSmsStat(){
$sms = CSms::find()->count();
$mobile = CSms::find()->groupBy('mobile')->count();
return ['sms'=>$sms,'mobile'=>$mobile];
}
//附件统计
public static function getAttachStat(){
$num = CAttachment::find()->count();
$size = CAttachment::find()->sum('filesize');
return ['num'=>$num, 'size'=>$size];
}
}
+2
View File
@@ -0,0 +1,2 @@
<?php
Yii::setAlias('@backend', dirname(__DIR__));
+16
View File
@@ -0,0 +1,16 @@
<?php
$config = [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=120.79.11.71;dbname=dacms_dev',
'username' => 'dacms_dev',
'password' => 'HS8wRyTT2sKeLdAJ',
'charset' => 'utf8',
'tablePrefix' => '',
],
],
];
return $config;
+23
View File
@@ -0,0 +1,23 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-09 10:32:33
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 10:41:57
* @Email: fm453@lukegzs.com
*/
$config = [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=dacms',
'username' => 'dacms',
'password' => 'eydnsidc',
'charset' => 'utf8',
'tablePrefix' => '',
],
],
];
return $config;
+112
View File
@@ -0,0 +1,112 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: Fm453
# @Last modified time: 2021-09-14T23:39:32+08:00
$params = array_merge(
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/../../common/config/params-api.php'),
require(__DIR__ . '/params-local.php')
);
$config = [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'site', //默认路由
'bootstrap' => ['log'],
'modules' => [
"admin" => [
"class" => 'mdm\admin\Module',
],
"data" => [
'class' => 'vendor\fmsoft\modules\data\Module', //自动加载我的数据处理模型
],
],
'aliases' => [
"@mdm/admin" => "@vendor/mdmsoft/yii2-admin",
],
'as access' => [
//加了才会自动验证是否有权限
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
//允许访问的action
//controller/action
// '*', //开发环境配置完成后务必抹掉此项
'site/*',
'index/*'
]
],
'layout' => 'main',//布局文件 优先级: 控制器>配置文件>系统默认
'language' => 'zh-CN', //目标语言
//组件
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'CU5iSYmIp6kbjKKuh541KsA_oaYvTuNh',
],
//身份认证类
'user' => [
'identityClass' => 'backend\models\Adminer',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
'loginUrl' => ['site/login'], //配置登录url(可选项)
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
//Rbac权限控制
'authManager' => [
// 'class' => 'yii\rbac\PhpManager',
'class' => 'yii\rbac\DbManager',
'itemTable' => 'auth_item',
'assignmentTable' => 'auth_assignment',
'itemChildTable' => 'auth_item_child',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'suffix' => '.hi', //后缀
'rules' => [
],
],
],
'params' => $params
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// 'allowedIPs' => ['127.0.0.1', '::1', '你的IP地址']
];
}
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['*'] //允许所有IP访问或指定允许的IP地址
];
}
return $config;
+102
View File
@@ -0,0 +1,102 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: fm453
# @Last modified time: 2021-09-15T09:58:48+08:00
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-api.php'),
require(__DIR__ . '/params.php')
);
$config = [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'site', //默认路由
'bootstrap' => ['log'],
'modules' => [
"admin" => [
"class" => 'mdm\admin\Module',
],
"data" => [
'class' => 'vendor\fmsoft\modules\data\Module', //自动加载我的数据处理模型
],
],
'aliases' => [
"@mdm/admin" => "@vendor/mdmsoft/yii2-admin",
],
'as access' => [
//加了才会自动验证是否有权限
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
//允许访问的action
//controller/action
//'*', //开发环境配置完成后务必抹掉此项
'site/*',
'index/*'
]
],
'layout' => 'main',//布局文件 优先级: 控制器>配置文件>系统默认
'language' => 'zh-CN', //目标语言
//组件
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'CU5iSYmIp6kbjKKuh541KsA_oaYvTuNh',
],
//身份认证类
'user' => [
'identityClass' => 'backend\models\Adminer',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
'loginUrl' => ['site/login'], //配置登录url(可选项)
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
//Rbac权限控制
'authManager' => [
'class' => 'yii\rbac\DbManager',
'itemTable' => 'auth_item',
'assignmentTable' => 'auth_assignment',
'itemChildTable' => 'auth_item_child',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'suffix' => '.hi', //后缀
'rules' => [
],
],
],
'params' => $params
];
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
+25
View File
@@ -0,0 +1,25 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: fm453
# @Last modified time: 2021-09-14T23:20:49+08:00
return [
'configGroup' => [
1 => '基本配置',
2 => '邮箱配置',
3 => '附件配置',
],
'adminEmail' => 'fm453@lukegzs.com',
'noticeEmail' => '393213759@qq.com',
//默认值组
'defaultAdminPassword' => 'Hi12345678', //默认的管理员密码
'defaultAdminAvatar' => '@web/img/profile_small.png', //默认管理员头像
'defaultSuperRoleId' => 1, //默认的超级管理员角色id
'defaultSuperAdminId' => 1, //默认的超级管理员id
'siteOpenTime' => '8:00', //上班时间
'siteCloseTime' => '20:00', //歇业时间
'defaultAttributeValue' => '(未设置)', //空值默认
'defaultActionColumnButtonOption' => ['class' => 'btn btn-white btn-xs'], //列表页操作按钮选项
];
+25
View File
@@ -0,0 +1,25 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: fm453
# @Last modified time: 2021-09-14T23:18:13+08:00
return [
'configGroup' => [
1 => '基本配置',
2 => '邮箱配置',
3 => '附件配置',
],
'adminEmail' => 'fm453@lukegzs.com',
'noticeEmail' => '393213759@qq.com',
//默认值组
'defaultAdminPassword' => 'Hi12345678', //默认的管理员密码
'defaultAdminAvatar' => '@web/img/profile_small.png', //默认管理员头像
'defaultSuperRoleId' => 1, //默认的超级管理员角色id
'defaultSuperAdminId' => 1, //默认的超级管理员id
'siteOpenTime' => '8:00', //上班时间
'siteCloseTime' => '20:00', //歇业时间
'defaultAttributeValue' => '(未设置)', //空值默认
'defaultActionColumnButtonOption' => ['class' => 'btn btn-white btn-xs'], //列表页操作按钮选项
];
+20
View File
@@ -0,0 +1,20 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: fm453
# @Last modified time: 2021-09-14T23:20:10+08:00
$test = [
'id' => 'app-backend-tests',
'components' => [
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
],
];
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/test-local.php'),
require(__DIR__ . '/main-local.php'),
$test
);
+20
View File
@@ -0,0 +1,20 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm43@hiluker.com
# @Last modified by: Fm453
# @Last modified time: 2021-09-14T23:52:44+08:00
$test = [
'id' => 'app-backend-tests',
'components' => [
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
],
];
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../common/config/test.php'),
require(__DIR__ . '/main.php'),
$test
);
+266
View File
@@ -0,0 +1,266 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:23:45
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 00:17:15
* @Email: fm453@lukegzs.com
*/
//运维人员管理
namespace backend\controllers;
use Yii;
use backend\models\AuthItem;
use backend\models\AuthAssignment;
use backend\models\Menu;
use backend\models\Adminer;
use yii\data\Pagination;
use yii\web\Controller;
class AdminerController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
//用户列表
public function actionList()
{
$username = Yii::$app->user->identity->username;
$status = [
0 => ['title'=>'禁用','css'=>'default'],
10 => ['title'=>'启用','css'=>'success'],
];
$search = [];
$search['username'] = Yii::$app->request->get('username');
$search['mobile'] = Yii::$app->request->get('mobile');
$page = (int)Yii::$app->request->get('page');
$page = max(1,$page)-1;
if (Yii::$app->request->post('search')) {
$search = Yii::$app->request->post('search');
}
if($search['username']!=''){
$username = $search['username'];
$data = Adminer::find()->where(['LIKE','username',$username],['<>','status',1]);
}elseif($search['mobile']!=''){
$mobile = $search['mobile'];
$data = Adminer::find()->where(['LIKE','mobile',$mobile],['<>','status',1]);
}else{
$data = Adminer::find()->where(['<>','status',1]);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20','params'=>$search,'page'=>$page]);
$user = $data->joinWith('usergroup')->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('list',[
'user'=>$user,
'search'=>$search,
'status' => $status,
'pages' => $pages
]);
}
//新增用户
public function actionCreate()
{
$model = new Adminer();
$model1 = new AuthItem();
$auth = Yii::$app->authManager;
$item = $auth->getRoles();
$itemArr =array();
foreach($item as $v){
$itemArr[] .= $v->name;
}
foreach($itemArr as $key=>$value)
{
$item_one[$value]=$value;
}
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$model->username = $post['Adminer']['username'];
$model->email = $post['Adminer']['email'];
$model->mobile = $post['Adminer']['mobile'];
$user = Adminer::find()->where(['username'=>$model->username])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '用户名已存在!');
return $this->redirect(['create']);
}
$user = User::find()->where(['mobile'=>$model->mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '手机号已被使用!');
return $this->redirect(['create']);
}
$user = User::find()->where(['email'=>$model->email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '邮箱重复!');
return $this->redirect(['create']);
}
$model->nickname = $post['Adminer']['nickname'];
$model->avatar = $post['Adminer']['avatar'];
$model->setPassword($post['Adminer']['auth_key']);
$model->generateAuthKey();
$model->created_at = time();
$model->save();
$user_id = $model->attributes['id']; //获取插入后id
$role = $auth->createRole($post['AuthItem']['name']);//创建角色对象
$auth->assign($role, $user_id);//添加对应关系
return $this->redirect(['list']);
} else {
return $this->render('create', [
'model' => $model,
'model1' => $model1,
'item' => $item_one,
'params' => Yii::$app->params
]);
}
}
//更新用户
public function actionUpdate(){
$item_name = Yii::$app->request->get('item_name');
$id = Yii::$app->request->get('id');
$model = Adminer::find()->joinWith('usergroup')->where(['id' => $id])->one(); //加入了角色组数据
$auth = Yii::$app->authManager;
$item = $auth->getRoles();
$item_one = $itemArr =array();
foreach($item as $v){
$itemArr[] .= $v->name;
}
foreach($itemArr as $key=>$value)
{
$item_one[$value]=$value;
}
$model1 = $this->findModel($id); //仅账号本身数据
if ($model1->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$mobile = $post['Adminer']['mobile'];
if($model->mobile != $mobile){
$user = Adminer::find()->where(['mobile'=>$mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该手机号已由其他账号绑定!');
return $this->render('update',[
'model' => $model,
'item' => $item_one
]);
}
}
$email = $post['Adminer']['email'];
if($model->email != $email){
$user = Adminer::find()->where(['email'=>$email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该邮箱已有其他账号绑定!');
return $this->render('update',[
'model' => $model,
'item' => $item_one
]);
}
}
//更新密码
if(!empty($post['Adminer']['auth_key_new'])){
$model1->setPassword($post['Adminer']['auth_key_new']);
$model1->generateAuthKey();
}else{
$model1->auth_key = $post['Adminer']['auth_key'];
}
$model1->avatar = $post['Adminer']['avatar'];
$model1->mobile = $post['Adminer']['mobile'];
$model->nickname = $post['Adminer']['nickname'];
$model1->save($post);
//分配角色
if(isset($post['AuthAssignment'])){
$role = $auth->createRole($post['AuthAssignment']['item_name']); //创建角色对象
$user_id = $id;//获取用户id
$auth->revokeAll($user_id);
$auth->assign($role, $user_id);//添加对应关系
}
\Yii::$app->getSession()->setFlash('sucess', '账户信息更新成功!');
return $this->redirect(['list']);
}
return $this->render('update',[
'model' => $model,
'item' => $item_one
]);
}
//剔除用户(软删)
public function actionDelete($id)
{
$id = Yii::$app->request->get('id');
$model = $this->findModel($id);
$model->status = 1;
$res = $model->save();
var_dump($res);die;
//剔除权限
$connection=Yii::$app->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand()->delete("auth_assignment", "user_id = '$id'")->execute();
$transaction->commit();
}
catch(Exception $ex)
{
$transaction->rollBack();
}
\Yii::$app->getSession()->setFlash('sucess', '该账户已删除!');
return $this->redirect(['list']);
}
//删除用户
public function actionRemove($id)
{
$connection=Yii::$app->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand()->delete("c_adminer", "id = '$id'")->execute();
$connection->createCommand()->delete("auth_assignment", "user_id = '$id'")->execute();
$transaction->commit();
}
catch(Exception $ex)
{
$transaction->rollBack();
}
return $this->redirect(['list']);
}
//启停用户
public function actionStatus(){
$id = Yii::$app->request->get('id');
$id = (int)$id;
if($id>0){
$status = Yii::$app->request->get('status');
$model = $this->findModel($id);
$model->status = $status;
$res = $model->save();
if(!$res){
\Yii::$app->getSession()->setFlash('error', '用户状态更新失败!');
}
}
return $this->redirect(['adminer/list']);
}
protected function findModel($id)
{
if (($model = Adminer::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
+189
View File
@@ -0,0 +1,189 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-09 01:20:14
# @Last modified by: Fm453
# @Last modified time: 2021-09-15T00:40:06+08:00
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use common\components\HiCookie;
use common\models\Fans;
class FansController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
//粉丝列表
public function actionList()
{
$username = Yii::$app->user->identity->username;
$cookie = new HiCookie();
$post = Yii::$app->request->post();
$where = $serach = [];
$searchCookie = 'Fans::List';
$Fans = new Fans();
if(isset($_GET['reset']) && $_GET['reset']==1){
$post['search'] = [];
}
if(isset($post['search'])){
$search = $post['search'];
$cookie->set($searchCookie,$search,false);
}elseif($cookie->get($searchCookie)){
$search = $cookie->get($searchCookie);
}
$where[] = 'or';
$search['username'] = isset($search['username']) ? trim(htmlspecialchars_decode($search['username'])) : '';
if($search['username']){
$where[] = ['LIKE','mobile',$search['username']];
}
$search['email'] = isset($search['email']) ? trim(htmlspecialchars_decode($search['email'])) : '';
if($search['email']){
$where[] = ['LIKE','email',$search['email']];
}
//没有搜索条件时,重置一下$where
if(count($where)==1){
$where = [];
}
$data = $Fans->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = $this->getStatus();
return $this->render('list',[
'fans'=>$res,
'search'=>$search,
'count'=>$data->count(),
'status'=>$status,
'pages' => $pages
]);
}
//新增粉丝
public function actionCreate()
{
$model = new Fans();
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$model->mobile = $post['Fans']['username'];
$model->email = $post['Fans']['email'];
$user = Fans::find()->where(['mobile'=>$model->mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该账号已存在!');
return $this->redirect(['create']);
}
$user = Fans::find()->where(['email'=>$model->email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '邮箱重复!');
return $this->redirect(['create']);
}
$model->setPassword($post['Fans']['auth_key']);
$model->generateAuthKey();
$model->created_at = time();
$model->save();
$user_id = $model->attributes['id']; //获取插入后id
return $this->redirect(['list']);
} else {
return $this->render('create', [
'model' => $model,
'params' => Yii::$app->params
]);
}
}
//更新粉丝
public function actionUpdate(){
$id = Yii::$app->request->get('id');
$model = $this->findModel($id);
$status = $this->getStatus();
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$email = $post['Fans']['email'];
if($model->email != $email){
$user = Fans::find()->where(['email'=>$email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该邮箱已有其他账号绑定!');
return $this->render('update',[
'model' => $model,
'status'=>$status,
]);
}
}
//更新密码
if(!empty($post['Fans']['auth_key_new'])){
$model->setPassword($post['Fans']['auth_key_new']);
$model->generateAuthKey();
}else{
$model->auth_key = $post['Fans']['auth_key'];
}
$model->email = $post['Fans']['email'];
$model->status = $post['Fans']['status'];
$res = $model->save($post);
\Yii::$app->getSession()->setFlash('sucess', '账户信息更新成功!');
return $this->redirect(['list']);
}
return $this->render('update',[
'model' => $model,
'status'=>$status,
]);
}
//删除粉丝
public function actionRemove($id)
{
$connection=Yii::$app->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand()->delete(Fans::tableName(), "id = '$id'")->execute();
$transaction->commit();
}
catch(Exception $ex)
{
$transaction->rollBack();
}
return $this->redirect(['list']);
}
protected function findModel($id)
{
if (($model = Fans::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
protected function getStatus(){
return $status = [
0=>'禁用',
1=>'未知',
10=>'正常'
];
}
}
+65
View File
@@ -0,0 +1,65 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:25:38
# @Last modified by: fm453
# @Last modified time: 2021-09-14T12:16:02+08:00
* @Email: fm453@lukegzs.com
*/
//主入口页
namespace backend\controllers;
use Yii;
use common\models\CLog;
use common\models\User;
use common\models\Member;
use common\models\Fans;
use backend\models\Menu;
use yii\data\Pagination;
use yii\web\Controller;
class IndexController extends Controller
{
// public $enableCsrfValidation = false;
public function actionIndex()
{
return $this->render('index');
}
public function actionWelcome()
{
//登录记录
$query = CLog::find();
$nowTable = CLog::tablename();
$count = $query->count();
$pages = new Pagination(['totalCount' => $count,'pageSize' => '10']);
$log = $query->offset($pages->offset)
->limit($pages->limit)
->orderBy('id desc')
->all();
$sql = "SELECT *,FROM_UNIXTIME(create_time,'%Y-%m') as period,COUNT(*) as times FROM ".$nowTable." GROUP BY period LIMIT 12";
$History = Yii::$app->db->createCommand($sql)->queryAll();
$HistoryMonthStr = '';
$HistoryMonthNum = '';
foreach($History as $val){
$HistoryMonthStr .= "'".$val['period']."',";
$HistoryMonthNum .= $val['times'].",";
}
$HistoryMonthStr = substr($HistoryMonthStr,0,-1);
$HistoryMonthNum = substr($HistoryMonthNum,0,-1);
$keywords = '';
$description = '';
return $this->render('welcome',[
'log' => $log,
'pages' => $pages,
'HistoryMonthStr' => $HistoryMonthStr,
'HistoryMonthNum' => $HistoryMonthNum,
'keywords' => $keywords,
'description' => $description,
]);
}
}
+185
View File
@@ -0,0 +1,185 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:27:07
* @Last Modified by: fm453
* @Last Modified time: 2018-04-23 14:28:58
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use backend\models\AuthItem;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\Pagination;
use backend\models\ItemForm;
use yii\helpers\Json;
/**
* ItemController implements the CRUD actions for AuthItem model.
*/
class ItemController extends Controller
{
/*public function beforeAction($action)
{
//$action = Yii::$app->controller->action->id;
$action = Yii::$app->controller->module->requestedRoute;
if(\Yii::$app->user->can($action)){
return true;
}else{
//throw new \yii\web\UnauthorizedHttpException('对不起,您现在还没获此操作的权限');
echo '<div style="margin: 100px auto;text-align: center;background-color: #1ab394; color: #ffffff;width: 500px;height: 50px;line-height: 50px;border-radius: 5px;;"><h4>对不起,您现在还没获此操作的权限</h4></div>';
}
}*/
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all AuthItem models.
* @return mixed
*/
public function actionIndex()
{
$model = new AuthItem();
//分页
$curPage = Yii:: $app-> request->get( 'page',1);
$pageSize = 10;
//搜索
$type = Yii:: $app-> request->get( 'type', '');
$value = Yii:: $app-> request->get( 'value', '');
$search = ($type&&$value)?[ 'like',$type,$value]: '';
//查询语句
$query = $model->find()->where(['type'=>1])->orderBy( 'created_at DESC'); //列表只显示角色
$data = $model->getPages($query,$curPage,$pageSize,$search);
$pages = new Pagination([ 'totalCount' =>$data[ 'count'], 'pageSize' => $pageSize]);
return $this->render('index',['pages'=>$pages,'data'=>$data]);
}
public function actionPermission()
{
$model = new AuthItem();
//分页
$curPage = Yii:: $app-> request->get( 'page',1);
$pageSize = 10;
//搜索
$type = Yii:: $app-> request->get( 'type', '');
$value = Yii:: $app-> request->get( 'value', '');
$search = ($type&&$value)?[ 'like',$type,$value]: '';
//查询语句
$query = $model->find()->where(['type'=>2])->orderBy( 'created_at DESC'); //列表只显示角色
$data = $model->getPages($query,$curPage,$pageSize,$search);
$pages = new Pagination([ 'totalCount' =>$data[ 'count'], 'pageSize' => $pageSize]);
return $this->render('index',['pages'=>$pages,'data'=>$data]);
}
/**
* Displays a single AuthItem model.
* @param string $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new AuthItem model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new AuthItem();
//设置场景
$model->setScenario(ItemForm:: SCENARIOS_CREATE);
if ($model->load(Yii::$app->request->post())) {
if($model->validate()){
$model->addItem();
return $this->redirect(['index']);
}
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing AuthItem model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param string $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = new AuthItem();
$model = $model-> getItem($id);
//设置场景
$model->setScenario(AuthItem:: SCENARIOS_UPDATE);
if ($model->load(Yii:: $app-> request->post())) {
if($model->validate()){
$model->updateItem($id);
return $this->redirect([ 'view', 'id' => $model->name]);
}
}
return $this->render( 'update', [
'model' => $model,
]);
}
/**
* Deletes an existing AuthItem model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param string $id
* @return mixed
*/
public function actionDelete()
{
$model = new AuthItem();
$model->setScenario(AuthItem:: SCENARIOS_DELETE);
$model-> name = Yii:: $app-> request->post('id');
$res = $model->romoveItem();
if(!$res){
return Json:: encode(['status'=>false,'msg'=>'删除失败!']);
}
return Json::encode(['status' =>true]);
}
/**
* Finds the AuthItem model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return AuthItem the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = AuthItem::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
+206
View File
@@ -0,0 +1,206 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-09 01:20:14
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 08:54:55
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use common\components\HiCookie;
use common\models\Member;
class MemberController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
//会员列表
public function actionList()
{
$username = Yii::$app->user->identity->username;
$cookie = new HiCookie();
$post = Yii::$app->request->post();
$where = $serach = [];
$searchCookie = 'Member::List';
$Member = new Member();
if(isset($_GET['reset']) && $_GET['reset']==1){
$post['search'] = [];
}
if(isset($post['search'])){
$search = $post['search'];
$cookie->set($searchCookie,$search,false);
}elseif($cookie->get($searchCookie)){
$search = $cookie->get($searchCookie);
}
$where[] = 'or';
$search['username'] = isset($search['username']) ? trim(htmlspecialchars_decode($search['username'])) : '';
if($search['username']){
$where[] = ['LIKE','username',$search['username']];
}
$search['mobile'] = isset($search['mobile']) ? trim(htmlspecialchars_decode($search['mobile'])) : '';
if($search['mobile']){
$where[] = ['LIKE','mobile',$search['mobile']];
}
$search['email'] = isset($search['email']) ? trim(htmlspecialchars_decode($search['email'])) : '';
if($search['email']){
$where[] = ['LIKE','email',$search['email']];
}
//没有搜索条件时,重置一下$where
if(count($where)==1){
$where = [];
}
$data = $Member->find()->where($where);
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$members = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = [
0=>'禁用',
1=>'正常'
];
return $this->render('list',[
'member'=>$members,
'search'=>$search,
'count'=>$data->count(),
'status'=>$status,
'pages' => $pages
]);
}
//新增会员
public function actionCreate()
{
$model = new Member();
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$model->username = $post['Member']['username'];
$model->mobile = $post['Member']['mobile'];
$model->email = $post['Member']['email'];
$user = Member::find()->where(['mobile'=>$model->mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该手机号已使用!');
return $this->redirect(['create']);
}
$user = Member::find()->where(['email'=>$model->email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '邮箱重复!');
return $this->redirect(['create']);
}
$model->avatar = $post['Member']['avatar'];
$model->setPassword($post['Member']['auth_key']);
$model->generateAuthKey();
$model->created_at = time();
$model->save();
$user_id = $model->attributes['id']; //获取插入后id
return $this->redirect(['list']);
} else {
return $this->render('create', [
'model' => $model,
'params' => Yii::$app->params
]);
}
}
//更新会员
public function actionUpdate(){
$id = Yii::$app->request->get('id');
$model = $this->findModel($id);
$status = [
0=>'禁用',
1=>'正常'
];
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$mobile = $post['Member']['mobile'];
if($model->mobile != $mobile){
$user = Member::find()->where(['mobile'=>$mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该手机号已由其他账号绑定!');
return $this->render('update',[
'model' => $model,
'status'=>$_status,
]);
}
}
$email = $post['Member']['email'];
if($model->email != $email){
$user = Member::find()->where(['email'=>$email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该邮箱已有其他账号绑定!');
return $this->render('update',[
'model' => $model,
'status'=>$status,
]);
}
}
//更新密码
if(!empty($post['Member']['auth_key_new'])){
$model->setPassword($post['Member']['auth_key_new']);
$model->generateAuthKey();
}else{
$model->auth_key = $post['Member']['auth_key'];
}
$model->avatar = $post['Member']['username'];
$model->avatar = $post['Member']['avatar'];
$model->mobile = $post['Member']['mobile'];
$model->email = $post['Member']['email'];
$model->status = $post['Member']['status'];
$res = $model->save($post);
\Yii::$app->getSession()->setFlash('sucess', '账户信息更新成功!');
return $this->redirect(['list']);
}
return $this->render('update',[
'model' => $model,
'status'=>$status,
]);
}
//删除会员
public function actionRemove($id)
{
$connection=Yii::$app->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand()->delete(Member::tableName(), "id = '$id'")->execute();
$transaction->commit();
}
catch(Exception $ex)
{
$transaction->rollBack();
}
return $this->redirect(['list']);
}
protected function findModel($id)
{
if (($model = Member::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
+174
View File
@@ -0,0 +1,174 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:29:02
* @Last Modified by: fm453
* @Last Modified time: 2018-04-23 14:29:07
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use backend\models\Menu;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use backend\models\AuthItem;
use yii\data\Pagination;
/**
* MenuController implements the CRUD actions for Menu model.
*/
class MenuController extends Controller
{
/**
* @inheritdoc
*/
/*public function behaviors()
{
$action = Yii::$app->controller->module->requestedRoute;
if(\Yii::$app->user->can($action)){
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['GET'],
],
],
];
}else{
//throw new \yii\web\UnauthorizedHttpException('对不起,您现在还没获此操作的权限');
echo '<div style="margin: 100px auto;text-align: center;background-color: #1ab394; color: #ffffff;width: 500px;height: 50px;line-height: 50px;border-radius: 5px;;"><h4>对不起,您现在还没获此操作的权限</h4></div>';
}
}*/
/**
* Lists all Menu models.
* @return mixed
*/
public function actionIndex()
{
$menu = new Menu();
$menu = $menu->getMenuList();
return $this->render('index', [
'menu' => $menu
]);
}
/**
* Displays a single Menu model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Menu model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Menu();
$menu = $model->getAllMenu();
$menuArr = array('0'=>"顶级菜单");
foreach($menu as $v){
$menuArr[$v['id']] = $v['name'];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
//增加菜单同时增加权限
$post = Yii::$app->request->post();
$name = $post['Menu']['route'];
if(!empty($name)){
$auth = Yii::$app->authManager;
$createPost = $auth->createPermission($name);
$createPost->description = '创建了[' . $name. ']权限';
$auth->add($createPost);
//将权限赋给角色
$parent = $auth->createRole('超级管理员'); //创建角色对象
$child = $auth->createPermission($name); //创建权限对象
$auth->addChild($parent, $child); //添加对应关系
}
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
'menuArr' => $menuArr,
]);
}
}
/**
* Updates an existing Menu model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$menu = $model->getAllMenu();
$menuArr = array('0'=>"顶级菜单");
foreach($menu as $v){
$menuArr[$v['id']] = $v['name'];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
'menuArr' => $menuArr,
]);
}
}
/**
* Deletes an existing Menu model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
//通过id找到router
$MenuModel = new Menu();
$name = $MenuModel->getRouteById($id);
//删除菜单同时删除权限
if(!empty($name)){
$model = new AuthItem();
$model->setScenario(AuthItem:: SCENARIOS_DELETE);
$model-> name = $name;
$res = $model->romoveItem();
}
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Menu model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Menu the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
+146
View File
@@ -0,0 +1,146 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:29:14
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 10:11:46
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use backend\models\AuthItem;
use backend\models\Menu;
use backend\models\AuthItemChild;
use yii\web\Controller;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* PermissionController implements the CRUD actions for AuthItemChild model.
*/
class PermissionController extends Controller
{
public $enableCsrfValidation = false;
/**
* @inheritdoc
*/
/*public function beforeAction($action)
{
$action = Yii::$app->controller->module->requestedRoute;
if(\Yii::$app->user->can($action)){
return true;
}else{
echo '<div style="margin: 100px auto;text-align: center;background-color: #1ab394; color: #ffffff;width: 500px;height: 50px;line-height: 50px;border-radius: 5px;;"><h4>对不起,您现在还没获此操作的权限</h4></div>';
}
}*/
//给角色配置权限
public function actionSet($id)
{
$auth = Yii::$app->authManager;
$Permission = $auth->getPermissionsByRole($id);
$items = AuthItem::find()->joinWith('permissionName')->where(['type' => '2'])->all();
$menu = Menu::find()->where(['parent'=>'0'])->all();
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$parent = $auth->createRole($post['parent']); //创建角色对象
if(!empty($post['permission'])){
$auth->removeChildren($parent);
foreach($post['permission'] as $v){
$child = $auth->createPermission($v); //创建权限对象
$auth->addChild($parent, $child); //重新增加对应权限
}
}else{
$auth->removeChildren($parent); //权限节点全不选择,清除对应权限
}
return $this->redirect(['permission/set','id'=>$parent->name]);
} else {
return $this->render('set', [
'Permission' => $Permission,
'items'=>$items,
'id'=>$id,
'menu' =>$menu
]);
}
}
/**
* Lists all AuthItemChild models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => AuthItemChild::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single AuthItemChild model.
* @param string $parent
* @param string $child
* @return mixed
*/
public function actionView($parent, $child)
{
return $this->render('view', [
'model' => $this->findModel($parent, $child),
]);
}
/**
* Creates a new AuthItemChild model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new AuthItemChild();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'parent' => $model->parent, 'child' => $model->child]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Deletes an existing AuthItemChild model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param string $parent
* @param string $child
* @return mixed
*/
public function actionDelete($parent, $child)
{
$this->findModel($parent, $child)->delete();
return $this->redirect(['index']);
}
/**
* Finds the AuthItemChild model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $parent
* @param string $child
* @return AuthItemChild the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($parent, $child)
{
if (($model = AuthItemChild::findOne(['parent' => $parent, 'child' => $child])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
/**
* @Author: fm453
* @Date: 2018-04-23 14:29:56
* @Last Modified by: fm453
* @Last Modified time: 2021-09-08 13:28:31
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use backend\models\LoginForm;
use backend\models\Menu;
use backend\components\Helper;
/**
* Site controller
*/
class SiteController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['logout', 'index'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['get'],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
public function actionIndex()
{
$user_id=Yii::$app->user->identity->getId();
$user_info = Yii::$app->authManager->getRolesByUser($user_id);
$menu = new Menu();
$menu = $menu->getLeftMenuList();
return $this->render('index',[
'menu' => $menu,
'user_info' => key($user_info)
]);
}
public function actionList()
{
return $this->render('list');
}
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$model->loginLog(); //将登陆记录到日志表
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
public function actionError($e){
echo $e;
}
}
+211
View File
@@ -0,0 +1,211 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-08 17:26:29
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 03:12:35
* @Email: fm453@lukegzs.com
*/
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use common\models\User;
class UserController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
//用户列表
public function actionList()
{
$username = Yii::$app->user->identity->username;
$search = [];
$search['username'] = Yii::$app->request->get('username');
$search['mobile'] = Yii::$app->request->get('mobile');
$page = (int)Yii::$app->request->get('page');
$page = max(1,$page)-1;
if (Yii::$app->request->post('search')) {
$search = Yii::$app->request->post('search');
}
if($search['username']!=''){
$username = $search['username'];
$data = User::find()->where(['LIKE','username',$username],['>','status',0]);
}elseif($search['mobile']!=''){
$mobile = $search['mobile'];
$data = User::find()->where(['LIKE','mobile',$mobile],['>','status',0]);
}else{
$data = User::find()->where(['>','status',0]);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20','params'=>$search,'page'=>$page]);
$user = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = User::status();
return $this->render('list',[
'user'=>$user,
'search'=>$search,
'status' => $status,
'pages' => $pages
]);
}
//新增用户
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$model->username = $post['User']['username'];
$model->mobile = $post['User']['mobile'];
$model->email = $post['User']['email'];
$user = User::find()->where(['username'=>$model->username])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '用户名已存在!');
return $this->redirect(['create']);
}
$user = User::find()->where(['mobile'=>$model->mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该手机号已使用!');
return $this->redirect(['create']);
}
$user = User::find()->where(['email'=>$model->email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '邮箱重复!');
return $this->redirect(['create']);
}
$model->avatar = $post['User']['avatar'];
$model->setPassword($post['User']['auth_key']);
$model->generateAuthKey();
$model->created_at = time();
$model->save();
$user_id = $model->attributes['id']; //获取插入后id
return $this->redirect(['list']);
} else {
return $this->render('create', [
'model' => $model,
'params' => Yii::$app->params
]);
}
}
//更新用户
public function actionUpdate(){
$id = Yii::$app->request->get('id');
$model = $this->findModel($id);
$status = User::status();
$_status = [];
foreach($status as $k => $v){
$_status[$k] = $v['title'];
}
if ($model->load(Yii::$app->request->post())) {
$post = Yii::$app->request->post();
$mobile = $post['User']['mobile'];
if($model->mobile != $mobile){
$user = User::find()->where(['mobile'=>$mobile])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该手机号已由其他账号绑定!');
return $this->render('update',[
'model' => $model,
'userstatus'=>$_status,
]);
}
}
$email = $post['User']['email'];
if($model->email != $email){
$user = User::find()->where(['email'=>$email])->all();
if(!empty($user)){
\Yii::$app->getSession()->setFlash('error', '该邮箱已有其他账号绑定!');
return $this->render('update',[
'model' => $model,
'userstatus'=>$_status,
]);
}
}
//更新密码
if(!empty($post['User']['auth_key_new'])){
$model->setPassword($post['User']['auth_key_new']);
$model->generateAuthKey();
}else{
$model->auth_key = $post['User']['auth_key'];
}
$model->avatar = $post['User']['avatar'];
$model->mobile = $post['User']['mobile'];
$model->email = $post['User']['email'];
$model->status = $post['User']['status'];
$model->sms_left = $post['User']['sms_left'];
$res = $model->save($post);
\Yii::$app->getSession()->setFlash('sucess', '账户信息更新成功!');
return $this->redirect(['list']);
}
return $this->render('update',[
'model' => $model,
'userstatus'=>$_status,
]);
}
//移除用户(软删除)
public function actionDelete($id)
{
$id = Yii::$app->request->get('id');
$model = $this->findModel($id);
$model->status = 0;
$model->save();
return $this->redirect(['list']);
}
//删除用户
public function actionRemove($id)
{
$connection=Yii::$app->db;
$transaction=$connection->beginTransaction();
try
{
$connection->createCommand()->delete("c_user", "id = '$id'")->execute();
$transaction->commit();
}
catch(Exception $ex)
{
$transaction->rollBack();
}
return $this->redirect(['list']);
}
//启停用户
public function actionStatus(){
$id = Yii::$app->request->get('id');
$id = (int)$id;
if($id>0){
$status = Yii::$app->request->get('status');
$model = $this->findModel($id);
$model->status = $status;
$res = $model->save();
if(!$res){
\Yii::$app->getSession()->setFlash('error', '用户状态更新失败!');
}
}
return $this->redirect(['list']);
}
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
Executable
+8
View File
@@ -0,0 +1,8 @@
api账号
账号:publicapi
密码:api.hiluker
——————————————————————————
admin超级账号
账号: fm453
密码: Lukegzs168.com
+22
View File
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>恭喜,站点创建成功!</title>
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="//cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="margin-top:9%;">
<div class="jumbotron">
<div class="panel panel-success">
<div class="panel-heading"><h1>恭喜, 站点创建成功!</h1></div>
</div>
<p><h3>站点创建成功,本页面由系统自动生成。</h3></p>
<p><li>本页面在FTP根目录下的index.html</li></p>
<p><li>您可以删除或覆盖本页面</li></p>
</div>
</div>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
*
+218
View File
@@ -0,0 +1,218 @@
<?php
# @Author: fm453
# @Date: 2021-12-31T04:42:26+08:00
# @Last modified by: fm453
# @Last modified time: 2022-01-29T23:43:56+08:00
namespace backend\models;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\base\NotSupportedException;
use backend\models\AuthAssignment;
use yii\web\IdentityInterface;
class Adminer extends ActiveRecord implements IdentityInterface
{
public $password;
const STATUS_DELETE = 0;
const STATUS_ACTIVE = 10;
public static $statusTexts = [
self::STATUS_DELETE => '禁用',
self::STATUS_ACTIVE => '启用',
];
public static $statusStyles = [
self::STATUS_DELETE => 'label-warning',
self::STATUS_ACTIVE => 'label-info',
];
public static function tableName() {
return '{{%c_adminer}}';
}
public function behaviors() {
return [
TimestampBehavior::className(),
];
}
public function rules() {
return [
[['username', 'email'], 'required'],
[['username'], 'string', 'length' => [2, 32]],
[['nickname'],'string','max'=>32],
[['password'], 'required', 'on' => ['create']],
[['auth_key'], 'string', 'length' => 32],
[['username', 'email','mobile'], 'unique'],
[['email'], 'email'],
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [
self::STATUS_DELETE,self::STATUS_ACTIVE,1
]], //状态值1是软删除
[['status', 'created_at', 'updated_at'], 'integer'],
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
//去除首尾空白
[['username', 'nickname', 'mobile', 'email'], 'filter', 'filter' => 'trim'],
];
}
public function attributeLabels() {
return [
'id' => 'ID',
'username' => Yii::t('common' ,'Username'),
'nickname' => '姓名',
'auth_key' => Yii::t('common' ,'Password'),
'password_hash' => 'Password Hash',
'email' => Yii::t('common' ,'Email'),
'mobile' => Yii::t('common' ,'Mobile'),
'status' => '状态',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'user_role' => '所属角色',
'role' => Yii::t('common' ,'Role'),
];
}
public function scenarios() {
$scenarios = parent::scenarios();
$scenarios['create'] = ['username', 'email', 'password', 'status'];
$scenarios['update'] = ['username', 'email', 'password', 'status'];
return $scenarios;
}
/*用户组 S*/
public function getUsergrouplist()
{
/**
* 第一个参数为要关联的字表模型类名称,
*第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
*/
return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']);
}
public function getUsergroup()
{
/**
* 第一个参数为要关联的字表模型类名称,
*第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
*/
return $this->hasOne(AuthAssignment::className(), ['user_id' => 'id']);
}
/*用户组 E*/
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
public function beforeSave($insert) {
if($this->isNewRecord) {
$this->generateAuthKey();
}
if(!empty($this->password)) $this->setPassword($this->password);
return parent::beforeSave($insert);
}
/**
* 生成加密后的密码
* @param [string] $password [用户密码]
*/
public function setPassword($password) {
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/*获取所有用户*/
public function get_all_user(){
// $user = Yii::$app->db->createCommand('select * from '. tableName())->queryAll();
$user = static::findAll();
return $user;
}
/**
* 获取账号信息
* @param [int] $id [后台用户id]
*/
public static function findIdentity($id) {
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
public static function findIdentityByAccessToken($token, $type = null) {
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* 获取账号信息
* @param [string] $username [用户名]
*/
public static function findByUsername($username) {
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
//获取用户所在的用户组
public function getGroup() {
return implode(',', array_keys(Yii::$app->authManager->getRolesByUser($this->id)));
}
/**
* 获取账号主键值(id)
*/
public function getId() {
return $this->getPrimaryKey();
}
/**
* 获取账号auth_key值
*/
public function getAuthKey() {
return $this->auth_key;
}
/**
* 验证auth_key
* @param [string] $authKey [auth key]
*/
public function validateAuthKey($authKey) {
return $this->getAuthKey() === $authKey;
}
/**
* 验证用户密码
* @param [string] $password [用户密码]
*/
public function validatePassword($password) {
return Yii::$app->security->validatePassword($password, $this->password_hash);
return true;
}
/**
* 获取账号状态
*/
public function getStatus() {
return self::$statusTexts[$this->status];
}
/**
* 获取账号状态样式
*/
public function getStatusStyle() {
return self::$statusStyles[$this->status];
}
/**
* 获取状态
*/
public function getStatusTexts() {
return self::$statusTexts;
}
}
+58
View File
@@ -0,0 +1,58 @@
<?php
namespace backend\models;
use Yii;
/**
* This is the model class for table "auth_assignment".
*
* @property string $item_name
* @property string $user_id
* @property integer $created_at
*
* @property AuthItem $itemName
*/
class AuthAssignment extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%auth_assignment}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['item_name', 'user_id'], 'required'],
[['created_at'], 'integer'],
[['item_name', 'user_id'], 'string', 'max' => 64],
[['item_name'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::className(), 'targetAttribute' => ['item_name' => 'name']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'item_name' => 'Item Name',
'user_id' => 'User ID',
'created_at' => 'Created At',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getItemName()
{
return $this->hasOne(AuthItem::className(), ['name' => 'item_name']);
}
}
+217
View File
@@ -0,0 +1,217 @@
<?php
namespace backend\models;
use Yii;
use common\models\base\BaseModel;
use backend\models\Menu;
/**
* This is the model class for table "auth_item".
*
* @property string $name
* @property integer $type
* @property string $description
* @property string $rule_name
* @property string $data
* @property integer $created_at
* @property integer $updated_at
*
* @property AuthAssignment[] $authAssignments
* @property AuthRule $ruleName
* @property AuthItemChild[] $authItemChildren
* @property AuthItemChild[] $authItemChildren0
* @property AuthItem[] $children
* @property AuthItem[] $parents
*/
class AuthItem extends BaseModel
{
const T_ROLE = 1; //角色
const T_POWER = 2; //权限
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_DELETE = 'delete';
const SCENARIOS_UPDATE = 'update';
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%auth_item}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'type'], 'required'],
[['type', 'created_at', 'updated_at'], 'integer'],
[['description', 'data'], 'string'],
[['name', 'rule_name'], 'string', 'max' => 64],
[['rule_name'], 'exist', 'skipOnError' => true, 'targetClass' => AuthRule::className(), 'targetAttribute' => ['rule_name' => 'name']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'name' => '名称',
'type' => '类型',
'description' => '描述',
'rule_name' => '规则名称',
'data' => 'Data',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthAssignments()
{
return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getRuleName()
{
return $this->hasOne(AuthRule::className(), ['name' => 'rule_name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItemChildren()
{
return $this->hasMany(AuthItemChild::className(), ['parent' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItemChildren0()
{
return $this->hasMany(AuthItemChild::className(), ['child' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getChildren()
{
return $this->hasMany(AuthItem::className(), ['name' => 'child'])->viaTable('auth_item_child', ['parent' => 'name']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getParents()
{
return $this->hasMany(AuthItem::className(), ['name' => 'parent'])->viaTable('auth_item_child', ['child' => 'name']);
}
/**
* 场景设置
* @see \yii\base\Model::scenarios()
*/
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'type', 'description'],
self:: SCENARIOS_DELETE => ['name'],
self:: SCENARIOS_UPDATE => ['name', 'type', 'description'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
/**
* 角色&权限的创建方法
* @return boolean 返回成功或者失败的状态值
*/
public function addItem()
{
//实例化AuthManager类
$auth = Yii::$app->authManager;
if($this->type == self::T_ROLE){
$item = $auth->createRole($this->name);
$item->description = $this->description?:'创建['.$this->name.']角色';
}else{
$item = $auth->createPermission($this->name);
$item->description = $this->description?:'创建['.$this->name.']权限';
}
return $auth->add($item);
}
/**
* 角色&权限的删除方法
* @return boolean 返回成功或者失败的状态值
*/
public function romoveItem()
{
$this->name = trim($this->name);
if($this->validate()){
$auth = Yii::$app->authManager;
$item = $auth->getRole($this->name)?:$auth->getPermission($this->name);
return $auth->remove($item);
}
return false;
}
/**
* 获取权限
* @param unknown $id
* @throws \Exception
*/
public function getItem($id) {
$model = AuthItem:: findOne(['name'=>$id]);
if(!$model)
throw new \Exception( '编辑的角色或权限不存在!' );
$this-> name = $model-> name;
$this-> type = $model-> type;
$this-> description = $model-> description;
return $this;
}
/**
* 编辑权限
* @param unknown $item_name
* @return boolean
*/
public function updateItem($item_name)
{
$auth = Yii:: $app-> authManager;
if($this->type == self::T_ROLE){
$item = $auth->createRole($this-> name);
$item-> description = $this-> description?: '创建['.$this-> name. ']角色';
}else{
$item = $auth->createPermission($this-> name);
$item-> description = $this-> description?: '创建['.$this-> name. ']权限';
}
return $auth->update($item_name, $item);
}
//获取所有的权限
public function getAllPermission(){
$permission = self::find()->where(['type'=>2])->all();
return $permission;
}
//关联菜单数据
public function getPermissionName(){
return $this->hasOne(Menu::className(), ['route' => 'name']);
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace backend\models;
use Yii;
/**
* This is the model class for table "auth_item_child".
*
* @property string $parent
* @property string $child
*
* @property AuthItem $parent0
* @property AuthItem $child0
*/
class AuthItemChild extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%auth_item_child}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['parent', 'child'], 'required'],
[['parent', 'child'], 'string', 'max' => 64],
[['parent'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::className(), 'targetAttribute' => ['parent' => 'name']],
[['child'], 'exist', 'skipOnError' => true, 'targetClass' => AuthItem::className(), 'targetAttribute' => ['child' => 'name']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'parent' => 'Parent',
'child' => 'Child',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getParent0()
{
return $this->hasOne(AuthItem::className(), ['name' => 'parent']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getChild0()
{
return $this->hasOne(AuthItem::className(), ['name' => 'child']);
}
public function getPermission($id){
$permission = self::find()->where(['parent'=>$id])->asArray()->all();
return $permission;
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace backend\models;
use Yii;
/**
* This is the model class for table "auth_rule".
*
* @property string $name
* @property string $data
* @property integer $created_at
* @property integer $updated_at
*
* @property AuthItem[] $authItems
*/
class AuthRule extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%auth_rule}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['data'], 'string'],
[['created_at', 'updated_at'], 'integer'],
[['name'], 'string', 'max' => 64],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'name' => 'Name',
'data' => 'Data',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthItems()
{
return $this->hasMany(AuthItem::className(), ['rule_name' => 'name']);
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace backend\models;
/**
* @author Xianan Huang
*
*/
use Yii;
use yii\base\Model;
use backend\models\AuthRule;
class ItemForm extends Model
{
public $name;
public $type;
public $description;
const T_ROLE = 1; //角色
const T_POWER = 2; //权限
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_DELETE = 'delete';
public function rules()
{
return [
[['name', 'type'], 'required'],
['name', 'unique', 'targetClass' => '\common\models\AuthItemModel', 'message' => '此名称已经被占用。'],
['type', 'integer'],
[['name', 'description'], 'string', 'max' => 25],
[['rule_name'], 'exist', 'skipOnError' => true, 'targetClass' => AuthRule::className(), 'targetAttribute' => ['rule_name' => 'name']]
];
}
public function attributeLabels()
{
return [
'name' => '名称',
'type' => '类型',
'description' => '描述',
];
}
/**
* 场景设置
* @see \yii\base\Model::scenarios()
*/
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'type', 'description'],
self:: SCENARIOS_DELETE => ['name'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
/**
* 角色&权限的创建方法
* @return boolean 返回成功或者失败的状态值
*/
public function addItem()
{
//实例化AuthManager类
$auth = Yii::$app->authManager;
if($this->type == self::T_ROLE){
$item = $auth->createRole($this->name);
$item->description = $this->description?:'创建['.$this->name.']角色';
}else{
$item = $auth->createPermission($this->name);
$item->description = $this->description?:'创建['.$this->name.']权限';
}
return $auth->add($item);
}
}
+133
View File
@@ -0,0 +1,133 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-09 22:59:04
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 23:00:33
* @Email: fm453@lukegzs.com
*/
namespace backend\models;
use Yii;
use yii\base\Model;
use common\models\CLog;
use backend\models\Adminer;
/**
* Login form
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = false;
private $_user; //防止被外部程序修改
/**
* @inheritdoc
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => Yii::t('common','Username'),
'password' => Yii::t('common','Password'),
'rememberMe' => Yii::t('common','Remember Me'),
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, Yii::t('common','Incorrect username or password.'));
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false; //如果为true 将允许任意密码登陆
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = Adminer::findByUsername($this->username); //千万注意后端的登陆使用的是Adminer模型,不是User
}
return $this->_user;
}
//登录记录
public function loginLog(){
$request = Yii::$app->getRequest();
$nowFile = $request -> getScriptFile();
$data = "登陆系统|途径:".$nowFile;
$model = new CLog();
$model->username = $this->username;
$model->ip = Yii::$app->request->userIP;
$model->data = $data;
$model->create_time = time();
$model->save();
//编制邮件发送通知
$message = Yii::$app->mailer->compose();
$message->setFrom(Yii::$app->params['noticeEmail']);
//给登陆者发送
$subject = "账号登陆提醒";
$body = "您的账号【".$this->username."】刚刚登陆了网站:".Yii::$app->getRequest()->absoluteUrl;
$message->setTo(Yii::$app->user->identity->email)
->setSubject($subject)
->setTextBody($body)
->send();
//给管理人员发送
$subject = "账号登陆提醒";
$body = "运维账号【".$this->username."】刚刚登陆了网站:".Yii::$app->getRequest()->absoluteUrl;
$message->setTo('1280880631@qq.com')
->setSubject($subject)
->setTextBody($body)
->send();
}
}
+154
View File
@@ -0,0 +1,154 @@
<?php
namespace backend\models;
use Yii;
/**
* This is the model class for table "c_menu".
*
* @property integer $id
* @property string $name
* @property integer $parent
* @property string $route
* @property integer $order
* @property string $data
*/
class Menu extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_menu}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['parent', 'sort'], 'integer'],
[['data'], 'string'],
[['status'], 'string'],
[['name'], 'string', 'max' => 128],
[['route'], 'string', 'max' => 256],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名称',
'parent' => '父级',
'route' => '路由',
'sort' => '排序',
'data' => '描述',
];
}
//获取顶级菜单列表
public function getAllMenu(){
$menu = Yii::$app->db->createCommand("SELECT * FROM ".$this->tableName()." WHERE parent='0' ")->queryAll();
return $menu;
}
//获取所有菜单列表
public function getMenuList(){
$menu = Yii::$app->db->createCommand("SELECT * FROM ".$this->tableName()." ORDER BY sort ASC ")->queryAll();
$menu = self::list_to_tree($menu,'id','parent');
return $menu;
}
//获取左侧菜单列表
public function getLeftMenuList(){
$uid = Yii::$app->user->identity->getId();
$auth = Yii::$app->authManager;
$Permission = $auth->getPermissionsByUser($uid);
$RoutesList = '';
foreach($Permission as $vo){
$RoutesList .= "'".$vo->name."',";
}
$RoutesList = substr($RoutesList,0,-1);
if($RoutesList == ''){
$RoutesList = "'/index/welcome','/site/index'";
}
$menu = Yii::$app->db->createCommand("SELECT * FROM ".$this->tableName()." WHERE route IN ($RoutesList) ORDER BY `order` ASC")->queryAll();
$menu = Yii::$app->db->createCommand("SELECT * FROM ".$this->tableName()." ORDER BY `order` ASC")->queryAll();
$menu = self::list_to_tree2($menu,'id','parent');
return $menu;
}
//通过id找到router
public function getRouteById($id){
$router = Yii::$app->db->createCommand("SELECT * FROM `".$this->tableName()."` WHERE id='$id'")->queryOne();
return $router['route'];
}
/**
* 把返回的数据集转换成Tree
* @param array $list 要转换的数据集
* @param string $pid parent标记字段
* @param string $level level标记字段
* @return array
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
function list_to_tree($list, $pk='id', $pid = 'pid', $child = '_child', $root = 0) {
// 创建Tree
$tree = array();
if(is_array($list)) {
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$list[$key]['name'] ='&nbsp;&nbsp;&nbsp;&nbsp;|--'.$list[$key]['name'];
$parent[$child][] =& $list[$key];
}
}
}
}
return $tree;
}
function list_to_tree2($list, $pk='id', $pid = 'pid', $child = '_child', $root = 0) {
// 创建Tree
$tree = array();
if(is_array($list)) {
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$list[$key]['name'] =$list[$key]['name'];
$parent[$child][] =& $list[$key];
}
}
}
}
return $tree;
}
}
+2
View File
@@ -0,0 +1,2 @@
管理后台
本系统整体为超级管理,只用于控制权限、管理站群集中数据等;
Binary file not shown.
@@ -0,0 +1 @@
a:2:{i:0;s:21:"0.89175900 1721813425";i:1;N;}
@@ -0,0 +1 @@
a:2:{i:0;s:21:"0.93636400 1721816489";i:1;N;}
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More