Lae/app/Http/Controllers/Api/ForumController.php
iVampireSP.com 4918efa597
优化导入,格式化代码
分离出充值系统

修复了充值的问题
2022-11-16 13:16:56 +08:00

67 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Closure;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use function config;
// use Exception;
// use Illuminate\Http\Request;
class ForumController extends Controller
{
private $http, $baseUrl;
public function __construct()
{
$this->baseUrl = config('forum.base_url');
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
}
public function announcements()
{
$resp = $this->cache(function () {
return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-createdAt');
});
return $this->resp($resp);
}
public function cache(Closure $callback)
{
// 获取调用方法名
$method = debug_backtrace()[1]['function'];
return Cache::remember('forum.func.' . $method, 60, function () use ($callback) {
return $callback();
});
}
public function get($url)
{
$resp = $this->http->get($url)->json()['data'];
return $resp;
}
public function resp($data)
{
$data['base_url'] = $this->baseUrl;
return $this->success($data);
}
public function pinned()
{
$resp = $this->cache(function () {
return $this->get('discussions?filter[tag]=pinned&page[offset]=0&sort=-createdAt');
});
return $this->resp($resp);
}
}