Browse Source

活动开奖

lizhen_gitee 2 months ago
parent
commit
94b0c7c79e
2 changed files with 25 additions and 13 deletions
  1. 5 2
      application/api/controller/Active.php
  2. 20 11
      application/index/controller/Plantask.php

+ 5 - 2
application/api/controller/Active.php

@@ -12,7 +12,7 @@ class Active extends Api
 {
 
     // 无需登录的接口,*表示全部
-    protected $noNeedLogin = [''];
+    protected $noNeedLogin = ['active_finish'];
     // 无需鉴权的接口,*表示全部
     protected $noNeedRight = ['*'];
 
@@ -74,7 +74,7 @@ class Active extends Api
         $this->success('已收集',$this->get_my_number());
     }
 
-    //开奖
+    //开奖,计划任务
     public function active_finish(){
         $check = Db::name('active_log')->where('opendate',date('Ymd'))->find();
         if(!empty($check)){
@@ -95,6 +95,9 @@ class Active extends Api
 
         //所有已存在的不重复号码,打乱之后,取前N个
         $box = Db::name('active_user_number')->where('createdate',date('Ymd'))->group('number')->column('number');
+        if(empty($box)){
+            $this->error('今天没有人参与');
+        }
         shuffle($box);
         $box_count = $box_count > count($box) ? count($box) : $box_count;
         $gift_number = array_chunk($box,$box_count)[0]; //中奖数组,不重复

+ 20 - 11
application/index/controller/Plantask.php

@@ -9,6 +9,19 @@ use app\common\library\Tlssigapiv2;
 
 class Plantask extends Controller
 {
+
+
+
+    //定时跑用户活跃,改成离线。 一分钟一次
+    public function auto_user_active()
+    {
+        $start_time = time() - (3600 * 24);
+        $end_time   = time() - (3600 * 2);
+        $sql        = "update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime between {$start_time} and {$end_time})";
+        db()->query($sql);
+    }
+
+    ////////////////////////////////////////////////////////
     //主动拉取im群组内 聊天记录。没用到
     public function auto_imgroup(){
         $im_config = config('tencent_im');
@@ -127,17 +140,6 @@ class Plantask extends Controller
         echo '结束';
         exit;
     }
-
-    //定时跑用户活跃,改成离线。 一分钟一次
-    public function auto_user_active()
-    {
-        $start_time = time() - (3600 * 24);
-        $end_time   = time() - (3600 * 2);
-        $sql        = "update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime between {$start_time} and {$end_time})";
-        db()->query($sql);
-    }
-
-    ////////////////////////////////////////////////////////
     /////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
     //下载远程文件 到指定目录
     private function downloadfile($file_url, $path = '', $save_file_name = '')
@@ -324,5 +326,12 @@ class Plantask extends Controller
     }
     ////////////////////////////////////////////////////////
 
+    private function error($msg){
+        echo $msg;exit;
+    }
+
+    private function success($msg){
+        echo $msg;exit;
+    }
 
 }