From 18939d88db4799b2ba0359016d9a4ae1e76e2a22 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 29 三月 2024 14:01:35 +0800
Subject: [PATCH] 完善

---
 models/operation.go |   57 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/models/operation.go b/models/operation.go
index a81b5ae..63f9cc5 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -22,18 +22,19 @@
 		//FromLocation      Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃�
 		//ToLocationID      int                      `json:"toLocationId"    gorm:"type:int;not null;comment:鐩爣浣嶇疆id"`         //鐩爣浣嶇疆id
 		//ToLocation        Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"`    //鐩爣浣嶇疆
-		OperationDate     string          `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"`
-		ContacterID       int             `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
-		ContacterName     string          `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
-		CompanyID         int             `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"`
-		CompanyName       string          `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
-		Comment           string          `json:"comment" gorm:"type:text;comment:澶囨敞"`
-		LogisticCompanyId string          `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:鐗╂祦鍏徃id"`
-		LogisticCompany   LogisticCompany `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
-		WaybillNumber     string          `json:"waybillNumber" gorm:"type:varchar(255);comment:杩愬崟鍙�"`    //杩愬崟鍙�
-		Weight            decimal.Decimal `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"`           //閲嶉噺
-		LogisticWeight    decimal.Decimal `gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺" json:"logisticWeight"` //鐗╂祦閲嶉噺
-		Source            string          `json:"source" gorm:"type:varchar(255);comment:鏉ユ簮绯荤粺,鐢ㄤ簬杩斿洖淇敼鐘舵��"`
+		OperationDate     string                   `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"`
+		ContacterID       int                      `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
+		ContacterName     string                   `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
+		CompanyID         int                      `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"`
+		CompanyName       string                   `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
+		Comment           string                   `json:"comment" gorm:"type:text;comment:澶囨敞"`
+		LogisticCompanyId string                   `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:鐗╂祦鍏徃id"`
+		LogisticCompany   LogisticCompany          `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
+		WaybillNumber     string                   `json:"waybillNumber" gorm:"type:varchar(255);comment:杩愬崟鍙�"`    //杩愬崟鍙�
+		Weight            decimal.Decimal          `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"`           //閲嶉噺
+		LogisticWeight    decimal.Decimal          `gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺" json:"logisticWeight"` //鐗╂祦閲嶉噺
+		Source            string                   `json:"source" gorm:"type:varchar(255);comment:鏉ユ簮绯荤粺,鐢ㄤ簬杩斿洖淇敼鐘舵��"`
+		OperationSource   constvar.OperationSource `json:"operationSource" gorm:"type:tinyint(3);not null;default:0;comment:鎿嶄綔鏉ユ簮"` //鎿嶄綔鏉ユ簮
 
 		Details           []*OperationDetails        `json:"details" gorm:"foreignKey:OperationID;references:Id"`
 		BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
@@ -43,10 +44,11 @@
 		ReceiverPhone string `json:"receiverPhone" gorm:"type:varchar(31);comment:鑱旂郴鐢佃瘽"`
 		ReceiverAddr  string `json:"receiverAddr" gorm:"type:varchar(255);comment:鏀惰揣鍦板潃"`
 
-		LocationID   int      `json:"locationID"   gorm:"type:int;not null;comment:婧愪綅缃甶d"`          //婧愪綅缃甶d
-		Location     Location `json:"location" gorm:"foreignkey:LocationID;references:Id"`          //婧愪綅缃�
-		ToLocationID int      `json:"toLocationId"    gorm:"type:int;not null;comment:浠撳簱浣嶇疆id"`      //鐩爣浣嶇疆id
-		ToLocation   Location `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆
+		LocationID         int      `json:"locationID"   gorm:"type:int;not null;comment:婧愪綅缃甶d"`          //婧愪綅缃甶d
+		Location           Location `json:"location" gorm:"foreignkey:LocationID;references:Id"`          //婧愪綅缃�
+		ToLocationID       int      `json:"toLocationId"    gorm:"type:int;not null;comment:浠撳簱浣嶇疆id"`      //鐩爣浣嶇疆id
+		ToLocation         Location `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆
+		SalesDetailsNumber string   `gorm:"type:varchar(191);comment:閿�鍞槑缁嗙紪鐮�" json:"salesDetailsNumber"`
 	}
 
 	OperationSearch struct {
@@ -136,6 +138,11 @@
 	return slf
 }
 
+func (slf *OperationSearch) SetSalesDetailsNumber(salesDetailsNumber string) *OperationSearch {
+	slf.SalesDetailsNumber = salesDetailsNumber
+	return slf
+}
+
 func (slf *OperationSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Operation{})
 
@@ -151,7 +158,7 @@
 	}
 
 	if slf.SourceNumber != "" {
-		db = db.Where("source_number like ?", fmt.Sprintf("%%%v%%", slf.SourceNumber))
+		db = db.Where("source_number = ?", slf.SourceNumber)
 	}
 
 	if slf.Number != "" {
@@ -180,6 +187,10 @@
 
 	if slf.BaseOperationType != 0 {
 		db = db.Where("base_operation_type = ?", slf.BaseOperationType)
+	}
+
+	if slf.SalesDetailsNumber != "" {
+		db = db.Where("sales_details_number = ?", slf.SalesDetailsNumber)
 	}
 
 	return db
@@ -298,7 +309,7 @@
 	if slf.PageNum*slf.PageSize > 0 {
 		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
 	}
-	if err := db.Preload("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil {
+	if err := db.Find(&records).Error; err != nil {
 		return records, fmt.Errorf("find records err: %v", err)
 	}
 
@@ -354,3 +365,13 @@
 	}
 	return int(total), nil
 }
+
+func (slf *OperationSearch) Count() (int64, error) {
+	var (
+		total int64
+		db    = slf.build()
+	)
+
+	err := db.Count(&total).Error
+	return total, err
+}

--
Gitblit v1.8.0