feat(shopro_huifu): 添加汇付进件管理功能 - 新增汇付进件管理模块,支持新建、编辑进件流程 - 实现用户角色绑定验证功能,确保进件角色的有效性 - 集成Vue.js前端界面,提供完整的表单操作体验 - 支持个人和企业两种账户类型的进件资料录入 - 添加银行支行搜索功能,方便结算账户信息填写 - 完善进件状态管理和审核流程控制 - 增加图片上传组件,支持身份证、营业执照等证件上传 ```
178 行
6.1 KiB
PHP
178 行
6.1 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', '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']);
|
||
$this->success('已提交汇付进件');
|
||
} catch (\Throwable $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
|
||
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('请选择用户');
|
||
}
|
||
$user = HuifuOnboardAdminView::enrichListRow(['user_id' => $userId, 'payload' => '']);
|
||
$this->success('ok', null, [
|
||
'user' => [
|
||
'id' => $userId,
|
||
'nickname' => $user['user_nickname'] ?? '',
|
||
'mobile' => $user['user_mobile'] ?? '',
|
||
],
|
||
'roles' => HuifuOnboardAdminView::listRolesForUser($userId),
|
||
]);
|
||
}
|
||
|
||
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();
|
||
$saved = $service->saveDraft($userId, $roleType, $roleRefId, $form);
|
||
$this->success('进件资料已保存,状态为待后台审核', null, [
|
||
'id' => $saved ? $saved['id'] : 0,
|
||
]);
|
||
} catch (\InvalidArgumentException $e) {
|
||
$this->error($e->getMessage());
|
||
} catch (\Throwable $e) {
|
||
$this->error(HuifuOnboardError::translate($e->getMessage()));
|
||
}
|
||
}
|
||
|
||
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);
|
||
$this->success('已重新提交进件');
|
||
} catch (\Throwable $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
}
|