49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
/**
|
|
* 科目映射的业务平台口径。
|
|
*
|
|
* 淘宝和天猫在实际经营中按同一平台处理;规则仍保留原始平台名,
|
|
* 这样历史操作记录和精确规则不会丢失。
|
|
*/
|
|
final class AccountMappingPlatform
|
|
{
|
|
public const TAOBAO = '淘宝';
|
|
|
|
public const TMALL = '天猫';
|
|
|
|
public const TAOBAO_TMALL = '淘宝天猫';
|
|
|
|
public static function canonical(string $platform): string
|
|
{
|
|
$platform = trim($platform);
|
|
|
|
return match ($platform) {
|
|
self::TAOBAO, self::TMALL, self::TAOBAO_TMALL => self::TAOBAO_TMALL,
|
|
default => $platform,
|
|
};
|
|
}
|
|
|
|
public static function equivalent(string $left, string $right): bool
|
|
{
|
|
return self::canonical($left) === self::canonical($right);
|
|
}
|
|
|
|
/**
|
|
* 排序优先级:原平台精确匹配优先,同口径平台其次,其它平台最后。
|
|
*/
|
|
public static function matchRank(string $candidate, string $target): int
|
|
{
|
|
$candidate = trim($candidate);
|
|
$target = trim($target);
|
|
|
|
if (mb_strtolower($candidate) === mb_strtolower($target)) {
|
|
return 0;
|
|
}
|
|
|
|
return self::equivalent($candidate, $target) ? 1 : 2;
|
|
}
|
|
}
|