1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\model;
- use think\facade\Cache;
- use think\Model;
- class GrantedAuth extends Model
- {
- // 权限组
- protected $json = ['auth'];
- /**
- * 权限来源
- */
- public function from()
- {
- return $this->belongsTo(Org::class, 'from', 'id');
- }
- /**
- * 权限授予
- */
- public function to()
- {
- return $this->belongsTo(Org::class, 'to', 'id');
- }
- /**
- * 授权权限获取
- */
- public function getIdsByAuth($auth, $to)
- {
- // 从缓存中获取授权企业id
- $key = $auth.'-'.$to;
- $data = Cache::get($key);
- if($data !== null){
- $data = json_decode($data);
- }
- // 如果缓存没有则进行查询
- $condition = [
- // ['auth->'.$auth, '=', true],
- ['to', '=', $to]
- ];
- $data = self::where($condition)->column('from');
- // 将查询结果放入到缓存中,并添加标签
- Cache::tag('auth_to_'.$to)->set($auth.'-'.$to, json_encode($data), 3600);
- return $data;
- }
- }
|