package goods // 自营商城商品管理 import ( "applet/app/admin/md" "applet/app/admin/svc/goods" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/svc" "applet/app/utils" "fmt" "github.com/gin-gonic/gin" "github.com/mcuadros/go-defaults" ) func DelMallGoods(c *gin.Context) { var idsMap map[string][]string if err := c.ShouldBindJSON(&idsMap); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } goods.DelMallGoods(c, idsMap["ids"]) } // AddMallGoods 添加商品、编辑、复制 func AddMallGoods(c *gin.Context) { var req md.AddGoodsReq // 设置默认值(结构体default标签的值) defaults.SetDefaults(&req) // 初始化翻译器 if err := utils.ValidatorTransInitZh(); err != nil { e.OutErr(c, e.ERR, fmt.Sprintf("init trans failed, err:%v\n", err)) return } err := c.ShouldBindJSON(&req) if err != nil { err = svc.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } err = goods.AddMallGoods(c, &req) if err != nil { switch err.(type) { case e.E: err1 := err.(e.E) e.OutErr(c, err1.Code, err1) return default: e.OutErr(c, e.ERR, err) return } } e.OutSuc(c, 1, nil) return } func MallGoodsDetail(c *gin.Context) { id := c.Query("id") if id == "" { id = "0" } resp, err := goods.MallGoodsDetail(c, utils.StrToInt(id)) if err != nil { e.OutErr(c, 400, err) return } e.OutSuc(c, resp, nil) return } func ChangeSaleState(c *gin.Context) { var args struct { GoodsIds []string `json:"goods_ids"` SaleState int `json:"sale_state"` } err := c.ShouldBindJSON(&args) if err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) return } if args.SaleState != 1 && args.SaleState != 2 { e.OutErr(c, e.ERR_INVALID_ARGS, "状态值不正确") return } eg := db.Db _, err = eg.In("goods_id", args.GoodsIds).Update(&model.Goods{SaleState: args.SaleState}) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err) return } e.OutSuc(c, 1, nil) }