Files
xk-api-yii/common/helpers/FakeId.php
2024-09-19 11:32:39 +08:00

41 lines
1015 B
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
/**
* Created by PhpStorm.
* User: chatfeed
* Date: 2022/5/25
* Time: 7:28 PM
*/
namespace common\helpers;
use admin\exceptions\ApiException;
/**
* ID加前缀偏移真实ID
*/
class FakeId
{
//店员DY供应商GY药店YI业务员XS,用户YH,市场专员ZY 药店账号 限2位字符
private static $offset = ['DY'=>612155,'GY'=>215851,'YD'=>721143,'XS'=>116555,'YH'=>135435,'ZY'=> 123456];
public static function encodeId($type,$id){
if(!isset(self::$offset[$type])){
throw new ApiException("{$type}类型不存在");
}
return $type.($id+self::$offset[$type]);
}
public static function decodeId($id){
if(!$id){
return 0;
}
preg_match('/([A-Z]{2})(\d+)/s',$id,$macths);
if(!isset($macths[1]) || !isset(self::$offset[$macths[1]])){
throw new ApiException("{$macths[1]}类型不存在");
}
;
return (int)$macths[2]-self::$offset[$macths[1]];
}
}