TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], ], ], ]; } public function afterFind() { parent::afterFind(); isset($this->created_at) && $this->created_at = date('Y-m-d H:i:s', $this->created_at); isset($this->updated_at) && $this->updated_at = date('Y-m-d H:i:s', $this->updated_at); } //用户 public function getUser(){ return $this->hasOne(User::class,['id'=>'user_id']); } //门店 public function getStore() { return $this->hasOne(Store::class,['id'=>'store_id']); } public function getDepart() { return $this->hasOne(Department::class,['id'=>'depart_id']); } public function getDoctor() { return $this->hasOne(DoctorInfo::class,['su_id'=>'service_user_id']); } //就诊人 public function getPatient() { return $this->hasOne(UserPatient::class,['id'=>'user_patient_id']); } public function getPrescription(){ return $this->hasMany(Prescription::class, ['register_id' => 'id']); } //转诊记录 public function getTransferPrescription() { return $this->hasOne(TransferPrescription::class, ['id' => 'transfer_prescription_id']); } //健康信息 public function getHealthInquery() { return $this->hasOne(UserPatientHealthInquiry::class,['user_patient_id'=>'user_patient_id']); } //病历 public function getCase() { return $this->hasOne(UserPatientCase::class,['register_id'=>'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 = ''; $map = "select user_patient_id, store_id, order_no, order_number, price,is_pay,refuse_reason from yii_register where service_user_id=$su_id"; $list= Register::findBySql($map)->asArray()->all(); //把结果按照显示顺序存到返回的数组中 if(!empty($list)){ foreach ($list as $key => $value){ $inventory[$key]['user_patient_id']= $value['user_patient_id']; $inventory[$key]['store_id'] = $value['store_id']; $inventory[$key]['order_no'] = $value['order_no']; $inventory[$key]['order_number'] = $value['order_number']; $inventory[$key]['price'] = $value['price']; $inventory[$key]['is_pay'] = $value['is_pay']; $inventory[$key]['refuse_reason'] = $value['refuse_reason']; } }else{ $inventory[0]['register']= '无数据导出'; } return $inventory; } }