使用 type WebProductService struct { } type AppProductService struct { } // Create 后台管理前端,创建商品 func (p *WebProductService) Create(param models.WebProductCreateParam) int64 { product := models.Product{ CategoryId: param.CategoryId, Title: param.Title, Description: param.Description, Price: param.Price, Amount: param.Amount, MainImage: param.MainImage, Delivery: param.Delivery, Assurance: param.Assurance, Name: param.Name, Weight: param.Weight, Brand: param.Brand, Origin: param.Origin, ShelfLife: param.ShelfLife, NetWeight: param.NetWeight, UseWay: param.UseWay, PackingWay: param.PackingWay, StorageConditions: param.StorageConditions, DetailImage: param.DetailImage, Status: param.Status, Created: common.NowTime(), } rows := global.Db.Create(&product).RowsAffected records := global.Db.First(&product, product.Id).RowsAffected if records > 0 { id := strconv.FormatUint(product.Id, 10) result, err := global.Es.Index().Index("product").Id(id).BodyJson(product).Do(ctx) if err != nil { fmt.Println(err) } return result.PrimaryTerm } return rows }
相似问题