81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Controller\AbstractController;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
abstract class Base extends AbstractController
|
|
{
|
|
/**
|
|
* 账号ID
|
|
* @var int
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
public int $account_id = 0;
|
|
|
|
public array $account = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->account_id = $this->request->getAttribute("account_id");
|
|
$this->account = $this->request->getAttribute("account");
|
|
}
|
|
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array|string $msg
|
|
* @param array|null $data
|
|
* @param $count
|
|
* @param $summary
|
|
* @return ResponseInterface
|
|
*/
|
|
public function success(array|string $msg = "success", array|null $data = null, $count = null, $summary = null)
|
|
{
|
|
if (!is_string($msg)) {
|
|
$data = $msg;
|
|
$msg = "success";
|
|
}
|
|
return $this->response(0, $msg, $data, $count, $summary);
|
|
}
|
|
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
* @param array|string $msg
|
|
* @param array|null $data
|
|
* @param $count
|
|
* @param $summary
|
|
* @return ResponseInterface
|
|
*/
|
|
public function error(array|string $msg = "error", array|null $data = null, $count = null, $summary = null)
|
|
{
|
|
if (!is_string($msg)) {
|
|
$data = $msg;
|
|
$msg = "error";
|
|
}
|
|
return $this->response(1, $msg, $data, $count, $summary);
|
|
}
|
|
|
|
/**
|
|
* 响应
|
|
* @param int $code
|
|
* @param string $msg
|
|
* @param array|null $data
|
|
* @param int|null $count
|
|
* @param array|null $summary
|
|
* @return ResponseInterface
|
|
*/
|
|
protected function response(int $code, string $msg, array $data = null, int $count = null, array $summary = null): ResponseInterface
|
|
{
|
|
$body = compact("code", "msg", "data", "count", "summary");
|
|
if ($count === null) unset($body['count']);
|
|
if ($data === null) unset($body['data']);
|
|
if ($summary === null) unset($body['summary']);
|
|
return $this->response->json($body);
|
|
}
|
|
|
|
|
|
} |