| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php namespace App\Models\Manager;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- /**
- * 用户权限组模型
- *
- */
- class AuthGroupAccess extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'auth_group_access';
- // 是否主动维护时间戳
- public $timestamps = false;
- protected $connection = 'mysql';
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- public static $allowShowPhone = null;
- /**
- * 添加数据
- *
- */
- public function add($data)
- {
- // 时间
- $data['insert_time'] = time();
- $data['update_time'] = time();
- // 写入数据表
- $id = $this->query()->insertGetId($data);
- // 如果操作失败
- if( !$id ) return 0;
- // 返回结果
- return $id;
- }
- /**
- * 添加数据
- *
- */
- public function edit($id,$data)
- {
- // 更新时间
- $data['update_time'] = time();
- // 写入数据表
- $result = $this->query()->where([['id','=',$id]])->update($data);
- // 如果操作失败
- if( !$result ) return 0;
- // 返回结果
- return $id;
- }
- /**
- * 获得权限列表
- * @param integer $uid 用户id
- *
- */
- public function getGroupByUid($uid)
- {
- // 获取分组名
- $group = $this->query()
- ->join('auth_group','auth_group_access.group_id','=','auth_group.id')
- ->where([['auth_group_access.admin_uid','=',$uid]])
- ->pluck('auth_group.name')->toArray();
- // 返回结果
- if ( is_super($uid,'manager') ) $group[] = '超管';
- // 返回结果
- return $group;
- }
- /**
- * 获得权限列表
- * @param integer $uid 用户id
- *
- */
- public function showPhoneByUid($uid)
- {
- // 如果有结果,返回结果过
- if( !is_null(self::$allowShowPhone) ) return self::$allowShowPhone;
- // 超管默认显示
- if ( is_super($uid,'manager') ) return self::$allowShowPhone = 1;
- // 非超管,查看用户是否有小组可以显示
- self::$allowShowPhone = (int) $this->query()->join('auth_group','auth_group_access.group_id','=','auth_group.id')->where([['auth_group_access.admin_uid','=',$uid],['auth_group.show_phone','=',1]])->value('auth_group.show_phone');
- // 返回结果
- return self::$allowShowPhone;
- }
- }
|