diff --git a/internal/api/mobile/goods/cart.go b/internal/api/mobile/goods/cart.go new file mode 100644 index 0000000..f9a1bca --- /dev/null +++ b/internal/api/mobile/goods/cart.go @@ -0,0 +1,99 @@ +package goods + +import ( + "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" + "recook/internal/back" + "recook/internal/dbc" + "recook/internal/model/promotion" + "recook/internal/model/shopping_trolley" + "recook/internal/v2/model/recook/goods" + "recook/tools" +) + +type ShoppingCart struct { + BrandID uint `json:"brandID"` //品牌id + BrandLogo string `json:"brandLogo"` //品牌logo + BrandName string `json:"brandName"` //品牌名称 + ShoppingTrolleyID uint `json:"shoppingTrolleyId"` //购物车id + GoodsID uint `json:"goodsId"` //商品id + GoodsName string `json:"goodsName"` //商品名称 + Description string `json:"description"` //商品描述 + SkuName string `json:"skuName"` //商品sku名称 + Quantity uint `json:"quantity"` //购物车商品数量 + Inventory uint `json:"inventory"` // 总库存 + SalesVolume uint `json:"salesVolume"` // 总销量 + MainPhotoURL string `json:"mainPhotoUrl"` // 主图链接 + PromotionName string `json:"promotionName"` //促销名称 + OriginalPrice decimal.Decimal `json:"originalPrice"` //原价 + Price decimal.Decimal `json:"price"` //售价 + Commission decimal.Decimal `json:"commission"` //提成 + Valid bool `json:"valid"` //超出库存 + Promotion *promotion.Goods `gorm:"column:promotion" json:"promotion"` //促销 + IsImport int `json:"isImport"` //是否进口商品 + Storehouse int `json:"storehouse"` //进口商品仓库 + IsFerme int `json:"isFerme"` //是否包税 + Ferme decimal.Decimal `json:"ferme"` + HasCoin bool `json:"hasCoin"` //是否支持瑞币抵扣 + HasBalance bool `json:"hasBalance"` //是否支持余额支付 + PublishStatus uint `json:"publish_status"` //是否上下架 + CountryIcon string `json:"country_icon"` + GysId uint `json:"gys_id"` //供应商id + SecKill SecKillDetail `json:"sec_kill"` //秒杀 +} + +// QueryCartGoodsList @Title 购物车列表 +func QueryCartGoodsList(c *gin.Context) { + var p queryShoppingTrolleyListParam + if err := tools.ParseParams(&p, c); err != nil { + back.Fail(c, err.Error()) + return + } + p.UserID = 1 + if p.UserID == 0 { + back.Suc(c, "", make([]ShoppingCart, 0, 0)) + return + } + //var u user.Information + //dbc.DB.First(&u, "id = ?", p.UserID) + var trolleyList []shopping_trolley.Information + subShoppingCartList := make([]ShoppingCart, 0, 0) + dbc.DB.Preload("Brand").Preload("Goods").Preload("Sku").Order("created_at desc").Find(&trolleyList, "user_id = ?", p.UserID) + recookGoodsInfoModel := &goods.RecookGoodsInfoModel{} + valid := true + for _, t := range trolleyList { + if t.Quantity > t.Sku.Inventory { + valid = false + } + subShoppingCartList = append(subShoppingCartList, ShoppingCart{ + BrandID: t.BrandID, + BrandLogo: t.Brand.LogoURL, + BrandName: t.Brand.Name, + ShoppingTrolleyID: t.ID, + GoodsID: t.GoodsID, + GoodsName: t.Goods.GoodsName, + Description: t.Goods.Description, + SkuName: t.Sku.Name, + Quantity: t.Quantity, + Inventory: t.Sku.Inventory, + SalesVolume: t.Sku.SalesVolume, + MainPhotoURL: t.Sku.PicURL, + PromotionName: "", + OriginalPrice: t.Sku.OriginalPrice, + Price: t.Sku.DiscountPrice, + Commission: t.Sku.Commission, + Valid: valid, + Promotion: nil, + IsImport: t.Goods.IsImport, + Storehouse: t.Goods.Storehouse, + IsFerme: t.Goods.IsFerme, + Ferme: t.Sku.PurchasePrice.Mul(decimal.NewFromFloat(1.2)).Mul(decimal.NewFromFloat(0.091)).Truncate(2), + HasCoin: recookGoodsInfoModel.HasCoin(t.Goods.Storehouse), + HasBalance: recookGoodsInfoModel.HasBalance(t.Goods.Storehouse), + PublishStatus: t.Goods.PublishStatus, + CountryIcon: "", + GysId: t.Goods.VendorID, + }) + } + back.Suc(c, "操作成功", subShoppingCartList) +}