feat: 厂家确认后退货群发送回执 (#859)
This commit is contained in:
parent
3538ed40b4
commit
973433a4b7
@ -15,6 +15,7 @@ use Modules\EcommerceFinance\View\SupplierReconciliationPageData;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 钉钉群推送的厂家退货明细临时页面,不需要厂家账号登录。
|
||||
@ -116,6 +117,22 @@ class SupplierReturnShare extends Controller
|
||||
if ($disputed > 0) {
|
||||
$message .= "({$disputed} 行异议保持原状态,暂不扣减)";
|
||||
}
|
||||
if ($confirmed > 0) {
|
||||
try {
|
||||
$receiptSent = $this->notifier->sendReturnConfirmationReceipt(
|
||||
$target['supplier'],
|
||||
$target['month'],
|
||||
$confirmed,
|
||||
$disputed,
|
||||
);
|
||||
$message .= $receiptSent
|
||||
? ';确认回执已发送到该厂家钉钉群'
|
||||
: ';厂家未配置钉钉机器人,确认回执未发送';
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
$message .= ';确认回执发送失败,请联系财务';
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->to($pageUrl)->with('success', $message . '。');
|
||||
}
|
||||
|
||||
@ -190,6 +190,41 @@ class SupplierDingTalkNotifier
|
||||
return ['messages' => 1, 'rows' => count($returns)];
|
||||
}
|
||||
|
||||
public function sendReturnConfirmationReceipt(
|
||||
string $supplier,
|
||||
string $month,
|
||||
int $confirmedRows,
|
||||
int $disputedRows,
|
||||
): bool {
|
||||
$configs = $this->configs();
|
||||
$config = is_array($configs[$supplier] ?? null) ? $configs[$supplier] : [];
|
||||
$webhook = trim((string) ($config['webhook'] ?? ''));
|
||||
if ($webhook === '') {
|
||||
return false;
|
||||
}
|
||||
$this->assertWebhook($webhook);
|
||||
|
||||
$lines = [
|
||||
'### 供应商退货确认回执 · ' . $supplier,
|
||||
'- 对账月份:**' . $month . '**',
|
||||
'- 本次确认:**' . max(0, $confirmedRows) . '** 行退货扣减',
|
||||
'- 异议保留:**' . max(0, $disputedRows) . '** 行',
|
||||
'- 确认方式:厂家通过退货明细链接确认',
|
||||
'- 确认时间:' . now()->format('Y-m-d H:i:s'),
|
||||
'- 系统状态:**已回传财务系统**',
|
||||
];
|
||||
|
||||
$this->send(
|
||||
$webhook,
|
||||
trim((string) ($config['secret'] ?? '')),
|
||||
(bool) ($config['at_all'] ?? false),
|
||||
$supplier . ' · 退货确认回执 · ' . $month,
|
||||
implode("\n", $lines),
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string,mixed>> $rows
|
||||
* @return array{count:int,extra:int,mismatch:int,missing:int,difference_amount:float}
|
||||
@ -272,7 +307,7 @@ class SupplierDingTalkNotifier
|
||||
'',
|
||||
'#### [查看退货明细表格](' . $detailUrl . ')',
|
||||
'- 打开后可查看完整表格,并下载 Excel 或 CSV。',
|
||||
'- 核对无误可在页面点击“全部确认无异议”,确认结果会实时回传财务系统。',
|
||||
'- 核对无误可在页面点击“全部确认无异议”,确认结果会实时回传财务系统,并向本群发送确认回执。',
|
||||
'- 明细包含发货时间、条码、商品、数量、单价、金额、仓库、配货单号、快递单号和确认状态。',
|
||||
'',
|
||||
'> 链接仅可查看本厂家 ' . $month . ' 的退货数据,有效期 '
|
||||
|
||||
@ -69,7 +69,7 @@
|
||||
</div>
|
||||
<p>
|
||||
本页读取财务系统最终退货数据,包含待确认、已确认和异议中记录。
|
||||
核对无误可点“全部确认无异议”,确认结果会立即回传财务系统;异议中的记录保持原状态。
|
||||
核对无误可点“全部确认无异议”,确认结果会立即回传财务系统并向本群发送确认回执;异议中的记录保持原状态。
|
||||
也可直接下载 Excel 或 CSV,Excel 文件已冻结表头并启用筛选。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@ -669,6 +669,8 @@ class SupplierReconciliationDingTalkTest extends FeatureTestCase
|
||||
$companyId,
|
||||
null,
|
||||
);
|
||||
$this->saveRobot();
|
||||
Http::fake(['*' => Http::response(['errcode' => 0, 'errmsg' => 'ok'])]);
|
||||
|
||||
$pageUrl = app(SupplierReturnShareLink::class)->pageUrl($companyId, '晨丰', '2026-10');
|
||||
$page = $this->get($pageUrl)->assertOk();
|
||||
@ -682,9 +684,18 @@ class SupplierReconciliationDingTalkTest extends FeatureTestCase
|
||||
->assertStatus(302)
|
||||
->assertSessionHas(
|
||||
'success',
|
||||
'已全部确认:1 行退货扣减生效(1 行异议保持原状态,暂不扣减)。',
|
||||
'已全部确认:1 行退货扣减生效(1 行异议保持原状态,暂不扣减);确认回执已发送到该厂家钉钉群。',
|
||||
);
|
||||
|
||||
Http::assertSentCount(1);
|
||||
Http::assertSent(fn ($request): bool => str_contains(
|
||||
(string) ($request['markdown']['text'] ?? ''),
|
||||
'供应商退货确认回执 · 晨丰',
|
||||
) && str_contains(
|
||||
(string) ($request['markdown']['text'] ?? ''),
|
||||
'系统状态:**已回传财务系统**',
|
||||
));
|
||||
|
||||
$statuses = app(SupplierReturnConfirmation::class)->statuses('晨丰', $companyId);
|
||||
$this->assertSame(SupplierReturnConfirmation::STATUS_CONFIRMED, $statuses['return:confirm-first'] ?? null);
|
||||
$this->assertSame(SupplierReturnConfirmation::STATUS_DISPUTED, $statuses['return:confirm-disputed'] ?? null);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user