71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
<?php
|
|
namespace app\api\controller;
|
|
|
|
use support\Request;
|
|
use app\common\model\Report;
|
|
use app\common\model\Order;
|
|
|
|
class ReportController
|
|
{
|
|
// 获取C端自己的报告
|
|
public function detail(Request $request)
|
|
{
|
|
$orderId = (int)$request->get('order_id');
|
|
$userId = $request->user->id;
|
|
|
|
$order = Order::where('id', $orderId)->where('user_id', $userId)->first();
|
|
if (!$order) {
|
|
return jsonResponse(null, '订单不存在', 404);
|
|
}
|
|
|
|
$report = Report::with(['inspector'])->where('order_id', $orderId)->first();
|
|
if (!$report) {
|
|
return jsonResponse(null, '报告尚未出具', 404);
|
|
}
|
|
|
|
return jsonResponse([
|
|
'report_no' => $report->report_no,
|
|
'conclusion' => $report->conclusion,
|
|
'level' => $report->level,
|
|
'flaws' => $report->flaws_json,
|
|
'images' => $report->images_json,
|
|
'verify_code' => $report->verify_code,
|
|
'created_at' => $report->created_at->format('Y-m-d H:i:s'),
|
|
'inspector' => [
|
|
'name' => $report->inspector->nickname ?? $report->inspector->username,
|
|
]
|
|
]);
|
|
}
|
|
|
|
// 公开验证防伪码 (无需登录)
|
|
public function verify(Request $request)
|
|
{
|
|
$code = trim($request->get('code', ''));
|
|
if (!$code) {
|
|
return jsonResponse(null, '防伪码不能为空', 400);
|
|
}
|
|
|
|
$report = Report::with(['order', 'inspector'])->where('verify_code', $code)->first();
|
|
if (!$report) {
|
|
return jsonResponse(null, '无效的防伪码或报告不存在', 404);
|
|
}
|
|
|
|
return jsonResponse([
|
|
'report_no' => $report->report_no,
|
|
'conclusion' => $report->conclusion,
|
|
'level' => $report->level,
|
|
'flaws' => $report->flaws_json,
|
|
'images' => $report->images_json,
|
|
'created_at' => $report->created_at->format('Y-m-d H:i:s'),
|
|
'order' => [
|
|
'category' => $report->order->category,
|
|
'brand' => $report->order->brand,
|
|
'model' => $report->order->model,
|
|
],
|
|
'inspector' => [
|
|
'name' => $report->inspector->nickname ?? $report->inspector->username,
|
|
]
|
|
], '验证成功,该报告真实有效');
|
|
}
|
|
}
|