Commit aae54743 authored by gongguan's avatar gongguan

修改数据需求的获取形式

parent 1df4d685
...@@ -68,25 +68,21 @@ export default class StatService { ...@@ -68,25 +68,21 @@ export default class StatService {
const endDayTimestamp = formatDate(endDay).getTimestamp() const endDayTimestamp = formatDate(endDay).getTimestamp()
while (curDayTimestamp <= endDayTimestamp) { while (curDayTimestamp <= endDayTimestamp) {
// 访问PV // 访问PV
const PV = await this.accessdao.count({ activityId, createDay: day }) const PVpromise = this.accessdao.count({ activityId, createDay: day })
// 访问UV // 访问UV
const UV = await this.userdao.count({ activityId, [`login.${day}`]: { $exists: true } }) const UVpromise = this.userdao.count({ activityId, [`login.${day}`]: { $exists: true } })
// 新增UV // 新增UV
const newUV = await this.userdao.count({ activityId, createDay: day }) const newUVpromise = this.userdao.count({ activityId, createDay: day })
// 新增PV
// const newPV = await this.userdao.count({ activityId, createDay: day })
// 新增UV(通过邀请) // 新增UV(通过邀请)
const newUVFromInviteUV = ( const newUVFromInviteUVpromise = this.accessdao.aggregate([
await this.accessdao.aggregate([ { $match: { activityId, createDay: day, inviteId: { $exists: true } } },
{ $match: { activityId, createDay: day, inviteId: { $exists: true } } }, { $project: { openId: true } },
{ $project: { openId: true } }, { $group: { _id: '$openId', count: { $sum: 1 } } }
{ $group: { _id: '$openId', count: { $sum: 1 } } } ])
])
).length
// 已入会(老会员)PV // 已入会(老会员)PV
const vipPV = await this.accessdao.count({ const vipPVpromise = this.accessdao.count({
activityId, activityId,
createDay: day, createDay: day,
//@ts-ignore //@ts-ignore
...@@ -95,7 +91,7 @@ export default class StatService { ...@@ -95,7 +91,7 @@ export default class StatService {
}) })
// 已入会(老会员)UV // 已入会(老会员)UV
const vipUV = await this.userdao.count({ const vipUVpromise = this.userdao.count({
activityId, activityId,
[`login.${day}`]: { $exists: true }, [`login.${day}`]: { $exists: true },
$or: [ $or: [
...@@ -107,30 +103,26 @@ export default class StatService { ...@@ -107,30 +103,26 @@ export default class StatService {
}) })
// 未入会PV // 未入会PV
const noVipPV = await this.accessdao.count({ activityId, createDay: day, isVip: false }) const noVipPVpromise = this.accessdao.count({ activityId, createDay: day, isVip: false })
// 未入会UV // 未入会UV
const noVipUV = ( const noVipUVpromise = this.accessdao.aggregate([
await this.accessdao.aggregate([ { $match: { activityId, createDay: day, isVip: false } },
{ $match: { activityId, createDay: day, isVip: false } }, { $project: { openId: true } },
{ $project: { openId: true } }, { $group: { _id: '$openId', count: { $sum: 1 } } }
{ $group: { _id: '$openId', count: { $sum: 1 } } } ])
])
).length
// 新增入会UV // 新增入会UV
const newVipUV = await this.userdao.count({ activityId, 'member.newMember': true, 'member.bememberDay': day }) const newVipUVpromise = this.userdao.count({ activityId, 'member.newMember': true, 'member.bememberDay': day })
const newFollowUV = await this.userdao.count({ activityId, 'follow.newFollow': true, 'follow.followDay': day }) const newFollowUVpromise = this.userdao.count({ activityId, 'follow.newFollow': true, 'follow.followDay': day })
// 助力成功UV // 助力成功UV
const helpSuccessUV = ( const helpSuccessUVpromise = this.statdao.aggregate([
await this.statdao.aggregate([ { $match: { activityId, createDay: day, type: STAT_TYPE.INITE_SUCCESS } },
{ $match: { activityId, createDay: day, type: STAT_TYPE.INITE_SUCCESS } }, { $project: { openId: true } },
{ $project: { openId: true } }, { $group: { _id: '$openId', count: { $sum: 1 } } }
{ $group: { _id: '$openId', count: { $sum: 1 } } } ])
])
).length
// 根据任务类型获取完成任务的人数 // 根据任务类型获取完成任务的人数
// example: await getTaskCompleteUV('collectGoods', day) // example: await getTaskCompleteUV('collectGoods', day)
...@@ -141,22 +133,48 @@ export default class StatService { ...@@ -141,22 +133,48 @@ export default class StatService {
}) })
} }
const [
PV,
UV,
newUV,
newUVFromInviteUV,
vipPV,
vipUV,
noVipPV,
noVipUV,
newVipUV,
newFollowUV,
helpSuccessUV,
] = await Promise.all([
PVpromise,
UVpromise,
newUVpromise,
newUVFromInviteUVpromise,
vipPVpromise,
vipUVpromise,
noVipPVpromise,
noVipUVpromise,
newVipUVpromise,
newFollowUVpromise,
helpSuccessUVpromise,
])
const keyValueMapper = { const keyValueMapper = {
时间: day, 时间: day,
访问PV: PV, 访问PV: PV,
访问UV: UV, 访问UV: UV,
新增UV: newUV, 新增UV: newUV,
'新增UV(通过邀请)': newUVFromInviteUV, '新增UV(通过邀请)': newUVFromInviteUV.length,
'已入会(老会员)PV': vipPV, '已入会(老会员)PV': vipPV,
'已入会(老会员)UV': vipUV, '已入会(老会员)UV': vipUV,
未入会PV: noVipPV, 未入会PV: noVipPV,
未入会UV: noVipUV, 未入会UV: noVipUV.length,
新入会UV: newVipUV, 新入会UV: newVipUV,
新增关注UV: newFollowUV, 新增关注UV: newFollowUV,
助力成功UV: helpSuccessUV 助力成功UV: helpSuccessUV.length
//收藏商品任务完成UV: await getTaskCompleteUV('collectGoods', day) //收藏商品任务完成UV: await getTaskCompleteUV('collectGoods', day)
} }
console.log(keyValueMapper, 'xlsxData') console.log('keyValueMapper::::::::::', keyValueMapper)
if (day === startDay) { if (day === startDay) {
xlsxData.push(Object.keys(keyValueMapper)) xlsxData.push(Object.keys(keyValueMapper))
...@@ -167,6 +185,7 @@ export default class StatService { ...@@ -167,6 +185,7 @@ export default class StatService {
curDayTimestamp = tommorrow curDayTimestamp = tommorrow
day = dateFormatter(transformBeijingDate(tommorrow), 'yyyy/MM/dd') day = dateFormatter(transformBeijingDate(tommorrow), 'yyyy/MM/dd')
} }
console.log('xlsxData::::::::::', xlsxData)
return xlsxData return xlsxData
} }
......
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