From c92534229c83436ffe9e6752209200dd70b77808 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期四, 17 八月 2023 19:19:44 +0800
Subject: [PATCH] add
---
model/quotation.go | 44 +++++++++++++++++++++++---------------------
1 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/model/quotation.go b/model/quotation.go
index 61061ae..99d70fe 100644
--- a/model/quotation.go
+++ b/model/quotation.go
@@ -8,20 +8,22 @@
type (
// Quotation 鎶ヤ环鍗�
Quotation struct {
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- ClientId int `json:"client_id" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
- Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鎶ヤ环鍗曞彿"`
- QuotationStatusId int `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:鎶ヤ环鍗曠姸鎬乮d"`
- ValidityDate *CustomTime `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:鏈夋晥鏈�"`
- ContactId int `json:"contact_id" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
- MemberId int `json:"member_id" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
- SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
- Conditions string `json:"conditions" gorm:"column:conditions;type:text;comment:鎶ヤ环鏉′欢"`
- File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"`
- Client Client `json:"client" gorm:"foreignKey:ClientId"`
- Contact Contact `json:"contact" gorm:"foreignKey:ContactId"`
- SaleChance SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
- Products []Product `json:"products" gorm:"many2many:quotation_product"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ ClientId int `json:"client_id" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+ Number string `json:"number" gorm:"column:number;type:varchar(255);comment:鎶ヤ环鍗曞彿"`
+ QuotationStatusId int `json:"quotation_status_id" gorm:"column:quotation_status_id;type:int;comment:鎶ヤ环鍗曠姸鎬乮d"`
+ QuotationStatus QuotationStatus `json:"quotation_status" gorm:"foreignKey:QuotationStatusId"`
+ ValidityDate *CustomTime `json:"validity_date" gorm:"column:validity_date;type:datetime;comment:鏈夋晥鏈�"`
+ ContactId int `json:"contact_id" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+ MemberId int `json:"member_id" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+ Member User `json:"member" gorm:"foreignKey:MemberId"`
+ SaleChanceId int `json:"sale_chance_id" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
+ Conditions string `json:"conditions" gorm:"column:conditions;type:text;comment:鎶ヤ环鏉′欢"`
+ File string `json:"file" gorm:"column:file;type:varchar(255);comment:闄勪欢"`
+ Client Client `json:"client" gorm:"foreignKey:ClientId"`
+ Contact Contact `json:"contact" gorm:"foreignKey:ContactId"`
+ SaleChance SaleChance `json:"sale_chance" gorm:"foreignKey:SaleChanceId"`
+ Products []Product `json:"products" gorm:"many2many:quotation_product"`
gorm.Model `json:"-"`
}
@@ -57,20 +59,20 @@
for key, value := range slf.SearchMap {
switch v := value.(type) {
case string:
- if key == "validity_date" || key == "number" {
- db = db.Where(key+" = ?", v)
+ if key == "number" || key == "validity_date" {
+ db = db.Where(key+" LIKE ?", "%"+v+"%")
}
if key == "client_name" {
- db = db.Joins("Client").Where("client.name = ?", v)
+ db = db.Joins("Client").Where("Client.name LIKE ?", "%"+v+"%")
}
if key == "contact_name" {
- db = db.Joins("Contact").Where("contact.name = ?", v)
+ db = db.Joins("Contact").Where("Contact.name LIKE ?", "%"+v+"%")
}
- if key == "validity_date" {
- db = db.Where(key+" = ?", v)
+ if key == "member_name" {
+ db = db.Joins("Member").Where("Member.username LIKE ?", "%"+v+"%")
}
case int:
@@ -117,7 +119,7 @@
db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
}
- err := db.Find(&records).Error
+ err := db.Preload("Member").Preload("QuotationStatus").Preload("Client").Preload("Contact").Order("id desc").Find(&records).Error
return records, total, err
}
--
Gitblit v1.8.0