1010 *
1111 * @property string $group_name
1212 * @property string $group_id
13+ * @property string $group_status
1314 * @package wind\rest\models
1415 */
1516class AuthGroups extends \yii \db \ActiveRecord
@@ -19,7 +20,7 @@ class AuthGroups extends \yii\db\ActiveRecord
1920 const STATUS_CLOSE = '1 ' ;
2021 public $ id ;
2122
22- public function __construct ($ id , array $ config = [])
23+ public function __construct ($ id = null , array $ config = [])
2324 {
2425 parent ::__construct ($ config );
2526 $ this ->id = $ id ;
@@ -41,6 +42,7 @@ public function rules()
4142 return [
4243 [['group_id ' ], 'string ' , 'max ' => 50 ],
4344 [['group_name ' ], 'string ' , 'max ' => 100 ],
45+ [['group_status ' ], 'string ' , 'max ' => 50 ],
4446 ];
4547 }
4648
@@ -50,22 +52,26 @@ public function rules()
5052 public function attributeLabels ()
5153 {
5254 return [
53- 'group_id ' => 'GROUP ID ' ,
55+ 'group_id ' => '分组ID ' ,
5456 'group_name ' => '分组名称 ' ,
57+ 'group_status ' => '分组状态 ' ,
5558 ];
5659 }
5760
5861 /**
5962 * 可用列表
63+ * @param null $is_all 是否查询所有分组
6064 *
6165 * @return array|\yii\db\ActiveRecord[]
6266 */
63- public function lists ()
67+ public function lists ($ is_all = null )
6468 {
6569 $ model = clone $ this ;
6670 $ query = $ model ->find ();
6771 $ query ->select (['group_id ' , 'group_name ' ]);
68- $ query ->andWhere (['group_status ' => self ::STATUS_OPEN ]);
72+ if ( !$ is_all ) {
73+ $ query ->andWhere (['group_status ' => self ::STATUS_OPEN ]);
74+ }
6975 $ result = $ query ->asArray ()->all ();
7076
7177 return $ result ;
@@ -122,12 +128,17 @@ public function revoke()
122128 *
123129 * @return array
124130 */
125- public function assignUser ()
131+ public function assignUser ($ single_group = null )
126132 {
127133 $ group_child_model = new AuthGroupsChild ();
128134 //assign 已分配的
129135 $ assign = $ group_child_model ->assigned ($ this ->id );
130- $ user_id_arr = array_filter (array_column ($ assign , 'id ' ));
136+ if ($ single_group ) {
137+ $ assign_filter = $ group_child_model ->assignedAll ();
138+ } else {
139+ $ assign_filter = $ assign ;
140+ }
141+ $ user_id_arr = array_filter (array_column ($ assign_filter , 'id ' ));
131142 //all 所有
132143 $ user_model = new \wind \rest \models \searchs \User ();
133144 $ all = $ user_model ->allUsers (['id ' , 'realname ' ]);
@@ -141,5 +152,47 @@ public function assignUser()
141152 return compact (['all ' , 'assign ' ]);
142153 }
143154
155+ /**
156+ * 添加
157+ *
158+ * @param $group_id
159+ * @param $group_name
160+ *
161+ * @return bool
162+ */
163+ public function create ($ group_id , $ group_name )
164+ {
165+ $ model = $ this ::findOne (['group_id ' => $ group_id ]) ?: clone $ this ;
166+ $ model ->group_id = $ group_id ;
167+ $ model ->group_name = $ group_name ;
168+ if ( !$ model ->save ()) {
169+ \Yii::error ($ model ->errors );
170+
171+ return false ;
172+ }
173+
174+ return true ;
175+ }
144176
177+ /**
178+ * 停用|启用
179+ *
180+ * @param $group_id
181+ * @param $group_status
182+ *
183+ * @return bool
184+ */
185+ public function status ($ group_id , $ group_status )
186+ {
187+ $ model = $ this ::findOne (['group_id ' => $ group_id ]);
188+ $ model ->group_id = $ group_id ;
189+ $ model ->group_status = $ group_status ;
190+ if ( !$ model ->save ()) {
191+ \Yii::error ($ model ->errors );
192+
193+ return false ;
194+ }
195+
196+ return true ;
197+ }
145198}
0 commit comments