| 
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -5,6 +5,7 @@ import (
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"fmt"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"github.com/pkg/errors"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"github.com/zeromicro/go-zero/core/logx"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"gorm.io/gorm"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					"live-service/common/nerr"
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				)
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
			
			 | 
			 | 
			
				@ -45,20 +46,22 @@ func (m *customUserIntegralModel) InsertTx(ctx context.Context, tx *gorm.DB, dat
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return err
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func (m *customUserIntegralModel) UpdateIntegralTx(ctx context.Context, tx *gorm.DB, userId, change int64) error {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if change < 0 {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				func (m *customUserIntegralModel) UpdateIntegralTx(ctx context.Context, tx *gorm.DB, userId, integral int64) error {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if integral < 0 {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return errors.New("无法将积分更新至负数")
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					db := withTx(ctx, m.conn, tx)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					result := db.Table(m.table).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Where("user_id = ?", userId).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Update("integral", change)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Where("`user_id` = ?", userId).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Update("`integral`", integral)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if result.Error != nil {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return result.Error
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					// TODO 这里得处理一下
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					if result.RowsAffected == 0 {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return ErrRowsAffectedZero
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						logx.Statf("更新积分影响行数为0, user_id: %d, integral: %d", userId, integral)
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return nil
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					}
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					return nil
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
				}
 | 
			
		
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
			
			 | 
			 | 
			
				@ -67,7 +70,7 @@ func (m *customUserIntegralModel) FindIntegral(ctx context.Context, tx *gorm.DB,
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					var resp int64
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					err := withTx(ctx, m.conn, tx).Table(m.table).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Select(fmt.Sprintf("%s.integral", m.table)).
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Where("user_id = ?", userId).Take(&resp).Error
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						Where("`user_id` = ?", userId).Take(&resp).Error
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					switch err {
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
					case nil:
 | 
			
		
		
	
		
			
				 | 
				 | 
			
			 | 
			 | 
			
						return resp, nil
 | 
			
		
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
			
			 | 
			 | 
			
				
 
 |