102 行
3.3 KiB
PHP
102 行
3.3 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller\shopro_huifu;
|
||
|
||
use addons\shopro_huifu\library\onboard\HuifuOnboardAdminView;
|
||
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
|
||
{
|
||
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 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());
|
||
}
|
||
}
|
||
}
|