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