| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace common\models\rbac;
- use common\enums\StatusEnum;
- use common\models\user\UserLevel;
- use PHPUnit\Util\Exception;
- /**
- * This is the model class for table "{{%rbac_auth_item_child}}".
- *
- *
- * @property int $role_id 角色id
- * @property int $item_id 权限id
- * @property string $name 别名
- * @property string $app_id 类别
- * @property int $is_addon 是否插件
- * @property string $addons_name 插件名称
- */
- class AuthItemChild extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%rbac_auth_item_child}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['role_id', 'item_id', 'is_addon'], 'integer'],
- [['name'], 'string', 'max' => 64],
- [['app_id'], 'string', 'max' => 20],
- [['addons_name'], 'string', 'max' => 100],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'role_id' => '角色id',
- 'item_id' => '权限id',
- 'name' => '别名',
- 'app_id' => '类别',
- 'is_addon' => '是否插件',
- 'addons_name' => '插件名称',
- ];
- }
- public static function setData(array $params){
- try{
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }catch(Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @param array $cond
- * @param array $with
- * @param int $is_array
- * @param string $select
- * @return array|AuthItemChild[]|\yii\db\ActiveRecord[]
- */
- public static function getList(array $cond, array $with = [], int $is_array = 0, string $select = '*')
- {
- $query = self::find()->select($select);
- self::paramPack(['where' => $cond, 'with' => $with], $query);
- $i = 1;
- $page_size = 1000;
- $data = [];
- while ($list =$query->offset(($i - 1) * $page_size)->limit($page_size)->asArray($is_array)->all()) {
- $data = array_merge($data, $list);
- $i++;
- }
- return $data;
- }
- /**
- * @desc:更新应用配置,异步更新用户已选择的权限
- * @Author: hua
- * @Date: 2021/12/23
- * @Time: 9:16
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data // ['addons_name'=>'xxxx']
- */
- public static function updateAuthItemChildSync($data){
- $where = [
- ['is_addon'=>1],
- ['addons_name'=>$data['addons_name']],
- ['status'=>StatusEnum::ENABLED],
- ];
- $list = AuthItem::lists(['where'=>$where]);
- if($list){
- foreach ($list as $item){
- $attributes = [
- 'item_id'=>$item['id'],
- ];
- $condition = [
- 'name'=>$item['name'],
- 'app_id'=>$item['app_id'],
- 'is_addon'=>$item['is_addon'],
- 'addons_name'=>$item['addons_name'],
- ];
- AuthItemChild::updateAll($attributes,$condition);
- }
- }
- }
- /**
- * 获取全部选中的itemid
- *
- * @param array $condition
- * @return array
- */
- public static function getCheckedKey(array $condition)
- {
- return static::find()
- ->where($condition)
- ->select('item_id')
- ->column();
- }
- /**
- * 批量插入权限
- *
- * @param array $data
- * @return int
- */
- public static function batchInsertAuth(array $data)
- {
- return static::find()
- ->createCommand()
- ->batchInsert(static::tableName(), array_keys($data[0]), $data)->execute();
- }
- }
|