Files
toolbox/app/Enums/CaseLabelBit.php
T
2026-08-12 18:00:09 +08:00

91 lines
3.1 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\Enums;
/**
* CRM 病例标记位 ea_case_cstm.label_bit
*
* 对应 service 项目的 Eainc\Enum\Cases\LabelBitEnum。
*
* 数据流:
* 1. CRMservice)通过 /case/update/bit 写入 ea_case_cstm.label_bit
* 并投递 case_basic_info_change 事件(携带 labelBit);
* 2. agent-be 的 CaseEventHandleService::fillCase 消费事件后写入
* cases.is_need_pfp = label_bit & DebtEnum::needMoney()
* 其中 needMoney() 是 configs 表 stuck_payment_reason 里所有 key 的按位或。
*
* 也就是说 is_need_pfp 并不是布尔值,而是「被 stuck_payment_reason 过滤后的卡款原因位图」。
*/
final class CaseLabelBit
{
/** @var int bit0 允许 APP 授信放行(非卡款原因) */
public const ALLOW_PROCESS_BY_HONEST = 1;
/** @var int bit1 新病例订单卡生产 */
public const APPLIANCE_NEED_MONEY = 2;
/** @var int bit2 产品变更(升档)卡生产 */
public const UPGRADE_NEED_MONEY = 4;
/** @var int bit3 病例延期产品卡生产 */
public const EXTENSION_NEED_MONEY = 8;
/** @var array<int,string> CRM 侧原始位含义 */
private const CRM_LABELS = [
self::ALLOW_PROCESS_BY_HONEST => '允许APP授信放行',
self::APPLIANCE_NEED_MONEY => '新病例订单卡生产',
self::UPGRADE_NEED_MONEY => '产品变更卡生产',
self::EXTENSION_NEED_MONEY => '病例延期卡生产',
];
/** @var array<int,string> 面向用户的原因解释 */
private const DESCRIPTIONS = [
self::ALLOW_PROCESS_BY_HONEST => '允许 APP 走授信放行的开关,不属于卡款原因,不会计入 is_need_pfp',
self::APPLIANCE_NEED_MONEY => '新病例订单款项未结清,CRM 把病例卡在生产前,需要代理在代理端确认进产',
self::UPGRADE_NEED_MONEY => '病例做了产品变更(升档),差价款项未结清,需要代理确认进产后才会放行',
self::EXTENSION_NEED_MONEY => '病例服务年限延期的费用未结清,需要先结清费用才能继续生产',
];
public static function crmLabel(int $bit): string
{
return self::CRM_LABELS[$bit] ?? ('未知标记位 '.$bit);
}
public static function description(int $bit): string
{
return self::DESCRIPTIONS[$bit] ?? '未在 CRM 枚举中定义的标记位,需确认 CRM 是否新增了卡款原因';
}
/**
* 拆出位图中所有置位的 bit
*
* @return int[]
*/
public static function split(int $value): array
{
$bits = [];
for ($bit = 1; $bit > 0 && $bit <= $value; $bit <<= 1) {
if (($value & $bit) === $bit) {
$bits[] = $bit;
}
}
return $bits;
}
/**
* 把位图翻译成可读文本,如「新病例订单卡生产 / 产品变更卡生产」
*/
public static function toText(int $value): string
{
if ($value <= 0) {
return '无标记';
}
return implode(' / ', array_map(
static fn (int $bit): string => self::crmLabel($bit),
self::split($value)
));
}
}