123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare (strict_types = 1);
- namespace app\model\system;
- use library\traits\JwtAuthModelTrait;
- use library\traits\ModelTrait;
- use think\Model;
- /**
- * @mixin \think\Model
- */
- class SystemRole extends Model
- {
- use ModelTrait;
- use JwtAuthModelTrait;
- private $roleData;
- /**
- * 获取角色数据
- * @param $id
- * @param string $field
- * @return mixed
- */
- public function getRoleId($id,$field = '*') {
- $this->getRoleData();
- foreach ($this->roleData as $v) {
- if($v['id'] == $id) {
- return $field == '*' ? $v : $v[$field];
- }
- }
- }
- /**
- * @param $post
- */
- public function saveRole($post) {
- $save['name'] = $post['name'];
- $save['status'] = $post['status'];
- if($post['id']) {
- $info = $this->where("name",$post['name'])->find();
- if(!empty($info) && $info['id'] != $post['id'] ) {
- return self::setErrorInfo('角色名重复了');
- }
- $this->where('id',$post['id'])->save($save);
- return true;
- } else {
- $this->insert([
- 'name' => $post['name'],
- 'status' => $post['status']
- ]);
- }
- return true;
- }
- public function getRoleData(){
- if(empty($this->roleData))
- $this->roleData = $this->where('status',1)->select();
- return $this->roleData;
- }
- }
|