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; } }