|
|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|