contract_income_history.go 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package fms
  2. import (
  3. "hongze/fms_api/global"
  4. "hongze/fms_api/models/base"
  5. "time"
  6. )
  7. type ContractIncomeHistory struct {
  8. IncomeId int `json:"income_id" gorm:"primaryKey;column:income_id"` //
  9. Amount float64 `json:"amount" gorm:"column:amount"` // 开票金额
  10. InvoiceTime time.Time `json:"invoice_time" gorm:"column:invoice_time"` // 开票日期/到款月
  11. SellerId int `json:"seller_id" gorm:"column:seller_id"` // 销售ID
  12. GroupId int `json:"group_id" gorm:"column:group_id"` // 销售ID
  13. SellerName string `json:"seller_name" gorm:"column:seller_name"` // 销售名称
  14. GroupName string `json:"group_name" gorm:"column:group_name"` // 销售名称
  15. NewCompany int `json:"new_company" gorm:"column:new_company"` // 是否为新客户:0-否;1-是
  16. CompanyName string `json:"company_name" gorm:"column:company_name"` // 客户名称
  17. DepartmentId int `json:"department_id" gorm:"column:department_id"` // 部门ID
  18. }
  19. func (c *ContractIncomeHistory) List(condition string, pars []interface{}) (list []*ContractIncomeHistory, err error) {
  20. list = make([]*ContractIncomeHistory, 0)
  21. err = global.DEFAULT_MYSQL.Model(c).
  22. Where(condition, pars...).
  23. Find(&list).Error
  24. return
  25. }
  26. func (c *ContractIncomeHistory) TableName() string {
  27. return "contract_income_history"
  28. }
  29. // GetIncomeHistory
  30. func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
  31. sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date,
  32. seller_id as final_seller_id,group_id AS seller_group_id,'CNY' AS currency_unit FROM contract_income_history WHERE `
  33. sql += condition
  34. sql += ` ORDER BY invoice_date `
  35. err = global.DEFAULT_MYSQL.Raw(sql, pars...).Find(&results).Error
  36. return
  37. }
  38. // GetIncomeHistoryList
  39. func GetIncomeHistoryList() (results []*ContractIncomeHistory, err error) {
  40. sql := `SELECT * FROM contract_income_history `
  41. err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
  42. return
  43. }
  44. func (c *ContractIncomeHistory) Update(updateCols []string) (err error) {
  45. err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
  46. return
  47. }
  48. func GetLatestHistoryIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
  49. sql := `SELECT
  50. *
  51. FROM
  52. contract_income_history WHERE 1=1 `
  53. sql += condition
  54. sql += ` ORDER BY invoice_time DESC `
  55. err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
  56. return
  57. }
  58. // GetIncomeHistoryPage
  59. func GetIncomeHistoryPage(condition string, pars []interface{}, page *base.Page) (results []*IncomeSummaryItem, count int64, err error) {
  60. sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date,
  61. seller_id as final_seller_id,group_id AS seller_group_id,'CNY' AS currency_unit FROM contract_income_history WHERE `
  62. sql += condition
  63. query := global.DEFAULT_MYSQL.Table("contract_income_history").
  64. Select("amount,seller_name,new_company AS contract_type,company_name," +
  65. "invoice_time AS invoice_date, seller_id as final_seller_id,group_id AS seller_group_id," +
  66. "'CNY' AS currency_unit").Where(condition, pars...)
  67. if len(page.GetOrderItemsString()) > 0 {
  68. query = query.Order(page.GetOrderItemsString())
  69. }
  70. query.Count(&count)
  71. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
  72. return
  73. }