You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
/**
* Created by PhpStorm.
* User: weizongsong
* Date: 2019-04-12
* Time: 22:34
*/
namespace App\Http\Controllers\Admin;
use App\Forms\AdverseForm;
use App\Models\Adverse;
use Illuminate\Http\Request;
class AdverseController extends CommonController
{
public $bladePath = "admin.adverse";
public $urlPrefix = "admin/adverse";
public $modelName = "不良事件";
public $modelClass = Adverse::class;
public $formClass = AdverseForm::class;
/**
* 列表页面
*/
public function index(Request $request)
{
$query = $this->model->with(['project', 'order', 'solver']);
// 搜索条件
if ($request->filled('keyword')) {
$keyword = $request->keyword;
$query->where(function ($q) use ($keyword) {
$q->where('description', 'like', "%{$keyword}%")
->orWhere('solved_result', 'like', "%{$keyword}%")
->orWhereHas('project', function ($q) use ($keyword) {
$q->where('name', 'like', "%{$keyword}%");
})
->orWhereHas('order', function ($q) use ($keyword) {
$q->where('serial', 'like', "%{$keyword}%");
});
});
}
// 状态筛选
if ($request->filled('status')) {
$query->where('solved_status', $request->status);
}
// 类型筛选
if ($request->filled('type')) {
$query->where('type', $request->type);
}
// 项目筛选
if ($request->filled('project_id')) {
$query->where('project_id', $request->project_id);
}
// 时间范围筛选
if ($request->filled('date_from')) {
$query->where('created_at', '>=', $request->date_from);
}
if ($request->filled('date_to')) {
$query->where('created_at', '<=', $request->date_to . ' 23:59:59');
}
$data = $query->orderBy('created_at', 'desc')->paginate(15);
// 统计数据
$stats = [
'total' => $this->model->count(),
'pending' => $this->model->where('solved_status', Adverse::STATUS_PENDING)->count(),
'processing' => $this->model->where('solved_status', Adverse::STATUS_PROCESSING)->count(),
'solved' => $this->model->where('solved_status', Adverse::STATUS_SOLVED)->count(),
'closed' => $this->model->where('solved_status', Adverse::STATUS_CLOSED)->count(),
];
return view($this->bladePath . ".index", compact("data", "stats"));
}
/**
* 订单搜索接口
* 前端传递参数project_id, keyword
*/
public function orderSearch(\Illuminate\Http\Request $request)
{
$project_id = $request->input('project_id');
$keyword = $request->input('keyword');
if (!$project_id || !$keyword) {
return $this->error("缺少必要参数");
}
$order = \App\Models\Orders::where('project_id', $project_id)
->where(function ($q) use ($keyword) {
$q->where('serial', 'like', "%{$keyword}%")
->orWhere('contact', 'like', "%{$keyword}%")
->orWhere('mobile', 'like', "%{$keyword}%");
})
->first();
if (!$order) {
return $this->error("未找到相关订单");
}
// 返回订单信息
return $this->success("搜索成功", "", $order);
}
}