feat(shopro_huifu): 添加商户入驻查询日志记录功能 为HuifuOnboardQuery类的pollAndUpdate方法添加详细的错误日志记录, 包括开始轮询、跳过条件判断、申请状态查询和基础信息查询等关键步骤的日志输出, 便于调试和监控商户入驻流程的状态变化。 同时为applyRemoteStatus和isBasicActive方法增加日志记录, 帮助追踪远程状态解析结果和基础状态激活检查的过程。 ```
142 行
5.7 KiB
PHP
142 行
5.7 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro_huifu\library\onboard;
|
|
|
|
use addons\shopro_huifu\library\SdkLoader;
|
|
use addons\shopro_huifu\model\Onboard;
|
|
|
|
class HuifuOnboardQuery
|
|
{
|
|
protected $sdk;
|
|
|
|
public function __construct(HuifuOnboardSdk $sdk = null)
|
|
{
|
|
$this->sdk = $sdk ?: new HuifuOnboardSdk();
|
|
}
|
|
|
|
public function pollAndUpdate(Onboard $row)
|
|
{
|
|
\think\Log::error('[shopro_huifu] onboard poll begin file=' . realpath(__FILE__)
|
|
. ' id=' . $row['id']
|
|
. ' huifu_id=' . ($row['huifu_id'] ?? '')
|
|
. ' apply_no=' . ($row['apply_no'] ?? '')
|
|
. ' busi_req_seq_id=' . ($row['busi_req_seq_id'] ?? '')
|
|
. ' status=' . ($row['onboard_status'] ?? ''));
|
|
|
|
if (!$row['huifu_id']) {
|
|
\think\Log::error('[shopro_huifu] onboard poll skipped: missing huifu_id id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
if ($row['onboard_status'] === Onboard::STATUS_APPROVED) {
|
|
\think\Log::error('[shopro_huifu] onboard poll skipped: already approved id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
|
|
$applyNo = $row['apply_no'];
|
|
if ($applyNo) {
|
|
$status = $this->queryApply($row['huifu_id'], $applyNo);
|
|
\think\Log::error('[shopro_huifu] onboard apply query id=' . $row['id']
|
|
. ' apply_no=' . $applyNo
|
|
. ' data=' . json_encode($status, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
$row = $this->applyRemoteStatus($row, $status);
|
|
if ($row['onboard_status'] === Onboard::STATUS_APPROVED) {
|
|
return $row;
|
|
}
|
|
} else {
|
|
\think\Log::error('[shopro_huifu] onboard apply query skipped: empty apply_no id=' . $row['id']);
|
|
}
|
|
|
|
$basic = $this->queryBasic($row['huifu_id']);
|
|
\think\Log::error('[shopro_huifu] onboard basic query id=' . $row['id']
|
|
. ' data=' . json_encode($basic, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
if ($this->isBasicActive($basic)) {
|
|
if (in_array($row['onboard_status'], [Onboard::STATUS_BUSI_PENDING, Onboard::STATUS_BASIC_OK], true)) {
|
|
$row->onboard_status = Onboard::STATUS_APPROVED;
|
|
$row->reject_reason = '';
|
|
$row->resp_snapshot = json_encode($basic, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
HuifuOnboardReceiverSync::sync($row);
|
|
}
|
|
}
|
|
|
|
return $row;
|
|
}
|
|
|
|
public function queryApply($huifuId, $applyNo)
|
|
{
|
|
SdkLoader::requireRequest('V2UserApplyQueryRequest.php');
|
|
$meta = $this->sdk->newReqMeta();
|
|
$request = new \BsPaySdk\request\V2UserApplyQueryRequest();
|
|
$request->setHuifuId($huifuId);
|
|
$request->setReqSeqId($meta['req_seq_id']);
|
|
$request->setReqDate($meta['req_date']);
|
|
$request->setApplyNo($applyNo);
|
|
$result = $this->sdk->getClient()->postRequest($request);
|
|
$safe = $this->sdk->getClient()->safeApiResult($result);
|
|
return $safe['ok'] ? $safe['data'] : [];
|
|
}
|
|
|
|
public function queryBasic($huifuId)
|
|
{
|
|
SdkLoader::requireRequest('V2UserBasicdataQueryRequest.php');
|
|
$meta = $this->sdk->newReqMeta();
|
|
$request = new \BsPaySdk\request\V2UserBasicdataQueryRequest();
|
|
$request->setHuifuId($huifuId);
|
|
$request->setReqSeqId($meta['req_seq_id']);
|
|
$request->setReqDate($meta['req_date']);
|
|
$result = $this->sdk->getClient()->postRequest($request);
|
|
$safe = $this->sdk->getClient()->safeApiResult($result);
|
|
return $safe['ok'] ? $safe['data'] : [];
|
|
}
|
|
|
|
protected function applyRemoteStatus(Onboard $row, array $data)
|
|
{
|
|
if (!$data) {
|
|
\think\Log::error('[shopro_huifu] onboard remote status empty id=' . $row['id']);
|
|
return $row;
|
|
}
|
|
$stat = strtolower((string) ($data['apply_status'] ?? $data['audit_status'] ?? $data['status'] ?? ''));
|
|
$desc = (string) ($data['apply_desc'] ?? $data['resp_desc'] ?? $data['reject_reason'] ?? '');
|
|
|
|
\think\Log::error('[shopro_huifu] onboard remote status parsed id=' . $row['id']
|
|
. ' stat=' . $stat
|
|
. ' desc=' . $desc
|
|
. ' keys=' . implode(',', array_keys($data)));
|
|
|
|
if (in_array($stat, ['s', 'success', 'approved', '1', '02', '2'], true)) {
|
|
$row->onboard_status = Onboard::STATUS_APPROVED;
|
|
$row->reject_reason = '';
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
HuifuOnboardReceiverSync::sync($row);
|
|
return $row;
|
|
}
|
|
if (in_array($stat, ['f', 'fail', 'failed', 'rejected', '3', '03', '-1'], true)) {
|
|
$row->onboard_status = Onboard::STATUS_REJECTED;
|
|
$row->reject_reason = $desc ?: '汇付进件审核驳回';
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
return $row;
|
|
}
|
|
|
|
$row->onboard_status = Onboard::STATUS_BUSI_PENDING;
|
|
$row->resp_snapshot = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$row->save();
|
|
return $row;
|
|
}
|
|
|
|
protected function isBasicActive(array $data)
|
|
{
|
|
if (!$data) {
|
|
\think\Log::error('[shopro_huifu] onboard basic active check: empty response');
|
|
return false;
|
|
}
|
|
$stat = strtolower((string) ($data['user_status'] ?? $data['status'] ?? $data['acct_stat'] ?? ''));
|
|
$active = in_array($stat, ['n', 'normal', 's', 'success', '1'], true);
|
|
\think\Log::error('[shopro_huifu] onboard basic active check stat=' . $stat
|
|
. ' active=' . ($active ? '1' : '0')
|
|
. ' keys=' . implode(',', array_keys($data)));
|
|
return $active;
|
|
}
|
|
}
|