From bd379cf89e0091f931cd1db569560dd4fe63ad3b Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期三, 03 一月 2024 15:00:28 +0800
Subject: [PATCH] 报价单统计

---
 router/quotation.go |    9 +-
 model/quotation.go  |   11 +++
 docs/swagger.yaml   |   19 ++++++
 api/v1/quotation.go |   27 +++++++++
 docs/docs.go        |   34 +++++++++++
 docs/swagger.json   |   34 +++++++++++
 6 files changed, 129 insertions(+), 5 deletions(-)

diff --git a/api/v1/quotation.go b/api/v1/quotation.go
index e1cf09f..ecbe7da 100644
--- a/api/v1/quotation.go
+++ b/api/v1/quotation.go
@@ -209,3 +209,30 @@
 		Count: int(total),
 	})
 }
+
+// Statistics
+//
+//	@Tags		Quotation
+//	@Summary	鎶ヤ环鍗曠粺璁�
+//	@Produce	application/json
+//	@Success	200		{object}	contextx.Response{data=map[string]int64}
+//	@Router		/api/quotation/statistics [get]
+func (con *QuotationApi) Statistics(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+	m := make(map[string]int64)
+	total, _ := model.NewQuotationSearch(nil).Count()
+	m["total"] = total
+	//宸插垱寤�
+	created, _ := model.NewQuotationSearch(nil).SetQuotationStatusId(1).Count()
+	m["created"] = created
+	//宸插鎵�
+	approved, _ := model.NewQuotationSearch(nil).SetQuotationStatusId(3).Count()
+	m["approved"] = approved
+	//宸叉帴鍙�
+	accepted, _ := model.NewQuotationSearch(nil).SetQuotationStatusId(5).Count()
+	m["accepted"] = accepted
+	ctx.OkWithDetailed(m)
+}
diff --git a/docs/docs.go b/docs/docs.go
index fd336df..1455302 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -5323,6 +5323,40 @@
                 }
             }
         },
+        "/api/quotation/statistics": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Quotation"
+                ],
+                "summary": "鎶ヤ环鍗曠粺璁�",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "object",
+                                            "additionalProperties": {
+                                                "type": "integer"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/api/quotation/update": {
             "put": {
                 "produces": [
diff --git a/docs/swagger.json b/docs/swagger.json
index 1d49ed2..431fd5d 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -5311,6 +5311,40 @@
                 }
             }
         },
+        "/api/quotation/statistics": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "Quotation"
+                ],
+                "summary": "鎶ヤ环鍗曠粺璁�",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "type": "object",
+                                            "additionalProperties": {
+                                                "type": "integer"
+                                            }
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/api/quotation/update": {
             "put": {
                 "produces": [
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index c46537f..cd49b10 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -9687,6 +9687,25 @@
       summary: 鎶ヤ环鍗曞垪琛�
       tags:
       - Quotation
+  /api/quotation/statistics:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            allOf:
+            - $ref: '#/definitions/contextx.Response'
+            - properties:
+                data:
+                  additionalProperties:
+                    type: integer
+                  type: object
+              type: object
+      summary: 鎶ヤ环鍗曠粺璁�
+      tags:
+      - Quotation
   /api/quotation/update:
     put:
       parameters:
diff --git a/model/quotation.go b/model/quotation.go
index 2ea3ad6..c4618ee 100644
--- a/model/quotation.go
+++ b/model/quotation.go
@@ -65,6 +65,9 @@
 	if slf.Number != "" {
 		db = db.Where("number = ?", slf.Number)
 	}
+	if slf.QuotationStatusId != 0 {
+		db = db.Where("quotation_status_id = ?", slf.QuotationStatusId)
+	}
 
 	if len(slf.SearchMap) > 0 {
 		for key, value := range slf.SearchMap {
@@ -134,7 +137,7 @@
 		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
 	}
 
-	err := db.Preload("Products").Preload("Member").Preload("QuotationStatus").Preload("Client").Preload("Contact").Order("id desc").Find(&records).Error
+	err := db.Preload("Products").Preload("Member").Preload("QuotationStatus").Preload("Client").Preload("Contact").Preload("SaleChance").Order("id desc").Find(&records).Error
 	return records, total, err
 }
 
@@ -191,7 +194,13 @@
 	slf.Number = number
 	return slf
 }
+
 func (slf *QuotationSearch) SetIds(ids []int) *QuotationSearch {
 	slf.Orm = slf.Orm.Where("id in (?)", ids)
 	return slf
 }
+
+func (slf *QuotationSearch) SetQuotationStatusId(id int) *QuotationSearch {
+	slf.QuotationStatusId = id
+	return slf
+}
diff --git a/router/quotation.go b/router/quotation.go
index 83068cd..06f98df 100644
--- a/router/quotation.go
+++ b/router/quotation.go
@@ -11,9 +11,10 @@
 	quotationRouter := router.Group("quotation")
 	quotationApi := v1.ApiGroup.QuotationApi
 	{
-		quotationRouter.POST("add", quotationApi.Add)         // 娣诲姞鎶ヤ环鍗�
-		quotationRouter.DELETE("delete", quotationApi.Delete) // 鍒犻櫎鎶ヤ环鍗�
-		quotationRouter.PUT("update", quotationApi.Update)    // 鏇存柊鎶ヤ环鍗�
-		quotationRouter.POST("list", quotationApi.List)       // 鑾峰彇鎶ヤ环鍗曞垪琛�
+		quotationRouter.POST("add", quotationApi.Add)              // 娣诲姞鎶ヤ环鍗�
+		quotationRouter.DELETE("delete", quotationApi.Delete)      // 鍒犻櫎鎶ヤ环鍗�
+		quotationRouter.PUT("update", quotationApi.Update)         // 鏇存柊鎶ヤ环鍗�
+		quotationRouter.POST("list", quotationApi.List)            // 鑾峰彇鎶ヤ环鍗曞垪琛�
+		quotationRouter.GET("statistics", quotationApi.Statistics) // 鎶ヤ环鍗曠粺璁�
 	}
 }

--
Gitblit v1.8.0