contract_income_history.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "time"
  5. )
  6. type ContractIncomeHistory struct {
  7. IncomeId int `json:"income_id" gorm:"primaryKey;column:income_id"` //
  8. Amount float64 `json:"amount" gorm:"column:amount"` // 开票金额
  9. InvoiceTime time.Time `json:"invoice_time" gorm:"column:invoice_time"` // 开票日期/到款月
  10. SellerId int `json:"seller_id" gorm:"column:seller_id"` // 销售ID
  11. SellerName string `json:"seller_name" gorm:"column:seller_name"` // 销售名称
  12. NewCompany int `json:"new_company" gorm:"column:new_company"` // 是否为新客户:0-否;1-是
  13. CompanyName string `json:"company_name" gorm:"column:company_name"` // 客户名称
  14. }
  15. func (c *ContractIncomeHistory) List(condition string, pars []interface{}) (list []*ContractIncomeHistory, err error) {
  16. list = make([]*ContractIncomeHistory, 0)
  17. err = global.DEFAULT_MYSQL.Model(c).
  18. Where(condition, pars...).
  19. Find(&list).Error
  20. return
  21. }
  22. func (c *ContractIncomeHistory) TableName() string {
  23. return "contract_income_history"
  24. }
  25. // GetIncomeHistory
  26. func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
  27. sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date FROM contract_income_history WHERE `
  28. sql += condition
  29. sql += ` ORDER BY invoice_date `
  30. err = global.DEFAULT_MYSQL.Raw(sql, pars...).Find(&results).Error
  31. return
  32. }
  33. // GetIncomeHistoryList
  34. func GetIncomeHistoryList() (results []*ContractIncomeHistory, err error) {
  35. sql := `SELECT * FROM contract_income_history WHERE seller_id=0 `
  36. err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
  37. return
  38. }
  39. func (c *ContractIncomeHistory) Update(updateCols []string) (err error) {
  40. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  41. return
  42. }
  43. func GetLatestHistoryIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
  44. sql := `SELECT
  45. *
  46. FROM
  47. contract_income_history WHERE 1=1 `
  48. sql += condition
  49. sql += ` ORDER BY invoice_time DESC `
  50. err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
  51. return
  52. }