TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } /** * 科室 */ public function getTags() { return $this->hasMany(DoctorTagIll::class, ['id' => 'ti_id']) ->viaTable(UserPatientIll::tableName(), ['up_id' => 'id']); } public function getHealth() { return $this->hasMany(UserPatientHealthInquiry::class, ['user_patient_id' => 'up_id']); } public static function inventory($params) { $su_id=\Yii::$app->user->id; //统计时间范围 if(!empty($params['min']) && !empty($params['max'])){ $ti = strtotime($params['max'])+3600*24; }else{ $date_max = date('Y-m-d'); $date_min = date('Y-m-d',strtotime("-31 day")); } //查询数据 $where = ''; $list=DoctorPatient::find()->where([ 'su_id'=>$su_id ])->with(['health'])->asArray()->all(); //把结果按照显示顺序存到返回的数组中 if(!empty($list)){ foreach ($list as $key => $value){ $inventory[$key]['name']= $value['name']; $inventory[$key]['id_card'] = $value['id_card']; $inventory[$key]['sex'] = $value['sex']; $inventory[$key]['mobile'] = $value['mobile']; $inventory[$key]['liver_function'] = $value['health'][0]['liver_function']; $inventory[$key]['liver_index'] = $value['health'][0]['liver_index']; $inventory[$key]['renal_function'] = $value['health'][0]['renal_function']; $inventory[$key]['renal_index'] = $value['health'][0]['renal_index']; $inventory[$key]['person_status'] = $value['health'][0]['person_status']; $inventory[$key]['person_history'] = $value['health'][0]['person_history']; $inventory[$key]['allergic_status'] = $value['health'][0]['allergic_status']; $inventory[$key]['allergic_history'] = $value['health'][0]['allergic_history']; $inventory[$key]['family_status'] = $value['health'][0]['family_status']; $inventory[$key]['family_history'] = $value['health'][0]['family_history']; } }else{ $inventory[0]['patient']= '无数据导出'; } return $inventory; } }