添加购物车查询商品主图片

master
shenzhuan 2 years ago
parent ad82c2e061
commit 094936ba93

@ -51,7 +51,7 @@ func (u *ProductRepository) Page(length int32, pageIndex int32) (coun int64, pro
} }
func (u *ProductRepository) ShowProductDetail(id int32) (product *model.ProductDetail, err error) { func (u *ProductRepository) ShowProductDetail(id int32) (product *model.ProductDetail, err error) {
sql := "select p.`id` , p.`name`, p.product_type,p.category_id ,p.starting_price,\n " + sql := "select p.`id` , p.`name`, p.product_type,p.category_id ,p.starting_price, p.main_picture,\n " +
" pd.detail as detail ,GROUP_CONCAT(pp.picture SEPARATOR ',') as picture_list\n" + " pd.detail as detail ,GROUP_CONCAT(pp.picture SEPARATOR ',') as picture_list\n" +
"FROM `product` p\n" + "FROM `product` p\n" +
" left join product_detail pd on p.id = pd.product_id\n " + " left join product_detail pd on p.id = pd.product_id\n " +

@ -80,13 +80,17 @@ func main() {
} }
// //
respDetail, err := clientA.ShowProductDetail(context.TODO(), reqDetail) respDetail, err := clientA.ShowProductDetail(context.TODO(), reqDetail)
req.ProductName = respDetail.ProductDetail[0].Name if respDetail != nil {
req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture req.ProductName = respDetail.ProductDetail[0].Name
log.Println(" /ProductDetailReq get :", req) req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture
}
log.Println(" /ShowProductDetail resp :", respDetail)
//SKU //SKU
//添加购物车 远程调用服务 //添加购物车 远程调用服务
log.Println(" /AddCart req :", req)
resp, err := client.AddCart(context.TODO(), req) resp, err := client.AddCart(context.TODO(), req)
log.Println(" /increase :", resp) log.Println(" /AddCart resp :", resp)
//根据响应做输出 //根据响应做输出
if err != nil { if err != nil {
log.Println(err.Error()) log.Println(err.Error())

@ -32,10 +32,11 @@ type CartRepository struct {
func (u *CartRepository) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) { func (u *CartRepository) AddCart(req *proto.AddCartReq) (obj *model.ShoppingCart, err error) {
cart := model.ShoppingCart{ cart := model.ShoppingCart{
Number: req.Number, Number: req.Number,
ProductId: req.ProductId, ProductId: req.ProductId,
ProductSkuId: req.ProductSkuId, ProductSkuId: req.ProductSkuId,
ProductName: req.ProductName, ProductName: req.ProductName,
ProductMainPicture: req.ProductMainPicture,
} }
cart.CreateTime = time.Now() // cart.CreateTime = time.Now() //
u.mysqlDB.Create(&cart) u.mysqlDB.Create(&cart)

Loading…
Cancel
Save