From 8e1135bc59587d3a0ba5e77f73eb464e928e0baa Mon Sep 17 00:00:00 2001 From: limeng <1131177064@qq.com> Date: Wed, 2 Dec 2026 21:26:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=A3=E5=8F=91=E8=BF=90=E8=B4=B9):=20?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=8E=82=E5=AE=B6=E4=B8=8A=E4=BC=A0=E8=B4=A6?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/DropshipFreightController.php | 46 +++++++++++++++++++ .../Services/SupplierDingTalkNotifier.php | 17 +++++++ .../dropship-freight/factories.blade.php | 4 ++ .../dropship-freight/upload.blade.php | 11 +++++ routes/admin.php | 1 + .../Business/DropshipFreightConfirmTest.php | 37 +++++++++++++++ 6 files changed, 116 insertions(+) diff --git a/app/Http/Controllers/Business/DropshipFreightController.php b/app/Http/Controllers/Business/DropshipFreightController.php index f44c1ed3f..0f3260b19 100644 --- a/app/Http/Controllers/Business/DropshipFreightController.php +++ b/app/Http/Controllers/Business/DropshipFreightController.php @@ -233,6 +233,52 @@ final class DropshipFreightController extends Controller return $this->back($request, [], '已推送到「' . $f->name . '」钉钉群(第 ' . $version . ' 次),等厂家在确认页确认。'); } + /** + * 通知厂家上传代发运费账单:传 factory 只通知这一家;不传就通知这个月还没上传、且配了钉钉群机器人的全部厂家。 + */ + public function notifyUpload(Request $request) + { + $data = $request->validate(['month' => ['required', 'date_format:Y-m'], 'factory' => ['nullable', 'integer']]); + $month = $data['month']; + $notifier = app(SupplierDingTalkNotifier::class); + $factories = collect($this->store->factories()); + $single = ! empty($data['factory']); + if ($single) { + $factories = $factories->where('id', (int) $data['factory'])->values(); + abort_if($factories->isEmpty(), 404); + } + $uploaded = array_flip($this->store->db()->table('dropship_bill_files')->where('bill_month', $month)->whereNotNull('factory_id') + ->distinct()->pluck('factory_id')->map('intval')->all()); + $robots = $notifier->configurationMap($factories->pluck('name')->map('strval')->all()); + $portal = route('business.supplier-portal.home', ['company_id' => self::companyId()]); + $sent = $failed = []; + $noRobot = $done = 0; + foreach ($factories as $f) { + if (! $single && isset($uploaded[(int) $f->id])) { + $done++; + continue; + } + if (! ($robots[$f->name]['configured'] ?? false)) { + $noRobot++; + continue; + } + try { + $notifier->pushDropshipUploadReminder((string) $f->name, $month, $portal); + $sent[] = $f->name; + } catch (Throwable $error) { + report($error); + $failed[] = $f->name; + } + } + if ($single && $noRobot > 0) { + throw ValidationException::withMessages(['dropship' => '这家还没有配置钉钉群机器人(在供应商对账里配置,和货款对账同一个群)。']); + } + + return $this->back($request, [], '已通知 ' . count($sent) . ' 家上传 ' . $month . ' 代发运费账单' . ($sent !== [] ? ':' . implode('、', array_slice($sent, 0, 40)) : '') + . ($done > 0 ? ';' . $done . ' 家已经上传,没再通知' : '') . ($noRobot > 0 ? ';' . $noRobot . ' 家没配钉钉群机器人' : '') + . ($failed !== [] ? ';发送失败:' . implode('、', $failed) : '') . '。'); + } + /** 厂家开了运费、但不是「一致」的单:不结算或运费有差,确认页上请厂家重点看。 */ public static function attention(array $rows): int { diff --git a/modules/EcommerceFinance/Services/SupplierDingTalkNotifier.php b/modules/EcommerceFinance/Services/SupplierDingTalkNotifier.php index aff81c0e5..49791461d 100644 --- a/modules/EcommerceFinance/Services/SupplierDingTalkNotifier.php +++ b/modules/EcommerceFinance/Services/SupplierDingTalkNotifier.php @@ -505,6 +505,23 @@ class SupplierDingTalkNotifier return true; } + /** 代发运费:提醒厂家到厂家对账入口(钉钉登录)上传这个月的代发运费账单。 */ + public function pushDropshipUploadReminder(string $supplier, string $month, string $portalUrl): void + { + [$webhook, $config] = $this->robotFor($supplier, 'dropship_upload_reminder'); + $this->send($webhook, trim((string) ($config['secret'] ?? '')), (bool) ($config['at_all'] ?? false), + $supplier . ' · 代发运费账单上传提醒 · ' . $this->displayMonth($month), implode("\n", [ + '### 代发运费账单上传提醒 · ' . $supplier, + '- 请上传 **' . $this->displayMonth($month) . '** 代发运费账单', + '- 按上传模板填写(单号、省、重量、运费、送货备注、面单、费率),单号和运费必填', + '', + '#### [打开厂家对账入口](' . $portalUrl . ')', + '- 钉钉登录后,在「上传运费账单」里选「代发运费账单」,可先下载上传模板。', + '- 上传后群里会收到回执;如无法登录或上传,请在群里联系财务。', + ])); + $this->touch($supplier, 1); + } + /** 快递账单:往这家快递的钉钉对账群推免登录上传链接(机器人在快递账单对账 → 对账分组里配置)。 */ public function pushCourierUploadLink(string $courier, string $month, string $url): void { diff --git a/resources/views/business/pages/courier-payables/dropship-freight/factories.blade.php b/resources/views/business/pages/courier-payables/dropship-freight/factories.blade.php index 3fac89da3..2d0c28581 100644 --- a/resources/views/business/pages/courier-payables/dropship-freight/factories.blade.php +++ b/resources/views/business/pages/courier-payables/dropship-freight/factories.blade.php @@ -34,6 +34,10 @@