@@ -0,0 +1,159 @@ | |||||
package hdl | |||||
import ( | |||||
"applet/app/db" | |||||
"applet/app/e" | |||||
"applet/app/md" | |||||
"applet/app/utils" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||||
"context" | |||||
"encoding/json" | |||||
"github.com/gin-gonic/gin" | |||||
"github.com/olivere/elastic/v7" | |||||
"github.com/shopspring/decimal" | |||||
"time" | |||||
) | |||||
// MemberCenterGetBasic | |||||
// @Summary 蛋蛋星球-会员中心-基础数据(获取) | |||||
// @Tags 会员中心 | |||||
// @Description 基础数据(获取) | |||||
// @Accept json | |||||
// @Produce json | |||||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||||
// @Success 200 {object} md.MemberCenterGetBasicResp "具体数据" | |||||
// @Failure 400 {object} md.Response "具体错误" | |||||
// @Router /api/v1/memberCenter/getBasic [GET] | |||||
func MemberCenterGetBasic(c *gin.Context) { | |||||
val, exists := c.Get("user") | |||||
if !exists { | |||||
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) | |||||
return | |||||
} | |||||
user, ok := val.(*model.User) | |||||
if !ok { | |||||
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) | |||||
return | |||||
} | |||||
// 1. 获取会员等级名称 | |||||
userLevelDb := implement.NewUserLevelDb(db.Db) | |||||
level, err := userLevelDb.UserLevelByID(user.Level) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
// 2. 获取基础设置 | |||||
settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) | |||||
setting, err := settingDb.EggEnergyBasicSettingGetOne() | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
// 3. 查询余额 | |||||
virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) | |||||
// 3.1 活跃积分(蛋蛋积分 = 团队 + 个人) | |||||
eggPersonalPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggPointsCoinId) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
eggTeamPoint, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggPointsCoinId) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
eggPoint := utils.StrToFloat64(eggPersonalPoint.Amount) + utils.StrToFloat64(eggTeamPoint.Amount) | |||||
// 3.2 蛋蛋能量 (个人 + 团队) | |||||
eggPersonalEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.PersonEggEnergyCoinId) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
eggTeamEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.TeamEggEnergyCoinId) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
eggEnergy := utils.StrToFloat64(eggPersonalEnergy.Amount) + utils.StrToFloat64(eggTeamEnergy.Amount) | |||||
// 3.3 钱包余额 | |||||
walletDb := implement.NewUserWalletDb(db.Db) | |||||
wallet, err := walletDb.GetUserVirtualWallet(user.Id) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
// 3.4 贡献值 | |||||
contributionValue, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, setting.ContributionCoinId) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
coreDataDb := implement.NewEggEnergyCoreDataDb(db.Db) | |||||
coreData, err := coreDataDb.EggEnergyCoreDataGet() | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
// 4. 预估蛋蛋能量价值 | |||||
nowPrice, err := decimal.NewFromString(coreData.NowPrice) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_UNMARSHAL, nil) | |||||
return | |||||
} | |||||
eggEnergyValue := nowPrice.Mul(decimal.NewFromFloat(eggEnergy)) | |||||
// 5. 查询蛋蛋分 | |||||
now := time.Now().Add(-7 * time.Hour * 24) | |||||
esIndexName := es2.GetLatestEffectiveIndexFromAlias(now) | |||||
// 构建查询条件 | |||||
boolQuery := elastic.NewBoolQuery() | |||||
boolQuery.Filter(elastic.NewTermQuery("uid", user.Id)) | |||||
searchResult, err := es.EsClient.Search(). | |||||
Index(esIndexName). | |||||
Query(boolQuery). | |||||
Pretty(true). | |||||
Do(context.Background()) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||||
return | |||||
} | |||||
var results []md.UserEggFlowReqRespList | |||||
// 检查是否有结果 | |||||
if searchResult.Hits.TotalHits.Value != 0 { | |||||
// 解析结果 | |||||
for _, hit := range searchResult.Hits.Hits { | |||||
var doc md.UserEggFlowReqRespList | |||||
err = json.Unmarshal(hit.Source, &doc) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
results = append(results, doc) | |||||
} | |||||
} | |||||
score := results[0].ScoreValue | |||||
resp := md.MemberCenterGetBasicResp{ | |||||
Nickname: user.Nickname, | |||||
LevelName: level.LevelName, | |||||
ActiveNum: utils.Float64ToStr(eggPoint), | |||||
EggScore: utils.Float64ToStr(score), | |||||
EggEnergy: utils.Float64ToStr(eggEnergy), | |||||
EggEnergyValue: eggEnergyValue.String(), | |||||
ContributionValue: contributionValue.Amount, | |||||
Date: "29", | |||||
Ratio: "1:1000", | |||||
Amount: wallet.Amount, | |||||
} | |||||
e.OutSuc(c, resp, nil) | |||||
return | |||||
} |
@@ -0,0 +1,34 @@ | |||||
package md | |||||
type MemberCenterGetBasicResp struct { | |||||
Nickname string `json:"nickname"` // 会员名称 | |||||
LevelName string `json:"level_name"` // 会员等级名称 | |||||
ActiveNum string `json:"active_num"` // 活跃值 | |||||
EggScore string `json:"egg_score"` // 蛋蛋分 | |||||
EggEnergy string `json:"egg_energy"` // 能量值 | |||||
EggEnergyValue string `json:"egg_energy_value"` // 能量预估价值 | |||||
ContributionValue string `json:"contribution_value"` // 贡献值 | |||||
Date string `json:"date"` // 兑换时间(每月x日) | |||||
Ratio string `json:"ratio"` // 兑换比例(x:y) | |||||
Amount string `json:"amount"` // 账户余额 | |||||
} | |||||
type UserEggFlowReqRespList struct { | |||||
IndexId string `json:"index_id"` //文档id | |||||
ScoreValue float64 `json:"score_value"` //蛋蛋分-起始值 | |||||
ScoreValueKind int `json:"score_value_kind"` //评分类型(0:未知 1:人工 2:系统) | |||||
Ecpm float64 `json:"ecpm"` //ecpm | |||||
InviteUserNums int `json:"invite_user_nums"` //拉新人数 | |||||
TeamActivityNums int `json:"team_activity_nums"` //团队活跃次数 | |||||
SignInNums int `json:"sign_in_nums"` //签到次数 | |||||
ImActivityNums int `json:"im_activity_nums"` //im活跃次数 | |||||
SendRedPackageNums int `json:"send_red_package_nums"` //发红包次数 | |||||
EggEnergyExchangeAccountBalance int `json:"egg_energy_exchange_account_balance"` //蛋蛋能量兑换余额数量 | |||||
AccountBalanceExchangeEggEnergyNums int `json:"account_balance_exchange_egg_energy_nums"` //余额兑换蛋蛋能量数量 | |||||
SendCircleOfFriendNums int `json:"send_circle_of_friend_nums"` //发朋友圈次数 | |||||
ForumCommentsNums int `json:"forum_comments_nums"` //论坛评论次数 | |||||
CollegeLearningNums int `json:"college_learning_nums"` //学院学习次数 | |||||
ViolateNums int `json:"violate_nums"` //违规次数 | |||||
BrowseInterfaceNums int `json:"browse_interface_nums"` //浏览界面次数 | |||||
PersonAddActivityValue int `json:"person_add_activity_value"` //个人活跃积分 | |||||
} |
@@ -79,6 +79,10 @@ func route(r *gin.RouterGroup) { | |||||
rAddFriend.GET("/myFansUserList", hdl.MyFansUserList) // 添加好友-我的粉丝-好友列表 | rAddFriend.GET("/myFansUserList", hdl.MyFansUserList) // 添加好友-我的粉丝-好友列表 | ||||
rAddFriend.GET("/nineDimensionalSpace", hdl.NineDimensionalSpace) // 添加好友-我的粉丝-九维空间 | rAddFriend.GET("/nineDimensionalSpace", hdl.NineDimensionalSpace) // 添加好友-我的粉丝-九维空间 | ||||
} | } | ||||
rMemberCenter := r.Group("/memberCenter") | |||||
{ | |||||
rMemberCenter.GET("/getBasic", hdl.MemberCenterGetBasic) // 会员中心-基础数据 | |||||
} | |||||
} | } | ||||
@@ -1,5 +1,4 @@ | |||||
// Code generated by swaggo/swag. DO NOT EDIT. | |||||
// Package docs Code generated by swaggo/swag. DO NOT EDIT | |||||
package docs | package docs | ||||
import "github.com/swaggo/swag" | import "github.com/swaggo/swag" | ||||
@@ -617,6 +616,44 @@ const docTemplate = `{ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"/api/v1/memberCenter/getBasic": { | |||||
"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.MemberCenterGetBasicResp" | |||||
} | |||||
}, | |||||
"400": { | |||||
"description": "具体错误", | |||||
"schema": { | |||||
"$ref": "#/definitions/md.Response" | |||||
} | |||||
} | |||||
} | |||||
} | |||||
}, | |||||
"/api/v1/register": { | "/api/v1/register": { | ||||
"post": { | "post": { | ||||
"description": "注册", | "description": "注册", | ||||
@@ -716,9 +753,7 @@ const docTemplate = `{ | |||||
"name": "req", | "name": "req", | ||||
"in": "body", | "in": "body", | ||||
"required": true, | "required": true, | ||||
"schema": { | |||||
"type": "object" | |||||
} | |||||
"schema": {} | |||||
} | } | ||||
], | ], | ||||
"responses": { | "responses": { | ||||
@@ -1135,6 +1170,51 @@ const docTemplate = `{ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"md.MemberCenterGetBasicResp": { | |||||
"type": "object", | |||||
"properties": { | |||||
"active_num": { | |||||
"description": "活跃值", | |||||
"type": "string" | |||||
}, | |||||
"amount": { | |||||
"description": "账户余额", | |||||
"type": "string" | |||||
}, | |||||
"contribution_value": { | |||||
"description": "贡献值", | |||||
"type": "string" | |||||
}, | |||||
"date": { | |||||
"description": "兑换时间(每月x日)", | |||||
"type": "string" | |||||
}, | |||||
"egg_energy": { | |||||
"description": "能量值", | |||||
"type": "string" | |||||
}, | |||||
"egg_energy_value": { | |||||
"description": "能量预估价值", | |||||
"type": "string" | |||||
}, | |||||
"egg_score": { | |||||
"description": "蛋蛋分", | |||||
"type": "string" | |||||
}, | |||||
"level_name": { | |||||
"description": "会员等级名称", | |||||
"type": "string" | |||||
}, | |||||
"nickname": { | |||||
"description": "会员名称", | |||||
"type": "string" | |||||
}, | |||||
"ratio": { | |||||
"description": "兑换比例(x:y)", | |||||
"type": "string" | |||||
} | |||||
} | |||||
}, | |||||
"md.MyFansResp": { | "md.MyFansResp": { | ||||
"type": "object", | "type": "object", | ||||
"properties": { | "properties": { | ||||
@@ -1416,6 +1496,8 @@ var SwaggerInfo = &swag.Spec{ | |||||
Description: "APP客户端-Api接口", | Description: "APP客户端-Api接口", | ||||
InfoInstanceName: "swagger", | InfoInstanceName: "swagger", | ||||
SwaggerTemplate: docTemplate, | SwaggerTemplate: docTemplate, | ||||
LeftDelim: "{{", | |||||
RightDelim: "}}", | |||||
} | } | ||||
func init() { | func init() { | ||||
@@ -610,6 +610,44 @@ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"/api/v1/memberCenter/getBasic": { | |||||
"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.MemberCenterGetBasicResp" | |||||
} | |||||
}, | |||||
"400": { | |||||
"description": "具体错误", | |||||
"schema": { | |||||
"$ref": "#/definitions/md.Response" | |||||
} | |||||
} | |||||
} | |||||
} | |||||
}, | |||||
"/api/v1/register": { | "/api/v1/register": { | ||||
"post": { | "post": { | ||||
"description": "注册", | "description": "注册", | ||||
@@ -709,9 +747,7 @@ | |||||
"name": "req", | "name": "req", | ||||
"in": "body", | "in": "body", | ||||
"required": true, | "required": true, | ||||
"schema": { | |||||
"type": "object" | |||||
} | |||||
"schema": {} | |||||
} | } | ||||
], | ], | ||||
"responses": { | "responses": { | ||||
@@ -1128,6 +1164,51 @@ | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
"md.MemberCenterGetBasicResp": { | |||||
"type": "object", | |||||
"properties": { | |||||
"active_num": { | |||||
"description": "活跃值", | |||||
"type": "string" | |||||
}, | |||||
"amount": { | |||||
"description": "账户余额", | |||||
"type": "string" | |||||
}, | |||||
"contribution_value": { | |||||
"description": "贡献值", | |||||
"type": "string" | |||||
}, | |||||
"date": { | |||||
"description": "兑换时间(每月x日)", | |||||
"type": "string" | |||||
}, | |||||
"egg_energy": { | |||||
"description": "能量值", | |||||
"type": "string" | |||||
}, | |||||
"egg_energy_value": { | |||||
"description": "能量预估价值", | |||||
"type": "string" | |||||
}, | |||||
"egg_score": { | |||||
"description": "蛋蛋分", | |||||
"type": "string" | |||||
}, | |||||
"level_name": { | |||||
"description": "会员等级名称", | |||||
"type": "string" | |||||
}, | |||||
"nickname": { | |||||
"description": "会员名称", | |||||
"type": "string" | |||||
}, | |||||
"ratio": { | |||||
"description": "兑换比例(x:y)", | |||||
"type": "string" | |||||
} | |||||
} | |||||
}, | |||||
"md.MyFansResp": { | "md.MyFansResp": { | ||||
"type": "object", | "type": "object", | ||||
"properties": { | "properties": { | ||||
@@ -247,6 +247,39 @@ definitions: | |||||
token: | token: | ||||
type: string | type: string | ||||
type: object | type: object | ||||
md.MemberCenterGetBasicResp: | |||||
properties: | |||||
active_num: | |||||
description: 活跃值 | |||||
type: string | |||||
amount: | |||||
description: 账户余额 | |||||
type: string | |||||
contribution_value: | |||||
description: 贡献值 | |||||
type: string | |||||
date: | |||||
description: 兑换时间(每月x日) | |||||
type: string | |||||
egg_energy: | |||||
description: 能量值 | |||||
type: string | |||||
egg_energy_value: | |||||
description: 能量预估价值 | |||||
type: string | |||||
egg_score: | |||||
description: 蛋蛋分 | |||||
type: string | |||||
level_name: | |||||
description: 会员等级名称 | |||||
type: string | |||||
nickname: | |||||
description: 会员名称 | |||||
type: string | |||||
ratio: | |||||
description: 兑换比例(x:y) | |||||
type: string | |||||
type: object | |||||
md.MyFansResp: | md.MyFansResp: | ||||
properties: | properties: | ||||
now_team_assistance_num: | now_team_assistance_num: | ||||
@@ -832,6 +865,31 @@ paths: | |||||
summary: 登陆 | summary: 登陆 | ||||
tags: | tags: | ||||
- 登录 | - 登录 | ||||
/api/v1/memberCenter/getBasic: | |||||
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.MemberCenterGetBasicResp' | |||||
"400": | |||||
description: 具体错误 | |||||
schema: | |||||
$ref: '#/definitions/md.Response' | |||||
summary: 蛋蛋星球-会员中心-基础数据(获取) | |||||
tags: | |||||
- 会员中心 | |||||
/api/v1/register: | /api/v1/register: | ||||
post: | post: | ||||
consumes: | consumes: | ||||
@@ -894,8 +952,7 @@ paths: | |||||
in: body | in: body | ||||
name: req | name: req | ||||
required: true | required: true | ||||
schema: | |||||
type: object | |||||
schema: {} | |||||
produces: | produces: | ||||
- application/json | - application/json | ||||
responses: | responses: | ||||
@@ -33,7 +33,7 @@ require ( | |||||
require ( | require ( | ||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241122012509-ceb61ba8203c | code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241122012509-ceb61ba8203c | ||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241122035952-de4df98d64dc | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241122063050-e7a72a7c807c | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | 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 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | ||||