123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package fms
- import (
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- "time"
- )
- type ContractIncomeHistory struct {
- IncomeId int `json:"income_id" gorm:"primaryKey;column:income_id"` //
- Amount float64 `json:"amount" gorm:"column:amount"` // 开票金额
- InvoiceTime time.Time `json:"invoice_time" gorm:"column:invoice_time"` // 开票日期/到款月
- SellerId int `json:"seller_id" gorm:"column:seller_id"` // 销售ID
- GroupId int `json:"group_id" gorm:"column:group_id"` // 销售ID
- SellerName string `json:"seller_name" gorm:"column:seller_name"` // 销售名称
- GroupName string `json:"group_name" gorm:"column:group_name"` // 销售名称
- NewCompany int `json:"new_company" gorm:"column:new_company"` // 是否为新客户:0-否;1-是
- CompanyName string `json:"company_name" gorm:"column:company_name"` // 客户名称
- DepartmentId int `json:"department_id" gorm:"column:department_id"` // 部门ID
- }
- func (c *ContractIncomeHistory) List(condition string, pars []interface{}) (list []*ContractIncomeHistory, err error) {
- list = make([]*ContractIncomeHistory, 0)
- err = global.DEFAULT_MYSQL.Model(c).
- Where(condition, pars...).
- Find(&list).Error
- return
- }
- func (c *ContractIncomeHistory) TableName() string {
- return "contract_income_history"
- }
- // GetIncomeHistory
- func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
- sql := `SELECT amount,amount AS origin_amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date,
- seller_id as final_seller_id,group_id AS seller_group_id,'CNY' AS currency_unit FROM contract_income_history WHERE `
- sql += condition
- sql += ` ORDER BY invoice_date `
- err = global.DEFAULT_MYSQL.Raw(sql, pars...).Find(&results).Error
- return
- }
- // GetIncomeHistoryList
- func GetIncomeHistoryList() (results []*ContractIncomeHistory, err error) {
- sql := `SELECT * FROM contract_income_history `
- err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
- return
- }
- func (c *ContractIncomeHistory) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(c).Select(updateCols).Updates(c).Error
- return
- }
- func GetLatestHistoryIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
- sql := `SELECT
- *
- FROM
- contract_income_history WHERE 1=1 `
- sql += condition
- sql += ` ORDER BY invoice_time DESC `
- err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
- return
- }
- // GetIncomeHistoryPage
- func GetIncomeHistoryPage(condition string, pars []interface{}, page *base.Page) (results []*IncomeSummaryItem, count int64, err error) {
- query := global.DEFAULT_MYSQL.Table("contract_income_history").
- Select("amount,amount AS origin_amount, seller_name,new_company AS contract_type,company_name,"+
- "invoice_time AS invoice_date, seller_id as final_seller_id,group_id AS seller_group_id,"+
- "'CNY' AS currency_unit").Where(condition, pars...)
- if len(page.GetOrderItemsString()) > 0 {
- query = query.Order(page.GetOrderItemsString())
- }
- query.Count(&count)
- err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
- return
- }
|