From 1babf36f12dc2a0f8a9942b9edf73a8945241f80 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 28 Jun 2023 16:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BE=E5=AF=B9=E9=82=80=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/invite_cv/invite_apply.go | 21 +++++ domain/model/invite_m/invite_apply.go | 41 ++++++++-- ...6\345\257\271\347\224\263\350\257\267.sql" | 1 + resp/response.go | 26 ++++++ route/invite_r/party_invite.go | 82 +++++++++++++++++++ route/router.go | 3 +- 6 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 cv/invite_cv/invite_apply.go diff --git a/cv/invite_cv/invite_apply.go b/cv/invite_cv/invite_apply.go new file mode 100644 index 0000000..baf3f65 --- /dev/null +++ b/cv/invite_cv/invite_apply.go @@ -0,0 +1,21 @@ +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 { + 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.已拒绝 +} diff --git a/domain/model/invite_m/invite_apply.go b/domain/model/invite_m/invite_apply.go index e2b2d6e..b2780e8 100644 --- a/domain/model/invite_m/invite_apply.go +++ b/domain/model/invite_m/invite_apply.go @@ -1,15 +1,20 @@ package invite_m -import "git.hilo.cn/hilo-common/domain" +import ( + "git.hilo.cn/hilo-common/domain" + "time" +) type InviteApply struct { - Id uint64 `json:"id"` - UserId uint64 `json:"user_id"` - NewUserId uint64 `json:"new_user_id"` - Platform string `json:"platform"` - RechargeInfo string `json:"recharge_info"` - Status uint8 `json:"status"` // 状态0.未审核1.已通过2.已拒绝 - VideoUrl string `json:"video_url"` + Id uint64 `json:"id"` + UserId uint64 `json:"user_id"` + NewUserId uint64 `json:"new_user_id"` + Platform string `json:"platform"` + 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"` } func CreateInviteApply(model *domain.Model, userId, newUserId uint64, platform, recharge, videoUrl string) error { @@ -20,3 +25,23 @@ func CreateInviteApply(model *domain.Model, userId, newUserId uint64, platform, } return nil } + +func GetApplyList(model *domain.Model, userId uint64, pageIndex, pageSize, gType int, beginTime, endTime time.Time) ([]*InviteApply, int64, error) { + db := model.DB().Model(InviteApply{}).Where("user_id = ?", userId).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 +} diff --git "a/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" "b/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" index 6d675af..41bf5d9 100644 --- "a/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" +++ "b/mysql/\346\226\260\344\272\272\346\264\276\345\257\271\347\224\263\350\257\267.sql" @@ -5,6 +5,7 @@ CREATE TABLE `invite_apply` ( `platform` varchar(20) NOT NULL COMMENT '从那个平台过来', `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', `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, diff --git a/resp/response.go b/resp/response.go index 2530a0d..e4b2784 100755 --- a/resp/response.go +++ b/resp/response.go @@ -63,6 +63,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(), diff --git a/route/invite_r/party_invite.go b/route/invite_r/party_invite.go index 4793e1d..085767c 100644 --- a/route/invite_r/party_invite.go +++ b/route/invite_r/party_invite.go @@ -3,12 +3,18 @@ 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" + "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" "hilo-user/myerr/bizerr" + "hilo-user/req" "hilo-user/resp" + "time" ) // @Tags 新人邀请 @@ -88,3 +94,79 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { 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 string `form:"beginTime" binding:"required"` + EndTime string `form:"endTime" binding:"required"` + Type int `form:"type" binding:"required"` + } + + var param paramStr + if err := c.ShouldBindQuery(¶m); err != nil { + return myCtx, err + } + if param.Type < 1 || 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) + } + endTime = utils.GetDayEndTime(endTime) + userId, err := req.GetUserId(c) + if err != nil { + return myCtx, err + } + + var model = domain.CreateModelContext(myCtx) + + list, total, err := invite_m.GetApplyList(model, userId, param.PageIndex, param.PageSize, param.Type, beginTime, 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, false) + if err != nil { + model.Log.Errorf("GetApplyList param:%v, err:%v", param, err) + return myCtx, err + } + res := make([]*invite_cv.InviteApplyRes, 0, len(list)) + for _, v := range list { + res = append(res, &invite_cv.InviteApplyRes{ + 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, + }) + } + + resp.ResponsePageOk(c, res, total, param.PageSize, param.PageIndex) + return myCtx, nil +} diff --git a/route/router.go b/route/router.go index 02060b6..2217830 100755 --- a/route/router.go +++ b/route/router.go @@ -55,7 +55,8 @@ func InitRouter() *gin.Engine { } userV2 := v2.Group("/user") { - userV2.GET("/invite/apply", wrapper(invite_r.InviteApply)) + userV2.POST("/invite/apply", wrapper(invite_r.InviteApply)) + userV2.GET("/invite/apply", wrapper(invite_r.InviteApplyList)) } inner := r.Group("/inner") inner.Use(ExceptionHandle, LoggerHandle) -- 2.22.0