diff --git a/application/api/controller/Black.php b/application/api/controller/Black.php new file mode 100644 index 0000000..6906c36 --- /dev/null +++ b/application/api/controller/Black.php @@ -0,0 +1,92 @@ +request->post(); + $rule = new Validate([ + 'reviewer_id' => 'require' + ]); + if (!$rule->check($aParam)) { + return jsonError($rule->getError()); + } + //查询审核人是否存在 + $aUser = Db::name('user')->where(['user_id' => $aParam['reviewer_id'],'is_reviewer' => 1])->column('user_id'); + if(empty($aUser)){ + return jsonError('Reviewer does not exist'); + } + + //判断是否添加该审稿人 + $aBlack = Db::name('user_reviewer_black')->field('reviewer_black_id')->where(['reviewer_id'=>$aParam['reviewer_id'],'state' => 1])->find(); + if(!empty($aBlack)){ + return jsonError('The reviewer has been marked as a bad reviewer and there is no need to repeat the process'); + } + //组装数据入库 + $aParam['create_time'] = time(); + $aParam['reason'] = empty($aParam['reason']) ? '' : addslashes(htmlspecialchars(trim($aParam['reason']))); + $aParam['state'] = 1; + + $result = Db::name('user_reviewer_black')->insert($aParam); + if(!$result){ + return jsonError('Failed to add bad reviewers'); + } + return jsonSuccess([]); + } + /** + * @title 更新审稿人状态 + * @param reviewer_id 审稿人ID + * + */ + public function updateReviewer(){ + + $aParam = $this->request->post(); + $rule = new Validate([ + 'reviewer_id' => 'require' + ]); + if (!$rule->check($aParam)) { + return jsonError($rule->getError()); + } + //查询审核人是否存在 + $aUser = Db::name('user')->where(['user_id' => $aParam['reviewer_id'],'is_reviewer' => 1])->column('user_id'); + if(empty($aUser)){ + return jsonError('Reviewer does not exist'); + } + + //判断是否添加该审稿人 + $aBlack = Db::name('user_reviewer_black')->field('reviewer_black_id')->where(['reviewer_id'=>$aParam['reviewer_id'],'state' => 1])->find(); + if(empty($aBlack)){ + return jsonError('Reviewer not marked as a bad reviewer, please confirm'); + } + //组装数据更新数据库 + $aUpdate = ['state' => 2,'update_time' => time()]; + $result = Db::name('user_reviewer_black')->where('reviewer_black_id',$aBlack['reviewer_black_id'])->update($aUpdate); + if(!$result){ + return jsonError('Failed to remove the bad reviewer tag'); + } + return jsonSuccess([]); + } +} diff --git a/application/api/controller/Crontask.php b/application/api/controller/Crontask.php new file mode 100644 index 0000000..0ffeeb4 --- /dev/null +++ b/application/api/controller/Crontask.php @@ -0,0 +1,280 @@ +['in',[3,5]] + ]; + $iCount = Db::name('article')->field('article_id,state')->where($aWhere)->count(); + if(empty($iCount)){ + $this->showMessage('未查询到满足要求的审稿人数据',2); + exit; + } + $iSize = 1000; + $iDealNum = ceil($iCount/$iSize); + + //数据处理 + Db::startTrans(); + for ($iPage=1; $iPage <= $iDealNum; $iPage++) { + echo '======='.$iPage.'========='."\n"; + $iStart = ($iPage - 1) * $iSize; + $aArticle = Db::name('article')->field('article_id,state')->where($aWhere)->limit($iStart,$iSize)->select(); + if(empty($aArticle)){ + continue; + } + //获取该文章审核人的信息 + $aWhere = [ + 'article_id'=>['in',array_column($aArticle, 'article_id')], + 'state'=>['in',[2,3]] + ]; + $aReviewer = Db::name('article_reviewer')->field('article_id,reviewer_id,state')->where($aWhere)->order('article_id asc')->select(); + if(empty($aReviewer)){ + continue; + } + //查询审核人信息 + $aUserId = array_keys($aReviewer); + $aUser = Db::name('user')->field('user_id,rs_num,right_times,error_times')->whereIn('user_id',$aUserId)->select(); + if(empty($aUser)){ + continue; + } + $aUser = array_column($aUser, null,'user_id'); + + //处理数据并组装数据 + $aArticleState = array_column($aArticle, 'state','article_id'); + $aCase = ['right_times' => '', 'right_rate' => '','error_times' => '', 'error_rate' => '']; + $aToState = [2 => 3,3 => 5];//文章3拒稿5录用 审稿人2拒稿3通过 + foreach ($aReviewer as $key => $item) { + //文章状态 + $iArticleState = empty($aArticleState[$item['article_id']]) ? 0 : $aArticleState[$item['article_id']]; + if(empty($iArticleState)){ + continue; + } + if(empty($aToState[$item['state']])){ + continue; + } + $aUserInfo = $aUser[$item['reviewer_id']] ?? []; + if(empty($aUserInfo)){ + continue; + } + if($iArticleState == $aToState[$item['state']]){ + + $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']){ + $iErrorTimes = $aUserInfo['error_times']+1; + $iErrorNum = empty($aUserInfo['rs_num']) ? 0 : round($iErrorTimes/$aUserInfo['rs_num']/100,2); + $aCase['error_times'] .= "WHEN {$item['reviewer_id']} THEN "; + $aCase['error_times'] .= "'{$iErrorTimes}' "; + $aCase['error_rate'] .= "WHEN {$item['reviewer_id']} THEN "; + $aCase['error_rate'] .= "'{$iErrorNum}' "; + + } + $aId[] = $item['reviewer_id']; + } + + //更新数据库 + foreach ($aCase as $key => $value) { + if(empty($value)){ + continue; + } + $aUpdate[$key] = Db::raw('CASE user_id '.$value.'END'); + } + if(empty($aUpdate) || empty($aId)){ + $this->showMessage('未查询到满足要求的审稿人数据4',2); + return false; + } + $result = Db::name('user') + ->where('user_id', 'IN', $aId) + ->limit(count($aId)) + ->update($aUpdate); + echo '---------'.$iPage.'--------'."\n"; + } + Db::commit(); + $this->showMessage('审稿人质量数据处理完成',1); + } + /** + * 批量处理审稿人活跃度/疲劳度[近两个月] + * + * @return void + */ + public function reviewerActivity(){ + $sDate = strtotime(date('Y-m-d 00:00:00', strtotime('-2 month'))); + //获取该文章审核人的信息 + $aWhere = [ + 'ctime'=>['>',$sDate], + 'state'=>['in',[1,2,3]] + ]; + $aReviewer = Db::name('article_reviewer')->field('reviewer_id,count(article_id) as review_num ')->where($aWhere)->order('reviewer_id asc')->group('reviewer_id')->select(); + + //查询审稿人数量不为0的审稿信息 + $aUserWhere = [ + // 'is_reviewer' => 1, + 'review_num' => ['>',0] + ]; + $aUser = Db::name('user')->field('user_id,review_num')->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'] = 'CASE user_id '; + foreach ($item as $key => $value) { + //用户ID + $iUserId = $value['reviewer_id']; + + //拼接更新语句 + if(empty($aUser[$iUserId])){ + //更新数量 + $aCase['review_num'] .= "WHEN {$iUserId} THEN "; + $aCase['review_num'] .= "'{$value['review_num']}' "; + $aUpdateId[] = $iUserId; + continue; + } + //审核数量无变化,跳过更新 + if($aUser[$iUserId]['review_num'] == $value['review_num']){ + unset($aUser[$iUserId]); + continue; + } + //审核数量有,变化更新数量 + $aCase['review_num'] .= "WHEN {$iUserId} THEN "; + $aCase['review_num'] .= "'{$value['review_num']}' "; + $aUpdateId[] = $iUserId; + unset($aUser[$iUserId]); + } + //SQL拼接最后结尾 + $aCase['review_num'] .= 'END'; + //执行更新 + if(empty($aUpdateId)){ + continue; + } + $result = Db::name('user') + ->where(['user_id' => ['in',$aUpdateId]]) + ->update([ + 'review_num' => Db::raw($aCase['review_num']), + ]); + } + Db::commit(); + // $this->showMessage('更新审稿人审核数量成功',1); + } + 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(['is_reviewer' => 1,'user_id' => ['in',$aUserId]]) + ->limit(count($aUserId)) + ->update([ + 'review_num' => 0, + ]); + // if(!$result){ + // $this->showMessage('清空审稿人审核数量失败:'.Db::getLastSql(),2); + // } + + } + Db::commit(); + // $this->showMessage('清空审稿人审核数量成功:'.Db::getLastSql(),1); + } + $this->showMessage('批量更新审稿人审核数量成功',1); + } + + /** + * @title 审稿人拒绝审稿[超过七日默认自动拒绝审稿] + * + */ + public function refuseReviewArticle(){ + $sDate = strtotime(date('Y-m-d 00:00:00', strtotime('-7 day'))); + //获取该文章审核人的信息 + $aWhere = [ + 'ctime'=>['<',$sDate], + 'state'=> 5 + ]; + + //统计每个审稿人未审稿的数量 + $aReviewerNum = Db::name('article_reviewer')->field('reviewer_id,count(art_rev_id) as num')->where($aWhere)->group('reviewer_id')->order('reviewer_id asc')->select(); + if(empty($aReviewerNum)){ + $this->showMessage('未查询到需要超过七日的稿件',2); + exit; + } + + //更新超过七日未审核的数据 + Db::startTrans(); + //更新审稿人未审稿的数量 + $aChunkReviewerNum = array_chunk($aReviewerNum, 100); + foreach ($aChunkReviewerNum as $key => $value) { + $aId = array_column($value, 'reviewer_id'); + if(empty($aId)){ + continue; + } + $aWhere['reviewer_id']=['in',$aId]; + $iCount = array_sum(array_column($value, 'num')); + Db::name('article_reviewer')->where($aWhere)->limit($iCount)->update(['state' => 4]); + + $aCase['review_num'] = 'CASE user_id '; + foreach ($value as $key => $item) { + //审核数量有,变化更新数量 + $aCase['review_num'] .= "WHEN {$item['reviewer_id']} THEN "; + $aCase['review_num'] .= Db::raw("review_num + {$item['num']}")." "; + $aUpdateId[] = $item['reviewer_id']; + } + //SQL拼接最后结尾 + $aCase['review_num'] .= 'END'; + //执行更新 + $result = Db::name('user') + ->where(['user_id' => ['in',$aUpdateId]]) + ->update([ + 'rd_num' => Db::raw($aCase['review_num']), + ]); + } + Db::commit(); + + $this->showMessage('批量更新超过七日未审稿的状态成功',2); + + } + + /** + * + * 格式化信息输出 + * + * @access public + * @return void + * @author huangpu + * @date 2018.09.28 + * @param $[message] [<显示信息>] + * @param $[status] [<输出信息1成功,2失败>] + */ + private function showMessage($message, $status = 1) { + if ($status == 1) { + echo "[SUCCESS]"; + } else { + echo "[ERROR]"; + } + echo date("Y-m-d H:i:s") . " " . $message . "\n"; + } +} diff --git a/application/api/controller/Recommend.php b/application/api/controller/Recommend.php new file mode 100644 index 0000000..58d57a9 --- /dev/null +++ b/application/api/controller/Recommend.php @@ -0,0 +1,119 @@ +request->post(); + //分页 + $iSize = empty($aParam['size']) ? 10 : $aParam['size']; + $iPage = empty($aParam['page']) ? 1 : $aParam['page']; + $limit_start = ($iPage - 1) * $iSize; + + if(empty($aParam['article_id'])){ + exit(json_encode(array('status' => 2,'msg' => 'Please select an article' ))); + } + + //查询文章 + $aArticle = Db::table('t_major_to_article')->field('article_id')->where('article_id',$aParam['article_id'])->find(); + if(empty($aArticle)){ + exit(json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' ))); + } + //查询文章领域 + $aMajorId = Db::table('t_major_to_article')->where('article_id',$aArticle['article_id'])->column('major_id'); + if(empty($aMajorId)){ + exit(json_encode(array('status' => 4,'msg' => 'No field found for the article' ))); + } + + // //根据文章领域获取满足该领域父类 + // $aMajorId = Db::table('t_major')->field('major_id,major_title,pid')->whereIn('major_id', $aMajorArticle)->where('pid != 1')->select(); + $aParentId = Db::table('t_major')->where(['major_id' => ['in',$aMajorId]])->column('major_id,pid'); + $aMajorId = $this->getChildIds(array_values($aParentId)); + + //数据处理拼接父类ID为1的领域 + foreach ($aParentId as $key => $value) { + if(in_array($value, [0,1])){ + array_push($aMajorId,$key); + continue; + } + } + //查询所属该领域的审稿人 + if(empty($aMajorId)){ + exit(json_encode(array('status' => 5,'msg' => 'No reviewers in the field of the article were found' ))); + } + $aMajorUser = Db::name('major_to_user')->whereIn('major_id', $aMajorId)->where('state',0)->order('major_id asc')->column('user_id'); + if(empty($aMajorUser)){ + exit(json_encode(array('status' => 6,'msg' => 'No reviewers in the field of the article were found' ))); + } + $aMajorUser = array_unique($aMajorUser); + + //查询审稿人是否为劣迹审稿人 + $aBlack = Db::name('user_reviewer_black')->whereIn('reviewer_id', $aMajorUser)->where('state',1)->column('reviewer_id'); + if(!empty($aBlack)){ + $aMajorUser = array_diff($aMajorUser, $aBlack); + } + + //查用户信息 + $aWhere = ['user_id' => ['in',$aMajorUser],'state' => 0,'is_reviewer' => 1]; + //统计数量 + $iCount = Db::table('t_user')->where($aWhere)->count(); + if(empty($iCount)){ + exit(json_encode(array('status' => 1,'msg' => '','data' => ['total' => 0,'lists' => []]))); + } + $sOrder = 'review_num asc,right_rate desc'; + $aUser = Db::table('t_user')->field('user_id,account,realname,rs_num,right_times,error_times,right_rate,error_rate,review_num')->where($aWhere)->order($sOrder)->limit($limit_start, $iSize)->select(); + //查询审稿人详细信息 + $aUserId = array_column($aUser, 'user_id'); + $aInfo = Db::name('user_reviewer_info')->field('reviewer_id,technical,country,introduction,company,field')->whereIn('reviewer_id',$aUserId)->select(); + $aInfo = empty($aInfo) ? [] : array_column($aInfo, null,'reviewer_id'); + + foreach ($aUser as $key => $value) { + $value += empty($aInfo[$value['user_id']]) ? [] : $aInfo[$value['user_id']]; + $aUser[$key] = $value; + } + exit(json_encode(array('status' => 1,'msg' => '','data' => ['total' => $iCount,'lists' => $aUser]))); +// + + } + + /** + * 递归获取某个分类下的所有子分类ID + * @param int $parentId 父级ID + * @param array &$result 结果存储 + */ + private function getChildIds($parentId, &$result = []) { + + $parentId = array_unique(array_diff($parentId, [1])); + $children = Db::table('t_major')->whereIn('pid', $parentId)->where('major_state',0)->order('major_id asc')->column('major_id'); + $result = array_merge($result,$children); + if (!empty($children)) { + $this->getChildIds($children, $result); // 递归查询子级 + } + return $result ?? []; + } + + +}