feat: add report review publish flow
This commit is contained in:
@@ -434,8 +434,6 @@ class AppraisalTasksController
|
||||
Db::rollback();
|
||||
return api_error('请先提交鉴定结论生成报告草稿', 422);
|
||||
}
|
||||
$publish = $this->publishReportRecord($report, $request, false);
|
||||
(new FulfillmentFlowService())->markReportPublished((int)$task['order_id'], $request);
|
||||
Db::commit();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
Db::rollback();
|
||||
@@ -445,14 +443,20 @@ class AppraisalTasksController
|
||||
return api_error($e->getMessage(), $e->getCode() ?: 404);
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return api_error('验真吊牌绑定或报告发布失败', 500, ['detail' => $e->getMessage()]);
|
||||
return api_error('验真吊牌绑定失败', 500, ['detail' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
return api_success([
|
||||
'id' => $id,
|
||||
'material_tag' => $tag,
|
||||
'report' => $publish,
|
||||
], '验真吊牌已绑定,报告已发布');
|
||||
'report' => [
|
||||
'id' => (int)$report['id'],
|
||||
'report_status' => (string)$report['report_status'],
|
||||
'publish_time' => (string)($report['publish_time'] ?? ''),
|
||||
'verify_url' => '',
|
||||
'report_page_url' => '',
|
||||
],
|
||||
], '验真吊牌已绑定,报告待管理员发布');
|
||||
}
|
||||
|
||||
public function saveZhongjianReport(Request $request)
|
||||
@@ -571,8 +575,8 @@ class AppraisalTasksController
|
||||
}
|
||||
$this->saveTaskKeyPoints($savedResultId, $keyPoints, $now);
|
||||
|
||||
$this->createOrUpdateReportDraft((int)$task['order_id'], $task, $resultPayload, $now);
|
||||
$report = $this->findLatestAppraisalReport((int)$task['order_id']);
|
||||
$draftChange = $this->createOrUpdateReportDraft((int)$task['order_id'], $task, $resultPayload, $now);
|
||||
$report = $draftChange['report'];
|
||||
if (!$report) {
|
||||
Db::rollback();
|
||||
return api_error('中检报告草稿生成失败', 500);
|
||||
@@ -612,16 +616,22 @@ class AppraisalTasksController
|
||||
}
|
||||
|
||||
$tag = (new MaterialTagService())->bindTagToReportByTask($id, $qrInput, $request);
|
||||
$publish = $this->publishReportRecord($freshReport, $request, false);
|
||||
(new FulfillmentFlowService())->markReportPublished((int)$task['order_id'], $request);
|
||||
$this->insertReportLog((int)$freshReport['id'], $draftChange['action'], $draftChange['before'], $freshReport, $request, '报告已提交,待管理员发布');
|
||||
$this->insertReportLog((int)$freshReport['id'], 'submit', $draftChange['before'], $freshReport, $request, '鉴定师提交报告');
|
||||
|
||||
Db::commit();
|
||||
|
||||
return api_success([
|
||||
'id' => $id,
|
||||
'material_tag' => $tag,
|
||||
'report' => $publish,
|
||||
], '验真吊牌已绑定,报告已发布');
|
||||
'report' => [
|
||||
'id' => (int)$freshReport['id'],
|
||||
'report_status' => (string)$freshReport['report_status'],
|
||||
'publish_time' => (string)($freshReport['publish_time'] ?? ''),
|
||||
'verify_url' => '',
|
||||
'report_page_url' => '',
|
||||
],
|
||||
], '报告已提交,待管理员发布');
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return api_error('中检报告录入失败', 500, ['detail' => $e->getMessage()]);
|
||||
@@ -820,15 +830,16 @@ class AppraisalTasksController
|
||||
'created_at' => $now,
|
||||
]);
|
||||
|
||||
$this->createOrUpdateReportDraft((int)$task['order_id'], $task, $payload, $now);
|
||||
$report = $this->findLatestAppraisalReport((int)$task['order_id']);
|
||||
$draftChange = $this->createOrUpdateReportDraft((int)$task['order_id'], $task, $payload, $now);
|
||||
$report = $draftChange['report'];
|
||||
if (!$report) {
|
||||
Db::rollback();
|
||||
return api_error('报告草稿生成失败', 500);
|
||||
}
|
||||
$tag = (new MaterialTagService())->bindTagToReportByTask($id, $qrInput, $request);
|
||||
$publish = $this->publishReportRecord($report, $request, false);
|
||||
(new FulfillmentFlowService())->markReportPublished((int)$task['order_id'], $request);
|
||||
$freshReport = $this->findLatestAppraisalReport((int)$task['order_id']) ?: $report;
|
||||
$this->insertReportLog((int)$freshReport['id'], $draftChange['action'], $draftChange['before'], $freshReport, $request, '报告已提交,待管理员发布');
|
||||
$this->insertReportLog((int)$freshReport['id'], 'submit', $draftChange['before'], $freshReport, $request, '鉴定师提交报告');
|
||||
|
||||
Db::commit();
|
||||
(new EnterpriseWebhookService())->recordOrderEvent((int)$task['order_id'], 'appraisal_finished', [
|
||||
@@ -839,8 +850,14 @@ class AppraisalTasksController
|
||||
return api_success([
|
||||
'id' => $id,
|
||||
'material_tag' => $tag,
|
||||
'report' => $publish,
|
||||
], '验真吊牌已绑定,报告已发布');
|
||||
'report' => [
|
||||
'id' => (int)$freshReport['id'],
|
||||
'report_status' => (string)$freshReport['report_status'],
|
||||
'publish_time' => (string)($freshReport['publish_time'] ?? ''),
|
||||
'verify_url' => '',
|
||||
'report_page_url' => '',
|
||||
],
|
||||
], '报告已提交,待管理员发布');
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return api_error('结论保存失败', 500, [
|
||||
@@ -1467,6 +1484,15 @@ class AppraisalTasksController
|
||||
$stage = (string)($task['task_stage'] ?? '');
|
||||
$submittedAt = (string)($task['submitted_at'] ?? '');
|
||||
$orderStatus = (string)($task['order_status'] ?? '');
|
||||
$reportStatus = $report ? (string)($report['report_status'] ?? '') : '';
|
||||
|
||||
if ($reportStatus === 'published') {
|
||||
return 'completed';
|
||||
}
|
||||
|
||||
if (in_array($reportStatus, ['draft', 'pending_publish', 'updated', 'rejected'], true)) {
|
||||
return 'processing';
|
||||
}
|
||||
|
||||
if (
|
||||
$submittedAt !== ''
|
||||
@@ -1504,6 +1530,7 @@ class AppraisalTasksController
|
||||
'draft' => '草稿中',
|
||||
'pending_publish' => '待发布',
|
||||
'published' => '已发布',
|
||||
'rejected' => '已驳回',
|
||||
'updated' => '已更新',
|
||||
'invalid' => '已作废',
|
||||
default => $status,
|
||||
@@ -1804,7 +1831,7 @@ class AppraisalTasksController
|
||||
return (string)Db::name($table)->where('id', $id)->value($field);
|
||||
}
|
||||
|
||||
private function createOrUpdateReportDraft(int $orderId, array $task, array $resultPayload, string $now): void
|
||||
private function createOrUpdateReportDraft(int $orderId, array $task, array $resultPayload, string $now): array
|
||||
{
|
||||
$report = Db::name('reports')->where('order_id', $orderId)->order('id', 'desc')->find();
|
||||
$order = Db::name('orders')->where('id', $orderId)->find();
|
||||
@@ -1842,17 +1869,27 @@ class AppraisalTasksController
|
||||
'report_title' => $task['service_provider'] === 'zhongjian' ? '中检鉴定报告' : '安心验鉴定报告',
|
||||
'report_status' => 'pending_publish',
|
||||
'publish_time' => null,
|
||||
'invalid_reason' => '',
|
||||
'reject_reason' => '',
|
||||
'rejected_by' => null,
|
||||
'rejected_by_name' => '',
|
||||
'rejected_at' => null,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
|
||||
if ($report) {
|
||||
$beforeReport = $report;
|
||||
$reportData['report_version'] = (int)($report['report_version'] ?? 1) + 1;
|
||||
Db::name('reports')->where('id', $report['id'])->update($reportData);
|
||||
$reportId = (int)$report['id'];
|
||||
$logAction = 'update_draft';
|
||||
} else {
|
||||
$reportData['report_no'] = 'AXY-R-' . date('Ymd') . '-' . mt_rand(1000, 9999);
|
||||
$reportData['report_version'] = 1;
|
||||
$reportData['created_at'] = $now;
|
||||
$reportId = (int)Db::name('reports')->insertGetId($reportData);
|
||||
$beforeReport = [];
|
||||
$logAction = 'create_draft';
|
||||
}
|
||||
|
||||
$contentPayload = [
|
||||
@@ -1892,6 +1929,12 @@ class AppraisalTasksController
|
||||
$contentPayload['created_at'] = $now;
|
||||
Db::name('report_contents')->insert($contentPayload);
|
||||
}
|
||||
|
||||
return [
|
||||
'report' => Db::name('reports')->where('id', $reportId)->find() ?: [],
|
||||
'before' => $beforeReport,
|
||||
'action' => $logAction,
|
||||
];
|
||||
}
|
||||
|
||||
private function buildAppraisalSnapshot(string $serviceProvider, string $fallbackTime, ?array $firstReviewTask, ?array $finalReviewTask): array
|
||||
@@ -1915,6 +1958,41 @@ class AppraisalTasksController
|
||||
];
|
||||
}
|
||||
|
||||
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 normalizeAssigneeName(?string $value): string
|
||||
{
|
||||
$name = trim((string)$value);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -34,6 +34,7 @@ class ReportsController
|
||||
])
|
||||
->where('o.user_id', $userId)
|
||||
->whereIn('o.order_status', ['in_first_review', 'in_final_review', 'generating_report', 'report_published', 'completed'])
|
||||
->whereRaw('r.id IS NOT NULL')
|
||||
->order('o.id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@@ -194,7 +194,14 @@ class TicketsController
|
||||
$bizType = 'order';
|
||||
$bizId = $orderId;
|
||||
} elseif ($reportId > 0) {
|
||||
$report = Db::name('reports')->where('id', $reportId)->find();
|
||||
$report = Db::name('reports')
|
||||
->alias('r')
|
||||
->join('orders o', 'o.id = r.order_id')
|
||||
->where('r.id', $reportId)
|
||||
->where('r.report_status', 'published')
|
||||
->where('o.user_id', $userId)
|
||||
->field('r.id')
|
||||
->find();
|
||||
if (!$report) {
|
||||
return api_error('关联报告不存在', 404);
|
||||
}
|
||||
|
||||
@@ -179,7 +179,11 @@ class EnterpriseOrderService
|
||||
$timeline = Db::name('order_timelines')->where('order_id', (int)$order['id'])->order('occurred_at', 'asc')->select()->toArray();
|
||||
$sendLogistics = Db::name('order_logistics')->where('order_id', (int)$order['id'])->where('logistics_type', 'send_to_center')->order('id', 'desc')->find();
|
||||
$returnLogistics = Db::name('order_logistics')->where('order_id', (int)$order['id'])->where('logistics_type', 'return_to_user')->order('id', 'desc')->find();
|
||||
$report = Db::name('reports')->where('order_id', (int)$order['id'])->order('id', 'desc')->find();
|
||||
$report = Db::name('reports')
|
||||
->where('order_id', (int)$order['id'])
|
||||
->where('report_status', 'published')
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
$verify = $report ? (Db::name('report_verifies')->where('report_id', (int)$report['id'])->find() ?: null) : null;
|
||||
|
||||
return [
|
||||
|
||||
@@ -269,7 +269,7 @@ class FulfillmentFlowService
|
||||
$context = $this->formatOrderContext((int)$flow['order_id'], $request);
|
||||
$report = $context['report_info'] ?? null;
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published') {
|
||||
throw new \InvalidArgumentException('订单报告未发布,不能进入寄回流程');
|
||||
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
|
||||
}
|
||||
|
||||
return $context + [
|
||||
@@ -289,7 +289,7 @@ class FulfillmentFlowService
|
||||
}
|
||||
$report = $this->latestReport((int)$flow['order_id']);
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published') {
|
||||
throw new \InvalidArgumentException('订单报告未发布,不能确认寄回');
|
||||
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
|
||||
}
|
||||
|
||||
$tag = (new MaterialTagService())->findTagByInput($qrInput);
|
||||
@@ -320,7 +320,10 @@ class FulfillmentFlowService
|
||||
$report = $this->latestReport((int)$flow['order_id']);
|
||||
$content = $report ? Db::name('report_contents')->where('report_id', (int)$report['id'])->find() : null;
|
||||
$files = $this->decodeJsonArray($content['zhongjian_report_files_json'] ?? null);
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published' || trim((string)($report['zhongjian_report_no'] ?? '')) === '' || !$files) {
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published') {
|
||||
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
|
||||
}
|
||||
if (trim((string)($report['zhongjian_report_no'] ?? '')) === '' || !$files) {
|
||||
throw new \InvalidArgumentException('中检报告未完整录入,不能确认寄回');
|
||||
}
|
||||
|
||||
@@ -337,7 +340,7 @@ class FulfillmentFlowService
|
||||
|
||||
$report = $this->latestReport((int)$flow['order_id']);
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published') {
|
||||
throw new \InvalidArgumentException('订单报告未发布,不能确认寄回');
|
||||
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
|
||||
}
|
||||
if ((int)$report['id'] !== $reportId) {
|
||||
throw new \InvalidArgumentException('确认的报告与当前订单报告不匹配');
|
||||
@@ -371,6 +374,10 @@ class FulfillmentFlowService
|
||||
if (!$flow) {
|
||||
throw new \RuntimeException('未找到可用的内部流转挂牌', 404);
|
||||
}
|
||||
$report = $this->latestReport((int)$flow['order_id']);
|
||||
if (!$report || ($report['report_status'] ?? '') !== 'published') {
|
||||
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
|
||||
}
|
||||
if ((string)($flow['current_stage'] ?? '') !== 'return_confirmed') {
|
||||
throw new \InvalidArgumentException('请先完成报告确认,再登记回寄运单');
|
||||
}
|
||||
|
||||
@@ -344,10 +344,6 @@ class MaterialTagService
|
||||
if ($batch && ($batch['status'] ?? 'active') === 'invalid') {
|
||||
throw new \InvalidArgumentException('该吊牌所属批次已失效,不能绑定报告');
|
||||
}
|
||||
if (($tag['bind_status'] ?? '') === 'bound' || (int)($tag['report_id'] ?? 0) > 0) {
|
||||
throw new \InvalidArgumentException('该吊牌已绑定报告,不能重复绑定');
|
||||
}
|
||||
|
||||
$task = Db::name('appraisal_tasks')->where('id', $taskId)->find();
|
||||
if (!$task) {
|
||||
throw new \RuntimeException('任务不存在', 404);
|
||||
@@ -364,6 +360,21 @@ class MaterialTagService
|
||||
throw new \InvalidArgumentException('报告已发布,不能再绑定或更换吊牌');
|
||||
}
|
||||
|
||||
if (($tag['bind_status'] ?? '') === 'bound' || (int)($tag['report_id'] ?? 0) > 0) {
|
||||
if (
|
||||
(int)($tag['report_id'] ?? 0) === (int)$report['id']
|
||||
&& in_array((string)($report['report_status'] ?? ''), ['draft', 'pending_publish', 'updated', 'rejected'], true)
|
||||
) {
|
||||
return $this->formatTagCode($tag, [
|
||||
'id' => (int)$report['id'],
|
||||
'report_no' => (string)$report['report_no'],
|
||||
'report_status' => (string)$report['report_status'],
|
||||
]);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('该吊牌已绑定报告,不能重复绑定');
|
||||
}
|
||||
|
||||
$existing = Db::name('material_tag_codes')->where('report_id', (int)$report['id'])->find();
|
||||
if ($existing) {
|
||||
throw new \InvalidArgumentException('当前报告已绑定吊牌,不能重复绑定');
|
||||
@@ -530,18 +541,13 @@ class MaterialTagService
|
||||
if (($report['report_status'] ?? '') !== 'published') {
|
||||
return [
|
||||
'tag_status' => 'pending_report',
|
||||
'status_text' => '报告生成中',
|
||||
'status_text' => '报告未发布',
|
||||
'message' => '该吊牌已关联报告,正式报告发布后可查看完整内容。',
|
||||
'qr_token' => (string)$tag['qr_token'],
|
||||
'qr_url' => (string)$tag['qr_url'],
|
||||
'scan_count' => (int)$tag['scan_count'],
|
||||
'verify_count' => (int)$tag['verify_count'],
|
||||
'report_summary' => [
|
||||
'report_no' => (string)$report['report_no'],
|
||||
'report_title' => (string)$report['report_title'],
|
||||
'institution_name' => (string)$report['institution_name'],
|
||||
'publish_time' => (string)($report['publish_time'] ?? ''),
|
||||
],
|
||||
'report_summary' => null,
|
||||
'product_summary' => [],
|
||||
'result_summary' => [],
|
||||
'verify_passed' => false,
|
||||
|
||||
@@ -249,6 +249,7 @@ Route::get('/api/admin/report/detail', [AdminReportsController::class, 'detail']
|
||||
Route::post('/api/admin/report/trace-visibility', [AdminReportsController::class, 'updateTraceVisibility']);
|
||||
Route::post('/api/admin/report/inspection/save', [AdminReportsController::class, 'saveInspection']);
|
||||
Route::post('/api/admin/report/publish', [AdminReportsController::class, 'publish']);
|
||||
Route::post('/api/admin/report/reject', [AdminReportsController::class, 'reject']);
|
||||
Route::get('/api/admin/appraisal-tasks', [AdminAppraisalTasksController::class, 'index']);
|
||||
Route::get('/api/admin/appraisal-task/detail', [AdminAppraisalTasksController::class, 'detail']);
|
||||
Route::get('/api/admin/appraisal-task/assignable-admins', [AdminAppraisalTasksController::class, 'assignableAdmins']);
|
||||
|
||||
@@ -1067,6 +1067,10 @@ CREATE TABLE reports (
|
||||
report_entered_at DATETIME NULL DEFAULT NULL,
|
||||
trace_info_visible TINYINT(1) NOT NULL DEFAULT 0,
|
||||
invalid_reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
reject_reason VARCHAR(500) NOT NULL DEFAULT '',
|
||||
rejected_by BIGINT UNSIGNED NULL DEFAULT NULL,
|
||||
rejected_by_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
rejected_at DATETIME NULL DEFAULT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
|
||||
67
server-api/tools/schema_upgrade_report_review_flow.php
Normal file
67
server-api/tools/schema_upgrade_report_review_flow.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__));
|
||||
$dotenv->safeLoad();
|
||||
|
||||
$dsn = sprintf(
|
||||
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
|
||||
$_ENV['DB_HOST'] ?? '127.0.0.1',
|
||||
$_ENV['DB_PORT'] ?? '3306',
|
||||
$_ENV['DB_DATABASE'] ?? '',
|
||||
$_ENV['DB_CHARSET'] ?? 'utf8mb4'
|
||||
);
|
||||
|
||||
$pdo = new PDO(
|
||||
$dsn,
|
||||
$_ENV['DB_USERNAME'] ?? '',
|
||||
$_ENV['DB_PASSWORD'] ?? '',
|
||||
[
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]
|
||||
);
|
||||
|
||||
function reportReviewHasColumn(PDO $pdo, string $table, string $column): bool
|
||||
{
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
|
||||
$stmt->execute([$table, $column]);
|
||||
return (int)$stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
$reportColumns = [
|
||||
'reject_reason' => "ALTER TABLE reports ADD COLUMN reject_reason VARCHAR(500) NOT NULL DEFAULT '' AFTER invalid_reason",
|
||||
'rejected_by' => 'ALTER TABLE reports ADD COLUMN rejected_by BIGINT UNSIGNED NULL DEFAULT NULL AFTER reject_reason',
|
||||
'rejected_by_name' => "ALTER TABLE reports ADD COLUMN rejected_by_name VARCHAR(64) NOT NULL DEFAULT '' AFTER rejected_by",
|
||||
'rejected_at' => 'ALTER TABLE reports ADD COLUMN rejected_at DATETIME NULL DEFAULT NULL AFTER rejected_by_name',
|
||||
];
|
||||
|
||||
foreach ($reportColumns as $column => $sql) {
|
||||
if (!reportReviewHasColumn($pdo, 'reports', $column)) {
|
||||
$pdo->exec($sql);
|
||||
echo "ADD_COLUMN reports.{$column}\n";
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->exec("UPDATE reports SET reject_reason = invalid_reason WHERE report_status = 'rejected' AND reject_reason = '' AND invalid_reason <> ''");
|
||||
|
||||
$pdo->exec(<<<'SQL'
|
||||
CREATE TABLE IF NOT EXISTS report_logs (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
report_id BIGINT UNSIGNED NOT NULL,
|
||||
action VARCHAR(64) NOT NULL,
|
||||
operator_id BIGINT UNSIGNED NULL DEFAULT NULL,
|
||||
operator_name VARCHAR(64) NOT NULL DEFAULT '',
|
||||
before_data JSON NULL,
|
||||
after_data JSON NULL,
|
||||
remark VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_report_logs_report_id (report_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='报告操作日志'
|
||||
SQL);
|
||||
|
||||
echo "SCHEMA_UPGRADE_REPORT_REVIEW_FLOW_OK\n";
|
||||
Reference in New Issue
Block a user