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

社区Log

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