初始化仓库
This commit is contained in:
194
admin/models/forms/HospitalDocForm.php
Normal file
194
admin/models/forms/HospitalDocForm.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace admin\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\enums\UserRoleEnum;
|
||||
use common\models\DoctorApply;
|
||||
use common\models\DoctorPatient;
|
||||
use common\models\ServiceUser;
|
||||
use common\models\StoreDoctor;
|
||||
use GuzzleHttp\Client;
|
||||
use linslin\yii2\curl\Curl;
|
||||
use yii\db\Exception;
|
||||
|
||||
class HospitalDocForm extends BaseModel
|
||||
{
|
||||
public $store_id;
|
||||
public $doctor_id;
|
||||
|
||||
public $status;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['doctor_id','required'],
|
||||
[['status','store_id'],'integer']
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取互医信息
|
||||
public function DocInfo()
|
||||
{
|
||||
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
ServiceUser::find()->where([
|
||||
'id' => $this->doctor_id,
|
||||
'role' => UserRoleEnum::DOCTOR,
|
||||
'is_delete' => 0,
|
||||
])->one();
|
||||
|
||||
$sql = "select * from yii_doctor_platform where platform_doctor_id= $this->doctor_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()
|
||||
{
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
$ServiceUser = ServiceUser::find()->where([
|
||||
'id' => $this->doctor_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('请完善基本信息');
|
||||
|
||||
$store_ids=StoreDoctor::find()->where([
|
||||
'su_id'=>$this->doctor_id
|
||||
])->select('store_id')->column();
|
||||
|
||||
if (!$store_ids){
|
||||
throw new Exception('您还没有任何门店');
|
||||
}
|
||||
|
||||
$params=[
|
||||
'id' => $this->doctor_id,
|
||||
'store_id'=>$store_ids,
|
||||
'mobile'=>$ServiceUser->mobile,
|
||||
'docInfo' =>$ServiceUser->docInfo,
|
||||
'docIdentity'=> $ServiceUser->docIdentity,
|
||||
'docPracticing'=>$ServiceUser->docPracticing,
|
||||
'docService'=> $ServiceUser->docService,
|
||||
];
|
||||
|
||||
$response = (new Client(['http_errors' => false]))->post(
|
||||
\Yii::$app->params['platform']['url']."/platform/v1/sync/doctor",
|
||||
[
|
||||
'headers' => ['Content-Type' => 'application/json', 'Authorization' => "Bearer ".\Yii::$app->params['platform']['token']],
|
||||
\GuzzleHttp\RequestOptions::JSON =>$params
|
||||
]
|
||||
);
|
||||
$result = json_decode($response->getBody(),true);
|
||||
if ($result['errcode']) {
|
||||
throw new Exception($result['msg']);
|
||||
}
|
||||
|
||||
return ['升级成功'];
|
||||
}
|
||||
|
||||
//同步患者
|
||||
public function SyncPatient()
|
||||
{
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
$store=\Yii::$app->store;
|
||||
$patient=DoctorPatient::find()->where([
|
||||
'su_id'=>$this->doctor_id,
|
||||
])->all();
|
||||
|
||||
$sql = "select * from yii_doctor_platform where platform_doctor_id=$this->doctor_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 ['患者同步成功'];
|
||||
}
|
||||
|
||||
//医生审核
|
||||
public function ExamineDoc()
|
||||
{
|
||||
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg());
|
||||
}
|
||||
|
||||
$DoctorApply=DoctorApply::find()->where([
|
||||
'service_user_id'=>$this->doctor_id,
|
||||
'status'=>0,
|
||||
'is_delete'=>0,
|
||||
])->one();
|
||||
if (!$DoctorApply){
|
||||
throw new Exception('该医生没有升级申请');
|
||||
}
|
||||
|
||||
$DoctorApply->id=$DoctorApply->id;
|
||||
$DoctorApply->service_user_id=$this->doctor_id;
|
||||
$DoctorApply->status=$this->status;
|
||||
$DoctorApply->update();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user