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