新增阿里云oss上传文件

This commit is contained in:
wucongxing 2023-03-02 16:51:47 +08:00
parent d51d5355a0
commit 186f92c4ea
11 changed files with 188 additions and 159 deletions

View File

@ -134,5 +134,5 @@ function addAliyunOssWebsite($path): string
if (empty($path)){
return "";
}
return "https://" . config('alibaba.oss.bucket') . '.' .config('alibaba.oss.endpoint') . $path;
return config('alibaba.oss.custom_domain_name') . '/' . $path;
}

View File

@ -276,4 +276,15 @@ class UserDoctorController extends AbstractController
$data = $UserDoctorService->addPrescription();
return $this->response->json($data);
}
/**
* 获取医生名片
* @return ResponseInterface
*/
public function getDoctorInfoCard(): ResponseInterface
{
$UserDoctorService = new UserDoctorService();
$data = $UserDoctorService->getDoctorInfoCard();
return $this->response->json($data);
}
}

View File

@ -15,8 +15,8 @@ use Hyperf\Snowflake\Concern\Snowflake;
use Hyperf\Utils\Arr;
/**
* @property int $doctor_id 主键
* @property int $user_id 用户id
* @property string $doctor_id 主键
* @property string $user_id 用户id
* @property string $user_name 用户名称
* @property string $open_id 微信open_id
* @property string $union_id 微信开放平台唯一标识
@ -34,10 +34,10 @@ use Hyperf\Utils\Arr;
* @property int $age 年龄
* @property string $avatar 头像
* @property int $doctor_title 医生职称1:执业医师 2:主治医师 3:副主任医师 4:主任医师)
* @property int $department_custom_id 科室id-自定义
* @property string $department_custom_id 科室id-自定义
* @property string $department_custom_name 科室名称(如未自己输入,填入标准科室名称)
* @property string $department_custom_mobile 科室电话
* @property int $hospital_id 所属医院id
* @property string $hospital_id 所属医院id
* @property int $served_patients_num 服务患者数量
* @property string $praise_rate 好评率百分制。订单平均评价中超过4-5分的订单总数 / 总订单数 * 5
* @property string $avg_response_time 平均响应时间(分钟制)
@ -48,14 +48,15 @@ use Hyperf\Utils\Arr;
* @property int $is_img_quick_reception 是否参加快速图文接诊0: 1:是)
* @property int $is_platform_deep_cooperation 是否平台深度合作医生0: 1:是)
* @property int $is_enterprise_deep_cooperation 是否企业深度合作医生0: 1:是)
* @property string $qr_code 分享二维码
* @property string $be_good_at 擅长
* @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
{
@ -69,12 +70,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', 'be_good_at', 'brief_introduction', 'created_at', 'updated_at'];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['doctor_id' => 'string', 'user_id' => 'string', 'status' => 'integer', 'idcard_status' => 'integer', 'iden_auth_status' => 'integer', 'multi_point_status' => 'integer', 'is_bind_bank' => 'integer', 'is_recommend' => 'integer', 'sex' => 'integer', 'age' => 'integer', 'doctor_title' => 'integer', 'department_custom_id' => 'string', 'hospital_id' => 'string', 'served_patients_num' => 'integer', 'number_of_fans' => 'integer', 'is_online' => 'integer', 'is_img_expert_reception' => 'integer', 'is_img_welfare_reception' => 'integer', 'is_img_quick_reception' => 'integer', 'is_platform_deep_cooperation' => 'integer', 'is_enterprise_deep_cooperation' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
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 string $primaryKey = "doctor_id";

View File

@ -41,6 +41,10 @@ class SafeService extends BaseService
// 证书
$dir = $dir . 'cert/';
break;
case 3:
// 名片
$dir = $dir . 'card/';
break;
default:
// code...

View File

@ -3,6 +3,7 @@
namespace App\Services;
use App\Amqp\Producer\PrescriptionDistributePhProducer;
use App\Constants\DoctorTitleCode;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\BasicBank;
@ -14,6 +15,7 @@ use App\Model\DoctorBankCard;
use App\Model\DoctorExpertise;
use App\Model\DoctorInquiryConfig;
use App\Model\DoctorWord;
use App\Model\Hospital;
use App\Model\InquiryCaseProduct;
use App\Model\OrderEvaluation;
use App\Model\OrderInquiry;
@ -27,12 +29,19 @@ use App\Model\User;
use App\Model\UserDoctor;
use App\Model\UserDoctorInfo;
use App\Utils\Mask;
use Extend\Alibaba\Oss;
use Extend\Wechat\Wechat;
use Hyperf\Amqp\Producer;
use Hyperf\DbConnection\Db;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class UserDoctorService extends BaseService
{
@ -1097,9 +1106,9 @@ class UserDoctorService extends BaseService
return fail();
}
if (in_array($order_inquiry['inquiry_status'], [1, 2,3,6,7])){
if (in_array($order_inquiry['inquiry_status'], [1, 2, 3, 6, 7])) {
// 问诊订单状态1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
return fail(HttpEnumCode::HTTP_ERROR,"订单无法开具处方");
return fail(HttpEnumCode::HTTP_ERROR, "订单无法开具处方");
}
// 检测处方是否重复开具
@ -1108,7 +1117,7 @@ class UserDoctorService extends BaseService
$params['doctor_id'] = $user_info['client_user_id'];
$order_prescription = OrderPrescription::getOne($params);
if (!empty($order_prescription)) {
return fail(HttpEnumCode::HTTP_ERROR,"订单已开具处方,无法重复开具");
return fail(HttpEnumCode::HTTP_ERROR, "订单已开具处方,无法重复开具");
}
Db::beginTransaction();
@ -1127,9 +1136,9 @@ class UserDoctorService extends BaseService
$data['patient_age'] = $order_inquiry['patient_age'];
$data['doctor_advice'] = $doctor_advice;
$order_prescription = OrderPrescription::addOrderPrescription($data);
if (empty($order_prescription)){
if (empty($order_prescription)) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR,"处方开具失败");
return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败");
}
foreach ($prescription_icd as $item) {
@ -1224,6 +1233,89 @@ class UserDoctorService extends BaseService
return success();
}
/**
* 获取医生名片
* @throws NotFoundExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ContainerExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function getDoctorInfoCard(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
// 获取医生信息
$params = array();
$params['doctor_id'] = $user_info['client_user_id'];
$fields = [
'doctor_id',
'iden_auth_status',
'idcard_status',
'multi_point_status',
'hospital_id',
];
$user_doctor = UserDoctor::getOne($params, $fields);
if (empty($user_doctor)) {
return fail(HttpEnumCode::HTTP_ERROR, "非法医生");
}
$res = $this->checkDoctorAuth($user_doctor);
if ($res !== true) {
return fail(HttpEnumCode::HTTP_ERROR, $res);
}
// 获取医生医院
$params = array();
$params['hospital_id'] = $user_doctor['hospital_id'];
$hospital = Hospital::getOne($params);
if (empty($hospital)) {
return fail();
}
// 获取医生分享二维码
$qr_code = $user_doctor['qr_code'];
if (empty($qr_code)){
$weChat = new Wechat(1);
$options = [
"scene" => "doctor_id=" . $user_doctor['doctor_id'],// query 参数
"page" => "",
"check_path" => false,
"env_version" => "develop",
];
$img_buffer = $weChat->getUnlimitedQRCode($options);
$oss = new Oss();
$filename = $user_doctor['doctor_id'] . '.' . 'jpg';
$qr_code = $oss->putObject($filename, $img_buffer);
// 存储至医生表
$params = array();
$params['doctor_id'] = $user_doctor['doctor_id'];
$data = array();
$data['qr_code'] = $qr_code;
UserDoctor::editUserDoctor($params,$data);
}
$result = array();
$result['user_name'] = $user_doctor['user_name'];
$result['doctor_title'] = DoctorTitleCode::getMessage($user_doctor['doctor_title']);
$result['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
$result['department_custom_name'] = $user_doctor['department_custom_name'];
$result['hospital_name'] = $hospital['hospital_name'];
$result['qr_code_url'] = addAliyunOssWebsite($user_doctor['qr_code']);
return success($result);
}
/**
* 检测医生身份认证
* @param object|array $user_doctor 医生表数据

View File

@ -59,6 +59,6 @@ class PcreMatch
return $path;
}
return str_replace('https://' . config('alibaba.oss.bucket') . '.' .config('alibaba.oss.endpoint'),"",$path);
return str_replace(config('alibaba.oss.custom_domain_name'),"",$path);
}
}

View File

@ -1,138 +0,0 @@
<?php
namespace App\Utils;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use EasyWeChat\Kernel\Exceptions\BadResponseException;
use EasyWeChat\Kernel\Exceptions\DecryptException;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\HttpClient\AccessTokenAwareClient;
use EasyWeChat\MiniApp\Application;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
/**
* 废弃
*/
class WeChat
{
protected Application $app;
protected array $config;
protected AccessTokenAwareClient $client;
#[Inject]
protected ContainerInterface $container;
public function __construct()
{
$this->config = config("easy_we_chat");
try {
// 获取WeChat客户端
$this->app = new Application($this->config);
// 替换缓存
$this->app->setCache(ApplicationContext::getContainer()->get(CacheInterface::class));
$this->client = $this->app->getClient();
} catch (InvalidArgumentException $e) {
throw new BusinessException('实例化EasyWeChat类失败:' . $e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 根据 jsCode 获取用户 session 信息
* @param string $code code
* @return array
* @throws ClientExceptionInterface
* @throws DecodingExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
* @throws \Exception
*/
public function codeToSession(string $code): array
{
try {
$utils = $this->app->getUtils();
return $utils->codeToSession($code);
} catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 解密微信会话信息
* @param string $sessionKey 会话密钥
* @param string $iv 加密算法的初始向量
* @param string $encryptedData 用户信息的加密数据
* @return array
*/
public function decryptSession(string $sessionKey, string $iv, string $encryptedData): array
{
try {
$utils = $this->app->getUtils();
return $utils->decryptSession($sessionKey, $iv, $encryptedData);
} catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 获取 access_token
* @return string
*/
public function getAccessToken(): string
{
try {
$accessToken = $this->app->getAccessToken();
return $accessToken->getToken();
} catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
/**
* 获取手机号
* @param string $code
* @return array
* @throws ClientExceptionInterface
* @throws DecodingExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface|BadResponseException
*/
public function getPhone(string $code): array
{
$options = [
"code" => $code,
];
$response = $this->client->postJson('wxa/business/getuserphonenumber', $options);
if ($response->isFailed()) {
// 出错了,处理异常
$result = $response->toArray();
if(empty($result)){
throw new BusinessException( $response->toJson(false),HttpEnumCode::GET_WX_ERROR);
}
if (isset($result['errcode'])){
if ($result['errcode'] == "40029"){
// code过期
throw new BusinessException( HttpEnumCode::getMessage(HttpEnumCode::GET_WX_ERROR),HttpEnumCode::GET_WX_ERROR);
}
}
throw new BusinessException( $response->toJson(false),HttpEnumCode::GET_WX_ERROR);
}
return $response->toArray(false);
}
}

View File

@ -61,6 +61,7 @@ return [
"accessKeySecret" => "q1aiIZCJJuf92YbKk2cSXnPES4zx26",
"bucket" => "gdxz-hospital",
"endpoint" => "oss-cn-chengdu.aliyuncs.com",
"custom_domain_name" => "https://img.applets.igandanyiyuan.com",
],
],
'verify_dun' =>[ // 网易易盾

View File

@ -158,6 +158,9 @@ Router::addGroup('/doctor', function () {
// 获取医生专长列表-身份认证
Router::get('/expertise', [UserDoctorController::class, 'getAuthDoctorExpertise']);
// 获取医生名片
Router::get('/card', [UserDoctorController::class, 'getDoctorInfoCard']);
});
});

View File

@ -79,4 +79,24 @@ class Oss
{
return str_replace('+00:00', '.000Z', gmdate('c', $time));
}
/**
* 上传
* @param string $filename 图片名称
* @param mixed $content 内容 字符串或文件流
* @return string
*/
public function putObject(string $filename, mixed $content): string
{
try {
$ossClient = $this->createClient();
$object = "applet/doctor/card/".$filename;
$ossClient->putObject($this->config['bucket'], $object, $content);
return $object;
}catch(\Exception $e) {
throw new BusinessException($e->getMessage());
}
}
}

View File

@ -217,4 +217,44 @@ class Wechat
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
// 获取分享二维码
/**
* @throws NotFoundExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ContainerExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function getUnlimitedQRCode(array $options){
try {
$this->createApp($this->config['app_id'], $this->config['secret']);
$client = $this->createClient($this->config['app_id'], $this->config['secret']);
$response = $client->postJson('wxa/getwxacodeunlimit', $options);
if ($response->isFailed()) {
// 出错了,处理异常
$result = $response->toArray();
if(empty($result)){
// 返回值为空
return [];
}
if (isset($result['errcode'])){
throw new BusinessException();
}
return [];
}
return $response->getContent(true);
} catch (\Exception $e) {
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
}
}
}