新增
This commit is contained in:
@@ -4,11 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\controller\order;
|
||||
|
||||
use app\adminapi\logic\order\OrderLogic;
|
||||
use app\common\model\Order;
|
||||
use think\response\Xml;
|
||||
|
||||
/**
|
||||
* 微信支付回调控制器
|
||||
* 支持:1) 预创建订单的支付 2) 员工直接在企业微信发起对外收款(自动创建订单)
|
||||
* Class WechatNotifyController
|
||||
* @package app\adminapi\controller\order
|
||||
*/
|
||||
@@ -33,24 +35,36 @@ class WechatNotifyController
|
||||
return $this->xmlResponse('FAIL', '签名验证失败');
|
||||
}
|
||||
|
||||
// 验证金额
|
||||
$order = Order::where('order_no', $data['out_trade_no'])->find();
|
||||
$outTradeNo = $data['out_trade_no'] ?? '';
|
||||
$totalFee = (int)($data['total_fee'] ?? 0);
|
||||
$amount = $totalFee / 100;
|
||||
$transactionId = $data['transaction_id'] ?? '';
|
||||
|
||||
$order = Order::where('order_no', $outTradeNo)->find();
|
||||
|
||||
if (!$order) {
|
||||
// 订单不存在:员工直接在企业微信发起收款,自动创建订单并标记已支付
|
||||
if ($data['result_code'] == 'SUCCESS' && $totalFee > 0) {
|
||||
$newOrder = OrderLogic::createFromCallback($outTradeNo, $amount, $transactionId);
|
||||
if ($newOrder) {
|
||||
return $this->xmlResponse('SUCCESS', '支付成功');
|
||||
}
|
||||
}
|
||||
return $this->xmlResponse('FAIL', '订单不存在');
|
||||
}
|
||||
|
||||
if ((int)$data['total_fee'] != (int)($order->amount * 100)) {
|
||||
if ($totalFee != (int)($order->amount * 100)) {
|
||||
return $this->xmlResponse('FAIL', '金额不匹配');
|
||||
}
|
||||
|
||||
// 验证交易状态
|
||||
if ($data['result_code'] == 'SUCCESS') {
|
||||
// 更新订单状态
|
||||
// 更新订单状态(支持普通微信支付及企业微信对外收款)
|
||||
if ($order->status == 1) { // 只有待支付的订单才能更新
|
||||
$order->status = 2; // 已支付
|
||||
$order->payment_method = 'wechat';
|
||||
$order->payment_time = date('Y-m-d H:i:s');
|
||||
$order->trade_no = $data['transaction_id'];
|
||||
$order->trade_no = $transactionId;
|
||||
$order->save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user