Merge branch 'feature/mhw-v1.01' of gitee.com:fusenpack/fusenapi into feature/mhw-v1.01
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/clients"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@@ -20,6 +21,15 @@ type EnvConfig struct {
|
||||
NamespaceId string `yaml:"namespace"`
|
||||
DataId string `yaml:"dataid"`
|
||||
Group string `yaml:"group"`
|
||||
ProxyServer struct {
|
||||
KeyFile string `yaml:"key"`
|
||||
PemFile string `yaml:"pem"`
|
||||
} `yaml:"proxyserver"`
|
||||
|
||||
ServerBackend struct {
|
||||
KeyFile string `yaml:"key"`
|
||||
PemFile string `yaml:"pem"`
|
||||
} `yaml:"serverbackend"`
|
||||
}
|
||||
|
||||
var optPathDirs = []string{"/opt", "./", "../", "../../"}
|
||||
@@ -63,7 +73,7 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId, data string)) string {
|
||||
func StartNacosConfig(configFile string, cfg any, OnChange func(namespace, group, dataId, data string)) {
|
||||
env := GetEnvCofing()
|
||||
|
||||
// 创建serverConfig
|
||||
@@ -136,9 +146,40 @@ func StartNacosConfig(configFile string, OnChange func(namespace, group, dataId,
|
||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||
}
|
||||
|
||||
log.Println("加载成功:", cfgYaml)
|
||||
var selfConfig map[string]interface{} = make(map[string]interface{})
|
||||
err = yaml.Unmarshal([]byte(content), &selfConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||
}
|
||||
|
||||
return content
|
||||
content, err = configClient.GetConfig(vo.ConfigParam{
|
||||
DataId: "common",
|
||||
Group: env.Group,
|
||||
OnChange: nil,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||
}
|
||||
|
||||
var commonConfig map[string]interface{} = make(map[string]interface{})
|
||||
err = yaml.Unmarshal([]byte(content), &commonConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||
}
|
||||
|
||||
for k, v := range commonConfig {
|
||||
selfConfig[k] = v
|
||||
}
|
||||
|
||||
data, err := yaml.Marshal(selfConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get config from Nacos: %v", err)
|
||||
}
|
||||
|
||||
log.Print("加载成功: ", cfgYaml, "\n环境: ", env.Group, "\n", string(data))
|
||||
err = conf.LoadFromYamlBytes(data, cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get config content from Nacos: %v", err)
|
||||
}
|
||||
// log.Println(content)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,33 @@ package fsconfig_test
|
||||
import (
|
||||
"fusenapi/utils/fsconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func TestCase1(t *testing.T) {
|
||||
fsconfig.StartNacosConfig("auth.yaml", nil)
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
|
||||
ReplicaId uint64
|
||||
|
||||
MainAddress string
|
||||
WebsocketAddr string
|
||||
|
||||
OAuth struct {
|
||||
Google struct {
|
||||
Appid string
|
||||
Secret string
|
||||
}
|
||||
|
||||
Facebook struct {
|
||||
Appid string
|
||||
Secret string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCase1(t *testing.T) {
|
||||
var c Config
|
||||
fsconfig.StartNacosConfig("auth.yaml", &c, nil)
|
||||
}
|
||||
|
||||
44
utils/shopping_cart/caculate_cart_price.go
Normal file
44
utils/shopping_cart/caculate_cart_price.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package shopping_cart
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/step_price"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 计算价格
|
||||
func CaculateCartPrice(purchaseQuantity int64, productPrice *gmodel.FsProductPrice, fittingPrice int64) (ItemPrice, totalPrice int64, stepNum, stepPrice []int, err error) {
|
||||
//阶梯数量切片
|
||||
stepNum, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
//请求的数量
|
||||
reqPurchaseQuantity := purchaseQuantity
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*productPrice.EachBoxNum)))
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
//如果有配件,单价也要加入配件价格
|
||||
itemPrice += fittingPrice
|
||||
//单个购物车总价
|
||||
totalPrice = itemPrice * reqPurchaseQuantity
|
||||
return itemPrice, totalPrice, stepNum, stepPrice, nil
|
||||
}
|
||||
@@ -10,9 +10,8 @@ type DataTransferData struct {
|
||||
|
||||
// websocket接受要云渲染处理的数据
|
||||
type RenderImageReqMsg struct {
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
OnlyReturnCombineImage bool `json:"only_return_combine_image"` //是否只返回刀版图
|
||||
RenderData RenderData `json:"render_data"`
|
||||
RenderId string `json:"render_id"` //渲染id
|
||||
RenderData RenderData `json:"render_data"` //渲染主要参数
|
||||
}
|
||||
type RenderData struct {
|
||||
TemplateTag string `json:"template_tag"` //模板标签(必须)
|
||||
@@ -25,7 +24,6 @@ type RenderData struct {
|
||||
Address string `json:"address"` //地址(可选)
|
||||
Phone string `json:"phone"` //电话(可选)
|
||||
Qrcode string `json:"qrcode"` //二维码(可选)
|
||||
ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选)
|
||||
UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值)
|
||||
GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user