结算方式为订单合同或现结的厂家不再计入未上传进度,也不发送群催办。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com>
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Repositories;
|
|
|
|
use Illuminate\Database\DatabaseManager;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class SupplierStatementSettlementRepository
|
|
{
|
|
public const TABLE = 'js_supplier_payment_summary';
|
|
|
|
private readonly \Illuminate\Database\ConnectionInterface $connection;
|
|
|
|
private readonly string $connectionName;
|
|
|
|
public function __construct(DatabaseManager $database)
|
|
{
|
|
$this->connectionName = (string) config('upstream_mirrors.connection', 'business_mirror');
|
|
$this->connection = $database->connection($this->connectionName);
|
|
}
|
|
|
|
/**
|
|
* 读取每家供应商在目标月份或之前最近一期的结算方式。
|
|
*
|
|
* @param list<string> $suppliers
|
|
* @return array<string,array{settlement_method:string,month:string}>
|
|
*/
|
|
public function latestMethods(array $suppliers, string $month): array
|
|
{
|
|
$month = trim($month);
|
|
$suppliers = array_values(array_unique(array_filter(
|
|
array_map(static fn (mixed $supplier): string => trim((string) $supplier), $suppliers),
|
|
static fn (string $supplier): bool => $supplier !== '',
|
|
)));
|
|
if ($suppliers === []
|
|
|| preg_match('/^\d{4}-(0[1-9]|1[0-2])$/D', $month) !== 1
|
|
|| ! Schema::connection($this->connectionName)->hasTable(self::TABLE)) {
|
|
return [];
|
|
}
|
|
|
|
$rows = $this->connection->table(self::TABLE)
|
|
->whereIn('supplier', $suppliers)
|
|
->where('Month', '<=', $month)
|
|
->whereNotNull('settleway')
|
|
->where('settleway', '<>', '')
|
|
->orderByDesc('Month')
|
|
->orderByDesc('id')
|
|
->get(['supplier', 'settleway', 'Month']);
|
|
|
|
$methods = [];
|
|
foreach ($rows as $row) {
|
|
$supplier = trim((string) ($row->supplier ?? ''));
|
|
if ($supplier === '' || isset($methods[$supplier])) {
|
|
continue;
|
|
}
|
|
|
|
$settlementMethod = trim((string) ($row->settleway ?? ''));
|
|
if ($settlementMethod === '') {
|
|
continue;
|
|
}
|
|
|
|
$methods[$supplier] = [
|
|
'settlement_method' => $settlementMethod,
|
|
'month' => trim((string) ($row->Month ?? '')),
|
|
];
|
|
}
|
|
|
|
return $methods;
|
|
}
|
|
}
|