diff --git a/app/hdl/hdl_home_page.go b/app/hdl/hdl_home_page.go index aee5724..55f008a 100644 --- a/app/hdl/hdl_home_page.go +++ b/app/hdl/hdl_home_page.go @@ -357,15 +357,39 @@ func IsCanSignIn(c *gin.Context) { // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/homePage/isCanGetRedPackage [get] func IsCanGetRedPackage(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. 红包活动是否开启 redPackageDb := implement.NewNewUserRedPackageDb(db.Db) redPackage, err := redPackageDb.NewUserRedPackageGetOne() if err != nil { e.OutErr(c, e.ERR, err.Error()) return } + + // 2. 用户已有红包活动记录 + userRecordsDb := implement.NewNewUserRedPackageWithUserRecordsDb(db.Db) + records, err := userRecordsDb.NewUserRedPackageWithUserRecordsGetLastPendingByParams(map[string]interface{}{ + "key": "uid", + "value": user.Id, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, nil) + return + } + isCan := false if redPackage != nil { - if redPackage.IsOpen == 1 { + if redPackage.IsOpen == 1 && records != nil { isCan = true } } diff --git a/app/hdl/hdl_points_center.go b/app/hdl/hdl_points_center.go index e3f6b79..348ae66 100644 --- a/app/hdl/hdl_points_center.go +++ b/app/hdl/hdl_points_center.go @@ -17,9 +17,14 @@ import ( "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" svc2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" + 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" "errors" "fmt" "github.com/gin-gonic/gin" + "github.com/olivere/elastic/v7" "github.com/shopspring/decimal" "time" ) @@ -665,6 +670,50 @@ func GetContributionValueFlow(c *gin.Context) { e.OutSuc(c, resp, nil) } +func GetPointMap(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 + } + now := time.Now() + // 1. 获取当期有效蛋蛋分 + nowIndex := es2.GetLatestEffectiveIndexFromAlias(now) + boolQuery := elastic.NewBoolQuery() + boolQuery.Filter(elastic.NewTermQuery("uid", user.Id)) + searchResult, err := es.EsClient.Search(). + Index(nowIndex). + Query(boolQuery). + Pretty(true). + Do(context.Background()) + if searchResult == nil { + e.OutErr(c, e.ERR_DB_ORM, errors.New("failed to get current egg score")) + 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_UNMARSHAL, err.Error()) + return + } + results = append(results, doc) + } + } + // nowScore := utils.Float64ToStr(results[0].ScoreValue) + // todo 计算分数权重 + +} + // GetEggPointRecord // @Summary 蛋蛋星球-积分中心-蛋蛋分明细(获取) // @Tags 积分中心 diff --git a/app/hdl/hdl_red_packet.go b/app/hdl/hdl_red_packet.go new file mode 100644 index 0000000..2f82664 --- /dev/null +++ b/app/hdl/hdl_red_packet.go @@ -0,0 +1,49 @@ +package hdl + +import ( + "applet/app/db" + "applet/app/e" + "applet/app/md" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "github.com/gin-gonic/gin" +) + +func RedPacketInfo(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 + } + + userRecordsDb := implement.NewNewUserRedPackageWithUserRecordsDb(db.Db) + records, err := userRecordsDb.NewUserRedPackageWithUserRecordsGetLastPendingByParams(map[string]interface{}{ + "key": "uid", + "value": user.Id, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, nil) + return + } + if records == nil { + e.OutErr(c, e.ERR_NO_DATA, "该用户没有有效新人红包活动") + return + } + + resp := md.RedPacketInfoResp{ + Uid: records.Uid, + TotalAmount: records.TotalAmount, + Days: records.Days, + BalanceAmount: records.BalanceAmount, + BalanceDays: records.BalanceDays, + ReceiveDays: records.ReceiveDays, + State: records.State, + CreateAt: records.CreateAt, + } + e.OutSuc(c, resp, nil) +} diff --git a/app/md/md_red_packet.go b/app/md/md_red_packet.go new file mode 100644 index 0000000..a58949b --- /dev/null +++ b/app/md/md_red_packet.go @@ -0,0 +1,12 @@ +package md + +type RedPacketInfoResp struct { + Uid int64 `json:"uid"` // 用户 ID + TotalAmount string `json:"total_amount"` // 金额 + Days int `json:"days"` // 天数 + BalanceAmount string `json:"balance_amount"` // 剩余金额 + BalanceDays int `json:"balance_days"` // 剩余天数 + ReceiveDays int `json:"receive_days"` // 领取天数 + State int `json:"state"` // 状态(0:待领取 1:领取中 2:已领取 3:已冻结) + CreateAt string `json:"create_at"` // 创建时间 +} diff --git a/app/router/router.go b/app/router/router.go index 7b4b61c..4f4139f 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -100,6 +100,7 @@ func route(r *gin.RouterGroup) { rPointsCenter.POST("/exchangeEnergy", hdl.ExchangeEnergy) // 积分中心-能量兑换 rPointsCenter.GET("/contributionValue", hdl.GetContributionValue) // 积分中心-贡献值 rPointsCenter.GET("/contributionValueFlow", hdl.GetContributionValueFlow) // 积分中心-贡献值明细 + rPointsCenter.GET("/pointMap", hdl.GetPointMap) // 积分中心-蛋蛋分六芒星 rPointsCenter.GET("/record", hdl.GetEggPointRecord) // 积分中心-蛋蛋分历史记录 rPointsCenter.GET("/energyFlow", hdl.GetEggEnergyFlow) // 积分中心-积分收支明细 } @@ -107,7 +108,10 @@ func route(r *gin.RouterGroup) { { rWallet.GET("/amountFlow", hdl.GetAmountFlow) // 余额流水 } - + rRedPacket := r.Group("/redPacket") // 红包 + { + rRedPacket.GET("/index", hdl.RedPacketInfo) + } } func rComm(r *gin.RouterGroup) { diff --git a/go.mod b/go.mod index 6cdc52f..d32d04f 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241125012958-44d150a46684 + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241125034400-ef18ee319fd2 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241123093218-87b65e51eea3 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