Skip to content

Commit

Permalink
Merge pull request #60 from cbluebird/main
Browse files Browse the repository at this point in the history
更新校园咨询
  • Loading branch information
cbluebird authored Aug 10, 2023
2 parents 177b0ef + 3715ee7 commit c9e1a32
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/config/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ func GetWebpUrlKey() string {
func SetWebpUrlKey(url string) error {
return setConfig(webpUrlKey, url)
}

func GetNoticeBackGround(name string) string {
return getConfig(name)
}
51 changes: 44 additions & 7 deletions app/controllers/funcControllers/noticeController/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ import (
"wejh-go/app/utils"
)

type Publisher struct {
Name string `json:"name"`
BackgroundImageUrl string `json:"backgroundImageUrl"`
}

type RepNotice struct {
ID int `json:"id"`
Title string `json:"title"`
Img1 interface{} `json:"img1"`
Img2 interface{} `json:"img2"`
Img3 interface{} `json:"img3"`
Content string `json:"content"`
Publisher Publisher `json:"publisher"`
}

type NoticeForm struct {
ID int `json:"id"`
Title string `json:"title"`
Expand Down Expand Up @@ -134,7 +149,23 @@ func GetNotice(c *gin.Context) {
_ = c.AbortWithError(200, apiException.ServerError)
return
}
utils.JsonSuccessResponse(c, notice)
var data []RepNotice
for _, i := range notice {
temp := RepNotice{
ID: i.ID,
Title: i.Title,
Img1: i.Img1,
Img2: i.Img2,
Img3: i.Img3,
Content: i.Content,
Publisher: Publisher{
Name: i.Publisher,
BackgroundImageUrl: getPublisherImage(i.Publisher),
},
}
data = append(data, temp)
}
utils.JsonSuccessResponse(c, data)
}

func getPublisher(c *gin.Context) *string {
Expand All @@ -144,14 +175,20 @@ func getPublisher(c *gin.Context) *string {
return nil
}
var publisher string
if user.Username == "zhforu" {
publisher = "For You 朝晖校区"
} else if user.Username == "pfforu" {
publisher = "For You 屏峰校区"
} else if user.Username == "mgsforu" {
publisher = "For You 莫干山校区"
if user.Username == "zhforu" || user.Username == "pfforu" || user.Username == "mgsforu" {
publisher = "For You工程"
} else if user.Type == models.Admin {
publisher = "Admin"
}
return &publisher
}

func getPublisherImage(publisher string) string {
var img string
if publisher == "For You工程" {
img = config.GetNoticeBackGround("ForYou_img")
} else if publisher == "Admin" {
img = config.GetNoticeBackGround("JH_img")
}
return img
}

0 comments on commit c9e1a32

Please sign in to comment.