fix
zhangqian
2023-08-29 35edc2fddbd90831ef7bf79043871c9d8d50003d
fix
6个文件已修改
293 ■■■■■ 已修改文件
api/v1/purchase/purchase.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase_products.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/purchase/purchase.go
@@ -36,12 +36,14 @@
    var params purchaserequest.AddPurchase
    err := c.ShouldBindJSON(&params)
    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
    }
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": "供应商id",
                    "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": "供应商id",
                    "type": "integer"
                },
                "totalPrice": {
                    "description": "价税合计",
                    "type": "number"
                },
                "wholeDiscount": {
                    "description": "整单折扣值",
                    "type": "number"
                },
                "wholeDiscountType": {
                    "description": "整单折扣类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.WholeDiscountType"
                        }
                    ]
                }
            }
        },
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": "供应商id",
                    "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": "供应商id",
                    "type": "integer"
                },
                "totalPrice": {
                    "description": "价税合计",
                    "type": "number"
                },
                "wholeDiscount": {
                    "description": "整单折扣值",
                    "type": "number"
                },
                "wholeDiscountType": {
                    "description": "整单折扣类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.WholeDiscountType"
                        }
                    ]
                }
            }
        },
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: 供应商id
        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: 供应商id
        type: integer
      totalPrice:
        description: 价税合计
        type: number
      wholeDiscount:
        description: 整单折扣值
        type: number
      wholeDiscountType:
        allOf:
        - $ref: '#/definitions/purchase.WholeDiscountType'
        description: 整单折扣类型
    type: object
  purchaserequest.PurchaseType:
    properties:
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
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:供应商id"`     // 产品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:采购总价"` // 采购总价