1.新增营收分析接口;
This commit is contained in:
parent
f8e1a6e92d
commit
ff4b3a7b54
|
@ -807,8 +807,8 @@ func (e MiGuDeployService) HomepageDataSummary(c *gin.Context) {
|
|||
Where("subscribe_time >= ? AND subscribe_time <= ?", startTime, endTime)
|
||||
|
||||
// 添加产品和渠道的过滤条件
|
||||
if req.SkuCode != "" {
|
||||
qs = qs.Where("product_id = ?", req.SkuCode)
|
||||
if req.ProductID != 0 {
|
||||
qs = qs.Where("product_id = ?", req.ProductID)
|
||||
}
|
||||
if req.Channel != "" {
|
||||
qs = qs.Where("channel_code = ?", req.Channel)
|
||||
|
@ -852,8 +852,8 @@ func (e MiGuDeployService) HomepageDataSummary(c *gin.Context) {
|
|||
Where("subscribe_time >= ? AND subscribe_time <= ?", startTime, endTime)
|
||||
|
||||
// 处理产品编号 (SkuCode) 过滤条件
|
||||
if req.SkuCode != "" {
|
||||
dailyQuery = dailyQuery.Where("product_id = ?", req.SkuCode)
|
||||
if req.ProductID != 0 {
|
||||
dailyQuery = dailyQuery.Where("product_id = ?", req.ProductID)
|
||||
}
|
||||
|
||||
// 处理渠道名称 (Channel) 过滤条件
|
||||
|
@ -887,6 +887,77 @@ func (e MiGuDeployService) HomepageDataSummary(c *gin.Context) {
|
|||
e.OK(resp, "")
|
||||
}
|
||||
|
||||
// CalculateRevenueAnalysis 营收分析
|
||||
// @Summary 营收分析
|
||||
// @Tags 2024-咪咕-管理后台
|
||||
// @Produce json
|
||||
// @Accept json
|
||||
// @Param request body models.RetentionMonthsReq true "营收分析"
|
||||
// @Success 200 {object} models.RetentionMonthsResp
|
||||
// @Router /api/v1/admin/home/revenue_analysis [post]
|
||||
func (e MiGuDeployService) CalculateRevenueAnalysis(c *gin.Context) {
|
||||
fmt.Println("CalculateRevenueAnalysis")
|
||||
err := e.MakeContext(c).MakeOrm().Errors
|
||||
if err != nil {
|
||||
fmt.Println("MakeContext err:", err)
|
||||
e.Logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 绑定请求参数
|
||||
req := &models.RetentionMonthsReq{}
|
||||
if err := c.ShouldBindJSON(req); err != nil {
|
||||
response.Error(c, http.StatusBadRequest, err, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
// 构建查询
|
||||
query := e.Orm.Model(&models.MgOrder{})
|
||||
|
||||
// 新用户数的查询条件:当月的所有数据(包含订购和退订,不用区分)
|
||||
if req.StartTime != "" && req.EndTime != "" {
|
||||
query = query.Where("subscribe_time >= ? AND subscribe_time <= ?", req.StartTime, req.EndTime)
|
||||
}
|
||||
if req.ProductID != 0 {
|
||||
query = query.Where("product_id = ?", req.ProductID)
|
||||
}
|
||||
if req.Channel != "" {
|
||||
query = query.Where("channel_code = ?", req.Channel)
|
||||
}
|
||||
|
||||
// 统计每个月的新用户数和当月有效用户数
|
||||
var result []models.MonthlyRetention
|
||||
err = query.
|
||||
Select(`DATE_FORMAT(subscribe_time, '%Y-%m') AS month,
|
||||
COUNT(DISTINCT phone_number) AS new_user_count,
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN unsubscribe_time IS NULL OR TIMESTAMPDIFF(HOUR, subscribe_time, unsubscribe_time) > 24
|
||||
THEN phone_number END) AS valid_users_count`).
|
||||
Group("month").
|
||||
Order("month").
|
||||
Find(&result).Error
|
||||
if err != nil {
|
||||
response.Error(c, http.StatusInternalServerError, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 计算总的新用户数
|
||||
totalNewUserCount := 0
|
||||
totalValidUsers := 0
|
||||
for _, data := range result {
|
||||
totalNewUserCount += data.NewUserCount
|
||||
totalValidUsers += data.ValidUsersCount
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
resp := models.RetentionMonthsResp{
|
||||
TotalNewUsers: totalNewUserCount, // 添加总新用户数
|
||||
TotalValidUsers: totalValidUsers, // 添加有效用户数
|
||||
MonthlyRetentionData: result,
|
||||
}
|
||||
response.OK(c, resp, "查询成功")
|
||||
}
|
||||
|
||||
// AddChannel 新增渠道
|
||||
// @Summary 新增渠道
|
||||
// @Tags 2024-咪咕-管理后台
|
||||
|
|
|
@ -492,7 +492,7 @@ type DeleteChannelResp struct {
|
|||
type HomepageDataSummaryReq struct {
|
||||
StartTime string `json:"start_time"` // 查询开始时间
|
||||
EndTime string `json:"end_time"` // 查询结束时间
|
||||
SkuCode string `json:"sku_code"` // 产品编号
|
||||
ProductID int `json:"product_id"` // 产品ID
|
||||
Channel string `json:"channel"` // 渠道名称
|
||||
}
|
||||
|
||||
|
@ -521,6 +521,28 @@ type SummaryData struct {
|
|||
RetentionRate string `json:"retention_rate"` // 留存率 (字符串,保留两位小数,如 "73.65%")
|
||||
}
|
||||
|
||||
// RetentionMonthsReq 查询用户留存月份的请求结构体
|
||||
type RetentionMonthsReq struct {
|
||||
StartTime string `json:"start_time"` // 查询开始时间
|
||||
EndTime string `json:"end_time"` // 查询结束时间
|
||||
ProductID int `json:"product_id"` // 产品ID
|
||||
Channel string `json:"channel"` // 渠道名称
|
||||
}
|
||||
|
||||
// MonthlyRetention 表示每月留存数据
|
||||
type MonthlyRetention struct {
|
||||
Month string `json:"month"` // 年月
|
||||
NewUserCount int `json:"new_user_count"` // 新用户数
|
||||
ValidUsersCount int `json:"valid_users_count"` // 当月有效用户数
|
||||
}
|
||||
|
||||
// RetentionMonthsResp 表示响应参数结构体
|
||||
type RetentionMonthsResp struct {
|
||||
TotalNewUsers int `json:"total_new_users"` // 总新用户数
|
||||
TotalValidUsers int `json:"total_valid_users"` // 总有效用户数
|
||||
MonthlyRetentionData []MonthlyRetention `json:"monthly_retention_data"` // 每月留存数据
|
||||
}
|
||||
|
||||
// MiGuCaptchaRequest 调用下单接口(森越转发)
|
||||
func MiGuCaptchaRequest(r *MiGuSendCaptchaReq) (MiGuRsp, error) {
|
||||
var miGuResp MiGuRsp
|
||||
|
|
|
@ -28,6 +28,7 @@ func registerMiGuControlManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.Gi
|
|||
api.POST("user_retention/list", apiMiGu.UserRetentionList) // 用户留存记录
|
||||
api.POST("sys_channel/list", apiMiGu.SysChannelList) // 查询系统所有渠道编码
|
||||
api.POST("home/data", apiMiGu.HomepageDataSummary) // 查询首页汇总数据
|
||||
api.POST("home/revenue_analysis", apiMiGu.CalculateRevenueAnalysis) // 查询不同日期的留存月份
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,39 @@ const docTemplateadmin = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/admin/home/revenue_analysis": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"2024-咪咕-管理后台"
|
||||
],
|
||||
"summary": "营收分析",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "营收分析",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.RetentionMonthsReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.RetentionMonthsResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/admin/order/list": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
|
@ -5021,9 +5054,9 @@ const docTemplateadmin = `{
|
|||
"description": "查询结束时间",
|
||||
"type": "string"
|
||||
},
|
||||
"sku_code": {
|
||||
"description": "产品编号",
|
||||
"type": "string"
|
||||
"product_id": {
|
||||
"description": "产品ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"start_time": {
|
||||
"description": "查询开始时间",
|
||||
|
@ -5350,6 +5383,23 @@ const docTemplateadmin = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"models.MonthlyRetention": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"month": {
|
||||
"description": "年月",
|
||||
"type": "string"
|
||||
},
|
||||
"new_user_count": {
|
||||
"description": "新用户数",
|
||||
"type": "integer"
|
||||
},
|
||||
"valid_users_count": {
|
||||
"description": "当月有效用户数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.NewSendDataReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -5652,6 +5702,47 @@ const docTemplateadmin = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"models.RetentionMonthsReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"channel": {
|
||||
"description": "渠道名称",
|
||||
"type": "string"
|
||||
},
|
||||
"end_time": {
|
||||
"description": "查询结束时间",
|
||||
"type": "string"
|
||||
},
|
||||
"product_id": {
|
||||
"description": "产品ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"start_time": {
|
||||
"description": "查询开始时间",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.RetentionMonthsResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"monthly_retention_data": {
|
||||
"description": "每月留存数据",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.MonthlyRetention"
|
||||
}
|
||||
},
|
||||
"total_new_users": {
|
||||
"description": "总新用户数",
|
||||
"type": "integer"
|
||||
},
|
||||
"total_valid_users": {
|
||||
"description": "总有效用户数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.SendCaptchaReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
|
@ -143,6 +143,39 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/admin/home/revenue_analysis": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"2024-咪咕-管理后台"
|
||||
],
|
||||
"summary": "营收分析",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "营收分析",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.RetentionMonthsReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.RetentionMonthsResp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/admin/order/list": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
|
@ -5013,9 +5046,9 @@
|
|||
"description": "查询结束时间",
|
||||
"type": "string"
|
||||
},
|
||||
"sku_code": {
|
||||
"description": "产品编号",
|
||||
"type": "string"
|
||||
"product_id": {
|
||||
"description": "产品ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"start_time": {
|
||||
"description": "查询开始时间",
|
||||
|
@ -5342,6 +5375,23 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"models.MonthlyRetention": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"month": {
|
||||
"description": "年月",
|
||||
"type": "string"
|
||||
},
|
||||
"new_user_count": {
|
||||
"description": "新用户数",
|
||||
"type": "integer"
|
||||
},
|
||||
"valid_users_count": {
|
||||
"description": "当月有效用户数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.NewSendDataReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
@ -5644,6 +5694,47 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"models.RetentionMonthsReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"channel": {
|
||||
"description": "渠道名称",
|
||||
"type": "string"
|
||||
},
|
||||
"end_time": {
|
||||
"description": "查询结束时间",
|
||||
"type": "string"
|
||||
},
|
||||
"product_id": {
|
||||
"description": "产品ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"start_time": {
|
||||
"description": "查询开始时间",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.RetentionMonthsResp": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"monthly_retention_data": {
|
||||
"description": "每月留存数据",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.MonthlyRetention"
|
||||
}
|
||||
},
|
||||
"total_new_users": {
|
||||
"description": "总新用户数",
|
||||
"type": "integer"
|
||||
},
|
||||
"total_valid_users": {
|
||||
"description": "总有效用户数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"models.SendCaptchaReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
|
|
@ -1052,9 +1052,9 @@ definitions:
|
|||
end_time:
|
||||
description: 查询结束时间
|
||||
type: string
|
||||
sku_code:
|
||||
description: 产品编号
|
||||
type: string
|
||||
product_id:
|
||||
description: 产品ID
|
||||
type: integer
|
||||
start_time:
|
||||
description: 查询开始时间
|
||||
type: string
|
||||
|
@ -1288,6 +1288,18 @@ definitions:
|
|||
description: 留存率(以百分比形式存储)
|
||||
type: string
|
||||
type: object
|
||||
models.MonthlyRetention:
|
||||
properties:
|
||||
month:
|
||||
description: 年月
|
||||
type: string
|
||||
new_user_count:
|
||||
description: 新用户数
|
||||
type: integer
|
||||
valid_users_count:
|
||||
description: 当月有效用户数
|
||||
type: integer
|
||||
type: object
|
||||
models.NewSendDataReq:
|
||||
properties:
|
||||
cert_list:
|
||||
|
@ -1498,6 +1510,35 @@ definitions:
|
|||
page_size:
|
||||
type: integer
|
||||
type: object
|
||||
models.RetentionMonthsReq:
|
||||
properties:
|
||||
channel:
|
||||
description: 渠道名称
|
||||
type: string
|
||||
end_time:
|
||||
description: 查询结束时间
|
||||
type: string
|
||||
product_id:
|
||||
description: 产品ID
|
||||
type: integer
|
||||
start_time:
|
||||
description: 查询开始时间
|
||||
type: string
|
||||
type: object
|
||||
models.RetentionMonthsResp:
|
||||
properties:
|
||||
monthly_retention_data:
|
||||
description: 每月留存数据
|
||||
items:
|
||||
$ref: '#/definitions/models.MonthlyRetention'
|
||||
type: array
|
||||
total_new_users:
|
||||
description: 总新用户数
|
||||
type: integer
|
||||
total_valid_users:
|
||||
description: 总有效用户数
|
||||
type: integer
|
||||
type: object
|
||||
models.SendCaptchaReq:
|
||||
properties:
|
||||
channel:
|
||||
|
@ -2022,6 +2063,27 @@ paths:
|
|||
summary: 查询首页汇总数据
|
||||
tags:
|
||||
- 2024-咪咕-管理后台
|
||||
/api/v1/admin/home/revenue_analysis:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: 营收分析
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.RetentionMonthsReq'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/models.RetentionMonthsResp'
|
||||
summary: 营收分析
|
||||
tags:
|
||||
- 2024-咪咕-管理后台
|
||||
/api/v1/admin/order/list:
|
||||
post:
|
||||
consumes:
|
||||
|
|
Loading…
Reference in New Issue
Block a user