feat: add report review publish flow
This commit is contained in:
@@ -42,6 +42,10 @@ class ReportsController
|
||||
'r.report_entry_admin_name',
|
||||
'r.report_entered_at',
|
||||
'r.trace_info_visible',
|
||||
'r.invalid_reason',
|
||||
'r.reject_reason',
|
||||
'r.rejected_by_name',
|
||||
'r.rejected_at',
|
||||
'o.order_no',
|
||||
'p.product_name',
|
||||
'p.category_name',
|
||||
@@ -85,6 +89,9 @@ class ReportsController
|
||||
'report_entry_admin_name' => (string)($item['report_entry_admin_name'] ?? ''),
|
||||
'report_entered_at' => (string)($item['report_entered_at'] ?? ''),
|
||||
'trace_info_visible' => (int)($item['trace_info_visible'] ?? 0) === 1,
|
||||
'reject_reason' => (string)($item['reject_reason'] ?? $item['invalid_reason'] ?? ''),
|
||||
'rejected_by_name' => (string)($item['rejected_by_name'] ?? ''),
|
||||
'rejected_at' => (string)($item['rejected_at'] ?? ''),
|
||||
'product_name' => $item['product_name'] ?: (string)($productSnapshot['product_name'] ?? ''),
|
||||
'category_name' => $item['category_name'] ?: (string)($productSnapshot['category_name'] ?? ''),
|
||||
'brand_name' => $item['brand_name'] ?: (string)($productSnapshot['brand_name'] ?? ''),
|
||||
@@ -137,6 +144,7 @@ class ReportsController
|
||||
$appraisalSnapshot = $this->enrichAppraisalSnapshot($report, $appraisalSnapshot);
|
||||
$evidenceAttachments = $this->evidenceService()->normalize($content['evidence_attachments_json'] ?? null, $request);
|
||||
$materialTag = (new MaterialTagService())->findBoundTagForReport($id);
|
||||
$logs = $this->reportLogs($id);
|
||||
|
||||
$verify = Db::name('report_verifies')->where('report_id', $id)->find() ?: [];
|
||||
if (($report['report_status'] ?? '') === 'published') {
|
||||
@@ -172,6 +180,9 @@ class ReportsController
|
||||
'report_entry_admin_name' => (string)($report['report_entry_admin_name'] ?? ''),
|
||||
'report_entered_at' => (string)($report['report_entered_at'] ?? ''),
|
||||
'trace_info_visible' => (int)($report['trace_info_visible'] ?? 0) === 1,
|
||||
'reject_reason' => (string)($report['reject_reason'] ?? $report['invalid_reason'] ?? ''),
|
||||
'rejected_by_name' => (string)($report['rejected_by_name'] ?? ''),
|
||||
'rejected_at' => (string)($report['rejected_at'] ?? ''),
|
||||
],
|
||||
'product_info' => $productSnapshot,
|
||||
'result_info' => $resultSnapshot,
|
||||
@@ -188,6 +199,8 @@ class ReportsController
|
||||
'report_page_url' => $verify['report_page_url'] ?? $reportPageUrl,
|
||||
'verify_count' => (int)($verify['verify_count'] ?? 0),
|
||||
],
|
||||
'audit_logs' => array_values(array_filter($logs, fn(array $log) => in_array($log['action'], ['publish', 'reject'], true))),
|
||||
'change_logs' => array_values(array_filter($logs, fn(array $log) => !in_array($log['action'], ['publish', 'reject'], true))),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -412,6 +425,7 @@ class ReportsController
|
||||
Db::rollback();
|
||||
return api_error('报告不存在', 404);
|
||||
}
|
||||
$beforeReport = $report;
|
||||
|
||||
if (!in_array($report['report_status'], ['draft', 'pending_publish', 'updated', 'published'], true)) {
|
||||
Db::rollback();
|
||||
@@ -446,10 +460,18 @@ class ReportsController
|
||||
Db::name('reports')->where('id', $id)->update([
|
||||
'report_status' => 'published',
|
||||
'publish_time' => $effectivePublishTime,
|
||||
'invalid_reason' => '',
|
||||
'reject_reason' => '',
|
||||
'rejected_by' => null,
|
||||
'rejected_by_name' => '',
|
||||
'rejected_at' => null,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
$report['report_status'] = 'published';
|
||||
$report['publish_time'] = $effectivePublishTime;
|
||||
$report = Db::name('reports')->where('id', $id)->find() ?: array_merge($report, [
|
||||
'report_status' => 'published',
|
||||
'publish_time' => $effectivePublishTime,
|
||||
]);
|
||||
$this->insertReportLog($id, 'publish', $beforeReport, $report, $request, '管理员审核通过并发布报告');
|
||||
}
|
||||
|
||||
if ($isOrderAppraisalReport) {
|
||||
@@ -532,18 +554,177 @@ class ReportsController
|
||||
}
|
||||
}
|
||||
|
||||
public function reject(Request $request)
|
||||
{
|
||||
$id = (int)$request->input('id', 0);
|
||||
$reason = trim((string)$request->input('reason', ''));
|
||||
if (!$id) {
|
||||
return api_error('报告 ID 不能为空', 422);
|
||||
}
|
||||
if ($reason === '') {
|
||||
return api_error('驳回原因不能为空', 422);
|
||||
}
|
||||
|
||||
$now = date('Y-m-d H:i:s');
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$report = Db::name('reports')->where('id', $id)->find();
|
||||
if (!$report) {
|
||||
Db::rollback();
|
||||
return api_error('报告不存在', 404);
|
||||
}
|
||||
if (($report['report_status'] ?? '') !== 'pending_publish') {
|
||||
Db::rollback();
|
||||
return api_error('仅待发布报告可以驳回', 422);
|
||||
}
|
||||
if (($report['report_type'] ?? 'appraisal') !== 'appraisal' || (int)($report['order_id'] ?? 0) <= 0) {
|
||||
Db::rollback();
|
||||
return api_error('仅订单鉴定报告可以驳回复鉴', 422);
|
||||
}
|
||||
|
||||
$beforeReport = $report;
|
||||
Db::name('reports')->where('id', $id)->update([
|
||||
'report_status' => 'rejected',
|
||||
'publish_time' => null,
|
||||
'invalid_reason' => mb_substr($reason, 0, 255),
|
||||
'reject_reason' => mb_substr($reason, 0, 500),
|
||||
'rejected_by' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'rejected_by_name' => trim((string)$request->header('x-admin-name', '')),
|
||||
'rejected_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
$task = Db::name('appraisal_tasks')
|
||||
->where('order_id', (int)$report['order_id'])
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
if ($task) {
|
||||
Db::name('appraisal_tasks')->where('id', (int)$task['id'])->update([
|
||||
'status' => 'processing',
|
||||
'submitted_at' => null,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
Db::name('orders')->where('id', (int)$report['order_id'])->update([
|
||||
'order_status' => (($task['task_stage'] ?? '') === 'final_review') ? 'in_final_review' : 'in_first_review',
|
||||
'display_status' => '报告已驳回,待重新鉴定',
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
Db::name('order_timelines')->insert([
|
||||
'order_id' => (int)$report['order_id'],
|
||||
'node_code' => 'report_rejected',
|
||||
'node_text' => '报告已驳回',
|
||||
'node_desc' => mb_substr($reason, 0, 255),
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'occurred_at' => $now,
|
||||
'created_at' => $now,
|
||||
]);
|
||||
|
||||
$freshReport = Db::name('reports')->where('id', $id)->find() ?: [];
|
||||
$this->insertReportLog($id, 'reject', $beforeReport, $freshReport, $request, $reason);
|
||||
|
||||
Db::commit();
|
||||
|
||||
return api_success([
|
||||
'id' => $id,
|
||||
'report_status' => 'rejected',
|
||||
'reject_reason' => mb_substr($reason, 0, 255),
|
||||
], '报告已驳回');
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return api_error('报告驳回失败', 500, [
|
||||
'detail' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function reportStatusText(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
'draft' => '草稿中',
|
||||
'pending_publish' => '待发布',
|
||||
'published' => '已发布',
|
||||
'rejected' => '已驳回',
|
||||
'updated' => '已更新',
|
||||
'invalid' => '已作废',
|
||||
default => $status,
|
||||
};
|
||||
}
|
||||
|
||||
private function reportLogs(int $reportId): array
|
||||
{
|
||||
$rows = Db::name('report_logs')
|
||||
->where('report_id', $reportId)
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return array_map(function (array $row) {
|
||||
return [
|
||||
'id' => (int)$row['id'],
|
||||
'action' => (string)$row['action'],
|
||||
'action_text' => $this->reportLogActionText((string)$row['action']),
|
||||
'operator_id' => (int)($row['operator_id'] ?? 0),
|
||||
'operator_name' => (string)($row['operator_name'] ?? ''),
|
||||
'before_data' => $this->decodeJsonField($row['before_data'] ?? null),
|
||||
'after_data' => $this->decodeJsonField($row['after_data'] ?? null),
|
||||
'remark' => (string)($row['remark'] ?? ''),
|
||||
'created_at' => (string)($row['created_at'] ?? ''),
|
||||
];
|
||||
}, $rows);
|
||||
}
|
||||
|
||||
private function reportLogActionText(string $action): string
|
||||
{
|
||||
return match ($action) {
|
||||
'submit' => '提交报告',
|
||||
'create_draft' => '生成待发布报告',
|
||||
'update_draft' => '更新待发布报告',
|
||||
'publish' => '发布报告',
|
||||
'reject' => '驳回报告',
|
||||
default => $action,
|
||||
};
|
||||
}
|
||||
|
||||
private function insertReportLog(int $reportId, string $action, array $before, array $after, Request $request, string $remark = ''): void
|
||||
{
|
||||
if ($reportId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Db::name('report_logs')->insert([
|
||||
'report_id' => $reportId,
|
||||
'action' => $action,
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'operator_name' => trim((string)$request->header('x-admin-name', '')),
|
||||
'before_data' => $before ? json_encode($this->reportLogSnapshot($before), JSON_UNESCAPED_UNICODE) : null,
|
||||
'after_data' => $after ? json_encode($this->reportLogSnapshot($after), JSON_UNESCAPED_UNICODE) : null,
|
||||
'remark' => mb_substr($remark, 0, 255),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
}
|
||||
|
||||
private function reportLogSnapshot(array $report): array
|
||||
{
|
||||
return [
|
||||
'id' => (int)($report['id'] ?? 0),
|
||||
'report_no' => (string)($report['report_no'] ?? ''),
|
||||
'order_id' => (int)($report['order_id'] ?? 0),
|
||||
'report_status' => (string)($report['report_status'] ?? ''),
|
||||
'report_version' => (int)($report['report_version'] ?? 0),
|
||||
'publish_time' => (string)($report['publish_time'] ?? ''),
|
||||
'zhongjian_report_no' => (string)($report['zhongjian_report_no'] ?? ''),
|
||||
'invalid_reason' => (string)($report['invalid_reason'] ?? ''),
|
||||
'reject_reason' => (string)($report['reject_reason'] ?? ''),
|
||||
'rejected_by_name' => (string)($report['rejected_by_name'] ?? ''),
|
||||
'rejected_at' => (string)($report['rejected_at'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
private function reportTypeText(string $reportType): string
|
||||
{
|
||||
return match ($reportType) {
|
||||
|
||||
Reference in New Issue
Block a user