新增分配医生队列
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Amqp\Producer\AssignDoctorProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Services\BaseService;
|
||||
use App\Utils\Log;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\HttpMessage\Stream\SwooleFileStream;
|
||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class CallBackController extends AbstractController
|
||||
@@ -46,7 +49,6 @@ class CallBackController extends AbstractController
|
||||
Log::getInstance()->info("微信支付回调数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
dump($message);
|
||||
|
||||
// 查询订单
|
||||
$params = array();
|
||||
@@ -57,7 +59,6 @@ class CallBackController extends AbstractController
|
||||
Log::getInstance()->info("非法订单");
|
||||
return $server->serve();
|
||||
}
|
||||
dump(1);
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1){
|
||||
@@ -66,7 +67,7 @@ class CallBackController extends AbstractController
|
||||
Log::getInstance()->info("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
dump(2);
|
||||
|
||||
// 支付状态无需验证,如第一次支付失败,会修改支付状态,再次支付时,会出现验证不通过的情况
|
||||
|
||||
// 修改支付状态
|
||||
@@ -75,6 +76,13 @@ class CallBackController extends AbstractController
|
||||
// 支付成功
|
||||
$data['inquiry_pay_status'] = 2;
|
||||
$data['pay_time'] = date('Y-m-d H:i:s',strtotime($message['success_time']));// 支付时间
|
||||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||
// 专家-公益
|
||||
$data['inquiry_status'] = 3;// 3:待接诊
|
||||
}elseif ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||
// 快速-购药
|
||||
$data['inquiry_status'] = 2;// 2:待分配
|
||||
}
|
||||
}elseif($message['trade_state'] == "CLOSED"){
|
||||
// 已关闭
|
||||
$data['inquiry_pay_status'] = 6;
|
||||
@@ -95,17 +103,59 @@ class CallBackController extends AbstractController
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
dump(3);
|
||||
|
||||
// 处理分配医生问题
|
||||
if ($message['trade_state'] == "SUCCESS"){
|
||||
if ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||
// 快速-购药
|
||||
// 加入分配医生队列
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
|
||||
$message = new AssignDoctorProducer($data);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$result = $producer->produce($message);
|
||||
if (!$result) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("加入分配医生队列失败");
|
||||
return $this->wxPayErrorReturn("加入分配医生队列失败");
|
||||
}
|
||||
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||
// 专家-公益
|
||||
// 创建患者im账号
|
||||
// 检测医生im账号
|
||||
// 患者给医生发送im问诊消息
|
||||
// 消息订阅通知队列
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $server->serve();
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付返回错误响应
|
||||
* @param string $message
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function wxPayErrorReturn(string $message): ResponseInterface
|
||||
{
|
||||
return $this->response
|
||||
->withStatus(500)
|
||||
->withBody(
|
||||
new SwooleStream(
|
||||
strval(
|
||||
json_encode(['code' => 'ERROR', 'message' => $message], JSON_UNESCAPED_UNICODE)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
// im回调
|
||||
public function imCallBack(){
|
||||
$request_params = $this->request->all();
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Controller;
|
||||
use App\Amqp\Producer\PrescriptionDistributePhProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\DoctorInquiryTime;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Request\UserRequest;
|
||||
use App\Services\UserDoctorService;
|
||||
use App\Services\UserService;
|
||||
@@ -78,21 +80,42 @@ class UserController extends AbstractController
|
||||
// $wx_info_data = $weChat->codeToSession("0219AIFa1ROoUE0e4lIa1bO27I29AIF9");
|
||||
// dump($wx_info_data);die;
|
||||
|
||||
$out_trade_no = $this->request->input('out_trade_no');
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
// 发起支付
|
||||
// $out_trade_no = $this->request->input('out_trade_no');
|
||||
// $generator = $this->container->get(IdGeneratorInterface::class);
|
||||
//
|
||||
// $WechatPay = new WechatPay(1);
|
||||
//
|
||||
// // 获取预支付交易会话标识
|
||||
// $total = 0.01 * 100;
|
||||
// $prepay = $WechatPay->getJsapiPrepayId($out_trade_no,$total,"omgU35DlE-rxTAGgcBjOuc4xdcX8");
|
||||
// if (empty($prepay)){
|
||||
// return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
// }
|
||||
//
|
||||
// // 获取小程序支付配置
|
||||
// $pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
// return $this->response->json($pay_config);
|
||||
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$total = 0.01 * 100;
|
||||
$prepay = $WechatPay->getJsapiPrepayId($out_trade_no,$total,"omgU35DlE-rxTAGgcBjOuc4xdcX8");
|
||||
if (empty($prepay)){
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = 1;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
return $this->response->json($pay_config);
|
||||
|
||||
$options = array();
|
||||
$options['transaction_id'] = $order_inquiry['escrow_trade_no'];
|
||||
$options['out_refund_no'] = $order_inquiry['inquiry_refund_no'];
|
||||
$options['reason'] = "退款原因";
|
||||
$options['amount'] = [
|
||||
'refund' => 0.01 * 100,
|
||||
'total' => 0.01 * 100,
|
||||
'currency' => "CNY",
|
||||
];
|
||||
|
||||
$result = $WechatPay->refund($options);
|
||||
dump($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user