diff --git a/route/charge_r/charge.go b/route/charge_r/charge.go new file mode 100644 index 0000000000000000000000000000000000000000..60fb8d0f4165f7800d03c6208d24dcdcf505f0e5 --- /dev/null +++ b/route/charge_r/charge.go @@ -0,0 +1,117 @@ +package charge_r + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/mycontext" + "git.hilo.cn/hilo-common/resource/mysql" + "git.hilo.cn/hilo-common/resource/redisCli" + "git.hilo.cn/hilo-common/utils" + "github.com/gin-gonic/gin" + "hilo-group/_const/enum/groupPower_e" + "hilo-group/_const/redis_key" + "hilo-group/cv/user_cv" + "hilo-group/domain/cache/user_c" + "hilo-group/domain/model/groupPower_m" + "hilo-group/myerr" + "hilo-group/req" + "hilo-group/resp" + "strconv" + "time" +) + +// @Tags 充值 +// @Summary 是否可以分享充值链接 +// @Param extId query string true "分享对象的external id" +// @Success 200 +// @Router /v1/charge/share [get] +func CanShareChargeLink(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + extId := c.Query("extId") + model := domain.CreateModelContext(myContext) + toUser, err := user_c.GetUserByExternalId(model, extId) + if err != nil { + return myContext, err + } + type res struct { + CanShare bool `json:"canShare"` + } + //var beginTime, endTime time.Time + var beginTime time.Time + if t == 1 { + //endTime = now + beginTime = midnight + } else if t == 2 { + //endTime = midnight + beginTime = midnight.AddDate(0, 0, -7) + } else { + return myContext, myerr.NewSysError("type 参数错误") + } + + type R struct { + DiamondNum uint + UserId uint64 + } + rs := []R{} + //用缓存 + rows, err := redisCli.GetRedis().ZRevRangeWithScores(context.Background(), redis_key.GetGroupPowerDiamondLogWeek(beginTime.Format(utils.COMPACT_DATE_FORMAT)), 0, -1).Result() + if err != nil { + return nil, myerr.WrapErr(err) + } + groupPowerIds := make([]uint64, 0, len(rows)) + for i, _ := range rows { + groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64) + if err != nil { + return nil, myerr.WrapErr(err) + } + groupPowerIds = append(groupPowerIds, groupPowerId) + } + //搜集所有的群组(有效) + 群组管理人 + groupPowerUsers := []groupPower_m.GroupPowerUser{} + if err := mysql.Db.Raw("SELECT u.user_id, u.group_power_id FROM group_power_user u, group_power p WHERE u.group_power_id = p.id AND u.role = ? and p.status = ? and p.id in (?)", groupPower_e.GroupPowerUserRoleMgr, groupPower_e.GroupPowerUserHas, groupPowerIds).Scan(&groupPowerUsers).Error; err != nil { + return nil, myerr.WrapErr(err) + } + //转换成map + groupPowerIdUserIdMap := map[uint64]uint64{} + for _, r := range groupPowerUsers { + groupPowerIdUserIdMap[r.GroupPowerId] = r.UserId + } + //只需找到前3个 + for i, _ := range rows { + groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64) + if err != nil { + return nil, myerr.WrapErr(err) + } + if len(rs) >= 3 { + break + } else if userId, flag := groupPowerIdUserIdMap[groupPowerId]; flag { + rs = append(rs, R{ + DiamondNum: uint(rows[i].Score), + UserId: userId, + }) + } + } + + userIds := make([]uint64, 0, 64) + for i, _ := range rs { + userIds = append(userIds, rs[i].UserId) + } + + userMap, err := user_cv.GetUserDetailMap(userIds, userId) + if err != nil { + return myContext, err + } + + results := make([]ReturnGroupPowerBillboardOwnerWeek, 0, len(userIds)) + for i, _ := range rs { + results = append(results, ReturnGroupPowerBillboardOwnerWeek{ + User: *userMap[rs[i].UserId], + Diamond: rs[i].DiamondNum, + }) + } + resp.ResponseOk(c, results) + return myContext, nil +} diff --git a/route/router.go b/route/router.go index 92d830e348e31e4479eeea22b40aebe5ff924d41..4b5e9685b86215b70824008bfb603e388be83cab 100644 --- a/route/router.go +++ b/route/router.go @@ -9,6 +9,7 @@ import ( "hilo-group/_const/enum/mgr_e" _ "hilo-group/docs" "hilo-group/domain/model/mgr_m" + "hilo-group/route/charge_r" "hilo-group/route/group_power_r" "hilo-group/route/group_r" ) @@ -126,6 +127,11 @@ func InitRouter() *gin.Engine { groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek)) groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek)) } + + charge := v1.Group("/charge") + { + charge.GET("/share", wrapper(charge_r.CanShareChargeLink)) + } return r }