diff --git a/app/Amqp/Consumer/AssignDoctorConsumer.php b/app/Amqp/Consumer/AssignDoctorConsumer.php index 28fbdac..a23eaf1 100644 --- a/app/Amqp/Consumer/AssignDoctorConsumer.php +++ b/app/Amqp/Consumer/AssignDoctorConsumer.php @@ -197,7 +197,6 @@ class AssignDoctorConsumer extends ConsumerMessage }catch (\Exception $e) { // 验证失败 Log::getInstance()->error("分配医生成功,发送系统问诊消息失败:" . $e->getMessage()); - // 加入消息通知队列 return Result::ACK; } diff --git a/app/Common/Common.php b/app/Common/Common.php index daa418e..4789e4b 100644 --- a/app/Common/Common.php +++ b/app/Common/Common.php @@ -34,7 +34,7 @@ function dump(...$vars) * @param string $message 返回提示信息 * @return array */ -function success(array $data = [], int $code = HttpEnumCode::HTTP_SUCCESS, string $message = ""): array +function success(array|string $data = [], int $code = HttpEnumCode::HTTP_SUCCESS, string $message = ""): array { if (empty($message)) { $message = HttpEnumCode::getMessage($code); diff --git a/app/Controller/SafeController.php b/app/Controller/SafeController.php index 6ff2928..5a1a1de 100644 --- a/app/Controller/SafeController.php +++ b/app/Controller/SafeController.php @@ -25,4 +25,17 @@ class SafeController extends AbstractController $data = $SafeService->getOssSign(); return $this->response->json($data); } + + /** + * 获取im签名数据 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function getImSign(): ResponseInterface + { + $SafeService = new SafeService(); + $data = $SafeService->getImSign(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 6f3047f..ee6d810 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -239,5 +239,20 @@ class UserController extends AbstractController // $Prescription = new Prescription(); // $token = $Prescription->getProd(); // dump($token); + + // 创建im账号 +// $account = new Account(); + // 创建单个账号 +// $account->createAccount("111295","测试患者1",""); +// $profile = new Profile(); +// $result = $profile->getOneAccountPortraitList("111295"); +// dump($result); +// $arg = array(); +// $arg['Tag_Profile_IM_Image'] = "https://img.applets.igandanyiyuan.com/applet/doctor/avatar/03dc8df2-e7c0-4ad9-b87e-5133e40e0f76.jpg"; +// $profile->setProfile("111295",$arg); + +// $ImService = new ImService(); +// $ImService->setUserProfile("491925054435950592"); + } } \ No newline at end of file diff --git a/app/Model/User.php b/app/Model/User.php index fcfc214..9e1b47f 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -9,10 +9,12 @@ use Hyperf\Database\Model\Builder; use Hyperf\Snowflake\Concern\Snowflake; /** - * @property int $user_id 主键 + * @property string $user_id 主键 * @property string $user_name 用户名称 * @property string $user_account 账号 * @property string $mobile 手机号 + * @property int $sex 性别(0:未知 1:男 2:女) + * @property string $avatar 头像 * @property string $wx_mobile 微信手机号 * @property string $user_password 密码 * @property string $salt 密码混淆码 @@ -36,12 +38,12 @@ class User extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'login_ip', 'last_login_at', 'created_at', 'updated_at']; + protected array $fillable = ['user_id', 'user_name', 'user_account', 'mobile', 'sex', 'avatar', 'wx_mobile', 'user_password', 'salt', 'user_type', 'user_status', 'register_method', 'login_ip', 'last_login_at', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. */ - protected array $casts = ['user_id' => 'string', 'user_type' => 'integer', 'user_status' => 'integer', 'register_method' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['user_id' => 'string', 'user_type' => 'integer', 'user_status' => 'integer', 'register_method' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'sex' => 'integer']; protected string $primaryKey = "user_id"; diff --git a/app/Model/UserDoctor.php b/app/Model/UserDoctor.php index 2dd7d34..0034be9 100644 --- a/app/Model/UserDoctor.php +++ b/app/Model/UserDoctor.php @@ -15,8 +15,8 @@ use Hyperf\Snowflake\Concern\Snowflake; use Hyperf\Utils\Arr; /** - * @property string $doctor_id 主键 - * @property string $user_id 用户id + * @property int $doctor_id 主键 + * @property int $user_id 用户id * @property string $user_name 用户名称 * @property string $open_id 微信open_id * @property string $union_id 微信开放平台唯一标识 @@ -29,15 +29,12 @@ use Hyperf\Utils\Arr; * @property string $multi_point_fail_reason 多点执业认证失败原因 * @property int $is_bind_bank 是否已绑定结算银行卡(0:否 1:是) * @property int $is_recommend 是否首页推荐(0:否 1:是) - * @property string $mobile 电话 - * @property int $sex 性别(0:未知 1:男 2:女) - * @property int $age 年龄 * @property string $avatar 头像 * @property int $doctor_title 医生职称(1:执业医师 2:主治医师 3:副主任医师 4:主任医师) - * @property string $department_custom_id 科室id-自定义 + * @property int $department_custom_id 科室id-自定义 * @property string $department_custom_name 科室名称(如未自己输入,填入标准科室名称) * @property string $department_custom_mobile 科室电话 - * @property string $hospital_id 所属医院id + * @property int $hospital_id 所属医院id * @property int $served_patients_num 服务患者数量 * @property string $praise_rate 好评率(百分制。订单平均评价中超过4-5分的订单总数 / 总订单数 * 5) * @property string $avg_response_time 平均响应时间(分钟制) @@ -53,10 +50,10 @@ use Hyperf\Utils\Arr; * @property string $brief_introduction 医生简介 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 - * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[] $DoctorExpertise - * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[] $DoctorInquiryConfig - * @property-read Hospital $Hospital - * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[] $OrderInquiry + * @property-read \Hyperf\Database\Model\Collection|DoctorExpertise[] $DoctorExpertise + * @property-read \Hyperf\Database\Model\Collection|DoctorInquiryConfig[] $DoctorInquiryConfig + * @property-read Hospital $Hospital + * @property-read \Hyperf\Database\Model\Collection|OrderInquiry[] $OrderInquiry */ class UserDoctor extends Model { @@ -70,7 +67,7 @@ class UserDoctor extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_fail_reason', 'is_bind_bank', 'is_recommend', 'mobile', 'sex', 'age', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_online', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; + protected array $fillable = ['doctor_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'iden_auth_status', 'iden_auth_fail_reason', 'multi_point_status', 'multi_point_fail_reason', 'is_bind_bank', 'is_recommend', 'avatar', 'doctor_title', 'department_custom_id', 'department_custom_name', 'department_custom_mobile', 'hospital_id', 'served_patients_num', 'praise_rate', 'avg_response_time', 'number_of_fans', 'is_online', 'is_img_expert_reception', 'is_img_welfare_reception', 'is_img_quick_reception', 'is_platform_deep_cooperation', 'is_enterprise_deep_cooperation', 'qr_code', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at']; protected string $primaryKey = "doctor_id"; diff --git a/app/Model/UserPatient.php b/app/Model/UserPatient.php index 8219008..6751ea2 100644 --- a/app/Model/UserPatient.php +++ b/app/Model/UserPatient.php @@ -9,17 +9,14 @@ namespace App\Model; use Hyperf\Snowflake\Concern\Snowflake; /** - * @property int $patient_id 主键id - * @property int $user_id 用户id + * @property string $patient_id 主键id + * @property string $user_id 用户id * @property string $user_name 用户名称 * @property string $open_id 微信open_id * @property string $union_id 微信开放平台唯一标识 * @property string $wx_session_key 微信会话密钥 * @property int $status 状态(0:禁用 1:正常 2:删除) * @property int $idcard_status 实名认证状态(0:未认证 1:认证通过 2:认证失败) - * @property string $mobile 手机号 - * @property int $sex 性别(0:未知 1:男 2:女) - * @property int $age 年龄 * @property string $avatar 头像 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 @@ -36,7 +33,7 @@ class UserPatient extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['patient_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'mobile', 'sex', 'age', 'avatar', 'created_at', 'updated_at']; + protected array $fillable = ['patient_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'idcard_status', 'avatar', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. diff --git a/app/Model/UserPharmacist.php b/app/Model/UserPharmacist.php index 1b3f9ec..bea8720 100644 --- a/app/Model/UserPharmacist.php +++ b/app/Model/UserPharmacist.php @@ -16,11 +16,8 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $union_id 微信开放平台唯一标识 * @property string $wx_session_key 微信会话密钥 * @property int $status 状态(0:禁用 1:正常 2:删除) - * @property string $mobile 电话 - * @property int $sex 性别(0:未知 1:男 2:女) - * @property int $age 年龄 - * @property string $avatar 头像 * @property int $is_online 是否在线(0:不在线 1:在线) + * @property string $avatar 头像 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 */ @@ -36,7 +33,7 @@ class UserPharmacist extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['pharmacist_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'mobile', 'sex', 'age', 'avatar', 'is_online', 'created_at', 'updated_at']; + protected array $fillable = ['pharmacist_id', 'user_id', 'user_name', 'open_id', 'union_id', 'wx_session_key', 'status', 'is_online', 'avatar', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. diff --git a/app/Services/ImService.php b/app/Services/ImService.php index 45f6703..8e5d188 100644 --- a/app/Services/ImService.php +++ b/app/Services/ImService.php @@ -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(); diff --git a/app/Services/IndexService.php b/app/Services/IndexService.php index 0508cb5..0ebc7bf 100644 --- a/app/Services/IndexService.php +++ b/app/Services/IndexService.php @@ -9,6 +9,7 @@ use App\Model\DoctorInquiryConfig as DoctorInquiryConfigModel; use App\Model\Module as ModuleModel; use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel; use App\Model\PharmacistAuditStatistic; +use App\Model\User; use App\Model\UserDoctor as UserDoctorModel; use App\Model\UserPharmacist; @@ -40,8 +41,6 @@ class IndexService extends BaseService "iden_auth_fail_reason", "multi_point_status", "is_bind_bank", - "mobile", - "avatar", "praise_rate", "avg_response_time", "number_of_fans", diff --git a/app/Services/LoginService.php b/app/Services/LoginService.php index de596e2..e7f071f 100644 --- a/app/Services/LoginService.php +++ b/app/Services/LoginService.php @@ -9,6 +9,7 @@ use App\Model\UserPatient as UserPatientModel; use App\Model\UserPharmacist as UserPharmacistModel; use App\Utils\Http; use App\Utils\Jwt; +use Extend\TencentIm\Account; use Extend\Wechat\Wechat; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; @@ -85,7 +86,6 @@ class LoginService extends BaseService $data['union_id'] = $wx_info_data['unionid'] ?? ""; $data['wx_session_key'] = $wx_info_data['session_key']; $data['status'] = 1; - $data['mobile'] = $phone_info['phone_info']['purePhoneNumber']; if ($user['user_type'] == 1) { // 患者 @@ -114,6 +114,11 @@ class LoginService extends BaseService $client_user_id = $user_doctor['doctor_id']; } + + // 创建im账号 + $account = new Account(); + // 创建单个账号 + $account->createAccount($user->user_id,$user->user_name,""); } else { // 已注册用户 // 重复注册不同端 @@ -272,7 +277,6 @@ class LoginService extends BaseService $data['user_id'] = $user->user_id; $data['user_name'] = $user['user_name']; $data['status'] = 1; - $data['mobile'] = $phone; if ($user['user_type'] == 1) { // 患者 diff --git a/app/Services/SafeService.php b/app/Services/SafeService.php index 0fcd35e..a2bf80c 100644 --- a/app/Services/SafeService.php +++ b/app/Services/SafeService.php @@ -2,8 +2,15 @@ namespace App\Services; +use App\Exception\BusinessException; +use App\Model\User; use App\Model\User as UserModel; +use App\Model\UserDoctor; +use App\Model\UserPatient; +use App\Model\UserPharmacist; use Extend\Alibaba\Oss; +use Extend\TencentIm\Account; +use Extend\TencentIm\Safe; /** * 安全服务 @@ -67,4 +74,33 @@ class SafeService extends BaseService return success($oss->signature($dir)); } + + /** + * 获取im签名数据 + * @return array + */ + public function getImSign(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + if (empty($user_info)){ + return success(); + } + + // 验证用户数据 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user = User::getOne($params); + if (empty($user)){ + return success(); + } + + $safe = new Safe(); + $sign = $safe->getUserSign($user['user_id']); + if (empty($sign)){ + return success(); + } + + return success($sign); + } } \ No newline at end of file diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index c872f1f..7690e08 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -1509,7 +1509,7 @@ class UserDoctorService extends BaseService * @param string $inquiry_type * @return string */ - public function getInquiryAssignDoctor(string $inquiry_type,): string + public function getInquiryAssignDoctor(string $inquiry_type): string { // 获取问诊配置 $params = array(); diff --git a/app/Services/UserService.php b/app/Services/UserService.php index e27bb71..bc2f346 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -10,6 +10,7 @@ use App\Model\UserDoctor; use App\Model\UserDoctorInfo; use App\Model\UserPatient; use App\Utils\PcreMatch; +use Extend\TencentIm\Profile; use Extend\Wechat\Wechat; use Hyperf\Amqp\Result; use Hyperf\DbConnection\Db; @@ -91,58 +92,83 @@ class UserService extends BaseService // 匹配去除oss网址 $avatar = PcreMatch::pregRemoveOssWebsite($avatar); - // 获取对应用户信息 - if ($user['user_type'] == 1){ - // 患者 + Db::beginTransaction(); + try { + // 修改用户表 + $data = array(); + $data['avatar'] = $avatar; + $params = array(); $params['user_id'] = $user_info['user_id']; - $user_patient = UserPatient::getOne($params); - if (empty($user_patient)){ - return fail(); - } - - if ($user_patient['avatar'] != $avatar) { - $data = array(); - $data['avatar'] = $avatar; + User::editUser($params,$data); + // 获取对应用户信息 + if ($user['user_type'] == 1){ + // 患者 $params = array(); - $params['patient_id'] = $user_patient['patient_id']; - UserPatient::editUserPatient($params,$data); - } - }elseif ($user['user_type'] == 2){ - // 医生 - $params = array(); - $params['user_id'] = $user_info['user_id']; - $user_doctor = UserDoctor::getOne($params); - if (empty($user_doctor)){ - return fail(); - } + $params['user_id'] = $user_info['user_id']; + $user_patient = UserPatient::getOne($params); + if (empty($user_patient)){ + Db::rollBack(); + return fail(); + } - if ($user_doctor['avatar'] != $avatar) { - $data = array(); - $data['avatar'] = $avatar; + if ($user_patient['avatar'] != $avatar) { + $data = array(); + $data['avatar'] = $avatar; + $params = array(); + $params['patient_id'] = $user_patient['patient_id']; + UserPatient::editUserPatient($params,$data); + } + }elseif ($user['user_type'] == 2){ + // 医生 $params = array(); - $params['doctor_id'] = $user_doctor['doctor_id']; - UserDoctor::editUserDoctor($params,$data); - } - }elseif ($user['user_type'] == 3){ - // 药师 - $params = array(); - $params['user_id'] = $user_info['user_id']; - $user_pharmacist = UserPatient::getOne($params); - if (empty($user_pharmacist)){ - return fail(); - } + $params['user_id'] = $user_info['user_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)){ + Db::rollBack(); + return fail(); + } - if ($user_pharmacist['avatar'] != $avatar) { - $data = array(); - $data['avatar'] = $avatar; + if ($user_doctor['avatar'] != $avatar) { + $data = array(); + $data['avatar'] = $avatar; + $params = array(); + $params['doctor_id'] = $user_doctor['doctor_id']; + UserDoctor::editUserDoctor($params,$data); + } + }elseif ($user['user_type'] == 3){ + // 药师 $params = array(); - $params['pharmacist_id'] = $user_pharmacist['pharmacist_id']; - UserPatient::editUserPatient($params,$data); + $params['user_id'] = $user_info['user_id']; + $user_pharmacist = UserPatient::getOne($params); + if (empty($user_pharmacist)){ + Db::rollBack(); + return fail(); + } + + if ($user_pharmacist['avatar'] != $avatar) { + $data = array(); + $data['avatar'] = $avatar; + + $params = array(); + $params['pharmacist_id'] = $user_pharmacist['pharmacist_id']; + UserPatient::editUserPatient($params,$data); + } } + + // 修改im头像 + $profile = new Profile(); + $arg = array(); + $arg['Tag_Profile_IM_Image'] = addAliyunOssWebsite($avatar); + $profile->setProfile($user_info['user_id'],$arg); + + Db::commit(); + } catch (\Exception $e) { + Db::rollBack(); + return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage()); } return success(); diff --git a/config/routes.php b/config/routes.php index c33e0a3..942c299 100644 --- a/config/routes.php +++ b/config/routes.php @@ -381,6 +381,9 @@ Router::addGroup('/area', function () { Router::addGroup('/sign', function () { // 获取oss签名数据 Router::get('/oss', [SafeController::class, 'getOssSign']); + + // 获取im签名数据 + Router::get('/im', [SafeController::class, 'getImSign']); }); // 基础数据 diff --git a/extend/TencentIm/Account.php b/extend/TencentIm/Account.php index f72d84c..75915b2 100644 --- a/extend/TencentIm/Account.php +++ b/extend/TencentIm/Account.php @@ -23,7 +23,7 @@ class Account extends Base * @return array * @throws GuzzleException */ - public function createAccount(string $user_id,string $nick_name,string $avatar): array + public function createAccount(string $user_id,string $nick_name = "",string $avatar = ""): array { try { $options = [ diff --git a/extend/TencentIm/Profile.php b/extend/TencentIm/Profile.php index 65dde6b..377bad1 100644 --- a/extend/TencentIm/Profile.php +++ b/extend/TencentIm/Profile.php @@ -53,12 +53,13 @@ class Profile extends Base /** * 拉取一个账户的多个资料 + * 返回未设置的字段 * @param string $user_id * @param array $arg * @return array|string[] * @throws GuzzleException */ - public function getOneAccountPortraitList(string $user_id,array $arg = ['Tag_Profile_IM_Gender','Tag_Profile_Custom_Hname','Tag_Profile_Custom_Title']): array + public function getOneAccountPortraitList(string $user_id,array $arg = ['Tag_Profile_IM_Gender','Tag_Profile_Custom_Hname','Tag_Profile_Custom_Title',"Tag_Profile_IM_Image"]): array { try { $options = [ @@ -70,10 +71,20 @@ class Profile extends Base $path = $this->config['base_url'] . $this->version . "/profile/portrait_get?" . $this->buildRequestParams(); $result = $this->postRequest($path,$options); + + $result_arg = []; if (!empty($result['UserProfileItem'])){ foreach ($result['UserProfileItem'] as $user_profile_item){ if(!empty($user_profile_item['ProfileItem'])){ - $result_arg = array_column($user_profile_item['ProfileItem'],"Tag"); + foreach ($user_profile_item['ProfileItem'] as $profile_item){ + if (!empty($profile_item['Value'])){ + // 性别为未知时跳过 + if ($profile_item['Tag'] == "Tag_Profile_IM_Gender" && $profile_item['Value'] == "Gender_Type_Unknown"){ + continue; + } + $result_arg[] = $profile_item['Tag']; + } + } } } } diff --git a/extend/TencentIm/Safe.php b/extend/TencentIm/Safe.php new file mode 100644 index 0000000..3461415 --- /dev/null +++ b/extend/TencentIm/Safe.php @@ -0,0 +1,16 @@ +