3 Star 1 Fork 898

高煜涛/gin-vue-admin

forked from pixel/gin-vue-admin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fd_health_manager_register.go 6.61 KB
一键复制 编辑 原始数据 按行查看 历史
高煜涛 提交于 2024-10-25 10:46 . 24/10/44
package manager
import (
"gitee.com/g-qs/gin-vue-admin/server/global"
"gitee.com/g-qs/gin-vue-admin/server/model/common/request"
"gitee.com/g-qs/gin-vue-admin/server/model/manager"
managerReq "gitee.com/g-qs/gin-vue-admin/server/model/manager/request"
"gitee.com/g-qs/gin-vue-admin/server/model/system"
"gorm.io/gorm"
)
type FdHealthManagerRegisterService struct {
}
// CreateFdHealthManagerRegister 创建健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) CreateFdHealthManagerRegister(fdHealthManagerRegister *manager.FdHealthManagerRegister) (err error) {
err = global.GVA_DB.Create(fdHealthManagerRegister).Error
return err
}
// DeleteFdHealthManagerRegister 删除健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) DeleteFdHealthManagerRegister(fdHealthManagerRegister manager.FdHealthManagerRegister) (err error) {
err = global.GVA_DB.Delete(&fdHealthManagerRegister).Error
return err
}
// DeleteFdHealthManagerRegisterByIds 批量删除健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) DeleteFdHealthManagerRegisterByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]manager.FdHealthManagerRegister{}, "id in ?", ids.Ids).Error
return err
}
// UpdateFdHealthManagerRegister 更新健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) UpdateFdHealthManagerRegister(fdHealthManagerRegister manager.FdHealthManagerRegister) (err error) {
return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
if fdHealthManagerRegister.RegisterStatus != nil && *fdHealthManagerRegister.RegisterStatus == 1 {
fdHealthManagerRegister.RegisterInfo = "通过"
err = global.GVA_DB.First(&manager.FdHealthManager{}, "hm_id = ?", fdHealthManagerRegister.HmId).Update("is_register", true).Error
if err != nil {
return err
}
}
err = global.GVA_DB.Save(&fdHealthManagerRegister).Error
return err
})
}
// GetFdHealthManagerRegister 根据id获取健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) GetFdHealthManagerRegister(id uint) (fdHealthManagerRegister manager.FdHealthManagerRegister, err error) {
err = global.GVA_DB.Preload("FdHealthManager").Where("id = ?", id).First(&fdHealthManagerRegister).Error
return
}
// GetFdHealthManagerRegisterInfoList 分页获取健康师注册记录
// Author [piexlmax](https://github.com/piexlmax)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) GetFdHealthManagerRegisterInfoList(info managerReq.FdHealthManagerRegisterSearch) (list []manager.FdHealthManagerRegister, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
// 创建db
db := global.GVA_DB.Where("store_id = ?", info.FdHealthManager.StoreId).Joins("FdHealthManager").Preload("FdHealthManager", func(db *gorm.DB) *gorm.DB {
return db.Omit("Password")
}).Model(&manager.FdHealthManagerRegister{})
var fdHealthManagerRegisters []manager.FdHealthManagerRegister
// 如果有条件搜索 下方会自动创建搜索语句
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
}
if info.Name != "" {
db = db.Where("FdHealthManager.name LIKE ?", "%"+info.Name+"%")
}
if info.Phone != "" {
db = db.Where("FdHealthManager.phone = ?", info.Phone)
}
err = db.Count(&total).Error
if err != nil {
return
}
if limit != 0 {
db = db.Limit(limit).Offset(offset)
}
err = db.Find(&fdHealthManagerRegisters).Error
return fdHealthManagerRegisters, total, err
}
// GetScHealthManagerRegisterList 获取健康师注册列表【服务中心】
// Author [g-qs](https://github.com/g-qs)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) GetScHealthManagerRegisterList(info managerReq.FdHealthManagerRegisterSearch, ScID uint) (list []manager.FdHealthManagerRegister, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
// 创建db
var serviceStations []system.SysUser
err = global.GVA_DB.Model(&system.SysUser{}).Where("creator = ?", ScID).Find(&serviceStations).Error
var ids []uint
for _, v := range serviceStations {
ids = append(ids, v.ID)
}
db := global.GVA_DB.Where("store_id IN (?)", ids).Joins("FdHealthManager").Preload("FdHealthManager", func(db *gorm.DB) *gorm.DB {
return db.Omit("Password")
}).Model(&manager.FdHealthManagerRegister{})
var fdHealthManagerRegisters []manager.FdHealthManagerRegister
// 如果有条件搜索 下方会自动创建搜索语句
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
}
if info.Name != "" {
db = db.Where("FdHealthManager.name LIKE ?", "%"+info.Name+"%")
}
if info.Phone != "" {
db = db.Where("FdHealthManager.phone = ?", info.Phone)
}
err = db.Count(&total).Error
if err != nil {
return
}
if limit != 0 {
db = db.Limit(limit).Offset(offset)
}
err = db.Find(&fdHealthManagerRegisters).Error
return fdHealthManagerRegisters, total, err
}
// GetAllHealthManagerRegisterInfoList 分页获取全部健康师注册记录【超管】
// Author [g-qs](https://gitee.com/g-qs)
func (fdHealthManagerRegisterService *FdHealthManagerRegisterService) GetAllHealthManagerRegisterInfoList(info managerReq.FdHealthManagerRegisterSearch) (list []manager.FdHealthManagerRegister, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
// 创建db
db := global.GVA_DB.Joins("FdHealthManager").Preload("FdHealthManager", func(db *gorm.DB) *gorm.DB {
return db.Preload("HealthManageCenter").Omit("Password")
}).Model(&manager.FdHealthManagerRegister{})
var fdHealthManagerRegisters []manager.FdHealthManagerRegister
// 如果有条件搜索 下方会自动创建搜索语句
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
db = db.Where("FdHealthManager.created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
}
if info.Name != "" {
db = db.Where("FdHealthManager.name LIKE ?", "%"+info.Name+"%")
}
if info.Phone != "" {
db = db.Where("FdHealthManager.phone = ?", info.Phone)
}
err = db.Count(&total).Error
if err != nil {
return
}
if limit != 0 {
db = db.Limit(limit).Offset(offset)
}
err = db.Find(&fdHealthManagerRegisters).Error
return fdHealthManagerRegisters, total, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/g-qs/gin-vue-admin.git
git@gitee.com:g-qs/gin-vue-admin.git
g-qs
gin-vue-admin
gin-vue-admin
533102b8437a

搜索帮助