package test import ( "srm/global" "srm/model/common/request" "srm/model/test" testReq "srm/model/test/request" ) type MemberService struct { } // CreateMember 创建Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) CreateMember(m *test.Member) (err error) { err = global.GVA_DB.Create(m).Error return err } // DeleteMember 删除Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) DeleteMember(m test.Member) (err error) { err = global.GVA_DB.Delete(&m).Error return err } // DeleteMemberByIds 批量删除Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) DeleteMemberByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]test.Member{}, "id in ?", ids.Ids).Error return err } // UpdateMember 更新Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) UpdateMember(m test.Member) (err error) { err = global.GVA_DB.Updates(&m).Error return err } // GetMember 根据id获取Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) GetMember(id uint) (m test.Member, err error) { err = global.GVA_DB.Where("id = ?", id).First(&m).Error return } // GetMemberInfoList 分页获取Member记录 // Author [piexlmax](https://github.com/piexlmax) func (mService *MemberService) GetMemberInfoList(info testReq.MemberSearch) (list []test.Member, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 创建db db := global.GVA_DB.Model(&test.Member{}) var ms []test.Member // 如果有条件搜索 下方会自动创建搜索语句 if info.StartCreatedAt != nil && info.EndCreatedAt != nil { db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt) } if info.Uuid != "" { db = db.Where("uuid LIKE ?", "%"+info.Uuid+"%") } if info.UserName != "" { db = db.Where("user_name LIKE ?", "%"+info.UserName+"%") } if info.Nickname != "" { db = db.Where("nickname LIKE ?", "%"+info.Nickname+"%") } err = db.Count(&total).Error if err != nil { return } err = db.Limit(limit).Offset(offset).Find(&ms).Error return ms, total, err }