| | |
| | | package model
|
| | |
|
| | | import (
|
| | | "aps_crm/constvar"
|
| | | "aps_crm/pkg/mysqlx"
|
| | | "gorm.io/gorm"
|
| | | "time"
|
| | |
| | | ServiceContractSearch struct {
|
| | | ServiceContract
|
| | |
|
| | | Orm *gorm.DB
|
| | | Keyword string
|
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | | Orm *gorm.DB
|
| | | QueryClass constvar.ServiceContractQueryClass
|
| | | KeywordType constvar.ServiceContractKeywordType
|
| | | Keyword interface{}
|
| | | OrderBy string
|
| | | PageNum int
|
| | | PageSize int
|
| | | }
|
| | | )
|
| | |
|
| | |
| | |
|
| | | 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)
|
| | | }
|
| | | switch slf.QueryClass {
|
| | | case constvar.ServiceContractQueryClassExpireAfter30Day:
|
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 30))
|
| | | case constvar.ServiceContractQueryClassExpireAfter60Day:
|
| | | db = db.Where("end_time > ?", time.Now(), time.Now().AddDate(0, 0, 60))
|
| | | case constvar.ServiceContractQueryClassExpiredBefore15Day:
|
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -15))
|
| | | case constvar.ServiceContractQueryClassExpiredBefore60Day:
|
| | | db = db.Where("end_time < ?", time.Now().AddDate(0, 0, -60))
|
| | |
|
| | | }
|
| | | switch slf.KeywordType {
|
| | | case constvar.ServiceContractKeywordContractNo:
|
| | | db = db.Where("number = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordCustomerName:
|
| | | db = db.Where("client_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractDate:
|
| | | db = db.Where("sign_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractType:
|
| | | db = db.Where("service_contract_type_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordContractStatus:
|
| | | db = db.Where("service_contract_status_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordPrincipal:
|
| | | db = db.Where("member_id = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordProductName:
|
| | | subQuery := db.Table("service_contract_id").Select("product_id").Where("product_id = ?", slf.Keyword)
|
| | | db = db.Where("id = ?", subQuery)
|
| | | case constvar.ServiceContractKeywordServiceBeginDate:
|
| | | db = db.Where("start_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordServiceEndDate:
|
| | | db = db.Where("end_time = ?", slf.Keyword)
|
| | | case constvar.ServiceContractKeywordServiceTotalPrice:
|
| | | //todo
|
| | |
|
| | | }
|
| | |
|
| | | return db
|
| | |
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetKeywordType(keyword constvar.ServiceContractKeywordType) *ServiceContractSearch {
|
| | | slf.KeywordType = keyword
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetQueryClass(queryClass constvar.ServiceContractQueryClass) *ServiceContractSearch {
|
| | | slf.QueryClass = queryClass
|
| | | return slf
|
| | | }
|
| | |
|
| | | func (slf *ServiceContractSearch) SetKeyword(keyword string) *ServiceContractSearch {
|
| | | slf.Keyword = keyword
|
| | | return slf
|