fonchain-artshow/cmd/dao/show_apply.go

73 lines
1.7 KiB
Go
Raw Normal View History

2022-09-21 06:30:52 +00:00
package dao
import (
"fonchain-artshow/cmd/model"
2022-09-22 06:23:56 +00:00
"fonchain-artshow/pb/artShow"
2022-09-21 06:30:52 +00:00
"fonchain-artshow/pkg/db"
2022-09-22 06:23:56 +00:00
"fonchain-artshow/pkg/m"
2022-09-21 06:30:52 +00:00
"go.uber.org/zap"
"gorm.io/gorm"
)
func SaveShowApply(showApply *model.ShowApply) (tx *gorm.DB, err error) {
tx = db.DbArtShow.Begin()
if showApply.ID != uint(0) {
err = tx.Model(&model.ShowApply{}).Omit("id").Where("id = ?", showApply.ID).Updates(showApply).Error
} else {
2022-10-27 08:06:36 +00:00
err = tx.Model(&model.ShowApply{}).Create(&showApply).Error
2022-09-21 06:30:52 +00:00
}
if err != nil {
zap.L().Error("ShowApply err", zap.Error(err))
return
}
return
}
2022-09-22 06:23:56 +00:00
func ShowApplyList(in *artShow.ApplyListReq) (err error, total int64, out []*model.ShowApply) {
2022-09-21 06:30:52 +00:00
out = make([]*model.ShowApply, 0)
queryDB := db.DbArtShow.Model(&model.ShowApply{})
2022-09-22 06:23:56 +00:00
if in.Status == 0 {
in.Status = m.SHOWAPPLY_ADD
}
queryDB.Where("status = ?", in.Status)
2022-09-21 06:30:52 +00:00
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("ShowApplyList count err", zap.Error(err))
return
}
if in.PageSize != 0 {
queryDB = queryDB.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize))
}
err = queryDB.Find(&out).Error
if err != nil {
zap.L().Error("ShowApplyList err", zap.Error(err))
return
}
return
}
func ShowApplyDetail(applyID uint) (err error, out *model.ShowApply) {
out = new(model.ShowApply)
err = db.DbArtShow.Model(&model.ShowApply{}).Where("id = ?", applyID).Find(&out).Error
if err != nil {
zap.L().Error("ShowApplyDetail err", zap.Error(err))
return
}
return
}
2022-10-27 08:06:36 +00:00
2022-09-22 06:23:56 +00:00
func DelShowApply(in *artShow.DelApplyReq) (tx *gorm.DB, err error) {
2022-09-21 06:30:52 +00:00
tx = db.DbArtShow.Begin()
err = tx.Delete(&model.ShowApply{}, in.ApplyID).Error
if err != nil {
zap.L().Error("ShowApply delete err", zap.Error(err))
return
}
return
}