Initial commit,修正
This commit is contained in:
Executable
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use backend\models\AuthAssignment;
|
||||
|
||||
class Adminer extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
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 rules() {
|
||||
return [
|
||||
//[['username', 'email'], 'required'],
|
||||
//[['username'], 'string', 'length' => [6, 15]],
|
||||
//[['password'], 'required', 'on' => ['create']],
|
||||
//[['reg_ip', 'last_login_time', 'last_login_ip'], 'integer'],
|
||||
//[['auth_key'], 'string', 'length' => 32],
|
||||
//[['username', 'email'], 'unique'],
|
||||
//[['email'], 'email'],
|
||||
//['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
//['status', 'in', 'range' => [
|
||||
// self::STATUS_ACTIVE, self::STATUS_DELETE
|
||||
//]],
|
||||
|
||||
[['username','email'], 'required'],
|
||||
//[['role', 'status', 'created_at', 'updated_at'], 'integer'],
|
||||
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
|
||||
[['auth_key'], 'string', 'max' => 32],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'username' => Yii::t('common' ,'Username'),
|
||||
'auth_key' => Yii::t('common' ,'Password'),
|
||||
'auth_key' => Yii::t('common' ,'Password'),
|
||||
'password_hash' => 'Password Hash',
|
||||
'email' => Yii::t('common' ,'Email'),
|
||||
'mobile' => Yii::t('common' ,'Mobile'),
|
||||
'reg_ip' => 'Reg Ip',
|
||||
'last_login_time' => '最后登录时间',
|
||||
'last_login_ip' => '最后登录IP',
|
||||
'status' => '状态',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
'user_role' => '所属角色',
|
||||
'role' => Yii::t('common' ,'Role'),
|
||||
];
|
||||
}
|
||||
|
||||
//获取所有用户
|
||||
public function get_all_user(){
|
||||
$user = Yii::$app->db->createCommand('select * from '. tableName())->queryAll();
|
||||
return $user;
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates password hash from password and sets it to the model
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates "remember me" authentication key
|
||||
*/
|
||||
public function generateAuthKey()
|
||||
{
|
||||
$this->auth_key = Yii::$app->security->generateRandomString();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+58
@@ -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']);
|
||||
}
|
||||
}
|
||||
Executable
+217
@@ -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']);
|
||||
}
|
||||
}
|
||||
Executable
+70
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable
+60
@@ -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']);
|
||||
}
|
||||
}
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:10:33
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2018-11-22 10:23:52
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "c_attachment".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $pid 平台ID
|
||||
* @property int $mid 关联会员ID
|
||||
* @property int $uid 关联管理员ID
|
||||
* @property int $type 附件类型
|
||||
* @property string $title 附件标题
|
||||
* @property string $route 附件路径
|
||||
* @property int $filesize 附件大小(byte)
|
||||
* @property string $options 额外参数
|
||||
* @property int $status_code 状态代码
|
||||
* @property int $deleted 是否删除
|
||||
* @property int $update_at 数据更新时间
|
||||
* @property int $create_at 数据创建时间
|
||||
*/
|
||||
class CAttachment extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'c_attachment';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['siteid','pid', 'mid', 'uid', 'type', 'filesize', 'update_at', 'create_at'], 'required'],
|
||||
[['siteid','pid', 'mid', 'uid', 'type', 'filesize', 'status_code', 'update_at', 'create_at'], 'integer'],
|
||||
[['options'], 'string'],
|
||||
[['title', 'route'], 'string', 'max' => 255],
|
||||
[['deleted'], 'string', 'max' => 1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => Yii::t('app', 'ID'),
|
||||
'siteid' => Yii::t('app', '站点ID'),
|
||||
'pid' => Yii::t('app', '平台ID'),
|
||||
'mid' => Yii::t('app', '关联会员ID'),
|
||||
'uid' => Yii::t('app', '关联管理员ID'),
|
||||
'type' => Yii::t('app', '附件类型'),
|
||||
'title' => Yii::t('app', '附件标题'),
|
||||
'route' => Yii::t('app', '附件路径'),
|
||||
'filesize' => Yii::t('app', '附件大小(byte)'),
|
||||
'options' => Yii::t('app', '额外参数'),
|
||||
'status_code' => Yii::t('app', '状态代码'),
|
||||
'deleted' => Yii::t('app', '是否删除'),
|
||||
'update_at' => Yii::t('app', '数据更新时间'),
|
||||
'create_at' => Yii::t('app', '数据创建时间'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+76
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "log".
|
||||
*
|
||||
* @property string $username
|
||||
* @property string $ip
|
||||
* @property string $data
|
||||
* @property string $create_time
|
||||
*/
|
||||
class Log extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%c_log}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['username', 'create_time'], 'string', 'max' => 32],
|
||||
[['ip', 'data'], 'string', 'max' => 64],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => 'Username',
|
||||
'ip' => 'Ip',
|
||||
'data' => 'Data',
|
||||
'create_time' => 'Create Time',
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "logs".
|
||||
*
|
||||
* @property string $username
|
||||
* @property string $ip
|
||||
* @property string $data
|
||||
* @property string $create_time
|
||||
*/
|
||||
class Logs extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%c_logs}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['username', 'create_time'], 'string', 'max' => 32],
|
||||
[['ip', 'data'], 'string', 'max' => 64],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'username' => 'Username',
|
||||
'ip' => 'Ip',
|
||||
'data' => 'Data',
|
||||
'create_time' => 'Create Time',
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use backend\models\AuthAssignment;
|
||||
/**
|
||||
* This is the model class for table "c_user".
|
||||
*
|
||||
* @property integer $id
|
||||
* @property string $username
|
||||
* @property string $auth_key
|
||||
* @property string $password_hash
|
||||
* @property string $password_reset_token
|
||||
* @property string $email
|
||||
* @property integer $role
|
||||
* @property integer $status
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
*/
|
||||
class User extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%c_user}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['username','email'], 'required'],
|
||||
//[['role', 'status', 'created_at', 'updated_at'], 'integer'],
|
||||
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
|
||||
[['auth_key'], 'string', 'max' => 32],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'username' => Yii::t('common' ,'Username'),
|
||||
'auth_key' => Yii::t('common' ,'Password'),
|
||||
'password_hash' => 'Password Hash',
|
||||
'password_reset_token' => 'Password Reset Token',
|
||||
'email' => Yii::t('common' ,'Email'),
|
||||
'mobile' => Yii::t('common' ,'Mobile'),
|
||||
'role' => Yii::t('common' ,'Role'),
|
||||
'status' => 'Status',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
];
|
||||
}
|
||||
//获取所有用户
|
||||
public function get_all_user(){
|
||||
$user = Yii::$app->db->createCommand('select * from '. tableName())->queryAll();
|
||||
return $user;
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates password hash from password and sets it to the model
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates "remember me" authentication key
|
||||
*/
|
||||
public function generateAuthKey()
|
||||
{
|
||||
$this->auth_key = Yii::$app->security->generateRandomString();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+154
@@ -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'] =' |--'.$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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use backend\models\AuthAssignment;
|
||||
/**
|
||||
* This is the model class for table "c_user".
|
||||
*
|
||||
* @property integer $id
|
||||
* @property string $username
|
||||
* @property string $auth_key
|
||||
* @property string $password_hash
|
||||
* @property string $password_reset_token
|
||||
* @property string $email
|
||||
* @property integer $role
|
||||
* @property integer $status
|
||||
* @property integer $created_at
|
||||
* @property integer $updated_at
|
||||
*/
|
||||
class User extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%c_user}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['username','email'], 'required'],
|
||||
//[['role', 'status', 'created_at', 'updated_at'], 'integer'],
|
||||
[['username', 'password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
|
||||
[['auth_key'], 'string', 'max' => 32],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'username' => Yii::t('common' ,'Username'),
|
||||
'auth_key' => Yii::t('common' ,'Password'),
|
||||
'password_hash' => 'Password Hash',
|
||||
'password_reset_token' => 'Password Reset Token',
|
||||
'email' => Yii::t('common' ,'Email'),
|
||||
'mobile' => Yii::t('common' ,'Mobile'),
|
||||
'role' => Yii::t('common' ,'Role'),
|
||||
'status' => 'Status',
|
||||
'created_at' => 'Created At',
|
||||
'updated_at' => 'Updated At',
|
||||
];
|
||||
}
|
||||
//获取所有用户
|
||||
public function get_all_user(){
|
||||
$user = Yii::$app->db->createCommand('select * from '. tableName())->queryAll();
|
||||
return $user;
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates password hash from password and sets it to the model
|
||||
*
|
||||
* @param string $password
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates "remember me" authentication key
|
||||
*/
|
||||
public function generateAuthKey()
|
||||
{
|
||||
$this->auth_key = Yii::$app->security->generateRandomString();
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
*
|
||||
Executable
+220
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:33:23
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:34:36
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
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' => [5, 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;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:34:17
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:34:25
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:35:20
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:35:48
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-04-26 08:32:06
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:36:26
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:36:45
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:40:19
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:09+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmContract extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%contract}}';
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:18+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmCustomer extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%customer}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:26+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmEmployee extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%employee}}';
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function rules()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function attributeLabels()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:32+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmFeeOrder extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%fee_order}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:38+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmHotel extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%hotel}}';
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:43+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmOrder extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%order}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:48+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmOrderPre extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%order_pre}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:54+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmOrderStatus extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%order_status}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:27:59+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmPlat extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%plat}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:28:18+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmRoom extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%room}}';
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:28:23+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmRoomOwner extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%roomowner}}';
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:28:30+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmStat extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%stat}}';
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:28:35+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmStore extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%store}}';
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function rules()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function attributeLabels()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2018-11-22 02:22:45
|
||||
# @Last modified by: fm453
|
||||
# @Last modified time: 2021-09-15T15:28:41+08:00
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class FmUserExt extends \yii\db\ActiveRecord
|
||||
{
|
||||
//指定数据库
|
||||
public static function getDb()
|
||||
{
|
||||
return Yii::$app->get('lvju');
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%user_ext}}';
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function rules()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @inheritdoc
|
||||
// */
|
||||
// public function attributeLabels()
|
||||
// {
|
||||
// return [];
|
||||
// }
|
||||
}
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:37:16
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:40:11
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+133
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-09 22:59:04
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 19:55:54
|
||||
* @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 = true;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @Author: fm453
|
||||
* @Date: 2021-09-10 17:39:57
|
||||
* @Last Modified by: fm453
|
||||
* @Last Modified time: 2021-09-10 17:40:04
|
||||
* @Email: fm453@lukegzs.com
|
||||
*/
|
||||
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'] =' |--'.$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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user