定时任务新增
This commit is contained in:
@@ -357,6 +357,107 @@ class Crontask extends Controller
|
||||
$this->showMessage('批量更新超过七日未审稿的状态成功',2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 批量处理审稿人活跃度[近两年]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reviewerActivityForYear(){
|
||||
$sDate = strtotime(date('Y-m-d 00:00:00', strtotime('-2 year')));
|
||||
//获取该文章审核人的信息
|
||||
$aWhere = [
|
||||
'ctime'=>['>',$sDate],
|
||||
'state'=>['in',[1,2,3]]
|
||||
];
|
||||
$aReviewer = Db::name('article_reviewer')->field('reviewer_id,count(article_id) as review_num_two_year ')->where($aWhere)->order('reviewer_id asc')->group('reviewer_id')->select();
|
||||
|
||||
//查询审稿人数量不为0的审稿信息
|
||||
$aUserWhere = [
|
||||
// 'is_reviewer' => 1,
|
||||
'review_num_two_year' => ['>',0]
|
||||
];
|
||||
$aUser = Db::name('user')->field('user_id,review_num_two_year')->where($aUserWhere)->select();
|
||||
if(empty($aReviewer) && empty($aUser)){
|
||||
$this->showMessage('未查询到待处理的审稿人数据【近两年】',2);
|
||||
exit;
|
||||
}
|
||||
$aUser = empty($aUser) ? [] : array_column($aUser, null,'user_id');
|
||||
if(!empty($aReviewer)){
|
||||
$aChunk = array_chunk($aReviewer, 100);
|
||||
Db::startTrans();
|
||||
foreach ($aChunk as $key => $item) { //数据分片操作
|
||||
//需要更新的用户ID
|
||||
$aUpdateId = [];
|
||||
//SQL拼接
|
||||
$aCase['review_num_two_year'] = 'CASE user_id ';
|
||||
foreach ($item as $key => $value) {
|
||||
//用户ID
|
||||
$iUserId = $value['reviewer_id'];
|
||||
|
||||
//拼接更新语句
|
||||
if(empty($aUser[$iUserId])){
|
||||
//更新数量
|
||||
$aCase['review_num_two_year'] .= "WHEN {$iUserId} THEN ";
|
||||
$aCase['review_num_two_year'] .= "'{$value['review_num_two_year']}' ";
|
||||
$aUpdateId[] = $iUserId;
|
||||
continue;
|
||||
}
|
||||
//审核数量无变化,跳过更新
|
||||
if($aUser[$iUserId]['review_num_two_year'] == $value['review_num_two_year']){
|
||||
unset($aUser[$iUserId]);
|
||||
continue;
|
||||
}
|
||||
//审核数量有,变化更新数量
|
||||
$aCase['review_num_two_year'] .= "WHEN {$iUserId} THEN ";
|
||||
$aCase['review_num_two_year'] .= "'{$value['review_num_two_year']}' ";
|
||||
$aUpdateId[] = $iUserId;
|
||||
unset($aUser[$iUserId]);
|
||||
}
|
||||
//SQL拼接最后结尾
|
||||
$aCase['review_num_two_year'] .= 'END';
|
||||
//执行更新
|
||||
if(empty($aUpdateId)){
|
||||
continue;
|
||||
}
|
||||
$result = Db::name('user')
|
||||
->where(['user_id' => ['in',$aUpdateId]])
|
||||
->update([
|
||||
'review_num_two_year' => Db::raw($aCase['review_num_two_year']),
|
||||
]);
|
||||
if ($result === false) {
|
||||
$this->showMessage('更新近两年审稿人审核数量失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||
}else{
|
||||
$this->showMessage('更新近两年审稿人审核数量成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
}
|
||||
if(!empty($aUser)){
|
||||
$aChunk = array_chunk($aUser, 100);
|
||||
Db::startTrans();
|
||||
foreach ($aChunk as $key => $item) { //数据分片操作
|
||||
$aUserId = array_column($item, 'user_id');
|
||||
if(empty($aUserId)){
|
||||
continue;
|
||||
}
|
||||
$result = Db::name('user')->where(['user_id' => ['in',$aUserId]])
|
||||
->limit(count($aUserId))
|
||||
->update([
|
||||
'review_num' => 0,
|
||||
]);
|
||||
if ($result === false) {
|
||||
$this->showMessage('清空近两年审稿人审核数量失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||
}else{
|
||||
$this->showMessage('清空近两年审稿人审核数量成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||
}
|
||||
|
||||
}
|
||||
Db::commit();
|
||||
}
|
||||
$this->showMessage('批量更新近两年审稿人审核数量成功'."\n",1);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 格式化信息输出
|
||||
|
||||
Reference in New Issue
Block a user