改进
This commit is contained in:
parent
652d2060bc
commit
86316342f2
@ -22,31 +22,18 @@ public function __construct()
|
|||||||
|
|
||||||
public function get($url)
|
public function get($url)
|
||||||
{
|
{
|
||||||
|
$resp = $this->http->get($url)->json()['data'];
|
||||||
try {
|
return $resp;
|
||||||
$resp = $this->http->get($url)->json()['data'];
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return $this->error($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success($resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function announcements()
|
public function announcements()
|
||||||
{
|
{
|
||||||
|
|
||||||
$resp = $this->cache(function () {
|
$resp = $this->cache(function () {
|
||||||
return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-commentCount');
|
return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-commentCount');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isset($resp->original['data'])) {
|
return $this->resp($resp);
|
||||||
$resp = $resp->original['data'];
|
|
||||||
} else {
|
|
||||||
$resp = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success($resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,9 +42,15 @@ public function cache(Closure $callback)
|
|||||||
// 获取调用方法名
|
// 获取调用方法名
|
||||||
$method = debug_backtrace()[1]['function'];
|
$method = debug_backtrace()[1]['function'];
|
||||||
|
|
||||||
|
|
||||||
return Cache::remember('forum.func.' . $method . '.user_' . auth()->id(), 60, function () use ($callback) {
|
return Cache::remember('forum.func.' . $method . '.user_' . auth()->id(), 60, function () use ($callback) {
|
||||||
return $callback();
|
return $callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function resp($data) {
|
||||||
|
$data['base_url'] = $this->baseUrl;
|
||||||
|
|
||||||
|
return $this->success($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user