From 75d63602ad1ac26ef775514de5eb4ea280db2f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Wed, 28 Oct 2026 16:19:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B1=95=E7=A4=BA=E8=B4=9F=E6=95=B0?= =?UTF-8?q?=E9=A2=84=E8=AD=A6=E6=9C=80=E6=96=B0=E8=B4=A6=E6=9C=9F=E5=90=88?= =?UTF-8?q?=E8=AE=A1=20(#741)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在采购钉钉任务页展示最新账期供应商负数合计。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com> --- .../SupplierNegativeAlertDingTalkForms.php | 4 +- .../SupplierNegativeAlertDingTalkWorkflow.php | 48 +++++++++++++++++++ .../negative-alerts/dingtalk-task.blade.php | 41 ++++++++++++++++ .../SupplierNegativeAlertDingTalkTest.php | 35 ++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Business/SupplierNegativeAlertDingTalkForms.php b/app/Http/Controllers/Business/SupplierNegativeAlertDingTalkForms.php index d2f57ecc..264a4b60 100644 --- a/app/Http/Controllers/Business/SupplierNegativeAlertDingTalkForms.php +++ b/app/Http/Controllers/Business/SupplierNegativeAlertDingTalkForms.php @@ -26,10 +26,12 @@ class SupplierNegativeAlertDingTalkForms extends Controller } $snapshot = json_decode((string) $assignment->snapshot, true); + $snapshot = is_array($snapshot) ? array_values($snapshot) : []; return view('business.pages.negative-alerts.dingtalk-task', [ 'assignment' => $assignment, - 'suppliers' => is_array($snapshot) ? array_values($snapshot) : [], + 'suppliers' => $snapshot, + 'latestPeriod' => $this->workflow->latestPeriodSummary($snapshot), 'supplierResults' => $this->workflow->resultsForAssignment((int) $assignment->id), 'token' => $token, ]); diff --git a/modules/EcommerceFinance/Services/SupplierNegativeAlertDingTalkWorkflow.php b/modules/EcommerceFinance/Services/SupplierNegativeAlertDingTalkWorkflow.php index b90771f5..702b07ff 100644 --- a/modules/EcommerceFinance/Services/SupplierNegativeAlertDingTalkWorkflow.php +++ b/modules/EcommerceFinance/Services/SupplierNegativeAlertDingTalkWorkflow.php @@ -439,6 +439,54 @@ class SupplierNegativeAlertDingTalkWorkflow return $latest; } + /** + * 任务页展示:按任务快照中的最新账期汇总该采购的负数金额。 + * + * @param list> $snapshot + * @return array{month:string,negative_amount:float,supplier_count:int,row_count:int} + */ + public function latestPeriodSummary(array $snapshot): array + { + $latestMonth = ''; + foreach ($snapshot as $supplier) { + foreach ((array) ($supplier['rows'] ?? []) as $row) { + $month = trim((string) ($row['summary_month'] ?? '')); + if (preg_match('/^\d{4}-\d{2}$/', $month) === 1 && $month > $latestMonth) { + $latestMonth = $month; + } + } + } + + $negativeAmount = 0.0; + $supplierNames = []; + $rowCount = 0; + foreach ($snapshot as $supplier) { + $supplierName = trim((string) ($supplier['supplier'] ?? '')); + foreach ((array) ($supplier['rows'] ?? []) as $row) { + $month = trim((string) ($row['summary_month'] ?? '')); + if ($latestMonth !== '' && $month !== $latestMonth) { + continue; + } + $amount = (float) ($row['alert_amount'] ?? 0); + if ($amount >= 0) { + continue; + } + $negativeAmount += $amount; + $rowCount++; + if ($supplierName !== '') { + $supplierNames[$supplierName] = true; + } + } + } + + return [ + 'month' => $latestMonth, + 'negative_amount' => round($negativeAmount, 2), + 'supplier_count' => count($supplierNames), + 'row_count' => $rowCount, + ]; + } + /** @return array */ public function resultsForAssignment(int $assignmentId): array { diff --git a/resources/views/business/pages/negative-alerts/dingtalk-task.blade.php b/resources/views/business/pages/negative-alerts/dingtalk-task.blade.php index e636dc9a..da57e3d4 100644 --- a/resources/views/business/pages/negative-alerts/dingtalk-task.blade.php +++ b/resources/views/business/pages/negative-alerts/dingtalk-task.blade.php @@ -2,6 +2,7 @@ $assignment = $assignment ?? null; $suppliers = $suppliers ?? []; $supplierResults = $supplierResults ?? []; + $latestPeriod = $latestPeriod ?? ['month' => '', 'negative_amount' => 0, 'supplier_count' => 0, 'row_count' => 0]; $completed = ($assignment->status ?? '') === 'completed'; $filledCount = collect($suppliers)->filter( static fn (array $supplier): bool => filled($supplierResults[$supplier['supplier'] ?? ''] ?? null) @@ -66,6 +67,32 @@ background: #FDF1F1; color: #7A1010; } + .period-summary { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + justify-content: space-between; + gap: 10px 20px; + margin-bottom: 12px; + padding: 16px; + border: 1px solid #D7C39D; + border-radius: 12px; + background: #FFFDF8; + } + .period-summary__amount { display: grid; gap: 3px; } + .period-summary__amount span { color: var(--muted); font-size: 12px; } + .period-summary__amount strong { + color: var(--danger); + font-size: 24px; + line-height: 1.25; + font-variant-numeric: tabular-nums; + } + .period-summary__meta { + max-width: 260px; + color: var(--muted); + font-size: 12px; + line-height: 1.6; + } .summary { display: grid; grid-template-columns: repeat(3, 1fr); @@ -194,6 +221,20 @@ @endif +
+
+ + 最新账期负数合计 · + {{ ($latestPeriod['month'] ?? '') !== '' ? $latestPeriod['month'] : '未标注月份' }} + + ¥{{ number_format((float) ($latestPeriod['negative_amount'] ?? 0), 2) }} +
+
+ 该账期涉及 {{ number_format((int) ($latestPeriod['supplier_count'] ?? 0)) }} 家供应商、 + {{ number_format((int) ($latestPeriod['row_count'] ?? 0)) }} 条负数预警 +
+
+
供应商 diff --git a/tests/Feature/Business/SupplierNegativeAlertDingTalkTest.php b/tests/Feature/Business/SupplierNegativeAlertDingTalkTest.php index 6734e0cb..4cb331da 100644 --- a/tests/Feature/Business/SupplierNegativeAlertDingTalkTest.php +++ b/tests/Feature/Business/SupplierNegativeAlertDingTalkTest.php @@ -109,6 +109,11 @@ class SupplierNegativeAlertDingTalkTest extends FeatureTestCase ->assertSeeText('供应商负数预警处理') ->assertSeeText('三洋木业') ->assertSeeText('久柯家具') + ->assertSeeText('最新账期负数合计') + ->assertSeeText('2026-09') + ->assertSeeText('¥-230.00') + ->assertSeeText('该账期涉及') + ->assertSeeText('3 条负数预警') ->assertSee('placeholder="请填写该供应商的核对、沟通或处理结果"', false) ->assertSeeText('处理结果'); $this->assertSame(2, substr_count((string) $response->getContent(), 'name="results[]"')); @@ -168,6 +173,36 @@ class SupplierNegativeAlertDingTalkTest extends FeatureTestCase ->assertSeeText('任务链接无效或已过期'); } + public function test_latest_period_summary_only_uses_the_newest_accounting_month(): void + { + $summary = app(SupplierNegativeAlertDingTalkWorkflow::class)->latestPeriodSummary([ + [ + 'supplier' => '供应商甲', + 'rows' => [ + ['summary_month' => '2026-08', 'alert_amount' => -100], + ['summary_month' => '2026-09', 'alert_amount' => -50], + ], + ], + [ + 'supplier' => '供应商乙', + 'rows' => [ + ['summary_month' => '2026-09', 'alert_amount' => -30], + ], + ], + [ + 'supplier' => '供应商丙', + 'rows' => [ + ['summary_month' => '2026-08', 'alert_amount' => -200], + ], + ], + ]); + + $this->assertSame('2026-09', $summary['month']); + $this->assertSame(-80.0, $summary['negative_amount']); + $this->assertSame(2, $summary['supplier_count']); + $this->assertSame(2, $summary['row_count']); + } + public function test_one_click_sends_all_purchasers_in_one_group_message(): void { $this->seedBulkRows();