Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
046c31c898
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/fssql"
|
||||
|
@ -68,6 +69,7 @@ func InheritGuestIdResource(tx *gorm.DB, userId, guestId int64, afterDo func(txR
|
|||
Where("guest_id = ?", guestId).
|
||||
UpdateColumn("user_id", userId).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logx.Info(err, "找到user_id1 afterDo")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -76,13 +78,16 @@ func InheritGuestIdResource(tx *gorm.DB, userId, guestId int64, afterDo func(txR
|
|||
UpdateColumn("user_id", userId).Error
|
||||
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logx.Info(err, "找到user_id1 afterDo")
|
||||
return err
|
||||
}
|
||||
|
||||
err = txUserInfo.
|
||||
Where("guest_id = ?", guestId).
|
||||
UpdateColumn("user_id", userId).Error
|
||||
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
logx.Info(err, "找到user_id1 afterDo")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +174,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
var err error
|
||||
|
||||
err = tx.Model(&FsUser{}).Where("email = ?", token.Email).Take(user).Error
|
||||
log.Println("success", token.TraceId)
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
||||
FirstName := token.Extend["first_name"].(string)
|
||||
|
@ -189,9 +195,11 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
return err
|
||||
}
|
||||
|
||||
log.Println("success", token.TraceId)
|
||||
|
||||
// 继承guest_id的资源表
|
||||
err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error {
|
||||
|
||||
log.Println("success", token.TraceId)
|
||||
userProfile := &UserProfile{
|
||||
FirstName: FirstName,
|
||||
LastName: LastName,
|
||||
|
@ -216,7 +224,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
|
||||
err = txUserInfo.Where("module = 'profile' and user_id = ?", uinfo.UserId).Take(nil).Error
|
||||
// txUserInfo.Statement.Table
|
||||
|
||||
log.Println(err, "找到user_id1")
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
err = txUserInfo.Create(uinfo).Error
|
||||
|
@ -225,6 +233,7 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT
|
|||
}
|
||||
}
|
||||
} else {
|
||||
log.Println("找到user_id2")
|
||||
err = fssql.MetadataModulePATCH(txUserInfo, "profile", FsUserInfo{}, metadata, "user_id = ?", *uinfo.UserId)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
single_server_name=$1
|
||||
|
||||
go mod tidy
|
||||
go mod vendor
|
||||
|
||||
|
@ -8,16 +10,18 @@ run_server() {
|
|||
server_name=$1
|
||||
echo "Running $server_name"
|
||||
|
||||
|
||||
|
||||
# 如果之前存在相同名字的 screen 会话,先将其终止
|
||||
existing_session=$(screen -ls | grep -w "$server_name")
|
||||
if [ -n "$existing_session" ]; then
|
||||
echo "Terminating existing screen session for $server_name"
|
||||
screen -S "$server_name" -X quit
|
||||
fi
|
||||
|
||||
# 导航到相应的目录
|
||||
# 导航到相应的目录
|
||||
cd server/$server_name
|
||||
go build -linkshared
|
||||
|
||||
[ -f .gitignore ] || echo $server_name > .gitignore
|
||||
# 使用 screen 运行 go run <server_name>.go
|
||||
screen -dmS $server_name -L ./$server_name
|
||||
|
@ -29,14 +33,17 @@ run_server() {
|
|||
find /tmp/go-build* -mmin +5 -exec rm -rf {} +
|
||||
find /tmp/go-link* -mmin +5 -exec rm -rf {} +
|
||||
|
||||
# 列出所有服务器目录
|
||||
server_dirs=() # 初始化一个空数组
|
||||
|
||||
for dir in server/*/ ; do # 遍历 "server/" 下的所有子目录
|
||||
dir=${dir%*/} # 删除末尾的 "/"
|
||||
dir=${dir##*/} # 删除开头的 "server/"
|
||||
server_dirs+=("$dir") # 添加到数组
|
||||
done
|
||||
if [ -n "$single_server_name" ]; then
|
||||
server_dirs=("$single_server_name")
|
||||
else
|
||||
for dir in server/*/ ; do # 遍历 "server/" 下的所有子目录
|
||||
dir=${dir%*/} # 删除末尾的 "/"
|
||||
dir=${dir##*/} # 删除开头的 "server/"
|
||||
server_dirs+=("$dir") # 添加到数组
|
||||
done
|
||||
fi
|
||||
|
||||
# 在每个服务器目录下运行相应的 go 程序
|
||||
for server_dir in "${server_dirs[@]}"; do
|
||||
|
|
|
@ -97,7 +97,7 @@ func CommonNotify(WebsocketAddr, wid string, event *wevent.WebsocketEvent) error
|
|||
func (l *UserEmailConfirmationLogic) UserEmailConfirmation(req *types.RequestEmailConfirmation, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
logx.Error("找到user_id1 UserEmailConfirmation")
|
||||
switch auth.OperateType(req.OpType) {
|
||||
case auth.OpTypeRegister:
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
//TODO: 可以优化, 合并模块
|
||||
var condUser string
|
||||
switch userinfo.GetIdType() {
|
||||
case auth.IDTYPE_User:
|
||||
|
@ -120,13 +121,13 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
cond := fmt.Sprintf("module = '%s' and %s", moduleName, condUser)
|
||||
|
||||
if mquery, ok := mquerys[mtable]; ok {
|
||||
mquery.ModuleQuery[strings.Join(mlist[2:], ",")] = struct{}{}
|
||||
mquery.ModuleQuery[strings.Join(mlist[2:], ".")] = struct{}{}
|
||||
} else {
|
||||
mquery := &ModuleQuery{
|
||||
TableName: tname,
|
||||
ModuleName: mtable + "." + moduleName,
|
||||
Cond: cond,
|
||||
ModuleQuery: map[string]struct{}{strings.Join(mlist[2:], ","): {}}}
|
||||
ModuleQuery: map[string]struct{}{strings.Join(mlist[2:], "."): {}}}
|
||||
mquerys[mtable] = mquery
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +135,6 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
for _, mquery := range mquerys {
|
||||
|
||||
sqlstr := fmt.Sprintf("select id, module, %s as querydata from %s where %s order by ctime DESC limit 1", mquery.EncodeQuery("metadata"), mquery.TableName, mquery.Cond)
|
||||
|
||||
raw := l.svcCtx.MysqlConn.Raw(sqlstr)
|
||||
|
||||
if raw.Error != nil {
|
||||
|
|
|
@ -17,46 +17,57 @@ import (
|
|||
func TestMain(t *testing.T) {
|
||||
|
||||
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
|
||||
condUser := "user_id = 105"
|
||||
condUser := "user_id = 134"
|
||||
|
||||
// var condUser string
|
||||
// switch userinfo.GetIdType() {
|
||||
// case auth.IDTYPE_User:
|
||||
// condUser = fmt.Sprintf("user_id = %d", userinfo.UserId)
|
||||
// case auth.IDTYPE_Guest:
|
||||
// condUser = fmt.Sprintf("guest_id = %d", userinfo.GuestId)
|
||||
// default:
|
||||
// condUser = "user_id = 0 and guest_id = 0"
|
||||
// }
|
||||
|
||||
var mquerys map[string]*ModuleQuery = make(map[string]*ModuleQuery)
|
||||
var metadict map[string]any = make(map[string]any)
|
||||
|
||||
for _, module := range []string{"material.logo.logo_url", "userinfo.profile"} {
|
||||
if !check.CheckModuleQuery(module) {
|
||||
for _, module := range []string{"userinfo.profile", "userinfo.profile.logo_selected", "userinfo.profile.logo_selected.logo_url1"} {
|
||||
|
||||
if !check.CheckModuleQuery(module) {
|
||||
return
|
||||
}
|
||||
|
||||
mlist := strings.Split(module, ".")
|
||||
if len(mlist) < 2 {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
mtable := mlist[0]
|
||||
tname, ok := ModuleTable[mtable]
|
||||
if !ok {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
moduleName := mlist[1]
|
||||
cond := fmt.Sprintf("module = '%s' and %s", moduleName, condUser)
|
||||
|
||||
if mquery, ok := mquerys[mtable]; ok {
|
||||
mquery.ModuleQuery[strings.Join(mlist[2:], ",")] = struct{}{}
|
||||
mquery.ModuleQuery[strings.Join(mlist[2:], ".")] = struct{}{}
|
||||
} else {
|
||||
mquery := &ModuleQuery{
|
||||
TableName: tname,
|
||||
Cond: cond,
|
||||
ModuleName: mtable + "." + moduleName,
|
||||
ModuleQuery: map[string]struct{}{strings.Join(mlist[2:], ","): {}}}
|
||||
Cond: cond,
|
||||
ModuleQuery: map[string]struct{}{strings.Join(mlist[2:], "."): {}}}
|
||||
mquerys[mtable] = mquery
|
||||
}
|
||||
}
|
||||
|
||||
for _, mquery := range mquerys {
|
||||
|
||||
sqlstr := fmt.Sprintf("select id, module, %s as querydata from %s where %s order by ctime dec limit 1", mquery.EncodeQuery("metadata"), mquery.TableName, mquery.Cond)
|
||||
|
||||
log.Println(mquery.ModuleName, mquery.ModuleQuery)
|
||||
sqlstr := fmt.Sprintf("select id, module, %s as querydata from %s where %s order by ctime DESC limit 1", mquery.EncodeQuery("metadata"), mquery.TableName, mquery.Cond)
|
||||
raw := conn.Raw(sqlstr)
|
||||
|
||||
if raw.Error != nil {
|
||||
|
@ -64,10 +75,11 @@ func TestMain(t *testing.T) {
|
|||
continue
|
||||
} else {
|
||||
logx.Error(raw.Error)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var info map[string]any = make(map[string]any)
|
||||
var info map[string]any
|
||||
err := raw.Scan(&info).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
continue
|
||||
|
@ -78,11 +90,13 @@ func TestMain(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
logx.Error(info)
|
||||
|
||||
queryjson, ok := info["querydata"].(string)
|
||||
if !ok {
|
||||
return
|
||||
for k, v := range mquery.EncodeEmpty() {
|
||||
metadict[k] = v
|
||||
}
|
||||
continue
|
||||
// return resp.SetStatusWithMessage(basic.CodeDbSqlErr, mquery.ModuleName)
|
||||
}
|
||||
|
||||
var querydata map[string]any = make(map[string]any)
|
||||
|
@ -97,6 +111,54 @@ func TestMain(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// 隐含白板用户逻辑
|
||||
if v, ok := metadict["userinfo.profile"]; ok {
|
||||
|
||||
if v == nil {
|
||||
|
||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||
log.Println(info)
|
||||
metadict["userinfo.profile"] = info
|
||||
// log.Println(metadict)
|
||||
} else {
|
||||
profileDict := v.(map[string]any)
|
||||
if _, ok := profileDict["logo_selected"]; !ok {
|
||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||
profileDict["logo_selected"] = info["logo_selected"]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
||||
if v == nil {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
log.Println(metadict)
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
|
||||
|
||||
qname := strings.Split(moduleQuery, ".")
|
||||
queryAsName := qname[len(qname)-1]
|
||||
sqlstr := fmt.Sprintf(
|
||||
"select JSON_EXTRACT(metadata,'$.%s') as %s from %s where module = '%s' and user_id = 0 and guest_id = 0 order by ctime DESC limit 1",
|
||||
moduleQuery, // logo_selected
|
||||
queryAsName, // logo_selected
|
||||
tname, // fs_user_info
|
||||
module, // profile
|
||||
)
|
||||
raw := conn.Raw(sqlstr)
|
||||
var info map[string]any
|
||||
err := raw.Scan(&info).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
logx.Error(err)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func TestCaseJSON_EXTRACT(t *testing.T) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
|
@ -54,6 +53,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
//获取购物车列表
|
||||
carts, _, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
Ids: cartIds,
|
||||
Fields: "id,size_id,product_id,fitting_id",
|
||||
UserId: userinfo.UserId,
|
||||
Page: 1,
|
||||
Limit: len(cartIds),
|
||||
|
@ -65,46 +65,6 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
if len(carts) < len(req.CalculateList) {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "please refresh page for the shopping cart has changed!!")
|
||||
}
|
||||
//**************获取相关数据校验变更************
|
||||
var (
|
||||
mapSize = make(map[int64]gmodel.FsProductSize)
|
||||
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
||||
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
||||
mapSizePrice = make(map[string]gmodel.FsProductPrice)
|
||||
mapProduct = make(map[int64]gmodel.FsProduct)
|
||||
mapResourceMetadata = make(map[string]interface{})
|
||||
)
|
||||
//获取相关信息
|
||||
err = NewGetCartsLogic(l.ctx, l.svcCtx).GetRelationInfo(GetRelationInfoReq{
|
||||
Carts: carts,
|
||||
MapSize: mapSize,
|
||||
MapModel: mapModel,
|
||||
MapTemplate: mapTemplate,
|
||||
MapSizePrice: mapSizePrice,
|
||||
MapProduct: mapProduct,
|
||||
MapResourceMetadata: mapResourceMetadata,
|
||||
})
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
//定义map收集变更信息
|
||||
mapCartChange := make(map[int64]string)
|
||||
mapSnapshot := make(map[int64]gmodel.CartSnapshot)
|
||||
//校验购物车数据是否变更
|
||||
err = l.svcCtx.Repositories.NewShoppingCart.VerifyShoppingCartSnapshotDataChange(repositories.VerifyShoppingCartSnapshotDataChangeReq{
|
||||
Carts: carts,
|
||||
MapSize: mapSize,
|
||||
MapModel: mapModel,
|
||||
MapTemplate: mapTemplate,
|
||||
MapCartChange: mapCartChange,
|
||||
MapSnapshot: mapSnapshot,
|
||||
MapProduct: mapProduct,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "system err:failed to check shopping cart change data")
|
||||
}
|
||||
//**************************
|
||||
sizeIds := make([]int64, 0, len(carts))
|
||||
productIds := make([]int64, 0, len(carts))
|
||||
fittingIds := make([]int64, 0, len(carts))
|
||||
|
@ -148,10 +108,6 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
}
|
||||
//请求的数量
|
||||
reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity
|
||||
//传入数量是<= 0则取数据库的
|
||||
if reqPurchaseQuantity <= 0 {
|
||||
reqPurchaseQuantity = *cart.PurchaseQuantity
|
||||
}
|
||||
isSelected := int64(0)
|
||||
if mapCalculateQuantity[cart.Id].IsSelected {
|
||||
isSelected = 1
|
||||
|
@ -173,16 +129,16 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
}
|
||||
calculateResultList = append(calculateResultList, types.CalculateResultItem{
|
||||
CartId: cart.Id,
|
||||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
|
||||
ItemPrice: format.CentitoDollar(itemPrice, 3),
|
||||
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
|
||||
})
|
||||
updData := &gmodel.FsShoppingCart{
|
||||
PurchaseQuantity: &reqPurchaseQuantity,
|
||||
IsSelected: &isSelected,
|
||||
}
|
||||
//如果是没有变更且是选中则累加总价
|
||||
if _, ok = mapCartChange[cart.Id]; !ok && isSelected == 1 {
|
||||
//如果是选中则累加总价
|
||||
if isSelected == 1 {
|
||||
subTotalPrice += totalPrice
|
||||
updData.IsSelected = &isSelected
|
||||
}
|
||||
//更新购物车购买数量
|
||||
if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil {
|
||||
|
@ -196,7 +152,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error())
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{
|
||||
SubTotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(subTotalPrice)),
|
||||
SubTotalPrice: format.CentitoDollarWithNoHalfAdjust(subTotalPrice, 2),
|
||||
CalculateResultList: calculateResultList,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -44,23 +44,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
if req.CurrentPage <= 0 {
|
||||
req.CurrentPage = constants.DEFAULT_PAGE
|
||||
}
|
||||
//获取全部购物车id
|
||||
allCratIds, count, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
UserId: userinfo.UserId,
|
||||
Fields: "id",
|
||||
Sort: "id DESC",
|
||||
Page: 1,
|
||||
Limit: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to get your shopping carts")
|
||||
}
|
||||
ids := make([]int64, 0, count)
|
||||
for _, v := range allCratIds {
|
||||
ids = append(ids, v.Id)
|
||||
}
|
||||
limit := 10
|
||||
limit := 300
|
||||
//获取用户购物车列表
|
||||
carts, total, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{
|
||||
UserId: userinfo.UserId,
|
||||
|
@ -139,24 +123,17 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
}
|
||||
}
|
||||
//计算价格
|
||||
itemPrice, totalPrice, stepNum, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice)
|
||||
itemPrice, totalPrice, _, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
//获取阶梯数量
|
||||
stepQuantityList := make([]int64, 0, 20)
|
||||
tmpMinBuyNum := *sizePrice.MinBuyNum
|
||||
for tmpMinBuyNum < (int64(stepNum[len(stepNum)-1]) + 5) {
|
||||
//阶梯数
|
||||
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
|
||||
stepQuantityList = append(stepQuantityList, tmpQuantity)
|
||||
tmpMinBuyNum++
|
||||
}
|
||||
//尺寸信息
|
||||
sizeCapacity := snapShot.SizeInfo.Capacity
|
||||
if sizeInfo, ok := mapSize[*cart.SizeId]; ok {
|
||||
sizeCapacity = *sizeInfo.Capacity
|
||||
}
|
||||
//配件信息
|
||||
fittingName := snapShot.FittingInfo.FittingName
|
||||
if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||
fittingName = *fittingInfo.Name
|
||||
|
@ -164,7 +141,9 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
productCover := "" //产品封面图
|
||||
productName := snapShot.ProductInfo.ProductName
|
||||
productSn := snapShot.ProductInfo.ProductSn
|
||||
//产品封面图资源元数据
|
||||
var productCoverMetadata interface{}
|
||||
//产品信息
|
||||
if productInfo, ok := mapProduct[*cart.ProductId]; ok {
|
||||
productCover = *productInfo.Cover
|
||||
productName = *productInfo.Title
|
||||
|
@ -194,8 +173,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
FittingId: *cart.FittingId,
|
||||
FittingName: fittingName,
|
||||
},
|
||||
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
|
||||
ItemPrice: format.CentitoDollar(itemPrice, 3),
|
||||
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
|
||||
DiyInformation: types.DiyInformation{
|
||||
Phone: snapShot.UserDiyInformation.Phone,
|
||||
Address: snapShot.UserDiyInformation.Address,
|
||||
|
@ -203,17 +182,18 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
Qrcode: snapShot.UserDiyInformation.Qrcode,
|
||||
Slogan: snapShot.UserDiyInformation.Slogan,
|
||||
},
|
||||
PurchaseQuantity: *cart.PurchaseQuantity,
|
||||
StepNum: stepQuantityList,
|
||||
IsInvalid: false,
|
||||
InvalidDescription: "",
|
||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||
IsSelected: *cart.IsSelected > 0,
|
||||
PurchaseQuantity: *cart.PurchaseQuantity,
|
||||
MinPurchaseQuantity: *sizePrice.EachBoxNum * (*sizePrice.MinBuyNum),
|
||||
StepPurchaseQuantity: *sizePrice.EachBoxNum,
|
||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||
IsSelected: *cart.IsSelected > 0,
|
||||
}
|
||||
//是否有失效的
|
||||
if description, ok := mapCartChange[cart.Id]; ok {
|
||||
item.IsInvalid = true
|
||||
item.InvalidDescription = description
|
||||
//失效了返回给前端也是不选中
|
||||
item.IsSelected = false
|
||||
}
|
||||
list = append(list, item)
|
||||
}
|
||||
|
@ -224,8 +204,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
|||
CurrentPage: req.CurrentPage,
|
||||
PerPage: limit,
|
||||
},
|
||||
AllCartIdArray: ids,
|
||||
CartList: list,
|
||||
CartList: list,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -34,25 +34,25 @@ type GetCartsReq struct {
|
|||
}
|
||||
|
||||
type GetCartsRsp struct {
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
}
|
||||
|
||||
type CartItem struct {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
IsSelected bool `json:"is_selected"` //是否选中
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
|
||||
StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
IsSelected bool `json:"is_selected"` //是否选中
|
||||
}
|
||||
|
||||
type ProductInfo struct {
|
||||
|
|
|
@ -40,8 +40,6 @@ func pushCommonNotifyCache(data commonConnectionNotFoundDataCacheChanItem) {
|
|||
select {
|
||||
case commonConnectionNotFoundDataCacheChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 50): //超50ms就丢弃
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,8 +164,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
|||
go ws.consumeOutChanData()
|
||||
//消费入口数据
|
||||
go ws.consumeInChanData()
|
||||
//操作连接中渲染任务的增加/删除
|
||||
//go ws.operationRenderTask()
|
||||
//消费渲染缓冲队列
|
||||
go ws.consumeRenderImageData()
|
||||
//心跳
|
||||
|
@ -194,8 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
|
|||
userId: userInfo.UserId,
|
||||
guestId: userInfo.GuestId,
|
||||
extendRenderProperty: extendRenderProperty{
|
||||
renderChan: make(chan []byte, renderChanLen),
|
||||
renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度
|
||||
renderChan: make(chan []byte, renderChanLen),
|
||||
},
|
||||
}
|
||||
//保存连接
|
||||
|
@ -400,9 +397,6 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
|
|||
return
|
||||
case w.outChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 50): //阻塞超过50ms丢弃
|
||||
logx.Error("failed to send to out chan,time expired,data:", string(data))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,9 +407,6 @@ func (w *wsConnectItem) sendToInChan(data []byte) {
|
|||
return
|
||||
case w.inChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 200): //200豪秒超时丢弃,说明超过消费速度了
|
||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW, "send message is too frequent,the message is ignore by system:"+string(data)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
var (
|
||||
//每个websocket渲染任务缓冲队列长度默认值
|
||||
renderChanLen = 500
|
||||
renderChanLen = 200
|
||||
)
|
||||
|
||||
// 渲染处理器
|
||||
|
@ -30,20 +30,17 @@ type renderProcessor struct {
|
|||
|
||||
// 云渲染属性
|
||||
type extendRenderProperty struct {
|
||||
renderChan chan []byte //渲染消息入口的缓冲队列
|
||||
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
|
||||
renderChan chan []byte //渲染消息入口的缓冲队列
|
||||
}
|
||||
|
||||
// 处理分发到这里的数据
|
||||
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
//logx.Info("收到渲染任务消息:", string(data))
|
||||
//logx.Info("开始处理渲染任务消息:", string(data))
|
||||
select {
|
||||
case <-w.closeChan: //已经关闭
|
||||
return
|
||||
case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
|
||||
return
|
||||
case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,18 +51,13 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
|||
logx.Error("func renderImage err:", err)
|
||||
}
|
||||
}()
|
||||
var duration time.Duration = 1
|
||||
if w.extendRenderProperty.renderConsumeTickTime > 0 {
|
||||
duration = w.extendRenderProperty.renderConsumeTickTime
|
||||
}
|
||||
ticker := time.NewTicker(duration)
|
||||
defer ticker.Stop()
|
||||
var data []byte
|
||||
for {
|
||||
select {
|
||||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case <-ticker.C: //消费数据
|
||||
w.renderImage(<-w.extendRenderProperty.renderChan)
|
||||
case data = <-w.extendRenderProperty.renderChan: //消费数据
|
||||
w.renderImage(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -30,8 +29,6 @@ func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
|||
select {
|
||||
case userConnPoolCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 200):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,8 +48,6 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
|||
select {
|
||||
case userConnPoolCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 200):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,8 +63,6 @@ func sendToOutChanByUserIndex(userId, guestId int64, message []byte) {
|
|||
select {
|
||||
case userConnPoolCtlChan <- data:
|
||||
return
|
||||
case <-time.After(time.Millisecond * 200):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,24 +52,24 @@ type GetCartsReq {
|
|||
CurrentPage int `form:"current_page"` //当前页
|
||||
}
|
||||
type GetCartsRsp {
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
AllCartIdArray []int64 `json:"all_cartId_array"` //全部购物车id(不分页)
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
Meta Meta `json:"meta"` //分页信息
|
||||
CartList []CartItem `json:"cart_list"`
|
||||
}
|
||||
type CartItem {
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
IsSelected bool `json:"is_selected"` //是否选中
|
||||
CartId int64 `json:"cart_id"`
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
ItemPrice string `json:"item_price"` //单价
|
||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||
MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
|
||||
StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
|
||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||
IsSelected bool `json:"is_selected"` //是否选中
|
||||
}
|
||||
type ProductInfo {
|
||||
ProductId int64 `json:"product_id"` //产品id
|
||||
|
|
|
@ -57,7 +57,7 @@ func hasInvalidPatterns(key string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
var checkModuleRe = regexp.MustCompile("[^\\.a-zA-Z_-]")
|
||||
var checkModuleRe = regexp.MustCompile("[^\\.a-zA-Z_\\-0-9]")
|
||||
|
||||
// CheckModuleQuery 检查模块的json查询的格式
|
||||
func CheckModuleQuery(moduleQuery string) bool {
|
||||
|
|
|
@ -2,23 +2,29 @@ package format
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 厘转美元
|
||||
func CentitoDollar(price int64, remainFloatPoint ...uint) float64 {
|
||||
s := "%.3f"
|
||||
// 厘转美元(四舍五入)
|
||||
func CentitoDollar(price int64, remainFloatPoint ...uint) string {
|
||||
s := "%0.3f"
|
||||
if len(remainFloatPoint) > 0 {
|
||||
s = fmt.Sprintf("%%.%df", remainFloatPoint[0])
|
||||
s = fmt.Sprintf("%%0.%df", remainFloatPoint[0])
|
||||
}
|
||||
fmt.Println(s)
|
||||
str := fmt.Sprintf(s, float64(price)/float64(1000))
|
||||
dollar, _ := strconv.ParseFloat(str, 64)
|
||||
return dollar
|
||||
return fmt.Sprintf(s, float64(price)/float64(1000))
|
||||
}
|
||||
|
||||
// 厘转美元(向下截断,舍弃掉厘)用于计算总价
|
||||
func CentitoDollarWithNoHalfAdjust(price int64, remainFloatPoint ...uint) string {
|
||||
s := "%0.2f"
|
||||
if len(remainFloatPoint) > 0 {
|
||||
s = fmt.Sprintf("%%0.%df", remainFloatPoint[0])
|
||||
}
|
||||
t := price / 10
|
||||
return fmt.Sprintf(s, float64(t)/float64(100))
|
||||
}
|
||||
|
||||
// 厘转美元
|
||||
func CentitoDollarStr(price float64) string {
|
||||
s := "%.2f"
|
||||
s := "%0.2f"
|
||||
return fmt.Sprintf(s, price/float64(1000))
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ func MetadataModulePATCH(tx *gorm.DB, module string, tableStructPointer any, upd
|
|||
if stype.Kind() == reflect.Pointer {
|
||||
stype = stype.Elem()
|
||||
}
|
||||
tname := tx.NamingStrategy.TableName(stype.Name())
|
||||
|
||||
updatesql := `UPDATE %s
|
||||
SET metadata = CASE
|
||||
|
@ -80,7 +81,7 @@ func MetadataModulePATCH(tx *gorm.DB, module string, tableStructPointer any, upd
|
|||
args = append(args, metadata, metadata)
|
||||
args = append(args, values...)
|
||||
|
||||
updatesql = fmt.Sprintf(updatesql, tx.NamingStrategy.TableName(stype.Name()), module, WhereKeysCond)
|
||||
updatesql = fmt.Sprintf(updatesql, tname, module, WhereKeysCond)
|
||||
// logx.Error(updatesql)
|
||||
err = tx.Exec(updatesql, args...).Error
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user