where("student_id", $value); } } /** * 搜索器:合同管理合同名称 * @param $value * @param $data */ public function searchTitleAttr($query, $value, $data) { if ($value) { $query->where("title", "like", "%".$value."%"); } } /** * 搜索器:合同管理生效日期 * @param $value * @param $data */ public function searchStartDateAttr($query, $value, $data) { $start = empty($value[0]) ? 0 : strtotime($value[0]); $end = empty($value[1]) ? 0 : strtotime($value[1]); if ($start > 0 && $end > 0) { $query->where([["start_date", "between", [$start, $end]]]); } else if ($start > 0 && $end == 0) { $query->where([["start_date", ">=", $start]]); } else if ($start == 0 && $end > 0) { $query->where([["start_date", "<=", $end]]); } } /** * 搜索器:合同管理终止日期 * @param $value * @param $data */ public function searchEndDateAttr($query, $value, $data) { $start = empty($value[0]) ? 0 : strtotime($value[0]); $end = empty($value[1]) ? 0 : strtotime($value[1]); if ($start > 0 && $end > 0) { $query->where([["end_date", "between", [$start, $end]]]); } else if ($start > 0 && $end == 0) { $query->where([["end_date", ">=", $start]]); } else if ($start == 0 && $end > 0) { $query->where([["end_date", "<=", $end]]); } } /** * 搜索器:合同管理状态 * @param $value * @param $data */ public function searchStatusAttr($query, $value, $data) { if ($value) { $query->where("status", $value); } } /** * 搜索器:合同管理添加时间 * @param $value * @param $data */ public function searchCreateTimeAttr($query, $value, $data) { $start = empty($value[0]) ? 0 : strtotime($value[0]); $end = empty($value[1]) ? 0 : strtotime($value[1]); if ($start > 0 && $end > 0) { $query->where([["create_time", "between", [$start, $end]]]); } else if ($start > 0 && $end == 0) { $query->where([["create_time", ">=", $start]]); } else if ($start == 0 && $end > 0) { $query->where([["create_time", "<=", $end]]); } } public function students(){ return $this->hasOne(Students::class, 'id', 'student_id')->joinType('left')->withField('name,id')->bind(['student_id_name'=>'name']); } }