erp_old/app/api/controller/PayController.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2024-04-30 14:14:30 +08:00
<?php
namespace app\api\controller;
2024-05-07 09:20:37 +08:00
use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic;
use app\common\model\retail\Cashierclass;
2024-05-07 10:41:58 +08:00
use app\common\service\pay\PayService;
2024-04-30 14:14:30 +08:00
/**
* 支付
* Class PayController
* @package app\api\controller
*/
class PayController extends BaseApiController
{
2024-05-07 09:54:16 +08:00
public $notNeedLogin = ['notifyMnp'];
2024-04-30 14:14:30 +08:00
/**
* @notes 小程序支付回调
*/
public function notifyMnp()
{
2024-05-07 10:41:58 +08:00
$app=new PayService(1);
$result = $app->wechat->callback(Request()->post());
2024-05-07 09:45:43 +08:00
if($result && $result->event_type=='TRANSACTION.SUCCESS'){
2024-05-07 09:49:11 +08:00
$ciphertext=$result->resource['ciphertext'];
2024-05-07 09:45:43 +08:00
if ($ciphertext['trade_state'] === 'SUCCESS') {
$extra['transaction_id'] = $ciphertext['transaction_id'];
$attach = $ciphertext['attach'];
switch ($attach) {
case 'cashierclass':
2024-05-07 09:54:16 +08:00
$order = Cashierclass::where(['number' => $ciphertext['out_trade_no']])->findOrEmpty();
2024-05-07 09:45:43 +08:00
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
return true;
}
2024-05-07 09:54:16 +08:00
PayNotifyLogic::handle('cashierclass', $ciphertext['out_trade_no'], $ciphertext);
2024-05-07 10:41:58 +08:00
$app->wechat->success();
2024-05-07 09:45:43 +08:00
break;
}
2024-05-07 09:20:37 +08:00
}
}
2024-04-30 14:14:30 +08:00
}
}