185 行
6.2 KiB
PHP
185 行
6.2 KiB
PHP
<?php
|
||
|
||
namespace app\admin\controller;
|
||
|
||
use app\common\controller\Backend;
|
||
use Exception;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 师傅技能证书审核管理
|
||
*
|
||
* @icon fa fa-id-badge
|
||
*/
|
||
class MasterCert extends Backend
|
||
{
|
||
/**
|
||
* @var \app\admin\model\MasterCert
|
||
*/
|
||
protected $model = null;
|
||
protected $relationSearch = true;
|
||
protected $searchFields = 'id,cert_name,cert_code,master.realname,master.mobile';
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
$this->model = new \app\admin\model\MasterCert;
|
||
$this->view->assign('statusList', $this->model->getStatusList());
|
||
}
|
||
|
||
/**
|
||
* 技能证书列表
|
||
*/
|
||
public function index()
|
||
{
|
||
$this->request->filter(['strip_tags', 'trim']);
|
||
if (false === $this->request->isAjax()) {
|
||
return $this->view->fetch();
|
||
}
|
||
if ($this->request->request('keyField')) {
|
||
return $this->selectpage();
|
||
}
|
||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||
$list = $this->model
|
||
->with(['master'])
|
||
->where($where)
|
||
->order($sort, $order)
|
||
->paginate($limit);
|
||
|
||
return json(['total' => $list->total(), 'rows' => $list->items()]);
|
||
}
|
||
|
||
/**
|
||
* 查看证书详情
|
||
*/
|
||
public function detail($ids = null)
|
||
{
|
||
$row = $this->model->with(['master'])->where('master_cert.id', (int)$ids)->find();
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
$this->view->assign('row', $row);
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 审核技能证书
|
||
*/
|
||
public function audit($ids = null)
|
||
{
|
||
return $this->handleAudit((int)$ids);
|
||
}
|
||
|
||
/**
|
||
* 兼容 FastAdmin 默认编辑路由,复用审核逻辑
|
||
*/
|
||
public function edit($ids = null)
|
||
{
|
||
return $this->handleAudit((int)$ids);
|
||
}
|
||
|
||
/**
|
||
* 统一证书审核处理(保护证件原图只读,仅更新审核状态与意见并通知师傅)
|
||
*/
|
||
private function handleAudit($id)
|
||
{
|
||
$row = $this->model->with(['master'])->where('master_cert.id', (int)$id)->find();
|
||
if (!$row) {
|
||
$this->error(__('No Results were found'));
|
||
}
|
||
|
||
if (false === $this->request->isPost()) {
|
||
$this->view->assign('row', $row);
|
||
return $this->view->fetch('audit');
|
||
}
|
||
|
||
$params = $this->request->post('row/a', []);
|
||
if (empty($params)) {
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
|
||
$status = trim((string)($params['status'] ?? $row['status']));
|
||
$auditMsg = trim((string)($params['audit_msg'] ?? ''));
|
||
|
||
$statusList = $this->model->getStatusList();
|
||
if (!isset($statusList[$status])) {
|
||
$this->error('审核状态不合法');
|
||
}
|
||
if ($status === 'reject' && $auditMsg === '') {
|
||
$this->error('驳回技能证书时,必须填写驳回原因说明');
|
||
}
|
||
|
||
$oldStatus = (string)$row['status'];
|
||
$now = time();
|
||
$adminId = (int)$this->auth->id;
|
||
|
||
Db::startTrans();
|
||
try {
|
||
Db::name('master_cert')->where('id', (int)$row['id'])->update([
|
||
'status' => $status,
|
||
'audit_msg' => mb_substr($auditMsg, 0, 255),
|
||
'audit_admin_id' => $adminId,
|
||
'audittime' => in_array($status, ['pass', 'reject'], true) ? $now : null,
|
||
'updatetime' => $now,
|
||
]);
|
||
|
||
$masterId = (int)$row['master_id'];
|
||
if ($masterId > 0) {
|
||
$images = Db::name('master_cert')
|
||
->where('master_id', $masterId)
|
||
->where('status', 'in', ['pass', 'pending'])
|
||
->order('id desc')
|
||
->column('cert_image');
|
||
$cleanImages = array_values(array_unique(array_filter(array_map('strval', $images ?: []))));
|
||
$json = !empty($cleanImages) ? json_encode($cleanImages, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : '';
|
||
Db::name('master')->where('id', $masterId)->update([
|
||
'cert_images' => mb_substr($json, 0, 1000),
|
||
'updatetime' => $now,
|
||
]);
|
||
}
|
||
|
||
if ($status !== $oldStatus && in_array($status, ['pass', 'reject'], true) && $masterId > 0) {
|
||
$certName = (string)$row['cert_name'];
|
||
$msgTitle = $status === 'pass'
|
||
? "技能证书审核通过({$certName})"
|
||
: "技能证书审核未通过({$certName})";
|
||
$msgContent = $status === 'pass'
|
||
? "您上传的「{$certName}」已通过平台审核,可正常承接对应资质要求的工单。"
|
||
: ("您上传的「{$certName}」未通过审核,原因:" . ($auditMsg !== '' ? $auditMsg : '照片不清晰或证件不符合要求,请重新上传。'));
|
||
|
||
Db::name('message')->insert([
|
||
'receive_type' => 'master',
|
||
'receive_id' => $masterId,
|
||
'type' => 'audit',
|
||
'title' => $msgTitle,
|
||
'content' => $msgContent,
|
||
'order_id' => 0,
|
||
'is_read' => 0,
|
||
'createtime' => $now,
|
||
]);
|
||
|
||
$userId = (int)Db::name('master')->where('id', $masterId)->value('user_id');
|
||
if ($userId > 0) {
|
||
Db::name('message')->insert([
|
||
'receive_type' => 'user',
|
||
'receive_id' => $userId,
|
||
'type' => 'audit',
|
||
'title' => $msgTitle,
|
||
'content' => $msgContent,
|
||
'order_id' => 0,
|
||
'is_read' => 0,
|
||
'createtime' => $now,
|
||
]);
|
||
}
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (Exception $e) {
|
||
Db::rollback();
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$this->success('审核操作成功');
|
||
}
|
||
}
|