69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年10月3日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\models\common\notify\payment;
|
|
|
|
use app\models\Model;
|
|
use app\models\PaymentTypes;
|
|
|
|
class PaymentNotify extends Model
|
|
{
|
|
/**
|
|
* 支付回调后续处理
|
|
* @param PaymentOrderUnion $paymentOrderUnion
|
|
* @return mixed
|
|
*/
|
|
public function notify($paymentOrderUnion)
|
|
{
|
|
$paymentOrders = \app\models\PaymentOrder::find()
|
|
->where(['payment_order_union_id' => $paymentOrderUnion->id, 'notify_status' => [0,2]])
|
|
->all();
|
|
foreach ($paymentOrders as $paymentOrder) {
|
|
if($paymentOrder->is_pay != 1){
|
|
$paymentOrder->is_pay = 1;
|
|
$paymentOrder->pay_type = $paymentOrderUnion->pay_type;
|
|
if(!$paymentOrder->save()){
|
|
return $this->getModelError($paymentOrder);
|
|
}
|
|
}
|
|
$po = new \app\models\common\payment\PaymentOrder([
|
|
'orderNo' => $paymentOrder->order_no,
|
|
'amount' => (float)$paymentOrder->amount,
|
|
'title' => $paymentOrder->title,
|
|
'notifyClass' => $paymentOrder->notify_class,
|
|
'payType' => PaymentTypes::payTypeIdToKey($paymentOrder->pay_type),
|
|
]);
|
|
$NotifyClass = $paymentOrder->notify_class;
|
|
if(class_exists($NotifyClass)){
|
|
/** @var PaymentNotify $notifyObject */
|
|
$notifyObject = new $NotifyClass();
|
|
try {
|
|
$resp = $notifyObject->notify($po);
|
|
if($resp['code'] != 0){
|
|
$msg = "[ORDER_NO:{$paymentOrder->order_no}] ERR_MSG:{$resp['msg']}";
|
|
\Yii::error($msg,'NotifyPayment');
|
|
}
|
|
} catch (\Exception $exception) {
|
|
$exp_err = $exception->getMessage();
|
|
$msg = "[ORDER_NO:{$paymentOrder->order_no}] ERR_MSG:{$exp_err}";
|
|
\Yii::error($msg,'NotifyPayment');
|
|
}
|
|
} else {
|
|
//记录错误
|
|
$msg = "[ORDER_NO:{$paymentOrder->order_no}] ERR_MSG:{$paymentOrder->notify_class}不存在";
|
|
\Yii::error($msg,'NotifyPayment');
|
|
}
|
|
}
|
|
return $this->apiReturnSuccess();
|
|
}
|
|
}
|
|
|