123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- var express = require('express');
- var router = express.Router();
- var msg_statistic = require("../models/msg_statistic");
- /**
- * 群组消息统计:statistic/getgroupchatinfo.im?uid=x&gid=xx
- * 参数:
- * uid:信息所有者id
- * gid:群组id
- */
- router.get('/getgroupchatinfo.im', function (req, res, next) {
- if (req.query.uid == null
- || req.query.gid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getGroupChatInfo(req.query.uid, req.query.gid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- if (result.length == 0) {
- var data = {"uid":req.query.uid,"from_uid":"","from_gid":req.query.gid,"at_me":0,"last_content_type":1,"last_content":"","new_msg_count":0,"timestamp":0};
- res.send(data);
- return;
- }
- result[0].timestamp = Date.parse(new Date(result[0].timestamp));
- res.send(result[0]);
- });
- });
- /**
- * 一对一聊天消息统计:statistic/getp2pchatinfo.im?uid=x&peer_uid=xx
- * 参数:
- * uid:信息所有者id
- * peer_uid:聊天对端id
- */
- router.get('/getp2pchatinfo.im', function (req, res, next) {
- if (req.query.uid == null
- || req.query.peer_uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getP2PChatInfo(req.query.uid, req.query.peer_uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- if (result.length == 0) {
- var data = {"uid":req.query.uid,"from_uid":req.query.peer_uid,"last_content_type":1,"last_content":"","new_msg_count":0,"timestamp":0};
- res.send(data);
- return;
- }
- result[0].timestamp = Date.parse(new Date(result[0].timestamp));
- res.send(result[0]);
- });
- });
- /**
- * 获取聊天列表:statistic/getchatlist.im?uid=x
- * 参数:
- * uid:信息所有者id
- */
- router.get('/getchatlist.im', function (req, res, next) {
- if (req.query.uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getChatList(req.query.uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- if (result.length == 0) {
- var data = {"uid":req.query.uid,"from_uid":req.query.peer_uid,"last_content_type":1,"last_content":"","new_msg_count":0,"timestamp":0};
- res.send(data);
- return;
- }
- //result[0].timestamp = Date.parse(new Date(result[0].timestamp));
- for (var index = 0; index < result.length; index++) {
- result[index].timestamp = Date.parse(new Date(result[index].timestamp));
- }
- res.send(result);
- });
- });
- /**
- * 群组聊天消息所有未读数:statistic/getgroupunreadcount.im?uid=x
- * 参数:
- * uid:信息所有者id
- */
- router.get('/getgroupunreadcount.im', function (req, res, next) {
- if (req.query.uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getGroupChatAllUnRead(req.query.uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- var data = {"uid":req.query.uid,"msg_type":2,"new_msg_count":0};
- if (result.length == 0) {
- res.send(data);
- return;
- }
- var count = 0;
- var index = 0;
- var length = result.length;
- for (; index < length; index++) {
- count += result[index].new_msg_count;
- }
- data.new_msg_count = count;
- res.send(data);
- });
- });
- /**
- * 一对一聊天消息所有未读数:statistic/getp2punreadcount.im?uid=x
- * 参数:
- * uid:信息所有者id
- */
- router.get('/getp2punreadcount.im', function (req, res, next) {
- if (req.query.uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getP2PChatAllUnRead(req.query.uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- var data = {"uid":req.query.uid,"msg_type":1,"new_msg_count":0};
- if (result.length == 0) {
- res.send(data);
- return;
- }
- var count = 0;
- var index = 0;
- var length = result.length;
- for (; index < length; index++) {
- count += result[index].new_msg_count;
- }
- data.new_msg_count = count;
- res.send(data);
- });
- });
- /**
- * 所有聊天消息未读数:statistic/getallunreadmsgcount.im?uid=x
- * 参数:
- * uid:信息所有者id
- */
- router.get('/getallunreadmsgcount.im', function (req, res, next) {
- if (req.query.uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getChatAllUnRead(req.query.uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get statistic from db error'});
- return;
- }
- var data = {"uid":req.query.uid,"msg_type":0,"new_msg_count":0};
- if (result.length == 0) {
- res.send(data);
- return;
- }
- var count = 0;
- var index = 0;
- var length = result.length;
- for (; index < length; index++) {
- count += result[index].new_msg_count;
- }
- data.new_msg_count = count;
- res.send(data);
- });
- });
- /**
- * 获取角标数:statistic/getbadgenum.im?uid=x
- * 参数:
- * uid:用户id
- */
- router.get('/getbadgenum.im', function (req, res, next) {
- if (req.query.uid == null) {
- res.send({errno: -1, errmsg: 'parameter error'});
- return;
- }
- msg_statistic.getBadgeNumber(req.query.uid, function (err, result) {
- if (err) {
- res.send({errno: 1, errmsg: 'get badge error'});
- return;
- }
- var data = {"uid":req.query.uid,"badge":result};
- res.send(data);
- });
- });
- module.exports = router;
|