静态调用app

This commit is contained in:
Anyon 2022-07-12 10:51:41 +08:00
parent 708d6bc3be
commit a12f7599a2
2 changed files with 11 additions and 11 deletions

View File

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

View File

@ -17,14 +17,15 @@
use app\wechat\command\Auto; use app\wechat\command\Auto;
use app\wechat\command\Fans; use app\wechat\command\Fans;
use app\wechat\service\AutoService; use app\wechat\service\AutoService;
use think\admin\Library;
use think\Console; use think\Console;
if (app()->request->isCli()) { if (Library::$sapp->request->isCli()) {
Console::starting(function (Console $console) { Console::starting(function (Console $console) {
$console->addCommands([Fans::class, Auto::class]); $console->addCommands([Fans::class, Auto::class]);
}); });
} else { } else {
app()->event->listen('WechatFansSubscribe', function ($openid) { Library::$sapp->event->listen('WechatFansSubscribe', function ($openid) {
AutoService::register($openid); AutoService::register($openid);
}); });
} }