Commit 2f92f645 authored by chenweijian's avatar chenweijian

分享充值链接

parent 65297deb
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
}
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"hilo-group/_const/enum/mgr_e" "hilo-group/_const/enum/mgr_e"
_ "hilo-group/docs" _ "hilo-group/docs"
"hilo-group/domain/model/mgr_m" "hilo-group/domain/model/mgr_m"
"hilo-group/route/charge_r"
"hilo-group/route/group_power_r" "hilo-group/route/group_power_r"
"hilo-group/route/group_r" "hilo-group/route/group_r"
) )
...@@ -126,6 +127,11 @@ func InitRouter() *gin.Engine { ...@@ -126,6 +127,11 @@ func InitRouter() *gin.Engine {
groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek)) groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek))
groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek)) groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek))
} }
charge := v1.Group("/charge")
{
charge.GET("/share", wrapper(charge_r.CanShareChargeLink))
}
return r return r
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment