|
|
@ -5,7 +5,9 @@ namespace App\Controller; |
|
|
use App\Constants\LogLabel; |
|
|
use App\Constants\LogLabel; |
|
|
use App\Model\OrderMain; |
|
|
use App\Model\OrderMain; |
|
|
use EasyWeChat\Factory; |
|
|
use EasyWeChat\Factory; |
|
|
|
|
|
use Hyperf\DbConnection\Db; |
|
|
use Hyperf\Guzzle\CoroutineHandler; |
|
|
use Hyperf\Guzzle\CoroutineHandler; |
|
|
|
|
|
use Exception; |
|
|
|
|
|
|
|
|
class NotifyController extends BaseController |
|
|
class NotifyController extends BaseController |
|
|
{ |
|
|
{ |
|
|
@ -18,32 +20,55 @@ class NotifyController extends BaseController |
|
|
// 通知回调,进行业务处理
|
|
|
// 通知回调,进行业务处理
|
|
|
$response = $app->handlePaidNotify(function ($message, $fail) use ($app) { |
|
|
$response = $app->handlePaidNotify(function ($message, $fail) use ($app) { |
|
|
|
|
|
|
|
|
$this->log->event( |
|
|
|
|
|
LogLabel::PAY_NOTIFY_WXMINI, |
|
|
|
|
|
$message |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 查询订单
|
|
|
|
|
|
$orderMain = OrderMain::query() |
|
|
|
|
|
->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_ONLINE, 'state' => OrderMain::ORDER_STATE_UNPAY]) |
|
|
|
|
|
->where('time', '>=', date('Y-m-d H:i:s', (time()-900))) |
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($orderMain)) { |
|
|
|
|
|
// 去查一下微信订单
|
|
|
|
|
|
$wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id); |
|
|
|
|
|
|
|
|
Db::beginTransaction(); |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
$this->log->event( |
|
|
$this->log->event( |
|
|
LogLabel::PAY_NOTIFY_WXMINI, |
|
|
LogLabel::PAY_NOTIFY_WXMINI, |
|
|
$wxOrder |
|
|
|
|
|
|
|
|
$message |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 查询订单
|
|
|
|
|
|
$orderMain = OrderMain::query() |
|
|
|
|
|
->where(['global_order_id' => $message['out_trade_no'], 'type' => OrderMain::ORDER_TYPE_ONLINE, 'state' => OrderMain::ORDER_STATE_UNPAY]) |
|
|
|
|
|
->where('time', '>=', date('Y-m-d H:i:s', (time()-900))) |
|
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($orderMain)) { |
|
|
|
|
|
// 去查一下微信订单
|
|
|
|
|
|
$wxOrder = $app->order->queryByOutTradeNumber($orderMain->global_order_id); |
|
|
|
|
|
|
|
|
|
|
|
$this->log->event( |
|
|
|
|
|
LogLabel::PAY_NOTIFY_WXMINI, |
|
|
|
|
|
$wxOrder |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 修改订单、子订单状态
|
|
|
|
|
|
$currentTime = time(); |
|
|
|
|
|
$orderMain->state = OrderMain::ORDER_STATE_UNTAKE; |
|
|
|
|
|
$orderMain->time_pay = $currentTime; |
|
|
|
|
|
$orderMain->pay_time = date('Y-m-d H:i:s', $currentTime); |
|
|
|
|
|
$orderMain->save(); |
|
|
|
|
|
|
|
|
|
|
|
// 更新销量、商品库存,新增月销数据
|
|
|
|
|
|
|
|
|
// 修改订单、子订单状态
|
|
|
|
|
|
|
|
|
// 喇叭通知,兼容旧音响,MQTT+IOT
|
|
|
|
|
|
|
|
|
|
|
|
// 公众号模板消息
|
|
|
|
|
|
|
|
|
|
|
|
// 打印订单
|
|
|
|
|
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
|
|
|
|
|
Db::rollBack(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 更新销量、商品库存,新增月销数据
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
$response->send(); |
|
|
$response->send(); |
|
|
|