From d8ac88cfb72e3aac3a89c3cfe77774be3024a24c Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 11 八月 2023 17:54:43 +0800
Subject: [PATCH] update
---
model/contact.go | 88 ++++++++++++++++++++++++++++++--------------
1 files changed, 60 insertions(+), 28 deletions(-)
diff --git a/model/contact.go b/model/contact.go
index 3fc6048..a955791 100644
--- a/model/contact.go
+++ b/model/contact.go
@@ -3,23 +3,23 @@
import (
"aps_crm/pkg/mysqlx"
"gorm.io/gorm"
- "time"
)
type (
Contact struct {
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鑱旂郴浜哄鍚�"`
- Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鑱旂郴浜虹紪鍙�"`
- ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
- Position string `json:"position" gorm:"column:position;type:varchar(255);comment:鑱屼綅"`
- Phone string `json:"phone" gorm:"column:phone;type:varchar(255);comment:鐢佃瘽"`
- MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璐熻矗浜篒D"`
- IsFirst bool `json:"is_first" gorm:"column:is_first;type:tinyint(1);comment:鏄惁棣栬鑱旂郴浜�"`
- Wechat string `json:"wechat" gorm:"column:wechat;type:varchar(255);comment:寰俊"`
- Birthday time.Time `json:"birthday" gorm:"column:birthday;type:datetime;comment:鐢熸棩"`
- Email string `json:"email" gorm:"column:email;type:varchar(255);comment:閭"`
- Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:澶囨敞"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鑱旂郴浜哄鍚�"`
+ Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鑱旂郴浜虹紪鍙�"`
+ ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
+ Client Client `json:"-" gorm:"foreignKey:ClientId"`
+ Position string `json:"position" gorm:"column:position;type:varchar(255);comment:鑱屼綅"`
+ Phone string `json:"phone" gorm:"column:phone;type:varchar(255);comment:鐢佃瘽"`
+ MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璐熻矗浜篒D"`
+ IsFirst bool `json:"is_first" gorm:"column:is_first;type:tinyint(1);comment:鏄惁棣栬鑱旂郴浜�"`
+ Wechat string `json:"wechat" gorm:"column:wechat;type:varchar(255);comment:寰俊"`
+ Birthday *CustomTime `json:"birthday" gorm:"column:birthday;type:datetime;comment:鐢熸棩"`
+ Email string `json:"email" gorm:"column:email;type:varchar(255);comment:閭"`
+ Desc string `json:"desc" gorm:"column:desc;type:varchar(255);comment:澶囨敞"`
Address
gorm.Model `json:"-"`
}
@@ -27,11 +27,11 @@
ContactSearch struct {
Contact
- Orm *gorm.DB
- Keyword string
- OrderBy string
- PageNum int
- PageSize int
+ Orm *gorm.DB
+ SearchMap map[string]interface{}
+ OrderBy string
+ PageNum int
+ PageSize int
}
ContactDetail struct {
@@ -56,9 +56,6 @@
func (slf *ContactSearch) build() *gorm.DB {
var db = slf.Orm.Model(&Contact{})
- if slf.Keyword != "" {
- db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
- }
if slf.Id != 0 {
db = db.Where("id = ?", slf.Id)
}
@@ -68,6 +65,38 @@
if slf.ClientId != 0 {
db = db.Where("client_id = ?", slf.ClientId)
+ }
+
+ if len(slf.SearchMap) > 0 {
+ for key, value := range slf.SearchMap {
+ switch v := value.(type) {
+ case string:
+ if key == "name" || key == "position" || key == "phone" || key == "Number" {
+ db = db.Where(key+" LIKE ?", "%"+v+"%")
+ }
+
+ if key == "member_name" {
+ db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%")
+ }
+
+ if key == "client_name" {
+ //db = db.Joins("inner join clients on clients.id = contacts.client_id").Where("clients.name LIKE ?", "%"+v+"%")
+ db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "is_first" {
+ if v == "鏄�" {
+ db = db.Where("is_first = ?", true)
+ } else if v == "鍚�" {
+ db = db.Where("is_first = ?", false)
+ }
+ }
+ case int:
+ if key == "client_id" {
+ db = db.Where("client_id = ?", v)
+ }
+ }
+ }
}
return db
@@ -123,7 +152,6 @@
db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
}
-
err := db.Preload("FollowRecord").Preload("Client").Preload("Country").Preload("Province").Preload("City").Preload("Region").Find(&records).Error
return records, total, err
}
@@ -155,11 +183,6 @@
return db.Updates(data).Error
}
-func (slf *ContactSearch) SetKeyword(keyword string) *ContactSearch {
- slf.Keyword = keyword
- return slf
-}
-
func (slf *ContactSearch) SetPage(page, size int) *ContactSearch {
slf.PageNum, slf.PageSize = page, size
return slf
@@ -168,4 +191,13 @@
func (slf *ContactSearch) SetOrder(order string) *ContactSearch {
slf.OrderBy = order
return slf
-}
\ No newline at end of file
+}
+func (slf *ContactSearch) SetIds(ids []int) *ContactSearch {
+ slf.Orm = slf.Orm.Where("id in (?)", ids)
+ return slf
+}
+
+func (slf *ContactSearch) SetSearchMap(data map[string]interface{}) *ContactSearch {
+ slf.SearchMap = data
+ return slf
+}
--
Gitblit v1.8.0