文件
xionggeshop/addons/shopro_huifu/controller/Onboard.php
可乐加冰 abc40ef2a9 feat(huifu): 支持汇付进件通过后更换结算银行卡
- 用户端及后台管理端新增更换结算卡接口与页面交互
- 服务层实现换卡核心逻辑、参数校验及汇付接口调用
- 增加换卡异步通知处理与定时轮询补偿以同步审核状态
- 完善进件状态网关,补充换卡审核状态及驳回原因等字段
2026-11-15 00:52:59 +08:00

191 行
6.6 KiB
PHP

<?php
namespace addons\shopro_huifu\controller;
use addons\shopro_huifu\library\Bridge;
use addons\shopro_huifu\library\HuifuNotifyParser;
use addons\shopro_huifu\library\onboard\HuifuOnboardGate;
use addons\shopro_huifu\library\onboard\HuifuOnboardPicture;
use addons\shopro_huifu\library\onboard\HuifuOnboardService;
use addons\shopro_huifu\model\Onboard as OnboardModel;
use think\addons\Controller;
class Onboard extends Controller
{
protected $noNeedLogin = ['notify'];
protected $noNeedRight = ['*'];
protected function ensureEnabled()
{
if (!Bridge::isEnabled()) {
$this->error('汇付插件未启用');
}
}
public function config()
{
$this->ensureEnabled();
$this->success('ok', [
'required' => HuifuOnboardGate::isOnboardRequired(),
'account_types' => [
['value' => 'indv', 'label' => '个人'],
['value' => 'ent', 'label' => '个体户/企业'],
],
'bank_account_types' => [
['value' => '0', 'label' => '对私'],
['value' => '1', 'label' => '对公'],
],
]);
}
public function searchBranch()
{
$this->ensureEnabled();
$keyword = $this->request->get('keyword', $this->request->post('keyword', ''));
$cityCode = $this->request->get('city_code', $this->request->post('city_code', ''));
$limit = intval($this->request->get('limit', 20));
$list = \addons\shopro_huifu\library\onboard\HuifuOnboardBankBranch::search($keyword, $cityCode, $limit);
$this->success('ok', ['list' => $list]);
}
public function status()
{
$this->ensureEnabled();
$userId = $this->auth->id;
$roleType = $this->request->get('role_type', 'promoter');
$roleRefId = intval($this->request->get('role_ref_id', $userId));
if ($roleType === 'promoter') {
$roleRefId = $userId;
}
$row = OnboardModel::findByRole($userId, $roleType, $roleRefId);
$this->success('ok', HuifuOnboardGate::publicStatus($row));
}
public function uploadPicture()
{
$this->ensureEnabled();
if (!HuifuOnboardGate::isOnboardRequired()) {
$this->error('当前未开启汇付进件');
}
$fileType = $this->request->post('file_type', 'F02');
$imageUrl = $this->request->post('image_url', '');
if ($imageUrl === '') {
$this->error('请上传图片');
}
try {
$picture = new HuifuOnboardPicture();
$fileId = $picture->uploadByUrl($fileType, $imageUrl);
$this->success('上传成功', ['file_id' => $fileId, 'file_type' => $fileType]);
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
public function submit()
{
$this->ensureEnabled();
$userId = $this->auth->id;
$roleType = $this->request->post('role_type', 'promoter');
$roleRefId = intval($this->request->post('role_ref_id', $userId));
if ($roleType === 'promoter') {
$roleRefId = $userId;
}
$form = $this->request->post('huifu_onboard/a', []);
if (!$form) {
$form = $this->request->post('form/a', []);
}
try {
$service = new HuifuOnboardService();
$row = $service->submit($userId, $roleType, $roleRefId, $form);
$this->success('进件已提交', HuifuOnboardGate::publicStatus($row));
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
public function resubmit()
{
$this->ensureEnabled();
$userId = $this->auth->id;
$roleType = $this->request->post('role_type', 'promoter');
$roleRefId = intval($this->request->post('role_ref_id', $userId));
if ($roleType === 'promoter') {
$roleRefId = $userId;
}
$form = $this->request->post('huifu_onboard/a', []);
if (!$form) {
$form = $this->request->post('form/a', []);
}
try {
$service = new HuifuOnboardService();
$row = $service->resubmit($userId, $roleType, $roleRefId, $form);
$this->success('进件已重新提交', HuifuOnboardGate::publicStatus($row, $userId, $roleType, $roleRefId));
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
/**
* 进件已通过后更换结算银行卡
*/
public function modifyCard()
{
$this->ensureEnabled();
if (!HuifuOnboardGate::isOnboardRequired()) {
$this->error('当前未开启汇付进件');
}
$userId = $this->auth->id;
$roleType = $this->request->post('role_type', 'promoter');
$roleRefId = intval($this->request->post('role_ref_id', $userId));
if ($roleType === 'promoter') {
$roleRefId = $userId;
}
$form = $this->request->post('huifu_onboard/a', []);
if (!$form) {
$form = $this->request->post('form/a', []);
}
if (!$form || !is_array($form)) {
$this->error('请填写结算银行卡信息');
}
try {
$service = new HuifuOnboardService();
$row = $service->modifySettleCard($userId, $roleType, $roleRefId, $form);
$status = HuifuOnboardGate::publicStatus($row, $userId, $roleType, $roleRefId);
$msg = !empty($status['card_modify_pending'])
? '结算卡更换已提交,请等待审核'
: '结算卡更换成功';
$this->success($msg, $status);
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
public function notify()
{
$raw = HuifuNotifyParser::parse($this->request);
try {
$client = new \addons\shopro_huifu\library\HuifuClient();
$sign = HuifuNotifyParser::normalizeSign((string) ($raw['sign'] ?? ''));
$respData = (string) ($raw['resp_data'] ?? '');
if ($respData === '' || $sign === '' || !$client->verifyNotify($respData, $sign)) {
http_response_code(400);
echo '';
return;
}
$data = json_decode($respData, true);
if (!is_array($data)) {
http_response_code(400);
echo '';
return;
}
$service = new HuifuOnboardService();
$service->handleNotify($data);
http_response_code(200);
echo 'success';
} catch (\Throwable $e) {
http_response_code(500);
echo '';
}
}
}