本文共 3639 字,大约阅读时间需要 12 分钟。
public function send_message($sender_uid, $recipient_uid, $message) { if (!$sender_uid OR !$recipient_uid OR !$message) { return false; } if (! $inbox_dialog = $this->get_dialog_by_user($sender_uid, $recipient_uid)) { $inbox_dialog_id = $this->insert('inbox_dialog', array( 'sender_uid' => $sender_uid, 'sender_unread' => 0, 'recipient_uid' => $recipient_uid, 'recipient_unread' => 0, 'add_time' => time(), 'update_time' => time(), 'sender_count' => 0, 'recipient_count' => 0 )); } else { $inbox_dialog_id = $inbox_dialog['id']; } $message_id = $this->insert('inbox', array( 'dialog_id' => $inbox_dialog_id, 'message' => htmlspecialchars($message), 'add_time' => time(), 'uid' => $sender_uid )); $this->update_dialog_count($inbox_dialog_id, $sender_uid); $this->model('account')->update_inbox_unread($recipient_uid); //$this->model('account')->update_inbox_unread($sender_uid); if ($user_info = $this->model('account')->get_user_info_by_uid($sender_uid)) { $this->model('email')->action_email('NEW_MESSAGE', $recipient_uid, get_js_url('/inbox/'), array( 'user_name' => $user_info['user_name'], )); } return $message_id; }
public function send_action() { if (trim($_POST['message']) == '') { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('请输入私信内容'))); } if (!$recipient_user = $this->model('account')->get_user_info_by_username($_POST['recipient'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('接收私信的用户不存在'))); } if ($recipient_user['uid'] == $this->user_id) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('不能给自己发私信'))); } if ($recipient_user['inbox_recv']) { if (! $this->model('message')->check_permission($recipient_user['uid'], $this->user_id)) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('对方设置了只有 Ta 关注的人才能给 Ta 发送私信'))); } } // !注: 来路检测后面不能再放报错提示 if (!valid_post_hash($_POST['post_hash'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('页面停留时间过长,或内容已提交,请刷新页面'))); } $this->model('message')->send_message($this->user_id, $recipient_user['uid'], $_POST['message']); if ($_POST['return_url']) { $rsm = array( 'url' => get_js_url(strip_tags($_POST['return_url'])) ); } else { $rsm = array( 'url' => get_js_url('/inbox/') ); } H::ajax_json_output(AWS_APP::RSM($rsm, 1, null)); }