You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?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);
|
|
}
|
|
//获取同类型任务最后一次操作时间
|
|
public function getTypeLastTask($type)
|
|
{
|
|
$task = $this->field("end_time")->where(['status'=>"2",'type'=>$type])->order("id desc")->find();
|
|
if(empty($task)){
|
|
return false;
|
|
}else{
|
|
return date("Y-d-m H:i:s",$task['end_time']);
|
|
}
|
|
}
|
|
//插入任务
|
|
public function addTask($type,$params,$need_tasksid = true)
|
|
{
|
|
$task = $this->field("end_time")->where(['status'=>"1",'type'=>$type])->order("id desc")->find();
|
|
if(!empty($task)){
|
|
return false;
|
|
}
|
|
if($need_tasksid){
|
|
$params = rtrim($params,";").'/taskid/{$taskid};';
|
|
}
|
|
$save = [
|
|
"uid"=>$_SESSION['onethink_admin']['user_auth']['uid'],
|
|
"created_time"=>time(),
|
|
"params"=>$params,
|
|
"type"=>$type
|
|
];
|
|
return $this->add($save);
|
|
}
|
|
} |