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
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 充值
......@@ -26,92 +13,92 @@ import (
// @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)
//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, 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