info address default
This commit is contained in:
		
							parent
							
								
									bfeacad5f0
								
							
						
					
					
						commit
						8bc1607f00
					
				@ -14,18 +14,26 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []*FsAddressWithDefault, err error) {
 | 
			
		||||
	err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&resp).Error
 | 
			
		||||
 | 
			
		||||
	var dbresp []*FsAddress
 | 
			
		||||
	err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&dbresp).Error
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	now := time.Now().UTC().AddDate(10, 0, 0).Unix()
 | 
			
		||||
	for _, r := range resp {
 | 
			
		||||
		if r.Ltime.UTC().Unix() > now {
 | 
			
		||||
			r.IsDefault = 1
 | 
			
		||||
		} else {
 | 
			
		||||
			r.IsDefault = 0
 | 
			
		||||
	for _, r := range dbresp {
 | 
			
		||||
		rd := &FsAddressWithDefault{
 | 
			
		||||
			FsAddress: r,
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if r.Ltime.UTC().Unix() > now {
 | 
			
		||||
			rd.IsDefault = 1
 | 
			
		||||
		} else {
 | 
			
		||||
			rd.IsDefault = 0
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		resp = append(resp, rd)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return
 | 
			
		||||
 | 
			
		||||
@ -65,6 +65,6 @@ type UserProfileBase struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type FsAddressWithDefault struct {
 | 
			
		||||
	FsAddress
 | 
			
		||||
	*FsAddress
 | 
			
		||||
	IsDefault int64 `json:"is_default"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user