xiaogang 4 tahun lalu
induk
melakukan
57ea3d0492

+ 46 - 0
app/Console/Commands/ClearLimit.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\UserVipLimit;
+use Illuminate\Console\Command;
+
+class ClearLimit extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'chenglu:clear_limit';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '每天凌晨清空用户限制数据';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        /*
+		 * 每天初始化用户限制数据
+		 * */
+        UserVipLimit::query()->update(['weixin'=>0,'user'=>0,'dynamic'=>0,'user_detail'=>0,'user_info'=>0]);
+    }
+}

+ 55 - 0
app/Console/Commands/VipOutTime.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\User;
+use App\Models\UserVipLogModel;
+use Illuminate\Console\Command;
+
+class VipOutTime extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'chenglu:vip_out_time';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '定期检查用户会员是否过期';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        //定期检查用户VIP是否过期
+        $data = UserVipLogModel::query()->where(['status'=>1])->orderBy('end_day','asc')->get();
+        $data = $data->toArray();
+        foreach ($data as $k=>$v){
+            if($v['end_day']<date('Y-m-d H:i:s')){
+                //已经过期
+                UserVipLogModel::query()->where('id',$v['id'])->update(['status'=>0,'updated_at'=>date('Y-m-d H:i:s')]);
+                User::query()->where('id',$v['user_id'])->update(['is_vip'=>0]);
+            }else{
+                break;
+            }
+        }
+    }
+}

+ 8 - 0
app/Console/Kernel.php

@@ -2,6 +2,8 @@
 
 
 namespace App\Console;
 namespace App\Console;
 
 
+use App\Console\Commands\ClearLimit;
+use App\Console\Commands\VipOutTime;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Console\Scheduling\Schedule;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 
 
@@ -14,6 +16,8 @@ class Kernel extends ConsoleKernel
      */
      */
     protected $commands = [
     protected $commands = [
         //
         //
+        ClearLimit::class, //用户限制
+        VipOutTime::class, //VIP过期
     ];
     ];
 
 
     /**
     /**
@@ -25,6 +29,10 @@ class Kernel extends ConsoleKernel
     protected function schedule(Schedule $schedule)
     protected function schedule(Schedule $schedule)
     {
     {
         // $schedule->command('inspire')->hourly();
         // $schedule->command('inspire')->hourly();
+
+        //此处相当于规定同意的定时执行时间,如每天凌晨执行以下任务
+        $schedule->command('chenglu:clear_limit')->daily()->description('每天凌晨自动清空用户限制');
+        $schedule->command('chenglu:vip_out_time')->everyMinute()->description('每分钟检查用户会员是否过期');
     }
     }
 
 
     /**
     /**

+ 0 - 1
app/Services/HomeService.php

@@ -26,7 +26,6 @@ class HomeService
      * @param $param
      * @param $param
      */
      */
     public function get_list($param){
     public function get_list($param){
-
         $query = User::query()
         $query = User::query()
             ->leftJoin("users_info",'users.id','=','users_info.user_id')
             ->leftJoin("users_info",'users.id','=','users_info.user_id')
             ->select(['users.id','users.is_vip','users.tencent_im_user_id','users.sex','users.is_auth','users.latitude','users.longitude','users.online','users_info.avatar','users_info.nickname','users_info.area','users_info.birthday','users_info.height','users_info.weight'])
             ->select(['users.id','users.is_vip','users.tencent_im_user_id','users.sex','users.is_auth','users.latitude','users.longitude','users.online','users_info.avatar','users_info.nickname','users_info.area','users_info.birthday','users_info.height','users_info.weight'])