RoleAuthority.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/3
  6. * Time: 下午5:30
  7. */
  8. namespace backend\server;
  9. use common\models\UserRn;
  10. use common\models\UserUr;
  11. use Yii;
  12. class RoleAuthority
  13. {
  14. public function CreateRole()
  15. {
  16. $input = Yii::$app->request->post();
  17. $model = new UserRn();
  18. $model->load($input,'');
  19. $model->nid = $input['nid'];
  20. if(!$model->validate()) return $model->errors;
  21. $model->deleteAll(['rid'=>$model->rid,'type'=>$model->type]);
  22. foreach ($model->nid as $val)
  23. {
  24. $_model = clone $model;
  25. $_model->rid = $model->rid;
  26. $_model->nid = $val;
  27. $_model->type = $model->type;
  28. $_model->create_at = $_SERVER['REQUEST_TIME'];
  29. $_model->insert();
  30. }
  31. return true;
  32. }
  33. public function CreateUserRole()
  34. {
  35. $model = new UserUr();
  36. $model->load(Yii::$app->request->post('data'),'');
  37. $model->rid = Yii::$app->request->post('data')['rid'];
  38. if(!$model->validate()) return $model->errors;
  39. $model->deleteAll(['uid'=>$model->uid]);
  40. foreach ($model->rid as $val)
  41. {
  42. $model->isNewRecord = true;
  43. $model->rid = $val;
  44. $model->create_at = $_SERVER['REQUEST_TIME'];
  45. $model->insert();
  46. }
  47. return true;
  48. }
  49. }