From 35edc2fddbd90831ef7bf79043871c9d8d50003d Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 29 八月 2023 19:00:46 +0800
Subject: [PATCH] fix
---
api/v1/purchase/purchase.go | 2
model/purchase/purchase.go | 9 +
model/purchase/purchase_products.go | 2
docs/swagger.yaml | 70 +++++++++++++
docs/docs.go | 105 ++++++++++++++++++++
docs/swagger.json | 105 ++++++++++++++++++++
6 files changed, 280 insertions(+), 13 deletions(-)
diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go
index fe6f3ac..388ddd7 100644
--- a/api/v1/purchase/purchase.go
+++ b/api/v1/purchase/purchase.go
@@ -36,12 +36,14 @@
var params purchaserequest.AddPurchase
err := c.ShouldBindJSON(¶ms)
if err != nil {
+ global.GVA_LOG.Error("Add Purchase failed", zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
var purchaseRecord purchase.Purchase
if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil {
+ global.GVA_LOG.Error("Add Purchase failed", zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
diff --git a/docs/docs.go b/docs/docs.go
index fb4982c..00c67da 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -8414,6 +8414,21 @@
"OrderStatusCompleted"
]
},
+ "purchase.PriceAdjustmentType": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2
+ ],
+ "x-enum-comments": {
+ "PriceAdjustmentTypeAdd": "澧炲姞",
+ "PriceAdjustmentTypeSub": "鍑忓皯"
+ },
+ "x-enum-varnames": [
+ "PriceAdjustmentTypeAdd",
+ "PriceAdjustmentTypeSub"
+ ]
+ },
"purchase.Purchase": {
"type": "object",
"properties": {
@@ -8449,6 +8464,10 @@
"description": "閲囪喘缂栧彿",
"type": "string"
},
+ "orderSource": {
+ "description": "鍗曟嵁鏉ユ簮",
+ "type": "string"
+ },
"orderType": {
"description": "鍗曟嵁绫诲瀷",
"type": "string"
@@ -8456,6 +8475,18 @@
"phone": {
"description": "鑱旂郴浜虹數璇�",
"type": "string"
+ },
+ "priceAdjustment": {
+ "description": "浠锋牸璋冩暣鍊�",
+ "type": "number"
+ },
+ "priceAdjustmentType": {
+ "description": "浠锋牸璋冩暣绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.PriceAdjustmentType"
+ }
+ ]
},
"purchaseType": {
"$ref": "#/definitions/purchase.PurchaseType"
@@ -8466,6 +8497,10 @@
},
"quantity": {
"description": "閲囪喘鏁伴噺",
+ "type": "number"
+ },
+ "realTotalPrice": {
+ "description": "鏈�缁堜环鏍�",
"type": "number"
},
"remark": {
@@ -8491,9 +8526,25 @@
"description": "渚涘簲鍟唅d",
"type": "integer"
},
+ "totalPrice": {
+ "description": "浠风◣鍚堣",
+ "type": "number"
+ },
"warehouse": {
"description": "鏀惰揣浠撳簱",
"type": "string"
+ },
+ "wholeDiscount": {
+ "description": "鏁村崟鎶樻墸鍊�",
+ "type": "number"
+ },
+ "wholeDiscountType": {
+ "description": "鏁村崟鎶樻墸绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.WholeDiscountType"
+ }
+ ]
}
}
},
@@ -8515,9 +8566,6 @@
"price": {
"description": "閲囪喘鍗曚环",
"type": "number"
- },
- "product": {
- "$ref": "#/definitions/test.Product"
},
"productId": {
"description": "浜у搧id",
@@ -8562,6 +8610,21 @@
}
}
},
+ "purchase.WholeDiscountType": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2
+ ],
+ "x-enum-comments": {
+ "WholeDiscountTypeDiscount": "鐩存帴闄嶄环",
+ "WholeDiscountTypePercent": "鐧惧垎姣旈檷浠�"
+ },
+ "x-enum-varnames": [
+ "WholeDiscountTypePercent",
+ "WholeDiscountTypeDiscount"
+ ]
+ },
"purchaserequest.AddPurchase": {
"type": "object",
"properties": {
@@ -8603,9 +8666,29 @@
"description": "鑱旂郴浜虹數璇�",
"type": "string"
},
+ "priceAdjustment": {
+ "description": "浠锋牸璋冩暣鍊�",
+ "type": "number"
+ },
+ "priceAdjustmentType": {
+ "description": "浠锋牸璋冩暣绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.PriceAdjustmentType"
+ }
+ ]
+ },
"purchaseTypeId": {
"description": "閲囪喘绫诲瀷id",
"type": "integer"
+ },
+ "quantity": {
+ "description": "閲囪喘鏁伴噺",
+ "type": "number"
+ },
+ "realTotalPrice": {
+ "description": "鏈�缁堜环鏍�",
+ "type": "number"
},
"remark": {
"description": "澶囨敞",
@@ -8626,6 +8709,22 @@
"supplierId": {
"description": "渚涘簲鍟唅d",
"type": "integer"
+ },
+ "totalPrice": {
+ "description": "浠风◣鍚堣",
+ "type": "number"
+ },
+ "wholeDiscount": {
+ "description": "鏁村崟鎶樻墸鍊�",
+ "type": "number"
+ },
+ "wholeDiscountType": {
+ "description": "鏁村崟鎶樻墸绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.WholeDiscountType"
+ }
+ ]
}
}
},
diff --git a/docs/swagger.json b/docs/swagger.json
index 6e56b99..af79a49 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -8405,6 +8405,21 @@
"OrderStatusCompleted"
]
},
+ "purchase.PriceAdjustmentType": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2
+ ],
+ "x-enum-comments": {
+ "PriceAdjustmentTypeAdd": "澧炲姞",
+ "PriceAdjustmentTypeSub": "鍑忓皯"
+ },
+ "x-enum-varnames": [
+ "PriceAdjustmentTypeAdd",
+ "PriceAdjustmentTypeSub"
+ ]
+ },
"purchase.Purchase": {
"type": "object",
"properties": {
@@ -8440,6 +8455,10 @@
"description": "閲囪喘缂栧彿",
"type": "string"
},
+ "orderSource": {
+ "description": "鍗曟嵁鏉ユ簮",
+ "type": "string"
+ },
"orderType": {
"description": "鍗曟嵁绫诲瀷",
"type": "string"
@@ -8447,6 +8466,18 @@
"phone": {
"description": "鑱旂郴浜虹數璇�",
"type": "string"
+ },
+ "priceAdjustment": {
+ "description": "浠锋牸璋冩暣鍊�",
+ "type": "number"
+ },
+ "priceAdjustmentType": {
+ "description": "浠锋牸璋冩暣绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.PriceAdjustmentType"
+ }
+ ]
},
"purchaseType": {
"$ref": "#/definitions/purchase.PurchaseType"
@@ -8457,6 +8488,10 @@
},
"quantity": {
"description": "閲囪喘鏁伴噺",
+ "type": "number"
+ },
+ "realTotalPrice": {
+ "description": "鏈�缁堜环鏍�",
"type": "number"
},
"remark": {
@@ -8482,9 +8517,25 @@
"description": "渚涘簲鍟唅d",
"type": "integer"
},
+ "totalPrice": {
+ "description": "浠风◣鍚堣",
+ "type": "number"
+ },
"warehouse": {
"description": "鏀惰揣浠撳簱",
"type": "string"
+ },
+ "wholeDiscount": {
+ "description": "鏁村崟鎶樻墸鍊�",
+ "type": "number"
+ },
+ "wholeDiscountType": {
+ "description": "鏁村崟鎶樻墸绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.WholeDiscountType"
+ }
+ ]
}
}
},
@@ -8506,9 +8557,6 @@
"price": {
"description": "閲囪喘鍗曚环",
"type": "number"
- },
- "product": {
- "$ref": "#/definitions/test.Product"
},
"productId": {
"description": "浜у搧id",
@@ -8553,6 +8601,21 @@
}
}
},
+ "purchase.WholeDiscountType": {
+ "type": "integer",
+ "enum": [
+ 1,
+ 2
+ ],
+ "x-enum-comments": {
+ "WholeDiscountTypeDiscount": "鐩存帴闄嶄环",
+ "WholeDiscountTypePercent": "鐧惧垎姣旈檷浠�"
+ },
+ "x-enum-varnames": [
+ "WholeDiscountTypePercent",
+ "WholeDiscountTypeDiscount"
+ ]
+ },
"purchaserequest.AddPurchase": {
"type": "object",
"properties": {
@@ -8594,9 +8657,29 @@
"description": "鑱旂郴浜虹數璇�",
"type": "string"
},
+ "priceAdjustment": {
+ "description": "浠锋牸璋冩暣鍊�",
+ "type": "number"
+ },
+ "priceAdjustmentType": {
+ "description": "浠锋牸璋冩暣绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.PriceAdjustmentType"
+ }
+ ]
+ },
"purchaseTypeId": {
"description": "閲囪喘绫诲瀷id",
"type": "integer"
+ },
+ "quantity": {
+ "description": "閲囪喘鏁伴噺",
+ "type": "number"
+ },
+ "realTotalPrice": {
+ "description": "鏈�缁堜环鏍�",
+ "type": "number"
},
"remark": {
"description": "澶囨敞",
@@ -8617,6 +8700,22 @@
"supplierId": {
"description": "渚涘簲鍟唅d",
"type": "integer"
+ },
+ "totalPrice": {
+ "description": "浠风◣鍚堣",
+ "type": "number"
+ },
+ "wholeDiscount": {
+ "description": "鏁村崟鎶樻墸鍊�",
+ "type": "number"
+ },
+ "wholeDiscountType": {
+ "description": "鏁村崟鎶樻墸绫诲瀷",
+ "allOf": [
+ {
+ "$ref": "#/definitions/purchase.WholeDiscountType"
+ }
+ ]
}
}
},
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index d593c53..265cc91 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -694,6 +694,17 @@
- OrderStatusReceived
- OrderStatusStored
- OrderStatusCompleted
+ purchase.PriceAdjustmentType:
+ enum:
+ - 1
+ - 2
+ type: integer
+ x-enum-comments:
+ PriceAdjustmentTypeAdd: 澧炲姞
+ PriceAdjustmentTypeSub: 鍑忓皯
+ x-enum-varnames:
+ - PriceAdjustmentTypeAdd
+ - PriceAdjustmentTypeSub
purchase.Purchase:
properties:
contact:
@@ -720,12 +731,22 @@
number:
description: 閲囪喘缂栧彿
type: string
+ orderSource:
+ description: 鍗曟嵁鏉ユ簮
+ type: string
orderType:
description: 鍗曟嵁绫诲瀷
type: string
phone:
description: 鑱旂郴浜虹數璇�
type: string
+ priceAdjustment:
+ description: 浠锋牸璋冩暣鍊�
+ type: number
+ priceAdjustmentType:
+ allOf:
+ - $ref: '#/definitions/purchase.PriceAdjustmentType'
+ description: 浠锋牸璋冩暣绫诲瀷
purchaseType:
$ref: '#/definitions/purchase.PurchaseType'
purchaseTypeId:
@@ -733,6 +754,9 @@
type: integer
quantity:
description: 閲囪喘鏁伴噺
+ type: number
+ realTotalPrice:
+ description: 鏈�缁堜环鏍�
type: number
remark:
description: 澶囨敞
@@ -749,9 +773,19 @@
supplierId:
description: 渚涘簲鍟唅d
type: integer
+ totalPrice:
+ description: 浠风◣鍚堣
+ type: number
warehouse:
description: 鏀惰揣浠撳簱
type: string
+ wholeDiscount:
+ description: 鏁村崟鎶樻墸鍊�
+ type: number
+ wholeDiscountType:
+ allOf:
+ - $ref: '#/definitions/purchase.WholeDiscountType'
+ description: 鏁村崟鎶樻墸绫诲瀷
type: object
purchase.PurchaseProducts:
properties:
@@ -767,8 +801,6 @@
price:
description: 閲囪喘鍗曚环
type: number
- product:
- $ref: '#/definitions/test.Product'
productId:
description: 浜у搧id
type: integer
@@ -800,6 +832,17 @@
description: 鎺掑簭
type: integer
type: object
+ purchase.WholeDiscountType:
+ enum:
+ - 1
+ - 2
+ type: integer
+ x-enum-comments:
+ WholeDiscountTypeDiscount: 鐩存帴闄嶄环
+ WholeDiscountTypePercent: 鐧惧垎姣旈檷浠�
+ x-enum-varnames:
+ - WholeDiscountTypePercent
+ - WholeDiscountTypeDiscount
purchaserequest.AddPurchase:
properties:
productList:
@@ -829,9 +872,22 @@
phone:
description: 鑱旂郴浜虹數璇�
type: string
+ priceAdjustment:
+ description: 浠锋牸璋冩暣鍊�
+ type: number
+ priceAdjustmentType:
+ allOf:
+ - $ref: '#/definitions/purchase.PriceAdjustmentType'
+ description: 浠锋牸璋冩暣绫诲瀷
purchaseTypeId:
description: 閲囪喘绫诲瀷id
type: integer
+ quantity:
+ description: 閲囪喘鏁伴噺
+ type: number
+ realTotalPrice:
+ description: 鏈�缁堜环鏍�
+ type: number
remark:
description: 澶囨敞
type: string
@@ -845,6 +901,16 @@
supplierId:
description: 渚涘簲鍟唅d
type: integer
+ totalPrice:
+ description: 浠风◣鍚堣
+ type: number
+ wholeDiscount:
+ description: 鏁村崟鎶樻墸鍊�
+ type: number
+ wholeDiscountType:
+ allOf:
+ - $ref: '#/definitions/purchase.WholeDiscountType'
+ description: 鏁村崟鎶樻墸绫诲瀷
type: object
purchaserequest.PurchaseType:
properties:
diff --git a/model/purchase/purchase.go b/model/purchase/purchase.go
index 4506751..d9f7acd 100644
--- a/model/purchase/purchase.go
+++ b/model/purchase/purchase.go
@@ -46,18 +46,19 @@
type WholeDiscountType int
const (
+ WholeDiscountTypeDefault WholeDiscountType = 0 //鏃犳姌鎵�
WholeDiscountTypePercent WholeDiscountType = 1 //鐧惧垎姣旈檷浠�
WholeDiscountTypeDiscount WholeDiscountType = 2 //鐩存帴闄嶄环
)
func (wdt WholeDiscountType) IsValid(totalPrice, value decimal.Decimal) bool {
- if wdt != WholeDiscountTypePercent && wdt != WholeDiscountTypeDiscount {
+ if wdt != WholeDiscountTypePercent && wdt != WholeDiscountTypeDiscount && wdt != WholeDiscountTypeDefault {
return false
}
- if wdt == WholeDiscountTypeDiscount && value.GreaterThanOrEqual(totalPrice) {
+ if wdt == WholeDiscountTypeDiscount && value.GreaterThan(totalPrice) {
return false
}
- if wdt == WholeDiscountTypePercent && totalPrice.Mul(value).Div(decimal.NewFromInt(100)).GreaterThanOrEqual(totalPrice) {
+ if wdt == WholeDiscountTypePercent && totalPrice.Mul(value).Div(decimal.NewFromInt(100)).GreaterThan(totalPrice) {
return false
}
return true
@@ -74,7 +75,7 @@
if pat != PriceAdjustmentTypeAdd && pat != PriceAdjustmentTypeSub {
return false
}
- if pat == PriceAdjustmentTypeSub && value.GreaterThanOrEqual(totalPrice) {
+ if pat == PriceAdjustmentTypeSub && value.GreaterThan(totalPrice) {
return false
}
return true
diff --git a/model/purchase/purchase_products.go b/model/purchase/purchase_products.go
index 20373de..c04ff6b 100644
--- a/model/purchase/purchase_products.go
+++ b/model/purchase/purchase_products.go
@@ -10,7 +10,7 @@
global.GVA_MODEL
PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘id
ProductId int `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 浜у搧id
- Product test.Product `json:"product" gorm:"foreignKey:ProductId"`
+ Product test.Product `json:"-" gorm:"foreignKey:ProductId"`
Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:閲囪喘鏁伴噺"` // 閲囪喘鏁伴噺
Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鍗曚环"` // 閲囪喘鍗曚环
Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鎬讳环"` // 閲囪喘鎬讳环
--
Gitblit v1.8.0