48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
namespace app\common;
|
|
use think\Db;
|
|
class QueueJob
|
|
{
|
|
|
|
//必填参数
|
|
protected $aField = ['job_id','job_class','status','create_time','update_time','error','params'];
|
|
|
|
// 记录任务开始
|
|
public function addLog($aParam = []) {
|
|
|
|
//数据处理
|
|
$aField = $this->aField;
|
|
$aInsert = [];
|
|
foreach ($aField as $key => $value) {
|
|
if(isset($aParam[$value])){
|
|
$aInsert[$value] = $aParam[$value];
|
|
}
|
|
}
|
|
$result = 0;
|
|
if(!empty($aInsert)){
|
|
$result = DB::name('wechat_queue_logs')->insertGetId($aParam);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// 记录任务成功
|
|
public function updateLog($aParam = []) {
|
|
|
|
$iLogId = empty($aParam['log_id']) ? 0 : $aParam['log_id'];
|
|
if(empty($iLogId)){
|
|
return false;
|
|
}
|
|
//数据处理
|
|
$aField = $this->aField;
|
|
$aUpdate = [];
|
|
foreach ($aField as $key => $value) {
|
|
if(isset($aParam[$value])){
|
|
$aUpdate[$value] = $aParam[$value];
|
|
}
|
|
}
|
|
unset($aParam['log_id']);
|
|
$result = DB::name('wechat_queue_logs')->where('log_id',$iLogId)->limit(1)->update($aUpdate);
|
|
return $result;
|
|
}
|
|
}
|
|
?>
|