contract_income_history.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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,amount AS origin_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. query := global.DEFAULT_MYSQL.Table("contract_income_history").
  61. Select("amount,amount AS origin_amount, seller_name,new_company AS contract_type,company_name,"+
  62. "invoice_time AS invoice_date, seller_id as final_seller_id,group_id AS seller_group_id,"+
  63. "'CNY' AS currency_unit").Where(condition, pars...)
  64. if len(page.GetOrderItemsString()) > 0 {
  65. query = query.Order(page.GetOrderItemsString())
  66. }
  67. query.Count(&count)
  68. err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
  69. return
  70. }