初始化仓库
This commit is contained in:
230
service/models/forms/HospitalDocForm.php
Normal file
230
service/models/forms/HospitalDocForm.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace service\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\enums\UserRoleEnum;
|
||||
use common\enums\UserStatusEnum;
|
||||
use common\models\DoctorPatient;
|
||||
use common\models\ServiceUser;
|
||||
use yii\db\Exception;
|
||||
|
||||
//互医
|
||||
class HospitalDocForm extends BaseModel
|
||||
{
|
||||
public $store;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取互医信息
|
||||
public function DocInfo()
|
||||
{
|
||||
$su_id = \Yii::$app->user->identity->getId();
|
||||
$store = \Yii::$app->store;
|
||||
ServiceUser::find()->where([
|
||||
'id' => $su_id,
|
||||
'role' => UserRoleEnum::DOCTOR,
|
||||
'is_delete' => 0,
|
||||
])->one();
|
||||
|
||||
$sql = "select * from yii_doctor_platform where platform_doctor_id=$su_id and platform_store_id=$store";
|
||||
$doctor_is_exist = \Yii::$app->db1->createCommand($sql)->queryOne();
|
||||
if (!$doctor_is_exist){
|
||||
throw new Exception('您还没成为互医');
|
||||
}
|
||||
|
||||
$doctor_id = $doctor_is_exist['su_id'];
|
||||
|
||||
$doctor_info = "select * from yii_doctor_info where su_id=$doctor_id";
|
||||
$doctor_info_exist = \Yii::$app->db1->createCommand($doctor_info)->queryOne();
|
||||
|
||||
$doctor_identity = "select * from yii_doctor_identity where su_id=$doctor_id";
|
||||
$doctor_identity_exist = \Yii::$app->db1->createCommand($doctor_identity)->queryOne();
|
||||
|
||||
$doctor_practicing = "select * from yii_doctor_practicing where su_id=$doctor_id";
|
||||
$doctor_practicing_exist = \Yii::$app->db1->createCommand($doctor_practicing)->queryOne();
|
||||
|
||||
$doctor_service = "select * from yii_doctor_service where su_id=$doctor_id";
|
||||
$doctor_service_exist = \Yii::$app->db1->createCommand($doctor_service)->queryOne();
|
||||
|
||||
return [
|
||||
'doctor'=>$doctor_is_exist,
|
||||
'doctor_info'=>$doctor_info_exist,
|
||||
'doctor_identity'=>$doctor_identity_exist,
|
||||
'doctor_practicing'=>$doctor_practicing_exist,
|
||||
'doctor_service'=>$doctor_service_exist
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级为互医
|
||||
*/
|
||||
public function grade()
|
||||
{
|
||||
$su_id = \Yii::$app->user->identity->getId();
|
||||
$store = \Yii::$app->store;
|
||||
|
||||
$ServiceUser = ServiceUser::find()->where([
|
||||
'id' => $su_id,
|
||||
'role' => UserRoleEnum::DOCTOR,
|
||||
'is_delete' => 0,
|
||||
'plate_type'=>2 //萧康的医生
|
||||
])->one();
|
||||
if (!$ServiceUser){
|
||||
throw new Exception('萧康不存在该医生');
|
||||
}
|
||||
if (!$ServiceUser->docIdentity || !$ServiceUser->docPracticing || !$ServiceUser->docInfo || !$ServiceUser->docService)
|
||||
throw new Exception('请完善基本信息');
|
||||
|
||||
try {
|
||||
$t = \Yii::$app->db1->beginTransaction();
|
||||
$token = \Yii::$app->security->generateRandomString() . '_' . time();
|
||||
$mobile=$ServiceUser['mobile'];
|
||||
|
||||
$sql="select * from yii_service_user where mobile=$mobile";
|
||||
$is_exist=\Yii::$app->db1->createCommand($sql)->queryOne();
|
||||
$id=$is_exist['id'];
|
||||
|
||||
if (!$is_exist){
|
||||
\Yii::$app->db1->createCommand()->insert('yii_service_user',[
|
||||
'mobile'=>$mobile,
|
||||
'role'=>UserRoleEnum::DOCTOR,
|
||||
'status'=>UserStatusEnum::WAIT_JH,
|
||||
'created_at'=>time(),
|
||||
'updated_at'=>time(),
|
||||
])->execute();
|
||||
$last_id=\Yii::$app->db1->getLastInsertID();
|
||||
\Yii::$app->db1->createCommand()->insert('yii_service_user_token',[
|
||||
'su_id'=>$last_id,
|
||||
'token'=>$token,
|
||||
'created_at'=>time(),
|
||||
'updated_at'=>time(),
|
||||
])->execute();
|
||||
}
|
||||
|
||||
$service_id=$id??$last_id;
|
||||
|
||||
$sql_platform="select * from yii_doctor_platform where su_id=$service_id and platform_doctor_id=$su_id and platform_store_id=$store";
|
||||
$doctor_platform=\Yii::$app->db1->createCommand($sql_platform)->queryOne();
|
||||
|
||||
if (!$doctor_platform){
|
||||
//用户平台关系表
|
||||
\Yii::$app->db1->createCommand()->insert('yii_doctor_platform',[
|
||||
'su_id'=>$service_id,
|
||||
'platform_doctor_id'=>$su_id,
|
||||
'platform_id'=>1,
|
||||
'platform_store_id'=>\Yii::$app->store,
|
||||
'created_at'=>time(),
|
||||
'updated_at'=>time(),
|
||||
])->execute();
|
||||
}
|
||||
$t->commit();
|
||||
}catch (\Exception $e){
|
||||
$t->rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
|
||||
$info=$this->DocInfo();
|
||||
|
||||
if (!$info['doctor'] || !$info['doctor_info'] || !$info['doctor_identity'] || !$info['doctor_practicing'] || !$info['doctor_service'])
|
||||
{
|
||||
$transaction = \Yii::$app->db1->beginTransaction();
|
||||
try {
|
||||
\Yii::$app->db1->createCommand()->insert('yii_doctor_info', [
|
||||
'su_id' => $service_id,
|
||||
'avatar' => $ServiceUser->docInfo->avatar,
|
||||
'name' => $ServiceUser->docInfo->name,
|
||||
'mobile' => $ServiceUser->docInfo->mobile,
|
||||
'idcard' => $ServiceUser->docInfo->idcard,
|
||||
'depart_id' => $ServiceUser->docInfo->depart_id,
|
||||
'hospital_id' => $ServiceUser->docInfo->hospital_id,
|
||||
'yard_id' => $ServiceUser->docInfo->yard_id,
|
||||
'title_id' => $ServiceUser->docInfo->title_id,
|
||||
'good_at' => $ServiceUser->docInfo->good_at,
|
||||
'intro' => $ServiceUser->docInfo->intro,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
])->execute();
|
||||
\Yii::$app->db1->createCommand()->insert('yii_doctor_identity', [
|
||||
'su_id' => $service_id,
|
||||
'card_up' => $ServiceUser->docIdentity->card_up,
|
||||
'card_down' => $ServiceUser->docIdentity->card_down,
|
||||
'work_avator' => $ServiceUser->docIdentity->work_avator,
|
||||
'sign_type' => $ServiceUser->docIdentity->sign_type,
|
||||
'sign_image' => $ServiceUser->docIdentity->sign_image,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
])->execute();
|
||||
\Yii::$app->db1->createCommand()->insert('yii_doctor_practicing', [
|
||||
'su_id' => $service_id,
|
||||
'qualification' => $ServiceUser->docPracticing->qualification,
|
||||
'practicing' => $ServiceUser->docPracticing->practicing,
|
||||
'title' => $ServiceUser->docPracticing->title,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
])->execute();
|
||||
\Yii::$app->db1->createCommand()->insert('yii_doctor_service', [
|
||||
'su_id' => $service_id,
|
||||
'register_status' => $ServiceUser->docService->register_status,
|
||||
'register_price' => $ServiceUser->docService->register_price,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
])->execute();
|
||||
|
||||
|
||||
$this->SyncPatient();//同步患者
|
||||
|
||||
$transaction->commit();
|
||||
return ['信息已同步'];
|
||||
} catch (\Exception $e) {
|
||||
$transaction->rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
return ['您已在互医注册过并已完善相关信息'];
|
||||
}
|
||||
|
||||
public function SyncPatient()
|
||||
{
|
||||
$su_id=\Yii::$app->user->identity->getId();
|
||||
$store=\Yii::$app->store;
|
||||
$patient=DoctorPatient::find()->where([
|
||||
'su_id'=>$su_id,
|
||||
])->all();
|
||||
|
||||
$sql = "select * from yii_doctor_platform where platform_doctor_id=$su_id and platform_store_id=$store";
|
||||
$doctor_is_exist = \Yii::$app->db1->createCommand($sql)->queryOne();
|
||||
if (!$doctor_is_exist){
|
||||
throw new Exception('您还没成为互医');
|
||||
}
|
||||
|
||||
$rows=[];
|
||||
foreach ($patient as $value){
|
||||
$rows[]=[
|
||||
'su_id'=>$doctor_is_exist['su_id'],
|
||||
'user_id'=>$value['user_id'],
|
||||
'up_id'=>$value['up_id'],
|
||||
'name'=>$value['name'],
|
||||
'avatar'=>$value['avatar'],
|
||||
'id_card'=>$value['id_card'],
|
||||
'sex'=>$value['sex'],
|
||||
'mobile'=>$value['mobile'],
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
\Yii::$app->db1->createCommand()->batchInsert('yii_doctor_patient', ['su_id','user_id','up_id','name','avatar','id_card','sex','mobile','created_at','updated_at'],$rows)->execute();
|
||||
|
||||
return ['患者同步成功'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user