address add bystoreid api
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/order/internal/dao"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
func GetOrderSn(orderType string, adminId int64) string {
|
||||
@@ -20,42 +21,54 @@ func GetOrderSn(orderType string, adminId int64) string {
|
||||
return sn
|
||||
}
|
||||
|
||||
func GetCartData(info map[string]int) ([]dao.ProductInfo, utils.Status) {
|
||||
keys := make([]string, utils.NumberZero, len(info))
|
||||
func GetCartData(name string, info map[int64]int64) (*product.ItemsByIdsData, utils.Status) {
|
||||
keys := make([]int64, utils.NumberZero, len(info))
|
||||
for k := range info {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
//TODO keys 查询产品
|
||||
|
||||
var products []dao.ProductInfo
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
products, err := productClient.ItemsByIds(context.Background(), &product.ItemsByIdsReq{Ids: keys})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
|
||||
products = append(products, dao.ProductInfo{
|
||||
Id: 1, Name: "Product 1",
|
||||
Price: 100,
|
||||
Number: 5,
|
||||
Images: "image1.jpg",
|
||||
Stock: 10})
|
||||
products = append(products, dao.ProductInfo{
|
||||
Id: 2, Name: "Product 2",
|
||||
Price: 100.33,
|
||||
Number: 2,
|
||||
Images: "image1.jpg",
|
||||
Stock: 1033})
|
||||
return products, utils.Ok
|
||||
}
|
||||
|
||||
func GetCartInfo(info string) (map[string]int, utils.Status) {
|
||||
var list [][]int
|
||||
func GetCartInfo(info string) (map[int64]int64, utils.Status) {
|
||||
var list [][]int64
|
||||
err := jsoniter.Unmarshal([]byte(info), &list)
|
||||
if err != nil {
|
||||
return nil, utils.ErrorJsonDataError
|
||||
}
|
||||
|
||||
m := make(map[string]int, len(list))
|
||||
m := make(map[int64]int64, len(list))
|
||||
for _, item := range list {
|
||||
if len(item) >= 2 {
|
||||
m[strconv.Itoa(item[0])] = item[1]
|
||||
m[item[0]] = item[1]
|
||||
}
|
||||
}
|
||||
return m, utils.Ok
|
||||
}
|
||||
|
||||
func GetOneData(name string, id int64) (*product.Item, utils.Status) {
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
productInfo, err := productClient.InfoById(context.Background(), &product.InfoByIdReq{Id: id})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return nil, utils.Fail
|
||||
}
|
||||
|
||||
return productInfo, utils.Ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user