dootask/app/Http/Controllers/Api/AppsController.php
kuaifan 420d46d5cc feat(apps): 新增应用菜单角标(数字/红点,per-user 实时推送)
插件/微应用可在自己的菜单入口显示数字或红点角标,插件未打开也生效。

- 后端:新增 app_badges 表 + AppBadge 模型 + Module/Badge 业务编排 +
  AppsController(badge__set 应用密钥鉴权 / badge__clear 用户鉴权)
- 每应用独立密钥 APP_SECRET:按 appid 持久化于 appstore config.yml,鉴权校验
- 推送:复用 PushTask 下发 appBadge WS 消息;microapp_menu 附带初始角标
- 前端:appBadges Vuex module + WS 处理 + 三处菜单渲染(应用卡片/主菜单入口/
  父『应用』入口聚合)+ 移动端 Tabbar + 打开即清(badge_clear_on_open)
- 用户离职级联清理;同步 ai-kb 角标知识
2026-06-29 02:32:19 +00:00

75 lines
2.6 KiB
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
namespace App\Http\Controllers\Api;
use App\Models\User;
use App\Module\Badge;
use App\Module\Base;
use Request;
/**
* 插件 / 微应用相关接口。
*
* 动态路由routes/web.php
* api/apps/badge/set -> badge__set() 应用密钥鉴权,绝对设置/清除角标
* api/apps/badge/clear -> badge__clear() 当前用户 token 鉴权,清除自己的角标
*/
class AppsController extends AbstractController
{
/**
* @api {post} api/apps/badge/set 设置角标(应用密钥鉴权)
*
* @apiDescription 由插件服务端使用 APP_SECRET 调用,对 (appid, 菜单, 每个 userid) 绝对设置角标(幂等覆盖)。
* @apiVersion 1.0.0
* @apiGroup apps
* @apiName badge__set
*
* @apiParam {String} appid 应用ID
* @apiParam {String} secret 应用密钥APP_SECRET
* @apiParam {Number|Number[]} userid 目标用户ID单个或数组
* @apiParam {String} [menu_key] 菜单稳定标识;留空表示该应用第一个菜单
* @apiParam {Number} [count=0] 角标数字
* @apiParam {Boolean} [dot=false] 是否显示红点count=0 且 dot=false 即清除)
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息
* @apiSuccess {Object} data 返回数据
*/
public function badge__set()
{
return Base::retSuccess('success', Badge::set(
trim(Request::input('appid', '')),
trim(Request::input('secret', '')),
Request::input('userid'),
trim(Request::input('menu_key', '')),
Request::input('count', 0),
Request::input('dot', false)
));
}
/**
* @api {post} api/apps/badge/clear 清除角标(当前用户 token 鉴权)
*
* @apiDescription 供前端在 badge_clear_on_open=true 的菜单打开时调用,清除当前用户在该应用该菜单的角标。
* @apiVersion 1.0.0
* @apiGroup apps
* @apiName badge__clear
*
* @apiParam {String} appid 应用ID
* @apiParam {String} [menu_key] 菜单稳定标识;留空表示该应用第一个菜单
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息
* @apiSuccess {Object} data 返回数据
*/
public function badge__clear()
{
$user = User::auth();
return Base::retSuccess('success', Badge::clearForUser(
(int)$user->userid,
trim(Request::input('appid', '')),
trim(Request::input('menu_key', ''))
));
}
}