Skip to content

6.8 公告与链接管理 ​

概述

本节涵盖通知公告和友情链接两个模块,均继承 BaseTenantLogic 实现租户隔离。

说明: 本文件因历史原因命名为 content.md,实际文档内容为通知公告(Notice)和友情链接(Link)两个独立模块,并不存在 "Content" 模块。

通知公告 ​

模块特点 ​

特性说明
基类BaseTenantLogic(租户隔离)
文件字段cover(封面图),保存到 notice 目录
富文本字段content(公告内容)
枚举映射type → notice_type(1=通知 2=公告),status → notice_status
排序按 id 倒序(最新在前)

核心代码 ​

php
// app/logic/NoticeLogic.php

class NoticeLogic extends BaseTenantLogic
{
    /**
     * 关联的模型类
     *
     * @var string
     */
    protected string $modelClass = Notice::class;

    /**
     * 需要自动处理的文件上传字段
     *
     * @var array
     */
    protected array $fileFields = ['cover'];

    /**
     * 文件保存的子目录
     *
     * @var string
     */
    protected string $fileSaveDir = 'notice';

    /**
     * LIKE 模糊匹配字段
     *
     * @var array
     */
    protected array $pageLikeFields = ['title'];

    /**
     * 精确匹配字段
     *
     * @var array
     */
    protected array $pageEqFields = ['type', 'status'];

    /**
     * 默认排序规则
     *
     * @var array
     */
    protected array $pageOrderBy = [
        ['field' => 'tenant_id', 'type' => 'asc'],
        ['field' => 'id', 'type' => 'desc'],
    ];

    /**
     * 枚举显示名映射
     *
     * @var array
     */
    protected array $serializeMaps = [
        'type'   => 'notice_type',
        'status' => 'notice_status',
    ];

    /**
     * 富文本字段
     *
     * @var array
     */
    protected array $contentFields = ['content'];
}

API 接口 ​

方法路径权限码说明
GET/api/notice/pagesys:notice:page分页列表
GET/api/notice/list-全量列表
GET/api/notice/detail/:idsys:notice:detail详情
POST/api/notice/addsys:notice:add新增
PUT/api/notice/updatesys:notice:update修改
DELETE/api/notice/delete/:idsys:notice:delete删除
DELETE/api/notice/batchDeletesys:notice:batchDelete批量删除

友情链接 ​

模块特点 ​

特性说明
基类BaseTenantLogic(租户隔离)
文件字段image(友链Logo),保存到 link 目录
枚举映射type → link_type,form → link_form,status → link_status

核心代码 ​

php
// app/logic/LinkLogic.php

class LinkLogic extends BaseTenantLogic
{
    /**
     * 关联的模型类
     *
     * @var string
     */
    protected string $modelClass = Link::class;

    /**
     * 需要自动处理的文件上传字段
     *
     * @var array
     */
    protected array $fileFields = ['image'];

    /**
     * 文件保存的子目录
     *
     * @var string
     */
    protected string $fileSaveDir = 'link';

    /**
     * LIKE 模糊匹配字段
     *
     * @var array
     */
    protected array $pageLikeFields = ['name'];

    /**
     * 精确匹配字段
     *
     * @var array
     */
    protected array $pageEqFields = ['type', 'status'];

    /**
     * 默认排序规则
     *
     * @var array
     */
    protected array $pageOrderBy = [
        ['field' => 'tenant_id', 'type' => 'asc'],
        ['field' => 'sort', 'type' => 'asc'],
    ];

    /**
     * 枚举显示名映射
     *
     * @var array
     */
    protected array $serializeMaps = [
        'type'   => 'link_type',
        'form'   => 'link_form',
        'status' => 'link_status',
    ];
}

API 接口 ​

方法路径权限码说明
GET/api/link/pagesys🔗page分页列表
GET/api/link/detail/:idsys🔗detail详情
POST/api/link/addsys🔗add新增
PUT/api/link/updatesys🔗update修改
DELETE/api/link/delete/:idsys🔗delete删除
DELETE/api/link/batchDeletesys🔗batchDelete批量删除

小蚂蚁云团队 · 提供技术支持