- 在Onboard控制器中添加searchUser方法,支持按昵称、手机号、ID搜索用户 - 修改noNeedRight权限配置,添加searchUser访问权限 - 重构用户选择逻辑,使用新的fetchUserPublic和formatUserOption方法 - 实现用户搜索功能,支持关键词模糊匹配并返回格式化的用户选项 - 优化前端页面样式,采用卡片式布局提升用户体验 - 添加用户头像显示和个人信息展示功能 - 调整页面结构,增加标题栏、底部操作栏等组件 ```
183 行
6.3 KiB
PHP
183 行
6.3 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']);
|
||
$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('请选择用户');
|
||
}
|
||
$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();
|
||
$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());
|
||
}
|
||
}
|
||
}
|