feat: add kuaidi100 logistics sync
This commit is contained in:
61
server-api/app/support/Kuaidi100ConfigService.php
Normal file
61
server-api/app/support/Kuaidi100ConfigService.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\support;
|
||||
|
||||
use support\think\Db;
|
||||
|
||||
class Kuaidi100ConfigService
|
||||
{
|
||||
private const GROUP = 'kuaidi100';
|
||||
|
||||
public function getConfig(): array
|
||||
{
|
||||
$rows = Db::name('system_configs')
|
||||
->where('config_group', self::GROUP)
|
||||
->column('config_value', 'config_key');
|
||||
|
||||
$enabled = $this->normalizeEnabled((string)($rows['enabled'] ?? 'disabled')) === 'enabled';
|
||||
$minInterval = (int)($rows['query_min_interval_minutes'] ?? 30);
|
||||
$minInterval = max(5, min(1440, $minInterval > 0 ? $minInterval : 30));
|
||||
|
||||
return [
|
||||
'enabled' => $enabled,
|
||||
'customer' => trim((string)($rows['customer'] ?? '')),
|
||||
'key' => trim((string)($rows['key'] ?? '')),
|
||||
'callback_url' => trim((string)($rows['callback_url'] ?? '')),
|
||||
'callback_salt' => trim((string)($rows['callback_salt'] ?? '')),
|
||||
'query_min_interval_minutes' => $minInterval,
|
||||
];
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->getConfig()['enabled'];
|
||||
}
|
||||
|
||||
public function isReadyForQuery(): bool
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
return $config['enabled'] && $config['customer'] !== '' && $config['key'] !== '';
|
||||
}
|
||||
|
||||
public function isReadyForSubscribe(): bool
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
return $config['enabled'] && $config['key'] !== '' && $config['callback_url'] !== '';
|
||||
}
|
||||
|
||||
public function isReadyForRecognition(): bool
|
||||
{
|
||||
$config = $this->getConfig();
|
||||
|
||||
return $config['enabled'] && $config['key'] !== '';
|
||||
}
|
||||
|
||||
public function normalizeEnabled(string $value): string
|
||||
{
|
||||
return in_array($value, ['enabled', 'disabled'], true) ? $value : 'disabled';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user