@@ -624,3 +624,90 @@ func HeroList(c *gin.Context) { | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} | |||
// StarRoadProgress | |||
// @Summary 蛋蛋星球-主页-星球之路升级条件(获取) | |||
// @Tags 主页 | |||
// @Description 星球之路升级条件(获取) | |||
// @Accept json | |||
// @Produce json | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Success 200 {object} md.StarRoadProgressResp "具体数据" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/homePage/starRoad [get] | |||
func StarRoadProgress(c *gin.Context) { | |||
user := svc.GetUser(c) | |||
// 1. 获取等级列表 | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
levels, err := levelDb.UserLevelAllByAsc() | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
// 2. 获取下一等级信息 | |||
var nextLevel *model.UserLevel | |||
var currentLevelName string | |||
for i, level := range levels { | |||
if level.Id == user.Level { | |||
if i < len(levels)-1 { | |||
nextLevel = levels[i+1] | |||
} | |||
currentLevelName = level.LevelName | |||
} | |||
} | |||
var list []md.LevelTaskNode | |||
// 3. 判断是否已达到最高等级 | |||
if nextLevel != nil { | |||
// 4. 获取下一等级任务信息 | |||
taskDb := implement.NewUserLevelTaskDb(db.Db) | |||
levelTasks, err := taskDb.UserLevelTaskFindByParams(map[string]interface{}{ | |||
"key": "level_id", | |||
"value": nextLevel.Id, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
now := time.Now() | |||
// 5. 统计完成任务数 | |||
for _, levelTask := range levelTasks { | |||
var count int64 | |||
var err1 error | |||
// 5.1 判断任务是否完成 | |||
switch levelTask.TaskType { | |||
case 1: | |||
_, count, err1 = svc.IsFinishDirectPush(user.Id, levelTask.FinishCount) | |||
case 2: | |||
_, count, err1 = svc.IsFinishDirectPushOfActiveDays(user.Id, levelTask.FinishCount, levelTask.ActiveDays, now, levelTask.WithinDays) | |||
case 3: | |||
_, count, err1 = svc.IsFinishDirectPushLevel(user.Id, levelTask.LevelId, levelTask.FinishCount) | |||
} | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
} | |||
task := md.LevelTaskNode{ | |||
LevelId: levelTask.LevelId, | |||
IsMustTask: levelTask.IsMustTask, | |||
TaskType: levelTask.TaskType, | |||
WithinDays: levelTask.WithinDays, | |||
FinishCount: levelTask.FinishCount, | |||
ActiveDays: levelTask.ActiveDays, | |||
TaskTypeLevelId: levelTask.TaskType, | |||
FinishNum: count, | |||
} | |||
list = append(list, task) | |||
} | |||
} | |||
resp := md.StarRoadProgressResp{ | |||
LevelName: currentLevelName, | |||
LevelId: user.Level, | |||
List: list, | |||
} | |||
e.OutSuc(c, resp, nil) | |||
} |
@@ -59,3 +59,19 @@ type HeroListResp struct { | |||
SelfRank SelfHeroListNode `json:"self_rank"` // 当前用户排行 | |||
List []HeroListNode `json:"list"` | |||
} | |||
type StarRoadProgressResp struct { | |||
LevelName string `json:"level_name"` // 当前等级名称 | |||
LevelId int `json:"level_id"` // 当前等级 id | |||
List []LevelTaskNode `json:"list"` | |||
} | |||
type LevelTaskNode struct { | |||
LevelId int `json:"level_id"` // 等级 id | |||
IsMustTask int `json:"is_must_task"` // 是否必做 | |||
TaskType int `json:"task_type"` // 任务类型 1:直推会员人数,2:直推会员活跃天数,3:直推会员等级 | |||
WithinDays int `json:"within_days"` // 多少天内完成 | |||
FinishCount int `json:"finish_count"` // 多少天内完成的指标数 | |||
ActiveDays int `json:"active_days"` // 活跃多少天 | |||
TaskTypeLevelId int `json:"task_type_level_id"` // 会员等级id(task_type=3时生效) | |||
FinishNum int64 `json:"finish_num"` // 当前已完成数量 | |||
} |
@@ -109,6 +109,7 @@ func route(r *gin.RouterGroup) { | |||
rHomePage.GET("/isCanSignIn", hdl.IsCanSignIn) // 主页-是否可以签到 | |||
rHomePage.GET("/isCanGetRedPackage", hdl.IsCanGetRedPackage) // 主页-是否可以获得红包 | |||
rHomePage.GET("/heroList", hdl.HeroList) // 主页-英雄榜 | |||
rHomePage.GET("/starRoad", hdl.StarRoadProgress) // 主页-星球之路升级条件 | |||
} | |||
rAddFriend := r.Group("/addFriend") | |||
@@ -2,9 +2,12 @@ package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/utils" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||
"fmt" | |||
"github.com/shopspring/decimal" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
@@ -46,3 +49,84 @@ func CalcTodayEggEnergyPriceRises(engine *xorm.Engine, now time.Time) (err error | |||
} | |||
return nil, rises, isRises, nowPrice, initialPrice | |||
} | |||
// IsFinishDirectPush 直推x个用户 | |||
func IsFinishDirectPush(uid int64, num int) (bool, int64, error) { | |||
relateDb := implement.NewUserRelateDb(db.Db) | |||
count, err := relateDb.UserRelatesCountByParentUid(uid, 1) | |||
if err != nil { | |||
return false, count, err | |||
} | |||
if count >= int64(num) { | |||
return true, count, nil | |||
} | |||
return false, count, nil | |||
} | |||
// IsFinishDirectPushOfActiveDays a天内, 需要直推 b 个人, b个人需要在 a 天内每个人都活跃 c 天 | |||
func IsFinishDirectPushOfActiveDays(uid int64, num int, activeDays int, now time.Time, withInDays int) (bool, int64, error) { | |||
startAt := now.AddDate(0, 0, -withInDays).Format("2006-01-02 15:04:05") | |||
endAt := now.Format("2006-01-02 15:04:05") | |||
startAtDate := now.AddDate(0, 0, withInDays).Format("2006-01-02") | |||
endAtDate := now.Format("2006-01-02") | |||
// 1. 获取邀请用户 | |||
userDb := implement.NewUserDb(db.Db) | |||
users, err := userDb.UserFindInviteByDate(uid, startAt, endAt) | |||
if err != nil { | |||
return false, 0, err | |||
} | |||
if users == nil { | |||
return false, 0, nil | |||
} | |||
// 2. 计算活跃用户数 | |||
userIds := make([]string, 0, len(*users)) | |||
for _, user := range *users { | |||
userIds = append(userIds, utils.Int64ToStr(user.Id)) | |||
} | |||
// 2.1 计算活跃天数 | |||
sql := "select uid, COUNT(*) AS total " + | |||
"from egg_energy_user_activity " + | |||
"where uid in (%s) " + | |||
"and date between " + "'" + startAtDate + "'" + " and " + "'" + endAtDate + "' " + | |||
"group by uid" | |||
sql = fmt.Sprintf(sql, strings.Join(userIds, ",")) | |||
res, err := db.QueryNativeString(db.Db, sql) | |||
if err != nil { | |||
return false, 0, err | |||
} | |||
// 2.2 用户是否活跃计数 | |||
var count int64 | |||
for _, node := range res { | |||
if utils.StrToInt(node["total"]) >= activeDays { | |||
count++ | |||
} | |||
} | |||
if count >= int64(num) { | |||
return true, count, nil | |||
} | |||
return false, count, nil | |||
} | |||
// IsFinishDirectPushLevel 直推多少个等级x以上用户 | |||
func IsFinishDirectPushLevel(uid int64, levelId int, num int) (bool, int64, error) { | |||
levelDb := implement.NewUserLevelDb(db.Db) | |||
level, err := levelDb.UserLevelByID(levelId) | |||
if err != nil { | |||
return false, 0, err | |||
} | |||
if level == nil { | |||
return false, 0, nil | |||
} | |||
count, err := db.Db.Table("user"). | |||
Join("LEFT OUTER", []string{"user_level", "level"}, "user.level = level.id"). | |||
Where("user.parent_uid = ?", uid). | |||
Where("level.level_weight >= ?", level.LevelWeight).Count(&model.User{}) | |||
if err != nil { | |||
return false, 0, err | |||
} | |||
if count >= int64(num) { | |||
return true, count, nil | |||
} | |||
return false, count, nil | |||
} |
@@ -2198,6 +2198,44 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"/api/v1/homePage/starRoad": { | |||
"get": { | |||
"description": "星球之路升级条件(获取)", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"主页" | |||
], | |||
"summary": "蛋蛋星球-主页-星球之路升级条件(获取)", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "具体数据", | |||
"schema": { | |||
"$ref": "#/definitions/md.StarRoadProgressResp" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/im/redPackageDetail": { | |||
"get": { | |||
"description": "红包详情(获取)", | |||
@@ -5791,6 +5829,43 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"md.LevelTaskNode": { | |||
"type": "object", | |||
"properties": { | |||
"active_days": { | |||
"description": "活跃多少天", | |||
"type": "integer" | |||
}, | |||
"finish_count": { | |||
"description": "多少天内完成的指标数", | |||
"type": "integer" | |||
}, | |||
"finish_num": { | |||
"description": "当前已完成数量", | |||
"type": "integer" | |||
}, | |||
"is_must_task": { | |||
"description": "是否必做", | |||
"type": "integer" | |||
}, | |||
"level_id": { | |||
"description": "等级 id", | |||
"type": "integer" | |||
}, | |||
"task_type": { | |||
"description": "任务类型 1:直推会员人数,2:直推会员活跃天数,3:直推会员等级", | |||
"type": "integer" | |||
}, | |||
"task_type_level_id": { | |||
"description": "会员等级id(task_type=3时生效)", | |||
"type": "integer" | |||
}, | |||
"within_days": { | |||
"description": "多少天内完成", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"md.LoginReq": { | |||
"type": "object", | |||
"required": [ | |||
@@ -6472,6 +6547,25 @@ const docTemplate = `{ | |||
} | |||
} | |||
}, | |||
"md.StarRoadProgressResp": { | |||
"type": "object", | |||
"properties": { | |||
"level_id": { | |||
"description": "当前等级 id", | |||
"type": "integer" | |||
}, | |||
"level_name": { | |||
"description": "当前等级名称", | |||
"type": "string" | |||
}, | |||
"list": { | |||
"type": "array", | |||
"items": { | |||
"$ref": "#/definitions/md.LevelTaskNode" | |||
} | |||
} | |||
} | |||
}, | |||
"md.TotalRateResp": { | |||
"type": "object", | |||
"properties": { | |||
@@ -2192,6 +2192,44 @@ | |||
} | |||
} | |||
}, | |||
"/api/v1/homePage/starRoad": { | |||
"get": { | |||
"description": "星球之路升级条件(获取)", | |||
"consumes": [ | |||
"application/json" | |||
], | |||
"produces": [ | |||
"application/json" | |||
], | |||
"tags": [ | |||
"主页" | |||
], | |||
"summary": "蛋蛋星球-主页-星球之路升级条件(获取)", | |||
"parameters": [ | |||
{ | |||
"type": "string", | |||
"description": "验证参数Bearer和token空格拼接", | |||
"name": "Authorization", | |||
"in": "header", | |||
"required": true | |||
} | |||
], | |||
"responses": { | |||
"200": { | |||
"description": "具体数据", | |||
"schema": { | |||
"$ref": "#/definitions/md.StarRoadProgressResp" | |||
} | |||
}, | |||
"400": { | |||
"description": "具体错误", | |||
"schema": { | |||
"$ref": "#/definitions/md.Response" | |||
} | |||
} | |||
} | |||
} | |||
}, | |||
"/api/v1/im/redPackageDetail": { | |||
"get": { | |||
"description": "红包详情(获取)", | |||
@@ -5785,6 +5823,43 @@ | |||
} | |||
} | |||
}, | |||
"md.LevelTaskNode": { | |||
"type": "object", | |||
"properties": { | |||
"active_days": { | |||
"description": "活跃多少天", | |||
"type": "integer" | |||
}, | |||
"finish_count": { | |||
"description": "多少天内完成的指标数", | |||
"type": "integer" | |||
}, | |||
"finish_num": { | |||
"description": "当前已完成数量", | |||
"type": "integer" | |||
}, | |||
"is_must_task": { | |||
"description": "是否必做", | |||
"type": "integer" | |||
}, | |||
"level_id": { | |||
"description": "等级 id", | |||
"type": "integer" | |||
}, | |||
"task_type": { | |||
"description": "任务类型 1:直推会员人数,2:直推会员活跃天数,3:直推会员等级", | |||
"type": "integer" | |||
}, | |||
"task_type_level_id": { | |||
"description": "会员等级id(task_type=3时生效)", | |||
"type": "integer" | |||
}, | |||
"within_days": { | |||
"description": "多少天内完成", | |||
"type": "integer" | |||
} | |||
} | |||
}, | |||
"md.LoginReq": { | |||
"type": "object", | |||
"required": [ | |||
@@ -6466,6 +6541,25 @@ | |||
} | |||
} | |||
}, | |||
"md.StarRoadProgressResp": { | |||
"type": "object", | |||
"properties": { | |||
"level_id": { | |||
"description": "当前等级 id", | |||
"type": "integer" | |||
}, | |||
"level_name": { | |||
"description": "当前等级名称", | |||
"type": "string" | |||
}, | |||
"list": { | |||
"type": "array", | |||
"items": { | |||
"$ref": "#/definitions/md.LevelTaskNode" | |||
} | |||
} | |||
} | |||
}, | |||
"md.TotalRateResp": { | |||
"type": "object", | |||
"properties": { | |||
@@ -986,6 +986,33 @@ definitions: | |||
description: 能否签到 | |||
type: boolean | |||
type: object | |||
md.LevelTaskNode: | |||
properties: | |||
active_days: | |||
description: 活跃多少天 | |||
type: integer | |||
finish_count: | |||
description: 多少天内完成的指标数 | |||
type: integer | |||
finish_num: | |||
description: 当前已完成数量 | |||
type: integer | |||
is_must_task: | |||
description: 是否必做 | |||
type: integer | |||
level_id: | |||
description: 等级 id | |||
type: integer | |||
task_type: | |||
description: 任务类型 1:直推会员人数,2:直推会员活跃天数,3:直推会员等级 | |||
type: integer | |||
task_type_level_id: | |||
description: 会员等级id(task_type=3时生效) | |||
type: integer | |||
within_days: | |||
description: 多少天内完成 | |||
type: integer | |||
type: object | |||
md.LoginReq: | |||
properties: | |||
code: | |||
@@ -1465,6 +1492,19 @@ definitions: | |||
description: 当前人数 | |||
type: integer | |||
type: object | |||
md.StarRoadProgressResp: | |||
properties: | |||
level_id: | |||
description: 当前等级 id | |||
type: integer | |||
level_name: | |||
description: 当前等级名称 | |||
type: string | |||
list: | |||
items: | |||
$ref: '#/definitions/md.LevelTaskNode' | |||
type: array | |||
type: object | |||
md.TotalRateResp: | |||
properties: | |||
consumed_personal_egg_point: | |||
@@ -3282,6 +3322,31 @@ paths: | |||
summary: 蛋蛋星球-主页-实时数据(获取) | |||
tags: | |||
- 主页 | |||
/api/v1/homePage/starRoad: | |||
get: | |||
consumes: | |||
- application/json | |||
description: 星球之路升级条件(获取) | |||
parameters: | |||
- description: 验证参数Bearer和token空格拼接 | |||
in: header | |||
name: Authorization | |||
required: true | |||
type: string | |||
produces: | |||
- application/json | |||
responses: | |||
"200": | |||
description: 具体数据 | |||
schema: | |||
$ref: '#/definitions/md.StarRoadProgressResp' | |||
"400": | |||
description: 具体错误 | |||
schema: | |||
$ref: '#/definitions/md.Response' | |||
summary: 蛋蛋星球-主页-星球之路升级条件(获取) | |||
tags: | |||
- 主页 | |||
/api/v1/im/redPackageDetail: | |||
get: | |||
consumes: | |||
@@ -33,7 +33,7 @@ require ( | |||
) | |||
require ( | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241224090637-89a57f7fbb1e | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241225092233-b22661930965 | |||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241223102933-953e3394de41 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | |||