This commit is contained in:
2023-03-16 10:17:44 +08:00
parent d19a1271d3
commit 21fe6be452
18 changed files with 297 additions and 132 deletions
+105 -55
View File
@@ -36,55 +36,40 @@ class ImService extends BaseService
throw new BusinessException("用户数据错误");
}
if ($user['user_type'] == 1){
// 患者
$params = array();
$params['user_id'] = $user['user_id'];
$user_patient = UserPatient::getOne($params);
if (empty($user_patient)){
throw new BusinessException("患者数据错误");
}
$avatar = addAliyunOssWebsite($user_patient['avatar']);
$user_name = $user_patient['user_name'];
}elseif ($user['user_type'] == 2){
// 医生
$params = array();
$params['user_id'] = $user['user_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)){
throw new BusinessException("医生数据错误");
}
$avatar = addAliyunOssWebsite($user_doctor['avatar']);
$user_name = $user_doctor['user_name'];
}elseif ($user['user_type'] == 3){
// 药师
$params = array();
$params['user_id'] = $user['user_id'];
$user_pharmacist = UserPharmacist::getOne($params);
if (empty($user_pharmacist)){
throw new BusinessException("药师数据错误");
}
$avatar = addAliyunOssWebsite($user_pharmacist['avatar']);
$user_name = $user_pharmacist['user_name'];
}
$avatar = addAliyunOssWebsite($user['avatar']);
$account = new Account();
// 查询账号导入状态
$res = $account->checkAccountStatus($user['user_id']);
if (!$res){
// 创建单个账号
$account->createAccount($user_id,$user_name,$avatar);
$account->createAccount($user_id,$user['user_name'],$avatar);
}
// 医生检测并设置资料
if ($user['user_type'] == 2){
// 检测用户资料
$profile = new Profile();
$result = $profile->getOneAccountPortraitList($user['user_id']);
if (!empty($result)){
// 检测用户资料
$profile = new Profile();
$result = $profile->getOneAccountPortraitList($user['user_id']);
if (!empty($result)){
$arg = array();
// 头像
if (in_array('Tag_Profile_IM_Image',$result)){
$arg['Tag_Profile_IM_Image'] = $avatar;
}
// 性别
if (in_array('Tag_Profile_IM_Gender',$result)){
$arg['Tag_Profile_IM_Gender'] = sexToImSex($user['sex']);
}
if ($user['user_type'] == 2){
$params = array();
$params['user_id'] = $user['user_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)){
throw new BusinessException("医生数据错误");
}
// 获取订单医生医院
$params = array();
$params['hospital_id'] = $user_doctor['hospital_id'];
@@ -93,11 +78,77 @@ class ImService extends BaseService
throw new BusinessException("医生医院数据错误");
}
// 设置用户资料
$arg = array();
// 性别
if (in_array('Tag_Profile_IM_Gender',$result)){
$arg['Tag_Profile_IM_Gender'] = sexToImSex($user_doctor['sex']);
// 医院
if (in_array('Tag_Profile_Custom_Hname',$result)){
$arg['Tag_Profile_Custom_Hname'] = $hospital['hospital_name'];
}
// 职称
if (in_array('Tag_Profile_Custom_Title',$result)){
$arg['Tag_Profile_Custom_Title'] = $user_doctor['doctor_title'] ?? DoctorTitleCode::getMessage($user_doctor['doctor_title']);
}
}
if (!empty($arg)){
$profile->setProfile($user['user_id'],$arg);
}
}
return true;
} catch (\Exception $e) {
throw new BusinessException($e->getMessage());
}
}
/**
* 设置用户资料
* @param string $user_id
* @return bool
* @throws GuzzleException
*/
public function setUserProfile(string $user_id): bool
{
try {
$params = array();
$params['user_id'] = $user_id;
$user = User::getOne($params);
if (empty($user)){
throw new BusinessException("用户数据错误");
}
$avatar = addAliyunOssWebsite($user['avatar']);
// 检测用户资料
$profile = new Profile();
$result = $profile->getOneAccountPortraitList($user['user_id']);
if (!empty($result)){
$arg = array();
// 头像
if (in_array('Tag_Profile_IM_Image',$result)){
$arg['Tag_Profile_IM_Image'] = $avatar;
}
// 性别
if (in_array('Tag_Profile_IM_Gender',$result)){
$arg['Tag_Profile_IM_Gender'] = sexToImSex($user['sex']);
}
if ($user['user_type'] == 2){
$params = array();
$params['user_id'] = $user['user_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)){
throw new BusinessException("医生数据错误");
}
// 获取订单医生医院
$params = array();
$params['hospital_id'] = $user_doctor['hospital_id'];
$hospital = Hospital::getOne($params);
if (empty($hospital)){
throw new BusinessException("医生医院数据错误");
}
// 医院
@@ -106,13 +157,13 @@ class ImService extends BaseService
}
// 职称
if (in_array('Tag_Profile_Custom_Hname',$result)){
if (in_array('Tag_Profile_Custom_Title',$result)){
$arg['Tag_Profile_Custom_Title'] = $user_doctor['doctor_title'] ?? DoctorTitleCode::getMessage($user_doctor['doctor_title']);
}
}
if (!empty($arg)){
$profile->setProfile($user_doctor['user_id'],$arg);
}
if (!empty($arg)){
$profile->setProfile($user['user_id'],$arg);
}
}
@@ -120,7 +171,6 @@ class ImService extends BaseService
} catch (\Exception $e) {
throw new BusinessException($e->getMessage());
}
}
/**
@@ -178,12 +228,12 @@ class ImService extends BaseService
public function sendTextMessage(string $from_user_id,string $to_user_id,string $content,string $order_inquiry_id,int $inquiry_type): void
{
if (!empty($from_user_id)){
// 检测并创建发送者账号
$this->createAccount($from_user_id);
// 检测并创建发送者资料
$this->setUserProfile($from_user_id);
}
// 检测并创建接收者账号
$this->createAccount($to_user_id);
// 检测并创建接收者资料
$this->setUserProfile($to_user_id);
// 医生给患者发送消息
$message = new Message();