62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
"yintai-api/app/common/service"
|
|
)
|
|
|
|
type News struct {
|
|
ID int64
|
|
CoverImages string
|
|
CoverShow string
|
|
Count int64
|
|
CreateTime int64
|
|
UpdateTime int64
|
|
Weight int64
|
|
Pinned int64
|
|
}
|
|
|
|
func (r *News) Format() map[string]any {
|
|
res := make(map[string]any)
|
|
|
|
return res
|
|
}
|
|
|
|
type NewsPage struct {
|
|
News
|
|
NewsTranslations
|
|
CategoryID int64
|
|
CategoryName string
|
|
CategoryEn string
|
|
}
|
|
|
|
func (r *NewsPage) Format() map[string]any {
|
|
res := make(map[string]any)
|
|
images := make(map[string][]string, 0)
|
|
_ = json.Unmarshal([]byte(r.CoverImages), &images)
|
|
for k, imgs := range images {
|
|
for idx, img := range imgs {
|
|
img = service.NewQiniu().QuarterUrl(img)
|
|
images[k][idx] = img
|
|
}
|
|
}
|
|
|
|
res["id"] = r.ID
|
|
res["covers"] = images
|
|
res["covers_show"] = r.CoverShow
|
|
res["count"] = r.Count
|
|
res["create_time"] = time.Unix(r.CreateTime, 0).Format("2006-01-02 15:04:05")
|
|
res["lang"] = r.Lang
|
|
res["title"] = r.Title
|
|
res["content"] = r.Content
|
|
res["publish_time"] = r.PublishTime
|
|
res["category_id"] = r.CategoryID
|
|
res["category_name"] = r.CategoryName
|
|
res["category_name_en"] = r.CategoryEn
|
|
res["weight"] = r.Weight
|
|
res["pinned"] = r.Pinned
|
|
|
|
return res
|
|
}
|