个人简介相关接口

This commit is contained in:
wucongxing 2024-01-19 11:56:34 +08:00
parent fd555d167f
commit 8393a73c41
6 changed files with 425 additions and 47 deletions

View File

@ -45,14 +45,9 @@ class DoctorAuthController extends AbstractController
/**
* 获取身份认证信息
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getAuthIden(): ResponseInterface
{
$request = $this->container->get(DoctorAuthRequest::class);
$request->scene('getAuthIden')->validateResolved();
$DoctorAuthService = new DoctorAuthService();
$data = $DoctorAuthService->getAuthIden();
return $this->response->json($data);
@ -122,4 +117,31 @@ class DoctorAuthController extends AbstractController
$data = $DoctorAuthService->getDoctorIntroductionFailReason();
return $this->response->json($data);
}
/**
* 获取个人简介
* @return ResponseInterface
*/
public function getDoctorIntroduction(): ResponseInterface
{
$DoctorAuthService = new DoctorAuthService();
$data = $DoctorAuthService->getDoctorIntroduction();
return $this->response->json($data);
}
/**
* 修改个人简介
* @return ResponseInterface
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function putDoctorIntroduction(): ResponseInterface
{
$request = $this->container->get(DoctorAuthRequest::class);
$request->scene('putDoctorIntroduction')->validateResolved();
$DoctorAuthService = new DoctorAuthService();
$data = $DoctorAuthService->putDoctorIntroduction();
return $this->response->json($data);
}
}

View File

@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int $record_id 主键id
* @property int $doctor_id 医生id
* @property int $is_verified 是否已审核0: 1:是)
* @property string $avatar 头像
* @property string $be_good_at 擅长
* @property string $brief_introduction 医生简介
* @property string $expertise_ids 专长id逗号分隔
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class DoctorIntroductionRecord extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'doctor_introduction_record';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['record_id', 'doctor_id', 'is_verified', 'avatar', 'be_good_at', 'brief_introduction', 'expertise_ids', 'created_at', 'updated_at'];
protected string $primaryKey = "record_id";
/**
* 获取信息-单条
* @param array $params
* @param array $fields
* @return object|null
*/
public static function getOne(array $params, array $fields = ['*']): object|null
{
return self::where($params)->first($fields);
}
/**
* 获取信息-多条
* @param array $params
* @param array $fields
* @return object|null
*/
public static function getList(array $params, array $fields = ['*']): object|null
{
return self::where($params)->get($fields);
}
/**
* 新增
* @param array $data
* @return DoctorIntroductionRecord|\Hyperf\Database\Model\Model
*/
public static function addDoctorIntroductionRecord(array $data): \Hyperf\Database\Model\Model|DoctorIntroductionRecord
{
return self::create($data);
}
}

View File

@ -14,9 +14,6 @@ class DoctorAuthRequest extends FormRequest
'card_name',
'card_num'
],
'getAuthIden' => [ // 获取身份认证信息
'source',// 来源1:身份认证 2:简介)
],
'addAuthIden' => [ // 新增身份认证信息
'avatar',
'hospital_id',
@ -37,6 +34,12 @@ class DoctorAuthRequest extends FormRequest
'id_card_back',
'sign_image'
],
'putDoctorIntroduction' => [ // 修改个人简介
'avatar',
'brief_introduction',
'be_good_at',
'doctor_expertise',
],
];
/**

View File

@ -4,8 +4,10 @@ namespace App\Services;
use App\Constants\DoctorTitleCode;
use App\Constants\HttpEnumCode;
use App\Model\DiseaseClassExpertise;
use App\Model\DoctorExpertise;
use App\Model\DoctorIdenFail;
use App\Model\DoctorIntroductionRecord;
use App\Model\Hospital;
use App\Model\HospitalDepartmentCustom;
use App\Model\User;
@ -233,14 +235,13 @@ class DoctorAuthService extends BaseService
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$source = $this->request->input('source'); // 来源1:身份认证 2:简介)
// 获取医生数据
$fields = [
'doctor_id',
'user_id',
'idcard_status',
'iden_auth_status',
'introduction_status',
'avatar',
'hospital_id',
'department_custom_id',
@ -273,42 +274,40 @@ class DoctorAuthService extends BaseService
// 职称转换
$result['doctor_title_name'] = empty($doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($doctor['doctor_title']);
if ($source == 1){
// 获取医生详情数据
$result['license_cert'] = [];
$result['qualification_cert'] = [];
$result['work_cert'] = [];
// 获取医生详情数据
$result['license_cert'] = [];
$result['qualification_cert'] = [];
$result['work_cert'] = [];
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$user_doctor_info = UserDoctorInfo::getOne($params);
if (!empty($user_doctor_info)) {
// 医师执业证
if (!empty($user_doctor_info['license_cert'])) {
$license_cert = explode(',', $user_doctor_info['license_cert']);
foreach ($license_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['license_cert'] = $license_cert;
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$user_doctor_info = UserDoctorInfo::getOne($params);
if (!empty($user_doctor_info)) {
// 医师执业证
if (!empty($user_doctor_info['license_cert'])) {
$license_cert = explode(',', $user_doctor_info['license_cert']);
foreach ($license_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['license_cert'] = $license_cert;
}
// 医师职称证
if (!empty($user_doctor_info['qualification_cert'])) {
$qualification_cert = explode(',', $user_doctor_info['qualification_cert']);
foreach ($qualification_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['qualification_cert'] = $qualification_cert;
// 医师职称证
if (!empty($user_doctor_info['qualification_cert'])) {
$qualification_cert = explode(',', $user_doctor_info['qualification_cert']);
foreach ($qualification_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['qualification_cert'] = $qualification_cert;
}
// 医师资格证
if (!empty($user_doctor_info['work_cert'])) {
$work_cert = explode(',', $user_doctor_info['work_cert']);
foreach ($work_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['work_cert'] = $work_cert;
// 医师资格证
if (!empty($user_doctor_info['work_cert'])) {
$work_cert = explode(',', $user_doctor_info['work_cert']);
foreach ($work_cert as &$item) {
$item = addAliyunOssWebsite($item);
}
$result['work_cert'] = $work_cert;
}
}
@ -778,7 +777,7 @@ class DoctorAuthService extends BaseService
return success(null);
}
$result = array();
$result = null;
foreach ($doctor_iden_fails as $doctor_iden_fail) {
$result[$doctor_iden_fail['field_name']] = $doctor_iden_fail['fail_reason'];
}
@ -824,23 +823,304 @@ class DoctorAuthService extends BaseService
return success(null);
}
$result = null;
foreach ($doctor_iden_fails as $doctor_iden_fail) {
// 头像
if ($doctor_iden_fail['field_name'] == "avatar") {
$result['avatar_reason'] = $doctor_iden_fail['fail_reason'];
$result[$doctor_iden_fail['field_name']] = $doctor_iden_fail['fail_reason'];
}
// 医生简介
if ($doctor_iden_fail['field_name'] == "brief_introduction") {
$result['brief_introduction_reason'] = $doctor_iden_fail['fail_reason'];
$result[$doctor_iden_fail['field_name']] = $doctor_iden_fail['fail_reason'];
}
// 擅长
if ($doctor_iden_fail['field_name'] == "be_good_at") {
$result['be_good_at_reason'] = $doctor_iden_fail['fail_reason'];
$result[$doctor_iden_fail['field_name']] = $doctor_iden_fail['fail_reason'];
}
}
return $result;
return success($result);
}
/**
* 获取个人简介
* @return array
*/
public function getDoctorIntroduction(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
// 获取医生数据
$fields = [
'doctor_id',
'user_id',
'idcard_status',
'iden_auth_status',
'introduction_status',
'avatar',
'hospital_id',
'department_custom_id',
'department_custom_name',
'department_custom_mobile',
'doctor_title',
'brief_introduction',
'be_good_at',
];
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$doctor = UserDoctor::getOne($params, $fields);
if (empty($doctor)) {
return fail(HttpEnumCode::HTTP_ERROR, "未知医生");
}
// 实名认证状态0:未认证 1:认证通过 2:认证失败)
if ($doctor['idcard_status'] != 1) {
return fail(HttpEnumCode::HTTP_ERROR, "请先实名认证");
}
$result = $doctor->toArray();
// 头像
if (!empty($doctor['avatar'])) {
$result['avatar'] = addAliyunOssWebsite($doctor['avatar']);
}
// 职称转换
$result['doctor_title_name'] = empty($doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($doctor['doctor_title']);
// 获取医生医院
$result['hospital'] = [];
$fields = [
'hospital_id',
'hospital_name',
'hospital_level_name',
'province_id',
'province',
'city_id',
'city',
'county_id',
'county',
];
$params = array();
$params['hospital_id'] = $doctor['hospital_id'];
$hospital = Hospital::getOne($params, $fields);
if (!empty($hospital)) {
$result['hospital'] = $hospital;
}
// 获取医生已选择专长
$UserDoctorService = new UserDoctorService();
$result['doctor_expertise'] = $UserDoctorService->getDoctorSelectedExpertise($doctor['doctor_id']);
if ($doctor['introduction_status'] == 2 || $doctor['introduction_status'] == 3){
// 获取修改数据
$params = array();
$params['doctor_id'] = $doctor['doctor_id'];
$params['is_verified'] = 0;
$doctor_introduction_record = DoctorIntroductionRecord::getOne($params);
if (empty($doctor_introduction_record)){
return fail();
}
if (!empty($doctor_introduction_record['avatar'])){
$result['avatar'] = PcreMatch::pregRemoveOssWebsite($doctor_introduction_record['avatar']);
}
if (!empty($doctor_introduction_record['be_good_at'])){
$result['be_good_at'] = $doctor_introduction_record['be_good_at'];
}
if (!empty($doctor_introduction_record['brief_introduction'])){
$result['brief_introduction'] = $doctor_introduction_record['brief_introduction'];
}
// 处理专长
if (!empty($doctor_introduction_record['expertise_ids'])){
$result['doctor_expertise'] = array();
$expertise_ids = explode(',',$doctor_introduction_record['expertise_ids']);
foreach ($expertise_ids as $expertise_id){
$params = array();
$params['expertise_id'] = $expertise_id;
$disease_class_expertise = DiseaseClassExpertise::getOne($params);
if (empty($disease_class_expertise)){
return fail();
}
$data = array();
$data['expertise_id'] = $expertise_id;
$data['expertise_name'] = $disease_class_expertise['expertise_name'];
$result['doctor_expertise'][] = $data;
}
}
}
return success($result);
}
/**
* 修改个人简介
* @return array
*/
public function putDoctorIntroduction(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$request_params = $this->request->all();
// 获取医生数据
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$doctor = UserDoctor::getOne($params);
if (empty($doctor)) {
return fail(HttpEnumCode::HTTP_ERROR, "未知医生");
}
// 实名认证状态0:未认证 1:认证通过 2:认证失败)
if ($doctor['idcard_status'] != 1) {
return fail(HttpEnumCode::HTTP_ERROR, "请先实名认证");
}
// 身份认证状态0:未认证 1:认证通过 2:审核中 3:认证失败)
if ($doctor['iden_auth_status'] != 1) {
return fail(HttpEnumCode::HTTP_ERROR, "请先完成身份认证");
}
// 个人简介审核状态0:未审核 1:审核通过 2:审核中 3:审核失败)
if ($doctor['introduction_status'] == 0){
return fail(HttpEnumCode::HTTP_ERROR, "未审核,暂不允许修改");
}
if ($doctor['introduction_status'] == 2){
return fail(HttpEnumCode::HTTP_ERROR, "审核中,暂不允许修改");
}
// 组合存储数据
$doctor_introduction_record_data = array();
// 头像
$request_params['avatar'] = PcreMatch::pregRemoveOssWebsite($request_params['avatar']);
if ($doctor['avatar'] != $request_params['avatar']) {
$doctor_introduction_record_data['avatar'] = $request_params['avatar'];
}
// 医生简介
if ($doctor['brief_introduction'] != $request_params['brief_introduction']) {
$doctor_introduction_record_data['brief_introduction'] = $request_params['brief_introduction'];
}
// 擅长领域
if ($doctor['be_good_at'] != $request_params['be_good_at']) {
$doctor_introduction_record_data['be_good_at'] = $request_params['be_good_at'];
}
//已选择专长列表
$expertise_ids = [];
// 获取医生专长
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$doctor_expertise = DoctorExpertise::getList($params);
if (!empty($doctor_expertise)) {
$expertise_ids = array_column($doctor_expertise->toArray(), 'expertise_id');
}
// 对比已选择专长
// 对比专长是否删除
$is_delete_expertise = array_diff($request_params['doctor_expertise'], $expertise_ids);
// 对比专长是否新增
if (empty($is_delete_expertise)) {
$is_add_expertise = array_diff($expertise_ids, $request_params['doctor_expertise']);
}
// 专长是否改动false未改动 true已改动
$expertise_is_change = false;
if (!empty($is_delete_expertise) || !empty($is_add_expertise)) {
$doctor_introduction_record_data['expertise_ids'] = implode(',',$request_params['doctor_expertise']);
$expertise_is_change = true;
}
if (empty($doctor_introduction_record_data)){
// 未修改
return success();
}
// 审核失败,重新提交,判断被审核错误字段数据是否更改
if ($doctor['introduction_status'] == 3){
// 获取认证失败字段
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$doctor_iden_fails = DoctorIdenFail::getList($params);
if (!empty($doctor_iden_fails)){
foreach ($doctor_iden_fails as $doctor_iden_fail){
// 头像
if ($doctor_iden_fail['field_name'] == "avatar") {
if ($doctor['avatar'] == $request_params['avatar']){
return fail(HttpEnumCode::HTTP_ERROR,"医生头像" . $doctor_iden_fail['fail_reason']);
}
}
// 医生简介
if ($doctor_iden_fail['field_name'] == "brief_introduction") {
if ($doctor['brief_introduction'] == $request_params['brief_introduction']){
return fail(HttpEnumCode::HTTP_ERROR,"医生简介" . $doctor_iden_fail['fail_reason']);
}
}
// 擅长领域
if ($doctor_iden_fail['field_name'] == "be_good_at") {
if ($doctor['be_good_at'] == $request_params['be_good_at']){
return fail(HttpEnumCode::HTTP_ERROR,"擅长领域" . $doctor_iden_fail['fail_reason']);
}
}
// 专长
if ($doctor_iden_fail['field_name'] == "expertise_ids") {
if (!$expertise_is_change){
return fail(HttpEnumCode::HTTP_ERROR,"专长" . $doctor_iden_fail['fail_reason']);
}
}
}
}
}
Db::beginTransaction();
try {
// 新增医生简介修改记录表
$doctor_introduction_record_data['doctor_id'] = $doctor['doctor_id'];
$doctor_introduction_record_data['is_verified'] = 0;
$doctor_introduction_record = DoctorIntroductionRecord::addDoctorIntroductionRecord($doctor_introduction_record_data);
if (empty($doctor_introduction_record)){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
// 修改医生表个人简介审核状态
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$data = array();
$data['introduction_status'] = 2;
$data['updated_at'] = date('Y-m-d H:i:s', time());
$res = UserDoctor::editUserDoctor($params, $data);
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
Db::commit();
} catch (\Exception $e) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
return success();
}
}

View File

@ -148,6 +148,7 @@ class IndexService extends BaseService
"iden_auth_status",
"iden_auth_fail_reason",
"multi_point_status",
"introduction_status",
"is_bind_bank",
"praise_rate",
"avg_response_time",

View File

@ -73,7 +73,7 @@ Router::addGroup('/doctor', function () {
Router::get('/reason', [DoctorAuthController::class, 'getIdenAuthFailReason']);
});
// 身份认证
// 多点认证
Router::addGroup('/multi', function () {
// 获取多点执业认证信息
Router::get('', [DoctorAuthController::class, 'getAuthMulti']);
@ -84,8 +84,11 @@ Router::addGroup('/doctor', function () {
// 个人简介
Router::addGroup('/introduction', function () {
// 获取个人简介
Router::get('', [DoctorAuthController::class, 'getDoctorIntroduction']);
// 修改个人简介
Router::put('', [DoctorAuthController::class, 'addDoctorIntroduction']);
Router::put('', [DoctorAuthController::class, 'putDoctorIntroduction']);
// 获取个人简介审核失败原因
Router::get('/reason', [DoctorAuthController::class, 'getDoctorIntroductionFailReason']);