feat(PayController): 修改支付控制器代码,优化了小程序支付回调、微信支付查询等方法,并修复了相关bug。
This commit is contained in:
parent
89db630313
commit
136d9e1714
@ -19,7 +19,7 @@ use support\Log;
|
|||||||
class PayController extends BaseApiController
|
class PayController extends BaseApiController
|
||||||
{
|
{
|
||||||
|
|
||||||
public $notNeedLogin = ['notifyMnp', 'alipay_return', 'alipay_notify','wechatQuery'];
|
public $notNeedLogin = ['notifyMnp', 'alipay_return', 'alipay_notify', 'wechatQuery'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 小程序支付回调
|
* @notes 小程序支付回调
|
||||||
@ -44,19 +44,18 @@ class PayController extends BaseApiController
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if ($result && $result->event_type == 'REFUND.SUCCESS') {
|
if ($result && $result->event_type == 'REFUND.SUCCESS') {
|
||||||
$ciphertext = $result->resource['ciphertext'];
|
$ciphertext = $result->resource['ciphertext'];
|
||||||
if ($ciphertext['refund_status'] === 'SUCCESS') {
|
if ($ciphertext['refund_status'] === 'SUCCESS') {
|
||||||
//处理订单 -1判断是退的一单还是拆分的订单
|
//处理订单 -1判断是退的一单还是拆分的订单
|
||||||
$out_trade_no = $ciphertext['out_trade_no'].'-1';
|
$out_trade_no = $ciphertext['out_trade_no'] . '-1';
|
||||||
$check = StoreOrder::where('order_id',$out_trade_no)->count();
|
$check = StoreOrder::where('order_id', $out_trade_no)->count();
|
||||||
if($check){
|
if ($check) {
|
||||||
$ciphertext['out_trade_no'] =$out_trade_no;
|
$ciphertext['out_trade_no'] = $out_trade_no;
|
||||||
}
|
}
|
||||||
PayNotifyLogic::handle('refund', $ciphertext['out_trade_no'], $ciphertext);
|
PayNotifyLogic::handle('refund', $ciphertext['out_trade_no'], $ciphertext);
|
||||||
$app->wechat->success();
|
$app->wechat->success();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,22 +67,26 @@ class PayController extends BaseApiController
|
|||||||
public function wechatQuery()
|
public function wechatQuery()
|
||||||
{
|
{
|
||||||
$order_no = $this->request->get('order_no');
|
$order_no = $this->request->get('order_no');
|
||||||
$recharge = $this->request->get('recharge',0);
|
$recharge = $this->request->get('recharge', 0);
|
||||||
$order = [
|
$order = [
|
||||||
'out_trade_no' => $order_no,
|
'out_trade_no' => $order_no,
|
||||||
];
|
];
|
||||||
$app = new PayService(0);
|
$app = new PayService(0);
|
||||||
|
|
||||||
|
try {
|
||||||
$res = $app->wechat->query($order);
|
$res = $app->wechat->query($order);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail($e->extra['message']);
|
||||||
|
}
|
||||||
if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') {
|
if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') {
|
||||||
if($recharge==0){
|
if ($recharge == 0) {
|
||||||
PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res);
|
PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res);
|
||||||
}else{
|
} else {
|
||||||
PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res);
|
PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res);
|
||||||
}
|
}
|
||||||
return $this->success('支付成功');
|
return $this->success('支付成功');
|
||||||
} else {
|
} else {
|
||||||
return $this->fail('订单支付中或已失效');
|
return $this->fail('订单支付中');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +100,7 @@ class PayController extends BaseApiController
|
|||||||
if ($result) {
|
if ($result) {
|
||||||
$data = $result->toArray();
|
$data = $result->toArray();
|
||||||
if ($data['trade_status'] === 'TRADE_SUCCESS') {
|
if ($data['trade_status'] === 'TRADE_SUCCESS') {
|
||||||
$attach = $data['extend_params']['attach']??'';
|
$attach = $data['extend_params']['attach'] ?? '';
|
||||||
switch ($attach) {
|
switch ($attach) {
|
||||||
case 'alipay_cashier':
|
case 'alipay_cashier':
|
||||||
PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data);
|
PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data);
|
||||||
@ -117,7 +120,7 @@ class PayController extends BaseApiController
|
|||||||
if ($result) {
|
if ($result) {
|
||||||
$data = $result->toArray();
|
$data = $result->toArray();
|
||||||
if ($data['trade_status'] === 'TRADE_SUCCESS') {
|
if ($data['trade_status'] === 'TRADE_SUCCESS') {
|
||||||
$attach = $data['extend_params']['attach']??'';
|
$attach = $data['extend_params']['attach'] ?? '';
|
||||||
switch ($attach) {
|
switch ($attach) {
|
||||||
case 'alipay_cashier':
|
case 'alipay_cashier':
|
||||||
PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data);
|
PayNotifyLogic::handle('alipay_cashier', $data['out_trade_no'], $data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user