501 行
17 KiB
PHP
501 行
17 KiB
PHP
<?php
|
|
|
|
namespace Retail\Controller;
|
|
|
|
use Think\Controller;
|
|
|
|
/**
|
|
* 骑手认证审核管理控制器
|
|
* Class RiderAuthController
|
|
* @package Retail\Controller
|
|
*/
|
|
class RiderAuthController extends Controller
|
|
{
|
|
|
|
/**
|
|
* 认证审核管理主页
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->display();
|
|
}
|
|
|
|
/**
|
|
* 获取认证申请列表
|
|
*/
|
|
public function getAuthList()
|
|
{
|
|
try {
|
|
$page = I('get.page', 1, 'intval');
|
|
$pageSize = I('get.pageSize', 20, 'intval');
|
|
$keyword = I('get.keyword', '', 'trim');
|
|
$authStatus = I('get.auth_status', '', 'trim');
|
|
$healthStatus = I('get.health_status', '', 'trim');
|
|
$startTime = I('get.start_time', '', 'trim');
|
|
$endTime = I('get.end_time', '', 'trim');
|
|
|
|
$where = array();
|
|
|
|
// 关键词搜索(骑手姓名、手机号、身份证号)
|
|
if (!empty($keyword)) {
|
|
$where['_string'] = "(rider_name LIKE '%{$keyword}%' OR rider_phone LIKE '%{$keyword}%' OR id_card LIKE '%{$keyword}%')";
|
|
}
|
|
|
|
// 实名认证状态筛选
|
|
if (!empty($authStatus)) {
|
|
$where['auth_status'] = $authStatus;
|
|
}
|
|
|
|
// 健康证状态筛选
|
|
if (!empty($healthStatus)) {
|
|
$where['health_status'] = $healthStatus;
|
|
}
|
|
|
|
// 时间筛选
|
|
if (!empty($startTime)) {
|
|
$where['add_time'][] = array('egt', $startTime);
|
|
}
|
|
if (!empty($endTime)) {
|
|
$where['add_time'][] = array('elt', $endTime . ' 23:59:59');
|
|
}
|
|
|
|
$where['status'] = 1;
|
|
|
|
$Rider = M('RiderInfo');
|
|
|
|
// 获取总数
|
|
$total = $Rider->where($where)->count();
|
|
|
|
// 获取列表数据
|
|
$list = $Rider->field('id, rider_name, rider_phone, id_card, id_card_front, id_card_back,
|
|
auth_status, auth_remark, auth_time,
|
|
health_cert, health_status, health_remark, health_time,
|
|
add_time, rider_avatar')
|
|
->where($where)
|
|
->order('add_time DESC')
|
|
->page($page, $pageSize)
|
|
->select();
|
|
|
|
// 格式化数据
|
|
foreach ($list as &$item) {
|
|
$item['create_time_format'] = $item['add_time'];
|
|
$item['auth_time_format'] = $item['auth_time'] ? date('Y-m-d H:i:s', $item['auth_time']) : '';
|
|
$item['health_time_format'] = $item['health_time'] ? date('Y-m-d H:i:s', $item['health_time']) : '';
|
|
$item['auth_status_text'] = $this->getAuthStatusText($item['auth_status']);
|
|
$item['health_status_text'] = $this->getHealthStatusText($item['health_status']);
|
|
|
|
// 隐藏身份证号中间部分
|
|
if ($item['id_card']) {
|
|
$item['id_card_masked'] = substr($item['id_card'], 0, 6) . '********' . substr($item['id_card'], -4);
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
'code' => 0,
|
|
'msg' => 'success',
|
|
'data' => array(
|
|
'list' => $list,
|
|
'total' => $total,
|
|
'page' => $page,
|
|
'pageSize' => $pageSize
|
|
)
|
|
);
|
|
|
|
$this->ajaxReturn($result);
|
|
} catch (\Exception $e) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => $e->getMessage()));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取认证详情
|
|
*/
|
|
public function getAuthDetail()
|
|
{
|
|
$id = I('get.id', 0, 'intval');
|
|
|
|
if (empty($id)) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '参数错误'));
|
|
}
|
|
|
|
$detail = M('RiderInfo')->where(array('id' => $id, 'status' => 1))->find();
|
|
|
|
if (!$detail) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '骑手不存在'));
|
|
}
|
|
|
|
// 格式化数据
|
|
$detail['create_time_format'] = $detail['add_time'];
|
|
$detail['auth_time_format'] = $detail['auth_time'] ? date('Y-m-d H:i:s', $detail['auth_time']) : '';
|
|
$detail['health_time_format'] = $detail['health_time'] ? date('Y-m-d H:i:s', $detail['health_time']) : '';
|
|
$detail['auth_status_text'] = $this->getAuthStatusText($detail['auth_status']);
|
|
$detail['health_status_text'] = $this->getHealthStatusText($detail['health_status']);
|
|
|
|
// 获取审核管理员信息
|
|
if ($detail['auth_admin_id']) {
|
|
$admin = M('Admin')->where(array('id' => $detail['auth_admin_id']))->find();
|
|
$detail['auth_admin_name'] = $admin ? $admin['username'] : '';
|
|
}
|
|
|
|
if ($detail['health_admin_id']) {
|
|
$admin = M('Admin')->where(array('id' => $detail['health_admin_id']))->find();
|
|
$detail['health_admin_name'] = $admin ? $admin['username'] : '';
|
|
}
|
|
|
|
$this->ajaxReturn(array('code' => 0, 'msg' => 'success', 'data' => $detail));
|
|
}
|
|
|
|
/**
|
|
* 审核实名认证
|
|
*/
|
|
public function auditAuth()
|
|
{
|
|
$id = I('post.id', 0, 'intval');
|
|
$status = I('post.status', 0, 'intval'); // 1=通过, 2=拒绝
|
|
$remark = I('post.remark', '', 'trim');
|
|
|
|
if (empty($id)) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '参数错误'));
|
|
}
|
|
|
|
if (!in_array($status, [1, 2])) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '审核状态错误'));
|
|
}
|
|
|
|
$Rider = M('RiderInfo');
|
|
$rider = $Rider->where(array('id' => $id, 'status' => 1))->find();
|
|
|
|
if (!$rider) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '骑手不存在'));
|
|
}
|
|
|
|
if ($rider['auth_status'] != 0) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '该申请已处理'));
|
|
}
|
|
|
|
// 更新认证状态
|
|
$updateData = array(
|
|
'auth_status' => $status,
|
|
'auth_remark' => $remark,
|
|
'auth_time' => time(),
|
|
'auth_admin_id' => session('admin_id')
|
|
);
|
|
|
|
$result = $Rider->where(array('id' => $id))->save($updateData);
|
|
|
|
if ($result) {
|
|
// 记录审核日志
|
|
$logData = array(
|
|
'rider_id' => $id,
|
|
'type' => 'auth_audit',
|
|
'status' => $status,
|
|
'remark' => $remark,
|
|
'admin_id' => session('admin_id'),
|
|
'create_time' => time()
|
|
);
|
|
M('RiderAuditLog')->add($logData);
|
|
|
|
$this->ajaxReturn(array('code' => 0, 'msg' => '操作成功'));
|
|
} else {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '操作失败'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 审核健康证
|
|
*/
|
|
public function auditHealth()
|
|
{
|
|
$id = I('post.id', 0, 'intval');
|
|
$status = I('post.status', 0, 'intval'); // 1=通过, 2=拒绝
|
|
$remark = I('post.remark', '', 'trim');
|
|
|
|
if (empty($id)) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '参数错误'));
|
|
}
|
|
|
|
if (!in_array($status, [1, 2])) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '审核状态错误'));
|
|
}
|
|
|
|
$Rider = M('RiderInfo');
|
|
$rider = $Rider->where(array('id' => $id, 'status' => 1))->find();
|
|
|
|
if (!$rider) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '骑手不存在'));
|
|
}
|
|
|
|
if ($rider['health_status'] != 0) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '该申请已处理'));
|
|
}
|
|
|
|
// 更新健康证状态
|
|
$updateData = array(
|
|
'health_status' => $status,
|
|
'health_remark' => $remark,
|
|
'health_time' => time(),
|
|
'health_admin_id' => session('admin_id')
|
|
);
|
|
|
|
$result = $Rider->where(array('id' => $id))->save($updateData);
|
|
|
|
if ($result) {
|
|
// 记录审核日志
|
|
$logData = array(
|
|
'rider_id' => $id,
|
|
'type' => 'health_audit',
|
|
'status' => $status,
|
|
'remark' => $remark,
|
|
'admin_id' => session('admin_id'),
|
|
'create_time' => time()
|
|
);
|
|
M('RiderAuditLog')->add($logData);
|
|
|
|
$this->ajaxReturn(array('code' => 0, 'msg' => '操作成功'));
|
|
} else {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '操作失败'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 批量审核
|
|
*/
|
|
public function batchAudit()
|
|
{
|
|
$ids = I('post.ids', '', 'trim');
|
|
$type = I('post.type', '', 'trim'); // auth=实名认证, health=健康证
|
|
$status = I('post.status', 0, 'intval'); // 1=通过, 2=拒绝
|
|
$remark = I('post.remark', '', 'trim');
|
|
|
|
if (empty($ids) || empty($type)) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '参数错误'));
|
|
}
|
|
|
|
if (!in_array($status, [1, 2])) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '审核状态错误'));
|
|
}
|
|
|
|
if (!in_array($type, ['auth', 'health'])) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '审核类型错误'));
|
|
}
|
|
|
|
$idArray = explode(',', $ids);
|
|
$idArray = array_filter(array_map('intval', $idArray));
|
|
|
|
if (empty($idArray)) {
|
|
$this->ajaxReturn(array('code' => 1, 'msg' => '无效的ID列表'));
|
|
}
|
|
|
|
$Rider = M('RiderInfo');
|
|
$successCount = 0;
|
|
|
|
foreach ($idArray as $id) {
|
|
$rider = $Rider->where(array('id' => $id, 'status' => 1))->find();
|
|
|
|
if (!$rider) {
|
|
continue;
|
|
}
|
|
|
|
// 检查是否已处理
|
|
if ($type == 'auth' && $rider['auth_status'] != 0) {
|
|
continue;
|
|
}
|
|
if ($type == 'health' && $rider['health_status'] != 0) {
|
|
continue;
|
|
}
|
|
|
|
// 更新状态
|
|
if ($type == 'auth') {
|
|
$updateData = array(
|
|
'auth_status' => $status,
|
|
'auth_remark' => $remark,
|
|
'auth_time' => time(),
|
|
'auth_admin_id' => session('admin_id')
|
|
);
|
|
} else {
|
|
$updateData = array(
|
|
'health_status' => $status,
|
|
'health_remark' => $remark,
|
|
'health_time' => time(),
|
|
'health_admin_id' => session('admin_id')
|
|
);
|
|
}
|
|
|
|
$result = $Rider->where(array('id' => $id))->save($updateData);
|
|
|
|
if ($result) {
|
|
$successCount++;
|
|
|
|
// 记录审核日志
|
|
$logData = array(
|
|
'rider_id' => $id,
|
|
'type' => $type . '_audit',
|
|
'status' => $status,
|
|
'remark' => $remark,
|
|
'admin_id' => session('admin_id'),
|
|
'create_time' => time()
|
|
);
|
|
M('RiderAuditLog')->add($logData);
|
|
}
|
|
}
|
|
|
|
$this->ajaxReturn(array('code' => 0, 'msg' => "成功处理{$successCount}条记录"));
|
|
}
|
|
|
|
/**
|
|
* 导出认证数据
|
|
*/
|
|
public function exportAuth()
|
|
{
|
|
$keyword = I('get.keyword', '', 'trim');
|
|
$authStatus = I('get.auth_status', '', 'trim');
|
|
$healthStatus = I('get.health_status', '', 'trim');
|
|
$startTime = I('get.start_time', '', 'trim');
|
|
$endTime = I('get.end_time', '', 'trim');
|
|
|
|
$where = array();
|
|
|
|
// 构建查询条件(与列表查询相同)
|
|
if (!empty($keyword)) {
|
|
$where['_string'] = "(rider_name LIKE '%{$keyword}%' OR rider_phone LIKE '%{$keyword}%' OR id_card LIKE '%{$keyword}%')";
|
|
}
|
|
|
|
if (!empty($authStatus)) {
|
|
$where['auth_status'] = $authStatus;
|
|
}
|
|
|
|
if (!empty($healthStatus)) {
|
|
$where['health_status'] = $healthStatus;
|
|
}
|
|
|
|
if (!empty($startTime)) {
|
|
$where['add_time'][] = array('egt', $startTime);
|
|
}
|
|
if (!empty($endTime)) {
|
|
$where['add_time'][] = array('elt', $endTime . ' 23:59:59');
|
|
}
|
|
|
|
$where['status'] = 1;
|
|
|
|
// 获取数据
|
|
$list = M('RiderInfo')->field('id, rider_name, rider_phone, id_card,
|
|
auth_status, auth_remark, auth_time,
|
|
health_status, health_remark, health_time,
|
|
add_time')
|
|
->where($where)
|
|
->order('add_time DESC')
|
|
->select();
|
|
|
|
// 设置Excel头部
|
|
header('Content-Type: application/vnd.ms-excel');
|
|
header('Content-Disposition: attachment;filename="rider_auth_' . date('YmdHis') . '.xls"');
|
|
header('Cache-Control: max-age=0');
|
|
|
|
// 输出Excel内容
|
|
echo '<table border="1">';
|
|
echo '<tr>';
|
|
echo '<th>骑手ID</th>';
|
|
echo '<th>昵称</th>';
|
|
echo '<th>手机号</th>';
|
|
echo '<th>真实姓名</th>';
|
|
echo '<th>身份证号</th>';
|
|
echo '<th>实名认证状态</th>';
|
|
echo '<th>实名认证备注</th>';
|
|
echo '<th>实名认证时间</th>';
|
|
echo '<th>健康证状态</th>';
|
|
echo '<th>健康证备注</th>';
|
|
echo '<th>健康证审核时间</th>';
|
|
echo '<th>注册时间</th>';
|
|
echo '</tr>';
|
|
|
|
foreach ($list as $item) {
|
|
echo '<tr>';
|
|
echo '<td>' . $item['id'] . '</td>';
|
|
echo '<td>' . $item['name'] . '</td>';
|
|
echo '<td>' . $item['phone'] . '</td>';
|
|
echo '<td>' . $item['real_name'] . '</td>';
|
|
echo '<td>' . ($item['id_card'] ? substr($item['id_card'], 0, 6) . '********' . substr($item['id_card'], -4) : '') . '</td>';
|
|
echo '<td>' . $this->getAuthStatusText($item['auth_status']) . '</td>';
|
|
echo '<td>' . $item['auth_remark'] . '</td>';
|
|
echo '<td>' . ($item['auth_time'] ? date('Y-m-d H:i:s', $item['auth_time']) : '') . '</td>';
|
|
echo '<td>' . $this->getHealthStatusText($item['health_status']) . '</td>';
|
|
echo '<td>' . $item['health_remark'] . '</td>';
|
|
echo '<td>' . ($item['health_time'] ? date('Y-m-d H:i:s', $item['health_time']) : '') . '</td>';
|
|
echo '<td>' . date('Y-m-d H:i:s', $item['create_time']) . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
echo '</table>';
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* 获取认证统计数据
|
|
*/
|
|
public function getAuthStats()
|
|
{
|
|
$startTime = I('get.start_time', date('Y-m-01'), 'trim');
|
|
$endTime = I('get.end_time', date('Y-m-d'), 'trim');
|
|
|
|
$where = array();
|
|
$where['add_time'][] = array('egt', $startTime);
|
|
$where['add_time'][] = array('elt', $endTime . ' 23:59:59');
|
|
$where['is_deleted'] = 0;
|
|
|
|
$Rider = M('RiderInfo');
|
|
|
|
// 总骑手数
|
|
$totalCount = $Rider->where($where)->count();
|
|
|
|
// 实名认证统计
|
|
$authPendingCount = $Rider->where(array_merge($where, array('auth_status' => 0)))->count();
|
|
$authApprovedCount = $Rider->where(array_merge($where, array('auth_status' => 1)))->count();
|
|
$authRejectedCount = $Rider->where(array_merge($where, array('auth_status' => 2)))->count();
|
|
|
|
// 健康证统计
|
|
$healthPendingCount = $Rider->where(array_merge($where, array('health_status' => 0)))->count();
|
|
$healthApprovedCount = $Rider->where(array_merge($where, array('health_status' => 1)))->count();
|
|
$healthRejectedCount = $Rider->where(array_merge($where, array('health_status' => 2)))->count();
|
|
|
|
$stats = array(
|
|
'total_count' => $totalCount,
|
|
'auth_pending_count' => $authPendingCount,
|
|
'auth_approved_count' => $authApprovedCount,
|
|
'auth_rejected_count' => $authRejectedCount,
|
|
'health_pending_count' => $healthPendingCount,
|
|
'health_approved_count' => $healthApprovedCount,
|
|
'health_rejected_count' => $healthRejectedCount
|
|
);
|
|
|
|
$this->ajaxReturn(array('code' => 0, 'msg' => 'success', 'data' => $stats));
|
|
}
|
|
|
|
/**
|
|
* 获取实名认证状态文本
|
|
*/
|
|
private function getAuthStatusText($status)
|
|
{
|
|
$statusMap = array(
|
|
0 => '待审核',
|
|
1 => '已通过',
|
|
2 => '已拒绝'
|
|
);
|
|
|
|
return isset($statusMap[$status]) ? $statusMap[$status] : '未知';
|
|
}
|
|
|
|
/**
|
|
* 获取健康证状态文本
|
|
*/
|
|
private function getHealthStatusText($status)
|
|
{
|
|
$statusMap = array(
|
|
0 => '待审核',
|
|
1 => '已通过',
|
|
2 => '已拒绝'
|
|
);
|
|
|
|
return isset($statusMap[$status]) ? $statusMap[$status] : '未知';
|
|
}
|
|
}
|