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

This commit is contained in:
laodaming 2023-09-27 14:05:34 +08:00
commit d5e5f7e6e2
3 changed files with 19 additions and 4 deletions

View File

@ -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
@ -91,14 +93,14 @@ 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.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)

View File

@ -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)

View File

@ -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 必须重新处理