From 6e87a1f6795af50133b10fa853fd6c2d14bb698c Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期日, 13 八月 2023 15:20:27 +0800
Subject: [PATCH] 完善退款单
---
api/v1/salesRefund.go | 31 ---
model/salesRefund.go | 34 ++-
service/salesRefund.go | 36 ++++
model/request/salesRefund.go | 25 +-
pkg/ecode/code.go | 14 +
constvar/salesRefund.go | 7
docs/swagger.yaml | 68 +++++++
docs/docs.go | 103 ++++++++++++
docs/swagger.json | 103 ++++++++++++
pkg/ecode/msg.go | 2
model/receipt.go | 9
11 files changed, 353 insertions(+), 79 deletions(-)
diff --git a/api/v1/salesRefund.go b/api/v1/salesRefund.go
index 8da5dd5..1027e34 100644
--- a/api/v1/salesRefund.go
+++ b/api/v1/salesRefund.go
@@ -98,34 +98,13 @@
ctx.Ok()
}
-
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.RefundDate = salesRefund.RefundDate
salesRefundRes.ClientId = salesRefund.ClientId
salesRefundRes.Number = salesRefund.Number
salesRefundRes.MemberId = salesRefund.MemberId
- salesRefundRes.RefundMethod = salesRefund.RefundMethod
- salesRefundRes.AccountId = salesRefund.AccountId
+ salesRefundRes.PaymentTypeId = salesRefund.PaymentTypeId
+ salesRefundRes.BankAccountId = salesRefund.BankAccountId
salesRefundRes.IsInvoice = salesRefund.IsInvoice
salesRefundRes.Reason = salesRefund.Reason
salesRefundRes.Products = salesRefund.Products
@@ -155,7 +134,7 @@
}
ctx.OkWithDetailed(response.SalesRefundResponse{
- List: salesRefunds,
+ List: salesRefunds,
Count: int(total),
})
-}
\ No newline at end of file
+}
diff --git a/constvar/salesRefund.go b/constvar/salesRefund.go
new file mode 100644
index 0000000..0f65a91
--- /dev/null
+++ b/constvar/salesRefund.go
@@ -0,0 +1,7 @@
+package constvar
+
+type RefundSourceType int //鏉ユ簮绫诲瀷锛�1閿�鍞��璐э級
+
+const (
+ RefundSourceTypeSalesReturn RefundSourceType = 1 //閿�鍞��璐�
+)
diff --git a/docs/docs.go b/docs/docs.go
index 23edc3c..b96c515 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -10028,6 +10028,18 @@
"ReceiptSourceTypeChuKuDan"
]
},
+ "constvar.RefundSourceType": {
+ "type": "integer",
+ "enum": [
+ 1
+ ],
+ "x-enum-comments": {
+ "RefundSourceTypeSalesReturn": "閿�鍞��璐�"
+ },
+ "x-enum-varnames": [
+ "RefundSourceTypeSalesReturn"
+ ]
+ },
"constvar.SalesDetailsKeywordType": {
"type": "string",
"enum": [
@@ -11282,6 +11294,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -11301,9 +11316,20 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
+ },
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
},
"principalId": {
"description": "璐熻矗浜篿d",
@@ -11721,8 +11747,15 @@
"model.SalesRefund": {
"type": "object",
"properties": {
- "accountId": {
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
+ "bankAccountId": {
+ "description": "璐︽埛id",
"type": "integer"
+ },
+ "client": {
+ "$ref": "#/definitions/model.Client"
},
"clientId": {
"type": "integer"
@@ -11739,6 +11772,13 @@
"number": {
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
+ "paymentTypeId": {
+ "description": "鏀舵鏂瑰紡ID",
+ "type": "integer"
+ },
"products": {
"type": "array",
"items": {
@@ -11751,8 +11791,17 @@
"refundDate": {
"type": "string"
},
- "refundMethod": {
- "type": "string"
+ "sourceId": {
+ "description": "婧愬崟id",
+ "type": "integer"
+ },
+ "sourceType": {
+ "description": "鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級",
+ "allOf": [
+ {
+ "$ref": "#/definitions/constvar.RefundSourceType"
+ }
+ ]
}
}
},
@@ -13187,6 +13236,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -13206,9 +13258,20 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
+ },
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
},
"principalId": {
"description": "璐熻矗浜篿d",
@@ -14933,7 +14996,8 @@
"request.SalesRefund": {
"type": "object",
"properties": {
- "accountId": {
+ "bankAccountId": {
+ "description": "璐︽埛id",
"type": "integer"
},
"clientId": {
@@ -14948,6 +15012,10 @@
"number": {
"type": "string"
},
+ "paymentTypeId": {
+ "description": "鏀舵鏂瑰紡ID",
+ "type": "integer"
+ },
"products": {
"type": "array",
"items": {
@@ -14960,8 +15028,17 @@
"refundDate": {
"type": "string"
},
- "refundMethod": {
- "type": "string"
+ "sourceId": {
+ "description": "婧愬崟id",
+ "type": "integer"
+ },
+ "sourceType": {
+ "description": "鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級",
+ "allOf": [
+ {
+ "$ref": "#/definitions/constvar.RefundSourceType"
+ }
+ ]
}
}
},
@@ -16067,6 +16144,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -16086,10 +16166,21 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
},
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
+ },
"principalId": {
"description": "璐熻矗浜篿d",
"type": "integer"
diff --git a/docs/swagger.json b/docs/swagger.json
index cc9cc72..b653cad 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -10016,6 +10016,18 @@
"ReceiptSourceTypeChuKuDan"
]
},
+ "constvar.RefundSourceType": {
+ "type": "integer",
+ "enum": [
+ 1
+ ],
+ "x-enum-comments": {
+ "RefundSourceTypeSalesReturn": "閿�鍞��璐�"
+ },
+ "x-enum-varnames": [
+ "RefundSourceTypeSalesReturn"
+ ]
+ },
"constvar.SalesDetailsKeywordType": {
"type": "string",
"enum": [
@@ -11270,6 +11282,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -11289,9 +11304,20 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
+ },
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
},
"principalId": {
"description": "璐熻矗浜篿d",
@@ -11709,8 +11735,15 @@
"model.SalesRefund": {
"type": "object",
"properties": {
- "accountId": {
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
+ "bankAccountId": {
+ "description": "璐︽埛id",
"type": "integer"
+ },
+ "client": {
+ "$ref": "#/definitions/model.Client"
},
"clientId": {
"type": "integer"
@@ -11727,6 +11760,13 @@
"number": {
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
+ "paymentTypeId": {
+ "description": "鏀舵鏂瑰紡ID",
+ "type": "integer"
+ },
"products": {
"type": "array",
"items": {
@@ -11739,8 +11779,17 @@
"refundDate": {
"type": "string"
},
- "refundMethod": {
- "type": "string"
+ "sourceId": {
+ "description": "婧愬崟id",
+ "type": "integer"
+ },
+ "sourceType": {
+ "description": "鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級",
+ "allOf": [
+ {
+ "$ref": "#/definitions/constvar.RefundSourceType"
+ }
+ ]
}
}
},
@@ -13175,6 +13224,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -13194,9 +13246,20 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
+ },
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
},
"principalId": {
"description": "璐熻矗浜篿d",
@@ -14921,7 +14984,8 @@
"request.SalesRefund": {
"type": "object",
"properties": {
- "accountId": {
+ "bankAccountId": {
+ "description": "璐︽埛id",
"type": "integer"
},
"clientId": {
@@ -14936,6 +15000,10 @@
"number": {
"type": "string"
},
+ "paymentTypeId": {
+ "description": "鏀舵鏂瑰紡ID",
+ "type": "integer"
+ },
"products": {
"type": "array",
"items": {
@@ -14948,8 +15016,17 @@
"refundDate": {
"type": "string"
},
- "refundMethod": {
- "type": "string"
+ "sourceId": {
+ "description": "婧愬崟id",
+ "type": "integer"
+ },
+ "sourceType": {
+ "description": "鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級",
+ "allOf": [
+ {
+ "$ref": "#/definitions/constvar.RefundSourceType"
+ }
+ ]
}
}
},
@@ -16055,6 +16132,9 @@
"description": "鏀舵閲戦",
"type": "number"
},
+ "bankAccount": {
+ "$ref": "#/definitions/model.BankAccount"
+ },
"bankAccountId": {
"description": "璐︽埛id",
"type": "integer"
@@ -16074,10 +16154,21 @@
"description": "甯佺",
"type": "string"
},
+ "paymentType": {
+ "$ref": "#/definitions/model.PaymentType"
+ },
"paymentTypeId": {
"description": "鏀舵鏂瑰紡ID",
"type": "integer"
},
+ "principal": {
+ "description": "璐熻矗浜篿d",
+ "allOf": [
+ {
+ "$ref": "#/definitions/model.User"
+ }
+ ]
+ },
"principalId": {
"description": "璐熻矗浜篿d",
"type": "integer"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 787e7f1..6e74083 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -142,6 +142,14 @@
- ReceiptSourceTypeInvoice
- ReceiptSourceTypeCollectionPlan
- ReceiptSourceTypeChuKuDan
+ constvar.RefundSourceType:
+ enum:
+ - 1
+ type: integer
+ x-enum-comments:
+ RefundSourceTypeSalesReturn: 閿�鍞��璐�
+ x-enum-varnames:
+ - RefundSourceTypeSalesReturn
constvar.SalesDetailsKeywordType:
enum:
- 瀹㈡埛鍚嶇О
@@ -1002,6 +1010,8 @@
amount:
description: 鏀舵閲戦
type: number
+ bankAccount:
+ $ref: '#/definitions/model.BankAccount'
bankAccountId:
description: 璐︽埛id
type: integer
@@ -1016,9 +1026,15 @@
moneyType:
description: 甯佺
type: string
+ paymentType:
+ $ref: '#/definitions/model.PaymentType'
paymentTypeId:
description: 鏀舵鏂瑰紡ID
type: integer
+ principal:
+ allOf:
+ - $ref: '#/definitions/model.User'
+ description: 璐熻矗浜篿d
principalId:
description: 璐熻矗浜篿d
type: integer
@@ -1294,8 +1310,13 @@
type: object
model.SalesRefund:
properties:
- accountId:
+ bankAccount:
+ $ref: '#/definitions/model.BankAccount'
+ bankAccountId:
+ description: 璐︽埛id
type: integer
+ client:
+ $ref: '#/definitions/model.Client'
clientId:
type: integer
id:
@@ -1306,6 +1327,11 @@
type: integer
number:
type: string
+ paymentType:
+ $ref: '#/definitions/model.PaymentType'
+ paymentTypeId:
+ description: 鏀舵鏂瑰紡ID
+ type: integer
products:
items:
$ref: '#/definitions/model.Product'
@@ -1314,8 +1340,13 @@
type: string
refundDate:
type: string
- refundMethod:
- type: string
+ sourceId:
+ description: 婧愬崟id
+ type: integer
+ sourceType:
+ allOf:
+ - $ref: '#/definitions/constvar.RefundSourceType'
+ description: 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
type: object
model.SalesReturn:
properties:
@@ -2283,6 +2314,8 @@
amount:
description: 鏀舵閲戦
type: number
+ bankAccount:
+ $ref: '#/definitions/model.BankAccount'
bankAccountId:
description: 璐︽埛id
type: integer
@@ -2297,9 +2330,15 @@
moneyType:
description: 甯佺
type: string
+ paymentType:
+ $ref: '#/definitions/model.PaymentType'
paymentTypeId:
description: 鏀舵鏂瑰紡ID
type: integer
+ principal:
+ allOf:
+ - $ref: '#/definitions/model.User'
+ description: 璐熻矗浜篿d
principalId:
description: 璐熻矗浜篿d
type: integer
@@ -3482,7 +3521,8 @@
type: object
request.SalesRefund:
properties:
- accountId:
+ bankAccountId:
+ description: 璐︽埛id
type: integer
clientId:
type: integer
@@ -3492,6 +3532,9 @@
type: integer
number:
type: string
+ paymentTypeId:
+ description: 鏀舵鏂瑰紡ID
+ type: integer
products:
items:
$ref: '#/definitions/model.Product'
@@ -3500,8 +3543,13 @@
type: string
refundDate:
type: string
- refundMethod:
- type: string
+ sourceId:
+ description: 婧愬崟id
+ type: integer
+ sourceType:
+ allOf:
+ - $ref: '#/definitions/constvar.RefundSourceType'
+ description: 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
type: object
request.SalesReturn:
properties:
@@ -4245,6 +4293,8 @@
amount:
description: 鏀舵閲戦
type: number
+ bankAccount:
+ $ref: '#/definitions/model.BankAccount'
bankAccountId:
description: 璐︽埛id
type: integer
@@ -4259,9 +4309,15 @@
moneyType:
description: 甯佺
type: string
+ paymentType:
+ $ref: '#/definitions/model.PaymentType'
paymentTypeId:
description: 鏀舵鏂瑰紡ID
type: integer
+ principal:
+ allOf:
+ - $ref: '#/definitions/model.User'
+ description: 璐熻矗浜篿d
principalId:
description: 璐熻矗浜篿d
type: integer
diff --git a/model/receipt.go b/model/receipt.go
index bd862ba..c93385f 100644
--- a/model/receipt.go
+++ b/model/receipt.go
@@ -17,13 +17,16 @@
SourceType constvar.ReceiptSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"` // 婧愬崟id
PrincipalId int `gorm:"column:principal_id;type:int;not null;default 0;comment:璐熻矗浜篿d" json:"principalId"` // 璐熻矗浜篿d
+ Principal User `gorm:"foreignKey:PrincipalId" json:"principal"` // 璐熻矗浜篿d
ReceiptDate string `gorm:"column:receipt_date;type:varchar(255);not null;default '';comment:鏀舵鏃ユ湡" json:"receiptDate"` // 鏀舵鏃ユ湡
MoneyType string `gorm:"column:money_type;type:varchar(255);not null;default '';comment:甯佺" json:"moneyType"` // 甯佺
Amount decimal.Decimal `gorm:"column:amount;type:decimal(12,2);not null;default '0.00';comment:鏀舵閲戦" json:"amount"` // 鏀舵閲戦
PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID
- BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id
- Remark string `gorm:"column:remark;type:varchar(255);not null;default '';comment:澶囨敞" json:"remark"` // 澶囨敞
- FileId int `gorm:"column:file_id;type:int;not null;default 0;comment:闄勪欢id" json:"fileId"` // 闄勪欢id
+ PaymentType PaymentType `gorm:"foreignKey:PaymentTypeId" json:"paymentType"`
+ 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"`
+ Remark string `gorm:"column:remark;type:varchar(255);not null;default '';comment:澶囨敞" json:"remark"` // 澶囨敞
+ FileId int `gorm:"column:file_id;type:int;not null;default 0;comment:闄勪欢id" json:"fileId"` // 闄勪欢id
gorm.Model `json:"-"`
}
diff --git a/model/request/salesRefund.go b/model/request/salesRefund.go
index 04b792b..bc31ee5 100644
--- a/model/request/salesRefund.go
+++ b/model/request/salesRefund.go
@@ -1,21 +1,26 @@
package request
-import "aps_crm/model"
+import (
+ "aps_crm/constvar"
+ "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"`
+ ClientId int `json:"clientId"`
+ Number string `json:"number"`
+ MemberId int `json:"memberId"`
+ SourceType constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
+ SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"` // 婧愬崟id
+ RefundDate string `json:"refundDate"`
+ PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID
+ BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id
+ IsInvoice int `json:"isInvoice"`
+ Reason string `json:"reason"`
+ Products []*model.Product `json:"products"`
}
type UpdateSalesRefundRequest struct {
diff --git a/model/salesRefund.go b/model/salesRefund.go
index e34be5b..0874372 100644
--- a/model/salesRefund.go
+++ b/model/salesRefund.go
@@ -1,35 +1,39 @@
package model
import (
+ "aps_crm/constvar"
"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;"`
- gorm.Model `json:"-"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+ 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閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級" json:"sourceType"` // 鏉ユ簮绫诲瀷锛�1閿�鍞槑缁嗗崟2鏈嶅姟鍚堝悓3閿�鍞彂绁�4鏀舵璁″垝5鍑哄簱鍗曪級
+ SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:婧愬崟id " json:"sourceId"` // 婧愬崟id
+ MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+ RefundDate string `json:"refundDate" gorm:"column:refund_date;type:datetime;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"`
+ 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 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;"`
+ gorm.Model `json:"-"`
}
SalesRefundSearch struct {
SalesRefund
- Orm *gorm.DB
+ Orm *gorm.DB
Keyword string
OrderBy string
PageNum int
PageSize int
-
}
)
@@ -114,4 +118,4 @@
func (slf *SalesRefundSearch) SetOrder(order string) *SalesRefundSearch {
slf.OrderBy = order
return slf
-}
\ No newline at end of file
+}
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 6a3d1a2..45a6ee9 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -214,12 +214,14 @@
SalesReturnUpdateErr = 2900005 // 鏇存柊閿�鍞��璐у崟澶辫触
SalesReturnDeleteErr = 2900006 // 鍒犻櫎閿�鍞��璐у崟澶辫触
- SalesRefundExist = 3000001 // 閿�鍞��娆惧崟宸插瓨鍦�
- SalesRefundNotExist = 3000002 // 閿�鍞��娆惧崟涓嶅瓨鍦�
- SalesRefundListErr = 3000003 // 鑾峰彇閿�鍞��娆惧崟鍒楄〃澶辫触
- SalesRefundSetErr = 3000004 // 璁剧疆閿�鍞��娆惧崟澶辫触
- SalesRefundUpdateErr = 3000005 // 鏇存柊閿�鍞��娆惧崟澶辫触
- SalesRefundDeleteErr = 3000006 // 鍒犻櫎閿�鍞��娆惧崟澶辫触
+ SalesRefundExist = 3000001 // 閿�鍞��娆惧崟宸插瓨鍦�
+ SalesRefundNotExist = 3000002 // 閿�鍞��娆惧崟涓嶅瓨鍦�
+ SalesRefundListErr = 3000003 // 鑾峰彇閿�鍞��娆惧崟鍒楄〃澶辫触
+ SalesRefundSetErr = 3000004 // 璁剧疆閿�鍞��娆惧崟澶辫触
+ SalesRefundUpdateErr = 3000005 // 鏇存柊閿�鍞��娆惧崟澶辫触
+ SalesRefundDeleteErr = 3000006 // 鍒犻櫎閿�鍞��娆惧崟澶辫触
+ SalesRefundProductNotExist = 3000007 // 閫�璐т骇鍝佷笉瀛樺湪
+ SalesRefundProductPriceOrAmountErr = 3000009 // 閫�璐т骇鍝佷环鏍兼垨鏁伴噺閿欒
ContractExist = 3100001 // 鍚堝悓宸插瓨鍦�
ContractNotExist = 3100002 // 鍚堝悓涓嶅瓨鍦�
diff --git a/pkg/ecode/msg.go b/pkg/ecode/msg.go
index deeff57..f0df18e 100644
--- a/pkg/ecode/msg.go
+++ b/pkg/ecode/msg.go
@@ -23,6 +23,8 @@
SContractProductPriceLowerThanInvoiceAmountErr: "浜у搧鎬讳环浣庝簬宸插紑绁ㄩ噾棰�",
SContractProductPriceLowerThanReceivedAmountErr: "浜у搧鎬讳环浣庝簬宸叉敹閲戦",
SContractInvoiceProductPriceGreaterThanReceivableAmountErr: "寮�绁ㄦ�婚楂樹簬搴旀敹閲戦",
+ SalesRefundProductNotExist: "閫�璐т骇鍝佷笉瀛樺湪",
+ SalesRefundProductPriceOrAmountErr: "閫�璐т骇鍝佷环鏍兼垨鏁伴噺閿欒",
}
func GetMsg(errCode int) (errMsg string) {
diff --git a/service/salesRefund.go b/service/salesRefund.go
index de91872..d3414df 100644
--- a/service/salesRefund.go
+++ b/service/salesRefund.go
@@ -8,11 +8,36 @@
type SalesRefundService struct{}
func (SalesRefundService) AddSalesRefund(salesRefund *model.SalesRefund) int {
- err := model.NewSalesRefundSearch().Create(salesRefund)
+ salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Find()
+ if err != nil {
+ return ecode.SalesReturnNotExist
+ }
+
+ if code := CheckProduct(salesReturnRecord.Products, salesRefund.Products); code != ecode.OK {
+ return code
+ }
+
+ err = model.NewSalesRefundSearch().Create(salesRefund)
if err != nil {
return ecode.SalesRefundExist
}
+ return ecode.OK
+}
+
+func CheckProduct(returnProducts, refundProducts []*model.Product) int {
+ returnProductsMap := make(map[uint]*model.Product, len(returnProducts))
+ for _, product := range returnProducts {
+ returnProductsMap[product.Id] = product
+ }
+ for _, product := range refundProducts {
+ if returnProductsMap[product.Id] == nil {
+ return ecode.SalesRefundProductNotExist
+ }
+ if returnProductsMap[product.Id].Price != product.Price || product.Amount.GreaterThan(returnProductsMap[product.Id].Amount) {
+ return ecode.SalesRefundProductPriceOrAmountErr
+ }
+ }
return ecode.OK
}
@@ -36,6 +61,15 @@
return ecode.SalesRefundNotExist
}
+ salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Find()
+ if err != nil {
+ return ecode.SalesReturnNotExist
+ }
+
+ if code := CheckProduct(salesReturnRecord.Products, salesRefund.Products); code != ecode.OK {
+ return code
+ }
+
err = model.NewSalesRefundSearch().SetId(salesRefund.Id).Update(salesRefund)
if err != nil {
return ecode.SalesRefundSetErr
--
Gitblit v1.8.0