invoice_info_dao.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "youngee_m_api/app/entity"
  5. )
  6. type InvoiceInfoDao struct{}
  7. func (d InvoiceInfoDao) Select(invoiceId int64) (*entity.InvoiceInfo, error) {
  8. var invoiceInfo entity.InvoiceInfo
  9. err := Db.Debug().Model(&entity.InvoiceInfo{}).Where("invoice_id = ?", invoiceId).Find(&invoiceInfo).Error
  10. if err != nil {
  11. if err == gorm.ErrRecordNotFound {
  12. return &invoiceInfo, nil
  13. }
  14. return nil, err
  15. }
  16. return &invoiceInfo, nil
  17. }
  18. func (d InvoiceInfoDao) Delete(invoiceId int64) error {
  19. var invoiceInfo entity.InvoiceInfo
  20. err := Db.Debug().Model(&entity.InvoiceInfo{}).Where("invoice_id = ?", invoiceId).Delete(&invoiceInfo).Error
  21. if err != nil {
  22. return err
  23. }
  24. return nil
  25. }
  26. func (d InvoiceInfoDao) SelectDefault(enterpriseId string, invoiceType int64, isDefault int64) (*entity.InvoiceInfo, error) {
  27. var invoiceInfo entity.InvoiceInfo
  28. err := Db.Debug().Model(&entity.InvoiceInfo{}).Where("enterprise_id = ? AND invoice_type = ? AND is_default = ?", enterpriseId, invoiceType, isDefault).Find(&invoiceInfo).Error
  29. if err != nil {
  30. if err == gorm.ErrRecordNotFound {
  31. return &invoiceInfo, nil
  32. }
  33. return nil, err
  34. }
  35. return &invoiceInfo, nil
  36. }
  37. func (d InvoiceInfoDao) Insert(invoiceInfo *entity.InvoiceInfo) error {
  38. err := Db.Debug().Model(&entity.InvoiceInfo{}).Create(invoiceInfo).Error
  39. if err != nil {
  40. return err
  41. }
  42. return nil
  43. }