$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];
/*查询的字段*/
$searchFields = [
'report_identify' => 'like',
'drug_name' => 'like',
'event_term' => 'like',
'organize_role_id' => '=',
'case_causality' => '=',
'report_type' => '=',
'task_user_id' => '=',
'status' => '=',
];
/*获取查询条件*/
$where = $this->searchArray($searchFields);
/*获取数据*/
$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));
$data = $this->reportTaskRepo->findWhere($where, $fields);
//在Trait里封装
/**
* 获取请求中的参数的值
* @param array $fields [description]
* @return [type] [description]
*/
public function searchArray($fields=[])
{
$results = [];
if (is_array($fields)) {
foreach($fields as $field => $operator) {
if(request()->has($field) && $value = $this->checkParam($field, '', false)) {
$results[$field] = [$field, $operator, "%{$value}%"];
}
}
}
return $results;
}