From 4480763be441c09e9034d6a347587a2b1a5e197a Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 17 十月 2023 21:01:47 +0800
Subject: [PATCH] fix
---
router/RefundType.go | 17 +
api/v1/RefundType.go | 112 +++++++
model/paymentType.go | 6
model/salesRefund.go | 2
model/index.go | 2
model/RefundType.go | 148 +++++++++
model/request/RefundType.go | 18 +
router/index.go | 1
docs/swagger.yaml | 132 +++++++-
docs/docs.go | 208 +++++++++++-
docs/swagger.json | 208 +++++++++++-
service/RefundType.go | 64 ++++
12 files changed, 856 insertions(+), 62 deletions(-)
diff --git a/api/v1/RefundType.go b/api/v1/RefundType.go
new file mode 100644
index 0000000..469e511
--- /dev/null
+++ b/api/v1/RefundType.go
@@ -0,0 +1,112 @@
+package v1
+
+import (
+ "aps_crm/model/request"
+ "aps_crm/model/response"
+ "aps_crm/pkg/contextx"
+ "aps_crm/pkg/ecode"
+ "aps_crm/service"
+ "github.com/gin-gonic/gin"
+ "strconv"
+)
+
+type RefundTypeApi struct{}
+
+// Add
+// @Tags 閫�娆炬柟寮忕鐞�
+// @Summary 娣诲姞閫�娆炬柟寮�
+// @Produce application/json
+// @Param object body request.AddRefundType true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/refundType/add [post]
+func (s *RefundTypeApi) Add(c *gin.Context) {
+ var params request.AddRefundType
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ errCode := service.NewRefundTypeService().AddRefundType(¶ms.RefundType)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Delete
+// @Tags 閫�娆炬柟寮忕鐞�
+// @Summary 鍒犻櫎閫�娆炬柟寮�
+// @Produce application/json
+// @Param id path int true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/refundType/delete/{id} [delete]
+func (s *RefundTypeApi) Delete(c *gin.Context) {
+ ctx, ok := contextx.NewContext(c, nil)
+ if !ok {
+ return
+ }
+
+ id, _ := strconv.Atoi(c.Param("id"))
+ errCode := service.NewRefundTypeService().DeleteRefundType(id)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// Update
+// @Tags 閫�娆炬柟寮忕鐞�
+// @Summary 鏇存柊閫�娆炬柟寮�
+// @Produce application/json
+// @Param object body request.UpdateRefundType true "鏌ヨ鍙傛暟"
+// @Success 200 {object} contextx.Response{}
+// @Router /api/refundType/update [put]
+func (s *RefundTypeApi) Update(c *gin.Context) {
+ var params request.UpdateRefundType
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+ if params.Id == 0 {
+ ctx.Fail(ecode.ParamsErr)
+ }
+ params.RefundType.Id = params.Id
+
+ errCode := service.NewRefundTypeService().UpdateRefundType(¶ms.RefundType)
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.Ok()
+}
+
+// List
+// @Tags 閫�娆炬柟寮忕鐞�
+// @Summary 鑾峰彇閫�娆炬柟寮忓垪琛�
+// @Produce application/json
+// @Param object query request.GetRefundTypeList true "鍙傛暟"
+// @Success 200 {object} response.ListResponse{data=[]model.RefundType}
+// @Router /api/refundType/list [get]
+func (s *RefundTypeApi) List(c *gin.Context) {
+ var params request.GetRefundTypeList
+ ctx, ok := contextx.NewContext(c, ¶ms)
+ if !ok {
+ return
+ }
+
+ RefundType, total, errCode := service.NewRefundTypeService().GetRefundTypeList()
+ if errCode != ecode.OK {
+ ctx.Fail(errCode)
+ return
+ }
+
+ ctx.OkWithDetailed(response.ListResponse{
+ Data: RefundType,
+ Count: total,
+ })
+}
diff --git a/docs/docs.go b/docs/docs.go
index ab2884d..bbd6e7c 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -5689,6 +5689,142 @@
}
}
},
+ "/api/refundType/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "娣诲姞閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddRefundType"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鍒犻櫎閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鑾峰彇閫�娆炬柟寮忓垪琛�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "椤电爜",
+ "name": "page",
+ "in": "query"
+ },
+ {
+ "type": "integer",
+ "description": "姣忛〉澶у皬",
+ "name": "pageSize",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.ListResponse"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.RefundType"
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鏇存柊閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateRefundType"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/region/add": {
"post": {
"produces": [
@@ -11699,6 +11835,17 @@
}
}
},
+ "model.RefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"model.Region": {
"type": "object",
"properties": {
@@ -11896,7 +12043,7 @@
"type": "string"
},
"status_id": {
- "type": "integer"
+ "$ref": "#/definitions/model.Status"
},
"threats": {
"type": "string"
@@ -12120,6 +12267,14 @@
"model.SalesRefund": {
"type": "object",
"properties": {
+ "RefundType": {
+ "description": "閫�娆炬柟寮�",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.RefundType"
+ }
+ ]
+ },
"Source": {
"$ref": "#/definitions/model.SalesReturn"
},
@@ -12182,6 +12337,10 @@
},
"refundDate": {
"type": "string"
+ },
+ "refundTypeId": {
+ "description": "閫�娆炬柟寮廔D",
+ "type": "integer"
},
"sourceId": {
"description": "婧愬崟id",
@@ -13282,13 +13441,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -13888,6 +14040,17 @@
"name"
],
"properties": {
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "request.AddRefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
"name": {
"type": "string"
}
@@ -14864,13 +15027,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -15362,6 +15518,10 @@
},
"keywordType": {
"$ref": "#/definitions/constvar.SalesDetailsKeywordType"
+ },
+ "number": {
+ "description": "閿�鍞瓙鍗曞彿",
+ "type": "string"
},
"page": {
"description": "椤电爜",
@@ -16229,13 +16389,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -17078,6 +17231,17 @@
}
}
},
+ "request.UpdateRefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"request.UpdateRegion": {
"type": "object",
"properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index 8016219..c326f5f 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -5677,6 +5677,142 @@
}
}
},
+ "/api/refundType/add": {
+ "post": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "娣诲姞閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.AddRefundType"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/delete/{id}": {
+ "delete": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鍒犻櫎閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "鏌ヨ鍙傛暟",
+ "name": "id",
+ "in": "path",
+ "required": true
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/list": {
+ "get": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鑾峰彇閫�娆炬柟寮忓垪琛�",
+ "parameters": [
+ {
+ "type": "integer",
+ "description": "椤电爜",
+ "name": "page",
+ "in": "query"
+ },
+ {
+ "type": "integer",
+ "description": "姣忛〉澶у皬",
+ "name": "pageSize",
+ "in": "query"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "allOf": [
+ {
+ "$ref": "#/definitions/response.ListResponse"
+ },
+ {
+ "type": "object",
+ "properties": {
+ "data": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/model.RefundType"
+ }
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "/api/refundType/update": {
+ "put": {
+ "produces": [
+ "application/json"
+ ],
+ "tags": [
+ "閫�娆炬柟寮忕鐞�"
+ ],
+ "summary": "鏇存柊閫�娆炬柟寮�",
+ "parameters": [
+ {
+ "description": "鏌ヨ鍙傛暟",
+ "name": "object",
+ "in": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/request.UpdateRefundType"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "OK",
+ "schema": {
+ "$ref": "#/definitions/contextx.Response"
+ }
+ }
+ }
+ }
+ },
"/api/region/add": {
"post": {
"produces": [
@@ -11687,6 +11823,17 @@
}
}
},
+ "model.RefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"model.Region": {
"type": "object",
"properties": {
@@ -11884,7 +12031,7 @@
"type": "string"
},
"status_id": {
- "type": "integer"
+ "$ref": "#/definitions/model.Status"
},
"threats": {
"type": "string"
@@ -12108,6 +12255,14 @@
"model.SalesRefund": {
"type": "object",
"properties": {
+ "RefundType": {
+ "description": "閫�娆炬柟寮�",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.RefundType"
+ }
+ ]
+ },
"Source": {
"$ref": "#/definitions/model.SalesReturn"
},
@@ -12170,6 +12325,10 @@
},
"refundDate": {
"type": "string"
+ },
+ "refundTypeId": {
+ "description": "閫�娆炬柟寮廔D",
+ "type": "integer"
},
"sourceId": {
"description": "婧愬崟id",
@@ -13270,13 +13429,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -13876,6 +14028,17 @@
"name"
],
"properties": {
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "request.AddRefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
"name": {
"type": "string"
}
@@ -14852,13 +15015,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -15350,6 +15506,10 @@
},
"keywordType": {
"$ref": "#/definitions/constvar.SalesDetailsKeywordType"
+ },
+ "number": {
+ "description": "閿�鍞瓙鍗曞彿",
+ "type": "string"
},
"page": {
"description": "椤电爜",
@@ -16217,13 +16377,6 @@
"description": "鎵�灞炲叕鍙窱D",
"type": "integer"
},
- "codeRule": {
- "$ref": "#/definitions/code.CodeStandard"
- },
- "codeStandID": {
- "description": "缂栫爜id",
- "type": "string"
- },
"country_id": {
"description": "鍥藉ID",
"type": "integer"
@@ -17066,6 +17219,17 @@
}
}
},
+ "request.UpdateRefundType": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "integer"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
"request.UpdateRegion": {
"type": "object",
"properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 6b262fd..c473c3e 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -1233,6 +1233,13 @@
name:
type: string
type: object
+ model.RefundType:
+ properties:
+ id:
+ type: integer
+ name:
+ type: string
+ type: object
model.Region:
properties:
id:
@@ -1363,7 +1370,7 @@
solutions:
type: string
status_id:
- type: integer
+ $ref: '#/definitions/model.Status'
threats:
type: string
whether_established:
@@ -1512,6 +1519,10 @@
type: object
model.SalesRefund:
properties:
+ RefundType:
+ allOf:
+ - $ref: '#/definitions/model.RefundType'
+ description: 閫�娆炬柟寮�
Source:
$ref: '#/definitions/model.SalesReturn'
amountTotal:
@@ -1555,6 +1566,9 @@
type: string
refundDate:
type: string
+ refundTypeId:
+ description: 閫�娆炬柟寮廔D
+ type: integer
sourceId:
description: 婧愬崟id
type: integer
@@ -2301,11 +2315,6 @@
client_id:
description: 鎵�灞炲叕鍙窱D
type: integer
- codeRule:
- $ref: '#/definitions/code.CodeStandard'
- codeStandID:
- description: 缂栫爜id
- type: string
country_id:
description: 鍥藉ID
type: integer
@@ -2706,6 +2715,13 @@
type: string
required:
- name
+ type: object
+ request.AddRefundType:
+ properties:
+ id:
+ type: integer
+ name:
+ type: string
type: object
request.AddRegion:
properties:
@@ -3369,11 +3385,6 @@
client_id:
description: 鎵�灞炲叕鍙窱D
type: integer
- codeRule:
- $ref: '#/definitions/code.CodeStandard'
- codeStandID:
- description: 缂栫爜id
- type: string
country_id:
description: 鍥藉ID
type: integer
@@ -3729,6 +3740,9 @@
type: string
keywordType:
$ref: '#/definitions/constvar.SalesDetailsKeywordType'
+ number:
+ description: 閿�鍞瓙鍗曞彿
+ type: string
page:
description: 椤电爜
type: integer
@@ -4322,11 +4336,6 @@
client_id:
description: 鎵�灞炲叕鍙窱D
type: integer
- codeRule:
- $ref: '#/definitions/code.CodeStandard'
- codeStandID:
- description: 缂栫爜id
- type: string
country_id:
description: 鍥藉ID
type: integer
@@ -4888,6 +4897,13 @@
type: array
required:
- refund_method
+ type: object
+ request.UpdateRefundType:
+ properties:
+ id:
+ type: integer
+ name:
+ type: string
type: object
request.UpdateRegion:
properties:
@@ -9763,6 +9779,90 @@
summary: 鏇存柊閫�娆炬柟寮�
tags:
- RefundMethod
+ /api/refundType/add:
+ post:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.AddRefundType'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 娣诲姞閫�娆炬柟寮�
+ tags:
+ - 閫�娆炬柟寮忕鐞�
+ /api/refundType/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:
+ - 閫�娆炬柟寮忕鐞�
+ /api/refundType/list:
+ get:
+ parameters:
+ - description: 椤电爜
+ in: query
+ name: page
+ type: integer
+ - description: 姣忛〉澶у皬
+ in: query
+ name: pageSize
+ type: integer
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ allOf:
+ - $ref: '#/definitions/response.ListResponse'
+ - properties:
+ data:
+ items:
+ $ref: '#/definitions/model.RefundType'
+ type: array
+ type: object
+ summary: 鑾峰彇閫�娆炬柟寮忓垪琛�
+ tags:
+ - 閫�娆炬柟寮忕鐞�
+ /api/refundType/update:
+ put:
+ parameters:
+ - description: 鏌ヨ鍙傛暟
+ in: body
+ name: object
+ required: true
+ schema:
+ $ref: '#/definitions/request.UpdateRefundType'
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: OK
+ schema:
+ $ref: '#/definitions/contextx.Response'
+ summary: 鏇存柊閫�娆炬柟寮�
+ tags:
+ - 閫�娆炬柟寮忕鐞�
/api/region/add:
post:
parameters:
diff --git a/model/RefundType.go b/model/RefundType.go
new file mode 100644
index 0000000..43c1b87
--- /dev/null
+++ b/model/RefundType.go
@@ -0,0 +1,148 @@
+package model
+
+import (
+ "aps_crm/pkg/mysqlx"
+ "errors"
+ "fmt"
+ "gorm.io/gorm"
+ "sync"
+)
+
+type (
+ // RefundType 閫�娆炬柟寮�
+ RefundType struct {
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Name string `json:"name" gorm:"column:name"`
+ }
+
+ // RefundTypeSearch 鏀粯鏂瑰紡鎼滅储鏉′欢
+ RefundTypeSearch struct {
+ RefundType
+ Orm *gorm.DB
+ PageNum int
+ PageSize int
+ }
+)
+
+func (RefundType) TableName() string {
+ return "refund_type"
+}
+
+func NewRefundTypeSearch() *RefundTypeSearch {
+ return &RefundTypeSearch{
+ Orm: mysqlx.GetDB(),
+ }
+}
+
+func (slf *RefundTypeSearch) build() *gorm.DB {
+ var db = slf.Orm.Model(&RefundType{})
+ if slf.Id != 0 {
+ db = db.Where("id = ?", slf.Id)
+ }
+
+ return db
+}
+
+func (slf *RefundTypeSearch) Create(record *RefundType) error {
+ var db = slf.build()
+ return db.Create(record).Error
+}
+
+func (slf *RefundTypeSearch) CreateBatch(records []*RefundType) error {
+ var db = slf.build()
+ return db.Create(records).Error
+}
+
+func (slf *RefundTypeSearch) Delete() error {
+ var db = slf.build()
+ return db.Delete(&RefundType{}).Error
+}
+
+func (slf *RefundTypeSearch) Update(record *RefundType) error {
+ var db = slf.build()
+ return db.Updates(record).Error
+}
+
+func (slf *RefundTypeSearch) FindAll() ([]*RefundType, error) {
+ var db = slf.build()
+ var record = make([]*RefundType, 0)
+ err := db.Find(&record).Error
+ return record, err
+}
+
+func (slf *RefundTypeSearch) SetId(id int) *RefundTypeSearch {
+ slf.Id = id
+ return slf
+}
+
+func (slf *RefundTypeSearch) SetOrm(tx *gorm.DB) *RefundTypeSearch {
+ slf.Orm = tx
+ return slf
+}
+
+func (slf *RefundTypeSearch) First() (*RefundType, error) {
+ var db = slf.build()
+ var record = new(RefundType)
+ err := db.First(record).Error
+ return record, err
+}
+
+func (slf *RefundTypeSearch) Updates(values interface{}) error {
+ var db = slf.build()
+ return db.Updates(values).Error
+}
+
+func (slf *RefundTypeSearch) Save(record *RefundType) error {
+ if record.Id == 0 {
+ return errors.New("id涓虹┖")
+ }
+ var db = slf.build()
+
+ if err := db.Save(record).Error; err != nil {
+ return fmt.Errorf("save err: %v, record: %+v", err, record)
+ }
+
+ return nil
+}
+
+func (slf *RefundTypeSearch) Find() ([]*RefundType, int64, error) {
+ var db = slf.build()
+ var records = make([]*RefundType, 0)
+ var total int64
+ if err := db.Count(&total).Error; err != nil {
+ return records, total, err
+ }
+ if slf.PageNum > 0 && slf.PageSize > 0 {
+ db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
+ }
+
+ err := db.Find(&records).Error
+ return records, total, err
+}
+
+// InitDefaultData 鍒濆鍖栨暟鎹�
+func (slf *RefundTypeSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
+ var (
+ db = slf.Orm.Table(slf.TableName())
+ total int64 = 0
+ )
+ defer wg.Done()
+
+ if err := db.Count(&total).Error; err != nil {
+ errCh <- err
+ return
+ }
+ if total != 0 {
+ return
+ }
+ records := []*RefundType{
+ {1, "鍘熻矾杩斿洖"},
+ {2, "绾夸笅"},
+ {3, "鏀エ"},
+ }
+ err := slf.CreateBatch(records)
+ if err != nil {
+ errCh <- err
+ return
+ }
+}
diff --git a/model/index.go b/model/index.go
index 79e158f..d62248f 100644
--- a/model/index.go
+++ b/model/index.go
@@ -94,6 +94,7 @@
InvoiceStatus{},
InvoiceType{},
Invoice{},
+ RefundType{},
)
return err
}
@@ -140,6 +141,7 @@
NewStatusSearch(),
NewPaymentTypeSearch(),
NewBankAccountSearch(),
+ NewRefundTypeSearch(),
}
for _, model := range models {
diff --git a/model/paymentType.go b/model/paymentType.go
index cd1e6bc..0da5975 100644
--- a/model/paymentType.go
+++ b/model/paymentType.go
@@ -139,10 +139,12 @@
if total != 0 {
return
}
+
records := []*PaymentType{
- {1, "鍘熻矾杩斿洖"},
- {2, "绾夸笅"},
+ {1, "瀵瑰叕杞处"},
+ {2, "绾夸笅浠樻"},
{3, "鏀エ"},
+ {4, "鍏朵粬"},
}
err := slf.CreateBatch(records)
if err != nil {
diff --git a/model/request/RefundType.go b/model/request/RefundType.go
new file mode 100644
index 0000000..556c00d
--- /dev/null
+++ b/model/request/RefundType.go
@@ -0,0 +1,18 @@
+package request
+
+import (
+ "aps_crm/model"
+)
+
+type AddRefundType struct {
+ model.RefundType
+}
+
+type UpdateRefundType struct {
+ Id int `json:"id"`
+ model.RefundType
+}
+
+type GetRefundTypeList struct {
+ PageInfo
+}
diff --git a/model/salesRefund.go b/model/salesRefund.go
index 380aa9a..d4aadd8 100644
--- a/model/salesRefund.go
+++ b/model/salesRefund.go
@@ -23,6 +23,8 @@
RefundDate string `json:"refundDate" gorm:"column:refund_date;type:varchar(255);comment:閫�娆炬棩鏈�"`
PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID
PaymentType PaymentType `gorm:"foreignKey:PaymentTypeId" json:"paymentType"`
+ RefundTypeId int `gorm:"column:refund_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"refundTypeId"` // 閫�娆炬柟寮廔D
+ RefundType RefundType `gorm:"foreignKey:RefundTypeId" json:"RefundType"` //閫�娆炬柟寮�
BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id
BankAccount BankAccount `gorm:"foreignKey:BankAccountId" json:"bankAccount"`
IsInvoice string `json:"isInvoice" gorm:"column:is_invoice;type:varchar(255);comment:鏄惁寮�绁�"`
diff --git a/router/RefundType.go b/router/RefundType.go
new file mode 100644
index 0000000..83a4744
--- /dev/null
+++ b/router/RefundType.go
@@ -0,0 +1,17 @@
+package router
+
+import (
+ v1 "aps_crm/api/v1"
+ "github.com/gin-gonic/gin"
+)
+
+func InitRefundTypeRouter(router *gin.RouterGroup) {
+ RefundTypeRouter := router.Group("refundType")
+ RefundTypeApi := v1.RefundTypeApi{}
+ {
+ RefundTypeRouter.POST("add", RefundTypeApi.Add) // 娣诲姞閫�娆炬柟寮�
+ RefundTypeRouter.DELETE("delete/:id", RefundTypeApi.Delete) // 鍒犻櫎閫�娆炬柟寮�
+ RefundTypeRouter.PUT("update", RefundTypeApi.Update) // 鏇存柊閫�娆炬柟寮�
+ RefundTypeRouter.GET("list", RefundTypeApi.List) // 鑾峰彇閫�娆炬柟寮忓垪琛�
+ }
+}
diff --git a/router/index.go b/router/index.go
index c9d55be..47df283 100644
--- a/router/index.go
+++ b/router/index.go
@@ -184,6 +184,7 @@
InitReceiptRouter(PrivateGroup)
InitBankAccountRouter(PrivateGroup)
InitPaymentTypeRouter(PrivateGroup)
+ InitRefundTypeRouter(PrivateGroup)
InitFileRouter(PrivateGroup)
InitInvoiceRouter(PrivateGroup)
InitInvoiceStatusRouter(PrivateGroup)
diff --git a/service/RefundType.go b/service/RefundType.go
new file mode 100644
index 0000000..3da996a
--- /dev/null
+++ b/service/RefundType.go
@@ -0,0 +1,64 @@
+package service
+
+import (
+ "aps_crm/model"
+ "aps_crm/model/request"
+ "aps_crm/pkg/ecode"
+)
+
+type RefundTypeService struct{}
+
+func NewRefundTypeService() RefundTypeService {
+ return RefundTypeService{}
+}
+
+func (RefundTypeService) AddRefundType(RefundType *model.RefundType) int {
+ err := model.NewRefundTypeSearch().Create(RefundType)
+ if err != nil {
+ return ecode.DBErr
+ }
+
+ return ecode.OK
+}
+
+func (RefundTypeService) DeleteRefundType(id int) int {
+ err := model.NewRefundTypeSearch().SetId(id).Delete()
+ if err != nil {
+ return ecode.DBErr
+ }
+ return ecode.OK
+}
+
+func (RefundTypeService) GetRefundTypeList() ([]*model.RefundType, int64, int) {
+ list, total, err := model.NewRefundTypeSearch().Find()
+ if err != nil {
+ return nil, 0, ecode.DBErr
+ }
+
+ return list, total, ecode.OK
+}
+
+func (RefundTypeService) UpdateRefundTypes(RefundTypes []*request.UpdateRefundType) int {
+ for _, v := range RefundTypes {
+ // check RefundType exist
+ _, err := model.NewRefundTypeSearch().SetId(v.Id).First()
+ if err != nil {
+ return ecode.DBErr
+ }
+
+ err = model.NewRefundTypeSearch().SetId(v.Id).Updates(map[string]interface{}{})
+ if err != nil {
+ return ecode.DBErr
+ }
+ }
+
+ return ecode.OK
+}
+
+func (RefundTypeService) UpdateRefundType(RefundType *model.RefundType) int {
+ err := model.NewRefundTypeSearch().SetId(RefundType.Id).Update(RefundType)
+ if err != nil {
+ return ecode.DBErr
+ }
+ return ecode.OK
+}
--
Gitblit v1.8.0