You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.9 KiB

package diamond_show
import (
"github.com/gin-gonic/gin"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/model/diamond_show"
"recook/tools"
"strings"
)
type updateParam struct {
ShowID uint `json:"showId" validate:"min=1"`
URL string `json:"url" validate:"required"`
Color string `json:"color"`
BackgroundColor string `json:"BackgroundColor" validate:"required"`
}
func UpdateShowPic(c *gin.Context) {
var p updateParam
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
var show diamond_show.Information
err = dbc.DB.First(&show, p.ShowID).Error
if err != nil {
back.Err(c, err.Error())
return
}
// 验证颜色
if len(p.Color) > 0 && (len(p.Color) != 7 || !strings.HasPrefix(p.Color, "#")) {
back.Fail(c, "非法的颜色参数")
return
}
err = dbc.DB.Model(&show).Updates(diamond_show.Information{URL: p.URL, Color: p.BackgroundColor}).Error
if err != nil {
back.Err(c, err.Error())
return
}
back.Suc(c, "", &show)
return
}
type orderParam struct {
ShowIDList []uint `json:"showIdList"`
}
func Order(c *gin.Context) {
var p orderParam
if err := tools.Params(&p, c); err != nil {
back.Fail(c, err.Error())
return
}
var infos []diamond_show.Information
dbc.DB.Find(&infos)
list := make([]diamond_show.Information, 0, 0)
for _, v := range p.ShowIDList {
for _, v2 := range infos {
if v == v2.ID {
list = append(list, diamond_show.Information{
GoodsID: v2.GoodsID,
URL: v2.URL,
})
}
}
}
tx := dbc.DB.Begin()
{
if err := tx.Delete(diamond_show.Information{}).Error; err != nil {
back.Err(c, err.Error())
tx.Rollback()
return
}
for _, v := range list {
if err := tx.Create(&v).Error; err != nil {
back.Err(c, err.Error())
tx.Rollback()
return
}
}
}
tx.Commit()
back.Suc(c, "", list)
}