新增药品订单支付回调
This commit is contained in:
parent
54214fb5e9
commit
2a4b4f41fa
@ -10,6 +10,10 @@ use App\Model\Hospital;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserPatient;
|
||||
@ -34,30 +38,30 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class CallBackController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 患者端微信支付回调
|
||||
* 患者端问诊微信支付回调
|
||||
* @return ResponseInterface
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function wxPaySuccessCallBack(): ResponseInterface
|
||||
public function wxPayInquirySuccessCallBack(): ResponseInterface
|
||||
{
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1);
|
||||
$WechatPay = new WechatPay(1,1);
|
||||
$app = $WechatPay->createApp();
|
||||
$server = $app->getServer();
|
||||
|
||||
$message = $server->getRequestMessage();
|
||||
if (empty($message)){
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "问诊微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
// 验证推送消息签名
|
||||
$app->getValidator()->validate($app->getRequest());
|
||||
|
||||
Log::getInstance()->info("微信支付回调数据:" . json_encode($message->toArray(),JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance()->info("问诊微信支付回调数据:" . json_encode($message->toArray(),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])){
|
||||
Log::getInstance()->info("微信支付回调数据错误");
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -66,14 +70,14 @@ class CallBackController extends AbstractController
|
||||
$params['inquiry_no'] = $message['out_trade_no'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
Log::getInstance()->info("非法订单");
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1){
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Log::getInstance()->info("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,订单状态当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -114,15 +118,18 @@ class CallBackController extends AbstractController
|
||||
OrderInquiry::edit($params,$data);
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
Log::getInstance()->error("问诊微信支付回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信支付回调处理成功");
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理成功");
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理成功,开始分配医生/发送问诊消息");
|
||||
|
||||
try {
|
||||
if ($message['trade_state'] == "SUCCESS"){
|
||||
if ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||
Log::getInstance()->info("加入分配医生队列");
|
||||
|
||||
// 快速-购药
|
||||
// 加入分配医生队列
|
||||
$data = array();
|
||||
@ -135,6 +142,8 @@ class CallBackController extends AbstractController
|
||||
Log::getInstance()->info("加入分配医生队列失败");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
Log::getInstance()->info("加入分配医生队列成功");
|
||||
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||
// 专家-公益,发送im消息
|
||||
Log::getInstance()->info("开始发送im消息");
|
||||
@ -158,29 +167,29 @@ class CallBackController extends AbstractController
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("微信支付回调数据处理成功,发送系统问诊消息失败:" . $e->getMessage());
|
||||
Log::getInstance()->error("问诊微信支付回调数据处理成功,分配医生/发送问诊消息失败:" . $e->getMessage());
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信支付回调处理成功");
|
||||
Log::getInstance()->info("问诊微信支付回调处理成功");
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款回调
|
||||
* 微信问诊退款回调
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function wxPayRefundCallBack(): ResponseInterface
|
||||
public function wxPayInquiryRefundCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1);
|
||||
$WechatPay = new WechatPay(1,1);
|
||||
$app = $WechatPay->createApp();
|
||||
$server = $app->getServer();
|
||||
|
||||
@ -281,6 +290,251 @@ class CallBackController extends AbstractController
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者端药品微信支付回调
|
||||
* @return ResponseInterface
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function wxPayProductSuccessCallBack(): ResponseInterface
|
||||
{
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1,2);
|
||||
$app = $WechatPay->createApp();
|
||||
$server = $app->getServer();
|
||||
|
||||
$message = $server->getRequestMessage();
|
||||
if (empty($message)){
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "药品微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
// 验证推送消息签名
|
||||
$app->getValidator()->validate($app->getRequest());
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据:" . json_encode($message->toArray(),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])){
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据验证成功,执行数据库操作");
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 查询药品订单
|
||||
$params = array();
|
||||
$params['order_product_no'] = $message['out_trade_no'];
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,订单状态当前为" . $order_product['order_product_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 支付状态无需验证,如第一次支付失败,会修改支付状态,再次支付时,会出现验证不通过的情况
|
||||
|
||||
// 修改支付状态
|
||||
$data = array();
|
||||
if ($message['trade_state'] == "SUCCESS"){
|
||||
// 支付成功
|
||||
$data['order_product_status'] = 2;
|
||||
$data['pay_status'] = 2;// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
|
||||
}elseif($message['trade_state'] == "CLOSED"){
|
||||
// 已关闭
|
||||
$data['pay_status'] = 6;
|
||||
}elseif($message['trade_state'] == "REVOKED"){
|
||||
// 已撤销(付款码支付)
|
||||
$data['pay_status'] = 7;
|
||||
}elseif($message['trade_state'] == "USERPAYING"){
|
||||
// 用户支付中(付款码支付)
|
||||
$data['pay_status'] = 3;
|
||||
}elseif($message['trade_state'] == "PAYERROR"){
|
||||
// 支付失败(其他原因,如银行返回失败)
|
||||
$data['pay_status'] = 4;
|
||||
}
|
||||
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$data['updated_at'] = date('Y-m-d H:i:s',time());
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
|
||||
// 获取订单商品订单列表
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,未查询到对应订单商品订单列表");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 修改库存,去除锁定
|
||||
foreach ($order_product_item as $item){
|
||||
// 释放锁定库存
|
||||
$params = array();
|
||||
$params['product_id'] = $item['product_id'];
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,未查询到对应订单商品订单列表");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 锁定库存-订单商品数量 = 实际锁定库存数量
|
||||
$params = array();
|
||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
||||
ProductPlatformAmount::dec($params, 'lock_stock', (float)$item['amount']);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据验证成功");
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信药品退款回调
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function wxPayProductRefundCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1,1);
|
||||
$app = $WechatPay->createApp();
|
||||
$server = $app->getServer();
|
||||
|
||||
$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))));
|
||||
}
|
||||
|
||||
// 验证推送消息签名
|
||||
$app->getValidator()->validate($app->getRequest());
|
||||
|
||||
Log::getInstance()->info("微信退款回调数据:" . json_encode($message->toArray(),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])){
|
||||
Log::getInstance()->info("微信退款回调数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $message['out_trade_no'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
Log::getInstance()->info("非法订单");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 1){
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Log::getInstance()->info("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
|
||||
// 验证订单退款状态
|
||||
if ($order_inquiry['inquiry_refund_status'] == 3) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
Log::getInstance()->info("订单退款状态错误:当前为" . $order_inquiry['inquiry_refund_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if (in_array($order_inquiry['inquiry_pay_status'],[1,3,4,5,6,7])) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
Log::getInstance()->error("队列执行失败原因:订单未支付");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 退款状态
|
||||
if ($message['refund_status'] == "SUCCESS"){
|
||||
// 退款成功
|
||||
$inquiry_refund_status = 3;
|
||||
}elseif ($message['refund_status'] == "CLOSED"){
|
||||
// 退款关闭
|
||||
$inquiry_refund_status = 5;
|
||||
}elseif ($message['refund_status'] == "ABNORMAL"){
|
||||
// 退款异常
|
||||
$inquiry_refund_status = 6;
|
||||
}
|
||||
|
||||
if (empty($inquiry_refund_status)){
|
||||
// 错误,无退款状态
|
||||
Log::getInstance()->error("队列执行失败原因:订单未支付");
|
||||
return $this->wxPayErrorReturn("退款状态错误");
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
$data['success_time'] = $message['success_time'];
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiryRefund::edit($params,$data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信退款回调处理成功");
|
||||
|
||||
// 发送短信消息
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付返回错误响应
|
||||
* @param string $message
|
||||
@ -495,4 +749,5 @@ class CallBackController extends AbstractController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -90,18 +90,18 @@ class UserController extends AbstractController
|
||||
$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,2);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$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);
|
||||
|
||||
@ -154,7 +154,13 @@ class BasicDataService extends BaseService
|
||||
$params[] = ['disease_class_name', 'like', '%' . $disease_class_name . '%'];
|
||||
$disease_class = DiseaseClass::getList($params, $fields);
|
||||
if (empty($disease_class)){
|
||||
return success();
|
||||
$params = array();
|
||||
$params[] = ["disease_class_status", 1];
|
||||
$params[] = ["disease_class_enable", 1];
|
||||
$disease_class = DiseaseClass::getList($params, $fields);
|
||||
if(empty($disease_class)){
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -634,7 +634,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款接口
|
||||
* 问诊订单退款接口
|
||||
* 务必外层接收异常,回滚事务
|
||||
* @param string $order_inquiry_id
|
||||
* @param string $refund_reason 退款原因
|
||||
@ -670,7 +670,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1);
|
||||
$WechatPay = new WechatPay(1,1);
|
||||
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
|
||||
|
||||
@ -111,12 +111,12 @@ class OrderProductService extends BaseService
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 库存+1
|
||||
// 库存+订单商品数量
|
||||
$params = array();
|
||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
||||
ProductPlatformAmount::inc($params, 'stock', (float)$item['amount']);
|
||||
|
||||
// 锁定库存-1
|
||||
// 锁定库存-订单商品数量
|
||||
ProductPlatformAmount::dec($params, 'lock_stock', (float)$item['amount']);
|
||||
}
|
||||
|
||||
|
||||
@ -622,6 +622,18 @@ class PatientOrderService extends BaseService
|
||||
$payment_amount_total = $order_inquiry['payment_amount_total'];
|
||||
$coupon_amount_total = $order_inquiry['coupon_amount_total'];
|
||||
|
||||
// 发起支付
|
||||
$WechatPay = new WechatPay(1,1);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
||||
if (empty($prepay)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
|
||||
} elseif ($order_type == 2) {
|
||||
// 药品订单
|
||||
$params = array();
|
||||
@ -650,22 +662,22 @@ class PatientOrderService extends BaseService
|
||||
$amount_total = $order_product['amount_total'];
|
||||
$payment_amount_total = $order_product['payment_amount_total'];
|
||||
$coupon_amount_total = 0;
|
||||
|
||||
// 发起支付
|
||||
$WechatPay = new WechatPay(1,2);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
||||
if (empty($prepay)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
} else {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
$WechatPay = new WechatPay(1);
|
||||
|
||||
// 获取预支付交易会话标识
|
||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
||||
if (empty($prepay)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 获取小程序支付配置
|
||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||
|
||||
$result = array();
|
||||
$result['amount_total'] = $amount_total; // 订单金额
|
||||
$result['payment_amount_total'] = $payment_amount_total; // 实际订单金额
|
||||
@ -715,16 +727,6 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
}
|
||||
|
||||
// 检测是否已经存在药品订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_product = OrderProduct::getExists($params);
|
||||
if ($order_product) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||||
}
|
||||
|
||||
// 检测收货地址
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
@ -890,7 +892,7 @@ class PatientOrderService extends BaseService
|
||||
$data['order_type'] = 2;
|
||||
|
||||
$message = new CancelUnpayOrdersDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * 30 * 1);
|
||||
$message->setDelayMs(1000 * 60 * 30);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
|
||||
@ -41,8 +41,10 @@ return [
|
||||
"patient" => [
|
||||
"app_id" => env('PATIENT_WECHAT_APP_ID', 'wx70a196902e0841b6'),
|
||||
"secret" => env('PATIENT_WECHAT_APP_SECRET', '2671d2f4285180ddec5a5a2b16ed50f2'),
|
||||
"pay_notify_url" => env('PATIENT_WECHAT_PAY_NOTIFY_URL', 'callback/wxpay/inquiry/success'),
|
||||
"refund_notify_url" => env('PATIENT_WECHAT_REFUND_NOTIFY_URL', 'callback/wxpay/inquiry/refund'),
|
||||
"inquiry_pay_notify_url" => env('PATIENT_WECHAT_INQUIRY_PAY_NOTIFY_URL', 'callback/wxpay/inquiry/success'),
|
||||
"inquiry_refund_notify_url" => env('PATIENT_WECHAT_INQUIRY_REFUND_NOTIFY_URL', 'callback/wxpay/inquiry/refund'),
|
||||
"product_pay_notify_url" => env('PATIENT_WECHAT_PRODUCT_PAY_NOTIFY_URL', 'callback/wxpay/product/success'),
|
||||
"product_refund_notify_url" => env('PATIENT_WECHAT_PRODUCT_REFUND_NOTIFY_URL', 'callback/wxpay/product/refund'),
|
||||
],
|
||||
"pay" => [
|
||||
"mch_id" => env('PATIENT_WECHAT_MCH_ID', '1636644248'),
|
||||
|
||||
@ -443,10 +443,18 @@ Router::addGroup('/callback', function () {
|
||||
// 问诊
|
||||
Router::addGroup('/inquiry', function () {
|
||||
// 支付成功回调
|
||||
Router::post('/success', [CallBackController::class, 'wxPaySuccessCallBack']);
|
||||
Router::post('/success', [CallBackController::class, 'wxPayInquirySuccessCallBack']);
|
||||
|
||||
// 退款回调
|
||||
Router::post('/refund', [CallBackController::class, 'wxPayRefundCallBack']);
|
||||
Router::post('/refund', [CallBackController::class, 'wxPayInquiryRefundCallBack']);
|
||||
});
|
||||
// 药品
|
||||
Router::addGroup('/product', function () {
|
||||
// 支付成功回调
|
||||
Router::post('/success', [CallBackController::class, 'wxPayProductSuccessCallBack']);
|
||||
|
||||
// 退款回调
|
||||
Router::post('/refund', [CallBackController::class, 'wxPayProductRefundCallBack']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -21,11 +21,14 @@ class WechatPay
|
||||
{
|
||||
protected array $config;// 系统配置
|
||||
protected array $pay_config;// 支付系统配置
|
||||
protected string $pay_notify_url;// 支付回调地址
|
||||
protected string $refund_notify_url;// 退款回调地址
|
||||
|
||||
/**
|
||||
* @param string $user_type
|
||||
* @param string $user_type 用户类型(1:患者端 2:专家端 3:药师端)
|
||||
* @param int $order_type 订单类型(1:问诊订单 2:药品订单)
|
||||
*/
|
||||
public function __construct(string $user_type)
|
||||
public function __construct(string $user_type,int $order_type)
|
||||
{
|
||||
if ($user_type == 1){
|
||||
$this->config = config("we_chat.applets.patient");
|
||||
@ -40,6 +43,20 @@ class WechatPay
|
||||
if (empty($this->config)){
|
||||
throw new BusinessException("系统配置错误", HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (!in_array($order_type,[1,2])){
|
||||
throw new BusinessException("订单类型错误", HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
if ($order_type == 1){
|
||||
$this->pay_notify_url = $this->config['inquiry_pay_notify_url'];
|
||||
$this->refund_notify_url = $this->config['inquiry_refund_notify_url'];
|
||||
}
|
||||
|
||||
if ($order_type == 2){
|
||||
$this->pay_notify_url = $this->config['product_pay_notify_url'];
|
||||
$this->refund_notify_url = $this->config['product_refund_notify_url'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +126,7 @@ class WechatPay
|
||||
"out_trade_no" => $out_trade_no, // 商户系统内部订单号
|
||||
"appid" => $this->config['app_id'],
|
||||
"description" => "问诊服务",
|
||||
"notify_url" => env('DOMAIN_NAME_DEV') . $this->config['pay_notify_url'],
|
||||
"notify_url" => env('DOMAIN_NAME_DEV') . $this->pay_notify_url,
|
||||
"amount" => [
|
||||
"total" => $total,//订单总金额,单位为分。
|
||||
"currency" => "CNY"
|
||||
@ -178,7 +195,7 @@ class WechatPay
|
||||
try {
|
||||
$app = $this->createApp();
|
||||
|
||||
$options['notify_url'] = env('DOMAIN_NAME_DEV') . $this->config['refund_notify_url'];
|
||||
$options['notify_url'] = env('DOMAIN_NAME_DEV') . $this->refund_notify_url;
|
||||
|
||||
$response = $app->getClient()->postJson("v3/refund/domestic/refunds", $options);
|
||||
if ($response->isFailed()) {
|
||||
|
||||
@ -36,8 +36,10 @@ JWT_ALGO=HS256
|
||||
# [WECHAT]
|
||||
PATIENT_WECHAT_APP_ID=wx70a196902e0841b6
|
||||
PATIENT_WECHAT_APP_SECRET=2671d2f4285180ddec5a5a2b16ed50f2
|
||||
PATIENT_WECHAT_PAY_NOTIFY_URL=callback/wxpay/inquiry/success
|
||||
PATIENT_WECHAT_REFUND_NOTIFY_URL=callback/wxpay/inquiry/refund
|
||||
PATIENT_WECHAT_INQUIRY_PAY_NOTIFY_URL=callback/wxpay/inquiry/success
|
||||
PATIENT_WECHAT_INQUIRY_REFUND_NOTIFY_URL=callback/wxpay/inquiry/refund
|
||||
PATIENT_WECHAT_PRODUCT_PAY_NOTIFY_URL=callback/wxpay/product/success
|
||||
PATIENT_WECHAT_PRODUCT_REFUND_NOTIFY_URL=callback/wxpay/product/refund
|
||||
|
||||
# [DOCTOR]
|
||||
# [WECHAT]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user