FeedModel::doEditFeed PHP Method

doEditFeed() public method

分享操作,彻底删除、假删除、回复
public doEditFeed ( integer $feed_id, string $type, string $title, string $uid = null ) : array
$feed_id integer 分享ID
$type string 分享操作类型,deleteFeed:彻底删除,delFeed:假删除,feedRecover:恢复
$title string 知识内容,目前没没有该功能
$uid string 删除分享的用户ID(区别超级管理员)
return array 分享操作后的结果信息数组
    public function doEditFeed($feed_id, $type, $title, $uid = null)
    {
        $return = array('status' => '0');
        if (empty($feed_id)) {
            //$return['data'] = '分享ID不能为空!';
        } else {
            $map['feed_id'] = is_array($feed_id) ? array('IN', $feed_id) : intval($feed_id);
            $save['is_del'] = $type == 'delFeed' ? 1 : 0;
            if ($type == 'deleteFeed') {
                $feedArr = is_array($feed_id) ? $feed_id : explode(',', $feed_id);
                // 取消分享收藏
                foreach ($feedArr as $sid) {
                    $feed = $this->where('feed_id=' . $sid)->find();
                    model('Collection')->delByFeed($sid, 'feed');
                    // model('Collection')->delCollection($sid, 'feed', $feed['uid']);
                }
                // 彻底删除分享
                $res = $this->where($map)->delete();
                // 删除分享相关信息
                if ($res) {
                    $this->_deleteFeedAttach($feed_id, 'deleteAttach');
                }
            } else {
                $ids = !is_array($feed_id) ? array($feed_id) : $feed_id;
                $feedList = $this->getFeeds($ids);
                $res = $this->where($map)->save($save);
                if ($type == 'feedRecover') {
                    // 添加分享数
                    foreach ($feedList as $v) {
                        model('UserData')->setUid($v['user_info']['uid'])->updateKey('feed_count', 1);
                        model('UserData')->setUid($v['user_info']['uid'])->updateKey('weibo_count', 1);
                    }
                    $this->_deleteFeedAttach($ids, 'recoverAttach');
                } else {
                    // 减少分享数
                    foreach ($feedList as $v) {
                        model('UserData')->setUid($v['user_info']['uid'])->updateKey('feed_count', -1);
                        model('UserData')->setUid($v['user_info']['uid'])->updateKey('weibo_count', -1);
                    }
                    $this->_deleteFeedAttach($ids, 'delAttach');
                    // 删除频道相应分享
                    $channelMap['feed_id'] = array('IN', $ids);
                    D('channel')->where($channelMap)->delete();
                }
                model('Collection')->delByFeed($ids, 'feed');
                $this->cleanCache($ids);
                // 删除分享缓存信息
                // 资源分享缓存相关分享
                foreach ($feedList as $item) {
                    if ($item['app'] == 'public') {
                        $sids = $this->where('app_row_id=' . $item['feed_id'])->getAsFieldArray('feed_id');
                        $this->cleanCache($sids);
                    } else {
                        $tmp_map['app'] = $item['app'];
                        $tmp_map['app_row_id'] = $item['app_row_id'];
                        $sids = $this->where($tmp_map)->getAsFieldArray('feed_id');
                        $this->cleanCache($sids);
                    }
                }
            }
            // 删除评论信息
            $cmap['app'] = 'Public';
            $cmap['table'] = 'feed';
            $cmap['row_id'] = is_array($feed_id) ? array('IN', $feed_id) : intval($feed_id);
            $commentIds = model('Comment')->where($cmap)->getAsFieldArray('comment_id');
            model('Comment')->setAppName('Public')->setAppTable('feed')->deleteComment($commentIds);
            if ($res) {
                // TODO:是否记录知识,以及后期缓存处理
                $return = array('status' => 1);
                //添加积分
                model('Credit')->setUserCredit($uid, 'delete_weibo');
            }
        }
        return $return;
    }