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(); } }