You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
882 B

package finance
import (
"errors"
"github.com/shopspring/decimal"
"gorm.io/gorm"
"recook/internal/v2/model/finance"
)
var SourceLogic = &sourceLogic{}
type sourceLogic struct {
}
// BillAdd @Title 添加待开票金额
func (s *sourceLogic) BillAdd(tx *gorm.DB, sourceId uint, amount decimal.Decimal) error {
financeSource := finance.RecookFinanceSource{SourceId: sourceId}
if tx.Where(&financeSource).First(&financeSource).Error != nil {
financeSource.UnReceipt = amount
financeSource.TotalReceipt = amount
if tx.Create(&financeSource).Error != nil {
return errors.New("系统错误")
}
} else {
if tx.Model(&financeSource).UpdateColumns(map[string]interface{}{
"un_receipt": gorm.Expr("un_receipt + ?", amount),
"total_receipt": gorm.Expr("total_receipt + ?", amount),
}).Error != nil {
return errors.New("系统错误")
}
}
return nil
}