From 5f0170df9787c6f3ff17cc168b3f2e3f511453f6 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 31 十月 2023 20:04:16 +0800
Subject: [PATCH] 支持职级降级的情况
---
model/saleChance.go | 195 ++++++++++++++++++++++++++++++++++++------------
1 files changed, 144 insertions(+), 51 deletions(-)
diff --git a/model/saleChance.go b/model/saleChance.go
index 320cafb..9cde56f 100644
--- a/model/saleChance.go
+++ b/model/saleChance.go
@@ -2,45 +2,54 @@
import (
"aps_crm/pkg/mysqlx"
+ "fmt"
"gorm.io/gorm"
- "time"
)
type (
SaleChance 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:閿�鍞嚎绱㈢紪鍙�"`
- ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篒D"`
- ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
- SalesSourcesId int `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:鍟嗘満鏉ユ簮ID"`
- SaleTypeId int `json:"sale_type_id" gorm:"column:sale_type_id;type:int(11);comment:鍟嗘満绫诲瀷ID"`
- SaleStageId int `json:"sale_stage_id" gorm:"column:sale_stage_id;type:int(11);comment:鍟嗘満闃舵ID"`
- MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:閿�鍞礋璐d汉ID"`
- RegularCustomersId int `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:甯稿ID"`
- Competitors string `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:绔炰簤瀵规墜"`
- PossibilitiesId int `json:"possibilities_id" gorm:"column:possibilities_id;type:int(11);comment:鍙兘鎬D"`
- Budget float64 `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:棰勭畻"`
- ProjectedAmount float64 `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:棰勮閲戦"`
- Currency int `json:"currency" gorm:"column:currency;type:int(11);comment:甯佺"`
- ExpectedTime time.Time `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:棰勮鎴愪氦鏃堕棿"`
- StatusId int `json:"status_id" gorm:"column:status_id;type:int(11);comment:鐘舵�両D"`
- PainPoints string `json:"pain_points" gorm:"column:pain_points;type:text;comment:鐥涚偣"`
- WhetherEstablished string `json:"whether_established" gorm:"column:whether_established;type:text;comment:鏄惁鎴愮珛"`
- CapitalBudget string `json:"capital_budget" gorm:"column:capital_budget;type:text;comment:璧勯噾棰勭畻"`
- KeyMaker string `json:"key_maker" gorm:"column:key_maker;type:text;comment:鍏抽敭浜�"`
- KeyFactors string `json:"key_factors" gorm:"column:key_factors;type:text;comment:鍏抽敭鍥犵礌"`
- Process string `json:"process" gorm:"column:process;type:text;comment:鍐崇瓥娴佺▼"`
- Solutions string `json:"solutions" gorm:"column:solutions;type:text;comment:绔炰簤瀵规墜瑙e喅鏂规"`
- Advantages string `json:"advantages" gorm:"column:advantages;type:text;comment:绔炰簤浼樺娍"`
- Disadvantages string `json:"disadvantages" gorm:"column:disadvantages;type:text;comment:绔炰簤鍔e娍"`
- Opportunities string `json:"opportunities" gorm:"column:opportunities;type:text;comment:绔炰簤鏈轰細"`
- Threats string `json:"threats" gorm:"column:threats;type:text;comment:绔炰簤濞佽儊"`
- DetailAddress string `json:"detail_address" gorm:"column:detail_address;type:text;comment:璇︾粏鍦板潃"`
- Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
- Contact Contact `json:"contact" gorm:"foreignKey:ContactId;references:Id"`
- Client Client `json:"client" gorm:"foreignKey:ClientId;references:Id"`
- SalesSources SalesSources
+ 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:閿�鍞嚎绱㈢紪鍙�"`
+ ContactId int `json:"contact_id" gorm:"column:contact_id;type:int(11);comment:鑱旂郴浜篒D"`
+ Contact Contact `json:"contact" gorm:"foreignKey:ContactId;references:Id"`
+ ClientId int `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
+ SalesSourcesId int `json:"sales_sources_id" gorm:"column:sales_sources_id;type:int(11);comment:鍟嗘満鏉ユ簮ID"`
+ SaleTypeId int `json:"sale_type_id" gorm:"column:sale_type_id;type:int(11);comment:鍟嗘満绫诲瀷ID"`
+ SaleType SaleType `json:"sale_type" `
+ SaleStageId int `json:"sale_stage_id" gorm:"column:sale_stage_id;type:int(11);comment:鍟嗘満闃舵ID"`
+ SaleStage SaleStage `json:"sale_stage" gorm:"foreignKey:SaleStageId;references:Id"`
+ MemberId int `json:"member_id" gorm:"column:member_id;type:int(11);comment:閿�鍞礋璐d汉ID"`
+ Member User `json:"member" gorm:"foreignKey:MemberId"`
+ RegularCustomersId int `json:"regular_customers_id" gorm:"column:regular_customers_id;type:int(11);comment:甯稿ID"`
+ RegularCustomers RegularCustomers `json:"regular_customers"`
+ Competitors string `json:"competitors" gorm:"column:competitors;type:varchar(255);comment:绔炰簤瀵规墜"`
+ PossibilitiesId int `json:"possibilities_id" gorm:"column:possibilities_id;type:int(11);comment:鍙兘鎬D"`
+ Possibility Possibility `json:"possibility" gorm:"foreignKey:PossibilitiesId;references:Id"`
+ Budget float64 `json:"budget" gorm:"column:budget;type:decimal(10,2);comment:棰勭畻"`
+ ProjectedAmount float64 `json:"projected_amount" gorm:"column:projected_amount;type:decimal(10,2);comment:棰勮閲戦"`
+ Currency int `json:"currency" gorm:"column:currency;type:int(11);comment:甯佺"`
+ ExpectedTime *CustomTime `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:棰勮鎴愪氦鏃堕棿"`
+ StatusId int `json:"status_id" gorm:"column:status_id;type:int(11);comment:鐘舵�両D"`
+ Status Status `json:"status"` //鐘舵��
+ PainPoints string `json:"pain_points" gorm:"column:pain_points;type:text;comment:鐥涚偣"`
+ WhetherEstablished string `json:"whether_established" gorm:"column:whether_established;type:text;comment:鏄惁鎴愮珛"`
+ CapitalBudget string `json:"capital_budget" gorm:"column:capital_budget;type:text;comment:璧勯噾棰勭畻"`
+ KeyMaker string `json:"key_maker" gorm:"column:key_maker;type:text;comment:鍏抽敭浜�"`
+ KeyFactors string `json:"key_factors" gorm:"column:key_factors;type:text;comment:鍏抽敭鍥犵礌"`
+ Process string `json:"process" gorm:"column:process;type:text;comment:鍐崇瓥娴佺▼"`
+ Solutions string `json:"solutions" gorm:"column:solutions;type:text;comment:绔炰簤瀵规墜瑙e喅鏂规"`
+ Advantages string `json:"advantages" gorm:"column:advantages;type:text;comment:绔炰簤浼樺娍"`
+ Disadvantages string `json:"disadvantages" gorm:"column:disadvantages;type:text;comment:绔炰簤鍔e娍"`
+ Opportunities string `json:"opportunities" gorm:"column:opportunities;type:text;comment:绔炰簤鏈轰細"`
+ Threats string `json:"threats" gorm:"column:threats;type:text;comment:绔炰簤濞佽儊"`
+ DetailAddress string `json:"detail_address" gorm:"column:detail_address;type:text;comment:璇︾粏鍦板潃"`
+ Remark string `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
+ Client Client `json:"client" gorm:"foreignKey:ClientId;references:Id"`
+ CollectionProjections []CollectionProjection `json:"collection_projections" gorm:"foreignKey:SaleChanceId"`
+ SalesSources SalesSources `json:"sales_sources"`
+ CodeStandID string `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
+ Products []*Product `json:"products" gorm:"many2many:SaleChanceProduct;"`
Address
gorm.Model `json:"-"`
}
@@ -48,11 +57,11 @@
SaleChanceSearch struct {
SaleChance
- Orm *gorm.DB
- Keyword string
- OrderBy string
- PageNum int
- PageSize int
+ Orm *gorm.DB
+ SearchMap map[string]interface{}
+ OrderBy string
+ PageNum int
+ PageSize int
}
)
@@ -66,14 +75,58 @@
func (slf *SaleChanceSearch) build() *gorm.DB {
var db = slf.Orm.Model(&SaleChance{})
- if slf.Keyword != "" {
- db = db.Where("name LIKE ?", "%"+slf.Keyword+"%")
- }
if slf.Id > 0 {
db = db.Where("id = ?", slf.Id)
}
if slf.Name != "" {
db = db.Where("name = ?", slf.Name)
+ }
+ if slf.Number != "" {
+ db = db.Where("number = ?", slf.Number)
+ }
+
+ if len(slf.SearchMap) > 0 {
+ for key, value := range slf.SearchMap {
+ switch v := value.(type) {
+ case string:
+ if key == "name" || key == "number" {
+ db = db.Where(key+" LIKE ?", "%"+v+"%")
+ }
+
+ if key == "client_name" {
+ db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "contact_name" {
+ db = db.Joins("Contact").Where("Contact.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "member_name" {
+ db = db.Joins("User").Where("User.username LIKE ?", "%"+v+"%")
+ }
+
+ if key == "sale_stage" {
+ db = db.Joins("SaleStage").Where("SaleStage.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "possibilities" {
+ db = db.Joins("Possibilities").Where("Possibilities.name LIKE ?", "%"+v+"%")
+ }
+
+ if key == "expected_time" {
+ db = db.Where("expected_time LIKE ?", "%"+v+"%")
+ }
+
+ case int, float64:
+ if key == "member_id" || key == "budget" || key == "projected_amount" || key == "client_id" {
+ db = db.Where(key+" = ?", v)
+ }
+ case []int:
+ if key == "member_ids" {
+ db = db.Where("sale_chance.member_id in ?", v)
+ }
+ }
+ }
}
return db
@@ -87,7 +140,7 @@
func (slf *SaleChanceSearch) Update(record *SaleChance) (err error) {
var db = slf.build()
- err = db.Updates(record).Error
+ err = db.Preload("Products").Updates(record).Error
return
}
@@ -99,7 +152,7 @@
func (slf *SaleChanceSearch) Find() (record SaleChance, err error) {
var db = slf.build()
- err = db.First(&record).Error
+ err = db.Preload("Products").First(&record).Error
return
}
@@ -114,8 +167,18 @@
db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
}
- err := db.Preload("Client").Preload("Contact").Find(&records).Error
+ err := db.Preload("SaleType").Preload("RegularCustomers").Preload("SalesSources").Preload("Products").
+ Preload("Member").Preload("SaleStage").Preload("Possibility").
+ Preload("CollectionProjections").Preload("Client").
+ Preload("Province").Preload("City").Preload("Contact").Preload("Status").Order("id desc").Find(&records).Error
return records, total, err
+}
+
+func (slf *SaleChanceSearch) Count() (int64, error) {
+ var db = slf.build()
+ var total int64
+ err := db.Count(&total).Error
+ return total, err
}
func (slf *SaleChanceSearch) SetId(id int) *SaleChanceSearch {
@@ -128,11 +191,6 @@
return slf
}
-func (slf *SaleChanceSearch) SetKeyword(keyword string) *SaleChanceSearch {
- slf.Keyword = keyword
- return slf
-}
-
func (slf *SaleChanceSearch) SetPage(page, size int) *SaleChanceSearch {
slf.PageNum, slf.PageSize = page, size
return slf
@@ -141,4 +199,39 @@
func (slf *SaleChanceSearch) SetOrder(order string) *SaleChanceSearch {
slf.OrderBy = order
return slf
-}
\ No newline at end of file
+}
+
+func (slf *SaleChanceSearch) SetNumber(number string) *SaleChanceSearch {
+ slf.Number = number
+ return slf
+}
+
+func (slf *SaleChanceSearch) SetSearchMap(searchMap map[string]interface{}) *SaleChanceSearch {
+ slf.SearchMap = searchMap
+ return slf
+}
+func (slf *SaleChanceSearch) SetIds(ids []int) *SaleChanceSearch {
+ slf.Orm = slf.Orm.Where("id in (?)", ids)
+ return slf
+}
+func (slf *SaleChanceSearch) UpdateByMap(data map[string]interface{}) error {
+ var db = slf.build()
+ return db.Updates(data).Error
+}
+
+func (slf *SaleChanceSearch) 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
+}
--
Gitblit v1.8.0