Просмотр исходного кода

到期自动结束的计划任务

lizhen_gitee 1 месяц назад
Родитель
Сommit
106e35e20f
3 измененных файлов с 56 добавлено и 2 удалено
  1. 4 0
      app/Console/Kernel.php
  2. 50 0
      app/Jobs/AskFinishJob.php
  3. 2 2
      app/Wen/Utils/OrderUtils.php

+ 4 - 0
app/Console/Kernel.php

@@ -35,6 +35,7 @@ use App\Jobs\User\UserDeleteAfterJob;
 use App\Jobs\User\UserWithdrawalProcessJob;
 use App\Jobs\User\UserWithdrawalQueryJob;
 use App\Jobs\UserRobotExpIncreaseJob;
+use App\Jobs\AskFinishJob;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 use Illuminate\Support\Facades\Cache;
@@ -106,6 +107,9 @@ class Kernel extends ConsoleKernel
         $schedule->job(new UpdatePostTenantObjJob(0))->everyTenMinutes();
         $schedule->job(new TmpMetaClearJob())->everySixHours();
 
+        //已支付咨询订单到期自动结束
+        $schedule->job(new AskFinishJob())->everyMinute();
+
         $schedule->job(new CollecterPublishPostsJob)->everyTenMinutes();
         Cache::put('schedule', 1, 120);
         $this->queueCheck();

+ 50 - 0
app/Jobs/AskFinishJob.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Wen\Utils\Settings;
+use App\Wen\Utils\UserUtils;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\DB;
+
+class AskFinishJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        //已支付状态,且倒计时时间已经到了。给修改为结束
+        $where = [
+            ['status','=',10],
+            ['countdown_time','<',time() - 120],  //延迟2分钟
+        ];
+
+        $update = [
+            'status' => 20,
+            'finish_time' => time(),
+        ];
+
+        DB::table('ask_order')->where($where)->update($update);
+
+    }
+}

+ 2 - 2
app/Wen/Utils/OrderUtils.php

@@ -316,9 +316,9 @@ class OrderUtils{
         }else if($type == 101){
             //咨询订单  ask_order
             $ask_minute = DB::table($WxOrder->table_name)->where('id',$WxOrder->table_id)->value('ask_minute');
-            $finish_time = $ask_minute * 60 + time();
+            $countdown_time = $ask_minute * 60 + time(); //倒计时时间
 
-            DB::table($WxOrder->table_name)->where('id',$WxOrder->table_id)->update(['status'=>10,'paytime'=>time(),'finish_time'=>$finish_time]);
+            DB::table($WxOrder->table_name)->where('id',$WxOrder->table_id)->update(['status'=>10,'paytime'=>time(),'countdown_time'=>$countdown_time]);
         }else if($type == 102){
             //旁听订单  ask_sit_order
             DB::table($WxOrder->table_name)->where('id',$WxOrder->table_id)->update(['status'=>10,'paytime'=>time()]);