Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-10-07 17:03:45 +08:00
commit f2226ff0e4
7 changed files with 48 additions and 19 deletions

View File

@ -80,12 +80,11 @@ func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress)
return err
}
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64) (err error) {
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64, isDefault int64) (err error) {
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 ", isDefault)
now := time.Now().UTC()
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).Take(nil).Error
@ -93,17 +92,32 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
return err
}
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
if isDefault == 0 {
err = tx.Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
err = tx.Model(&FsAddress{}).Where("`address_id` != ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).Error
} else {
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
UpdateColumn("utime", now).Error
if err != nil {
logx.Error(err)
return err
}
err = tx.Model(&FsAddress{}).Where("`address_id` != ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
}
return nil

View File

@ -14,7 +14,7 @@ import (
func AddressDefaultHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddressIdRequest
var req types.AddressDefaultRequest
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return

View File

@ -73,7 +73,7 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U
}
if req.IsDefault > 0 {
m.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId)
m.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId, req.IsDefault)
}
addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)

View File

@ -30,7 +30,7 @@ func NewAddressDefaultLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ad
// func (l *AddressDefaultLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *AddressDefaultLogic) AddressDefault(req *types.AddressIdRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *AddressDefaultLogic) AddressDefault(req *types.AddressDefaultRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
@ -38,7 +38,12 @@ func (l *AddressDefaultLogic) AddressDefault(req *types.AddressIdRequest, userin
return resp.SetStatus(basic.CodeUnAuth)
}
err := l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, req.AddressId)
// 确认这个IsDefault的值范围
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
}
err := l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, req.AddressId, req.IsDefault)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}

View File

@ -71,7 +71,7 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo *
}
if req.IsDefault > 0 {
l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId)
l.svcCtx.AllModels.FsAddress.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId, req.IsDefault)
}
addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId)

View File

@ -18,6 +18,11 @@ type AddressIdRequest struct {
AddressId int64 `json:"address_id"` // 地址id
}
type AddressDefaultRequest struct {
AddressId int64 `json:"address_id"` // 地址id
IsDefault int64 `json:"is_default"` // 是否默认
}
type AddressRequest struct {
AddressId int64 `json:"address_id,optional"`
IsDefault int64 `json:"is_default"` //是否默认

View File

@ -20,7 +20,7 @@ service info {
post /api/info/user/profile/base/update(ProfileRequest) returns (response);
@handler AddressDefaultHandler
post /api/info/address/default(AddressIdRequest) returns (response);
post /api/info/address/default(AddressDefaultRequest) returns (response);
@handler AddressAddHandler
post /api/info/address/add(AddressRequest) returns (response);
@ -52,6 +52,11 @@ type (
AddressId int64 `json:"address_id"` // 地址id
}
AddressDefaultRequest {
AddressId int64 `json:"address_id"` // 地址id
IsDefault int64 `json:"is_default"` // 是否默认
}
AddressRequest {
AddressId int64 `json:"address_id,optional"`
IsDefault int64 `json:"is_default"` //是否默认