文章逻辑删除后,统计数量出错!

程_什么么
程_什么么 这家伙很懒,还没有设置简介

1 人点赞了该文章 · 1944 浏览

文章逻辑删除后,数量统计不正确!

看了下模块

代码顺序搞错了


/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:35

免责声明:

本文由 程_什么么 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

程_什么么
2019-08-10 19:36
编辑器不支持,代码插入样式。。。