v4.0.18版本提交

This commit is contained in:
2026-09-08 10:07:34 +08:00
parent 4bdb09068c
commit 23ba639e9b
46 changed files with 1922 additions and 162 deletions
@@ -30,6 +30,11 @@ import {
renderWecomTemplate,
} from './wecom-push-template.defaults';
/** 含 markdown 表格时改走 markdown_v2,群聊才能渲染表格 */
function wecomMarkdownUsesTable(content: string): boolean {
return /\|[^\n]*\|\s*\n\s*\|?\s*:?-{3,}/.test(content);
}
type PushRow = {
id: bigint;
name: string;
@@ -327,14 +332,16 @@ export class WecomMessagePushService implements OnModuleInit {
async sendMarkdownToWebhook(webhookUrl: string, content: string): Promise<boolean> {
const url = (webhookUrl || '').trim();
if (!url) return false;
const useTable = wecomMarkdownUsesTable(content);
const text = content.slice(0, useTable ? 4096 : 4000);
const payload = useTable
? { msgtype: 'markdown_v2', markdown_v2: { content: text } }
: { msgtype: 'markdown', markdown: { content: text } };
try {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
msgtype: 'markdown',
markdown: { content: content.slice(0, 4000) },
}),
body: JSON.stringify(payload),
});
const data = (await res.json().catch(() => ({}))) as {
errcode?: number;
@@ -580,20 +587,23 @@ export class WecomMessagePushService implements OnModuleInit {
},
'finance.partner_bill': {
vars: {
period: '2026-07',
period: '2026-07-27 ~ 2026-08-02',
billCount: '1',
totalAmount: '120.00',
billSummary: [
'城市:郑州',
'合伙人:郑州某某商贸-张三',
'订单笔数:8',
'核销笔数:12',
'订单佣金:¥100.00',
'核销佣金:¥20.00',
'账单:¥120.00',
'收款人:张三',
'收款账户:6222000011112222',
'收款开户行:郑州支行',
'| 郑州某某商贸-张三 | |',
'| :--- | ---: |',
'| 账期 | 2026-07-27 ~ 2026-08-02 |',
'| 订单数量 | 8 |',
'| 订单金额 | ¥1000.00 |',
'| 订单佣金 | ¥100.00 |',
'| 核销单数量 | 12 |',
'| 核销金额 | ¥200.00 |',
'| 核销佣金 | ¥20.00 |',
'| 累计金额 | ¥120.00 |',
'| 收款人 | 张三 |',
'| 收款银行账号 | 6222000011112222 |',
'| 开户行 | 郑州支行 |',
].join('\n'),
},
handlePath: '/finance/partner-bills',
@@ -9,7 +9,8 @@ import {
toWecomPluginMetricsView,
toWecomPluginUserView,
wecomPluginMetricsPeriod,
type WecomReportStats,
wecomReportCountedOrderWhere,
type WecomReportStats,
} from '@dukang/domain';
import {
WECOM_PLUGIN_TOOL_PATHS,
@@ -428,10 +429,11 @@ export class WecomPluginQueryService {
);
}
/** 日报口径:用户=有效未合并;订单金额=已付 payAmount;核销=RedeemRecord。today 期末为当前时刻。 */
/** 日报口径:用户=有效未合并;订单排除待支付/已取消/退款中;金额=已付 payAmount;核销=RedeemRecord。today 期末为当前时刻。 */
private async loadStats(start: Date, cutoff: Date): Promise<WecomReportStats> {
const userBase = { status: 1, mergedIntoUserId: null } as const;
const partnerBase = { isPrimary: 1 } as const;
const countedOrder = wecomReportCountedOrderWhere();
const paid = { payStatus: 'PAID' as const };
const [
@@ -462,15 +464,15 @@ export class WecomPluginQueryService {
}),
this.prisma.store.count({ where: { createdAt: { lt: cutoff } } }),
this.prisma.store.count({ where: { createdAt: { gte: start, lt: cutoff } } }),
this.prisma.order.count({ where: { createdAt: { lt: cutoff } } }),
this.prisma.order.count({ where: { createdAt: { gte: start, lt: cutoff } } }),
this.prisma.order.count({ where: { ...countedOrder, createdAt: { lt: cutoff } } }),
this.prisma.order.count({ where: { ...countedOrder, createdAt: { gte: start, lt: cutoff } } }),
this.prisma.order.aggregate({
_sum: { payAmount: true },
where: { ...paid, paidAt: { lt: cutoff } },
where: { ...countedOrder, ...paid, paidAt: { lt: cutoff } },
}),
this.prisma.order.aggregate({
_sum: { payAmount: true },
where: { ...paid, paidAt: { gte: start, lt: cutoff } },
where: { ...countedOrder, ...paid, paidAt: { gte: start, lt: cutoff } },
}),
this.prisma.redeemRecord.count({ where: { createdAt: { lt: cutoff } } }),
this.prisma.redeemRecord.count({ where: { createdAt: { gte: start, lt: cutoff } } }),
@@ -305,7 +305,7 @@ export const WECOM_PLUGIN_OPENAPI = {
get: {
summary: '经营指标',
description:
'today=今日截至当前;daily/weekly/monthly 与企微经营报告同一口径。stats 含 users/partners/stores/orders 存量与增量;storesIncrement 与 newStores 均为新增门店数。',
'today=今日截至当前;daily/weekly/monthly 与企微经营报告同一口径。订单排除待支付/已取消/退款中。stats 含 users/partners/stores/orders 存量与增量;storesIncrement 与 newStores 均为新增门店数。',
operationId: '查询经营指标',
parameters: [
{
@@ -150,13 +150,9 @@ export const WECOM_PUSH_TEMPLATE_DEFAULTS: WecomTemplateDefault[] = [
},
{
eventKey: 'finance.partner_bill',
title: '合伙人账单已生成',
title: '合伙人账单',
body: [
'**合伙人账单已生成**',
'账期:{{period}}',
'账单笔数:{{billCount}}',
'累计金额:¥{{totalAmount}}',
'时间:{{time}}',
'**合伙人账单**',
'',
'{{billSummary}}',
'',
@@ -315,6 +311,17 @@ export const WECOM_PUSH_TEMPLATE_LEGACY_BODIES: Partial<Record<WecomTemplateEven
'时间:{{time}}',
'[{{handleLabel}}]({{handleUrl}})',
].join('\n'),
[
'**合伙人月账单已生成**',
'账期:{{period}}',
'账单笔数:{{billCount}}',
'累计金额:¥{{totalAmount}}',
'时间:{{time}}',
'',
'{{billSummary}}',
'',
'[{{handleLabel}}]({{handleUrl}})',
].join('\n'),
],
'finance.winery_bill': [
[