|
|
|
@ -63,32 +63,23 @@ func main() {
|
|
|
|
|
GetUserTokenClient := proto.NewGetUserTokenService("shop-user", rpcServer.Client())
|
|
|
|
|
UpdateSkuClient := proto.NewUpdateSkuService("shop-product", rpcServer.Client())
|
|
|
|
|
|
|
|
|
|
//分页查询商品列表
|
|
|
|
|
//添加购物车
|
|
|
|
|
router.GET("/increase", func(c *gin.Context) {
|
|
|
|
|
// "number": 0,
|
|
|
|
|
// "productId": 0,
|
|
|
|
|
// "productSkuId": 0
|
|
|
|
|
number, _ := strconv.Atoi(c.Request.FormValue("number"))
|
|
|
|
|
productId, _ := strconv.Atoi(c.Request.FormValue("productId"))
|
|
|
|
|
productSkuId, _ := strconv.Atoi(c.Request.FormValue("productSkuId"))
|
|
|
|
|
uuid := c.Request.Header["Uuid"][0]
|
|
|
|
|
|
|
|
|
|
//intUuid, _ := strconv.Atoi(uuid)
|
|
|
|
|
// intput := "101010101110110"
|
|
|
|
|
cc := common.GetInput(uuid)
|
|
|
|
|
out := common.SQ(cc)
|
|
|
|
|
sum := 0
|
|
|
|
|
for o := range out {
|
|
|
|
|
sum += o
|
|
|
|
|
}
|
|
|
|
|
//fmt.Println(sum)
|
|
|
|
|
|
|
|
|
|
//Token校验
|
|
|
|
|
//拼接请求信息
|
|
|
|
|
tokenReq := &proto.TokenReq{
|
|
|
|
|
Uuid: uuid,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//响应
|
|
|
|
|
tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq)
|
|
|
|
|
//拼接请求信息
|
|
|
|
@ -107,26 +98,29 @@ func main() {
|
|
|
|
|
ProductSkuId: int32(productSkuId),
|
|
|
|
|
UserId: int32(sum),
|
|
|
|
|
}
|
|
|
|
|
resp, err := client.AddCart(context.TODO(), req)
|
|
|
|
|
resp := &proto.AddCartResp{}
|
|
|
|
|
//商品详情
|
|
|
|
|
reqDetail := &proto.ProductDetailReq{
|
|
|
|
|
Id: int32(productId),
|
|
|
|
|
}
|
|
|
|
|
respDetail, err := ShowProductDetailClient.ShowProductDetail(context.TODO(), reqDetail)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println("ShowProductDetail err : ", err)
|
|
|
|
|
common.RespFail(c.Writer, respErr, "查询商品详情失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if respDetail != nil {
|
|
|
|
|
req.ProductName = respDetail.ProductDetail[0].Name
|
|
|
|
|
req.ProductMainPicture = respDetail.ProductDetail[0].MainPicture
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println(" /ShowProductDetail resp :", respDetail)
|
|
|
|
|
//log.Println(" /ShowProductDetail resp :", respDetail)
|
|
|
|
|
//SKU详情
|
|
|
|
|
reqDetail.Id = req.ProductSkuId
|
|
|
|
|
respSkuDetail, err := ShowDetailSkuClient.ShowDetailSku(context.TODO(), reqDetail)
|
|
|
|
|
|
|
|
|
|
log.Println(" /ShowDetailSku resp :", respSkuDetail)
|
|
|
|
|
|
|
|
|
|
//log.Println(" /ShowDetailSku resp :", respSkuDetail)
|
|
|
|
|
//添加购物车 远程调用服务
|
|
|
|
|
log.Println(" /AddCart req :", req)
|
|
|
|
|
//log.Println(" /AddCart req :", req)
|
|
|
|
|
|
|
|
|
|
if respSkuDetail.ProductSku[0].Stock < req.Number {
|
|
|
|
|
common.RespFail(c.Writer, &proto.AddCartResp{}, "库存不足,添加失败")
|
|
|
|
@ -139,21 +133,25 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
respUpdate, err := UpdateSkuClient.UpdateSku(context.TODO(), updateSkuReq)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(" /UpdateSkuClient resp :", err)
|
|
|
|
|
log.Println(" /UpdateSku err :", err)
|
|
|
|
|
common.RespFail(c.Writer, resp, "修改库存失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
log.Println(" /UpdateSkuClient resp :", respUpdate.IsSuccess)
|
|
|
|
|
|
|
|
|
|
resp.ProductSkuSimple = respSkuDetail.ProductSku[0]
|
|
|
|
|
resp.ProductSimple = respDetail.ProductDetail[0]
|
|
|
|
|
|
|
|
|
|
log.Println(" /AddCart resp :", resp)
|
|
|
|
|
|
|
|
|
|
//开始增加购物车
|
|
|
|
|
resp, err = client.AddCart(context.TODO(), req)
|
|
|
|
|
//根据响应做输出
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err.Error())
|
|
|
|
|
common.RespFail(c.Writer, resp, "请求失败")
|
|
|
|
|
log.Println("addCart err ", err)
|
|
|
|
|
updateSkuReq.ProductSku.Stock += req.Number
|
|
|
|
|
_, err = UpdateSkuClient.UpdateSku(context.TODO(), updateSkuReq)
|
|
|
|
|
log.Println("rollback sku is Err :", err)
|
|
|
|
|
common.RespFail(c.Writer, resp, "添加购物车失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp.ProductSkuSimple = respSkuDetail.ProductSku[0]
|
|
|
|
|
resp.ProductSimple = respDetail.ProductDetail[0]
|
|
|
|
|
log.Println(" /AddCart resp :", resp)
|
|
|
|
|
////writer data message row total field
|
|
|
|
|
common.RespOK(c.Writer, resp, "请求成功")
|
|
|
|
|
})
|
|
|
|
|