初始化仓库
This commit is contained in:
93
service/models/forms/CaseForm.php
Normal file
93
service/models/forms/CaseForm.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace service\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\UserPatientCase;
|
||||
use yii\db\Exception;
|
||||
|
||||
//病历
|
||||
class CaseForm extends BaseModel
|
||||
{
|
||||
public $user_patient_id;
|
||||
public $register_id;
|
||||
public $hight;
|
||||
public $weight;
|
||||
public $temperature;
|
||||
public $blood;
|
||||
public $main_suit;
|
||||
public $family;
|
||||
public $now_history;
|
||||
public $popular;
|
||||
public $history;
|
||||
public $allergic;
|
||||
public $idea;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['user_patient_id','register_id'] ,'required'],
|
||||
[['hight', 'weight', 'temperature', 'blood'], 'integer'],
|
||||
[['main_suit', 'family', 'now_history', 'popular', 'history', 'allergic', 'idea'], 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
$today = strtotime(date('Y-m-d', time()));
|
||||
$end = $today + 60 * 60 * 24;
|
||||
|
||||
$UserPatientCase = UserPatientCase::find()->where([
|
||||
'user_patient_id' => $this->user_patient_id,
|
||||
'register_id' => $this->register_id,
|
||||
'store_id' => \Yii::$app->store,
|
||||
'service_user_id' => \Yii::$app->user->id,
|
||||
'is_delete' => 0
|
||||
])->andWhere(['between', 'created_at', $today, $end])->one();
|
||||
|
||||
try {
|
||||
if (!$UserPatientCase) {
|
||||
$UserPatientCase = new UserPatientCase();
|
||||
}
|
||||
$UserPatientCase->store_id = \Yii::$app->store;
|
||||
$UserPatientCase->service_user_id = \Yii::$app->user->id;
|
||||
$UserPatientCase->created_at =time();
|
||||
$UserPatientCase->updated_at =time();
|
||||
$UserPatientCase->attributes = $this->attributes;
|
||||
|
||||
|
||||
$UserPatientCase->saveOrFail();
|
||||
} catch (\Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
$UserPatientCase = UserPatientCase::find()->where([
|
||||
'register_id' => $this->register_id,
|
||||
'user_patient_id' => $this->user_patient_id,
|
||||
'is_delete' => 0,
|
||||
'service_user_id' => \Yii::$app->user->id,
|
||||
'store_id' => \Yii::$app->store,
|
||||
])->with(['userPatient'])->asArray()->all();
|
||||
|
||||
if (!$UserPatientCase) throw new Exception('病历不存在');
|
||||
|
||||
return $UserPatientCase;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user