package dao import ( "encoding/json" "errors" "github.com/fonchain-artistserver/cmd/model" "github.com/fonchain-artistserver/pb/supplyinfo" db "github.com/fonchain-artistserver/pkg/db" "github.com/fonchain-artistserver/pkg/m" "go.uber.org/zap" ) func GetSupplyInfoList(id, num int32) (rep *supplyinfo.GetSupplyInfoListRespond, err error) { rep = &supplyinfo.GetSupplyInfoListRespond{} var datas []*supplyinfo.GetSupplyInfoData var supplyInfoList []model.SupplyInfo if err := db.DB.Where("user_id = ? and types <= ?", id, num).Find(&supplyInfoList).Error; err != nil { zap.L().Error("get supplyInfo infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } for i, v := range supplyInfoList { supplyInfoList[i].CreateTime = v.CreatedAt.Format("2006-01-02") data := &supplyinfo.GetSupplyInfoData{} data.ID = uint64(supplyInfoList[i].ID) data.ArtworkId = supplyInfoList[i].ArtworkId data.ArtistId = supplyInfoList[i].ArtistId data.UserId = uint64(supplyInfoList[i].UserId) data.Name = supplyInfoList[i].Name data.ModelYear = supplyInfoList[i].ModelYear data.Photo = supplyInfoList[i].Photo data.ArtistPhoto = supplyInfoList[i].ArtistPhoto data.Width = uint64(supplyInfoList[i].Width) data.Height = uint64(supplyInfoList[i].Height) data.Ruler = uint64(supplyInfoList[i].Ruler) data.ExhibitInfo = supplyInfoList[i].ExhibitInfo data.ExhibitPic1 = supplyInfoList[i].ExhibitPic1 data.ExhibitPic2 = supplyInfoList[i].ExhibitPic2 data.CreateTime = supplyInfoList[i].CreateTime data.Introduct = supplyInfoList[i].Introduct data.NetworkTrace = supplyInfoList[i].NetworkTrace data.CreateAddress = supplyInfoList[i].CreateAddress data.Url = supplyInfoList[i].Url data.Types = supplyInfoList[i].Types data.Remark = supplyInfoList[i].Remark data.Remark2 = supplyInfoList[i].Remark2 data.Enable = supplyInfoList[i].Enable datas = append(datas, data) } rep.Data = datas return } func GetSupplyInfo(req *supplyinfo.GetSupplyInfoRequest) (rep *supplyinfo.GetSupplyInfoData, err error) { rep = &supplyinfo.GetSupplyInfoData{} var supplyInfoTmp model.SupplyInfo if err := db.DB.Where("id = ?", req.Id).Find(&supplyInfoTmp).Error; err != nil { zap.L().Error("get supplyInfo infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } rep.ID = uint64(supplyInfoTmp.ID) rep.ArtworkId = supplyInfoTmp.ArtworkId rep.ArtistId = supplyInfoTmp.ArtistId rep.UserId = uint64(supplyInfoTmp.UserId) rep.Name = supplyInfoTmp.Name rep.ModelYear = supplyInfoTmp.ModelYear rep.Photo = supplyInfoTmp.Photo rep.ArtistPhoto = supplyInfoTmp.ArtistPhoto rep.Width = uint64(supplyInfoTmp.Width) rep.Height = uint64(supplyInfoTmp.Height) rep.Ruler = uint64(supplyInfoTmp.Ruler) rep.ExhibitInfo = supplyInfoTmp.ExhibitInfo rep.ExhibitPic1 = supplyInfoTmp.ExhibitPic1 rep.ExhibitPic2 = supplyInfoTmp.ExhibitPic2 rep.CreateTime = supplyInfoTmp.CreateTime rep.Introduct = supplyInfoTmp.Introduct rep.NetworkTrace = supplyInfoTmp.NetworkTrace rep.CreateAddress = supplyInfoTmp.CreateAddress rep.Url = supplyInfoTmp.Url rep.Types = supplyInfoTmp.Types rep.Remark = supplyInfoTmp.Remark rep.Remark2 = supplyInfoTmp.Remark2 rep.Enable = supplyInfoTmp.Enable return } func UpdateSupplyInfo(req *supplyinfo.UpdateSupplyInfoRequest) (rep *supplyinfo.UpdateSupplyInfoRespond, err error) { var SupplyInfo model.SupplyInfo if err := db.DB.Where("id = ? ", req.ID).Find(&SupplyInfo).Error; err != nil { zap.L().Error("get supplyInfo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } SupplyInfo.CreateTime = req.CreateTime SupplyInfo.ModelYear = req.ModelYear SupplyInfo.NetworkTrace = req.NetworkTrace SupplyInfo.Url = req.Url SupplyInfo.Introduct = req.Introduct SupplyInfo.Types = req.Types SupplyInfo.ExhibitInfo = req.ExhibitInfo SupplyInfo.ExhibitPic1 = req.ExhibitPic1 SupplyInfo.ExhibitPic2 = req.ExhibitPic2 if err = db.DB.Save(&SupplyInfo).Error; err != nil { zap.L().Error("save supplyInfo info err", zap.Error(err)) err = errors.New(m.SAVE_ERROR) return } return } func GetVideoList(id int32) (rep *supplyinfo.GetVideoListRespond, err error) { rep = &supplyinfo.GetVideoListRespond{} var datas []*supplyinfo.GetVideoListData var ExhVideo []model.ExhVideo if err := db.DB.Where("user_id = ? and types <=4", id).Find(&ExhVideo).Error; err != nil { zap.L().Error("get exhVideo infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } for _, v := range ExhVideo { var data supplyinfo.GetVideoListData data.ID = uint64(v.ID) data.UserId = uint64(v.UserId) data.Url = v.Url data.Types = v.Types data.Remark = v.Remark data.Remark2 = v.Remark2 data.Enable = v.Enable datas = append(datas, &data) } rep.Data = datas return } func GetVideo(req *supplyinfo.GetVideoRequest) (rep *supplyinfo.GetVideoListData, err error) { rep = &supplyinfo.GetVideoListData{} var ExhVideo model.ExhVideo if err := db.DB.Where("id = ?", req.ID).First(&ExhVideo).Error; err != nil { zap.L().Error("get exhVideo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } rep.ID = uint64(ExhVideo.ID) rep.UserId = uint64(ExhVideo.UserId) rep.Url = ExhVideo.Url rep.Types = ExhVideo.Types rep.Remark = ExhVideo.Remark rep.Remark2 = ExhVideo.Remark2 rep.Enable = ExhVideo.Enable return } func UpdateVideo(req *supplyinfo.UpdateVideoRequest) (rep *supplyinfo.UpdateVideoRespond, err error) { rep = &supplyinfo.UpdateVideoRespond{} var ExhVideo model.ExhVideo if err := db.DB.Where("id = ? ", req.ID).First(&ExhVideo).Error; err != nil { zap.L().Error("get exhVideo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } ExhVideo.Url = req.Url ExhVideo.Types = req.Types if err := db.DB.Save(&ExhVideo).Error; err != nil { zap.L().Error("save exhVideo info err", zap.Error(err)) err = errors.New(m.SAVE_ERROR) return nil, err } return } func GetExam(req *supplyinfo.GetExamRequest) (rep *supplyinfo.GetExamListData, err error) { rep = &supplyinfo.GetExamListData{} var ExhExam model.ExhExam if err := db.DB.Where("id = ?", req.ID).First(&ExhExam).Error; err != nil { zap.L().Error("get exhVideo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } rep.ID = uint64(ExhExam.ID) rep.UserId = uint64(ExhExam.UserId) rep.Title = ExhExam.Title rep.Class = ExhExam.Class rep.TitleScore = uint64(ExhExam.TitleScore) rep.Score = ExhExam.Score rep.Types = ExhExam.Types rep.Remark = ExhExam.Remark rep.Remark2 = ExhExam.Remark2 rep.Enable = ExhExam.Enable return } func GetExamList(req *supplyinfo.GetExamListRequest) (rep *supplyinfo.GetExamListRespond, err error) { rep = &supplyinfo.GetExamListRespond{} var datas []*supplyinfo.GetExamListData var ExhExam []model.ExhExam if err := db.DB.Where("user_id = ? and types <=4", req.ID).Find(&ExhExam).Error; err != nil { zap.L().Error("get exhVideo infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } for _, v := range ExhExam { var data supplyinfo.GetExamListData data.ID = uint64(v.ID) data.UserId = uint64(v.UserId) data.Title = v.Title data.Class = v.Class data.TitleScore = uint64(v.TitleScore) data.Score = v.Score data.Types = v.Types data.Remark = v.Remark data.Remark2 = v.Remark2 data.Enable = v.Enable datas = append(datas, &data) } rep.Data = datas return } func UpdateExam(req *supplyinfo.UpdateExamRequest) (rep *supplyinfo.UpdateExamRespond, err error) { rep = &supplyinfo.UpdateExamRespond{} var ExhExam model.ExhExam if err := db.DB.Where("id = ? ", req.ID).First(&ExhExam).Error; err != nil { zap.L().Error("get exhVideo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } ExhExam.Score = req.Score ExhExam.Class = req.Class ExhExam.Types = req.Types ExhExam.Title = req.Title ExhExam.Class = req.Class ExhExam.TitleScore = uint(req.TitleScore) ExhExam.Score = req.Score ExhExam.Types = req.Types ExhExam.Remark = req.Remark ExhExam.Remark2 = req.Remark2 var score map[string]int32 var titleScore int32 json.Unmarshal([]byte(req.Score), &score) for _, v := range score { titleScore = titleScore + v } ExhExam.TitleScore = uint(titleScore) if err = db.DB.Save(&ExhExam).Error; err != nil { zap.L().Error("save supplyInfo info err", zap.Error(err)) err = errors.New(m.SAVE_ERROR) return } if req.Types == "2" { type titleScore struct { UserId uint Score int } var tmp []model.ExhExam if err = db.DB.Where("class = ?", req.Class).Order("title_score desc").Find(&tmp).Error; err != nil { zap.L().Error("get exhExam infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } var ranking int for k, v := range tmp { if v.UserId == uint(req.UserId) { ranking = k } } percent := (ranking + 1) / len(tmp) * 100 rep.Percent = int32(percent) return } return } func GetArtistInfoList(id int32) (rep *supplyinfo.GetArtistInfoListRespond, err error) { rep = &supplyinfo.GetArtistInfoListRespond{} var datas []*supplyinfo.GetArtistInfoListData var artistInfoTmp []model.ArtistInfo if err = db.DB.Where("user_id = ? and state <=4 ", id).Find(&artistInfoTmp).Error; err != nil { zap.L().Error("get artistInfo infos err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } for k, v := range artistInfoTmp { artistInfoTmp[k].Model.ID = uint(v.ID) data := &supplyinfo.GetArtistInfoListData{} data.ID = uint64(artistInfoTmp[k].ID) data.UserId = uint64(artistInfoTmp[k].UserId) data.ArtistId = artistInfoTmp[k].ArtistId data.BankAccount = artistInfoTmp[k].BankAccount data.BankName = artistInfoTmp[k].BankName data.Introduct = artistInfoTmp[k].Introduct data.CountryArtLevel = artistInfoTmp[k].CountryArtLevel data.ArtistCertPic = artistInfoTmp[k].ArtistCertPic data.Remark = artistInfoTmp[k].Remark data.Remark2 = artistInfoTmp[k].Remark2 data.State = uint64(artistInfoTmp[k].State) datas = append(datas, data) } rep.Data = datas return } func GetArtistInfo(req *supplyinfo.GetArtistInfoRequest) (rep *supplyinfo.GetArtistInfoListData, err error) { rep = &supplyinfo.GetArtistInfoListData{} var artistInfoTmp model.ArtistInfo if err := db.DB.Where("id = ?", req.ID).Find(&artistInfoTmp).Error; err != nil { zap.L().Error("get artistInfo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } rep.ID = uint64(artistInfoTmp.ID) rep.UserId = uint64(artistInfoTmp.UserId) rep.ArtistId = artistInfoTmp.ArtistId rep.BankAccount = artistInfoTmp.BankAccount rep.BankName = artistInfoTmp.BankName rep.Introduct = artistInfoTmp.Introduct rep.CountryArtLevel = artistInfoTmp.CountryArtLevel rep.ArtistCertPic = artistInfoTmp.ArtistCertPic rep.Remark = artistInfoTmp.Remark rep.Remark2 = artistInfoTmp.Remark2 rep.State = uint64(artistInfoTmp.State) return } func UpdateArtistInfo(req *supplyinfo.UpdateArtistInfoRequest) (rep *supplyinfo.UpdateArtistInfoRespond, err error) { rep = &supplyinfo.UpdateArtistInfoRespond{} var artistInfoTmp model.ArtistInfo if err := db.DB.Where("id = ? ", req.ID).Find(&artistInfoTmp).Error; err != nil { zap.L().Error("get artistInfo info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return nil, err } artistInfoTmp.BankAccount = req.BankAccount artistInfoTmp.BankName = req.BankName artistInfoTmp.Introduct = req.Introduct artistInfoTmp.State = uint(req.State) artistInfoTmp.CountryArtLevel = req.CountryArtLevel artistInfoTmp.ArtistCertPic = req.ArtistCertPic if err = db.DB.Save(&artistInfoTmp).Error; err != nil { zap.L().Error("save supplyInfo info err", zap.Error(err)) err = errors.New(m.SAVE_ERROR) return } return }