1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/3
- * Time: 下午5:30
- */
- namespace backend\server;
- use common\models\UserRn;
- use common\models\UserUr;
- use Yii;
- class RoleAuthority
- {
- public function CreateRole()
- {
- $input = Yii::$app->request->post();
- $model = new UserRn();
- $model->load($input,'');
- $model->nid = $input['nid'];
- if(!$model->validate()) return $model->errors;
- $model->deleteAll(['rid'=>$model->rid,'type'=>$model->type]);
- foreach ($model->nid as $val)
- {
- $_model = clone $model;
- $_model->rid = $model->rid;
- $_model->nid = $val;
- $_model->type = $model->type;
- $_model->create_at = $_SERVER['REQUEST_TIME'];
- $_model->insert();
- }
- return true;
- }
- public function CreateUserRole()
- {
- $model = new UserUr();
- $model->load(Yii::$app->request->post('data'),'');
- $model->rid = Yii::$app->request->post('data')['rid'];
- if(!$model->validate()) return $model->errors;
- $model->deleteAll(['uid'=>$model->uid]);
- foreach ($model->rid as $val)
- {
- $model->isNewRecord = true;
- $model->rid = $val;
- $model->create_at = $_SERVER['REQUEST_TIME'];
- $model->insert();
- }
- return true;
- }
- }
|