| | |
| | | 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 |
| | | } |
| | |
| | | "OrderStatusCompleted" |
| | | ] |
| | | }, |
| | | "purchase.PriceAdjustmentType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "PriceAdjustmentTypeAdd": "增加", |
| | | "PriceAdjustmentTypeSub": "减少" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "PriceAdjustmentTypeAdd", |
| | | "PriceAdjustmentTypeSub" |
| | | ] |
| | | }, |
| | | "purchase.Purchase": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "orderSource": { |
| | | "description": "单据来源", |
| | | "type": "string" |
| | | }, |
| | | "orderType": { |
| | | "description": "单据类型", |
| | | "type": "string" |
| | |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | | }, |
| | | "priceAdjustment": { |
| | | "description": "价格调整值", |
| | | "type": "number" |
| | | }, |
| | | "priceAdjustmentType": { |
| | | "description": "价格调整类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.PriceAdjustmentType" |
| | | } |
| | | ] |
| | | }, |
| | | "purchaseType": { |
| | | "$ref": "#/definitions/purchase.PurchaseType" |
| | |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "realTotalPrice": { |
| | | "description": "最终价格", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "totalPrice": { |
| | | "description": "价税合计", |
| | | "type": "number" |
| | | }, |
| | | "warehouse": { |
| | | "description": "收货仓库", |
| | | "type": "string" |
| | | }, |
| | | "wholeDiscount": { |
| | | "description": "整单折扣值", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscountType": { |
| | | "description": "整单折扣类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.WholeDiscountType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "price": { |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "product": { |
| | | "$ref": "#/definitions/test.Product" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "purchase.WholeDiscountType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "WholeDiscountTypeDiscount": "直接降价", |
| | | "WholeDiscountTypePercent": "百分比降价" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "WholeDiscountTypePercent", |
| | | "WholeDiscountTypeDiscount" |
| | | ] |
| | | }, |
| | | "purchaserequest.AddPurchase": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "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": "备注", |
| | |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "totalPrice": { |
| | | "description": "价税合计", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscount": { |
| | | "description": "整单折扣值", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscountType": { |
| | | "description": "整单折扣类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.WholeDiscountType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "OrderStatusCompleted" |
| | | ] |
| | | }, |
| | | "purchase.PriceAdjustmentType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "PriceAdjustmentTypeAdd": "增加", |
| | | "PriceAdjustmentTypeSub": "减少" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "PriceAdjustmentTypeAdd", |
| | | "PriceAdjustmentTypeSub" |
| | | ] |
| | | }, |
| | | "purchase.Purchase": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "orderSource": { |
| | | "description": "单据来源", |
| | | "type": "string" |
| | | }, |
| | | "orderType": { |
| | | "description": "单据类型", |
| | | "type": "string" |
| | |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | | }, |
| | | "priceAdjustment": { |
| | | "description": "价格调整值", |
| | | "type": "number" |
| | | }, |
| | | "priceAdjustmentType": { |
| | | "description": "价格调整类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.PriceAdjustmentType" |
| | | } |
| | | ] |
| | | }, |
| | | "purchaseType": { |
| | | "$ref": "#/definitions/purchase.PurchaseType" |
| | |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "realTotalPrice": { |
| | | "description": "最终价格", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "totalPrice": { |
| | | "description": "价税合计", |
| | | "type": "number" |
| | | }, |
| | | "warehouse": { |
| | | "description": "收货仓库", |
| | | "type": "string" |
| | | }, |
| | | "wholeDiscount": { |
| | | "description": "整单折扣值", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscountType": { |
| | | "description": "整单折扣类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.WholeDiscountType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "price": { |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "product": { |
| | | "$ref": "#/definitions/test.Product" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | |
| | | } |
| | | } |
| | | }, |
| | | "purchase.WholeDiscountType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1, |
| | | 2 |
| | | ], |
| | | "x-enum-comments": { |
| | | "WholeDiscountTypeDiscount": "直接降价", |
| | | "WholeDiscountTypePercent": "百分比降价" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "WholeDiscountTypePercent", |
| | | "WholeDiscountTypeDiscount" |
| | | ] |
| | | }, |
| | | "purchaserequest.AddPurchase": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "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": "备注", |
| | |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "totalPrice": { |
| | | "description": "价税合计", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscount": { |
| | | "description": "整单折扣值", |
| | | "type": "number" |
| | | }, |
| | | "wholeDiscountType": { |
| | | "description": "整单折扣类型", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/purchase.WholeDiscountType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | - OrderStatusReceived |
| | | - OrderStatusStored |
| | | - OrderStatusCompleted |
| | | purchase.PriceAdjustmentType: |
| | | enum: |
| | | - 1 |
| | | - 2 |
| | | type: integer |
| | | x-enum-comments: |
| | | PriceAdjustmentTypeAdd: 增加 |
| | | PriceAdjustmentTypeSub: 减少 |
| | | x-enum-varnames: |
| | | - PriceAdjustmentTypeAdd |
| | | - PriceAdjustmentTypeSub |
| | | purchase.Purchase: |
| | | properties: |
| | | contact: |
| | |
| | | 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: |
| | |
| | | type: integer |
| | | quantity: |
| | | description: 采购数量 |
| | | type: number |
| | | realTotalPrice: |
| | | description: 最终价格 |
| | | type: number |
| | | remark: |
| | | description: 备注 |
| | |
| | | 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: |
| | |
| | | price: |
| | | description: 采购单价 |
| | | type: number |
| | | product: |
| | | $ref: '#/definitions/test.Product' |
| | | productId: |
| | | description: 产品id |
| | | type: integer |
| | |
| | | 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: |
| | |
| | | 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 |
| | |
| | | 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: |
| | |
| | | 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 |
| | |
| | | if pat != PriceAdjustmentTypeAdd && pat != PriceAdjustmentTypeSub { |
| | | return false |
| | | } |
| | | if pat == PriceAdjustmentTypeSub && value.GreaterThanOrEqual(totalPrice) { |
| | | if pat == PriceAdjustmentTypeSub && value.GreaterThan(totalPrice) { |
| | | return false |
| | | } |
| | | return true |
| | |
| | | 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:采购总价"` // 采购总价 |