文章逻辑删除后,统计数量出错!
文章逻辑删除后,数量统计不正确!
看了下模块
代码顺序搞错了
/models/article.php 文件
原代码 先统计的数据,再更新的文章is_del 状态!
public function remove_article($article_id,$whereDel = false)
{
if (!$article_info = $this->get_article_info_by_id($article_id))
{
return false;
}
$delWhere = null;
$isdel = 1;
if($whereDel !== false){
$delWhere = ' and is_del != 1';
$isdel = $whereDel;
}
$this->update('topic_relation', ['is_del'=>$isdel],"`type` = 'article' AND item_id = " . intval($article_id).$delWhere);// 删除话题关联
$this->update('posts_index', ['is_del'=>$isdel],'post_type="article" and post_id = ' . intval($article_id).$delWhere);
$this->update('user_action_history', ['is_del'=>$isdel],'associate_id = ' . intval($article_id).$delWhere);
$this->shutdown_update('users', array(
'article_count' => $this->count('article', 'is_del=0 and uid = ' . intval($article_info['uid']))
), 'uid = ' . intval($article_info['uid']));
$this->model('topic')->update_discuss_count(3);
AWS_APP::cache()->clean();
return $this->update('article', ['is_del'=>$isdel],'id = ' . intval($article_id).$delWhere);
}
修改成
public function remove_article($article_id,$whereDel = false)
{
if (!$article_info = $this->get_article_info_by_id($article_id))
{
return false;
}
$delWhere = null;
$isdel = 1;
if($whereDel !== false){
$delWhere = ' and is_del != 1';
$isdel = $whereDel;
}
$this->update('topic_relation', ['is_del'=>$isdel],"`type` = 'article' AND item_id = " . intval($article_id).$delWhere);// 删除话题关联
$this->update('posts_index', ['is_del'=>$isdel],'post_type="article" and post_id = ' . intval($article_id).$delWhere);
$this->update('user_action_history', ['is_del'=>$isdel],'associate_id = ' . intval($article_id).$delWhere);
$this->update('article', ['is_del'=>$isdel],'id = ' . intval($article_id).$delWhere);
$this->shutdown_update('users', array(
'article_count' => $this->count('article', 'is_del=0 and uid = ' . intval($article_info['uid']))
), 'uid = ' . intval($article_info['uid']));
$this->model('topic')->update_discuss_count(3);
AWS_APP::cache()->clean();
return true;
}
下面的恢复文章 类模块也按此修改
public function recover_question($article_id,$whereDel = false)
(粗心大意,恢复文章类 翻译成了 恢复问题 ) 。。。。
2019-08-10 19:36