invite_apply.go 1.64 KB
Newer Older
chenweijian's avatar
chenweijian committed
1 2
package invite_m

chenweijian's avatar
chenweijian committed
3 4 5 6
import (
	"git.hilo.cn/hilo-common/domain"
	"time"
)
chenweijian's avatar
chenweijian committed
7 8

type InviteApply struct {
chenweijian's avatar
chenweijian committed
9 10 11 12 13 14 15 16 17
	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"`
chenweijian's avatar
chenweijian committed
18 19 20
}

func CreateInviteApply(model *domain.Model, userId, newUserId uint64, platform, recharge, videoUrl string) error {
chenweijian's avatar
chenweijian committed
21 22 23
	err := model.DB().Create(&InviteApply{
		UserId: userId, NewUserId: newUserId, Platform: platform, RechargeInfo: recharge, VideoUrl: videoUrl,
		CreatedTime: time.Now()}).Error
chenweijian's avatar
chenweijian committed
24 25 26 27 28 29
	if err != nil {
		model.Log.Errorf("CreateInviteApply err:%v", err)
		return err
	}
	return nil
}
chenweijian's avatar
chenweijian committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

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
}