Commit 41b3eacf authored by 陈志良's avatar 陈志良

社区Log

parent 98a887e2
...@@ -40,13 +40,8 @@ router.post('/info/create', function(req, res, next) { ...@@ -40,13 +40,8 @@ router.post('/info/create', function(req, res, next) {
//获取目标论坛板块 //获取目标论坛板块
router.get('/info/:fid/get', function(req, res, next) { router.get('/info/:fid/get', function(req, res, next) {
var fid = req.params.fid || null; var fid = req.params.fid || null;
httpService.createLog(req,2,null);
if (fid) { if (fid) {
httpService.createLog(req,fid,2);
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
//更新浏览数 //更新浏览数
......
...@@ -108,16 +108,19 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -108,16 +108,19 @@ router.get('/thread/:tid/get', function(req, res, next) {
}, },
function(data, callback) { function(data, callback) {
forumThreadService.getThreadById(tid, function(err, thread) { forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙 //文章类型 1、文章 2、话题 3、照片墙
var info_id = thread.info._id,
pid = thread.pid;
if (thread.type == 1) { if (thread.type == 1) {
httpService.createLog(req,3,2,tid); httpService.createLog(req,info_id,3,1,tid);
} else if (thread.type == 2 && thread.level == 1) { } else if (thread.type == 2 && thread.level == 1) {
httpService.createLog(req,3,1,tid); httpService.createLog(req,info_id,3,2,tid);
} else if (thread.type == 2 && thread.level == 2) { } else if (thread.type == 2 && thread.level == 2) {
httpService.createLog(req,3,4,tid); httpService.createLog(req,info_id,3,4,tid,pid);
} else if (thread.type == 3) { } else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req,3,3,tid); httpService.createLog(req,info_id,3,3,tid);
}else if(thread.type == 3 && thread.level == 2){
httpService.createLog(req,info_id,3,4,tid,pid);
} }
......
...@@ -9,44 +9,47 @@ var ForumPVLogSchema = new Schema({ ...@@ -9,44 +9,47 @@ var ForumPVLogSchema = new Schema({
require: true, require: true,
index: true index: true
}, },
user: { //访问者
type: String,
require: true,
index: true,
ref: 'ForumUser'
},
mid: { //会员ID mid: { //会员ID
type: Number, type: Number,
require: true, require: true,
index: true index: true
}, },
forumInfo: { //板块ID
type: String,
index: true,
ref: 'ForumInfo'
},
forumThread: { //话题、文章、照片墙的ID
type: String,
index: true,
ref: 'ForumThread'
},
open_id: { //微信公众号唯一识别 open_id: { //微信公众号唯一识别
type: String, type: String,
require: true, require: true,
index: true index: true
}, },
user: { //访问者 info: { //板块ID
type: String, type: String,
require: true,
index: true, index: true,
ref: 'ForumUser' ref: 'ForumInfo'
}, },
source: { //分享者 thread: { //话题、文章、照片墙的ID
type: String type: String,
index: true,
ref: 'forumThread'
}, },
type: { //页面:1.主页 2.板块 3.文章 type: { //页面:1.主页 2.板块 3.文章
type: Number, type: Number,
index: true, index: true,
require: true require: true
}, },
thread_type: { //文章类型:1.话题 2.文章 3.照片墙 4.子文章 thread_type: { //文章类型:1.普通文章 2.话题 3.照片墙 4.子文章
type: Number, type: Number,
index: true index: true
},
p_thread: { //父文章ID
type: Number,
index: true
},
source: { //分享者
type: String
}, },
ip: { //IP地址 ip: { //IP地址
type: String type: String
...@@ -59,7 +62,6 @@ var ForumPVLogSchema = new Schema({ ...@@ -59,7 +62,6 @@ var ForumPVLogSchema = new Schema({
required: true, required: true,
default: Date.now default: Date.now
} }
}, { }, {
'collection': 'pisns_forum_pv_log' 'collection': 'pisns_forum_pv_log'
}); });
......
...@@ -9,34 +9,31 @@ var ForumUVLogSchema = new Schema({ ...@@ -9,34 +9,31 @@ var ForumUVLogSchema = new Schema({
require: true, require: true,
index: true index: true
}, },
user: { //访问者
type: String,
require: true,
index: true,
ref: 'ForumUser'
},
mid: { //会员ID mid: { //会员ID
type: Number, type: Number,
require: true, require: true,
index: true index: true
}, },
forumInfo: { //板块ID
type: String,
index: true,
ref: 'ForumInfo'
},
forumThread: { //话题、文章、照片墙的ID
type: String,
index: true,
ref: 'forumThread'
},
open_id: { //微信公众号唯一识别 open_id: { //微信公众号唯一识别
type: String, type: String,
require: true, require: true,
index: true index: true
}, },
user: { //访问者 info: { //板块ID
type: String, type: String,
require: true,
index: true, index: true,
ref: 'ForumUser' ref: 'ForumInfo'
}, },
source: { //分享者 thread: { //话题、文章、照片墙的ID
type: String type: String,
index: true,
ref: 'forumThread'
}, },
type: { //页面:1.主页 2.板块 3.文章 type: { //页面:1.主页 2.板块 3.文章
type: Number, type: Number,
...@@ -46,7 +43,13 @@ var ForumUVLogSchema = new Schema({ ...@@ -46,7 +43,13 @@ var ForumUVLogSchema = new Schema({
thread_type: { //文章类型:1.话题 2.文章 3.照片墙 4.子文章 thread_type: { //文章类型:1.话题 2.文章 3.照片墙 4.子文章
type: Number, type: Number,
index: true index: true
},
p_thread: { //父文章ID
type: Number,
index: true
},
source: { //分享者
type: String
}, },
ip: { //IP地址 ip: { //IP地址
type: String type: String
...@@ -59,7 +62,6 @@ var ForumUVLogSchema = new Schema({ ...@@ -59,7 +62,6 @@ var ForumUVLogSchema = new Schema({
required: true, required: true,
default: Date.now default: Date.now
} }
}, { }, {
'collection': 'pisns_forum_uv_log' 'collection': 'pisns_forum_uv_log'
}); });
......
...@@ -49,53 +49,47 @@ var getClientIP = function(req) { ...@@ -49,53 +49,47 @@ var getClientIP = function(req) {
return ipAddress; return ipAddress;
}; };
exports.createLog = function(req, type, thread_type,id) { exports.createLog = function(req,info,type,thread_type,thread,p_thread) {
var ip = getClientIP(req); var logObj = {
var userAgent = req.headers['user-agent'];
var log = {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
mid: req.session.openUser.mid, mid: req.session.openUser.mid,
forumInfo: id,
open_id: req.session.mobileForumUser.openId, open_id: req.session.mobileForumUser.openId,
user: req.session.mobileForumUser.userId, user: req.session.mobileForumUser.userId,
info: info,
type: type, type: type,
thread_type: thread_type, thread_type:thread_type,
ip: ip, thread:thread,
userAgent: userAgent p_thread:p_thread,
ip: getClientIP(req),
userAgent: req.headers['user-agent']
}; };
if (log) { if (logObj) {
var forumPVLog = new ForumPVLog(log); then(function(cont){
var forumUVLog = new ForumUVLog(log); var pv_model = new ForumPVLog(logObj);
forumPVLog.save(function(err, pv) { pv_model.save(cont);
}).then(function(cont){
if (err) {
console.error(err);
} else {
var nowTime = moment(new Date()).format('YYYY-MM-DD');
var startTime = nowTime + " 00:00:00";
var entTime = nowTime + " 23:59:59";
var q = { var q = {
created: { created:{$gte:moment(new Date()).format('YYYY-MM-DD')},
'$gte': startTime, mid:logObj.mid,
'$lte': entTime openId:logObj.openId,
}, user:logObj.user,
user: log.fid info:logObj.info
}; };
ForumUVLog.find(q, function(err, uv) { if(logObj.thread){
if (err) { q.thread = logObj.thread;
console.error(err); q.thread_type = logObj.thread_tyep;
} else if (uv.length == 0) {
forumUVLog.save(function(err, uv) {
if (err) {
console.error(err);
} }
}); ForumUVLog.find(q,function(err,doc){
} cont(err,doc?false:true);
}); })
}).then(function(cont,isLog){
if(isLog){
var uv_model = new ForumUVLog(log);
uv_model.save();
} }
}).fail(function(cont,err){
console.error(err);
}); });
} else { } else {
console.error('没有日志信息'); console.error('没有日志信息');
......
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