1.新增显示分红说明文档菜单

2.文档新增英文版
This commit is contained in:
2026-05-29 11:18:10 +08:00
parent f3677eb0e3
commit 9be9e2666b
13 changed files with 1669 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\admin\controller\docs;
use app\common\controller\Backend;
use app\common\library\docs\MarkdownDocReader;
use support\Response;
use Webman\Http\Request;
@@ -13,7 +14,17 @@ use Webman\Http\Request;
*/
class Doc36ZiHuaMobileApi extends Backend
{
private const DOC_RELATIVE = 'docs' . DIRECTORY_SEPARATOR . '36字花-移动端接口设计草案.md';
private const DOC_ZH = [
'relative' => 'docs' . DIRECTORY_SEPARATOR . '36字花-移动端接口设计草案.md',
'filename' => '36字花-移动端接口设计草案.md',
'ascii_fallback' => '36zihua-mobile-api-design-draft.md',
];
private const DOC_EN = [
'relative' => 'docs' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . '36zihua-mobile-api-design-draft.md',
'filename' => '36zihua-mobile-api-design-draft.md',
'ascii_fallback' => '36zihua-mobile-api-design-draft.md',
];
public function content(Request $request): Response
{
@@ -22,19 +33,20 @@ class Doc36ZiHuaMobileApi extends Backend
return $response;
}
$path = $this->docAbsolutePath();
if (!is_file($path)) {
$doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN);
if (!is_file($doc['path'])) {
return $this->error(__('Document file not found'));
}
$raw = file_get_contents($path);
$raw = file_get_contents($doc['path']);
if ($raw === false) {
return $this->error(__('Failed to read document'));
}
return $this->success('', [
'markdown' => $raw,
'filename' => '36字花-移动端接口设计草案.md',
'filename' => $doc['filename'],
'lang' => $doc['lang'],
]);
}
@@ -45,22 +57,20 @@ class Doc36ZiHuaMobileApi extends Backend
return $response;
}
$path = $this->docAbsolutePath();
if (!is_file($path)) {
$doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN);
if (!is_file($doc['path'])) {
return $this->error(__('Document file not found'));
}
$body = file_get_contents($path);
$body = file_get_contents($doc['path']);
if ($body === false) {
return $this->error(__('Failed to read document'));
}
$utf8Name = '36字花-移动端接口设计草案.md';
$asciiFallback = '36zihua-mobile-api-design-draft.md';
$disposition = sprintf(
'attachment; filename="%s"; filename*=UTF-8\'\'%s',
$asciiFallback,
rawurlencode($utf8Name)
$doc['ascii_fallback'],
rawurlencode($doc['filename'])
);
return new Response(200, [
@@ -69,9 +79,4 @@ class Doc36ZiHuaMobileApi extends Backend
'Cache-Control' => 'private, max-age=0, must-revalidate',
], $body);
}
private function docAbsolutePath(): string
{
return rtrim(base_path(), DIRECTORY_SEPARATOR . '/') . DIRECTORY_SEPARATOR . self::DOC_RELATIVE;
}
}

View File

@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace app\admin\controller\docs;
use app\common\controller\Backend;
use app\common\library\docs\MarkdownDocReader;
use support\Response;
use Webman\Http\Request;
/**
* 后台只读展示《分红说明文档》Markdown并提供下载。
*/
class DocCommissionShare extends Backend
{
private const DOC_ZH = [
'relative' => 'docs' . DIRECTORY_SEPARATOR . '分红说明文档.md',
'filename' => '分红说明文档.md',
'ascii_fallback' => 'commission-share-guide.md',
];
private const DOC_EN = [
'relative' => 'docs' . DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR . 'commission-share-guide.md',
'filename' => 'commission-share-guide.md',
'ascii_fallback' => 'commission-share-guide.md',
];
public function content(Request $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
$doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN);
if (!is_file($doc['path'])) {
return $this->error(__('Document file not found'));
}
$raw = file_get_contents($doc['path']);
if ($raw === false) {
return $this->error(__('Failed to read document'));
}
return $this->success('', [
'markdown' => $raw,
'filename' => $doc['filename'],
'lang' => $doc['lang'],
]);
}
public function download(Request $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
$doc = MarkdownDocReader::resolve($request, self::DOC_ZH, self::DOC_EN);
if (!is_file($doc['path'])) {
return $this->error(__('Document file not found'));
}
$body = file_get_contents($doc['path']);
if ($body === false) {
return $this->error(__('Failed to read document'));
}
$disposition = sprintf(
'attachment; filename="%s"; filename*=UTF-8\'\'%s',
$doc['ascii_fallback'],
rawurlencode($doc['filename'])
);
return new Response(200, [
'Content-Type' => 'text/markdown; charset=UTF-8',
'Content-Disposition' => $disposition,
'Cache-Control' => 'private, max-age=0, must-revalidate',
], $body);
}
}