Files
dafuweng-saiadmin6.x/server/app/api/controller/BaseController.php
2026-03-10 11:42:39 +08:00

37 lines
963 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace app\api\controller;
use app\api\util\ApiLang;
use plugin\saiadmin\basic\OpenController;
use support\Response;
/**
* API 控制器基类:根据请求头 langen=英文zh=中文)对返回 message 做双语适配
*/
class BaseController extends OpenController
{
/**
* 成功返回message 按请求头 langen/zh翻译
*/
public function success(array|string $data = [], string $msg = 'success', int $option = JSON_UNESCAPED_UNICODE): Response
{
if (is_string($data)) {
$msg = $data;
$data = [];
}
$msg = ApiLang::translate((string) $msg);
return parent::success($data, $msg, $option);
}
/**
* 失败返回message 按 lang 翻译
*/
public function fail(string $msg = 'fail', int $code = 400): Response
{
$msg = ApiLang::translate($msg);
return parent::fail($msg, $code);
}
}