780 lines
25 KiB
Go
780 lines
25 KiB
Go
package officialwebsiteser
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/cachev2"
|
|
"91porn-server/common/constant/redisconst"
|
|
"time"
|
|
|
|
"91porn-server/common/stderr"
|
|
officialwebsitemod "91porn-server/models/v/officialWebsitemod"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// ─────────────────────────────────────────
|
|
// Service functions
|
|
// ─────────────────────────────────────────
|
|
|
|
func GetBasicData() (data GetBasicDataResp, err error) {
|
|
mod := &officialwebsitemod.BasicData{}
|
|
if err = mod.FindOne(); err != nil {
|
|
return
|
|
}
|
|
err = data.transfer(mod)
|
|
return
|
|
}
|
|
|
|
func CreateBasicData(req *ModifyBasicDataReq) (data officialwebsitemod.BasicData, err error) {
|
|
data, err = req.toMod()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if err = data.Create(); err != nil {
|
|
return officialwebsitemod.BasicData{}, err
|
|
}
|
|
return
|
|
}
|
|
|
|
func UpdateBasicData(req *ModifyBasicDataReq) (resp UpdateBasicDataResp, err error) {
|
|
if req == nil || req.ID == "" {
|
|
return
|
|
}
|
|
id, parseErr := primitive.ObjectIDFromHex(req.ID)
|
|
if parseErr != nil || isNilObjectID(id) {
|
|
err = stderr.ErrParamError
|
|
return
|
|
}
|
|
mod := &officialwebsitemod.BasicData{}
|
|
if err = mod.FindOne(); err != nil {
|
|
return
|
|
}
|
|
var update officialwebsitemod.M
|
|
if update, err = req.toM(); err != nil || update == nil {
|
|
return
|
|
}
|
|
resp.Count, err = mod.Update(officialwebsitemod.M{"_id": id}, update)
|
|
|
|
common.Go(func() {
|
|
// 删除缓存
|
|
cachev2.Classes().
|
|
CacheTime(redisconst.OfficialWebsiteBasicDataCacheExpire).
|
|
AutoListKey(redisconst.OfficialWebsiteBasicDataCacheKey).
|
|
DeleteCurrent()
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
func DeleteBasicData(req *DeleteBasicDataReq) (data DeleteBasicDataResp, err error) {
|
|
if req == nil {
|
|
err = stderr.CodeEmptyData
|
|
return
|
|
}
|
|
var id primitive.ObjectID
|
|
if id, err = primitive.ObjectIDFromHex(req.ID); err != nil {
|
|
return
|
|
}
|
|
if isNilObjectID(id) {
|
|
err = stderr.ErrParamError
|
|
return
|
|
}
|
|
mod := &officialwebsitemod.BasicData{}
|
|
data.Count, err = mod.Delete(officialwebsitemod.M{"_id": id})
|
|
return
|
|
}
|
|
|
|
// ─────────────────────────────────────────
|
|
// Query (BasicData) types
|
|
// ─────────────────────────────────────────
|
|
|
|
type GetBasicDataReq struct{}
|
|
|
|
type GetBasicDataResp struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
Title string `json:"title" bson:"title"`
|
|
Description string `json:"description" bson:"description"`
|
|
Banner []GBDBanner `json:"banner" bson:"banner"`
|
|
HeroBanner []GBDHeroBanner `json:"heroBanner" bson:"heroBanner"`
|
|
Masterpiece []GBDMasterpiece `json:"masterpiece" bson:"masterpiece"`
|
|
Business []GBDBusiness `json:"business" bson:"business"`
|
|
BannersDescription string `json:"bannersDescription" bson:"bannersDescription"`
|
|
BannersDuration int `json:"bannersDuration" bson:"bannersDuration"`
|
|
AboutUs GBDAboutUs `json:"aboutUs" bson:"aboutUs"`
|
|
FAQ []GBDFAQ `json:"faq" bson:"faq"`
|
|
HomePageCMS []GBDCMSData `json:"homePageCMS" bson:"homePageCMS"`
|
|
HomePageCMSDescription string `json:"homePageCMSDescription" bson:"homePageCMSDescription"`
|
|
RecruitCMS []GBDCMSData `json:"recruitCMS" bson:"recruitCMS"`
|
|
Tags []officialwebsitemod.Tag `json:"tags" bson:"tags"`
|
|
}
|
|
|
|
type GBDBanner struct {
|
|
Name string `json:"name" bson:"name"`
|
|
Description string `json:"description" bson:"description"`
|
|
Image string `json:"image" bson:"image"`
|
|
PhoneImage string `json:"phoneImage" bson:"phoneImage"`
|
|
Thumbnail string `json:"thumbnail" bson:"thumbnail"`
|
|
URL string `json:"url" bson:"url"`
|
|
}
|
|
|
|
type GBDHeroBanner struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
HeroID string `json:"heroId" bson:"heroId"`
|
|
Name string `json:"name" bson:"name"`
|
|
Description string `json:"description" bson:"description"`
|
|
Image string `json:"image" bson:"image"`
|
|
URL string `json:"url" bson:"url"`
|
|
Duration int `json:"duration" bson:"duration"`
|
|
}
|
|
|
|
type GBDMasterpiece struct {
|
|
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
Name string `json:"name" bson:"name"`
|
|
Description string `json:"description" bson:"description"`
|
|
Cover string `json:"cover" bson:"cover"`
|
|
Type string `json:"type" bson:"type"`
|
|
}
|
|
|
|
type GBDBusiness struct {
|
|
Name string `json:"name" bson:"name"`
|
|
EnglishName string `json:"englishName" bson:"englishName"`
|
|
Description string `json:"description" bson:"description"`
|
|
Cover string `json:"cover" bson:"cover"`
|
|
Detail []GBDBusinessDetail `json:"detail" bson:"detail"`
|
|
}
|
|
|
|
type GBDBusinessDetail struct {
|
|
Cover string `json:"cover" bson:"cover"`
|
|
Description string `json:"description" bson:"description"`
|
|
}
|
|
|
|
type GBDAboutUs struct {
|
|
Description string `json:"description" bson:"description"`
|
|
Companies []GBDCompanyInfo `json:"companies" bson:"companies"`
|
|
Values string `json:"values" bson:"values"`
|
|
ValuesImg string `json:"valuesImg" bson:"valuesImg"`
|
|
}
|
|
|
|
type GBDCompanyInfo struct {
|
|
Name string `json:"name" bson:"name"`
|
|
Address string `json:"address" bson:"address"`
|
|
Description string `json:"description" bson:"description"`
|
|
Contact []GBDContactInfo `json:"contact" bson:"contact"`
|
|
}
|
|
|
|
type GBDContactInfo struct {
|
|
Type string `json:"type" bson:"type"`
|
|
Value string `json:"value" bson:"value"`
|
|
}
|
|
|
|
type GBDFAQ struct {
|
|
Question string `json:"question" bson:"question"`
|
|
Answer string `json:"answer" bson:"answer"`
|
|
}
|
|
|
|
type GBDCMSData struct {
|
|
Description string `json:"description" bson:"description"`
|
|
Value string `json:"value" bson:"value"`
|
|
}
|
|
|
|
func (data *GetBasicDataResp) transfer(mod *officialwebsitemod.BasicData) error {
|
|
if mod == nil {
|
|
return stderr.CodeEmptyData
|
|
}
|
|
data.ID = mod.ID
|
|
data.Title = mod.Title
|
|
data.Description = mod.Description
|
|
data.Tags = mod.Tags
|
|
data.BannersDescription = mod.BannersDescription
|
|
data.BannersDuration = mod.BannersDuration
|
|
data.HomePageCMSDescription = mod.HomePageCMSDescription
|
|
data.AboutUs.Description = mod.AboutUs.Description
|
|
data.AboutUs.Values = mod.AboutUs.Values
|
|
data.AboutUs.ValuesImg = mod.AboutUs.ValuesImg
|
|
|
|
data.Banner = make([]GBDBanner, 0, len(mod.Banner))
|
|
for _, v := range mod.Banner {
|
|
data.Banner = append(data.Banner, GBDBanner{
|
|
Name: v.Name, Description: v.Description, Image: v.Image, PhoneImage: v.PhoneImage, Thumbnail: v.Thumbnail, URL: v.URL,
|
|
})
|
|
}
|
|
data.HeroBanner = make([]GBDHeroBanner, 0, len(mod.HeroBanner))
|
|
for _, v := range mod.HeroBanner {
|
|
data.HeroBanner = append(data.HeroBanner, GBDHeroBanner{
|
|
ID: v.ID, HeroID: v.HeroID.Hex(), Name: v.Name, Description: v.Description, Image: v.Image, URL: v.URL, Duration: v.Duration,
|
|
})
|
|
}
|
|
data.Masterpiece = make([]GBDMasterpiece, 0, len(mod.Masterpiece))
|
|
for _, v := range mod.Masterpiece {
|
|
data.Masterpiece = append(data.Masterpiece, GBDMasterpiece{
|
|
ID: v.ID, Name: v.Name, Description: v.Description, Cover: v.Cover, Type: v.Type,
|
|
})
|
|
}
|
|
data.Business = make([]GBDBusiness, 0, len(mod.Business))
|
|
for _, v := range mod.Business {
|
|
business := GBDBusiness{
|
|
Name: v.Name, EnglishName: v.EnglishName, Description: v.Description, Cover: v.Cover,
|
|
Detail: make([]GBDBusinessDetail, 0, len(v.Detail)),
|
|
}
|
|
for _, d := range v.Detail {
|
|
business.Detail = append(business.Detail, GBDBusinessDetail{
|
|
Cover: d.Cover, Description: d.Description,
|
|
})
|
|
}
|
|
data.Business = append(data.Business, business)
|
|
}
|
|
data.AboutUs.Companies = make([]GBDCompanyInfo, 0, len(mod.AboutUs.Companies))
|
|
for _, v := range mod.AboutUs.Companies {
|
|
company := GBDCompanyInfo{
|
|
Name: v.Name, Address: v.Address, Description: v.Description,
|
|
Contact: make([]GBDContactInfo, 0, len(v.Contact)),
|
|
}
|
|
for _, c := range v.Contact {
|
|
company.Contact = append(company.Contact, GBDContactInfo{Type: c.Type, Value: c.Value})
|
|
}
|
|
data.AboutUs.Companies = append(data.AboutUs.Companies, company)
|
|
}
|
|
data.FAQ = make([]GBDFAQ, 0, len(mod.FAQ))
|
|
for _, v := range mod.FAQ {
|
|
data.FAQ = append(data.FAQ, GBDFAQ{Question: v.Question, Answer: v.Answer})
|
|
}
|
|
data.HomePageCMS = make([]GBDCMSData, 0, len(mod.HomePageCMS))
|
|
for _, v := range mod.HomePageCMS {
|
|
data.HomePageCMS = append(data.HomePageCMS, GBDCMSData{Description: v.Description, Value: v.Value})
|
|
}
|
|
data.RecruitCMS = make([]GBDCMSData, 0, len(mod.RecruitCMS))
|
|
for _, v := range mod.RecruitCMS {
|
|
data.RecruitCMS = append(data.RecruitCMS, GBDCMSData{Description: v.Description, Value: v.Value})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ─────────────────────────────────────────
|
|
// Mutation (Modify) types
|
|
// ─────────────────────────────────────────
|
|
|
|
type ModifyBasicDataReq struct {
|
|
ID string `json:"id" form:"id"`
|
|
Title *string `json:"title" bson:"title"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Banner *[]ModifyBanner `json:"banner" bson:"banner"`
|
|
HeroBanner *[]ModifyHeroBanner `json:"heroBanner" bson:"heroBanner"`
|
|
Masterpiece *[]ModifyMasterpiece `json:"masterpiece" bson:"masterpiece"`
|
|
Business *[]ModifyBusiness `json:"business" bson:"business"`
|
|
BannersDescription *string `json:"bannersDescription" bson:"bannersDescription"`
|
|
BannersDuration *int `json:"bannersDuration" bson:"bannersDuration"`
|
|
AboutUs *ModifyAboutUs `json:"aboutUs" bson:"aboutUs"`
|
|
FAQ *[]ModifyFAQ `json:"faq" bson:"faq"`
|
|
HomePageCMS *[]ModifyCMSData `json:"homePageCMS" bson:"homePageCMS"`
|
|
HomePageCMSDescription *string `json:"homePageCMSDescription" bson:"homePageCMSDescription"`
|
|
RecruitCMS *[]ModifyCMSData `json:"recruitCMS" bson:"recruitCMS"`
|
|
Tags *[]officialwebsitemod.Tag `json:"tags" bson:"tags"`
|
|
}
|
|
|
|
type ModifyBanner struct {
|
|
Name *string `json:"name" bson:"name"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Image *string `json:"image" bson:"image"`
|
|
PhoneImage *string `json:"phoneImage" bson:"phoneImage"`
|
|
Thumbnail *string `json:"thumbnail" bson:"thumbnail"`
|
|
URL *string `json:"url" bson:"url"`
|
|
}
|
|
|
|
type ModifyHeroBanner struct {
|
|
ID *primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
HeroID *primitive.ObjectID `json:"heroId" bson:"heroId"`
|
|
Name *string `json:"name" bson:"name"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Image *string `json:"image" bson:"image"`
|
|
URL *string `json:"url" bson:"url"`
|
|
Duration *int `json:"duration" bson:"duration"`
|
|
}
|
|
|
|
type ModifyMasterpiece struct {
|
|
ID *primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
|
Name *string `json:"name" bson:"name"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Cover *string `json:"cover" bson:"cover"`
|
|
Type *string `json:"type" bson:"type"`
|
|
}
|
|
|
|
type ModifyBusiness struct {
|
|
Name *string `json:"name" bson:"name"`
|
|
EnglishName *string `json:"englishName" bson:"englishName"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Cover *string `json:"cover" bson:"cover"`
|
|
Detail *[]ModifyBusinessDetail `json:"detail" bson:"detail"`
|
|
}
|
|
|
|
type ModifyBusinessDetail struct {
|
|
Cover *string `json:"cover" bson:"cover"`
|
|
Description *string `json:"description" bson:"description"`
|
|
}
|
|
|
|
type ModifyAboutUs struct {
|
|
Description *string `json:"description" bson:"description"`
|
|
Companies *[]ModifyCompanyInfo `json:"companies" bson:"companies"`
|
|
Values *string `json:"values" bson:"values"`
|
|
ValuesImg *string `json:"valuesImg" bson:"valuesImg"`
|
|
}
|
|
|
|
type ModifyCompanyInfo struct {
|
|
Name *string `json:"name" bson:"name"`
|
|
Address *string `json:"address" bson:"address"`
|
|
Description *string `json:"description" bson:"description"`
|
|
Contact *[]ModifyContactInfo `json:"contact" bson:"contact"`
|
|
}
|
|
|
|
type ModifyContactInfo struct {
|
|
Type *string `json:"type" bson:"type"`
|
|
Value *string `json:"value" bson:"value"`
|
|
}
|
|
|
|
type ModifyFAQ struct {
|
|
Question *string `json:"question" bson:"question"`
|
|
Answer *string `json:"answer" bson:"answer"`
|
|
}
|
|
|
|
type ModifyCMSData struct {
|
|
Description *string `json:"description" bson:"description"`
|
|
Value *string `json:"value" bson:"value"`
|
|
}
|
|
|
|
type UpdateBasicDataResp struct {
|
|
Count int64 `json:"count"`
|
|
}
|
|
|
|
// ─────────────────────────────────────────
|
|
// Delete types
|
|
// ─────────────────────────────────────────
|
|
|
|
type DeleteBasicDataReq struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type DeleteBasicDataResp struct {
|
|
Count int64 `json:"count"`
|
|
}
|
|
|
|
// ─────────────────────────────────────────
|
|
// toMod — Modify* → model struct
|
|
// ─────────────────────────────────────────
|
|
|
|
func (v ModifyBanner) toMod() officialwebsitemod.Banner {
|
|
return officialwebsitemod.Banner{
|
|
Name: stringOrZero(v.Name), Description: stringOrZero(v.Description),
|
|
Image: stringOrZero(v.Image), Thumbnail: stringOrZero(v.Thumbnail),
|
|
PhoneImage: stringOrZero(v.PhoneImage), URL: stringOrZero(v.URL),
|
|
}
|
|
}
|
|
|
|
func (v ModifyHeroBanner) toMod() officialwebsitemod.HeroBanner {
|
|
return officialwebsitemod.HeroBanner{
|
|
HeroID: objectIDOrZero(v.HeroID), Name: stringOrZero(v.Name), Description: stringOrZero(v.Description),
|
|
Image: stringOrZero(v.Image), URL: stringOrZero(v.URL), Duration: intOrZero(v.Duration),
|
|
}
|
|
}
|
|
|
|
func (v ModifyMasterpiece) toMod() officialwebsitemod.Masterpiece {
|
|
return officialwebsitemod.Masterpiece{
|
|
ID: objectIDOrZero(v.ID), Name: stringOrZero(v.Name), Description: stringOrZero(v.Description),
|
|
Cover: stringOrZero(v.Cover), Type: stringOrZero(v.Type),
|
|
}
|
|
}
|
|
|
|
func (v ModifyBusiness) toMod() officialwebsitemod.Business {
|
|
out := officialwebsitemod.Business{
|
|
Name: stringOrZero(v.Name), EnglishName: stringOrZero(v.EnglishName),
|
|
Description: stringOrZero(v.Description), Cover: stringOrZero(v.Cover),
|
|
}
|
|
if v.Detail != nil {
|
|
out.Detail = make([]officialwebsitemod.BusinessDetail, 0, len(*v.Detail))
|
|
for _, d := range *v.Detail {
|
|
out.Detail = append(out.Detail, d.toMod())
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyBusinessDetail) toMod() officialwebsitemod.BusinessDetail {
|
|
return officialwebsitemod.BusinessDetail{
|
|
Cover: stringOrZero(v.Cover), Description: stringOrZero(v.Description),
|
|
}
|
|
}
|
|
|
|
func (v ModifyContactInfo) toMod() officialwebsitemod.ContactInfo {
|
|
return officialwebsitemod.ContactInfo{Type: stringOrZero(v.Type), Value: stringOrZero(v.Value)}
|
|
}
|
|
|
|
func (v ModifyCompanyInfo) toMod() officialwebsitemod.CompanyInfo {
|
|
out := officialwebsitemod.CompanyInfo{
|
|
Name: stringOrZero(v.Name), Address: stringOrZero(v.Address), Description: stringOrZero(v.Description),
|
|
}
|
|
if v.Contact != nil {
|
|
out.Contact = make([]officialwebsitemod.ContactInfo, 0, len(*v.Contact))
|
|
for _, c := range *v.Contact {
|
|
out.Contact = append(out.Contact, c.toMod())
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v *ModifyAboutUs) toMod() officialwebsitemod.AboutUs {
|
|
if v == nil {
|
|
return officialwebsitemod.AboutUs{}
|
|
}
|
|
out := officialwebsitemod.AboutUs{
|
|
Description: stringOrZero(v.Description), Values: stringOrZero(v.Values), ValuesImg: stringOrZero(v.ValuesImg),
|
|
}
|
|
if v.Companies != nil {
|
|
out.Companies = make([]officialwebsitemod.CompanyInfo, 0, len(*v.Companies))
|
|
for _, c := range *v.Companies {
|
|
out.Companies = append(out.Companies, c.toMod())
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyFAQ) toMod() officialwebsitemod.FAQ {
|
|
return officialwebsitemod.FAQ{Question: stringOrZero(v.Question), Answer: stringOrZero(v.Answer)}
|
|
}
|
|
|
|
func (v ModifyCMSData) toMod() officialwebsitemod.CMSData {
|
|
return officialwebsitemod.CMSData{Description: stringOrZero(v.Description), Value: stringOrZero(v.Value)}
|
|
}
|
|
|
|
// toMod 将请求结构体转换为完整的 BasicData model
|
|
func (req *ModifyBasicDataReq) toMod() (officialwebsitemod.BasicData, error) {
|
|
if req == nil {
|
|
return officialwebsitemod.BasicData{}, stderr.CodeEmptyData
|
|
}
|
|
data := officialwebsitemod.BasicData{
|
|
Title: stringOrZero(req.Title),
|
|
Description: stringOrZero(req.Description),
|
|
BannersDescription: stringOrZero(req.BannersDescription),
|
|
BannersDuration: intOrZero(req.BannersDuration),
|
|
HomePageCMSDescription: stringOrZero(req.HomePageCMSDescription),
|
|
}
|
|
if req.AboutUs != nil {
|
|
data.AboutUs = req.AboutUs.toMod()
|
|
}
|
|
if req.Banner != nil {
|
|
data.Banner = make([]officialwebsitemod.Banner, 0, len(*req.Banner))
|
|
for _, b := range *req.Banner {
|
|
data.Banner = append(data.Banner, b.toMod())
|
|
}
|
|
}
|
|
if req.HeroBanner != nil {
|
|
data.HeroBanner = make([]officialwebsitemod.HeroBanner, 0, len(*req.HeroBanner))
|
|
for _, h := range *req.HeroBanner {
|
|
data.HeroBanner = append(data.HeroBanner, h.toMod())
|
|
}
|
|
}
|
|
if req.Masterpiece != nil {
|
|
data.Masterpiece = make([]officialwebsitemod.Masterpiece, 0, len(*req.Masterpiece))
|
|
for _, m := range *req.Masterpiece {
|
|
data.Masterpiece = append(data.Masterpiece, m.toMod())
|
|
}
|
|
}
|
|
if req.Business != nil {
|
|
data.Business = make([]officialwebsitemod.Business, 0, len(*req.Business))
|
|
for _, b := range *req.Business {
|
|
data.Business = append(data.Business, b.toMod())
|
|
}
|
|
}
|
|
if req.FAQ != nil {
|
|
data.FAQ = make([]officialwebsitemod.FAQ, 0, len(*req.FAQ))
|
|
for _, f := range *req.FAQ {
|
|
data.FAQ = append(data.FAQ, f.toMod())
|
|
}
|
|
}
|
|
if req.HomePageCMS != nil {
|
|
data.HomePageCMS = make([]officialwebsitemod.CMSData, 0, len(*req.HomePageCMS))
|
|
for _, h := range *req.HomePageCMS {
|
|
data.HomePageCMS = append(data.HomePageCMS, h.toMod())
|
|
}
|
|
}
|
|
if req.RecruitCMS != nil {
|
|
data.RecruitCMS = make([]officialwebsitemod.CMSData, 0, len(*req.RecruitCMS))
|
|
for _, r := range *req.RecruitCMS {
|
|
data.RecruitCMS = append(data.RecruitCMS, r.toMod())
|
|
}
|
|
}
|
|
if req.Tags != nil {
|
|
data.Tags = *req.Tags
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
// ─────────────────────────────────────────
|
|
// toM — Modify* → officialwebsitemod.M (Mongo update doc)
|
|
// ─────────────────────────────────────────
|
|
|
|
func (v ModifyBanner) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Name != nil {
|
|
out["name"] = *v.Name
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Image != nil {
|
|
out["image"] = *v.Image
|
|
}
|
|
if v.Thumbnail != nil {
|
|
out["thumbnail"] = *v.Thumbnail
|
|
}
|
|
if v.PhoneImage != nil {
|
|
out["phoneImage"] = *v.PhoneImage
|
|
}
|
|
if v.URL != nil {
|
|
out["url"] = *v.URL
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyHeroBanner) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.ID != nil {
|
|
out["_id"] = *v.ID
|
|
}
|
|
if v.HeroID != nil {
|
|
out["heroId"] = *v.HeroID
|
|
}
|
|
if v.Name != nil {
|
|
out["name"] = *v.Name
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Image != nil {
|
|
out["image"] = *v.Image
|
|
}
|
|
if v.URL != nil {
|
|
out["url"] = *v.URL
|
|
}
|
|
if v.Duration != nil {
|
|
out["duration"] = *v.Duration
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyMasterpiece) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.ID != nil {
|
|
out["_id"] = *v.ID
|
|
}
|
|
if v.Name != nil {
|
|
out["name"] = *v.Name
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Cover != nil {
|
|
out["cover"] = *v.Cover
|
|
}
|
|
if v.Type != nil {
|
|
out["type"] = *v.Type
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyBusiness) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Name != nil {
|
|
out["name"] = *v.Name
|
|
}
|
|
if v.EnglishName != nil {
|
|
out["englishName"] = *v.EnglishName
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Cover != nil {
|
|
out["cover"] = *v.Cover
|
|
}
|
|
if v.Detail != nil {
|
|
detail := make([]officialwebsitemod.M, 0, len(*v.Detail))
|
|
for _, d := range *v.Detail {
|
|
detail = append(detail, d.toM())
|
|
}
|
|
out["detail"] = detail
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyBusinessDetail) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Cover != nil {
|
|
out["cover"] = *v.Cover
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyContactInfo) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Type != nil {
|
|
out["type"] = *v.Type
|
|
}
|
|
if v.Value != nil {
|
|
out["value"] = *v.Value
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyCompanyInfo) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Name != nil {
|
|
out["name"] = *v.Name
|
|
}
|
|
if v.Address != nil {
|
|
out["address"] = *v.Address
|
|
}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Contact != nil {
|
|
contacts := make([]officialwebsitemod.M, 0, len(*v.Contact))
|
|
for _, c := range *v.Contact {
|
|
contacts = append(contacts, c.toM())
|
|
}
|
|
out["contact"] = contacts
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v *ModifyAboutUs) toM() officialwebsitemod.M {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
out := officialwebsitemod.M{}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Values != nil {
|
|
out["values"] = *v.Values
|
|
}
|
|
if v.ValuesImg != nil {
|
|
out["valuesImg"] = *v.ValuesImg
|
|
}
|
|
if v.Companies != nil {
|
|
companies := make([]officialwebsitemod.M, 0, len(*v.Companies))
|
|
for _, c := range *v.Companies {
|
|
companies = append(companies, c.toM())
|
|
}
|
|
out["companies"] = companies
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyFAQ) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Question != nil {
|
|
out["question"] = *v.Question
|
|
}
|
|
if v.Answer != nil {
|
|
out["answer"] = *v.Answer
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (v ModifyCMSData) toM() officialwebsitemod.M {
|
|
out := officialwebsitemod.M{}
|
|
if v.Description != nil {
|
|
out["description"] = *v.Description
|
|
}
|
|
if v.Value != nil {
|
|
out["value"] = *v.Value
|
|
}
|
|
return out
|
|
}
|
|
|
|
// toM 将请求中的非 nil 字段构造为 Mongo $set 更新文档
|
|
func (req *ModifyBasicDataReq) toM() (officialwebsitemod.M, error) {
|
|
if req == nil {
|
|
return nil, stderr.CodeEmptyData
|
|
}
|
|
set := officialwebsitemod.M{}
|
|
if req.Title != nil {
|
|
set["title"] = *req.Title
|
|
}
|
|
if req.Description != nil {
|
|
set["description"] = *req.Description
|
|
}
|
|
if req.BannersDescription != nil {
|
|
set["bannersDescription"] = *req.BannersDescription
|
|
}
|
|
if req.BannersDuration != nil {
|
|
set["bannersDuration"] = *req.BannersDuration
|
|
}
|
|
if req.HomePageCMSDescription != nil {
|
|
set["homePageCMSDescription"] = *req.HomePageCMSDescription
|
|
}
|
|
if req.Banner != nil {
|
|
banners := make([]officialwebsitemod.M, 0, len(*req.Banner))
|
|
for _, b := range *req.Banner {
|
|
banners = append(banners, b.toM())
|
|
}
|
|
set["banner"] = banners
|
|
}
|
|
if req.HeroBanner != nil {
|
|
heroBanners := make([]officialwebsitemod.M, 0, len(*req.HeroBanner))
|
|
for _, h := range *req.HeroBanner {
|
|
heroBanners = append(heroBanners, h.toM())
|
|
}
|
|
set["heroBanner"] = heroBanners
|
|
}
|
|
if req.Masterpiece != nil {
|
|
masterpiece := make([]officialwebsitemod.M, 0, len(*req.Masterpiece))
|
|
for _, m := range *req.Masterpiece {
|
|
masterpiece = append(masterpiece, m.toM())
|
|
}
|
|
set["masterpiece"] = masterpiece
|
|
}
|
|
if req.Business != nil {
|
|
businesses := make([]officialwebsitemod.M, 0, len(*req.Business))
|
|
for _, b := range *req.Business {
|
|
businesses = append(businesses, b.toM())
|
|
}
|
|
set["business"] = businesses
|
|
}
|
|
if req.AboutUs != nil {
|
|
aboutUsM := req.AboutUs.toM()
|
|
if len(aboutUsM) > 0 {
|
|
set["aboutUs"] = aboutUsM
|
|
}
|
|
}
|
|
if req.FAQ != nil {
|
|
faqs := make([]officialwebsitemod.M, 0, len(*req.FAQ))
|
|
for _, f := range *req.FAQ {
|
|
faqs = append(faqs, f.toM())
|
|
}
|
|
set["faq"] = faqs
|
|
}
|
|
if req.HomePageCMS != nil {
|
|
cms := make([]officialwebsitemod.M, 0, len(*req.HomePageCMS))
|
|
for _, h := range *req.HomePageCMS {
|
|
cms = append(cms, h.toM())
|
|
}
|
|
set["homePageCMS"] = cms
|
|
}
|
|
if req.RecruitCMS != nil {
|
|
rcms := make([]officialwebsitemod.M, 0, len(*req.RecruitCMS))
|
|
for _, r := range *req.RecruitCMS {
|
|
rcms = append(rcms, r.toM())
|
|
}
|
|
set["recruitCMS"] = rcms
|
|
}
|
|
if req.Tags != nil {
|
|
set["tags"] = *req.Tags
|
|
}
|
|
if len(set) == 0 {
|
|
return nil, nil
|
|
}
|
|
set["updatedAt"] = time.Now().UTC()
|
|
return officialwebsitemod.M{"$set": set}, nil
|
|
}
|