Commit def9e5e1 authored by chenweijian's avatar chenweijian

代理限制

parent 7634aa8a
ALTER TABLE hilo.group_power ADD `level` INT UNSIGNED DEFAULT 0 NOT NULL COMMENT '家族等级';
ALTER TABLE hilo.group_power ADD nameplate varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' NOT NULL COMMENT '家族铭牌';
ALTER TABLE hilo.group_power ADD declaration varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' NOT NULL COMMENT '家族宣言';
update hilo.group_power set nameplate = id;
CREATE UNIQUE INDEX nameplate_IDX USING BTREE ON hilo.group_power (nameplate);
package charge_r package charge_r
import ( import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "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" "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" "hilo-group/resp"
"strconv"
"time"
) )
// @Tags 充值 // @Tags 充值
...@@ -26,92 +13,92 @@ import ( ...@@ -26,92 +13,92 @@ import (
// @Router /v1/charge/share [get] // @Router /v1/charge/share [get]
func CanShareChargeLink(c *gin.Context) (*mycontext.MyContext, error) { func CanShareChargeLink(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys) myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c) //userId, err := req.GetUserId(c)
if err != nil { //if err != nil {
return myContext, err // return myContext, err
} //}
extId := c.Query("extId") //extId := c.Query("extId")
model := domain.CreateModelContext(myContext) //model := domain.CreateModelContext(myContext)
toUser, err := user_c.GetUserByExternalId(model, extId) //toUser, err := user_c.GetUserByExternalId(model, extId)
if err != nil { //if err != nil {
return myContext, err // return myContext, err
} //}
type res struct { //type res struct {
CanShare bool `json:"canShare"` // CanShare bool `json:"canShare"`
} //}
//var beginTime, endTime time.Time ////var beginTime, endTime time.Time
var beginTime time.Time //var beginTime time.Time
if t == 1 { //if t == 1 {
//endTime = now // //endTime = now
beginTime = midnight // beginTime = midnight
} else if t == 2 { //} else if t == 2 {
//endTime = midnight // //endTime = midnight
beginTime = midnight.AddDate(0, 0, -7) // beginTime = midnight.AddDate(0, 0, -7)
} else { //} else {
return myContext, myerr.NewSysError("type 参数错误") // return myContext, myerr.NewSysError("type 参数错误")
} //}
//
type R struct { //type R struct {
DiamondNum uint // DiamondNum uint
UserId uint64 // UserId uint64
} //}
rs := []R{} //rs := []R{}
//用缓存 ////用缓存
rows, err := redisCli.GetRedis().ZRevRangeWithScores(context.Background(), redis_key.GetGroupPowerDiamondLogWeek(beginTime.Format(utils.COMPACT_DATE_FORMAT)), 0, -1).Result() //rows, err := redisCli.GetRedis().ZRevRangeWithScores(context.Background(), redis_key.GetGroupPowerDiamondLogWeek(beginTime.Format(utils.COMPACT_DATE_FORMAT)), 0, -1).Result()
if err != nil { //if err != nil {
return nil, myerr.WrapErr(err) // return nil, myerr.WrapErr(err)
} //}
groupPowerIds := make([]uint64, 0, len(rows)) //groupPowerIds := make([]uint64, 0, len(rows))
for i, _ := range rows { //for i, _ := range rows {
groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64) // groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64)
if err != nil { // if err != nil {
return nil, myerr.WrapErr(err) // return nil, myerr.WrapErr(err)
} // }
groupPowerIds = append(groupPowerIds, groupPowerId) // groupPowerIds = append(groupPowerIds, groupPowerId)
} //}
//搜集所有的群组(有效) + 群组管理人 ////搜集所有的群组(有效) + 群组管理人
groupPowerUsers := []groupPower_m.GroupPowerUser{} //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 { //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) // return nil, myerr.WrapErr(err)
} //}
//转换成map ////转换成map
groupPowerIdUserIdMap := map[uint64]uint64{} //groupPowerIdUserIdMap := map[uint64]uint64{}
for _, r := range groupPowerUsers { //for _, r := range groupPowerUsers {
groupPowerIdUserIdMap[r.GroupPowerId] = r.UserId // groupPowerIdUserIdMap[r.GroupPowerId] = r.UserId
} //}
//只需找到前3个 ////只需找到前3个
for i, _ := range rows { //for i, _ := range rows {
groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64) // groupPowerId, err := strconv.ParseUint(rows[i].Member.(string), 10, 64)
if err != nil { // if err != nil {
return nil, myerr.WrapErr(err) // return nil, myerr.WrapErr(err)
} // }
if len(rs) >= 3 { // if len(rs) >= 3 {
break // break
} else if userId, flag := groupPowerIdUserIdMap[groupPowerId]; flag { // } else if userId, flag := groupPowerIdUserIdMap[groupPowerId]; flag {
rs = append(rs, R{ // rs = append(rs, R{
DiamondNum: uint(rows[i].Score), // DiamondNum: uint(rows[i].Score),
UserId: userId, // UserId: userId,
}) // })
} // }
} //}
//
userIds := make([]uint64, 0, 64) //userIds := make([]uint64, 0, 64)
for i, _ := range rs { //for i, _ := range rs {
userIds = append(userIds, rs[i].UserId) // userIds = append(userIds, rs[i].UserId)
} //}
//
userMap, err := user_cv.GetUserDetailMap(userIds, userId) //userMap, err := user_cv.GetUserDetailMap(userIds, userId)
if err != nil { //if err != nil {
return myContext, err // return myContext, err
} //}
//
results := make([]ReturnGroupPowerBillboardOwnerWeek, 0, len(userIds)) //results := make([]ReturnGroupPowerBillboardOwnerWeek, 0, len(userIds))
for i, _ := range rs { //for i, _ := range rs {
results = append(results, ReturnGroupPowerBillboardOwnerWeek{ // results = append(results, ReturnGroupPowerBillboardOwnerWeek{
User: *userMap[rs[i].UserId], // User: *userMap[rs[i].UserId],
Diamond: rs[i].DiamondNum, // Diamond: rs[i].DiamondNum,
}) // })
} //}
resp.ResponseOk(c, results) resp.ResponseOk(c, nil)
return myContext, nil return myContext, nil
} }
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