From 82ce9a5114c6711e13c782ab84d88fe9bfcef355 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:04:53 +0800 Subject: [PATCH 1/6] info get profile --- model/gmodel/fs_address_logic.go | 2 ++ server/info/internal/logic/addressaddlogic.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 2dfcc55b..f890b1a5 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -84,6 +84,8 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error { + logx.Info("address_id:", addressId, " set default") + now := time.Now().UTC() err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index 0673e91c..dc291724 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -68,12 +68,16 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U ZipCode: &req.ZipCode, IsDefault: &isDefautl, } - _, err := m.CreateOne(l.ctx, createOne) // 新增地址 + address, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { logx.Error(err) // 日志记录错误 return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误 } + if req.IsDefault > 0 { + m.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId) + } + addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId) if err != nil { logx.Error(err) From 943eba6f1a46f517b7e66291d01262a6ba184527 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:12:28 +0800 Subject: [PATCH 2/6] info get profile --- model/gmodel/fs_address_logic.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index f890b1a5..af2ea9bd 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -93,14 +93,18 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId). + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ?", userId, addressId). UpdateColumn("ltime", now.AddDate(250, 0, 0)). UpdateColumn("utime", now).Error if err != nil { return err } - err = tx.Where(" `user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ? ", userId, addressId, now.AddDate(10, 0, 0)). + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error + if err != nil { + logx.Error(err) + } + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)). UpdateColumn("ltime", now).Error if err != nil { logx.Error(err) From b4f201eb98043614aea7f4315d79f0ba8514594d Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:18:16 +0800 Subject: [PATCH 3/6] info get profile --- model/gmodel/fs_address_logic.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index af2ea9bd..7230f658 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -2,6 +2,7 @@ package gmodel import ( "context" + "fmt" "time" "github.com/zeromicro/go-zero/core/logx" @@ -100,10 +101,11 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error + err = tx.Where(fmt.Sprintf("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > '%s'", now.AddDate(10, 0, 0)), userId, addressId).Take(nil).Error if err != nil { logx.Error(err) } + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)). UpdateColumn("ltime", now).Error if err != nil { From fe577052868fb56a00bbe7e746aeecd5797a203a Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:23:02 +0800 Subject: [PATCH 4/6] info get profile --- model/gmodel/fs_address_logic.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 7230f658..22498d89 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -2,7 +2,6 @@ package gmodel import ( "context" - "fmt" "time" "github.com/zeromicro/go-zero/core/logx" @@ -101,7 +100,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where(fmt.Sprintf("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > '%s'", now.AddDate(10, 0, 0)), userId, addressId).Take(nil).Error + err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and ltime > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error if err != nil { logx.Error(err) } From d61e939685f6dc6d837ed107cb5a9a13c2510bd3 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:24:47 +0800 Subject: [PATCH 5/6] info get profile --- model/gmodel/fs_address_logic.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 22498d89..3408e052 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -100,12 +100,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and ltime > ?", userId, addressId, now.AddDate(10, 0, 0)).Take(nil).Error - if err != nil { - logx.Error(err) - } - - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)). + err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)). UpdateColumn("ltime", now).Error if err != nil { logx.Error(err) From 3dc822fcde0710d0ce49ff21b2a0d42a1c699c1c Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 12:28:53 +0800 Subject: [PATCH 6/6] info get profile --- model/gmodel/fs_address_logic.go | 2 +- server/info/internal/logic/addressupdatelogic.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 3408e052..2efce67b 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -84,7 +84,7 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error { - logx.Info("address_id:", addressId, " set default") + logx.Info("address_id:", addressId, " set default ") now := time.Now().UTC() diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index 8cd33bd2..cc962cbe 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -66,7 +66,16 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo * return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error()) } - return resp.SetStatus(basic.CodeOK) + addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr) // 返回数据库创建错误 + } + + return resp.SetStatus(basic.CodeOK, map[string]any{ + "address_list": addresses, + }) // 返回成功并返回地址ID + } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理