package admin import ( "zhiyuan/pkg/app" "zhiyuan/pkg/utils" "zhiyuan/services/form" "zhiyuan/services/shop" "github.com/gin-gonic/gin" ) func ShopList(c *gin.Context) { type Shop struct { ID int `json:"id"` ShopName string `json:"shop_name"` CollectInfo string `json:"collect_info"` CreatedAt string `json:"created_at"` } shopList := make([]*Shop, 0) if _, err := shop.GetList(nil, nil, &shopList); err != nil { app.Error(c, err.Error()) return } for k, v := range shopList { v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD") shopList[k] = v } app.Success(c, shopList) } func ShopAdd(c *gin.Context) { var form form.ShopAdd if app.Bind(c, &form) != nil { return } id, err := shop.Add(form) if err != nil { app.Error(c, err.Error()) return } app.Success(c, gin.H{"id": id}) } func ShopEdit(c *gin.Context) { id := utils.StrTo(c.Param("id")).MustInt() if id <= 0 { app.ErrorMsg(c, "门店id有误", nil) return } var form form.ShopAdd if app.Bind(c, &form) != nil { return } if _, err := shop.Edit(form, id); err != nil { app.Error(c, err.Error()) return } app.Success(c, nil) }