| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | ServiceContract struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"` |
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"` |
| | | ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:合同id"` |
| | | QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"` |
| | | ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"` |
| | | SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"` |
| | | StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"` |
| | | EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"` |
| | | ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:合同状态id"` |
| | | ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"` |
| | | Terms string `json:"terms" gorm:"column:terms;type:text;comment:条款"` |
| | | Remark string `json:"remark" gorm:"column:remark;type:text;comment:备注"` |
| | | Products []Product `json:"products" gorm:"many2many:serviceContract_product;"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | | ServiceContractSearch struct { |
| | | ServiceContract |
| | | |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | } |
| | | ) |
| | | |
| | | func (ServiceContract) TableName() string { |
| | | return "service_contract" |
| | | } |
| | | |
| | | func NewServiceContractSearch() *ServiceContractSearch { |
| | | return &ServiceContractSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&ServiceContract{}) |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") |
| | | } |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Create(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Update(record *ServiceContract) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&ServiceContract{}).Error |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) Find() (*ServiceContract, error) { |
| | | var db = slf.build() |
| | | var record = &ServiceContract{} |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) { |
| | | var db = slf.build() |
| | | var records = make([]*ServiceContract, 0) |
| | | var total int64 |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return records, total, err |
| | | } |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | if slf.PageNum > 0 && slf.PageSize > 0 { |
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize) |
| | | } |
| | | |
| | | err := db.Preload("Products").Find(&records).Error |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch { |
| | | slf.Keyword = keyword |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetPage(page, size int) *ServiceContractSearch { |
| | | slf.PageNum, slf.PageSize = page, size |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ServiceContractSearch) SetOrder(order string) *ServiceContractSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | func (slf *ServiceContractSearch) SetIds(ids []int) *ServiceContractSearch { |
| | | slf.Orm = slf.Orm.Where("id in (?)", ids) |
| | | return slf |
| | | } |
| | | package model
|
| | |
|
| | | import (
|
| | | "aps_crm/pkg/mysqlx"
|
| | | "gorm.io/gorm"
|
| | | "time"
|
| | | )
|
| | |
|
| | | type (
|
| | | ServiceContract struct {
|
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
|
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"`
|
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"`
|
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
|
| | | ContactId int `json:"contactId" gorm:"column:contact_id;type:int;comment:联系人id"`
|
| | | SaleChanceId int `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:销售机会id"`
|
| | | ContractId int `json:"contractId" gorm:"column:contract_id;type:int;comment:合同id"`
|
| | | QuotationId int `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"`
|
| | | ServiceContractTypeId int `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:合同类型id"`
|
| | | SignTime time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:签约时间"`
|
| | | StartTime time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:开始时间"`
|
| | | EndTime time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:结束时间"`
|
| | | ServiceContractStatusId int `json:"serviceContractStatusId" gorm:"column:service_contract_status_id;type:int;comment:合同状态id"`
|
| | | ServiceTimes int `json:"serviceTimes" gorm:"column:service_times;type:int;comment:服务次数"`
|
| | | Terms string `json:"terms" gorm:"column:terms;type:text;comment:条款"`
|
| | | Remark string `json:"remark" gorm:"column:remark;type:text;comment:备注"`
|
| | | Products []Product `json:"products" gorm:"many2many:serviceContract_product;"`
|
| | | gorm.Model `json:"-"`
|
| | | }
|
| | |
|
| | | ServiceContractSearch struct {
|
| | | ServiceContract
|
| | |
|
| | | Orm *gorm.DB
|
| | | Keyword string
|
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | | }
|
| | | )
|
| | |
|
| | | func (ServiceContract) TableName() string {
|
| | | return "service_contract"
|
| | | }
|
| | |
|
| | | func NewServiceContractSearch() *ServiceContractSearch {
|
| | | return &ServiceContractSearch{
|
| | | Orm: mysqlx.GetDB(),
|
| | | }
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) build() *gorm.DB {
|
| | | var db = slf.Orm.Model(&ServiceContract{})
|
| | | if slf.Keyword != "" {
|
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
|
| | | }
|
| | | if slf.Keyword != "" {
|
| | | db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
|
| | | }
|
| | | if slf.Id != 0 {
|
| | | db = db.Where("id = ?", slf.Id)
|
| | | }
|
| | |
|
| | | return db
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Create(record *ServiceContract) error {
|
| | | var db = slf.build()
|
| | | return db.Create(record).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Update(record *ServiceContract) error {
|
| | | var db = slf.build()
|
| | | return db.Updates(record).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Delete() error {
|
| | | var db = slf.build()
|
| | | return db.Delete(&ServiceContract{}).Error
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) Find() (*ServiceContract, error) {
|
| | | var db = slf.build()
|
| | | var record = &ServiceContract{}
|
| | | err := db.First(record).Error
|
| | | return record, err
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) FindAll() ([]*ServiceContract, int64, error) {
|
| | | var db = slf.build()
|
| | | var records = make([]*ServiceContract, 0)
|
| | | var total int64
|
| | | if err := db.Count(&total).Error; err != nil {
|
| | | return records, total, err
|
| | | }
|
| | | if slf.PageNum > 0 && slf.PageSize > 0 {
|
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
|
| | | }
|
| | |
|
| | | if slf.PageNum > 0 && slf.PageSize > 0 {
|
| | | db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
|
| | | }
|
| | |
|
| | | err := db.Preload("Products").Find(&records).Error
|
| | | return records, total, err
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetId(id int) *ServiceContractSearch {
|
| | | slf.Id = id
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch {
|
| | | slf.Keyword = keyword
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetPage(page, size int) *ServiceContractSearch {
|
| | | slf.PageNum, slf.PageSize = page, size
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetOrder(order string) *ServiceContractSearch {
|
| | | slf.OrderBy = order
|
| | | return slf
|
| | | }
|
| | | func (slf *ServiceContractSearch) SetIds(ids []int) *ServiceContractSearch {
|
| | | slf.Orm = slf.Orm.Where("id in (?)", ids)
|
| | | return slf
|
| | | }
|