71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package vip
|
|
|
|
import (
|
|
"git.echol.cn/loser/lckt/global"
|
|
"git.echol.cn/loser/lckt/model/common/request"
|
|
"git.echol.cn/loser/lckt/model/vip"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type VipService struct{}
|
|
|
|
// GetVipList 获取会员列表
|
|
func (v *VipService) GetVipList(p request.PageInfo) (vipList []vip.Vip, total int64, err error) {
|
|
limit := p.PageSize
|
|
offset := p.PageSize * (p.Page - 1)
|
|
// 创建db
|
|
db := global.GVA_DB.Model(&vip.Vip{})
|
|
|
|
err = db.Count(&total).Error
|
|
if err != nil {
|
|
global.GVA_LOG.Error("获取会员列表失败", zap.Error(err))
|
|
return
|
|
}
|
|
|
|
if limit != 0 {
|
|
db = db.Limit(limit).Offset(offset)
|
|
}
|
|
err = db.Find(&vipList).Error
|
|
if err != nil {
|
|
global.GVA_LOG.Error("获取会员列表失败", zap.Error(err))
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// CreateVip 创建会员
|
|
func (v *VipService) CreateVip(vip vip.Vip) (err error) {
|
|
err = global.GVA_DB.Create(&vip).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// UpdateVip 更新会员
|
|
func (v *VipService) UpdateVip(vip vip.Vip) (err error) {
|
|
err = global.GVA_DB.Save(&vip).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// DeleteVip 删除会员
|
|
func (v *VipService) DeleteVip(vip vip.Vip) (err error) {
|
|
err = global.GVA_DB.Delete(&vip).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// GetVipById 获取会员详情
|
|
func (v *VipService) GetVipById(id string) (vip vip.Vip, err error) {
|
|
err = global.GVA_DB.Where("id = ?", id).First(&vip).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|