fix
wangpengfei
2023-08-10 f26d6d27c5f756c88a2a44f2cf0125f277ff177e
model/followRecord.go
@@ -12,6 +12,7 @@
      ClientId             int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:客户id"`
      ClientStatusId       int       `json:"client_status_id" gorm:"column:client_status_id;type:int(11);comment:客户状态id"`
      MemberId             int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:跟进人id"`
      Member               User      `json:"member" gorm:"foreignKey:MemberId"`
      Number               string    `json:"number" gorm:"column:number;type:varchar(255);comment:跟进编号"`
      ContactId            int       `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:联系人id"`
      Topic                string    `json:"topic" gorm:"column:topic;type:varchar(255);comment:跟进主题"`
@@ -32,7 +33,7 @@
      FollowRecord
      Orm      *gorm.DB
      Keyword  string
      SearchMap map[string]interface{}
      OrderBy  string
      PageNum  int
      PageSize int
@@ -51,56 +52,50 @@
func (slf *FollowRecordSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&FollowRecord{})
   if slf.Keyword != "" {
      db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
   }
   if slf.Keyword != "" {
      db = db.Where("topic LIKE ?", "%"+slf.Keyword+"%")
   }
   if slf.Id != 0 {
      db = db.Where("id = ?", slf.Id)
   }
   if slf.ClientId != 0 {
      db = db.Where("client_id = ?", slf.ClientId)
   }
   if slf.ClientStatusId != 0 {
      db = db.Where("client_status_id = ?", slf.ClientStatusId)
   if len(slf.SearchMap) > 0 {
      for key, value := range slf.SearchMap {
         switch v := value.(type) {
         case string:
            if key == "topic" || key == "record" {
               db = db.Where(key+" LIKE ?", "%"+v+"%")
   }
   if slf.MemberId != 0 {
      db = db.Where("member_id = ?", slf.MemberId)
            if key == "client_name" {
               db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
   }
   if slf.Number != "" {
      db = db.Where("number = ?", slf.Number)
            if key == "contact_name" {
               db = db.Joins("Contact").Where("Contact.name LIKE ?", "%"+v+"%")
   }
   if slf.ContactId != 0 {
      db = db.Where("contact_id = ?", slf.ContactId)
            if key == "member_name" {
               db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%")
   }
   if slf.Topic != "" {
      db = db.Where("topic = ?", slf.Topic)
            if key == "phone" {
               db = db.Joins("Contact").Where("Contacts.phone LIKE ?", "%"+v+"%")
   }
   if slf.Record != "" {
      db = db.Where("record = ?", slf.Record)
            if key == "follow_time" {
               db = db.Where("follow_time = ?", v)
   }
   if slf.SaleChanceId != 0 {
      db = db.Where("sale_chance_id = ?", slf.SaleChanceId)
            if key == "next_follow_time" {
               db = db.Where("next_follow_time = ?", v)
   }
   if slf.SalesLeadsId != 0 {
      db = db.Where("sales_leads_id = ?", slf.SalesLeadsId)
            if key == "client_status" {
               db = db.Joins("Client").Joins("Client.ClientStatus").Where("Client__ClientStatus.name LIKE ?", "%"+v+"%")
   }
   if slf.ContactInformationId != 0 {
      db = db.Where("contact_information_id = ?", slf.ContactInformationId)
   }
   if !slf.FollowTime.IsZero() {
      db = db.Where("follow_time = ?", slf.FollowTime)
   }
   if !slf.NextFollowTime.IsZero() {
      db = db.Where("next_follow_time = ?", slf.NextFollowTime)
   }
   if slf.Purpose != "" {
      db = db.Where("purpose = ?", slf.Purpose)
   }
   if slf.Content != "" {
      db = db.Where("content = ?", slf.Content)
   }
   return db
@@ -169,11 +164,6 @@
   return slf
}
func (slf *FollowRecordSearch) SetKeyword(keyword string) *FollowRecordSearch {
   slf.Keyword = keyword
   return slf
}
func (slf *FollowRecordSearch) SetPage(page, size int) *FollowRecordSearch {
   slf.PageNum, slf.PageSize = page, size
   return slf
@@ -192,3 +182,8 @@
   var db = slf.build()
   return db.Updates(data).Error
}
func (slf *FollowRecordSearch) SetSearchMap(data map[string]interface{}) *FollowRecordSearch {
   slf.SearchMap = data
   return slf
}