Commit 48c803e3 authored by chenweijian's avatar chenweijian

派对申请

parent 2c323d3c
package invite_cv
import "git.hilo.cn/hilo-common/resource/mysql"
type CvUserLevel struct {
UserId mysql.ID `json:"userId"` // 用户id
WealthUserGrade uint32 `json:"wealthUserGrade"` // 财富等级
CharmUserGrade uint32 `json:"charmUserGrade"` // 魅力等级
ActiveUserGrade uint32 `json:"activeUserGrade"` // 活跃等级
NobleLevel uint16 `json:"nobleLevel"` // 贵族等级
}
type InviteApplyRes struct {
List []*InviteApply `json:"list"`
NumList []*InviteApplyNumRes `json:"numList"`
MyCode string `json:"myCode"`
}
type InviteApply struct {
NewUserCode string `json:"newUserCode"`
Platform string `json:"platform"`
Recharge string `json:"recharge"`
UserCode string `json:"userCode"`
CreateUnix int64 `json:"createUnix"`
Level string `json:"level"`
Status uint8 `json:"status"` // 状态0.未审核1.已通过2.已拒绝
Avatar string `json:"avatar"`
ExternalId string `json:"externalId"`
Reason int `json:"reason"` // 1.已申请2.待审核3.已通过4.已拒绝"
}
type InviteApplyNumRes struct {
Type int `json:"type"` // 1.已申请2.待审核3.已通过4.已拒绝"
Num int `json:"num"`
}
type AgentPeriod struct {
Week []AgentPeriodWeek `json:"week"`
}
type AgentPeriodWeek struct {
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
}
package invite_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"time"
)
type InviteApply struct {
Id uint64 `json:"id"`
UserId uint64 `json:"user_id"`
NewUserId uint64 `json:"new_user_id"`
Platform string `json:"platform"`
PlatformId string `json:"platform_id"`
RechargeInfo string `json:"recharge_info"`
Status uint8 `json:"status"` // 状态0.未审核1.已通过2.已拒绝
VideoUrl string `json:"video_url"`
Level string `json:"level"`
CreatedTime time.Time `json:"created_time"`
Reason int `json:"reason"` // 1.已申请2.待审核3.已通过4.已拒绝"
SubUserId uint64 `json:"sub_user_id"` // 提交人
}
func CreateInviteApply(model *domain.Model, userId, newUserId, subUserId uint64, platform, platformId, recharge, videoUrl string) error {
err := model.DB().Create(&InviteApply{
UserId: userId, NewUserId: newUserId, Platform: platform, PlatformId: platformId, RechargeInfo: recharge, VideoUrl: videoUrl,
CreatedTime: time.Now(), SubUserId: subUserId}).Error
if err != nil {
model.Log.Errorf("CreateInviteApply err:%v", err)
return err
}
return nil
}
func GetApplyList(model *domain.Model, subUserId uint64, userIds []uint64, pageIndex, pageSize, gType int, beginTime,
endTime time.Time) ([]*InviteApply, int64, error) {
db := model.DB().Model(InviteApply{}).Where("user_id in (?) or sub_user_id = ?", userIds, subUserId).Where("created_time >= ? and created_time <= ?", beginTime, endTime)
switch gType { // 1.已申请2.待审核3.已通过4.已拒绝
case 2:
db = db.Where("`status` = ?", 0)
case 3:
db = db.Where("`status` = ?", 1)
case 4:
db = db.Where("`status` = ?", 2)
}
res := make([]*InviteApply, 0)
var count int64
err := db.Order("id desc").Offset((pageIndex - 1) * pageSize).Find(&res).Limit(-1).Offset(-1).Count(&count).Error
if err != nil {
model.Log.Errorf("GetApplyList err:%v", err)
return nil, 0, err
}
return res, count, nil
}
// 检查被邀请人是否存在
func IsInInviteApply(model *domain.Model, userId mysql.ID) (bool, error) {
var apply InviteApply
if err := model.Db.Model(InviteApply{}).Where("new_user_id = ?", userId).First(&apply).Error; err != nil {
if err != gorm.ErrRecordNotFound {
return false, err
}
return false, nil
}
// err == nil, record exists
return true, nil
}
// 检查被邀请人是否存在
func GetInviteApplyNumByType(model *domain.Model, gType int, beginTime, endTime time.Time, userIds []uint64, subUserId uint64) (int, error) {
var count int64
db := model.Db.Model(InviteApply{}).Where("user_id in (?) or sub_user_id = ?", userIds, subUserId).Where("created_time >= ? and created_time <= ?", beginTime, endTime)
switch gType { // 1.已申请2.待审核3.已通过4.已拒绝
case 2:
db = db.Where("`status` = ?", 0)
case 3:
db = db.Where("`status` = ?", 1)
case 4:
db = db.Where("`status` = ?", 2)
}
if err := db.Count(&count).Error; err != nil {
return 0, err
}
return int(count), nil
}
package promotion_m
import "git.hilo.cn/hilo-common/resource/mysql"
// 推广员
type PromotionAgent struct {
mysql.Entity
ManagerId mysql.ID
AgentId mysql.ID
}
// 邀请关系
type PromotionInvite struct {
mysql.Entity
ManagerId mysql.ID
AgentId mysql.ID
Invitee mysql.ID
Platform string
PlatformId string
Reason string
InviteDate string
}
// 邀请关系日志
type PromotionInviteLog struct {
mysql.Entity
AgentId mysql.ID
Invitee mysql.ID
AddReduce mysql.AddReduce
}
package promotion_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
)
// 获取推广员平台
func GetPromotionPlatforms(model *domain.Model) []string {
return []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla"}
}
// 检查是否推广员
func IsPromotionAgent(model *domain.Model, userId mysql.ID) bool {
var promotionAgent PromotionAgent
if err := model.Db.Model(PromotionAgent{}).Where("agent_id = ?", userId).First(&promotionAgent).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("IsPromotionAgent fail:%v", err)
}
} else if promotionAgent.ID > 0 {
return true
}
return false
}
// 检查被邀请人是否存在
func IsPromotionInvitee(model *domain.Model, userId mysql.ID) (bool, error) {
var promotionInvite PromotionInvite
if err := model.Db.Model(PromotionInvite{}).Where("invitee = ?", userId).First(&promotionInvite).Error; err != nil {
if err != gorm.ErrRecordNotFound {
return false, err
}
return false, nil
}
// err == nil, record exists
return true, nil
}
// 检查是否推广经理
func IsPromotionManager(model *domain.Model, userId mysql.ID) bool {
var promotionAgent PromotionAgent
if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ?", userId).First(&promotionAgent).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("IsPromotionManager fail:%v", err)
}
} else if promotionAgent.ID > 0 {
return true
}
return false
}
// 检查是否我的推广经理
func IsMyPromotionManager(model *domain.Model, userId, myUserId mysql.ID) bool {
var promotionAgent PromotionAgent
if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ? and agent_id = ?", userId, myUserId).First(&promotionAgent).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("IsMyPromotionManager fail:%v", err)
}
} else if promotionAgent.ID > 0 {
return true
}
return false
}
// 获取推广经理拥有的所有推广员,包含自己
func GetPromotionManagerAgentList(model *domain.Model, userId mysql.ID) ([]uint64, error) {
uids := make([]uint64, 0)
if err := model.Db.Model(PromotionAgent{}).Where("manager_id = ?", userId).Select("agent_id").
Pluck("agent_id", &uids).Error; err != nil {
model.Log.Errorf("IsPromotionManager fail:%v", err)
return nil, err
}
return uids, nil
}
// 添加推广邀请关系
func AddPromotionInvite(model *domain.Model, managerId, agentId, invitee mysql.ID, platform, platformId, reason, inviteDate string) error {
if err := model.Db.Create(&PromotionInvite{
ManagerId: managerId,
AgentId: agentId,
Invitee: invitee,
Platform: platform,
PlatformId: platformId,
Reason: reason,
InviteDate: inviteDate,
}).Error; err != nil {
return err
}
return addPromotionInviteLog(model, agentId, invitee, mysql.ADD)
}
// 添加推广邀请关系-日志
func addPromotionInviteLog(model *domain.Model, agentId, invitee mysql.ID, addReduce mysql.AddReduce) error {
return model.Db.Create(&PromotionInviteLog{
AgentId: agentId,
Invitee: invitee,
AddReduce: addReduce,
}).Error
}
......@@ -6,6 +6,7 @@ import (
var (
// 一般性错误
HttpSecret = myerr.NewBusinessCode(1000, "http secret err", myerr.BusinessData{})
TokenInvalid = myerr.NewBusinessCode(1001, "token invalid", myerr.BusinessData{})
ExternalIdNoExist = myerr.NewBusinessCode(1003, "externalId no exist", myerr.BusinessData{})
CodeNoExist = myerr.NewBusinessCode(1005, "code no exist", myerr.BusinessData{})
......@@ -28,4 +29,8 @@ var (
CpAlreadyInvite = myerr.NewBusinessCode(50120, "Already invited", myerr.BusinessData{}) // 已经发送过邀请了
CpHaveCancelNoDeal = myerr.NewBusinessCode(50121, "You have a cancel apply", myerr.BusinessData{}) // 有接触申请需要处理
InviteApplyNoPermission = myerr.NewBusinessCode(50122, "This user does not have invitation permission", myerr.BusinessData{}) // 该用户没有邀请权限
InviteApplyAlreadyInvited = myerr.NewBusinessCode(50123, "Already invited by someone else", myerr.BusinessData{}) // 已经被别人邀请了
InviteApplyCodeInvalid = myerr.NewBusinessCode(50124, "user id invalid", myerr.BusinessData{}) // 邀请人用户id错误
InviteApplyNewCodeInvalid = myerr.NewBusinessCode(50125, "user id invalid", myerr.BusinessData{}) // 被邀请人用户id错误
)
CREATE TABLE `invite_apply` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`user_id` bigint NOT NULL COMMENT '发起申请者',
`new_user_id` bigint NOT NULL COMMENT '被邀请的人',
`platform` varchar(20) NOT NULL COMMENT '来自平台',
`platform_id` varchar(150) NOT NULL COMMENT '平台id',
`recharge_info` varchar(50) NOT NULL COMMENT '新用户在其它平台充值的标志',
`status` tinyint unsigned NOT NULL COMMENT '状态0.未审核1.已通过2.已拒绝',
`level` varchar(5) NOT NULL DEFAULT '' COMMENT '申请等级(S,A,B,C)',
`video_url` varchar(400) NOT NULL COMMENT '上传的视频url',
`reason` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '拒绝原因',
`sub_user_id` bigint NOT NULL COMMENT '提交人',
`created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`) USING BTREE,
KEY `new_user_id` (`new_user_id`) USING BTREE,
KEY `platform` (`platform`) USING BTREE,
KEY `platform_id` (`platform_id`) USING BTREE,
KEY `status` (`status`) USING BTREE,
KEY `created_time` (`created_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='新人邀请申请';
INSERT INTO hilo.res_msg_translate (`language`, title, content, icon_url, msg_type, `type`, action_type, action_url)
VALUES ('en', '', 'The welcome party application of user {nick} (ID: {diamondIncome}) has been approved, the welcome party level is: {dayNum} level, inviter {beanNum} (ID: {groupCode})', '', 1, 59, 0, ''),
('tr', '', '{nick} kullanıcısının (ID: {diamondIncome}) karşılama partisi uygulaması onaylandı, karşılama partisi seviyesi: {dayNum} seviyesi, davet eden {beanNum} (ID: {groupCode})', '', 1, 59, 0, ''),
('en', '', 'The welcome party application of user {nick} (ID: {diamondIncome}) has been rejected. The reason for the rejection is: {dayNum}, inviter {beanNum} (ID: {groupCode})', '', 1, 60, 0, ''),
('tr', '', '{nick} kullanıcısının (ID: {diamondIncome}) karşılama partisi başvurusu reddedildi. Reddedilme nedeni: {dayNum}, davet eden {beanNum} (ID: {groupCode})', '', 1, 60, 0, ''),
('en', '', 'Welcome party application, please click to enter', 'https://image.whoisamy.shop/hilo/manager/welcomeparty.png', 1, 61, 1, 'https://h5.whoisamy.shop/action/hiloHtml/2023Activity/2023_7_03WelcomeParty/index.html'),
('tr', '', 'hoşgeldin partisi uygulaması, girmek için lütfen tıklayınız', 'https://image.whoisamy.shop/hilo/manager/welcomeparty.png', 1, 61, 1, 'https://h5.whoisamy.shop/action/hiloHtml/2023Activity/2023_7_03WelcomeParty/index.html');
......@@ -76,6 +76,32 @@ func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, has
c.JSON(http.StatusOK, response)
}
// 分页返回
// 客户端入参 req.PageReqBase
// 服务端返回 req.PageRespBase
func ResponsePageOk(c *gin.Context, data interface{}, total int64, pageSize, pageIndex int) {
if data == nil {
data = make([]interface{}, 0)
}
nextPageIndex := 0
hasNextPage := false
if (pageIndex-1)*pageSize+pageSize-1 < int(total) {
nextPageIndex = pageIndex + 1
hasNextPage = true
}
response := Response{
Code: myerr.GetSuccessCode(),
Message: myerr.GetSuccessMsg(),
OperationMessage: myerr.GetSuccessMsg(),
Data: req.PageRespBase{
NextPageIndex: nextPageIndex,
HasNextPage: hasNextPage,
Data: data,
},
}
c.JSON(http.StatusOK, response)
}
func ResponseWaring(c *gin.Context, waringError *myerr.WaringError) {
response := Response{
Code: waringError.GetCode(),
......
package invite_r
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-user/cv/invite_cv"
"hilo-user/domain/cache/user_c"
"hilo-user/domain/model/invite_m"
"hilo-user/domain/model/promotion_m"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr"
"hilo-user/req"
"hilo-user/resp"
"time"
)
// @Tags 新人邀请
// @Summary 提交申请
// @Param newUserCode formData string true "被邀请人id"
// @Param platform formData string true "平台"
// @Param platformId formData string true "平台Id"
// @Param recharge formData string true "充值金额"
// @Param userCode formData string true "邀请人id"
// @Param videoUrl formData string true "充值金额"
// @Success 200
// @Router /v2/user/invite/apply [post]
func InviteApply(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
type paramStr struct {
NewUserCode string `form:"newUserCode" binding:"required"`
Platform string `form:"platform" binding:"required"`
PlatformId string `form:"platformId" binding:"required"`
Recharge string `form:"recharge" binding:"required"`
UserCode string `form:"userCode" binding:"required"`
VideoUrl string `form:"videoUrl" binding:"required"`
}
myUserId, err := req.GetUserId(c)
if err != nil {
return myCtx, err
}
var param paramStr
if err := c.ShouldBind(&param); err != nil {
return myCtx, err
}
model := domain.CreateModelContext(myCtx)
// 平台是否填写正确
platforms := promotion_m.GetPromotionPlatforms(model)
var existsPlatform bool
for _, v := range platforms {
if v == param.Platform {
existsPlatform = true
}
}
if !existsPlatform {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InvalidParameter
}
// code 是否存在
newUser, err := user_m.GetUserByCode(model, param.NewUserCode)
if err != nil {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InviteApplyNewCodeInvalid
}
user, err := user_m.GetUserByCode(model, param.UserCode)
if err != nil {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InviteApplyCodeInvalid
}
if newUser.ID == 0 || user.ID == 0 {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InvalidParameter
}
// 邀请人是否有资格邀请
if !promotion_m.IsPromotionAgent(model, user.ID) {
model.Log.Errorf("InviteApply 没有邀请资格 param:%v", param)
return myCtx, bizerr.InviteApplyNoPermission
}
//if user.ID != myUserId && !promotion_m.IsMyPromotionManager(model, user.ID, myUserId) {
// model.Log.Errorf("InviteApply 没有邀请资格 param:%v", param)
// return myCtx, bizerr.InviteApplyNoPermission
//}
// 被邀请人是否已经被人提交过申请
isApply, err := invite_m.IsInInviteApply(model, newUser.ID)
if err != nil {
model.Log.Errorf("InviteApply param:%v, err:%v", param, err)
return myCtx, err
}
if isApply {
model.Log.Errorf("InviteApply 已经被别人邀请过了 param:%v", param)
return myCtx, bizerr.InviteApplyAlreadyInvited
}
// 被邀请人是否符合条件
isInvite, err := promotion_m.IsPromotionInvitee(model, newUser.ID)
if err != nil {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, err
}
if isInvite {
model.Log.Errorf("InviteApply 已经被别人邀请了 param:%v", param)
return myCtx, bizerr.InviteApplyAlreadyInvited
}
// 插入邀请表
err = invite_m.CreateInviteApply(model, user.ID, newUser.ID, myUserId, param.Platform, param.PlatformId, param.Recharge, param.VideoUrl)
if err != nil {
model.Log.Errorf("InviteApply param:%v", param)
return myCtx, err
}
resp.ResponseOk(c, nil)
return myCtx, nil
}
// @Tags 新人邀请
// @Summary 查询历史申请
// @Param pageIndex query int true "偏移值 默认:1" default(1)
// @Param pageSize query int true "请求数量 默认:10" default(10)
// @Param beginTime query string true "开始时间2006-01-02"
// @Param endTime query string true "结束时间2006-01-02"
// @Param type query int true "1.已申请2.待审核3.已通过4.已拒绝"
// @Success 200 {object} invite_cv.InviteApplyRes
// @Router /v2/user/invite/apply [get]
func InviteApplyList(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
type paramStr struct {
PageIndex int `form:"pageIndex" binding:"required"`
PageSize int `form:"pageSize" binding:"required"`
BeginTime time.Time `form:"beginTime" binding:"required" time_format:"2006-01-02"`
EndTime time.Time `form:"endTime" binding:"required" time_format:"2006-01-02"`
Type int `form:"type"`
}
var param paramStr
if err := c.ShouldBindQuery(&param); err != nil {
return myCtx, err
}
if param.Type < 0 || param.Type > 4 {
return myCtx, bizerr.InvalidParameter
}
//beginTime, err := time.ParseInLocation(utils.DATE_FORMAT, param.BeginTime, time.Local)
//if err != nil {
// return nil, myerr.WrapErr(err)
//}
//endTime, err := time.ParseInLocation(utils.DATE_FORMAT, param.EndTime, time.Local)
//if err != nil {
// return nil, myerr.WrapErr(err)
//}
param.EndTime = utils.GetDayEndTime(param.EndTime)
userId, err := req.GetUserId(c)
if err != nil {
return myCtx, err
}
var model = domain.CreateModelContext(myCtx)
agentIds := []uint64{userId}
if promotion_m.IsPromotionManager(model, userId) {
agentIds, err = promotion_m.GetPromotionManagerAgentList(model, userId)
if err != nil {
return myCtx, err
}
}
if param.Type == 0 { // 返回所有Type类型有多少条数
user, err := user_c.GetUserTinyById(model, userId)
if err != nil {
model.Log.Errorf("GetApplyList param:%v, err:%v", param, err)
return myCtx, bizerr.InvalidParameter
}
numList := make([]*invite_cv.InviteApplyNumRes, 0, 4)
for _, gType := range []int{1, 2, 3, 4} { // 1.已申请2.待审核3.已通过4.已拒绝
num, err := invite_m.GetInviteApplyNumByType(model, gType, param.BeginTime, param.EndTime, agentIds, userId)
if err != nil {
return myCtx, err
}
numList = append(numList, &invite_cv.InviteApplyNumRes{Type: gType, Num: num})
}
resp.ResponsePageOk(c, &invite_cv.InviteApplyRes{NumList: numList, MyCode: user.Code}, 0, 0, 0)
return myCtx, nil
}
list, total, err := invite_m.GetApplyList(model, userId, agentIds, param.PageIndex, param.PageSize, param.Type, param.BeginTime, param.EndTime)
if err != nil {
model.Log.Errorf("GetApplyList param:%v, err:%v", param, err)
return myCtx, err
}
uids := make([]uint64, 0, len(list)+1)
for _, v := range list {
uids = append(uids, v.UserId, v.NewUserId)
}
users, err := user_c.GetUserTinyMap(model, uids, true)
if err != nil {
model.Log.Errorf("GetApplyList param:%v, err:%v", param, err)
return myCtx, err
}
res := &invite_cv.InviteApplyRes{}
res.List = make([]*invite_cv.InviteApply, 0, len(list))
for _, v := range list {
res.List = append(res.List, &invite_cv.InviteApply{
NewUserCode: users[v.NewUserId].Code,
Platform: v.Platform,
Recharge: v.RechargeInfo,
UserCode: users[v.UserId].Code,
CreateUnix: v.CreatedTime.Unix(),
Level: v.Level,
Status: v.Status,
Avatar: users[v.NewUserId].Avatar,
ExternalId: users[v.NewUserId].ExternalId,
Reason: v.Reason,
})
}
resp.ResponsePageOk(c, res, total, param.PageSize, param.PageIndex)
return myCtx, nil
}
// @tags 新人邀请
// @Summary 平台列表
// @Success 200 {object} []string
// @Router /v2/user/invite/platform [get]
func PromotionPlatform(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
resp.ResponseOk(c, []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla"})
return myCtx, nil
}
// @Tags 新人邀请
// @Summary 查询周期
// @Success 200 {object} invite_cv.AgentPeriod
// @Router /v2/user/invite/period [get]
func AgentPeriod(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
var response invite_cv.AgentPeriod
week := now.BeginningOfWeek().AddDate(0, 0, 1) // 周一开始
for i := 0; i < 12; i++ {
response.Week = append(response.Week, invite_cv.AgentPeriodWeek{
StartDate: week.Format("2006-01-02"),
EndDate: week.AddDate(0, 0, 6).Format("2006-01-02"),
})
week = week.AddDate(0, 0, -7)
}
resp.ResponseOk(c, response)
return myCtx, nil
}
......@@ -2,6 +2,8 @@ package route
import (
"bytes"
"crypto/md5"
"fmt"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
......@@ -13,6 +15,7 @@ import (
"hilo-user/resp"
"io/ioutil"
"runtime/debug"
"strconv"
"strings"
"time"
)
......@@ -146,3 +149,54 @@ func EncryptHandle(c *gin.Context) {
}
c.Next()
}
//http信息解密(web)
func HttpWebSecretHandle(c *gin.Context) {
traceId, _ := c.Keys[mycontext.TRACEID]
timestamp := c.GetHeader("timestamp") //时间戳,单位秒
nonce := c.GetHeader("nonce") //随机数字
signature := c.GetHeader("signature") //sha1加密结果
mylogrus.MyLog.Debugf("handle secret begin timestamp:%v, nonce:%v, signature:%v traceId:%v", timestamp, nonce, signature, traceId)
if nonce == "hilo" {
mylogrus.MyLog.Infof("no check http secret handle")
} else {
if timestamp == "" || nonce == "" || signature == "" {
resp.ResponseBusiness(c, bizerr.HttpSecret)
c.Abort()
return
}
timestampInt, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil {
resp.ResponseBusiness(c, bizerr.HttpSecret)
c.Abort()
return
}
nowTimestamp := time.Now().Unix()
v := nowTimestamp - timestampInt
//10分钟内有效,改成60分钟,20210402产品让我改成60分钟,原因:依旧有用户时间戳不对,达到了30分钟
if v < -60*60 || v > 60*60 {
mylogrus.MyLog.Warnf("handle secret err, timestampInt:%v, nowTimestamp:%v, v:%v, traceId:%v", timestampInt, nowTimestamp, v, traceId)
//2021/11/05 产品让我关的,因为中东用户时间戳有问题
/* ResponseBusiness(c, bizerr.HttpSecret)
c.Abort()
return*/
}
str := timestamp + config.GetConfigApp().WEB_SECRET + nonce
//避免web的暴露,让用户知道app的api加密方式。
h := md5.New()
//h := sha1.New()
h.Write([]byte(str))
newSignature := fmt.Sprintf("%x", h.Sum(nil))
//newSignature := string(sha1.New().Sum([]byte(str))[:])
if signature != newSignature {
mylogrus.MyLog.Errorf("handle secret err signature:%v, newSignature:%v, traceId:%v", signature, newSignature, traceId)
resp.ResponseBusiness(c, bizerr.HttpSecret)
c.Abort()
return
}
}
c.Next()
}
......@@ -12,6 +12,7 @@ import (
"hilo-user/domain/model/msg_m"
"hilo-user/resp"
"hilo-user/route/cp_r"
"hilo-user/route/invite_r"
"hilo-user/route/user_r"
)
......@@ -52,6 +53,13 @@ func InitRouter() *gin.Engine {
//cp.GET("/relation/detail", wrapper(cp_r.CpDetailPage))
cp.GET("/im/check", wrapper(cp_r.CheckCpImExpire))
}
userV2 := v2.Group("/user")
{
userV2.POST("/invite/apply", wrapper(invite_r.InviteApply))
userV2.GET("/invite/apply", wrapper(invite_r.InviteApplyList))
userV2.GET("/invite/platform", wrapper(invite_r.PromotionPlatform))
userV2.GET("/invite/period", wrapper(invite_r.AgentPeriod))
}
inner := r.Group("/inner")
inner.Use(ExceptionHandle, LoggerHandle)
innerUser := inner.Group("/user")
......
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