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 }