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.

155 lines
4.6 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"
2 years ago
"fonchain-artshow/pkg/m"
uuid "github.com/satori/go.uuid"
2 years ago
"go.uber.org/zap"
"gorm.io/gorm"
2 years ago
"strings"
"time"
2 years ago
)
func SaveArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
2 years ago
uid, err := uuid.NewV4()
if err != nil {
return nil
2 years ago
}
2 years ago
artShow.ShowUID = uid.String()
artShow.ShowSeq = strings.Join([]string{m.ARTSHOW_PREFIX, time.Now().Format("20060102150405")}, "")
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 UpdateArtShow(tx *gorm.DB, artShow *model.ArtShow) (err error) {
err = tx.Model(&model.ArtShow{}).Omit("show_uid").Where("show_uid = ?", artShow.ShowUID).Updates(artShow).Error
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{})
2 years ago
if in.ArtistUID != "" {
queryDB = queryDB.Where("artist_uid = ? ", in.ArtistUID)
2 years ago
}
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
}
2 years ago
func ArtShowList_apply(applyUID string) (err error, out []*model.ArtShow) {
2 years ago
out = make([]*model.ArtShow, 0)
2 years ago
err = db.DbArtShow.Table("art_show as a ").Distinct("a.show_uid").Select("a.show_uid,a.show_seq,a.show_name,a.artist_name,a.artist_uid,a.artwork_num,a.ruler,a.price,a.reward,a.show_time,a.is_show").Joins(" right join show_rel as b on a.show_uid = b.show_uid").Where("b.apply_uid = ? ", applyUID).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")
2 years ago
tx.Joins(" left join show_rel as b on b.show_uid = a.show_uid").Where("a.is_show = ?", in.IsShow)
2 years ago
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_uid string) (err error) {
err = tx.Where("show_uid = ?", show_uid).Delete(&model.ArtShow{}).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow delete err", zap.Error(err))
return
}
return
}
2 years ago
func QueryArtShow(show_uid string) (err error, out *model.ArtShow) {
err = db.DbArtShow.Model(&model.ArtShow{}).Where("show_uid = ?", show_uid).Find(&out).Error
2 years ago
if err != nil {
zap.L().Error("ArtShow Find err", zap.Error(err))
return
}
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
2 years ago
err = db.DbArtShow.Table("art_show as a").Distinct("a.artist_uid").Joins(" join artwork_price as b on b.show_uid = a.show_uid").Where("a.is_show in (1,2)").Count(&NotShowNum).Error
2 years ago
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
ShowHisNum = 0
2 years ago
err = db.DbArtShow.Table("art_show as a").Distinct("a.artist_uid").Joins(" join artwork_price as b on b.show_uid = a.show_uid").Where("a.is_show = 3 ").Count(&ShowHisNum).Error
2 years ago
if err != nil {
zap.L().Error("ShowStatistical totalNum count err", zap.Error(err))
return
}
2 years ago
return
}