初始化仓库
This commit is contained in:
110
platform/models/forms/SyncPatientForm.php
Normal file
110
platform/models/forms/SyncPatientForm.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace platform\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\helpers\ArrayHelper;
|
||||
use common\helpers\FuncHelper;
|
||||
use GuzzleHttp\Client;
|
||||
use yii\base\Exception;
|
||||
use common\models\UserPatient;
|
||||
use common\validators\MobileValidator;
|
||||
use common\models\UserPatientHealthInquiry;
|
||||
|
||||
//同步用户form
|
||||
class SyncPatientForm extends BaseModel
|
||||
{
|
||||
public $user_id;
|
||||
public $avatar;
|
||||
public $name;
|
||||
public $id_card;
|
||||
public $age;
|
||||
public $sex;
|
||||
public $relation;
|
||||
public $mobile;
|
||||
public $is_default;
|
||||
public $liver_function;
|
||||
public $liver_index;
|
||||
public $renal_function;
|
||||
public $renal_index;
|
||||
public $person_status;
|
||||
public $person_history;
|
||||
public $allergic_status;
|
||||
public $allergic_history;
|
||||
public $family_status;
|
||||
public $family_history;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['user_id','name','id_card','age','sex','relation','mobile','is_default','liver_function','renal_function','person_status','allergic_status','family_status'],'required'],
|
||||
[['liver_index','renal_index','person_history','allergic_history','family_history'], 'string', 'max' => 500],
|
||||
['mobile',MobileValidator::class],
|
||||
['id_card', 'match', 'pattern' => '/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/i'],
|
||||
// ['id_card', 'checkCard'],
|
||||
[['avatar'],'string'],
|
||||
[['name','avatar'],'string']
|
||||
];
|
||||
}
|
||||
|
||||
// public function checkCard($attribute, $params)
|
||||
// {
|
||||
// $response = (new Client(['http_errors' => false]))->post("https://eid.shumaidata.com/eid/check", [
|
||||
// 'headers' => ['Authorization' =>"APPCODE f98bba3251714c759f5bd29d00e1c46e"],
|
||||
// 'query' => [
|
||||
// 'idcard' => $this->id_card,
|
||||
// 'name' => $this->name
|
||||
// ],
|
||||
// ]);
|
||||
// $result = json_decode($response->getBody(),true);
|
||||
// if(!($result['code']==0 && $result['result']['res']==1)){
|
||||
// $this->addError($attribute, '身份证名字不匹配');
|
||||
// }
|
||||
// }
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
$UserPatient = UserPatient::findOne([
|
||||
'user_id' => $this->user_id,
|
||||
'id_card' => $this->id_card,
|
||||
'is_delete' => 0
|
||||
]);
|
||||
|
||||
if($UserPatient->id){
|
||||
//更新
|
||||
$UserPatientHealthInquiry = UserPatientHealthInquiry::findOne(['user_patient_id' => $UserPatient->id]);
|
||||
if(!$UserPatientHealthInquiry){
|
||||
throw new Exception('就诊人健康信息不存在');
|
||||
}
|
||||
}else{
|
||||
//新增
|
||||
$UserPatient = new UserPatient();
|
||||
$UserPatientHealthInquiry = new UserPatientHealthInquiry();
|
||||
}
|
||||
|
||||
$Transaction = \Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
if($this->is_default){
|
||||
UserPatient::updateAll(['is_default'=>0],['user_id'=>$this->user_id]);
|
||||
}
|
||||
//就诊人
|
||||
$UserPatient->attributes = $this->attributes;
|
||||
$UserPatient->saveOrFail();
|
||||
|
||||
$attributes = $this->attributes;
|
||||
$attributes['user_patient_id'] = $UserPatient->id;
|
||||
|
||||
//就诊人健康信息
|
||||
$UserPatientHealthInquiry->attributes = $attributes;
|
||||
$UserPatientHealthInquiry->saveOrFail();
|
||||
|
||||
$Transaction->commit();
|
||||
}catch (Exception $exception){
|
||||
$Transaction->rollback();
|
||||
throw $exception;
|
||||
}
|
||||
return ['同步成功'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user