public function article_vote($type, $item_id, $rating, $uid, $reputation_factor, $item_uid) { $this->delete('article_vote', "`type` = '" . $this->quote($type) . "' AND item_id = " . intval($item_id) . ' AND uid = ' . intval($uid)); if ($rating) { if ($article_vote = $this->fetch_row('article_vote', "`type` = '" . $this->quote($type) . "' AND item_id = " . intval($item_id) . " AND rating = " . intval($rating) . ' AND uid = ' . intval($uid))) { $this->update('article_vote', array('rating' => intval($rating), 'time' => time(), 'reputation_factor' => $reputation_factor), 'id = ' . intval($article_vote['id'])); } else { $this->insert('article_vote', array('type' => $type, 'item_id' => intval($item_id), 'rating' => intval($rating), 'time' => time(), 'uid' => intval($uid), 'item_uid' => intval($item_uid), 'reputation_factor' => $reputation_factor)); } } switch ($type) { case 'article': $this->update('article', array('votes' => $this->count('article_vote', "`type` = '" . $this->quote($type) . "' AND item_id = " . intval($item_id) . " AND rating = 1")), 'id = ' . intval($item_id)); switch ($rating) { case 1: ACTION_LOG::save_action($uid, $item_id, ACTION_LOG::CATEGORY_QUESTION, ACTION_LOG::ADD_AGREE_ARTICLE); break; case -1: ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_QUESTION . ' AND associate_action = ' . ACTION_LOG::ADD_AGREE_ARTICLE . ' AND uid = ' . intval($uid) . ' AND associate_id = ' . intval($item_id)); break; } break; case 'comment': $this->update('article_comments', array('votes' => $this->count('article_vote', "`type` = '" . $this->quote($type) . "' AND item_id = " . intval($item_id) . " AND rating = 1")), 'id = ' . intval($item_id)); break; } $this->model('account')->sum_user_agree_count($item_uid); return true; }
/** * * 取消问题关注 * @param int $question_id * * @return boolean true|false */ public function delete_focus_question($question_id, $uid) { if (!$question_id or !$uid) { return false; } ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_QUESTION . ' AND associate_action = ' . ACTION_LOG::ADD_REQUESTION_FOCUS . ' AND uid = ' . intval($uid) . ' AND associate_id = ' . intval($question_id)); return $this->delete('question_focus', 'question_id = ' . intval($question_id) . " AND uid = " . intval($uid)); }
/** * 物理删除话题及其关联的图片等 * * @param $topic_id */ public function remove_topic_by_ids($topic_id) { if (!$topic_id) { return false; } if (is_array($topic_id)) { $topic_ids = $topic_id; } else { $topic_ids[] = $topic_id; } array_walk_recursive($topic_ids, 'intval_string'); foreach ($topic_ids as $topic_id) { if (!($topic_info = $this->get_topic_by_id($topic_id))) { continue; } if ($topic_info['topic_pic']) { foreach (AWS_APP::config()->get('image')->topic_thumbnail as $size) { @unlink(get_setting('upload_dir') . '/topic/' . str_replace(AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], $size['w'] . '_' . $size['h'], $topic_info['topic_pic'])); } @unlink(get_setting('upload_dir') . '/topic/' . str_replace('_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['w'] . '_' . AWS_APP::config()->get('image')->topic_thumbnail['min']['h'], '', $topic_info['topic_pic'])); } // 删除动作 ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_TOPIC . ' AND associate_id = ' . intval($topic_id)); ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_QUESTION . ' AND associate_action = ' . ACTION_LOG::ADD_TOPIC . ' AND associate_attached = ' . intval($topic_id)); $this->delete('topic_focus', 'topic_id = ' . intval($topic_id)); $this->delete('topic_relation', 'topic_id = ' . intval($topic_id)); $this->delete('feature_topic', 'topic_id = ' . intval($topic_id)); $this->delete('related_topic', 'topic_id = ' . intval($topic_id) . ' OR related_id = ' . intval($topic_id)); $this->delete('reputation_topic', ' topic_id = ' . intval($topic_id)); $this->delete('topic', 'topic_id = ' . intval($topic_id)); $this->update('topic', array('parent_id' => 0), 'parent_id = ' . intval($topic_id)); } return true; }
public function remove_user_by_uid($uid, $remove_user_data = false) { $delete_tables = array('active_data', 'answer_uninterested', 'draft', 'education_experience', 'favorite', 'favorite_tag', 'integral_log', 'invitation', 'question_focus', 'question_uninterested', 'report', 'reputation_category', 'reputation_topic', 'related_links', 'topic_focus', 'weixin_login', 'work_experience', 'users_attrib', 'users_online', 'users_qq', 'users_sina', 'users_ucenter', 'users_weixin', 'users_google', 'users'); $update_tables = array('redirect', 'topic_merge', 'topic_relation'); if ($remove_user_data) { if ($user_answers = $this->query_all("SELECT answer_id FROM " . get_table('answer') . " WHERE uid = " . intval($uid))) { foreach ($user_answers as $key => $val) { $answer_ids[] = $val['answer_id']; } $this->update('attach', array('item_id' => 0), "item_id IN (" . implode(',', $answer_ids) . ") AND item_type = 'answer'"); } if ($user_articles = $this->query_all("SELECT id FROM " . get_table('article') . " WHERE uid = " . intval($uid))) { foreach ($user_articles as $key => $val) { $this->model('article')->remove_article($val['id']); } } if ($user_questions = $this->query_all("SELECT question_id FROM " . get_table('question') . " WHERE published_uid = " . intval($uid))) { foreach ($user_questions as $key => $val) { $this->model('question')->remove_question($val['question_id']); } } $update_tables[] = 'answer'; $update_tables[] = 'article'; $delete_tables[] = 'answer_comments'; $delete_tables[] = 'answer_thanks'; $delete_tables[] = 'article_comments'; $delete_tables[] = 'article_vote'; $delete_tables[] = 'question_comments'; $delete_tables[] = 'question_thanks'; if ($inbox_dialog = $this->fetch_all('inbox_dialog', 'recipient_uid = ' . intval($uid) . ' OR sender_uid = ' . intval($uid))) { foreach ($inbox_dialog as $key => $val) { $this->delete('inbox', 'dialog_id = ' . $val['id']); $this->delete('inbox_dialog', 'id = ' . $val['id']); } } } else { $update_tables[] = 'answer'; $update_tables[] = 'answer_comments'; $update_tables[] = 'answer_thanks'; $update_tables[] = 'article'; $update_tables[] = 'article_comments'; $update_tables[] = 'article_vote'; $update_tables[] = 'question_comments'; $update_tables[] = 'question_thanks'; $delete_tables[] = 'inbox'; $this->update('question', array('published_uid' => '-1'), 'published_uid = ' . intval($uid)); } foreach ($delete_tables as $key => $table) { $this->delete($table, 'uid = ' . intval($uid)); } foreach ($update_tables as $key => $table) { $this->update($table, array('uid' => '-1'), 'uid = ' . intval($uid)); } $this->update('answer_vote', array('vote_uid' => '-1'), 'vote_uid = ' . intval($uid)); $this->model('verify')->remove_apply($uid); $this->model('notify')->delete_notify('sender_uid = ' . intval($uid) . ' OR recipient_uid = ' . intval($uid)); $this->delete('question_invite', 'sender_uid = ' . intval($uid) . ' OR recipients_uid = ' . intval($uid)); ACTION_LOG::delete_action_history('uid = ' . intval($uid)); $this->delete('user_follow', 'fans_uid = ' . intval($uid) . ' OR friend_uid = ' . intval($uid)); return true; }
public function remove_answer_by_id($answer_id) { if ($answer_info = $this->model('answer')->get_answer_by_id($answer_id)) { $this->delete('answer_vote', "answer_id = " . intval($answer_id)); // 删除赞同 $this->delete('answer_comments', 'answer_id = ' . intval($answer_id)); // 删除评论 $this->delete('answer_thanks', 'answer_id = ' . intval($answer_id)); // 删除感谢 $this->delete('answer_uninterested', 'answer_id = ' . intval($answer_id)); // 删除没有帮助 ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_ANSWER . ' AND associate_id = ' . intval($answer_id)); ACTION_LOG::delete_action_history('associate_type = ' . ACTION_LOG::CATEGORY_QUESTION . ' AND associate_action = ' . ACTION_LOG::ANSWER_QUESTION . ' AND associate_attached = ' . intval($answer_id)); if ($attachs = $this->model('publish')->get_attach('answer', $answer_id)) { foreach ($attachs as $key => $val) { $this->model('publish')->remove_attach($val['id'], $val['access_key']); } } $this->delete('answer', "answer_id = " . intval($answer_id)); $this->model('question')->update_answer_count($answer_info['question_id']); } return true; }