| | |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | Member User `json:"member" gorm:"foreignKey:MemberId"` |
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` |
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"` |
| | |
| | | AmountUnInvoiced decimal.Decimal `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:未开票金额" json:"amountUnInvoiced"` // 未开票金额 |
| | | AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:价税合计" json:"amountTotal"` // 价税合计 |
| | | Products []*Product `json:"products" gorm:"many2many:service_contract_product;"` |
| | | gorm.Model `json:"-"` |
| | | CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"` |
| | | CrmModel |
| | | } |
| | | |
| | | ServiceContractSearch struct { |
| | |
| | | PageNum int |
| | | PageSize int |
| | | Preload bool |
| | | MemberIds []int |
| | | } |
| | | ) |
| | | |
| | | func (ServiceContract) TableName() string { |
| | | func (slf *ServiceContract) TableName() string { |
| | | return "service_contract" |
| | | } |
| | | |
| | |
| | | db = db.Where("amount_receivable = ?", slf.Keyword) |
| | | |
| | | } |
| | | |
| | | if len(slf.MemberIds) > 0 { |
| | | db = db.Where("service_contract.member_id in ?", slf.MemberIds) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db. |
| | | Preload("Client"). |
| | | Preload("Member"). |
| | | Preload("Contact"). |
| | | Preload("SaleChance"). |
| | | Preload("SalesDetails"). |
| | | Preload("Quotation"). |
| | |
| | | Preload("Contact") |
| | | } |
| | | |
| | | if slf.SalesDetailsId != 0 { |
| | | db = db.Where("sales_details_id = ?", slf.SalesDetailsId) |
| | | } |
| | | |
| | | if slf.QuotationId != 0 { |
| | | db = db.Where("quotation_id = ?", slf.QuotationId) |
| | | } |
| | | if slf.SaleChanceId != 0 { |
| | | db = db.Where("sale_chance_id = ?", slf.SaleChanceId) |
| | | } |
| | | if slf.ContactId != 0 { |
| | | db = db.Where("contact_id = ?", slf.ContactId) |
| | | } |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | return db |
| | | } |
| | | |
| | |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) DeleteByIds(ids []int) error { |
| | | var db = slf.build() |
| | | db = db.Where("id in ?", ids) |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Find() ([]*ServiceContract, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*ServiceContract, 0) |
| | |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Order("id desc").Order("id desc").Find(&records).Error |
| | | err := db.Order("id desc").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Count() (int64, error) { |
| | | var db = slf.build() |
| | | var total int64 |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) MaxAutoIncr() (int, error) { |
| | | type Result struct { |
| | | Max int |
| | | } |
| | | |
| | | var ( |
| | | result Result |
| | | db = slf.build() |
| | | ) |
| | | |
| | | err := db.Select("MAX(id) as max").Scan(&result).Error |
| | | if err != nil { |
| | | return result.Max, fmt.Errorf("max err: %v", err) |
| | | } |
| | | return result.Max, nil |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetNumber(number string) *ServiceContractSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetMemberIds(memberIds []int) *ServiceContractSearch { |
| | | slf.MemberIds = memberIds |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetSalesDetailsId(salesDetailsId int) *ServiceContractSearch { |
| | | slf.SalesDetailsId = salesDetailsId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetQuotationId(quotationId int) *ServiceContractSearch { |
| | | slf.QuotationId = quotationId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetSaleChanceId(saleChanceId int) *ServiceContractSearch { |
| | | slf.SaleChanceId = saleChanceId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetContactId(contactId int) *ServiceContractSearch { |
| | | slf.ContactId = contactId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetPreload(preload bool) *ServiceContractSearch { |
| | | slf.Preload = preload |
| | | return slf |