| | |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` |
| | | ContactInformation ContactInformation `json:"contact_information" gorm:"foreignKey:ContactInformationId"` |
| | | CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:编码id"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | |
| | | } |
| | | if slf.ClientId != 0 { |
| | | db = db.Where("client_id = ?", slf.ClientId) |
| | | } |
| | | if slf.Number != "" { |
| | | db = db.Where("number = ?", slf.Number) |
| | | } |
| | | |
| | | if len(slf.SearchMap) > 0 { |
| | |
| | | if key == "client_id" || key == "contact_id" || key == "sales_leads_id" || key == "sale_chance_id" || key == "member_id" { |
| | | db = db.Where(key+" = ?", v) |
| | | } |
| | | case []int: |
| | | if key == "member_ids" { |
| | | db = db.Where("follow_records.member_id in ?", v) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | return records, total, err |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) Count() (int64, error) { |
| | | var count int64 |
| | | err := slf.build().Count(&count).Error |
| | | return count, err |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) Page(page, pageSize int) ([]*FollowRecord, int64, error) { |
| | | var records = make([]*FollowRecord, 0) |
| | | var count int64 |
| | |
| | | func (slf *FollowRecordSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&slf.FollowRecord).Error |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) Count() (int64, error) { |
| | | var db = slf.build() |
| | | var total int64 |
| | | err := db.Count(&total).Error |
| | | return total, err |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) 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 *FollowRecordSearch) SetId(id int) *FollowRecordSearch { |
| | |
| | | slf.SearchMap = data |
| | | return slf |
| | | } |
| | | func (slf *FollowRecordSearch) SetOrm(tx *gorm.DB) *FollowRecordSearch { |
| | | slf.Orm = tx |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FollowRecordSearch) SetNumber(number string) *FollowRecordSearch { |
| | | slf.Number = number |
| | | return slf |
| | | } |