コード例 #1
0
    /**
     * 保存分享的评论
     * @param array $_POST 提交的数据
     * @return int 评论编号
     */
    public function saveComment($_POST)
    {
        global $_FANWE;
        $share_id = intval($_POST['share_id']);
        $data = array();
        $data['content'] = htmlspecialchars(trim($_POST['content']));
        $data['uid'] = $_FANWE['uid'];
        $data['parent_id'] = intval($_POST['parent_id']);
        $data['share_id'] = $share_id;
        $data['create_time'] = TIME_UTC;
        $comment_id = FDB::insert('share_comment', $data, true);
        $is_relay = isset($_POST['is_relay']) ? intval($_POST['is_relay']) : 0;
        //转发分享
        if ($is_relay == 1) {
            $share = ShareService::getShareById($share_id);
            if ($share['base_id'] > 0) {
                $share_user = FS('User')->getUserCache($share['uid']);
                $_POST['content'] = trim($_POST['content']) . '//@' . $share_user['user_name'] . ':' . $share['content'];
            }
            //添加评论消息提示
            $result = FDB::query("INSERT INTO " . FDB::table('user_notice') . "(uid, type, num, create_time) VALUES('{$share['uid']}',3,1,'" . TIME_UTC . "')", 'SILENT');
            if (!$result) {
                FDB::query("UPDATE " . FDB::table('user_notice') . " SET num = num + 1, create_time='" . TIME_UTC . "' WHERE uid='{$share['uid']}' AND type=3");
            }
            ShareService::saveRelay($_POST);
        }
        //分享评论数量加1
        FDB::query('UPDATE ' . FDB::table('share') . '
			SET comment_count = comment_count + 1
			WHERE share_id = ' . $share_id);
        //清除分享评论列表缓存
        ShareService::updateShareCache($share_id, 'comments');
        return $comment_id;
    }
コード例 #2
0
    public function deleteShareCollectUser($share_id, $uid)
    {
        global $_FANWE;
        $share_id = (int) $share_id;
        $uid = (int) $uid;
        if (!$share_id || !$uid) {
            return false;
        }
        $share = ShareService::getShareById($share_id);
        if (empty($share)) {
            return false;
        }
        FDB::query('DELETE FROM ' . FDB::table('user_collect') . '
			WHERE c_uid = ' . $uid . ' AND share_id = ' . $share_id);
        //为专辑添加喜欢
        if ($share['type'] == 'album_item') {
            $album_share = (int) FDB::resultFirst('SELECT share_id FROM ' . FDB::table('album') . ' WHERE id = ' . $share['rec_id']);
            FDB::query('UPDATE ' . FDB::table('share') . ' SET collect_count = collect_count - 1 WHERE share_id = ' . $album_share);
            FDB::query('UPDATE ' . FDB::table('album') . ' SET collect_count = collect_count - 1 WHERE id = ' . $share['rec_id']);
        }
        if ($share['type'] == 'album') {
            FDB::query('UPDATE ' . FDB::table('album') . ' SET collect_count = collect_count - 1 WHERE share_id = ' . $share_id);
        }
        //分享被喜欢数减1
        FDB::query('UPDATE ' . FDB::table('share') . '
			SET collect_count = collect_count - 1
			WHERE share_id = ' . $share_id);
        //分享会员被喜欢数减1
        FDB::query('UPDATE ' . FDB::table('user_count') . '
			SET collects = collects - 1
			WHERE uid = ' . $share['uid']);
        //分享会员喜欢数减1
        FDB::query('UPDATE ' . FDB::table('user_count') . '
			SET favs = favs - 1
			WHERE uid = ' . $_FANWE['uid']);
        FS('Medal')->runAuto($share['uid'], 'collects');
        ShareService::updateShareCache($share_id, 'collects');
        return true;
    }