hasMany(OrderDetail::class, 'order_id', 'id'); } /** * @notes 关联患者(从诊单表) * @return \think\model\relation\BelongsTo */ public function patient() { return $this->belongsTo('app\common\model\tcm\Diagnosis', 'patient_id', 'id'); } /** * @notes 关联创建人 * @return \think\model\relation\BelongsTo */ public function creator() { return $this->belongsTo('app\common\model\auth\Admin', 'creator_id', 'id'); } /** * @notes 搜索器-订单号 */ public function searchOrderNoAttr($query, $value, $data) { if ($value) { $query->where('order_no', 'like', '%' . $value . '%'); } } /** * @notes 搜索器-患者关键词 */ public function searchPatientKeywordAttr($query, $value, $data) { if ($value) { $query->whereHas('patient', function ($q) use ($value) { $q->where('patient_name|patient_phone', 'like', '%' . $value . '%'); }); } } /** * @notes 搜索器-订单类型 */ public function searchOrderTypeAttr($query, $value, $data) { if ($value) { $query->where('order_type', '=', $value); } } /** * @notes 搜索器-订单状态 */ public function searchStatusAttr($query, $value, $data) { if ($value) { $query->where('status', '=', $value); } } /** * @notes 搜索器-创建时间开始 */ public function searchCreateTimeStartAttr($query, $value, $data) { if ($value) { $query->where('create_time', '>=', $value . ' 00:00:00'); } } /** * @notes 搜索器-创建时间结束 */ public function searchCreateTimeEndAttr($query, $value, $data) { if ($value) { $query->where('create_time', '<=', $value . ' 23:59:59'); } } /** * @notes 获取器-订单类型描述 */ public function getOrderTypeDescAttr($value, $data) { $typeMap = [1 => '挂号费', 2 => '问诊费', 3 => '药品费用']; return $typeMap[$data['order_type']] ?? '未知'; } /** * @notes 获取器-订单状态描述 */ public function getStatusDescAttr($value, $data) { $statusMap = [1 => '待支付', 2 => '已支付', 3 => '已取消', 4 => '已退款']; return $statusMap[$data['status']] ?? '未知'; } /** * @notes 获取器-患者名称 */ public function getPatientNameAttr($value, $data) { if ($value) { return $value; } try { $patient = $this->patient()->find(); return $patient ? $patient->patient_name : ''; } catch (\Exception $e) { return ''; } } /** * @notes 获取器-患者电话 */ public function getPatientPhoneAttr($value, $data) { if ($value) { return $value; } try { $patient = $this->patient()->find(); return $patient ? $patient->patient_phone : ''; } catch (\Exception $e) { return ''; } } /** * @notes 获取器-创建人名称 */ public function getCreatorNameAttr($value, $data) { if ($value) { return $value; } try { $creator = $this->creator()->find(); return $creator ? $creator->name : ''; } catch (\Exception $e) { return ''; } } }