Commit 53af3f02 authored by wwccw0591's avatar wwccw0591

pc

parent 31afbbc5
...@@ -122,7 +122,11 @@ class MessageController extends \Our\Controller_AbstractApi { ...@@ -122,7 +122,11 @@ class MessageController extends \Our\Controller_AbstractApi {
\Error\ErrorModel::throwException(\Error\CodeConfigModel::receiveError); \Error\ErrorModel::throwException(\Error\CodeConfigModel::receiveError);
} }
} }
public function getUnreadCountAction(){
$messageService = \Business\Message\MessageServiceModel::getInstance();
$unreadCount=$messageService->getUnreadCountByMemberIdAndType($this->memberId);
$this->success(array('unreadCount'=>$unreadCount));
}
public function setAction(){ public function setAction(){
$messageService = \Business\Message\MessageServiceModel::getInstance(); $messageService = \Business\Message\MessageServiceModel::getInstance();
$type=$this->req['data']['type']; $type=$this->req['data']['type'];
......
...@@ -88,7 +88,11 @@ class MessageServiceModel extends \Business\AbstractModel ...@@ -88,7 +88,11 @@ class MessageServiceModel extends \Business\AbstractModel
} }
public function getUnreadCountByMemberIdAndType($toId){
$messageHistoryDao=\DAO\MessageHistoryModel::getInstance();
$count=$messageHistoryDao->getUnreadCountByToIdAndToType($toId);
return $count;
}
/** /**
* 根据消息类型获得一条消息,已经未读消息数量 * 根据消息类型获得一条消息,已经未读消息数量
* *
...@@ -238,17 +242,17 @@ class MessageServiceModel extends \Business\AbstractModel ...@@ -238,17 +242,17 @@ class MessageServiceModel extends \Business\AbstractModel
$memberHistory = $memageHistoryDao->getOneById($messageHistoryId); $memberHistory = $memageHistoryDao->getOneById($messageHistoryId);
$isSuccess = false; $isSuccess = false;
if ($memberHistory['fromId'] == $memberId) { if ($memberHistory['fromId'] == $memberId) {
if ($memberHistory['status'] == ApiConst::recieveRemove) { if ($memberHistory['isDel'] == ApiConst::recieveRemove) {
$isSuccess = $memageHistoryDao->update($messageHistoryId, 'status', ApiConst::remove); $isSuccess = $memageHistoryDao->update($messageHistoryId, 'isDel', ApiConst::remove);
} else { } else {
$isSuccess = $memageHistoryDao->update($messageHistoryId, 'status', ApiConst::sendRemove); $isSuccess = $memageHistoryDao->update($messageHistoryId, 'isDel', ApiConst::sendRemove);
} }
} }
if ($memberHistory['toId'] == $memberId) { if ($memberHistory['toId'] == $memberId) {
if ($memberHistory['status'] == ApiConst::sendRemove) { if ($memberHistory['isDel'] == ApiConst::sendRemove) {
$isSuccess = $memageHistoryDao->update($messageHistoryId, 'status', ApiConst::remove); $isSuccess = $memageHistoryDao->update($messageHistoryId, 'isDel', ApiConst::remove);
} else { } else {
$isSuccess = $memageHistoryDao->update($messageHistoryId, 'status', ApiConst::recieveRemove); $isSuccess = $memageHistoryDao->update($messageHistoryId, 'isDel', ApiConst::recieveRemove);
} }
} }
return $isSuccess; return $isSuccess;
......
...@@ -38,12 +38,19 @@ class MessageHistoryModel extends \DAO\AbstractModel { ...@@ -38,12 +38,19 @@ class MessageHistoryModel extends \DAO\AbstractModel {
* *
*/ */
public function getListByMemberIdAndToIdAndToType($memberId,$selfType,$toId,$toType,$field='*',$pageIndex=0,$pageSize=20){ public function getListByMemberIdAndToIdAndToType($memberId,$selfType,$toId,$toType,$field='*',$pageIndex=0,$pageSize=20){
$where=Common::format(" ((fromId={0} and toId={1} and toType={2} and fromType={3} and status<>2) or (fromId={4} and toId={5} and fromType={6} and toType={7} and status<>3)) and status<>-1",$memberId,$toId,$toType,$selfType,$toId,$memberId,$toType,$selfType); $where=Common::format(" ((fromId={0} and toId={1} and toType={2} and fromType={3} and isDel not in(-1,2)) or (fromId={4} and toId={5} and fromType={6} and toType={7} and isDel not in(-1,2)))",$memberId,$toId,$toType,$selfType,$toId,$memberId,$toType,$selfType);
parent::setDb(); parent::setDb();
$messages=$this->lists($where,array('gmtCreate'=>'desc'),$field,$pageIndex,$pageSize); $messages=$this->lists($where,array('gmtCreate'=>'desc'),$field,$pageIndex,$pageSize);
return $messages; return $messages;
} }
public function getUnreadCountByToIdAndToType($toId,$toType){
$this->setDb($this->dbName);
$where=Common::format(" (toId={0} and status ={2})",$toId,$toType,ApiConst::unread);
$num=$this->db->from($this->_tableName)->select("count(*) as count")->where($where)->fetchNum();
return $num?$num:ApiConst::zero;
}
public function getOneById($id,$field='*'){ public function getOneById($id,$field='*'){
parent::setDb(); parent::setDb();
$where[$this->_primaryKey]=$id; $where[$this->_primaryKey]=$id;
...@@ -65,7 +72,7 @@ class MessageHistoryModel extends \DAO\AbstractModel { ...@@ -65,7 +72,7 @@ class MessageHistoryModel extends \DAO\AbstractModel {
} }
public function updateByFromIdAndSelfTypeAndToIdAndToType($fromId,$fromType,$toId,$toType){ public function updateByFromIdAndSelfTypeAndToIdAndToType($fromId,$fromType,$toId,$toType){
$where=Common::format(" (((fromId={0} and toId={1} and toType={2} and fromType={3}) or (toId={2} and fromId={3} and fromType={0} and toType={1})) and status=0)",$toId,$fromId,$fromType,$toType); $where=Common::format(" (((fromId={0} and toId={1} and toType={2} and fromType={3}) and status=0))",$toId,$fromId,$fromType,$toType);
$data['status']=ApiConst::read; $data['status']=ApiConst::read;
return $this->updateByWhere($where,$data); return $this->updateByWhere($where,$data);
} }
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获得已发送消息的用户列表和(系统消息,订单消息,快递用户消息最后一条消息)</title>
<style>
</style>
</head>
<body>
<form action="/message/getUnreadCount" method="post">
用户登录状态key:<input name="data[key]" value="fd4b739c4815297044191451eabf0eb5"/><br />
<input type="submit" value="提交">
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment