feat(shopro_huifu): 优化汇付进件提交异常处理 - 在submitFromDraft方法中添加HttpResponseException捕获并重新抛出 - 在resubmit方法中添加HttpResponseException捕获并重新抛出 - 改进错误消息显示,当异常消息为空时显示默认提示 - 调整代码结构确保成功消息在正确位置返回 ```
193 行
6.8 KiB
PHP
193 行
6.8 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller\shopro_huifu;
|
||
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardAdminService;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardAdminView;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardBankBranch;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardError;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardQuery;
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardService;
|
||
use addons\shopro_huifu\model\Onboard as OnboardModel;
|
||
use app\admin\controller\shopro\Base;
|
||
|
||
class Onboard extends Base
|
||
{
|
||
protected $noNeedRight = ['userRoles', 'searchUser', 'searchBranch'];
|
||
public function index()
|
||
{
|
||
if ($this->request->isAjax()) {
|
||
$detailId = intval($this->request->get('detail_id', 0));
|
||
if ($detailId > 0) {
|
||
return $this->detail($detailId);
|
||
}
|
||
$status = $this->request->get('status');
|
||
$query = OnboardModel::order('id desc');
|
||
if ($status) {
|
||
$query->where('onboard_status', $status);
|
||
}
|
||
$total = $query->count();
|
||
$list = $query->limit($this->request->get('offset', 0), $this->request->get('limit', 20))->select();
|
||
$rows = [];
|
||
foreach ($list as $item) {
|
||
$rows[] = HuifuOnboardAdminView::enrichListRow($item);
|
||
}
|
||
return $this->success('ok', null, ['total' => $total, 'rows' => $rows]);
|
||
}
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 进件资料详情(Ajax 请优先走 index?detail_id= 复用 index 权限)
|
||
*/
|
||
public function detail($ids = null)
|
||
{
|
||
if (!$this->request->isAjax() && !$this->request->isPost()) {
|
||
$this->error('非法请求');
|
||
}
|
||
$row = OnboardModel::get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
$this->success('ok', null, HuifuOnboardAdminView::buildDetail($row));
|
||
}
|
||
|
||
public function poll($ids = null)
|
||
{
|
||
$row = OnboardModel::get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
$query = new HuifuOnboardQuery();
|
||
$query->pollAndUpdate($row);
|
||
$this->success('已刷新状态', null, $row);
|
||
}
|
||
|
||
public function submit($ids = null)
|
||
{
|
||
$row = OnboardModel::get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
if ($row['onboard_status'] !== OnboardModel::STATUS_DRAFT) {
|
||
$this->error('仅待后台审核的记录可提交汇付');
|
||
}
|
||
try {
|
||
$service = new HuifuOnboardService();
|
||
$service->submitFromDraft($row['user_id'], $row['role_type'], $row['role_ref_id']);
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
throw $e;
|
||
} catch (\Throwable $e) {
|
||
$this->error($e->getMessage() ?: '提交汇付进件失败');
|
||
}
|
||
$this->success('已提交汇付进件');
|
||
}
|
||
|
||
public function add()
|
||
{
|
||
if ($this->request->isPost()) {
|
||
return $this->persistDraft();
|
||
}
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
public function edit($ids = null)
|
||
{
|
||
$row = OnboardModel::get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
if ($this->request->isPost()) {
|
||
return $this->persistDraft($row);
|
||
}
|
||
$this->assignconfig('onboardForm', HuifuOnboardAdminView::formDataFromRow($row));
|
||
return $this->view->fetch('shopro_huifu/onboard/add');
|
||
}
|
||
|
||
public function userRoles()
|
||
{
|
||
$userId = intval($this->request->get('user_id', 0));
|
||
if ($userId <= 0) {
|
||
$this->error('请选择用户');
|
||
}
|
||
$userRow = HuifuOnboardAdminView::fetchUserPublic($userId);
|
||
$this->success('ok', null, [
|
||
'user' => HuifuOnboardAdminView::formatUserOption($userRow),
|
||
'roles' => HuifuOnboardAdminView::listRolesForUser($userId),
|
||
]);
|
||
}
|
||
|
||
public function searchUser()
|
||
{
|
||
$keyword = trim((string) $this->request->get('keyword', ''));
|
||
if ($keyword === '') {
|
||
$this->success('ok', null, []);
|
||
}
|
||
$this->success('ok', null, HuifuOnboardAdminView::searchUsers($keyword, intval($this->request->get('limit', 20))));
|
||
}
|
||
|
||
public function searchBranch()
|
||
{
|
||
$keyword = trim((string) $this->request->get('keyword', ''));
|
||
$areaId = trim((string) $this->request->get('area_id', ''));
|
||
$this->success('ok', null, HuifuOnboardBankBranch::search($keyword, $areaId, 20));
|
||
}
|
||
|
||
protected function persistDraft($row = null)
|
||
{
|
||
$userId = intval($this->request->post('user_id', 0));
|
||
$roleType = trim((string) $this->request->post('role_type', ''));
|
||
$roleRefId = intval($this->request->post('role_ref_id', 0));
|
||
$form = $this->request->post('form/a', []);
|
||
if ($row) {
|
||
$userId = intval($row['user_id']);
|
||
$roleType = $row['role_type'];
|
||
$roleRefId = intval($row['role_ref_id']);
|
||
}
|
||
if (!$form || !is_array($form)) {
|
||
$this->error('请填写进件资料');
|
||
}
|
||
try {
|
||
$service = new HuifuOnboardAdminService();
|
||
$onboardId = $row ? intval($row['id']) : 0;
|
||
$saved = $service->saveDraft($userId, $roleType, $roleRefId, $form, $onboardId);
|
||
} catch (\InvalidArgumentException $e) {
|
||
$this->error($e->getMessage());
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
throw $e;
|
||
} catch (\Throwable $e) {
|
||
$this->error(HuifuOnboardError::translate($e->getMessage()));
|
||
}
|
||
if (!$saved) {
|
||
$this->error('进件资料保存失败,请检查汇付分账配置是否已启用');
|
||
}
|
||
$this->success('进件资料已保存,状态为待后台审核', null, [
|
||
'id' => intval($saved['id']),
|
||
]);
|
||
}
|
||
|
||
public function retry($ids = null)
|
||
{
|
||
$row = OnboardModel::get($ids);
|
||
if (!$row) {
|
||
$this->error('记录不存在');
|
||
}
|
||
if ($row['onboard_status'] === OnboardModel::STATUS_APPROVED) {
|
||
$this->error('已通过,无需重试');
|
||
}
|
||
$payload = json_decode($row['payload'] ?? '', true);
|
||
if (!$payload) {
|
||
$this->error('缺少原始进件资料,请用户在小程序重新提交');
|
||
}
|
||
try {
|
||
$service = new HuifuOnboardService();
|
||
$service->resubmit($row['user_id'], $row['role_type'], $row['role_ref_id'], $payload);
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
throw $e;
|
||
} catch (\Throwable $e) {
|
||
$this->error($e->getMessage() ?: '重新提交进件失败');
|
||
}
|
||
$this->success('已重新提交进件');
|
||
}
|
||
}
|