定时任务修改
This commit is contained in:
@@ -12,10 +12,10 @@ class Crontask extends Controller
|
|||||||
public function reviewerQuality()
|
public function reviewerQuality()
|
||||||
{
|
{
|
||||||
//查询文章状态
|
//查询文章状态
|
||||||
$aWhere = [
|
$aParam = [
|
||||||
'state'=>['in',[3,5]]
|
'state'=>['in',[3,5]]
|
||||||
];
|
];
|
||||||
$iCount = Db::name('article')->field('article_id,state')->where($aWhere)->count();
|
$iCount = Db::name('article')->field('article_id,state')->where($aParam)->count();
|
||||||
if(empty($iCount)){
|
if(empty($iCount)){
|
||||||
$this->showMessage('未查询到满足要求的审稿人数据',2);
|
$this->showMessage('未查询到满足要求的审稿人数据',2);
|
||||||
exit;
|
exit;
|
||||||
@@ -24,36 +24,38 @@ class Crontask extends Controller
|
|||||||
$iDealNum = ceil($iCount/$iSize);
|
$iDealNum = ceil($iCount/$iSize);
|
||||||
|
|
||||||
//数据处理
|
//数据处理
|
||||||
Db::startTrans();
|
$aUpdate = [];
|
||||||
for ($iPage=1; $iPage <= $iDealNum; $iPage++) {
|
for ($iPage=1; $iPage <= $iDealNum; $iPage++) {
|
||||||
echo '======='.$iPage.'========='."\n";
|
|
||||||
$iStart = ($iPage - 1) * $iSize;
|
$iStart = ($iPage - 1) * $iSize;
|
||||||
$aArticle = Db::name('article')->field('article_id,state')->where($aWhere)->limit($iStart,$iSize)->select();
|
$aArticleState = Db::name('article')->where($aParam)->limit($iStart,$iSize)->column('article_id,state');
|
||||||
if(empty($aArticle)){
|
if(empty($aArticleState)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//获取该文章审核人的信息
|
//获取该文章审核人的信息
|
||||||
$aWhere = [
|
$aWhere = [
|
||||||
'article_id'=>['in',array_column($aArticle, 'article_id')],
|
'article_id'=>['in',array_keys($aArticleState)],
|
||||||
'state'=>['in',[2,3]]
|
'state'=>['in',[1,2,3]]
|
||||||
];
|
];
|
||||||
$aReviewer = Db::name('article_reviewer')->field('article_id,reviewer_id,state')->where($aWhere)->order('article_id asc')->select();
|
$aReviewer = Db::name('article_reviewer')->field('article_id,reviewer_id,state')->where($aWhere)->order('article_id asc,reviewer_id asc')->select();
|
||||||
if(empty($aReviewer)){
|
if(empty($aReviewer)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//查询审核人信息
|
//查询审核人信息
|
||||||
$aUserId = array_keys($aReviewer);
|
$aUserId = array_column($aReviewer,'reviewer_id');
|
||||||
$aUser = Db::name('user')->field('user_id,rs_num,right_times,error_times')->whereIn('user_id',$aUserId)->select();
|
$aUser = Db::name('user')->field('user_id,rs_num,right_times,error_times')->whereIn('user_id',$aUserId)->order('user_id asc')->select();
|
||||||
if(empty($aUser)){
|
if(empty($aUser)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$aUser = array_column($aUser, null,'user_id');
|
$aUser = array_column($aUser, null,'user_id');
|
||||||
|
|
||||||
//处理数据并组装数据
|
//处理数据并组装数据
|
||||||
$aArticleState = array_column($aArticle, 'state','article_id');
|
|
||||||
$aCase = ['right_times' => '', 'right_rate' => '','error_times' => '', 'error_rate' => ''];
|
$aCase = ['right_times' => '', 'right_rate' => '','error_times' => '', 'error_rate' => ''];
|
||||||
$aToState = [2 => 3,3 => 5];//文章3拒稿5录用 审稿人2拒稿3通过
|
$aToState = [2 => 3,3 => 5];//文章3拒稿5录用 审稿人2拒稿3通过
|
||||||
|
$aId = [];
|
||||||
foreach ($aReviewer as $key => $item) {
|
foreach ($aReviewer as $key => $item) {
|
||||||
|
//审核次数+1;
|
||||||
|
$aUpdate[$item['reviewer_id']]['reviewer_id'] = $item['reviewer_id'] ;
|
||||||
|
$aUpdate[$item['reviewer_id']]['rs_num'] = empty($aUpdate[$item['reviewer_id']]['rs_num']) ? 1 : $aUpdate[$item['reviewer_id']]['rs_num']+1 ;
|
||||||
//文章状态
|
//文章状态
|
||||||
$iArticleState = empty($aArticleState[$item['article_id']]) ? 0 : $aArticleState[$item['article_id']];
|
$iArticleState = empty($aArticleState[$item['article_id']]) ? 0 : $aArticleState[$item['article_id']];
|
||||||
if(empty($iArticleState)){
|
if(empty($iArticleState)){
|
||||||
@@ -62,49 +64,65 @@ class Crontask extends Controller
|
|||||||
if(empty($aToState[$item['state']])){
|
if(empty($aToState[$item['state']])){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$aUserInfo = $aUser[$item['reviewer_id']] ?? [];
|
|
||||||
if(empty($aUserInfo)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if($iArticleState == $aToState[$item['state']]){
|
if($iArticleState == $aToState[$item['state']]){
|
||||||
|
$aUpdate[$item['reviewer_id']]['right_times'] = empty($aUpdate[$item['reviewer_id']]['right_times']) ? 1 : $aUpdate[$item['reviewer_id']]['right_times']+1 ;
|
||||||
$iTimes = $aUserInfo['right_times']+1;
|
|
||||||
$iRightNum = empty($aUserInfo['rs_num']) ? 0 : round($iTimes/$aUserInfo['rs_num']/100,2);
|
|
||||||
|
|
||||||
$aCase['right_times'] .= "WHEN {$item['reviewer_id']} THEN ";
|
|
||||||
$aCase['right_times'] .= "'{$iTimes}' ";
|
|
||||||
$aCase['right_rate'] .= "WHEN {$item['reviewer_id']} THEN ";
|
|
||||||
$aCase['right_rate'] .= "'{$iRightNum}' ";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if($iArticleState != $item['state']){
|
if($iArticleState != $item['state']){
|
||||||
$iErrorTimes = $aUserInfo['error_times']+1;
|
$aUpdate[$item['reviewer_id']]['error_times'] = empty($aUpdate[$item['reviewer_id']]['error_times']) ? 1 : $aUpdate[$item['reviewer_id']]['error_times']+1 ;
|
||||||
$iErrorNum = empty($aUserInfo['rs_num']) ? 0 : round($iErrorTimes/$aUserInfo['rs_num']/100,2);
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aChunk = array_chunk($aUpdate, $iSize);
|
||||||
|
Db::startTrans();
|
||||||
|
foreach ($aChunk as $key => $value) {
|
||||||
|
|
||||||
|
$aCase = ['right_times' => '', 'right_rate' => '','error_times' => '', 'error_rate' => '','rs_num' => ''];
|
||||||
|
foreach ($value as $item) {
|
||||||
|
|
||||||
|
//正确数
|
||||||
|
$iRsNum = empty($item['rs_num']) ? 0 : $item['rs_num'];
|
||||||
|
$iRightTimes = empty($item['right_times']) ? 0 : $item['right_times'];
|
||||||
|
$iRightRate = empty($iRightTimes) ? 0 : round($iRightTimes/$iRsNum,2);
|
||||||
|
$aCase['right_times'] .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
|
$aCase['right_times'] .= "'{$iRightTimes}' ";
|
||||||
|
$aCase['right_rate'] .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
|
$aCase['right_rate'] .= "'{$iRightRate}' ";
|
||||||
|
//错误数
|
||||||
|
$iErrorTimes = empty($item['error_times']) ? 0 : $item['error_times'];
|
||||||
|
$iErrorRate = empty($iErrorTimes) ? 0 : round($iErrorTimes/$iRsNum,2);
|
||||||
$aCase['error_times'] .= "WHEN {$item['reviewer_id']} THEN ";
|
$aCase['error_times'] .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
$aCase['error_times'] .= "'{$iErrorTimes}' ";
|
$aCase['error_times'] .= "'{$iErrorTimes}' ";
|
||||||
$aCase['error_rate'] .= "WHEN {$item['reviewer_id']} THEN ";
|
$aCase['error_rate'] .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
$aCase['error_rate'] .= "'{$iErrorNum}' ";
|
$aCase['error_rate'] .= "'{$iErrorRate}' ";
|
||||||
|
|
||||||
|
//审核数量
|
||||||
|
$aCase['rs_num'] .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
|
$aCase['rs_num'] .= "'{$iRsNum}' ";
|
||||||
}
|
}
|
||||||
$aId[] = $item['reviewer_id'];
|
$aId = array_column($value, 'reviewer_id');
|
||||||
}
|
|
||||||
|
|
||||||
//更新数据库
|
//更新数据库
|
||||||
foreach ($aCase as $key => $value) {
|
foreach ($aCase as $kk => $value) {
|
||||||
if(empty($value)){
|
if(empty($value)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$aUpdate[$key] = Db::raw('CASE user_id '.$value.'END');
|
$aUpdateCase[$kk] = Db::raw('CASE user_id '.$value.'END');
|
||||||
}
|
}
|
||||||
if(empty($aUpdate) || empty($aId)){
|
if(empty($aUpdateCase) || empty($aId)){
|
||||||
$this->showMessage('未查询到满足要求的审稿人数据4',2);
|
$this->showMessage('未查询到满足要求的审稿人数据['.$key.']'."\n",2);
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
$result = Db::name('user')
|
$result = Db::name('user')
|
||||||
->where('user_id', 'IN', $aId)
|
->where('user_id', 'IN', $aId)
|
||||||
->limit(count($aId))
|
->limit(count($aId))
|
||||||
->update($aUpdate);
|
->update($aUpdateCase);
|
||||||
echo '---------'.$iPage.'--------'."\n";
|
if ($result === false) {
|
||||||
|
$this->showMessage('审稿人质量数据处理失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||||
|
}else{
|
||||||
|
$this->showMessage('审稿人质量数据处理成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
$this->showMessage('审稿人质量数据处理完成',1);
|
$this->showMessage('审稿人质量数据处理完成',1);
|
||||||
@@ -176,9 +194,13 @@ class Crontask extends Controller
|
|||||||
->update([
|
->update([
|
||||||
'review_num' => Db::raw($aCase['review_num']),
|
'review_num' => Db::raw($aCase['review_num']),
|
||||||
]);
|
]);
|
||||||
|
if ($result === false) {
|
||||||
|
$this->showMessage('更新审稿人审核数量失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||||
|
}else{
|
||||||
|
$this->showMessage('更新审稿人审核数量成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
// $this->showMessage('更新审稿人审核数量成功',1);
|
|
||||||
}
|
}
|
||||||
if(!empty($aUser)){
|
if(!empty($aUser)){
|
||||||
$aChunk = array_chunk($aUser, 100);
|
$aChunk = array_chunk($aUser, 100);
|
||||||
@@ -193,15 +215,16 @@ class Crontask extends Controller
|
|||||||
->update([
|
->update([
|
||||||
'review_num' => 0,
|
'review_num' => 0,
|
||||||
]);
|
]);
|
||||||
// if(!$result){
|
if ($result === false) {
|
||||||
// $this->showMessage('清空审稿人审核数量失败:'.Db::getLastSql(),2);
|
$this->showMessage('清空审稿人审核数量失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||||
// }
|
}else{
|
||||||
|
$this->showMessage('清空审稿人审核数量成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
// $this->showMessage('清空审稿人审核数量成功:'.Db::getLastSql(),1);
|
|
||||||
}
|
}
|
||||||
$this->showMessage('批量更新审稿人审核数量成功',1);
|
$this->showMessage('批量更新审稿人审核数量成功'."\n",1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -226,7 +249,7 @@ class Crontask extends Controller
|
|||||||
//更新超过七日未审核的数据
|
//更新超过七日未审核的数据
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
//更新审稿人未审稿的数量
|
//更新审稿人未审稿的数量
|
||||||
$aChunkReviewerNum = array_chunk($aReviewerNum, 100);
|
$aChunkReviewerNum = array_chunk($aReviewerNum, 500);
|
||||||
foreach ($aChunkReviewerNum as $key => $value) {
|
foreach ($aChunkReviewerNum as $key => $value) {
|
||||||
$aId = array_column($value, 'reviewer_id');
|
$aId = array_column($value, 'reviewer_id');
|
||||||
if(empty($aId)){
|
if(empty($aId)){
|
||||||
@@ -234,30 +257,43 @@ class Crontask extends Controller
|
|||||||
}
|
}
|
||||||
$aWhere['reviewer_id']=['in',$aId];
|
$aWhere['reviewer_id']=['in',$aId];
|
||||||
$iCount = array_sum(array_column($value, 'num'));
|
$iCount = array_sum(array_column($value, 'num'));
|
||||||
Db::name('article_reviewer')->where($aWhere)->limit($iCount)->update(['state' => 4]);
|
$iResult = Db::name('article_reviewer')->where($aWhere)->limit($iCount)->update(['state' => 4]);
|
||||||
|
if ($iResult === false) {
|
||||||
$aCase['review_num'] = 'CASE user_id ';
|
$this->showMessage('更新审稿人审稿状态失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||||
|
}else{
|
||||||
|
$this->showMessage('更新审稿人审稿状态成功['.$key.']执行SQL条数:'.$iResult."\n",1);
|
||||||
|
}
|
||||||
|
$aCase = $aUpdateId = [];
|
||||||
|
$sRdNum = '';
|
||||||
foreach ($value as $key => $item) {
|
foreach ($value as $key => $item) {
|
||||||
|
if($item['reviewer_id'] <=0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//审核数量有,变化更新数量
|
//审核数量有,变化更新数量
|
||||||
$aCase['review_num'] .= "WHEN {$item['reviewer_id']} THEN ";
|
$sRdNum .= "WHEN {$item['reviewer_id']} THEN ";
|
||||||
$aCase['review_num'] .= Db::raw("review_num + {$item['num']}")." ";
|
$sRdNum .= Db::raw("rd_num + {$item['num']}")." ";
|
||||||
$aUpdateId[] = $item['reviewer_id'];
|
$aUpdateId[] = $item['reviewer_id'];
|
||||||
}
|
}
|
||||||
//SQL拼接最后结尾
|
//SQL拼接最后结尾
|
||||||
$aCase['review_num'] .= 'END';
|
$aCase['rd_num'] ='CASE user_id '.$sRdNum.'END';
|
||||||
//执行更新
|
//执行更新
|
||||||
$result = Db::name('user')
|
$result = Db::name('user')
|
||||||
->where(['user_id' => ['in',$aUpdateId]])
|
->where(['user_id' => ['in',$aUpdateId]])
|
||||||
|
->limit(count($aUpdateId))
|
||||||
->update([
|
->update([
|
||||||
'rd_num' => Db::raw($aCase['review_num']),
|
'rd_num' => Db::raw($aCase['rd_num']),
|
||||||
]);
|
]);
|
||||||
|
if ($result === false) {
|
||||||
|
$this->showMessage('更新用户拒绝审稿数量失败['.$key.']执行SQL:'.Db::getLastSql()."\n",2);
|
||||||
|
}else{
|
||||||
|
$this->showMessage('更新用户拒绝审稿数量成功['.$key.']执行SQL条数:'.$result."\n",1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
|
|
||||||
$this->showMessage('批量更新超过七日未审稿的状态成功',2);
|
$this->showMessage('批量更新超过七日未审稿的状态成功',2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 格式化信息输出
|
* 格式化信息输出
|
||||||
|
|||||||
Reference in New Issue
Block a user