From 0de477b38154b159d57419a41ce72faa3718f4e8 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 16 Nov 2011 10:03:18 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B1=BB=20class=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/message.php | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 application/models/message.php diff --git a/application/models/message.php b/application/models/message.php new file mode 100644 index 00000000..abafe139 --- /dev/null +++ b/application/models/message.php @@ -0,0 +1,95 @@ +prepare($sql); + $sth->execute(); + $msgbody = $sth->fetch(PDO::FETCH_ASSOC); + $msgid = $msgbody['id']; + if(!is_array($rid)) + { + $sql = "INSERT INTO messages (pid,rid,msgid,title) VALUES ('$pid','$rid','$msgid','$title')"; + $sth = $db->prepare($sql); + if($sth->execute()) + { + $rev[$rid]['msg'] = "发送成功"; + }else{ + $rev[$rid]['msg'] = "发送失败"; + } + }else{ + foreach ($rid as $v) + { + $sql = "INSERT INTO messages (pid,rid,msgid,title) VALUES ('$pid','$v','$msgid','$title')"; + $sth = $db->prepare($sql); + if($sth->execute()) + { + $rev[$v]['msg'] = "发送成功"; + }else{ + $rev[$v]['msg'] = "发送失败"; + } + } + } + }catch (Exception $e){ + $rev['error'] = $e->getMessage(); + } + return $rev; + } + + static function getNew($db,$uid,$type="member"){ + $rev = array(); + try{ + $sql = "SELECT * FROM messages m + LEFT JOIN messages_logs ml ON m.id=ml.mid + WHERE ml.uid IS NULL"; + if($type=="member") + { + $sql .= " AND m.rid IN (0,$uid)"; + }else if($type=="admin"){ + $sql .= " AND m.rid IN (-1,0,$uid)"; + } + + $result = $db->query($sql); + + $rows = $result->fetchAll(); + + $rev['count'] = count($rows); + $rev['rows'] = $rows; + + }catch (Exception $e){ + $rev['error'] = $e->getMessage(); + } + return $rev; + } + + static function getOne($db,$uid,$id){ + $rev = array(); + try{ + $sql = "SELECT m.pid,m.rid,m.sendtime,m.status,m.msgid,m.title,mc.body,u.realname,ml.uid FROM messages m + LEFT JOIN messages_content mc ON m.msgid=mc.id + LEFT JOIN users u on u.id=m.pid + LEFT JOIN messages_logs ml ON m.id=ml.mid + WHERE m.id=$id"; + $result = $db->query($sql); + $row = $result->fetch(); + + if(empty($row['uid'])) + { + $sql = "INSERT INTO messages_logs (uid,mid) VALUES ('$uid','$id')"; + @$db->exec($sql); + } + $rev['info'] = $row; + }catch (Exception $e){ + $rev['error'] = $e->getMessage(); + } + return $rev; + } +} \ No newline at end of file