CaiWuXiTong/app/Support/DropshipFreight/DropshipShareLink.php
Claude 505855da4c 代发运费对账:核对完成后推送厂家钉钉群确认,厂家免登录逐单确认或提异议
- 财务端:各厂家汇总/单家明细加「核对完成」「推送厂家确认」「重新推送」,显示厂家确认状态和异议
- 推送用供应商对账里这家的钉钉群机器人(和货款对账同一个群),附免登录签名链接(30 天)
- 厂家确认页:汇总、不结或运费有差的单逐单勾选异议并写原因,其他单号可按「单号 原因」填写;可下载厂家版 Excel
- 提交后状态实时回写,并在群里发回执;重新推送版本号加一,旧链接作废
- 状态和异议存在 supplier_payable_overrides 通用表,无数据库迁移

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNTa9mVziToe5w52mmrrar
2026-12-02 19:38:02 +08:00

59 lines
2.3 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\Support\DropshipFreight;
use DateTimeInterface;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\URL;
use Throwable;
/**
* 代发运费确认页的免登录链接(同供应商对账的货款确认页):
* 公司、厂家、月份、推送版本放进加密令牌,URL 再做 Laravel 签名,厂家只能看本厂家本次推送的账期。
*/
final class DropshipShareLink
{
public const TTL_DAYS = 30;
public function pageUrl(int $companyId, int $factoryId, string $month, int $version): string
{
return $this->signedRoute('signed.dropship-freight.show', $this->token($companyId, $factoryId, $month, $version), $companyId);
}
public function signedRoute(string $routeName, string $token, int $companyId, ?DateTimeInterface $expires = null): string
{
return URL::temporarySignedRoute($routeName, $expires ?? now()->addDays(self::TTL_DAYS), [
'company_id' => $companyId, 'token' => $token,
]);
}
/** @return array{factory_id:int,month:string,version:int}|null */
public function resolveToken(string $token, int $companyId): ?array
{
try {
$padding = (4 - strlen($token) % 4) % 4;
$encrypted = base64_decode(strtr($token . str_repeat('=', $padding), '-_', '+/'), true);
if ($encrypted === false) {
return null;
}
$payload = json_decode(Crypt::decryptString($encrypted), true, flags: JSON_THROW_ON_ERROR);
} catch (Throwable) {
return null;
}
if (! is_array($payload) || (int) ($payload['company_id'] ?? 0) !== $companyId || (int) ($payload['factory_id'] ?? 0) <= 0
|| preg_match('/^\d{4}-\d{2}$/', (string) ($payload['month'] ?? '')) !== 1 || (int) ($payload['version'] ?? 0) <= 0) {
return null;
}
return ['factory_id' => (int) $payload['factory_id'], 'month' => (string) $payload['month'], 'version' => (int) $payload['version']];
}
private function token(int $companyId, int $factoryId, string $month, int $version): string
{
$payload = json_encode(['company_id' => $companyId, 'factory_id' => $factoryId, 'month' => $month, 'version' => $version],
JSON_THROW_ON_ERROR);
return rtrim(strtr(base64_encode(Crypt::encryptString($payload)), '+/', '-_'), '=');
}
}