From d8c708a30d938ceb87348257add9dc10926044df Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期二, 24 十月 2023 20:08:02 +0800
Subject: [PATCH] 编码规则需求功能开发2

---
 model/severity.go             |    2 
 api/v1/client.go              |    2 
 model/contract.go             |    1 
 model/request/salesDetails.go |    1 
 api/v1/code.go                |    2 
 api/v1/serviceOrder.go        |    2 
 docs/swagger.yaml             |   39 +++++
 docs/docs.go                  |   54 ++++++++
 service/invoice.go            |    2 
 docs/swagger.json             |   54 ++++++++
 model/request/serviceOrder.go |    2 
 model/request/invoice.go      |   56 +++++----
 model/request/contract.go     |    1 
 api/v1/salesRefund.go         |    2 
 model/serviceOrder.go         |    8 
 model/salesDetails.go         |    5 
 api/v1/invoice.go             |    9 +
 model/salesRefund.go          |   14 +-
 model/client.go               |    3 
 service/salesRefund.go        |   14 +-
 model/invoice.go              |   34 +++++
 21 files changed, 242 insertions(+), 65 deletions(-)

diff --git a/api/v1/client.go b/api/v1/client.go
index bca5872..d7dc42e 100644
--- a/api/v1/client.go
+++ b/api/v1/client.go
@@ -41,7 +41,7 @@
 		return
 	}
 
-	count, err := model.NewClientSearch(nil).SetNumber(params.Number).Count()
+	count, err := model.NewClientSearch(nil).SetNumber(client.Number).Count()
 	if err != nil {
 		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜楠岃瘉澶辫触")
 		return
diff --git a/api/v1/code.go b/api/v1/code.go
index 2514e44..a94cb5a 100644
--- a/api/v1/code.go
+++ b/api/v1/code.go
@@ -122,6 +122,8 @@
 		id, err = model.NewServiceOrderSearch().MaxAutoIncr()
 	case constvar.CodeStandardTypeServerFollow:
 		id, err = model.NewServiceFollowupSearch().MaxAutoIncr()
+	case constvar.CodeStandardTypeSaleInvoice:
+		id, err = model.NewInvoiceSearch().MaxAutoIncr()
 	default:
 		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜瑙勫垯涓嶅瓨鍦�")
 		return
diff --git a/api/v1/invoice.go b/api/v1/invoice.go
index c451f3c..3c51eb3 100644
--- a/api/v1/invoice.go
+++ b/api/v1/invoice.go
@@ -34,6 +34,15 @@
 		ctx.Fail(ecode.ParamsErr)
 		return
 	}
+	count, err := model.NewInvoiceSearch().SetNumber(invoice.Number).Count()
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜楠岃瘉澶辫触")
+		return
+	}
+	if count > 0 {
+		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜宸插瓨鍦�")
+		return
+	}
 
 	errCode := service.NewInvoiceService().AddInvoice(&invoice)
 	if errCode != ecode.OK {
diff --git a/api/v1/salesRefund.go b/api/v1/salesRefund.go
index 2c30b99..00ce774 100644
--- a/api/v1/salesRefund.go
+++ b/api/v1/salesRefund.go
@@ -160,7 +160,7 @@
 	salesRefundRes.Reason = salesRefund.Reason
 	salesRefundRes.Products = salesRefund.Products
 	salesRefundRes.SourceType = salesRefund.SourceType
-	salesRefundRes.SourceId = salesRefund.SourceId
+	salesRefundRes.SalesReturnId = salesRefund.SourceId
 	salesRefundRes.CodeStandID = salesRefund.CodeStandID
 
 	return ecode.OK, salesRefundRes
diff --git a/api/v1/serviceOrder.go b/api/v1/serviceOrder.go
index b2bd4f1..e557bd7 100644
--- a/api/v1/serviceOrder.go
+++ b/api/v1/serviceOrder.go
@@ -42,7 +42,7 @@
 		return
 	}
 
-	count, err := model.NewServiceOrderSearch().SetNumber(serviceOrder.Number).Count()
+	count, err := model.NewServiceOrderSearch().SetNumber(serviceOrder.ServiceNumber).Count()
 	if err != nil {
 		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜楠岃瘉澶辫触")
 		return
diff --git a/docs/docs.go b/docs/docs.go
index b6d87f1..bf61850 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -11351,6 +11351,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompany": {
                     "$ref": "#/definitions/model.CourierCompany"
                 },
@@ -11386,6 +11389,9 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -12205,6 +12211,12 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotation": {
+                    "$ref": "#/definitions/model.Quotation"
+                },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -12322,9 +12334,6 @@
                         }
                     ]
                 },
-                "Source": {
-                    "$ref": "#/definitions/model.SalesReturn"
-                },
                 "amountTotal": {
                     "description": "浠风◣鍚堣",
                     "type": "number"
@@ -12388,6 +12397,9 @@
                 "refundTypeId": {
                     "description": "閫�娆炬柟寮廔D",
                     "type": "integer"
+                },
+                "salesReturn": {
+                    "$ref": "#/definitions/model.SalesReturn"
                 },
                 "sourceId": {
                     "description": "婧愬崟id",
@@ -13007,6 +13019,10 @@
                 "severity": {
                     "$ref": "#/definitions/model.Severity"
                 },
+                "severityId": {
+                    "description": "涓ラ噸绋嬪害id",
+                    "type": "integer"
+                },
                 "solution": {
                     "description": "瑙e喅鏂规硶",
                     "type": "string"
@@ -13561,6 +13577,10 @@
                 "quotation_id": {
                     "type": "integer"
                 },
+                "sendTime": {
+                    "description": "鍙戣揣鏃堕棿s",
+                    "type": "string"
+                },
                 "status_id": {
                     "type": "integer"
                 }
@@ -13701,6 +13721,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompanyId": {
                     "description": "鐗╂祦鍏徃",
                     "type": "integer"
@@ -13724,6 +13747,10 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "description": "鍙戠エ缂栧彿",
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -14330,6 +14357,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -14815,7 +14845,7 @@
                     "description": "鏈嶅姟鏂瑰紡id",
                     "type": "integer"
                 },
-                "severity": {
+                "severityId": {
                     "description": "涓ラ噸绋嬪害id",
                     "type": "integer"
                 },
@@ -15890,6 +15920,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -16481,6 +16514,10 @@
                 "quotation_id": {
                     "type": "integer"
                 },
+                "sendTime": {
+                    "description": "鍙戣揣鏃堕棿s",
+                    "type": "string"
+                },
                 "status_id": {
                     "type": "integer"
                 }
@@ -16718,6 +16755,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompanyId": {
                     "description": "鐗╂祦鍏徃",
                     "type": "integer"
@@ -16744,6 +16784,10 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "description": "鍙戠エ缂栧彿",
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -18196,7 +18240,7 @@
                     "description": "鏈嶅姟鏂瑰紡id",
                     "type": "integer"
                 },
-                "severity": {
+                "severityId": {
                     "description": "涓ラ噸绋嬪害id",
                     "type": "integer"
                 },
diff --git a/docs/swagger.json b/docs/swagger.json
index 29ed80e..28a34e8 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -11339,6 +11339,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompany": {
                     "$ref": "#/definitions/model.CourierCompany"
                 },
@@ -11374,6 +11377,9 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -12193,6 +12199,12 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotation": {
+                    "$ref": "#/definitions/model.Quotation"
+                },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -12310,9 +12322,6 @@
                         }
                     ]
                 },
-                "Source": {
-                    "$ref": "#/definitions/model.SalesReturn"
-                },
                 "amountTotal": {
                     "description": "浠风◣鍚堣",
                     "type": "number"
@@ -12376,6 +12385,9 @@
                 "refundTypeId": {
                     "description": "閫�娆炬柟寮廔D",
                     "type": "integer"
+                },
+                "salesReturn": {
+                    "$ref": "#/definitions/model.SalesReturn"
                 },
                 "sourceId": {
                     "description": "婧愬崟id",
@@ -12995,6 +13007,10 @@
                 "severity": {
                     "$ref": "#/definitions/model.Severity"
                 },
+                "severityId": {
+                    "description": "涓ラ噸绋嬪害id",
+                    "type": "integer"
+                },
                 "solution": {
                     "description": "瑙e喅鏂规硶",
                     "type": "string"
@@ -13549,6 +13565,10 @@
                 "quotation_id": {
                     "type": "integer"
                 },
+                "sendTime": {
+                    "description": "鍙戣揣鏃堕棿s",
+                    "type": "string"
+                },
                 "status_id": {
                     "type": "integer"
                 }
@@ -13689,6 +13709,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompanyId": {
                     "description": "鐗╂祦鍏徃",
                     "type": "integer"
@@ -13712,6 +13735,10 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "description": "鍙戠エ缂栧彿",
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -14318,6 +14345,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -14803,7 +14833,7 @@
                     "description": "鏈嶅姟鏂瑰紡id",
                     "type": "integer"
                 },
-                "severity": {
+                "severityId": {
                     "description": "涓ラ噸绋嬪害id",
                     "type": "integer"
                 },
@@ -15878,6 +15908,9 @@
                         "$ref": "#/definitions/model.Product"
                     }
                 },
+                "quotationId": {
+                    "type": "integer"
+                },
                 "remark": {
                     "type": "string"
                 },
@@ -16469,6 +16502,10 @@
                 "quotation_id": {
                     "type": "integer"
                 },
+                "sendTime": {
+                    "description": "鍙戣揣鏃堕棿s",
+                    "type": "string"
+                },
                 "status_id": {
                     "type": "integer"
                 }
@@ -16706,6 +16743,9 @@
                     "description": "瀹㈡埛id",
                     "type": "integer"
                 },
+                "codeStandID": {
+                    "type": "string"
+                },
                 "courierCompanyId": {
                     "description": "鐗╂祦鍏徃",
                     "type": "integer"
@@ -16732,6 +16772,10 @@
                 "invoiceTypeId": {
                     "description": "鍙戠エ绫诲瀷id",
                     "type": "integer"
+                },
+                "number": {
+                    "description": "鍙戠エ缂栧彿",
+                    "type": "string"
                 },
                 "principalId": {
                     "description": "閿�鍞礋璐d汉id",
@@ -18184,7 +18228,7 @@
                     "description": "鏈嶅姟鏂瑰紡id",
                     "type": "integer"
                 },
-                "severity": {
+                "severityId": {
                     "description": "涓ラ噸绋嬪害id",
                     "type": "integer"
                 },
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 1e7b9cb..28a52ba 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -895,6 +895,8 @@
       clientId:
         description: 瀹㈡埛id
         type: integer
+      codeStandID:
+        type: string
       courierCompany:
         $ref: '#/definitions/model.CourierCompany'
       courierCompanyId:
@@ -921,6 +923,8 @@
       invoiceTypeId:
         description: 鍙戠エ绫诲瀷id
         type: integer
+      number:
+        type: string
       principalId:
         description: 閿�鍞礋璐d汉id
         type: integer
@@ -1457,6 +1461,10 @@
         items:
           $ref: '#/definitions/model.Product'
         type: array
+      quotation:
+        $ref: '#/definitions/model.Quotation'
+      quotationId:
+        type: integer
       remark:
         type: string
       saleChance:
@@ -1533,8 +1541,6 @@
         allOf:
         - $ref: '#/definitions/model.RefundType'
         description: 閫�娆炬柟寮�
-      Source:
-        $ref: '#/definitions/model.SalesReturn'
       amountTotal:
         description: 浠风◣鍚堣
         type: number
@@ -1579,6 +1585,8 @@
       refundTypeId:
         description: 閫�娆炬柟寮廔D
         type: integer
+      salesReturn:
+        $ref: '#/definitions/model.SalesReturn'
       sourceId:
         description: 婧愬崟id
         type: integer
@@ -1996,6 +2004,9 @@
         type: integer
       severity:
         $ref: '#/definitions/model.Severity'
+      severityId:
+        description: 涓ラ噸绋嬪害id
+        type: integer
       solution:
         description: 瑙e喅鏂规硶
         type: string
@@ -2378,6 +2389,9 @@
         type: string
       quotation_id:
         type: integer
+      sendTime:
+        description: 鍙戣揣鏃堕棿s
+        type: string
       status_id:
         type: integer
     type: object
@@ -2468,6 +2482,8 @@
       clientId:
         description: 瀹㈡埛id
         type: integer
+      codeStandID:
+        type: string
       courierCompanyId:
         description: 鐗╂祦鍏徃
         type: integer
@@ -2486,6 +2502,9 @@
       invoiceTypeId:
         description: 鍙戠エ绫诲瀷id
         type: integer
+      number:
+        description: 鍙戠エ缂栧彿
+        type: string
       principalId:
         description: 閿�鍞礋璐d汉id
         type: integer
@@ -2883,6 +2902,8 @@
         items:
           $ref: '#/definitions/model.Product'
         type: array
+      quotationId:
+        type: integer
       remark:
         type: string
       saleChanceId:
@@ -3221,7 +3242,7 @@
       serviceTypeId:
         description: 鏈嶅姟鏂瑰紡id
         type: integer
-      severity:
+      severityId:
         description: 涓ラ噸绋嬪害id
         type: integer
       solution:
@@ -3975,6 +3996,8 @@
         items:
           $ref: '#/definitions/model.Product'
         type: array
+      quotationId:
+        type: integer
       remark:
         type: string
       saleChanceId:
@@ -4381,6 +4404,9 @@
         type: string
       quotation_id:
         type: integer
+      sendTime:
+        description: 鍙戣揣鏃堕棿s
+        type: string
       status_id:
         type: integer
     type: object
@@ -4534,6 +4560,8 @@
       clientId:
         description: 瀹㈡埛id
         type: integer
+      codeStandID:
+        type: string
       courierCompanyId:
         description: 鐗╂祦鍏徃
         type: integer
@@ -4554,6 +4582,9 @@
       invoiceTypeId:
         description: 鍙戠エ绫诲瀷id
         type: integer
+      number:
+        description: 鍙戠エ缂栧彿
+        type: string
       principalId:
         description: 閿�鍞礋璐d汉id
         type: integer
@@ -5533,7 +5564,7 @@
       serviceTypeId:
         description: 鏈嶅姟鏂瑰紡id
         type: integer
-      severity:
+      severityId:
         description: 涓ラ噸绋嬪害id
         type: integer
       solution:
diff --git a/model/client.go b/model/client.go
index a9a5e1c..590c079 100644
--- a/model/client.go
+++ b/model/client.go
@@ -71,6 +71,9 @@
 	if slf.Name != "" {
 		db.Where("name = ?", slf.Name)
 	}
+	if slf.Number != "" {
+		db.Where("number = ?", slf.Number)
+	}
 
 	if len(slf.SearchMap) > 0 {
 		for key, value := range slf.SearchMap {
diff --git a/model/contract.go b/model/contract.go
index 4617805..63dd9cf 100644
--- a/model/contract.go
+++ b/model/contract.go
@@ -22,6 +22,7 @@
 		File                  string                `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
 		CreatedAt             *CustomTime           `json:"created_at" gorm:"column:created_at;type:datetime;comment:鍒涘缓鏃堕棿"`
 		CodeStandID           string                `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
+		//SendTime              string                `json:"sendTime" gorm:"column:send_time;type:varchar(255);comment:鍙戣揣鏃堕棿"`
 		gormModel
 	}
 
diff --git a/model/invoice.go b/model/invoice.go
index 48ddcd2..0db64fa 100644
--- a/model/invoice.go
+++ b/model/invoice.go
@@ -12,6 +12,7 @@
 	// Invoice 閿�鍞彂绁�
 	Invoice struct {
 		Id               int                        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Number           string                     `json:"number" gorm:"column:number;type:varchar(255);comment:鍙戠エ缂栧彿"`
 		ClientId         int                        `gorm:"client_id" json:"clientId"` // 瀹㈡埛id
 		Client           Client                     `gorm:"foreignKey:ClientId"`
 		InvoiceTypeId    int                        `gorm:"invoice_type_id" json:"invoiceTypeId"` // 鍙戠エ绫诲瀷id
@@ -29,6 +30,7 @@
 		CourierCompanyId int                        `gorm:"courier_company_id" json:"courierCompanyId"` // 鐗╂祦鍏徃
 		CourierCompany   CourierCompany             `gorm:"foreignKey:CourierCompanyId"`
 		Products         []*Product                 `json:"products" gorm:"many2many:invoice_product;"`
+		CodeStandID      string                     `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
 	}
 
 	// InvoiceSearch 閿�鍞彂绁ㄦ悳绱㈡潯浠�
@@ -76,6 +78,9 @@
 	if slf.SourceId > 0 {
 		db = db.Where("source_id = ?", slf.SourceId)
 	}
+	if slf.Number != "" {
+		db.Where("number = ?", slf.Number)
+	}
 
 	return db
 }
@@ -107,6 +112,35 @@
 	return record, err
 }
 
+func (slf *InvoiceSearch) Count() (int64, error) {
+	var db = slf.build()
+	var total int64
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *InvoiceSearch) 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 *InvoiceSearch) SetNumber(number string) *InvoiceSearch {
+	slf.Number = number
+	return slf
+}
+
 func (slf *InvoiceSearch) SetId(id int) *InvoiceSearch {
 	slf.Id = id
 	return slf
diff --git a/model/request/contract.go b/model/request/contract.go
index 9a939f8..e051bb6 100644
--- a/model/request/contract.go
+++ b/model/request/contract.go
@@ -13,6 +13,7 @@
 	StatusId     int    `json:"status_id"`
 	File         string `json:"file"`
 	CodeStandID  string `json:"codeStandID"` //缂栫爜id
+	SendTime     string `json:"sendTime"`    //鍙戣揣鏃堕棿s
 }
 
 type UpdateContract struct {
diff --git a/model/request/invoice.go b/model/request/invoice.go
index 4e7c7e6..fa08e2f 100644
--- a/model/request/invoice.go
+++ b/model/request/invoice.go
@@ -6,36 +6,40 @@
 )
 
 type AddInvoice struct {
-	ClientId         int                        `gorm:"client_id" json:"clientId"`                  // 瀹㈡埛id
-	InvoiceTypeId    int                        `gorm:"invoice_type_id" json:"invoiceTypeId"`       // 鍙戠エ绫诲瀷id
-	PrincipalId      int                        `gorm:"principal_id" json:"principalId"`            // 閿�鍞礋璐d汉id
-	Subject          string                     `gorm:"subject" json:"subject"`                     // 涓婚
-	InvoiceStatusId  int                        `gorm:"invoice_status_id" json:"invoiceStatusId"`   // 鍙戠エ鐘舵�乮d
-	SourceType       constvar.InvoiceSourceType `gorm:"source_type" json:"sourceType"`              // 婧愬崟绫诲瀷(1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓)
-	SourceId         int                        `gorm:"source_id" json:"sourceId"`                  // 婧愬崟id
-	TaxpayerIdNumber string                     `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"` // 绾崇◣璇嗗埆鍙�
-	InvoiceNumber    string                     `gorm:"invoice_number" json:"invoiceNumber"`        // 鍙戠エ鍙风爜
-	InvoiceDate      string                     `gorm:"invoice_date" json:"invoiceDate"`            // 寮�绁ㄦ棩鏈�
-	CourierNumber    string                     `gorm:"courier_number" json:"courierNumber"`        // 鐗╂祦鍗曞彿
-	CourierCompanyId int                        `gorm:"courier_company_id" json:"courierCompanyId"` // 鐗╂祦鍏徃
-	Products         []model.Product            `json:"products"`                                   //鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�
+	Number           string                     `json:"number" gorm:"column:number;type:varchar(255);comment:鍙戠エ缂栧彿"` //鍙戠エ缂栧彿
+	ClientId         int                        `gorm:"client_id" json:"clientId"`                                  // 瀹㈡埛id
+	InvoiceTypeId    int                        `gorm:"invoice_type_id" json:"invoiceTypeId"`                       // 鍙戠エ绫诲瀷id
+	PrincipalId      int                        `gorm:"principal_id" json:"principalId"`                            // 閿�鍞礋璐d汉id
+	Subject          string                     `gorm:"subject" json:"subject"`                                     // 涓婚
+	InvoiceStatusId  int                        `gorm:"invoice_status_id" json:"invoiceStatusId"`                   // 鍙戠エ鐘舵�乮d
+	SourceType       constvar.InvoiceSourceType `gorm:"source_type" json:"sourceType"`                              // 婧愬崟绫诲瀷(1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓)
+	SourceId         int                        `gorm:"source_id" json:"sourceId"`                                  // 婧愬崟id
+	TaxpayerIdNumber string                     `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"`                 // 绾崇◣璇嗗埆鍙�
+	InvoiceNumber    string                     `gorm:"invoice_number" json:"invoiceNumber"`                        // 鍙戠エ鍙风爜
+	InvoiceDate      string                     `gorm:"invoice_date" json:"invoiceDate"`                            // 寮�绁ㄦ棩鏈�
+	CourierNumber    string                     `gorm:"courier_number" json:"courierNumber"`                        // 鐗╂祦鍗曞彿
+	CourierCompanyId int                        `gorm:"courier_company_id" json:"courierCompanyId"`                 // 鐗╂祦鍏徃
+	Products         []model.Product            `json:"products"`                                                   //鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�
+	CodeStandID      string                     `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
 }
 
 type UpdateInvoice struct {
 	Id               int             `json:"id" binding:"required"`
-	ClientId         int             `gorm:"client_id" json:"clientId"`                  // 瀹㈡埛id
-	InvoiceTypeId    int             `gorm:"invoice_type_id" json:"invoiceTypeId"`       // 鍙戠エ绫诲瀷id
-	PrincipalId      int             `gorm:"principal_id" json:"principalId"`            // 閿�鍞礋璐d汉id
-	Subject          string          `gorm:"subject" json:"subject"`                     // 涓婚
-	InvoiceStatusId  int             `gorm:"invoice_status_id" json:"invoiceStatusId"`   // 鍙戠エ鐘舵�乮d
-	SourceType       int             `gorm:"source_type" json:"sourceType"`              // 婧愬崟绫诲瀷(1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓)
-	SourceId         int             `gorm:"source_id" json:"sourceId"`                  // 婧愬崟id
-	TaxpayerIdNumber string          `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"` // 绾崇◣璇嗗埆鍙�
-	InvoiceNumber    string          `gorm:"invoice_number" json:"invoiceNumber"`        // 鍙戠エ鍙风爜
-	InvoiceDate      int             `gorm:"invoice_date" json:"invoiceDate"`            // 寮�绁ㄦ棩鏈�
-	CourierNumber    string          `gorm:"courier_number" json:"courierNumber"`        // 鐗╂祦鍗曞彿
-	CourierCompanyId int             `gorm:"courier_company_id" json:"courierCompanyId"` // 鐗╂祦鍏徃
-	Products         []model.Product `json:"products"`                                   //鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�
+	Number           string          `json:"number" gorm:"column:number;type:varchar(255);comment:鍙戠エ缂栧彿"` //鍙戠エ缂栧彿
+	ClientId         int             `gorm:"client_id" json:"clientId"`                                  // 瀹㈡埛id
+	InvoiceTypeId    int             `gorm:"invoice_type_id" json:"invoiceTypeId"`                       // 鍙戠エ绫诲瀷id
+	PrincipalId      int             `gorm:"principal_id" json:"principalId"`                            // 閿�鍞礋璐d汉id
+	Subject          string          `gorm:"subject" json:"subject"`                                     // 涓婚
+	InvoiceStatusId  int             `gorm:"invoice_status_id" json:"invoiceStatusId"`                   // 鍙戠エ鐘舵�乮d
+	SourceType       int             `gorm:"source_type" json:"sourceType"`                              // 婧愬崟绫诲瀷(1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓)
+	SourceId         int             `gorm:"source_id" json:"sourceId"`                                  // 婧愬崟id
+	TaxpayerIdNumber string          `gorm:"taxpayer_id_number" json:"taxpayerIdNumber"`                 // 绾崇◣璇嗗埆鍙�
+	InvoiceNumber    string          `gorm:"invoice_number" json:"invoiceNumber"`                        // 鍙戠エ鍙风爜
+	InvoiceDate      int             `gorm:"invoice_date" json:"invoiceDate"`                            // 寮�绁ㄦ棩鏈�
+	CourierNumber    string          `gorm:"courier_number" json:"courierNumber"`                        // 鐗╂祦鍗曞彿
+	CourierCompanyId int             `gorm:"courier_company_id" json:"courierCompanyId"`                 // 鐗╂祦鍏徃
+	Products         []model.Product `json:"products"`                                                   //鍙戠エ瀵瑰簲浜у搧锛屼粠鐩稿簲婧愬崟閲岃幏鍙�
+	CodeStandID      string          `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
 }
 
 type GetInvoiceList struct {
diff --git a/model/request/salesDetails.go b/model/request/salesDetails.go
index 08e425c..0b4a8bd 100644
--- a/model/request/salesDetails.go
+++ b/model/request/salesDetails.go
@@ -29,6 +29,7 @@
 	LogisticCost        float64          `json:"logisticCost" gorm:"column:logistic_cost;type:decimal(10,2);comment:鐗╂祦璐圭敤"`
 	CodeStandID         string           `json:"codeStandID"` //缂栫爜id
 	DeliverType         int              `json:"deliverType"` //浜や粯绫诲瀷:1.涓�娆″彂璐�,2.澶氭鍙戣揣
+	QuotationId         int              `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
 }
 
 type UpdateSalesDetails struct {
diff --git a/model/request/serviceOrder.go b/model/request/serviceOrder.go
index a9641dc..4805c77 100644
--- a/model/request/serviceOrder.go
+++ b/model/request/serviceOrder.go
@@ -20,7 +20,7 @@
 	AppointmentTime      string  `gorm:"appointment_time" json:"appointmentTime"`                                                                // 棰勭害涓婇棬鏃堕棿
 	SaleChanceId         int     `gorm:"sale_leads" json:"saleChanceId"`                                                                         // 閿�鍞満浼歩d
 	FaultTypeId          int     `gorm:"severity_id" json:"faultTypeId"`                                                                         // 鏁呴殰绫诲埆id
-	SeverityId           int     `gorm:"severity_id" json:"severity"`                                                                            // 涓ラ噸绋嬪害id
+	SeverityId           int     `gorm:"severity_id" json:"severityId"`                                                                          // 涓ラ噸绋嬪害id
 	ServiceOrderStatusId int     `gorm:"column:service_order_status_id;type:int;not null;default:0;comment:鏈嶅姟鍗曠姸鎬乮d" json:"serviceOrderStatusId"` // 澶勭悊鐘舵��
 	ExpectTime           string  `gorm:"expect_time" json:"expectTime"`                                                                          // 甯屾湜澶勭悊鏃堕棿
 	RealTime             string  `gorm:"real_time" json:"realTime"`                                                                              // 瀹為檯澶勭悊鏃堕棿
diff --git a/model/salesDetails.go b/model/salesDetails.go
index bf371e3..569fbf3 100644
--- a/model/salesDetails.go
+++ b/model/salesDetails.go
@@ -41,6 +41,8 @@
 		AmountTotal         decimal.Decimal   `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"`              // 浠风◣鍚堣
 		CodeStandID         string            `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
 		DeliverType         int               `json:"deliverType" gorm:"column:deliver_type;type:int;comment:浜や粯绫诲瀷(1.涓�娆″彂璐�,2.澶氭鍙戣揣)"`
+		QuotationId         int               `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+		Quotation           Quotation         `json:"quotation" gorm:"foreignKey:QuotationId"`
 		CrmModel
 	}
 
@@ -107,7 +109,8 @@
 			Preload("Member").
 			Preload("SaleChance").
 			Preload("WechatOrderStatus").
-			Preload("Client")
+			Preload("Client").
+			Preload("Quotation")
 	}
 
 	return db
diff --git a/model/salesRefund.go b/model/salesRefund.go
index 9155fb5..e593902 100644
--- a/model/salesRefund.go
+++ b/model/salesRefund.go
@@ -16,8 +16,8 @@
 		Client        Client                    `json:"client" gorm:"foreignKey:ClientId"`
 		Number        string                    `json:"number" gorm:"column:number;type:varchar(255);comment:閫�娆惧崟鍙�"`
 		SourceType    constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞��璐э級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞��璐э級
-		SourceId      int                       `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"`           // 婧愬崟id
-		Source        SalesReturn               `gorm:"foreignKey:SourceId" json:"Source"`
+		SalesReturnId int                       `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"`           // 婧愬崟id
+		SalesReturn   SalesReturn               `gorm:"foreignKey:SalesReturnId" json:"salesReturn"`
 		MemberId      int                       `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
 		Member        User                      `json:"member" gorm:"foreignKey:MemberId"`
 		RefundDate    string                    `json:"refundDate" gorm:"column:refund_date;type:varchar(255);comment:閫�娆炬棩鏈�"`
@@ -78,16 +78,16 @@
 		db = db.Where("source_type = ?", slf.SourceType)
 	}
 
-	if slf.SourceId != 0 {
-		db = db.Where("source_id = ?", slf.SourceId)
+	if slf.SalesReturnId != 0 {
+		db = db.Where("source_id = ?", slf.SalesReturnId)
 	}
 
 	if slf.Preload {
 		db = db.Preload("Client").
 			Preload("PaymentType").
 			Preload("BankAccount").
-			Preload("Source").
-			Preload("Products")
+			Preload("Products").
+			Preload("SalesReturn")
 	}
 	if slf.KeywordType != "" {
 		switch slf.KeywordType {
@@ -212,7 +212,7 @@
 }
 
 func (slf *SalesRefundSearch) SetSourceId(id int) *SalesRefundSearch {
-	slf.SourceId = id
+	slf.SalesReturnId = id
 	return slf
 }
 
diff --git a/model/serviceOrder.go b/model/serviceOrder.go
index 3440357..c3d350b 100644
--- a/model/serviceOrder.go
+++ b/model/serviceOrder.go
@@ -38,7 +38,7 @@
 		SaleChance           SaleChance         `gorm:"foreignKey:SaleChanceId"`
 		FaultTypeId          int                `gorm:"column:severity_id;type:int;not null;default:0;comment:鏁呴殰绫诲埆id" json:"faultTypeId"` // 鏁呴殰绫诲埆id
 		FaultType            FaultType          `gorm:"foreignKey:FaultTypeId"`
-		SeverityId           int                `gorm:"column:severity_id;type:int;not null;default:0;comment:涓ラ噸绋嬪害id" json:"severity"` // 涓ラ噸绋嬪害id
+		SeverityId           int                `gorm:"column:severity_order_id;type:int;not null;default:0;comment:涓ラ噸绋嬪害id" json:"severityId"` // 涓ラ噸绋嬪害id
 		Severity             Severity           `gorm:"foreignKey:SeverityId"`
 		ServiceOrderStatusId int                `gorm:"column:service_order_status_id;type:int;not null;default:0;comment:鏈嶅姟鍗曠姸鎬乮d" json:"serviceOrderStatusId"` // 澶勭悊鐘舵��
 		ServiceOrderStatus   ServiceOrderStatus `gorm:"foreignKey:ServiceOrderStatusId"`
@@ -134,8 +134,8 @@
 	if len(slf.ServiceManIds) > 0 {
 		db = db.Where("service_man_id in ?", slf.ServiceManIds)
 	}
-	if slf.Number != "" {
-		db = db.Where("number = ?", slf.Number)
+	if slf.ServiceNumber != "" {
+		db = db.Where("service_number = ?", slf.ServiceNumber)
 	}
 
 	return db
@@ -220,7 +220,7 @@
 }
 
 func (slf *ServiceOrderSearch) SetNumber(number string) *ServiceOrderSearch {
-	slf.Number = number
+	slf.ServiceNumber = number
 	return slf
 }
 
diff --git a/model/severity.go b/model/severity.go
index bccf576..51284df 100644
--- a/model/severity.go
+++ b/model/severity.go
@@ -29,7 +29,7 @@
 )
 
 func (Severity) TableName() string {
-	return "severity"
+	return "severity_order"
 }
 
 func NewSeveritySearch() *SeveritySearch {
diff --git a/service/invoice.go b/service/invoice.go
index edb207e..9aaf90f 100644
--- a/service/invoice.go
+++ b/service/invoice.go
@@ -43,7 +43,7 @@
 		if err != nil {
 			return ecode.DBErr
 		}
-	} else if invoice.SourceType == constvar.InvoiceSourceTypeServiceContract { //鏇存柊閿�鍞槑缁嗗凡寮�绁ㄩ噾棰�
+	} else if invoice.SourceType == constvar.InvoiceSourceTypeSaleDetail { //鏇存柊閿�鍞槑缁嗗凡寮�绁ㄩ噾棰�
 		salesDetails, err := model.NewSalesDetailsSearch().SetId(invoice.SourceId).SetPreload(true).First()
 		if err != nil {
 			return ecode.DBErr
diff --git a/service/salesRefund.go b/service/salesRefund.go
index c9897a1..52a4a88 100644
--- a/service/salesRefund.go
+++ b/service/salesRefund.go
@@ -12,7 +12,7 @@
 type SalesRefundService struct{}
 
 func (SalesRefundService) AddSalesRefund(salesRefund *model.SalesRefund) int {
-	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).SetPreload(true).First()
+	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SalesReturnId).SetPreload(true).First()
 	if err != nil {
 		return ecode.SalesReturnNotExist
 	}
@@ -37,7 +37,7 @@
 			return errors.New("閫�璐т骇鍝佸搴旀�讳环瓒呭嚭搴旈��鎬讳环")
 		}
 		salesReturnRecord.AmountShouldRefund = salesReturnRecord.AmountTotal.Sub(salesReturnRecord.AmountHasRefund).Round(2)
-		err = model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Update(salesReturnRecord)
+		err = model.NewSalesReturnSearch().SetId(salesRefund.SalesReturnId).Update(salesReturnRecord)
 		if err != nil {
 			code = ecode.DBErr
 			return err
@@ -73,7 +73,7 @@
 	if err != nil {
 		return ecode.SalesRefundNotExist
 	}
-	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(refund.SourceId).SetPreload(true).First()
+	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(refund.SalesReturnId).SetPreload(true).First()
 	if err != nil {
 		return ecode.SalesReturnNotExist
 	}
@@ -90,7 +90,7 @@
 		}
 		salesReturnRecord.AmountHasRefund = salesReturnRecord.AmountHasRefund.Sub(amount).Round(2)
 		salesReturnRecord.AmountShouldRefund = salesReturnRecord.AmountTotal.Sub(salesReturnRecord.AmountHasRefund).Round(2)
-		err = model.NewSalesReturnSearch().SetId(refund.SourceId).Update(salesReturnRecord)
+		err = model.NewSalesReturnSearch().SetId(refund.SalesReturnId).Update(salesReturnRecord)
 		if err != nil {
 			return err
 		}
@@ -120,7 +120,7 @@
 		return ecode.SalesRefundNotExist
 	}
 
-	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).SetPreload(true).First()
+	salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SalesReturnId).SetPreload(true).First()
 	if err != nil {
 		return ecode.SalesReturnNotExist
 	}
@@ -153,7 +153,7 @@
 			return errors.New("閫�璐т骇鍝佸搴旀�讳环瓒呭嚭搴旈��鎬讳环")
 		}
 
-		err = model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Update(salesReturnRecord)
+		err = model.NewSalesReturnSearch().SetId(salesRefund.SalesReturnId).Update(salesReturnRecord)
 		if err != nil {
 			code = ecode.DBErr
 			return err
@@ -168,7 +168,7 @@
 	return ecode.OK
 }
 
-func (SalesRefundService) GetSalesRefundList(page, pageSize int, keywordType constvar.SalesRefundKeywordType, keyword string, sourceId int, memberIds []int)  ([]*model.SalesRefund, int64, int) {
+func (SalesRefundService) GetSalesRefundList(page, pageSize int, keywordType constvar.SalesRefundKeywordType, keyword string, sourceId int, memberIds []int) ([]*model.SalesRefund, int64, int) {
 	// get contact list
 	contacts, total, err := model.NewSalesRefundSearch().
 		SetKeywordType(keywordType).

--
Gitblit v1.8.0