You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.0 KiB
Go

2 years ago
package dao
import (
"fonchain-artshow/cmd/model"
2 years ago
"fonchain-artshow/pb/artShow"
2 years ago
"fonchain-artshow/pkg/db"
"go.uber.org/zap"
"gorm.io/gorm"
2 years ago
"log"
2 years ago
)
func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
if artShow.ID != uint(0) {
2 years ago
err = tx.Model(&model.ArtShow{}).Omit("id").Where("id = ?", artShow.ID).Updates(artShow).Error
2 years ago
} else {
2 years ago
err = tx.Model(&model.ArtShow{}).Create(&artShow).Error
2 years ago
}
if err != nil {
zap.L().Error("ArtShow err", zap.Error(err))
return
}
return
}
2 years ago
func ArtShowList(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShow) {
2 years ago
queryDB := db.DbArtShow.Model(&model.ArtShow{})
if in.ArtistID != "" {
queryDB = queryDB.Where("artist_id = ? ", in.ArtistID)
}
if in.StartTime != "" && in.EndTime != "" {
queryDB = queryDB.Where("convert(show_time, date) between ? and ?", in.StartTime, in.EndTime)
}
2 years ago
if in.IsShow != 0 {
queryDB = queryDB.Where("is_show = ?", in.IsShow)
}
2 years ago
err = queryDB.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowList Count err", zap.Error(err))
return
}
out = make([]*model.ArtShow, 0)
err = queryDB.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowList Find err", zap.Error(err))
return
}
return
}
func ArtShowList_apply(applyID uint) (err error, out []*model.ArtShow) {
out = make([]*model.ArtShow, 0)
2 years ago
err = db.DbArtShow.Table("art_show as a ").Select("a.*").Distinct("a.id").Joins(" right join show_rel as b on a.id = b.show_id").Where("b.apply_id = ? ", applyID).Find(&out).Error
2 years ago
if err != nil {
zap.L().Error("ArtShowList_apply Find err", zap.Error(err))
return
}
return
}
2 years ago
func ArtShowListByApplyStatus(in *artShow.ShowListReq) (err error, total int64, out []*model.ArtShow) {
2 years ago
out = make([]*model.ArtShow, 0)
tx := db.DbArtShow.Table("art_show as a")
tx.Joins(" left join show_rel as b on b.show_id = a.id").Where("a.is_show = ?", in.IsShow)
err = tx.Count(&total).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Count err", zap.Error(err))
return
}
err = tx.Offset(int((in.Page - 1) * in.PageSize)).
Limit(int(in.PageSize)).Find(&out).Error
if err != nil {
zap.L().Error("ArtShowListByApplyStatus Find err", zap.Error(err))
return
}
return
}
2 years ago
func DelArtShow(tx *gorm.DB, show_id int64) (err error) {
err = tx.Where("id = ?", show_id).Delete(&model.ArtShow{}).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow delete err", zap.Error(err))
return
}
return
}
func QueryArtShow(id uint) (err error, out *model.ArtShow) {
err = db.DbArtShow.Model(&model.ArtShow{}).Where("id = ?", id).Find(&out).Error
if err != nil {
zap.L().Error("ArtShow Find err", zap.Error(err))
return
}
2 years ago
log.Println(out)
2 years ago
return
}
2 years ago
func ShowStatistical(isShow int32) (err error, artistNum, packageNum, totalNum, NotShowNum, ShowHisNum int64) {
2 years ago
2 years ago
artistNum = 0
2 years ago
err = db.DbArtShow.Model(&model.ArtShow{}).Distinct("artist_name").Where("is_show = ?", isShow).Count(&artistNum).Error
if err != nil {
zap.L().Error("ShowStatistical artistNum count err", zap.Error(err))
return
}
2 years ago
packageNum = 0
2 years ago
err = db.DbArtShow.Model(&model.ArtShow{}).Where("is_show = ?", isShow).Count(&packageNum).Error
if err != nil {
zap.L().Error("ShowStatistical packageNum count err", zap.Error(err))
return
}
2 years ago
totalNum = 0
err = db.DbArtShow.Model(&model.ArtShow{}).Count(&totalNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
NotShowNum = 0
err = db.DbArtShow.Table("art_show as a").Distinct("b.artist_name").Joins(" join artwork_price as b on b.show_id = a.id").Where("a.is_show in (1,2)").Count(&NotShowNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
ShowHisNum = 0
err = db.DbArtShow.Table("art_show as a").Distinct("b.artist_name").Joins(" join artwork_price as b on b.show_id = a.id").Where("a.is_show = 3 ").Count(&ShowHisNum).Error
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
2 years ago
return
}