From fb75494c64d496655ea7107f9f9bac697db45049 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Thu, 20 Aug 2020 17:06:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B3=BB=E7=BB=9F=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/CmdTasksController.class.php | 29 +++++++++++++++++ .../FinancialSummarySetController.class.php | 20 +++++++++++- .../Admin/Model/CmdTasksModel.class.php | 31 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 Application/Admin/Controller/CmdTasksController.class.php create mode 100644 Application/Admin/Model/CmdTasksModel.class.php diff --git a/Application/Admin/Controller/CmdTasksController.class.php b/Application/Admin/Controller/CmdTasksController.class.php new file mode 100644 index 000000000..ef64100e7 --- /dev/null +++ b/Application/Admin/Controller/CmdTasksController.class.php @@ -0,0 +1,29 @@ +getTask(); + if(!$params){ + echo('暂无任务'); + } + $taskid = $params['id']; + $cmd = $params['params']; + $cmd = str_replace('{$taskid}',$taskid,$cmd); + try { + system($cmd); + } catch (\Exception $e) { + D("CmdTasks")->updateTask(['id'=>$params['id'],'status' => 3, 'end_time' => time(), 'result' => $e->getMessage()]); + } + } + +} diff --git a/Application/Admin/Controller/FinancialSummarySetController.class.php b/Application/Admin/Controller/FinancialSummarySetController.class.php index f88bc0650..eb3894b23 100644 --- a/Application/Admin/Controller/FinancialSummarySetController.class.php +++ b/Application/Admin/Controller/FinancialSummarySetController.class.php @@ -14,6 +14,8 @@ class FinancialSummarySetController extends \Think\Controller public $month;//月份 public $year;//年份 public $adddata;//要添加的数据 + public $taskid=false; + public $result=''; //数据库 public $FinancialSummaryModel; public function _initialize(){ @@ -35,6 +37,11 @@ class FinancialSummarySetController extends \Think\Controller $this->CoinPayOrderModel = M("CoinPayOrder",'tab_');//会长充值平台币表 $this->TestOrderModel = M("TestOrder",'tab_');//测试订单录入 + $taskid = I("taskid"); + if(!empty($taskid)){ + $this->taskid = $taskid; + } + } /** * 更新某月数据 @@ -56,6 +63,9 @@ class FinancialSummarySetController extends \Think\Controller $this->reCount(); $this->setFinancialSummary(); + if($this->taskid){ + D("CmdTasks")->updateTask(['id'=>$this->taskid,'status'=>2,'end_time' => time(), 'result' =>$this->result]); + } } /** * 强制重新聚合 @@ -85,7 +95,11 @@ class FinancialSummarySetController extends \Think\Controller //判断是否已经聚合 $countRes = $this->FinancialSummaryModel->field("IFNULL(COUNT(*),0) count")->where("count_year = '{$this->year}' and count_month= '{$this->month}'")->find()['count']; if($countRes > 0){ - die("error:Repeated statistics,msg:{$this->date}已经聚合过"); + if($this->taskid){ + throw new \Exception("error:Repeated statistics,msg:{$this->date}已经聚合过"); + }else{ + die("error:Repeated statistics,msg:{$this->date}已经聚合过"); + } } echo "{$this->date}开始统计".PHP_EOL; echo "--收入类型统计中".PHP_EOL; @@ -108,6 +122,10 @@ class FinancialSummarySetController extends \Think\Controller $t2 = microtime(true); echo ("success {$this->date}:ok runtime:".round($t2-$t1,3).'s'.PHP_EOL); + + if($this->taskid){ + $this->result = "success {$this->date}:ok runtime:".round($t2-$t1,3).'s'; + } } /** * 获取类型为1的数据,按收入类型 diff --git a/Application/Admin/Model/CmdTasksModel.class.php b/Application/Admin/Model/CmdTasksModel.class.php new file mode 100644 index 000000000..ac7b9f408 --- /dev/null +++ b/Application/Admin/Model/CmdTasksModel.class.php @@ -0,0 +1,31 @@ +where(['status'=>"1"])->count(); + if($has_run > 0){ + return false; + } + $task = $this->field("id,params")->where(['status'=>"0"])->order("id asc")->find(); + if(empty($task)){ + return false; + }else{ + //修改状态为执行中 + $this->save(['id'=>$task['id'],'status'=>"1","start_time"=>time()]); + return $task; + } + } + public function updateTask($params) + { + $this->save($params); + } +} \ No newline at end of file