35 lines
1.6 KiB
PHP
35 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Support\CourierBills;
|
||
|
||
use Modules\EcommerceFinance\Services\SupplierPayableOverrideStore;
|
||
|
||
/**
|
||
* 快递上传链接推送记录:批量「推送上传链接到快递群」时,这个月已经推过的、已经有账单的分组跳过,免得重复打扰;
|
||
* 在「对账分组」里单独点某一家照发。记录按月存在 supplier_payable_overrides(dataset = courier-upload-link-pushed:YYYY-MM,记录键 = 分组 id)。
|
||
*/
|
||
final class CourierUploadPushes
|
||
{
|
||
public const DATASET = 'courier-upload-link-pushed:';
|
||
|
||
public function __construct(private readonly SupplierPayableOverrideStore $store) {}
|
||
|
||
/** @return array{pushed:array<int,true>,uploaded:array<int,true>} 这个月已推过 / 已有账单的分组 id */
|
||
public function done(string $month, int $companyId): array
|
||
{
|
||
$pushed = [];
|
||
foreach ($this->store->listRows(self::DATASET . $month, $companyId) as $row) {
|
||
$pushed[(int) $row['_action_key']] = true;
|
||
}
|
||
$uploaded = CourierBillMatcher::db()->table('courier_bill_statements')->where('bill_month', $month)->where('line_count', '>', 0)
|
||
->distinct()->pluck('group_id')->mapWithKeys(static fn ($id): array => [(int) $id => true])->all();
|
||
|
||
return ['pushed' => $pushed, 'uploaded' => $uploaded];
|
||
}
|
||
|
||
public function record(string $month, int $groupId, int $companyId, ?int $userId): void
|
||
{
|
||
$this->store->save(self::DATASET . $month, (string) $groupId, ['pushed_at' => now()->toDateTimeString()], $companyId, $userId, 'courier_upload_link');
|
||
}
|
||
}
|