From 6bb983c0766c26583493a956f255f87c742db59e Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期三, 12 七月 2023 14:53:37 +0800
Subject: [PATCH] add

---
 api/v1/index.go              |    2 
 api/v1/subOrder.go           |    2 
 pkg/ecode/code.go            |    6 
 docs/swagger.yaml            |  140 ++++++++
 docs/docs.go                 |  222 +++++++++++++
 api/v1/salesReturn.go        |    2 
 docs/swagger.json            |  222 +++++++++++++
 model/response/response.go   |    4 
 router/salesRefund.go        |   19 +
 api/v1/salesRefund.go        |  158 +++++++++
 service/index.go             |    1 
 model/salesRefund.go         |   80 +++++
 model/index.go               |    1 
 service/salesRefund.go       |   54 +++
 model/request/salesRefund.go |   24 +
 router/index.go              |    2 
 16 files changed, 939 insertions(+), 0 deletions(-)

diff --git a/api/v1/index.go b/api/v1/index.go
index 2d16f27..92307c2 100644
--- a/api/v1/index.go
+++ b/api/v1/index.go
@@ -36,6 +36,7 @@
 	SubOrderApi
 	SalesDetailsApi
 	SalesReturnApi
+	SalesRefundApi
 }
 
 var ApiGroup = new(Group)
@@ -71,4 +72,5 @@
 	subOrderService          = service.ServiceGroup.SubOrderService
 	salesDetailsService      = service.ServiceGroup.SalesDetailsService
 	salesReturnService       = service.ServiceGroup.SalesReturnService
+	salesRefundService       = service.ServiceGroup.SalesRefundService
 )
diff --git a/api/v1/salesRefund.go b/api/v1/salesRefund.go
new file mode 100644
index 0000000..39fe545
--- /dev/null
+++ b/api/v1/salesRefund.go
@@ -0,0 +1,158 @@
+package v1
+
+import (
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/model/response"
+	"aps_crm/pkg/contextx"
+	"aps_crm/pkg/ecode"
+	"github.com/gin-gonic/gin"
+	"strconv"
+)
+
+type SalesRefundApi struct{}
+
+// Add
+//
+//	@Tags		SalesRefund
+//	@Summary	娣诲姞閿�鍞��娆�
+//	@Produce	application/json
+//	@Param		object	body		request.AddSalesRefundRequest	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/salesRefund/add [post]
+func (s *SalesRefundApi) Add(c *gin.Context) {
+	var params request.AddSalesRefundRequest
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode, salesRefund := checkSalesRefundParams(params.SalesRefund)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	errCode = salesRefundService.AddSalesRefund(&salesRefund)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Delete
+//
+//	@Tags		SalesRefund
+//	@Summary	鍒犻櫎閿�鍞��娆�
+//	@Produce	application/json
+//	@Param		id	path		int	true	"鏌ヨ鍙傛暟"
+//	@Success	200	{object}	contextx.Response{}
+//	@Router		/api/salesRefund/delete/{id} [delete]
+func (s *SalesRefundApi) Delete(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+
+	id, _ := strconv.Atoi(c.Param("id"))
+	errCode := salesRefundService.DeleteSalesRefund(id)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Update
+//
+//	@Tags		SalesRefund
+//	@Summary	鏇存柊閿�鍞��娆�
+//	@Produce	application/json
+//	@Param		object	body		request.UpdateSalesRefundRequest	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/salesRefund/update [put]
+func (s *SalesRefundApi) Update(c *gin.Context) {
+	var params request.UpdateSalesRefundRequest
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode, salesRefund := checkSalesRefundParams(params.SalesRefund)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	salesRefund.Id = params.Id
+
+	errCode = salesRefundService.UpdateSalesRefund(&salesRefund)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// List
+//
+//	@Tags		SalesRefund
+//	@Summary	閿�鍞��娆惧垪琛�
+//	@Produce	application/json
+//	@Success	200	{object}	contextx.Response{data=response.SalesRefundResponse}
+//	@Router		/api/salesRefund/list [get]
+func (s *SalesRefundApi) List(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+
+	list, errCode := salesRefundService.GetSalesRefundList()
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.SalesRefundResponse{
+		List: list,
+	})
+
+}
+
+func checkSalesRefundParams(salesRefund request.SalesRefund) (errCode int, salesRefundRes model.SalesRefund) {
+	if salesRefund.ClientId == 0 {
+		return ecode.InvalidParams, salesRefundRes
+	}
+
+	if salesRefund.Number == "" {
+		return ecode.InvalidParams, salesRefundRes
+	}
+
+	if salesRefund.MemberId == 0 {
+		return ecode.InvalidParams, salesRefundRes
+	}
+
+	if salesRefund.RefundDate == "" {
+		return ecode.InvalidParams, salesRefundRes
+	}
+
+	t, err := checkTimeFormat(salesRefund.RefundDate)
+	if err != nil {
+		return ecode.InvalidParams, salesRefundRes
+	}
+	salesRefundRes.RefundDate = t
+	salesRefundRes.ClientId = salesRefund.ClientId
+	salesRefundRes.Number = salesRefund.Number
+	salesRefundRes.MemberId = salesRefund.MemberId
+	salesRefundRes.RefundMethod = salesRefund.RefundMethod
+	salesRefundRes.AccountId = salesRefund.AccountId
+	salesRefundRes.IsInvoice = salesRefund.IsInvoice
+	salesRefundRes.Reason = salesRefund.Reason
+	salesRefundRes.Products = salesRefund.Products
+
+	return ecode.OK, salesRefundRes
+}
diff --git a/api/v1/salesReturn.go b/api/v1/salesReturn.go
index bcc4692..cdc51ba 100644
--- a/api/v1/salesReturn.go
+++ b/api/v1/salesReturn.go
@@ -87,6 +87,8 @@
 		return
 	}
 
+	salesReturn.Id = params.Id
+
 	errCode = salesReturnService.UpdateSalesReturn(&salesReturn)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
diff --git a/api/v1/subOrder.go b/api/v1/subOrder.go
index 41e74cd..20c4a4a 100644
--- a/api/v1/subOrder.go
+++ b/api/v1/subOrder.go
@@ -87,6 +87,8 @@
 		return
 	}
 
+	subOrder.Id = params.Id
+
 	errCode = subOrderService.UpdateSubOrder(&subOrder)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
diff --git a/docs/docs.go b/docs/docs.go
index fcdb128..d262056 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3056,6 +3056,125 @@
                 }
             }
         },
+        "/api/salesRefund/add": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "娣诲姞閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddSalesRefundRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "鍒犻櫎閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/list": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "閿�鍞��娆惧垪琛�",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.SalesRefundResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/update": {
+            "put": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "鏇存柊閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.UpdateSalesRefundRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api/salesReturn/add": {
             "post": {
                 "produces": [
@@ -4672,6 +4791,44 @@
                 }
             }
         },
+        "model.SalesRefund": {
+            "type": "object",
+            "properties": {
+                "accountId": {
+                    "type": "integer"
+                },
+                "clientId": {
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "isInvoice": {
+                    "type": "integer"
+                },
+                "memberId": {
+                    "type": "integer"
+                },
+                "number": {
+                    "type": "string"
+                },
+                "products": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.Product"
+                    }
+                },
+                "reason": {
+                    "type": "string"
+                },
+                "refundDate": {
+                    "type": "string"
+                },
+                "refundMethod": {
+                    "type": "string"
+                }
+            }
+        },
         "model.SalesSources": {
             "type": "object",
             "properties": {
@@ -5317,6 +5474,14 @@
                 }
             }
         },
+        "request.AddSalesRefundRequest": {
+            "type": "object",
+            "properties": {
+                "salesRefund": {
+                    "$ref": "#/definitions/request.SalesRefund"
+                }
+            }
+        },
         "request.AddSalesReturnRequest": {
             "type": "object",
             "properties": {
@@ -5642,6 +5807,41 @@
                 },
                 "wechatOrderStatus": {
                     "type": "integer"
+                }
+            }
+        },
+        "request.SalesRefund": {
+            "type": "object",
+            "properties": {
+                "accountId": {
+                    "type": "integer"
+                },
+                "clientId": {
+                    "type": "integer"
+                },
+                "isInvoice": {
+                    "type": "integer"
+                },
+                "memberId": {
+                    "type": "integer"
+                },
+                "number": {
+                    "type": "string"
+                },
+                "products": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.Product"
+                    }
+                },
+                "reason": {
+                    "type": "string"
+                },
+                "refundDate": {
+                    "type": "string"
+                },
+                "refundMethod": {
+                    "type": "string"
                 }
             }
         },
@@ -6582,6 +6782,17 @@
                 }
             }
         },
+        "request.UpdateSalesRefundRequest": {
+            "type": "object",
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "salesRefund": {
+                    "$ref": "#/definitions/request.SalesRefund"
+                }
+            }
+        },
         "request.UpdateSalesReturnRequest": {
             "type": "object",
             "properties": {
@@ -6980,6 +7191,17 @@
                 }
             }
         },
+        "response.SalesRefundResponse": {
+            "type": "object",
+            "properties": {
+                "list": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.SalesRefund"
+                    }
+                }
+            }
+        },
         "response.SalesSourceResponse": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 609ea9b..f49b538 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3044,6 +3044,125 @@
                 }
             }
         },
+        "/api/salesRefund/add": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "娣诲姞閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddSalesRefundRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "鍒犻櫎閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/list": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "閿�鍞��娆惧垪琛�",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.SalesRefundResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api/salesRefund/update": {
+            "put": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "SalesRefund"
+                ],
+                "summary": "鏇存柊閿�鍞��娆�",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.UpdateSalesRefundRequest"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api/salesReturn/add": {
             "post": {
                 "produces": [
@@ -4660,6 +4779,44 @@
                 }
             }
         },
+        "model.SalesRefund": {
+            "type": "object",
+            "properties": {
+                "accountId": {
+                    "type": "integer"
+                },
+                "clientId": {
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "isInvoice": {
+                    "type": "integer"
+                },
+                "memberId": {
+                    "type": "integer"
+                },
+                "number": {
+                    "type": "string"
+                },
+                "products": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.Product"
+                    }
+                },
+                "reason": {
+                    "type": "string"
+                },
+                "refundDate": {
+                    "type": "string"
+                },
+                "refundMethod": {
+                    "type": "string"
+                }
+            }
+        },
         "model.SalesSources": {
             "type": "object",
             "properties": {
@@ -5305,6 +5462,14 @@
                 }
             }
         },
+        "request.AddSalesRefundRequest": {
+            "type": "object",
+            "properties": {
+                "salesRefund": {
+                    "$ref": "#/definitions/request.SalesRefund"
+                }
+            }
+        },
         "request.AddSalesReturnRequest": {
             "type": "object",
             "properties": {
@@ -5630,6 +5795,41 @@
                 },
                 "wechatOrderStatus": {
                     "type": "integer"
+                }
+            }
+        },
+        "request.SalesRefund": {
+            "type": "object",
+            "properties": {
+                "accountId": {
+                    "type": "integer"
+                },
+                "clientId": {
+                    "type": "integer"
+                },
+                "isInvoice": {
+                    "type": "integer"
+                },
+                "memberId": {
+                    "type": "integer"
+                },
+                "number": {
+                    "type": "string"
+                },
+                "products": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.Product"
+                    }
+                },
+                "reason": {
+                    "type": "string"
+                },
+                "refundDate": {
+                    "type": "string"
+                },
+                "refundMethod": {
+                    "type": "string"
                 }
             }
         },
@@ -6570,6 +6770,17 @@
                 }
             }
         },
+        "request.UpdateSalesRefundRequest": {
+            "type": "object",
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "salesRefund": {
+                    "$ref": "#/definitions/request.SalesRefund"
+                }
+            }
+        },
         "request.UpdateSalesReturnRequest": {
             "type": "object",
             "properties": {
@@ -6968,6 +7179,17 @@
                 }
             }
         },
+        "response.SalesRefundResponse": {
+            "type": "object",
+            "properties": {
+                "list": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.SalesRefund"
+                    }
+                }
+            }
+        },
         "response.SalesSourceResponse": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 38dad52..f9dc27a 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -606,6 +606,31 @@
       sales_status:
         $ref: '#/definitions/constvar.SalesStatus'
     type: object
+  model.SalesRefund:
+    properties:
+      accountId:
+        type: integer
+      clientId:
+        type: integer
+      id:
+        type: integer
+      isInvoice:
+        type: integer
+      memberId:
+        type: integer
+      number:
+        type: string
+      products:
+        items:
+          $ref: '#/definitions/model.Product'
+        type: array
+      reason:
+        type: string
+      refundDate:
+        type: string
+      refundMethod:
+        type: string
+    type: object
   model.SalesSources:
     properties:
       id:
@@ -1044,6 +1069,11 @@
         description: 鍟嗘満鏉ユ簮ID
         type: integer
     type: object
+  request.AddSalesRefundRequest:
+    properties:
+      salesRefund:
+        $ref: '#/definitions/request.SalesRefund'
+    type: object
   request.AddSalesReturnRequest:
     properties:
       salesReturn:
@@ -1270,6 +1300,29 @@
         type: string
       wechatOrderStatus:
         type: integer
+    type: object
+  request.SalesRefund:
+    properties:
+      accountId:
+        type: integer
+      clientId:
+        type: integer
+      isInvoice:
+        type: integer
+      memberId:
+        type: integer
+      number:
+        type: string
+      products:
+        items:
+          $ref: '#/definitions/model.Product'
+        type: array
+      reason:
+        type: string
+      refundDate:
+        type: string
+      refundMethod:
+        type: string
     type: object
   request.SalesReturn:
     properties:
@@ -1905,6 +1958,13 @@
         description: 鍟嗘満鏉ユ簮ID
         type: integer
     type: object
+  request.UpdateSalesRefundRequest:
+    properties:
+      id:
+        type: integer
+      salesRefund:
+        $ref: '#/definitions/request.SalesRefund'
+    type: object
   request.UpdateSalesReturnRequest:
     properties:
       clientId:
@@ -2159,6 +2219,13 @@
       list:
         items:
           $ref: '#/definitions/model.SalesLeads'
+        type: array
+    type: object
+  response.SalesRefundResponse:
+    properties:
+      list:
+        items:
+          $ref: '#/definitions/model.SalesRefund'
         type: array
     type: object
   response.SalesSourceResponse:
@@ -4046,6 +4113,79 @@
       summary: 鏇存柊閿�鍞嚎绱�
       tags:
       - SalesLeads
+  /api/salesRefund/add:
+    post:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.AddSalesRefundRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 娣诲姞閿�鍞��娆�
+      tags:
+      - SalesRefund
+  /api/salesRefund/delete/{id}:
+    delete:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 鍒犻櫎閿�鍞��娆�
+      tags:
+      - SalesRefund
+  /api/salesRefund/list:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            allOf:
+            - $ref: '#/definitions/contextx.Response'
+            - properties:
+                data:
+                  $ref: '#/definitions/response.SalesRefundResponse'
+              type: object
+      summary: 閿�鍞��娆惧垪琛�
+      tags:
+      - SalesRefund
+  /api/salesRefund/update:
+    put:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.UpdateSalesRefundRequest'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 鏇存柊閿�鍞��娆�
+      tags:
+      - SalesRefund
   /api/salesReturn/add:
     post:
       parameters:
diff --git a/model/index.go b/model/index.go
index 0c2846c..3a0814a 100644
--- a/model/index.go
+++ b/model/index.go
@@ -52,6 +52,7 @@
 		Product{},
 		SalesDetails{},
 		SalesReturn{},
+		SalesRefund{},
 	)
 	return err
 }
diff --git a/model/request/salesRefund.go b/model/request/salesRefund.go
new file mode 100644
index 0000000..3fb49bc
--- /dev/null
+++ b/model/request/salesRefund.go
@@ -0,0 +1,24 @@
+package request
+
+import "aps_crm/model"
+
+type AddSalesRefundRequest struct {
+	SalesRefund SalesRefund `json:"salesRefund"`
+}
+
+type SalesRefund struct {
+	ClientId     int             `json:"clientId"`
+	Number       string          `json:"number"`
+	MemberId     int             `json:"memberId"`
+	RefundDate   string          `json:"refundDate"`
+	RefundMethod string          `json:"refundMethod"`
+	AccountId    int             `json:"accountId"`
+	IsInvoice    int             `json:"isInvoice"`
+	Reason       string          `json:"reason"`
+	Products     []model.Product `json:"products"`
+}
+
+type UpdateSalesRefundRequest struct {
+	Id          int         `json:"id"`
+	SalesRefund SalesRefund `json:"salesRefund"`
+}
diff --git a/model/response/response.go b/model/response/response.go
index 666cad4..e4291dd 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -141,4 +141,8 @@
 	SalesReturnResponse struct {
 		List []*model.SalesReturn `json:"list"`
 	}
+
+	SalesRefundResponse struct {
+		List []*model.SalesRefund `json:"list"`
+	}
 )
diff --git a/model/salesRefund.go b/model/salesRefund.go
new file mode 100644
index 0000000..e2540c4
--- /dev/null
+++ b/model/salesRefund.go
@@ -0,0 +1,80 @@
+package model
+
+import (
+	"aps_crm/pkg/mysqlx"
+	"gorm.io/gorm"
+	"time"
+)
+
+type (
+	SalesRefund struct {
+		Id           int       `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ClientId     int       `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+		Number       string    `json:"number" gorm:"column:number;type:varchar(255);comment:閫�娆惧崟鍙�"`
+		MemberId     int       `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+		RefundDate   time.Time `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:閫�娆炬棩鏈�"`
+		RefundMethod string    `json:"refundMethod" gorm:"column:refund_method;type:varchar(255);comment:閫�娆炬柟寮�"`
+		AccountId    int       `json:"accountId" gorm:"column:account_id;type:int;comment:璐︽埛"`
+		IsInvoice    int       `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:鏄惁寮�绁�"`
+		Reason       string    `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�娆惧師鍥�"`
+		Products     []Product `json:"products" gorm:"many2many:salesRefund_product;"`
+	}
+
+	SalesRefundSearch struct {
+		SalesRefund
+		Orm *gorm.DB
+	}
+)
+
+func (SalesRefund) TableName() string {
+	return "sales_refund"
+}
+
+func NewSalesRefundSearch() *SalesRefundSearch {
+	return &SalesRefundSearch{
+		Orm: mysqlx.GetDB(),
+	}
+}
+
+func (slf *SalesRefundSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&SalesRefund{})
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
+	}
+
+	return db
+}
+
+func (slf *SalesRefundSearch) Create(record *SalesRefund) error {
+	var db = slf.build()
+	return db.Create(record).Error
+}
+
+func (slf *SalesRefundSearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&SalesRefund{}).Error
+}
+
+func (slf *SalesRefundSearch) Update(record *SalesRefund) error {
+	var db = slf.build()
+	return db.Updates(record).Error
+}
+
+func (slf *SalesRefundSearch) Find() (*SalesRefund, error) {
+	var db = slf.build()
+	var record = new(SalesRefund)
+	err := db.First(record).Error
+	return record, err
+}
+
+func (slf *SalesRefundSearch) FindAll() ([]*SalesRefund, error) {
+	var db = slf.build()
+	var records = make([]*SalesRefund, 0)
+	err := db.Preload("Products").Find(&records).Error
+	return records, err
+}
+
+func (slf *SalesRefundSearch) SetId(id int) *SalesRefundSearch {
+	slf.Id = id
+	return slf
+}
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 1808279..d0dd587 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -212,4 +212,10 @@
 	SalesReturnUpdateErr = 2900005 // 鏇存柊閿�鍞��璐у崟澶辫触
 	SalesReturnDeleteErr = 2900006 // 鍒犻櫎閿�鍞��璐у崟澶辫触
 
+	SalesRefundExist     = 3000001 // 閿�鍞��娆惧崟宸插瓨鍦�
+	SalesRefundNotExist  = 3000002 // 閿�鍞��娆惧崟涓嶅瓨鍦�
+	SalesRefundListErr   = 3000003 // 鑾峰彇閿�鍞��娆惧崟鍒楄〃澶辫触
+	SalesRefundSetErr    = 3000004 // 璁剧疆閿�鍞��娆惧崟澶辫触
+	SalesRefundUpdateErr = 3000005 // 鏇存柊閿�鍞��娆惧崟澶辫触
+	SalesRefundDeleteErr = 3000006 // 鍒犻櫎閿�鍞��娆惧崟澶辫触
 )
diff --git a/router/index.go b/router/index.go
index 8fc92b1..8676fdf 100644
--- a/router/index.go
+++ b/router/index.go
@@ -42,6 +42,7 @@
 	SubOrderRouter
 	SalesDetailsRouter
 	SalesReturnRouter
+	SalesRefundRouter
 }
 
 func InitRouter() *gin.Engine {
@@ -101,6 +102,7 @@
 		routerGroup.InitSubOrderRouter(PrivateGroup)          // 娉ㄥ唽subOrder璺敱
 		routerGroup.InitSalesDetailsRouter(PrivateGroup)      // 娉ㄥ唽salesDetails璺敱
 		routerGroup.InitSalesReturnRouter(PrivateGroup)       // 娉ㄥ唽salesReturn璺敱
+		routerGroup.InitSalesRefundRouter(PrivateGroup)       // 娉ㄥ唽salesRefund璺敱
 	}
 	return Router
 }
diff --git a/router/salesRefund.go b/router/salesRefund.go
new file mode 100644
index 0000000..5a30041
--- /dev/null
+++ b/router/salesRefund.go
@@ -0,0 +1,19 @@
+package router
+
+import (
+	v1 "aps_crm/api/v1"
+	"github.com/gin-gonic/gin"
+)
+
+type SalesRefundRouter struct{}
+
+func (s *SalesRefundRouter) InitSalesRefundRouter(router *gin.RouterGroup) {
+	salesRefundRouter := router.Group("salesRefund")
+	salesRefundApi := v1.ApiGroup.SalesRefundApi
+	{
+		salesRefundRouter.POST("add", salesRefundApi.Add)             // 娣诲姞閿�鍞��娆�
+		salesRefundRouter.DELETE("delete/:id", salesRefundApi.Delete) // 鍒犻櫎閿�鍞��娆�
+		salesRefundRouter.PUT("update", salesRefundApi.Update)        // 鏇存柊閿�鍞��娆�
+		salesRefundRouter.GET("list", salesRefundApi.List)            // 鑾峰彇閿�鍞��娆惧垪琛�
+	}
+}
diff --git a/service/index.go b/service/index.go
index b7c5f56..3743020 100644
--- a/service/index.go
+++ b/service/index.go
@@ -31,6 +31,7 @@
 	SubOrderService
 	SalesDetailsService
 	SalesReturnService
+	SalesRefundService
 }
 
 var ServiceGroup = new(Group)
diff --git a/service/salesRefund.go b/service/salesRefund.go
new file mode 100644
index 0000000..5efa2e1
--- /dev/null
+++ b/service/salesRefund.go
@@ -0,0 +1,54 @@
+package service
+
+import (
+	"aps_crm/model"
+	"aps_crm/pkg/ecode"
+)
+
+type SalesRefundService struct{}
+
+func (SalesRefundService) AddSalesRefund(salesRefund *model.SalesRefund) int {
+	err := model.NewSalesRefundSearch().Create(salesRefund)
+	if err != nil {
+		return ecode.SalesRefundExist
+	}
+
+	return ecode.OK
+}
+
+func (SalesRefundService) DeleteSalesRefund(id int) int {
+	_, err := model.NewSalesRefundSearch().SetId(id).Find()
+	if err != nil {
+		return ecode.SalesRefundNotExist
+	}
+
+	err = model.NewSalesRefundSearch().SetId(id).Delete()
+	if err != nil {
+		return ecode.SalesRefundNotExist
+	}
+	return ecode.OK
+}
+
+func (SalesRefundService) GetSalesRefundList() ([]*model.SalesRefund, int) {
+	list, err := model.NewSalesRefundSearch().FindAll()
+	if err != nil {
+		return nil, ecode.SalesRefundListErr
+	}
+
+	return list, ecode.OK
+}
+
+func (SalesRefundService) UpdateSalesRefund(salesRefund *model.SalesRefund) int {
+	// check salesRefund exist
+	_, err := model.NewSalesRefundSearch().SetId(salesRefund.Id).Find()
+	if err != nil {
+		return ecode.SalesRefundNotExist
+	}
+
+	err = model.NewSalesRefundSearch().SetId(salesRefund.Id).Update(salesRefund)
+	if err != nil {
+		return ecode.SalesRefundSetErr
+	}
+
+	return ecode.OK
+}

--
Gitblit v1.8.0