Commit 1babf36f authored by chenweijian's avatar chenweijian

派对邀请

parent 8874a8e0
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.已拒绝
}
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"`
......@@ -10,6 +13,8 @@ type InviteApply struct {
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
}
......@@ -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,
......
......@@ -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(),
......
......@@ -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(&param); 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
}
......@@ -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)
......
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