erp/app/api/controller/PayController.php
2024-05-07 10:41:58 +08:00

47 lines
1.4 KiB
PHP

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