From 3369456ac6de01e8703a9b38537406ec7c550bc5 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 25 八月 2023 11:05:45 +0800
Subject: [PATCH] fix

---
 model/contact.go |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/model/contact.go b/model/contact.go
index 43d899a..01c2732 100644
--- a/model/contact.go
+++ b/model/contact.go
@@ -3,23 +3,24 @@
 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"`
+		Member   User        `json:"member" gorm:"foreignKey:MemberId"`
+		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:"-"`
 	}
@@ -80,9 +81,23 @@
 				}
 
 				if key == "client_name" {
-					db = db.Joins("inner join clients on clients.id = contacts.client_id").Where("clients.name LIKE ?", "%"+v+"%")
+					//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:
+			case int64:
+			case float64:
+				if key == "client_id" {
+					db = db.Where("client_id = ? and is_first = true", v)
+				}
 			}
 		}
 	}
@@ -140,7 +155,7 @@
 		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
+	err := db.Preload("Member").Preload("FollowRecord").Preload("Client").Preload("Country").Preload("Province").Preload("City").Preload("Region").Order("id desc").Find(&records).Error
 	return records, total, err
 }
 

--
Gitblit v1.8.0