85 lines
3.1 KiB
PHP
85 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\controller\app;
|
|
|
|
use app\support\AppraisalEvidenceService;
|
|
use support\Request;
|
|
use support\think\Db;
|
|
|
|
class VerifyController
|
|
{
|
|
public function show(Request $request)
|
|
{
|
|
$reportNo = trim((string)$request->input('report_no', ''));
|
|
if ($reportNo === '') {
|
|
return api_error('报告编号不能为空', 422);
|
|
}
|
|
|
|
$verify = Db::name('report_verifies')->where('report_no', $reportNo)->find();
|
|
$report = Db::name('reports')
|
|
->where('report_no', $reportNo)
|
|
->where('report_status', 'published')
|
|
->find();
|
|
if (!$verify || !$report) {
|
|
return api_error('报告不存在', 404, [
|
|
'verify_status' => 'not_found',
|
|
]);
|
|
}
|
|
|
|
$now = date('Y-m-d H:i:s');
|
|
Db::name('report_verifies')->where('id', $verify['id'])->update([
|
|
'verify_count' => (int)$verify['verify_count'] + 1,
|
|
'last_verified_at' => $now,
|
|
'updated_at' => $now,
|
|
]);
|
|
Db::name('report_verify_logs')->insert([
|
|
'report_verify_id' => (int)$verify['id'],
|
|
'verify_type' => 'h5',
|
|
'ip' => (string)$request->getRealIp(),
|
|
'user_agent' => (string)$request->header('user-agent', ''),
|
|
'verified_at' => $now,
|
|
'created_at' => $now,
|
|
]);
|
|
|
|
$content = Db::name('report_contents')->where('report_id', $report['id'])->find();
|
|
$productSnapshot = $this->decodeJsonField($content['product_snapshot_json'] ?? null);
|
|
$resultSnapshot = $this->decodeJsonField($content['result_snapshot_json'] ?? null);
|
|
$evidenceAttachments = $this->evidenceService()->normalize($content['evidence_attachments_json'] ?? null, $request);
|
|
|
|
return api_success([
|
|
'verify_status' => $verify['verify_status'],
|
|
'verify_message' => match ($verify['verify_status']) {
|
|
'valid' => '该报告真实有效,可作为对应鉴定结果参考。',
|
|
'updated' => '该报告已更新,请以最新版本为准。',
|
|
'invalid' => '该报告已失效,请勿继续作为有效凭证使用。',
|
|
default => '当前验真状态异常,请稍后重试。',
|
|
},
|
|
'report_summary' => [
|
|
'report_no' => $report['report_no'],
|
|
'report_title' => $report['report_title'],
|
|
'institution_name' => $report['institution_name'],
|
|
'publish_time' => $report['publish_time'],
|
|
],
|
|
'product_summary' => $productSnapshot,
|
|
'result_summary' => $resultSnapshot,
|
|
'evidence_attachments' => $evidenceAttachments,
|
|
]);
|
|
}
|
|
|
|
private function decodeJsonField(mixed $value): array
|
|
{
|
|
if (is_array($value)) {
|
|
return $value;
|
|
}
|
|
if (is_string($value) && $value !== '') {
|
|
return json_decode($value, true) ?: [];
|
|
}
|
|
return [];
|
|
}
|
|
|
|
private function evidenceService(): AppraisalEvidenceService
|
|
{
|
|
return new AppraisalEvidenceService();
|
|
}
|
|
}
|