/** * 发送信息 * @param int $fuid 发信会员编号 * @param string $fusername 发信会员名称 * @param array $tuids 收信会员编号数组 * @param string $subject 信件主题 * @param string $message 信件内容 * @param int $type 信件类型 * @return int */ public function sendMsg($fuid, $fusername, $tuids, $subject, $message, $type = 0) { if (empty($fuid) || empty($fusername) || empty($tuids) || empty($message)) { return 0; } //清除重复会员编号 $tuids = array_unique($tuids); $relations = $mlids = array(); $tmp_tuids = $tuids; foreach ($tmp_tuids as $key => $uid) { if ($fuid == $uid || empty($uid)) { unset($tuids[$key]); continue; } $relations[$uid] = MessageService::getRelation($fuid, $uid); } if (empty($tuids)) { return MSG_SEND_NONE_ERROR; } if (!$subject) { $subject = htmlspecialchars(cutStr(clearExpress(trim($message)), 80)); } else { $subject = htmlspecialchars($subject); } $last_msg = htmlspecialchars(cutStr(clearExpress(trim($message)), 150)); $type = 0; if ($type == 0) { $res = FDB::query('SELECT mlid,min_max FROM ' . FDB::table('user_msg_list') . " WHERE min_max" . FDB::createIN($relations)); while ($data = FDB::fetch($res)) { $mlids[$data['min_max']] = $data['mlid']; } $msg_config = array('last_uid' => $fuid, 'last_user_name' => $fusername, 'last_msg' => $last_msg); $msg_config = addslashes(serialize($msg_config)); foreach ($relations as $key => $value) { if (!isset($mlids[$value])) { FDB::query("INSERT INTO " . FDB::table('user_msg_list') . "(uid,type,subject,members,min_max,dateline,msg_config) VALUES('{$fuid}', '1', '{$subject}', 2, '{$value}', '" . TIME_UTC . "', '{$msg_config}')"); $mlid = FDB::insertId(); FDB::query("INSERT INTO " . FDB::table('user_msg_index') . "(mlid) VALUES('{$mlid}')"); $miid = FDB::insertId(); FDB::query("INSERT INTO " . MessageService::getTablaName($mlid) . "(miid,mlid,uid,message,dateline,status) VALUES('{$miid}', '{$mlid}', '{$fuid}', '{$message}', '" . TIME_UTC . "', 0)"); FDB::query("INSERT INTO " . FDB::table('user_msg_member') . "(mlid, uid, is_new, num, last_update, last_dateline) VALUES('{$mlid}', '{$key}', '1', '1', '0', '" . TIME_UTC . "')"); FDB::query("INSERT INTO " . FDB::table('user_msg_member') . "(mlid, uid, is_new, num, last_update, last_dateline) VALUES('{$mlid}', '{$fuid}', '0', '1', '" . TIME_UTC . "', '" . TIME_UTC . "')"); } else { $mlid = $mlids[$value]; FDB::query("INSERT INTO " . FDB::table('user_msg_index') . "(mlid) VALUES('{$mlid}')"); $miid = FDB::insertId(); FDB::query("INSERT INTO " . MessageService::getTablaName($mlid) . "(miid,mlid,uid,message,dateline,status) VALUES('{$miid}', '{$mlid}', '{$fuid}', '{$message}', '" . TIME_UTC . "', 0)"); $result = FDB::query("INSERT INTO " . FDB::table('user_msg_member') . "(mlid, uid, is_new, num, last_update, last_dateline) VALUES('{$mlid}', '{$key}', '1', '1', '0', '" . TIME_UTC . "')", 'SILENT'); if (!$result) { FDB::query("UPDATE " . FDB::table('user_msg_member') . " SET is_new = 1, num = num + 1, last_dateline='" . TIME_UTC . "' WHERE mlid='{$mlid}' AND uid='{$key}'"); } $result = FDB::query("INSERT INTO " . FDB::table('user_msg_member') . "(mlid, uid, is_new, num, last_update, last_dateline) VALUES('{$mlid}', '{$fuid}', '0', '1', '" . TIME_UTC . "', '" . TIME_UTC . "')", 'SILENT'); if (!$result) { FDB::query("UPDATE " . FDB::table('user_msg_member') . " SET is_new = 1, num = num + 1, last_update='" . TIME_UTC . "', last_dateline='" . TIME_UTC . "' WHERE mlid='{$mlid}' AND uid='{$fuid}'"); } FDB::query("UPDATE " . FDB::table('user_msg_list') . " SET msg_config='{$msg_config}' WHERE mlid='{$mlid}'"); } } } else { } foreach ($tuids as $uid) { $result = FDB::query("INSERT INTO " . FDB::table('user_notice') . "(uid, type, num, create_time) VALUES('{$uid}',5,1,'" . TIME_UTC . "')", 'SILENT'); if (!$result) { FDB::query("UPDATE " . FDB::table('user_notice') . " SET num = num + 1, create_time='" . TIME_UTC . "' WHERE uid='{$uid}' AND type=5"); } } return $miid; }