From 5f0170df9787c6f3ff17cc168b3f2e3f511453f6 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 31 十月 2023 20:04:16 +0800
Subject: [PATCH] 支持职级降级的情况
---
model/followRecord.go | 96 +++++++++++++++++++++++++++++++++--------------
1 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/model/followRecord.go b/model/followRecord.go
index c7671f6..b220de2 100644
--- a/model/followRecord.go
+++ b/model/followRecord.go
@@ -2,29 +2,35 @@
import (
"aps_crm/pkg/mysqlx"
+ "fmt"
"gorm.io/gorm"
)
type (
FollowRecord struct {
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- 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:瀹㈡埛鐘舵�乮d"`
- MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"`
- 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:鑱旂郴浜篿d"`
- Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"`
- Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"`
- SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"`
- SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"`
- ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"`
- FollowTime *CustomTime `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"`
- NextFollowTime *CustomTime `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"`
- Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"`
- Content string `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:璺熻繘鍐呭"`
- Client Client `json:"client" gorm:"foreignKey:ClientId"`
- Contact Contact `json:"contact" gorm:"foreignKey:ContactId"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ 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:瀹㈡埛鐘舵�乮d"`
+ ClientStatus ClientStatus `json:"client_status" gorm:"foreignKey:ClientStatusId"`
+ MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:璺熻繘浜篿d"`
+ 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:鑱旂郴浜篿d"`
+ Topic string `json:"topic" gorm:"column:topic;type:varchar(255);comment:璺熻繘涓婚"`
+ Record string `json:"record" gorm:"column:record;type:MEDIUMTEXT;comment:璺熻繘璁板綍"`
+ SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int(11);comment:閿�鍞満浼歩d"`
+ SaleChance SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
+ SalesLeadsId int `json:"sales_leads_id" gorm:"column:sales_leads_id;type:int(11);comment:閿�鍞嚎绱d"`
+ SalesLeads SalesLeads `json:"sales_leads" gorm:"foreignKey:SalesLeadsId"`
+ ContactInformationId int `json:"contact_information_id" gorm:"column:contact_information_id;type:int(11);comment:鑱旂郴鏂瑰紡id"`
+ FollowTime *CustomTime `json:"follow_time" gorm:"column:follow_time;type:datetime;comment:璺熻繘鏃堕棿"`
+ NextFollowTime *CustomTime `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"`
+ Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"`
+ Content string `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:璺熻繘鍐呭"`
+ 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:"-"`
}
@@ -56,6 +62,9 @@
}
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 {
@@ -93,11 +102,13 @@
if key == "client_status" {
db = db.Joins("Client").Joins("Client.ClientStatus").Where("Client__ClientStatus.name LIKE ?", "%"+v+"%")
}
- case int:
- case int64:
- case float64:
- if key == "client_id" || key == "contact_id" || key == "sales_leads_id" || key == "sale_chance_id" {
+ case int, int64, float64:
+ 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)
}
}
}
@@ -123,14 +134,8 @@
db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
}
- err := db.Preload("Client").Preload("Contact").Order("id desc").Find(&records).Error
+ err := db.Preload("SalesLeads").Preload("SaleChance").Preload("ClientStatus").Preload("Member").Preload("Client").Preload("Contact").Preload("ContactInformation").Order("id desc").Find(&records).Error
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) {
@@ -157,6 +162,30 @@
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 {
@@ -192,3 +221,12 @@
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
+}
--
Gitblit v1.8.0