Browse Source

任务清零

zac3533 1 year ago
parent
commit
96e2f84cd2
2 changed files with 47 additions and 0 deletions
  1. 46 0
      application/admin/command/TaskClear.php
  2. 1 0
      application/command.php

+ 46 - 0
application/admin/command/TaskClear.php

@@ -0,0 +1,46 @@
+<?php
+ 
+namespace app\admin\command;
+
+use think\Db;
+use think\console\Command;
+use think\console\Input;
+use think\exception\DbException;
+use think\exception\PDOException;
+use think\console\Output;
+use think\Exception;
+use app\common\model\Config;
+use app\common\model\Users;
+ 
+class TaskClear extends Command
+{
+    protected function configure()
+    {
+        $this->setName('taskclear')->setDescription('任务清零');
+    }
+ 
+
+
+    //爬取企业信息
+    protected function execute(Input $input, Output $output)
+    {
+        $day_tasks_num  = (new Config())->getValue('day_tasks_num');//单日任务数
+        $list = Users::where('task_num', '>=', $day_tasks_num)->select();
+        $count = 0;
+        Db::startTrans();
+        try {
+            $day = date('md',time());
+            foreach ($list as $item) {
+                if(!empty($item->task_last_time) && ($day != date('md', $item->task_last_time))){
+                    $count += $item->allowField(true)->isUpdate(true)->save(['task_num' => 0]);
+                }
+            }
+            Db::commit();
+        } catch (PDOException|Exception $e) {
+            Db::rollback();
+            $output->writeln("error".$e->getMessage());
+        }
+        $output->writeln("任务清零执行完成!".$count);
+    }
+ 
+}

+ 1 - 0
application/command.php

@@ -17,4 +17,5 @@ return [
     'app\admin\command\Min',
     'app\admin\command\Addon',
     'app\admin\command\Api',
+    'taskclear'=>'app\admin\command\TaskClear'
 ];