From e59aa4e049f645544e4c54c5b84f0dc4b41ea268 Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Wed, 30 Apr 2025 19:03:24 +0800 Subject: [PATCH] no message --- app/routes.php | 3 +- public/tests/hook.php | 19 +++++++++++ resources/views/tabler/user/index.tpl | 3 +- resources/views/tabler/user/order/create.tpl | 7 ++++ src/Command/Cron.php | 12 +++---- src/Controllers/TestController.php | 7 ++-- src/Controllers/TomApi/HuodongController.php | 32 ++++++++++++++++++ src/Controllers/User/CouponController.php | 24 ++++++++++++-- src/Controllers/User/OrderController.php | 33 ++++++++++++++++++ src/Models/Huodong.php | 35 ++++++++++++++++++++ src/Services/Cron.php | 32 +++++++++++------- 11 files changed, 180 insertions(+), 27 deletions(-) create mode 100644 src/Controllers/TomApi/HuodongController.php create mode 100755 src/Models/Huodong.php diff --git a/app/routes.php b/app/routes.php index a23076f5..c9521f80 100755 --- a/app/routes.php +++ b/app/routes.php @@ -16,7 +16,8 @@ return static function (Slim\App $app): void { // test $app->get('/my', App\Controllers\MyController::class . ':index'); - + // tom通用api + $app->get('/api/huodong/findbydate/{date}', App\Controllers\TomApi\HuodongController::class . ':findByDate'); // gembox 日后分离出去 $app->group('/gembox', static function (RouteCollectorProxy $group): void { diff --git a/public/tests/hook.php b/public/tests/hook.php index 9e3da6ef..7efe38a8 100644 --- a/public/tests/hook.php +++ b/public/tests/hook.php @@ -73,6 +73,25 @@ $oHttp->aData['message']['text'] = '\/tk#ry__1 aasd'; $oHttp->aData['message']['text'] = '\/tk#list'; +$oHttp->aData['message']['text'] = '\/user#report__day__300'; + +$oHttp->aData['message']['text'] = '\/coupon#list'; + +$oHttp->aData['message']['text'] = '\/coupon#Like__name v'; + +$oHttp->aData['message']['text'] = '\/coupon#set__3__name ss1v'; + +$oHttp->aData['message']['text'] = '\/coupon#set__3__expire_time 2025-01-03 22:22:22#totime'; + +$oHttp->aData['message']['text'] = '\/coupon#clone 3'; + +$oHttp->aData['message']['text'] = '\/coupon#del 11'; + +$oHttp->aData['message']['text'] = '\/user#limit 10'; + +//$oHttp->aData['message']['text'] = '\/coupon#findById 3'; + + //{ // "update_id": 761180998, // "message": { diff --git a/resources/views/tabler/user/index.tpl b/resources/views/tabler/user/index.tpl index 80eee0cf..4e78176a 100755 --- a/resources/views/tabler/user/index.tpl +++ b/resources/views/tabler/user/index.tpl @@ -503,8 +503,7 @@

{if $user->class === 0} - 未购买套餐, - 购买一个套餐 + 未购买套餐,请先购买一个套餐 {else} 您的【{$class}】订阅会在 {$class_expire_days} 天后到期({$user->class_expire}) {/if} diff --git a/resources/views/tabler/user/order/create.tpl b/resources/views/tabler/user/order/create.tpl index 64d95f46..f6f66519 100755 --- a/resources/views/tabler/user/order/create.tpl +++ b/resources/views/tabler/user/order/create.tpl @@ -148,6 +148,13 @@ $('#coupon-code').text($('#coupon').val()); $('#product-buy-discount').text(data.discount); $('#product-buy-total').text(data.buy_price); + } else if (data.ret === 2) { + $('#coupon-code').text($('#coupon').val()); + $('#product-buy-discount').text(data.discount); + $('#product-buy-total').text(data.buy_price); + + $('#success-message').text(data.msg); + $('#success-dialog').modal('show'); } else { $('#fail-message').text(data.msg); $('#fail-dialog').modal('show'); diff --git a/src/Command/Cron.php b/src/Command/Cron.php index eb512241..9eaac085 100755 --- a/src/Command/Cron.php +++ b/src/Command/Cron.php @@ -33,14 +33,14 @@ EOL; $jobs = new CronService(); // Run new shop related jobs - $jobs->processPendingOrder(); - $jobs->processTabpOrderActivation(); - $jobs->processBandwidthOrderActivation(); - $jobs->processTimeOrderActivation(); + $jobs->processPendingOrder(); // 标记订单 - 待激活,超时 + $jobs->processTabpOrderActivation(); // 激活订单,过期订单(不重置用户流量) + $jobs->processBandwidthOrderActivation(); // 流量包处理,没用 + $jobs->processTimeOrderActivation(); // 时间包处理,没用 // Run user related jobs - $jobs->expirePaidUserAccount(); - $jobs->sendPaidUserUsageLimitNotification(); + $jobs->expirePaidUserAccount(); // 重置套餐用户流量 + $jobs->sendPaidUserUsageLimitNotification(); // 流量预警 // Run node related jobs $jobs->updateNodeIp(); diff --git a/src/Controllers/TestController.php b/src/Controllers/TestController.php index 265565ab..a1e0d12b 100755 --- a/src/Controllers/TestController.php +++ b/src/Controllers/TestController.php @@ -19,7 +19,7 @@ use App\Services\Reward; use App\Services\TomTool\Http; use App\Services\TomTool\VisitorCount; - +use App\Command\Cron; session_start(); final class TestController extends BaseController @@ -82,10 +82,9 @@ final class TestController extends BaseController public function test2() { - $_SESSION['test'] = 333; - var_dump($_SESSION); + $oCron = new Cron(); + $oCron->boot(); - http_response_code(200);exit; } public function test3() diff --git a/src/Controllers/TomApi/HuodongController.php b/src/Controllers/TomApi/HuodongController.php new file mode 100644 index 00000000..9004a564 --- /dev/null +++ b/src/Controllers/TomApi/HuodongController.php @@ -0,0 +1,32 @@ +where("end_date", ">=", $sFindDate)->first(); + + if ($oHuodong) { + echo json_encode($oHuodong); + } + + exit; + + } + +} diff --git a/src/Controllers/User/CouponController.php b/src/Controllers/User/CouponController.php index 91dfb9cd..290f4f42 100755 --- a/src/Controllers/User/CouponController.php +++ b/src/Controllers/User/CouponController.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Controllers\User; use App\Controllers\BaseController; +use App\Models\Huodong; use App\Models\Order; use App\Models\Product; use App\Models\UserCoupon; @@ -88,6 +89,25 @@ final class CouponController extends BaseController } $content = json_decode($coupon->content); + + $iRet = 1; + $sMsg = "优惠码可用"; + + $sDateNow = date("Y-m-d"); +// $sDateNow = "2025-05-02"; + $oHuodong = Huodong::where("start_date", "<=", $sDateNow)->where("end_date", ">=", $sDateNow)->first(); + + if ($oHuodong) { + if ($oHuodong->class == "A") { + if ($content->type === 'percentage') { + + $content->value = $oHuodong->coupon_global; + $iRet = 2; + $sMsg = '该优惠码可用,在【'.$oHuodong->title.'】期间视为-'.$oHuodong->coupon_global.'%优惠。'; + + } + } + } if ($content->type === 'percentage') { $discount = $product->price * $content->value / 100; @@ -98,8 +118,8 @@ final class CouponController extends BaseController $buy_price = $product->price - $discount; return $response->withJson([ - 'ret' => 1, - 'msg' => '优惠码可用', + 'ret' => $iRet, + 'msg' => $sMsg, 'discount' => $discount, 'buy_price' => $buy_price, ]); diff --git a/src/Controllers/User/OrderController.php b/src/Controllers/User/OrderController.php index a4dbc281..8e0fbf4f 100755 --- a/src/Controllers/User/OrderController.php +++ b/src/Controllers/User/OrderController.php @@ -9,6 +9,7 @@ use App\Models\Invoice; use App\Models\Order; use App\Models\Product; use App\Models\UserCoupon; +use App\Models\Huodong; use App\Utils\Cookie; use App\Utils\Tools; use Exception; @@ -138,6 +139,20 @@ final class OrderController extends BaseController if ($coupon_raw !== '') { $coupon = (new UserCoupon())->where('code', $coupon_raw)->first(); + + //// start 特别活动禁用优惠码 || 不禁用了,变为调整 +// if ($oHuodong) { +// if ($oHuodong->class == "A") { +// // 月套餐以上禁用优惠码 +// if ($product->type_by_time > 32) { +// return $response->withJson([ +// 'ret' => 0, +// 'msg' => '该商品在【'.$oHuodong->title.'】期间不能使用优惠码', +// ]); +// } +// } +// } + //// end if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) { return $response->withJson([ @@ -188,6 +203,21 @@ final class OrderController extends BaseController } $content = json_decode($coupon->content); + + //// start 特别活动期间限制优惠码额度 + $sDateNow = date("Y-m-d"); +// $sDateNow = "2025-05-02"; + + $oHuodong = Huodong::where("start_date", "<=", $sDateNow)->where("end_date", ">=", $sDateNow)->first(); + + if ($oHuodong !== null) { + if ($oHuodong->class == "A") { + if ($content->type === 'percentage') { + $content->value = $oHuodong->coupon_global; + } + } + } + //// end if ($content->type === 'percentage') { $discount = $product->price * $content->value / 100; @@ -236,6 +266,9 @@ final class OrderController extends BaseController $order->status = 'pending_payment'; $order->create_time = time(); $order->update_time = time(); + if (isset($oHuodong) && $oHuodong !== null && $oHuodong->class) { + $order->huodong_class = $oHuodong->class; + } $order->save(); $invoice_content = []; diff --git a/src/Models/Huodong.php b/src/Models/Huodong.php new file mode 100755 index 00000000..bd7a2400 --- /dev/null +++ b/src/Models/Huodong.php @@ -0,0 +1,35 @@ +type) { +// 'howto' => '使用', +// 'billing' => '财务', +// 'account' => '账户', +// default => '其他', +// }; +// } + +} diff --git a/src/Services/Cron.php b/src/Services/Cron.php index b17293ea..2efcfaad 100755 --- a/src/Services/Cron.php +++ b/src/Services/Cron.php @@ -579,18 +579,26 @@ final class Cron //// end //// * 特别活动追加,季套餐赠月套餐,年套餐赠季套餐 -// if ($order->huodong_class && $order->huodong_class == "A") { -// -// $oProduct = Product::where("name", $order->product_name) -// ->where("type_by_time", "<", $content->class_time) -// ->orderBy("type_by_time", "desc") -// ->first(); -// $oProductContent = json_decode($oProduct->content); -// -// $content->class_time += $oProductContent->class_time; -// $content->bandwidth += $oProductContent->bandwidth; -// -// } + if ($order->huodong_class && $order->huodong_class == "A") { + + // 按理是大于30天,做个冗余 + if ($content->class_time > 32) { + + $oProduct = Product::where("name", $order->product_name) + ->where("type_by_time", "<", $content->class_time) + ->orderBy("type_by_time", "desc") + ->first(); + + if ($oProduct) { + $oProductContent = json_decode($oProduct->content); + + $content->class_time += $oProductContent->class_time; + $content->bandwidth += $oProductContent->bandwidth; + } + + } + + } //// end // 激活TABP