修改支付事件

This commit is contained in:
邹景立 2021-03-20 18:26:11 +08:00
parent 4aca36f285
commit 8892a6fa2b
2 changed files with 11 additions and 8 deletions

View File

@ -290,7 +290,7 @@ abstract class PaymentService
if (empty($data['payment_type'])) unset($data['payment_type']); if (empty($data['payment_type'])) unset($data['payment_type']);
$this->app->db->name('ShopOrder')->where($map)->update($data); $this->app->db->name('ShopOrder')->where($map)->update($data);
// 触发订单更新事件 // 触发订单更新事件
if (in_array($status, [4, 5])) { if ($status >= 4) {
$this->app->event->trigger('ShopOrderPayment', $orderNo); $this->app->event->trigger('ShopOrderPayment', $orderNo);
} }
return true; return true;

View File

@ -10,7 +10,9 @@ use app\data\service\UserBalanceService;
use app\data\service\UserRebateService; use app\data\service\UserRebateService;
use think\Console; use think\Console;
if (app()->request->isCli()) { $app = app();
if ($app->request->isCli()) {
Console::starting(function (Console $console) { Console::starting(function (Console $console) {
$console->addCommand(OrderClean::class); $console->addCommand(OrderClean::class);
$console->addCommand(UserAmount::class); $console->addCommand(UserAmount::class);
@ -19,19 +21,20 @@ if (app()->request->isCli()) {
}); });
} else { } else {
// 注册订单支付处理事件 // 注册订单支付处理事件
app()->event->listen('ShopOrderPayment', function ($orderNo) { $app->event->listen('ShopOrderPayment', function ($orderNo) use ($app) {
app()->log->notice("订单 {$orderNo} 支付事件,执行用户升级行为"); $app->log->notice("订单 {$orderNo} 支付事件,执行用户升级行为");
OrderService::instance()->upgrade($orderNo); OrderService::instance()->upgrade($orderNo);
app()->log->notice("订单 {$orderNo} 支付事件,执行用户返利行为"); $app->log->notice("订单 {$orderNo} 支付事件,执行用户返利行为");
RebateService::instance()->execute($orderNo); RebateService::instance()->execute($orderNo);
app()->log->notice("订单 {$orderNo} 支付事件,执行发放余额行为"); $app->log->notice("订单 {$orderNo} 支付事件,执行发放余额行为");
UserBalanceService::instance()->confirm($orderNo); UserBalanceService::instance()->confirm($orderNo);
}); });
// 注册订单确认支付事件 // 注册订单确认支付事件
app()->event->listen('ShopOrderConfirm', function ($orderNo) { $app->event->listen('ShopOrderConfirm', function ($orderNo) use ($app) {
app()->log->notice("订单 {$orderNo} 确认事件,执行返利确认行为"); $app->log->notice("订单 {$orderNo} 确认事件,执行返利确认行为");
UserRebateService::instance()->confirm($orderNo); UserRebateService::instance()->confirm($orderNo);
}); });
} }