优化系统任务执行

master
chenzhi 4 years ago
parent b88f2986bd
commit 4f70b89063

@ -2,6 +2,7 @@
namespace Admin\Controller;
use Think\Controller;
use Think\Exception;
/**
* 系统任务接口
@ -16,12 +17,11 @@ class CmdTasksController extends Controller {
if(!$params){
echo('暂无任务');
}
$taskid = $params['id'];
$cmd = $params['params'];
$cmd = str_replace('{$taskid}',$taskid,$cmd);
try {
exec($cmd);
} catch (\Exception $e) {
exec($params['params'], $resArr, $status);
$result = json_encode($resArr,JSON_UNESCAPED_UNICODE);
D("CmdTasks")->updateTask(['id'=>$params['id'],'status' => 2, 'end_time' => time(), 'result' => $result]);
} catch (Exception $e) {
D("CmdTasks")->updateTask(['id'=>$params['id'],'status' => 3, 'end_time' => time(), 'result' => $e->getMessage()]);
}
}

@ -1,5 +1,6 @@
<?php
namespace Admin\Controller;
use Think\Exception;
/**
* 游戏流水聚合接口
@ -36,12 +37,6 @@ class FinancialSummarySetController extends \Think\Controller
$this->GameSupersignModel = M("GameSupersign",'tab_');
$this->CoinPayOrderModel = M("CoinPayOrder",'tab_');//会长充值平台币表
$this->TestOrderModel = M("TestOrder",'tab_');//测试订单录入
$taskid = I("taskid");
if(!empty($taskid)){
$this->taskid = $taskid;
}
}
/**
* 更新某月数据
@ -63,9 +58,6 @@ 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]);
}
}
/**
* 强制重新聚合
@ -95,11 +87,7 @@ 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){
if($this->taskid){
throw new \Exception("error:Repeated statistics,msg:{$this->date}已经聚合过");
}else{
die("error:Repeated statistics,msg:{$this->date}已经聚合过");
}
die("error:Repeated statistics,msg:{$this->date}已经聚合过");
}
echo "{$this->date}开始统计".PHP_EOL;
echo "--收入类型统计中".PHP_EOL;

@ -37,11 +37,11 @@ class CmdTasksModel extends Model{
if(empty($task)){
return false;
}else{
return date("Y-d-m H:i:s",$task['end_time']);
return date("Y-m-d H:i:s",$task['end_time']);
}
}
//插入任务
public function addTask($type,$params,$need_tasksid = true,$need_path=true)
public function addTask($type,$params,$need_path=true)
{
$task = $this->field("end_time")->where(['status'=>["in","0,1"],'type'=>$type])->order("id desc")->find();
if(!empty($task)){
@ -55,9 +55,7 @@ class CmdTasksModel extends Model{
$params = "cd ".ROOTTTTT.";".$params;
}
}
if($need_tasksid){
$params = rtrim($params,";").'/taskid/{$taskid};';
}
$params = rtrim($params,";").' 2>&1';
$save = [
"uid"=>$_SESSION['onethink_admin']['user_auth']['uid'],
"created_time"=>time(),

Loading…
Cancel
Save