Files
lone-services/services/order/internal/svc/order.go
T
2026-08-26 17:32:54 +08:00

62 lines
1.3 KiB
Go

package svc
import (
"fmt"
"lone-services/pkg/utils"
"lone-services/services/order/internal/dao"
"math/rand"
"strconv"
"time"
jsoniter "github.com/json-iterator/go"
)
func GetOrderSn(orderType string, adminId int64) string {
now := time.Now().Format("20060102150405")
r := rand.New(rand.NewSource(time.Now().UnixNano()))
rnd := r.Intn(90000000) + 10000000
sn := fmt.Sprintf("O%s%s%d%d", now, orderType, adminId, rnd)
return sn
}
func GetCartData(info map[string]int) ([]dao.ProductInfo, utils.Status) {
keys := make([]string, utils.NumberZero, len(info))
for k := range info {
keys = append(keys, k)
}
//TODO keys 查询产品
var products []dao.ProductInfo
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
err := jsoniter.Unmarshal([]byte(info), &list)
if err != nil {
return nil, utils.ErrorJsonDataError
}
m := make(map[string]int, len(list))
for _, item := range list {
if len(item) >= 2 {
m[strconv.Itoa(item[0])] = item[1]
}
}
return m, utils.Ok
}