新增系统执行命令方法

master
chenzhi 4 years ago
parent f5ad1a6d0c
commit fb75494c64

@ -0,0 +1,29 @@
<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 系统任务接口
* @author cz
* TODO: 罚款的游戏没有流水不统计补点为0 无法重算
*/
class CmdTasksController extends Controller {
public function run()
{
$params = D("CmdTasks")->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()]);
}
}
}

@ -14,6 +14,8 @@ class FinancialSummarySetController extends \Think\Controller
public $month;//月份 public $month;//月份
public $year;//年份 public $year;//年份
public $adddata;//要添加的数据 public $adddata;//要添加的数据
public $taskid=false;
public $result='';
//数据库 //数据库
public $FinancialSummaryModel; public $FinancialSummaryModel;
public function _initialize(){ public function _initialize(){
@ -35,6 +37,11 @@ class FinancialSummarySetController extends \Think\Controller
$this->CoinPayOrderModel = M("CoinPayOrder",'tab_');//会长充值平台币表 $this->CoinPayOrderModel = M("CoinPayOrder",'tab_');//会长充值平台币表
$this->TestOrderModel = M("TestOrder",'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->reCount();
$this->setFinancialSummary(); $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']; $countRes = $this->FinancialSummaryModel->field("IFNULL(COUNT(*),0) count")->where("count_year = '{$this->year}' and count_month= '{$this->month}'")->find()['count'];
if($countRes > 0){ 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 "{$this->date}开始统计".PHP_EOL;
echo "--收入类型统计中".PHP_EOL; echo "--收入类型统计中".PHP_EOL;
@ -108,6 +122,10 @@ class FinancialSummarySetController extends \Think\Controller
$t2 = microtime(true); $t2 = microtime(true);
echo ("success {$this->date}:ok runtime:".round($t2-$t1,3).'s'.PHP_EOL); 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的数据,按收入类型 * 获取类型为1的数据,按收入类型

@ -0,0 +1,31 @@
<?php
//推广公司模型
namespace Admin\Model;
use Think\Model;
/**
* 文档基础模型
*/
class CmdTasksModel extends Model{
protected $tablePrefix = 'tab_';
public function getTask()
{
//按顺序获取任务
$has_run = $this->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);
}
}
Loading…
Cancel
Save