collection.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import (
  3. "github.com/shopspring/decimal"
  4. "server/global"
  5. )
  6. type Collection struct {
  7. global.GVA_MODEL
  8. ProjectCode string `json:"projectCode" from:"projectCode" gorm:"comment:项目编码"`
  9. CollectionPrice decimal.Decimal `json:"collectionPrice" from:"collectionPrice" gorm:"type:decimal(10,2);not null;comment:收款金额"`
  10. Remarks string `json:"remarks" from:"remarks" gorm:"comment:备注"`
  11. CollectionTime string `json:"collectionTime" from:"collectionTime" gorm:"comment:收款日期;type:datetime"`
  12. }
  13. func (Collection) TableName() string {
  14. return "collection"
  15. }
  16. // TODO:收款查询
  17. // QueryCollection 查询收款
  18. func QueryCollection(code string) (collection []Collection, err error) {
  19. err = global.GVA_DB.Model(&Collection{}).Where("project_code = ?", code).Find(&collection).Error
  20. return collection, err
  21. }
  22. // QueryCollectionList 查询报销列表
  23. func QueryCollectionList(limit, offset int, code, time string) (collection []Collection, total int64, err error) {
  24. // 创建db
  25. db := global.GVA_DB.Model(&Collection{}).Where("project_code = ?", code)
  26. // 如果有条件搜索 下方会自动创建搜索语句
  27. if time != "" {
  28. db = db.Where("DATE_FORMAT(collection_time, '%Y-%m') = ?", time)
  29. }
  30. err = db.Count(&total).Error
  31. if err != nil {
  32. return
  33. }
  34. err = db.Order("id desc").Limit(limit).Offset(offset).Find(&collection).Error
  35. return collection, total, err
  36. }
  37. // TODO:收款新增
  38. // CreateCollection 新增收款
  39. func (c Collection) CreateCollection() error {
  40. return global.GVA_DB.Create(&c).Error
  41. }
  42. // TODO:收款修改
  43. // UpdateCollection 修改收款
  44. func (c Collection) UpdateCollection() error {
  45. return global.GVA_DB.Model(&c).Where("id = ?", c.ID).Updates(&c).Error
  46. }
  47. // TODO:收款删除
  48. // DeleteCollection 删除收款
  49. func (c Collection) DeleteCollection() error {
  50. return global.GVA_DB.Unscoped().Delete(&c).Error
  51. }