'timestamp', 'updated_at' => 'timestamp', 'process_start_time' => 'datetime', 'process_end_time' => 'datetime' ]; /** * 关联合同表 */ public function contract(): HasOne { return $this->hasOne(Contract::class, 'id', 'template_id'); } /** * 搜索器:状态 */ public function searchStatusAttr($query, $value, $data) { if ($value) { $query->where("status", $value); } } /** * 搜索器:用户类型 */ public function searchUserTypeAttr($query, $value, $data) { if ($value) { $query->where("user_type", $value); } } /** * 搜索器:模板ID * @param $query * @param $value * @param $data */ public function searchTemplateIdAttr($query, $value, $data) { if ($value) { $query->where("template_id", $value); } } /** * 搜索器:用户ID * @param $query * @param $value * @param $data */ public function searchUserIdAttr($query, $value, $data) { if ($value) { $query->where("user_id", $value); } } /** * 搜索器:创建时间 * @param $query * @param $value * @param $data */ public function searchCreatedAtAttr($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([["created_at", "between", [$start, $end]]]); } else if ($start > 0 && $end == 0) { $query->where([["created_at", ">=", $start]]); } else if ($start == 0 && $end > 0) { $query->where([["created_at", "<=", $end]]); } } /** * 状态获取器 * @param $value * @return string */ public function getStatusTextAttr($value) { $statusMap = [ 'pending' => '等待中', 'processing' => '处理中', 'completed' => '已完成', 'failed' => '失败' ]; return $statusMap[$this->getAttr('status')] ?? '未知'; } /** * 用户类型获取器 * @param $value * @return string */ public function getUserTypeTextAttr($value) { $typeMap = [ 'admin' => '管理员', 'staff' => '员工', 'member' => '会员' ]; return $typeMap[$this->getAttr('user_type')] ?? '未知'; } }