|
|
@ -10,6 +10,9 @@ import (
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
"go-micro.dev/v4/client"
|
|
|
|
"go-micro.dev/v4/client"
|
|
|
|
"go-micro.dev/v4/web"
|
|
|
|
"go-micro.dev/v4/web"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
//"goproduct/common"
|
|
|
|
//"goproduct/common"
|
|
|
|
common "git.mashibing.com/msb_47094/shopping-comm"
|
|
|
|
common "git.mashibing.com/msb_47094/shopping-comm"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
@ -70,7 +73,7 @@ func main() {
|
|
|
|
//UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client())
|
|
|
|
//UpdateCartClient := proto.NewUpdateCartService("shop-cart", rpcServer.Client())
|
|
|
|
//ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client())
|
|
|
|
//ShowProductDetailClient := proto.NewShowProductDetailService("shop-product", rpcServer.Client())
|
|
|
|
//ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client())
|
|
|
|
//ShowDetailSkuClient := proto.NewShowDetailSkuService("shop-product", rpcServer.Client())
|
|
|
|
//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())
|
|
|
|
AddTraderClient := proto.NewAddTradeOrderService("trade-order", rpcServer.Client())
|
|
|
|
AddTraderClient := proto.NewAddTradeOrderService("trade-order", rpcServer.Client())
|
|
|
|
//UpdateTraderClient := proto.NewUpdateTradeOrderService("trade-order", rpcServer.Client())
|
|
|
|
//UpdateTraderClient := proto.NewUpdateTradeOrderService("trade-order", rpcServer.Client())
|
|
|
@ -104,10 +107,47 @@ func main() {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// c.JSON(http.StatusOK, gin.H{"updateSku-compensate": "SUCCESS", "Message": "回滚库存成功!"})
|
|
|
|
// c.JSON(http.StatusOK, gin.H{"updateSku-compensate": "SUCCESS", "Message": "回滚库存成功!"})
|
|
|
|
//})
|
|
|
|
//})
|
|
|
|
router.POST("/cartAdvanceOrder", func(c *gin.Context) {
|
|
|
|
router.GET("/cartAdvanceOrder", func(c *gin.Context) {
|
|
|
|
req := &proto.AddTradeOrderReq{}
|
|
|
|
//开始检验登录
|
|
|
|
if err := c.BindJSON(req); err != nil {
|
|
|
|
uuid := c.Request.Header["Uuid"][0]
|
|
|
|
log.Fatalln(err)
|
|
|
|
cc := common.GetInput(uuid)
|
|
|
|
|
|
|
|
out := common.SQ(cc)
|
|
|
|
|
|
|
|
sum := 0
|
|
|
|
|
|
|
|
for o := range out {
|
|
|
|
|
|
|
|
sum += o
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Token校验
|
|
|
|
|
|
|
|
//拼接请求信息
|
|
|
|
|
|
|
|
tokenReq := &proto.TokenReq{
|
|
|
|
|
|
|
|
Uuid: uuid,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//响应
|
|
|
|
|
|
|
|
tokenResp, err := GetUserTokenClient.GetUserToken(context.TODO(), tokenReq)
|
|
|
|
|
|
|
|
if err != nil || tokenResp.IsLogin == false {
|
|
|
|
|
|
|
|
log.Println("GetUserToken err : ", err)
|
|
|
|
|
|
|
|
common.RespFail(c.Writer, tokenResp, "未登录!")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//拼接请求信息
|
|
|
|
|
|
|
|
log.Println("GetUserToken success : ", tokenResp)
|
|
|
|
|
|
|
|
//结束检验登录
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始订单插入
|
|
|
|
|
|
|
|
tempStr := c.Request.FormValue("cartIds") // 12,355,666
|
|
|
|
|
|
|
|
cartIds := SplitToInt32List(tempStr, ",")
|
|
|
|
|
|
|
|
isVirtual, _ := strconv.ParseBool(c.Request.FormValue("isVirtual"))
|
|
|
|
|
|
|
|
recipientAddressId, _ := strconv.Atoi(c.Request.FormValue("recipientAddressId"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//构建tradeOrder
|
|
|
|
|
|
|
|
tradeOrder := &proto.TradeOrder{}
|
|
|
|
|
|
|
|
tradeOrder.UserId = int32(sum)
|
|
|
|
|
|
|
|
tradeOrder.CreateUser = int32(sum)
|
|
|
|
|
|
|
|
tradeOrder.OrderStatus = 1
|
|
|
|
|
|
|
|
req := &proto.AddTradeOrderReq{
|
|
|
|
|
|
|
|
CartIds: cartIds,
|
|
|
|
|
|
|
|
IsVirtual: isVirtual,
|
|
|
|
|
|
|
|
RecipientAddressId: int32(recipientAddressId),
|
|
|
|
|
|
|
|
TradeOrder: tradeOrder,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp, err = AddTraderClient.AddTradeOrder(context.TODO(), req)
|
|
|
|
resp, err = AddTraderClient.AddTradeOrder(context.TODO(), req)
|
|
|
|
fmt.Println(resp)
|
|
|
|
fmt.Println(resp)
|
|
|
@ -250,6 +290,24 @@ func (c clientWrapper) Call(ctx context.Context, req client.Request, resp interf
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 格式化页面传入的cartIds
|
|
|
|
|
|
|
|
func SplitToInt32List(str string, sep string) (int32List []int32) {
|
|
|
|
|
|
|
|
tempStr := strings.Split(str, sep)
|
|
|
|
|
|
|
|
if len(tempStr) > 0 {
|
|
|
|
|
|
|
|
for _, item := range tempStr {
|
|
|
|
|
|
|
|
if item == "" {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val, err := strconv.ParseInt(item, 10, 32)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int32List = append(int32List, int32(val))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return int32List
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewClientHystrixWrapper() client.Wrapper {
|
|
|
|
func NewClientHystrixWrapper() client.Wrapper {
|
|
|
|
return func(i client.Client) client.Client {
|
|
|
|
return func(i client.Client) client.Client {
|
|
|
|
return &clientWrapper{i}
|
|
|
|
return &clientWrapper{i}
|
|
|
|