feat(shopro_huifu): 添加汇付地区编码转换和银行支行查询功能 - 新增 HuifuOnboardAreaHelper::toHuifuCityCode 方法,将区县级编码转换为地级市编码 - 新增 HuifuOnboardBankBranch::findByBranchCode 方法,支持按联行号精确查找银行信息 - 在业务开通流程中使用地区编码转换方法确保汇付银行卡信息正确 - 在验证器中添加根据联行号自动填充省市信息的功能 - 修复区域ID为空时省份ID的自动推导逻辑 ```
51 行
1.5 KiB
PHP
51 行
1.5 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_huifu\library\onboard;
|
||
|
||
class HuifuOnboardAreaHelper
|
||
{
|
||
/**
|
||
* 将小程序 shopro 省市区 ID 转为汇付 prov_id / area_id / district_id
|
||
*/
|
||
public static function applyRegionCodes(array &$data)
|
||
{
|
||
if (empty($data['prov_id']) && !empty($data['shopro_province_id'])) {
|
||
$data['prov_id'] = self::toCode($data['shopro_province_id']);
|
||
}
|
||
if (empty($data['area_id']) && !empty($data['shopro_city_id'])) {
|
||
$data['area_id'] = self::toCode($data['shopro_city_id']);
|
||
}
|
||
if (empty($data['district_id']) && !empty($data['shopro_district_id'])) {
|
||
$data['district_id'] = self::toCode($data['shopro_district_id']);
|
||
}
|
||
}
|
||
|
||
public static function toCode($id)
|
||
{
|
||
$id = trim((string) $id);
|
||
if ($id === '') {
|
||
return '';
|
||
}
|
||
if (strlen($id) >= 6) {
|
||
return substr($id, 0, 6);
|
||
}
|
||
return str_pad($id, 6, '0', STR_PAD_RIGHT);
|
||
}
|
||
|
||
/**
|
||
* 汇付银行卡 card_info.area_id 要求地级市编码(如安顺 520400),
|
||
* 小程序省市区选到区县时可能是 520402,需上提为 XXYY00。
|
||
*/
|
||
public static function toHuifuCityCode($code)
|
||
{
|
||
$code = self::toCode($code);
|
||
if ($code === '' || strlen($code) !== 6) {
|
||
return $code;
|
||
}
|
||
if (substr($code, 4, 2) !== '00') {
|
||
return substr($code, 0, 4) . '00';
|
||
}
|
||
return $code;
|
||
}
|
||
}
|