修正无医生数据
This commit is contained in:
@@ -3,11 +3,19 @@
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Amqp\Producer\AssignDoctorProducer;
|
||||
use App\Constants\DoctorTitleCode;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Hospital;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserPatient;
|
||||
use App\Services\BaseService;
|
||||
use App\Services\ImService;
|
||||
use App\Utils\Log;
|
||||
use Extend\TencentIm\Account;
|
||||
use Extend\TencentIm\Message;
|
||||
use Extend\TencentIm\Profile;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
@@ -25,8 +33,6 @@ class CallBackController extends AbstractController
|
||||
*/
|
||||
public function wxPaySuccessCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1);
|
||||
@@ -35,7 +41,6 @@ class CallBackController extends AbstractController
|
||||
|
||||
$message = $server->getRequestMessage();
|
||||
if (empty($message)){
|
||||
Db::rollBack();
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
@@ -45,7 +50,6 @@ class CallBackController extends AbstractController
|
||||
Log::getInstance()->info("微信支付回调数据:" . json_encode($message->toArray(),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("微信支付回调数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
@@ -55,7 +59,6 @@ class CallBackController extends AbstractController
|
||||
$params['inquiry_no'] = $message['out_trade_no'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("非法订单");
|
||||
return $server->serve();
|
||||
}
|
||||
@@ -63,7 +66,6 @@ class CallBackController extends AbstractController
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1){
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
@@ -103,8 +105,13 @@ class CallBackController extends AbstractController
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
// 处理分配医生问题
|
||||
try {
|
||||
if ($message['trade_state'] == "SUCCESS"){
|
||||
if ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||
// 快速-购药
|
||||
@@ -116,27 +123,62 @@ class CallBackController extends AbstractController
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$result = $producer->produce($message);
|
||||
if (!$result) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("加入分配医生队列失败");
|
||||
return $this->wxPayErrorReturn("加入分配医生队列失败");
|
||||
return $server->serve();
|
||||
}
|
||||
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||
// 专家-公益
|
||||
// 创建患者im账号
|
||||
// 检测医生im账号
|
||||
// 患者给医生发送im问诊消息
|
||||
// 消息订阅通知队列
|
||||
$ImService = new ImService();
|
||||
|
||||
// 检测并创建患者账号
|
||||
$ImService->createAccount($order_inquiry['user_id']);
|
||||
|
||||
// 获取订单医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
Log::getInstance()->info("医生数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 检测并创建医生账号
|
||||
$ImService->createAccount($user_doctor['user_id']);
|
||||
|
||||
// 医生给患者发送消息
|
||||
$message = new Message();
|
||||
|
||||
$arg = array();
|
||||
$arg['From_Account'] = $user_doctor['user_id']; // 发送方user_id 如系统发送,无需填写
|
||||
$arg['To_Account'] = $order_inquiry['user_id']; // 接收方user_id
|
||||
|
||||
$arg['MsgBody'] = [
|
||||
[
|
||||
"MsgType" => "TIMTextElem",
|
||||
"MsgContent" => [
|
||||
"Text" => "等待医生接诊",
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// 自定义消息
|
||||
$cloud_custom_data = array();
|
||||
$cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$cloud_custom_data['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||||
$cloud_custom_data['message_type'] = 1;//1:系统发送 其余:用户发送
|
||||
|
||||
$arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$message->sendMessage($arg);
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $server->serve();
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
Log::getInstance()->error("微信支付回调数据处理成功,发送系统问诊消息失败:" . $e->getMessage());
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
public function wxPayRefundCallBack(): ResponseInterface
|
||||
|
||||
Reference in New Issue
Block a user