| | |
| | | |
| | | purchaseRecord.ID = 0 |
| | | purchaseRecord.Status = purchase.OrderStatusConfirmed |
| | | purchaseRecord.HandledBy = "admin" |
| | | purchaseRecord.Creator = "admin" |
| | | err = service.NewPurchaseService().CreatePurchase(&purchaseRecord, params.ProductList) |
| | | |
| | | if err != nil { |
| | |
| | | return |
| | | } |
| | | |
| | | purchaseRecord.HandledBy = "admin" |
| | | purchaseRecord.Creator = "admin" |
| | | err = service.NewPurchaseService().UpdatePurchase(&purchaseRecord, params.ProductList) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("更新失败!", zap.Error(err)) |
| | |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "description": "制单人", |
| | | "type": "string" |
| | | }, |
| | | "deliveryDate": { |
| | | "description": "交付日期", |
| | | "type": "string" |
| | | }, |
| | | "handledBy": { |
| | | "description": "经办人", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | | "type": "integer" |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | "purchase.PurchaseType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "description": "制单人", |
| | | "type": "string" |
| | | }, |
| | | "deliveryDate": { |
| | | "description": "交付日期", |
| | | "type": "string" |
| | | }, |
| | | "handledBy": { |
| | | "description": "经办人", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | | "type": "integer" |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | "purchase.PurchaseType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | created_at: |
| | | description: 创建时间 |
| | | type: string |
| | | creator: |
| | | description: 制单人 |
| | | type: string |
| | | deliveryDate: |
| | | description: 交付日期 |
| | | type: string |
| | | handledBy: |
| | | description: 经办人 |
| | | type: string |
| | | id: |
| | | description: 主键ID |
| | |
| | | purchaseTypeId: |
| | | description: 采购类型id |
| | | type: integer |
| | | quantity: |
| | | description: 采购数量 |
| | | type: number |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | |
| | | type: object |
| | | purchase.PurchaseType: |
| | | properties: |
| | | created_at: |
| | | description: 创建时间 |
| | | type: string |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | |
| | | package purchase |
| | | |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "srm/global" |
| | | "srm/model/test" |
| | | ) |
| | | |
| | | type Purchase struct { |
| | | global.GVA_MODEL |
| | | PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购类型id |
| | | PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"` |
| | | SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id |
| | | Supplier test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"` |
| | | Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"` // 采购编号 |
| | | Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"` // 采购名称 |
| | | Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"` // 联系人 |
| | | Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"` // 联系人电话 |
| | | SigningDate string `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:签约日期"` // 签约日期 |
| | | DeliveryDate string `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:交付日期"` //交付日期 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:备注"` //备注 |
| | | Status OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"` //状态 |
| | | PurchaseTypeId int `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购类型id |
| | | PurchaseType PurchaseType `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"` |
| | | SupplierId int `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id |
| | | Supplier test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"` |
| | | Number string `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"` // 采购编号 |
| | | Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"` // 采购名称 |
| | | Quantity decimal.Decimal `json:"quantity" form:"quantity" gorm:"type:decimal(12,4);not null;comment:采购数量"` // 采购数量 |
| | | Contact string `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"` // 联系人 |
| | | Phone string `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"` // 联系人电话 |
| | | SigningDate string `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:签约日期"` // 签约日期 |
| | | DeliveryDate string `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:交付日期"` //交付日期 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:备注"` //备注 |
| | | Status OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"` //状态 |
| | | HandledBy string `json:"handledBy" form:"handledBy" gorm:"type:varchar(255);not null;default '';comment:经办人"` //经办人 |
| | | Creator string `json:"creator" form:"creator" gorm:"type:varchar(255);not null;default '';comment:制单人"` //制单人 |
| | | } |
| | | |
| | | type OrderStatus int |
| | |
| | | |
| | | import ( |
| | | "context" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "srm/global" |
| | |
| | | |
| | | func (slf *PurchaseService) CreatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) { |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | var quantity decimal.Decimal |
| | | for _, product := range productList { |
| | | quantity = quantity.Add(product.Amount) |
| | | } |
| | | params.Quantity = quantity |
| | | err = tx.Create(¶ms).Error |
| | | if err != nil { |
| | | return err |
| | |
| | | |
| | | func (slf *PurchaseService) UpdatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) { |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | var quantity decimal.Decimal |
| | | for _, product := range productList { |
| | | quantity = quantity.Add(product.Amount) |
| | | } |
| | | params.Quantity = quantity |
| | | err = tx.Where("id = ?", params.ID).Updates(params).Error |
| | | if err != nil { |
| | | return err |