1、用户留存记录优化,查询sql新增产品和渠道ID;
2、用户留存记录(按天)优化,查询该天的留存用户数时新增产品和渠道ID。
This commit is contained in:
parent
e8e51ffed8
commit
69748b530b
|
@ -1399,7 +1399,7 @@ func (e MiGuDeployService) UserRetentionList(c *gin.Context) {
|
||||||
|
|
||||||
// 查询对应月份的最近2个月1号留存数据
|
// 查询对应月份的最近2个月1号留存数据
|
||||||
// 现在遍历 retentionList,查询每个月份对应的最近1个月和最近2个月的留存数据
|
// 现在遍历 retentionList,查询每个月份对应的最近1个月和最近2个月的留存数据
|
||||||
for i := range retentionList {
|
for i, item := range retentionList {
|
||||||
// 获取当前记录的 RetentionMonth
|
// 获取当前记录的 RetentionMonth
|
||||||
year, month, _ := models.ParseYearMonth(retentionList[i].RetentionMonth)
|
year, month, _ := models.ParseYearMonth(retentionList[i].RetentionMonth)
|
||||||
|
|
||||||
|
@ -1420,8 +1420,12 @@ func (e MiGuDeployService) UserRetentionList(c *gin.Context) {
|
||||||
lastMonthRetentionCount = 0
|
lastMonthRetentionCount = 0
|
||||||
} else {
|
} else {
|
||||||
err = e.Orm.Model(&models.MgOrder{}).
|
err = e.Orm.Model(&models.MgOrder{}).
|
||||||
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
Where(
|
||||||
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ?", lastMonthSecondDay, currentMonthFirstDay, currentMonthNextFirstDay).
|
e.Orm.
|
||||||
|
Where("state = 1 AND created_at BETWEEN ? AND ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
||||||
|
Or("state = 2 AND unsubscribe_time > ? AND created_at BETWEEN ? AND ?", lastMonthSecondDay, currentMonthFirstDay, currentMonthNextFirstDay),
|
||||||
|
).
|
||||||
|
Where("product_id = ? AND channel_code = ?", item.ProductID, item.ChannelCode).
|
||||||
Count(&lastMonthRetentionCount).Error
|
Count(&lastMonthRetentionCount).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1433,8 +1437,12 @@ func (e MiGuDeployService) UserRetentionList(c *gin.Context) {
|
||||||
lastTwoMonthRetentionCount = 0
|
lastTwoMonthRetentionCount = 0
|
||||||
} else {
|
} else {
|
||||||
err = e.Orm.Model(&models.MgOrder{}).
|
err = e.Orm.Model(&models.MgOrder{}).
|
||||||
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
Where(
|
||||||
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ?", lastTwoMonthSecondDay, currentMonthFirstDay, currentMonthNextFirstDay).
|
e.Orm.
|
||||||
|
Where("state = 1 AND created_at BETWEEN ? AND ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
||||||
|
Or("state = 2 AND unsubscribe_time > ? AND created_at BETWEEN ? AND ?", lastTwoMonthSecondDay, currentMonthFirstDay, currentMonthNextFirstDay),
|
||||||
|
).
|
||||||
|
Where("product_id = ? AND channel_code = ?", item.ProductID, item.ChannelCode).
|
||||||
Count(&lastTwoMonthRetentionCount).Error
|
Count(&lastTwoMonthRetentionCount).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1619,7 +1627,9 @@ func (e MiGuDeployService) UserDayRetentionList(c *gin.Context) {
|
||||||
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
||||||
Where("product_id = ?", req.SkuCode). // 添加SkuCode条件
|
Where("product_id = ?", req.SkuCode). // 添加SkuCode条件
|
||||||
Where("channel_code = ?", req.Channel). // 添加Channel条件
|
Where("channel_code = ?", req.Channel). // 添加Channel条件
|
||||||
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ?", date+" 23:59:59", currentMonthFirstDay, currentMonthNextFirstDay).
|
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ? AND product_id = ? "+
|
||||||
|
"and channel_code = ?", date+" 23:59:59",
|
||||||
|
currentMonthFirstDay, currentMonthNextFirstDay, req.SkuCode, req.Channel).
|
||||||
Count(&retainedUserCount).Error
|
Count(&retainedUserCount).Error
|
||||||
|
|
||||||
// 查询该天的退订用户数
|
// 查询该天的退订用户数
|
||||||
|
@ -1683,7 +1693,9 @@ func (e MiGuDeployService) UserDayRetentionList(c *gin.Context) {
|
||||||
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
Where("state = 1 AND created_at between ? and ?", currentMonthFirstDay, currentMonthNextFirstDay).
|
||||||
Where("product_id = ?", req.SkuCode). // 添加SkuCode条件
|
Where("product_id = ?", req.SkuCode). // 添加SkuCode条件
|
||||||
Where("channel_code = ?", req.Channel). // 添加Channel条件
|
Where("channel_code = ?", req.Channel). // 添加Channel条件
|
||||||
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ?", date+" 23:59:59", currentMonthFirstDay, currentMonthNextFirstDay).
|
Or("state = 2 AND unsubscribe_time > ? AND created_at between ? and ? AND product_id = ? "+
|
||||||
|
"and channel_code = ?", date+" 23:59:59",
|
||||||
|
currentMonthFirstDay, currentMonthNextFirstDay, req.SkuCode, req.Channel).
|
||||||
Count(&retainedUserCount).Error
|
Count(&retainedUserCount).Error
|
||||||
|
|
||||||
//retainedUserCount, localErr = getRetentionForDay(date, e.Orm, currentMonthFirstDay, currentMonthNextFirstDay)
|
//retainedUserCount, localErr = getRetentionForDay(date, e.Orm, currentMonthFirstDay, currentMonthNextFirstDay)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user