| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace Modules\Api\Controllers;
- use App\Events\PayTotalEvent;
- use App\Exceptions\ApiException;
- use App\Models\OrderModel;
- use App\Models\PaymentModel;
- use App\Repositories\OrderRepository;
- use App\Repositories\Service\Payment\PaymentInterface;
- use Illuminate\Support\Facades\Cache;
- class OrderController
- {
- public function notify($orderId, $payCode)
- {
- logger(json_encode(request()->all()) . '发送回调信息!');
- // 写回调记录
- if (empty($orderId) || empty($payCode)) {
- throw new ApiException('参数错误');
- }
- $orderId = intval($orderId);
- $payCode = strval($payCode);
- $orderInfo = OrderModel::query()->where('id', $orderId)->first();
- if (empty($orderInfo)) {
- throw new ApiException('订单异常!');
- }
- $payInterface = PaymentInterface::factory($payCode);
- if ($orderInfo->status == 2) {
- return $payInterface->stopNotify();
- }
- $payment = PaymentModel::query()->where('pay_code', $payCode)->first(['partner_id']);
- $result = $payInterface->notify($orderSn, $tradeNo, $money, $payment->partner_id);
- if ($result) {
- $orderRes = app(OrderRepository::class)->doBuy($orderInfo->toArray(), $tradeNo, $money);
- if ($orderRes) {
- event(new PayTotalEvent($orderInfo->merchant_uid, $orderInfo->payment_uid, $orderInfo->payment_attr_uid, $orderInfo->real_amount, 2));
- return $payInterface->stopNotify();
- }
- }
- return 'nook';
- }
- }
|