| | |
| | | // @Security ApiKeyAuth |
| | | // @accept application/json |
| | | // @Produce application/json |
| | | // @Param data body purchaserequest.AddPurchase true "采购单用户名, 采购单手机号码" |
| | | // @Param data body purchaserequest.AddPurchase true "采购单,采购单产品" |
| | | // @Success 200 {object} response.Response{msg=string} "创建采购单" |
| | | // @Router /purchase/purchase [post] |
| | | func (e *PurchaseApi) CreatePurchase(c *gin.Context) { |
| | |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: productList}, "获取成功", c) |
| | | respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) |
| | | err = mapstructure.Decode(productList, &respProductList) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | for k, item := range productList { |
| | | respProductList[k].Amount = item.Amount |
| | | respProductList[k].Price = item.Price |
| | | respProductList[k].Total = item.Total |
| | | err = mapstructure.Decode(item.Product, &respProductList[k]) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | return |
| | | } |
| | | } |
| | | |
| | | response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: respProductList}, "获取成功", c) |
| | | } |
| | | |
| | | // GetPurchaseList |
| | |
| | | response.FailWithMessage(err.Error(), c) |
| | | return |
| | | } |
| | | PurchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) |
| | | purchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败"+err.Error(), c) |
| | | return |
| | | } |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: PurchaseList, |
| | | List: purchaseList, |
| | | Total: total, |
| | | Page: pageInfo.Page, |
| | | PageSize: pageInfo.PageSize, |
| | |
| | | iplimit-time: 3600 |
| | | use-multipoint: false |
| | | use-redis: false |
| | | grpc-url: 192.168.20.118:9091 |
| | | grpc-url: 192.168.20.119:9091 |
| | | grpc-admin-url: 192.168.20.119:50051 |
| | | tencent-cos: |
| | | bucket: xxxxx-10005608 |
| | |
| | | "summary": "创建采购单", |
| | | "parameters": [ |
| | | { |
| | | "description": "采购单用户名, 采购单手机号码", |
| | | "description": "采购单,采购单产品", |
| | | "name": "data", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "description": "制单人", |
| | | "type": "string" |
| | | }, |
| | | "deliveryDate": { |
| | | "description": "交付日期", |
| | | "type": "string" |
| | | }, |
| | | "handledBy": { |
| | | "description": "经办人", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "orderType": { |
| | | "description": "单据类型", |
| | | "type": "string" |
| | | }, |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | | "type": "integer" |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "warehouse": { |
| | | "description": "收货仓库", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "product": { |
| | | "$ref": "#/definitions/test.Product" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | |
| | | "purchase.PurchaseType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PurchaseProducts": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "price": { |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchaseId": { |
| | | "description": "采购id", |
| | | "type": "integer" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "total": { |
| | | "description": "采购总价", |
| | | "type": "number" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "response.PurchaseResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "productList": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/purchase.PurchaseProducts" |
| | | "$ref": "#/definitions/response.PurchaseProducts" |
| | | } |
| | | }, |
| | | "purchase": { |
| | |
| | | "summary": "创建采购单", |
| | | "parameters": [ |
| | | { |
| | | "description": "采购单用户名, 采购单手机号码", |
| | | "description": "采购单,采购单产品", |
| | | "name": "data", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "creator": { |
| | | "description": "制单人", |
| | | "type": "string" |
| | | }, |
| | | "deliveryDate": { |
| | | "description": "交付日期", |
| | | "type": "string" |
| | | }, |
| | | "handledBy": { |
| | | "description": "经办人", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | |
| | | "description": "采购编号", |
| | | "type": "string" |
| | | }, |
| | | "orderType": { |
| | | "description": "单据类型", |
| | | "type": "string" |
| | | }, |
| | | "phone": { |
| | | "description": "联系人电话", |
| | | "type": "string" |
| | |
| | | "purchaseTypeId": { |
| | | "description": "采购类型id", |
| | | "type": "integer" |
| | | }, |
| | | "quantity": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "remark": { |
| | | "description": "备注", |
| | |
| | | "supplierId": { |
| | | "description": "供应商id", |
| | | "type": "integer" |
| | | }, |
| | | "warehouse": { |
| | | "description": "收货仓库", |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "product": { |
| | | "$ref": "#/definitions/test.Product" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | |
| | | "purchase.PurchaseType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "created_at": { |
| | | "description": "创建时间", |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "description": "主键ID", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.PurchaseProducts": { |
| | | "type": "object", |
| | | "properties": { |
| | | "amount": { |
| | | "description": "采购数量", |
| | | "type": "number" |
| | | }, |
| | | "deliveryTime": { |
| | | "type": "integer" |
| | | }, |
| | | "modelNumber": { |
| | | "type": "string" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "price": { |
| | | "description": "采购单价", |
| | | "type": "number" |
| | | }, |
| | | "productId": { |
| | | "description": "产品id", |
| | | "type": "integer" |
| | | }, |
| | | "productType": { |
| | | "type": "string" |
| | | }, |
| | | "purchaseId": { |
| | | "description": "采购id", |
| | | "type": "integer" |
| | | }, |
| | | "purchasePrice": { |
| | | "type": "number" |
| | | }, |
| | | "shippingDuration": { |
| | | "type": "integer" |
| | | }, |
| | | "specifications": { |
| | | "type": "string" |
| | | }, |
| | | "total": { |
| | | "description": "采购总价", |
| | | "type": "number" |
| | | }, |
| | | "unit": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "response.PurchaseResponse": { |
| | | "type": "object", |
| | | "properties": { |
| | | "productList": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/purchase.PurchaseProducts" |
| | | "$ref": "#/definitions/response.PurchaseProducts" |
| | | } |
| | | }, |
| | | "purchase": { |
| | |
| | | created_at: |
| | | description: 创建时间 |
| | | type: string |
| | | creator: |
| | | description: 制单人 |
| | | type: string |
| | | deliveryDate: |
| | | description: 交付日期 |
| | | type: string |
| | | handledBy: |
| | | description: 经办人 |
| | | type: string |
| | | id: |
| | | description: 主键ID |
| | |
| | | number: |
| | | description: 采购编号 |
| | | type: string |
| | | orderType: |
| | | description: 单据类型 |
| | | type: string |
| | | phone: |
| | | description: 联系人电话 |
| | | type: string |
| | |
| | | purchaseTypeId: |
| | | description: 采购类型id |
| | | type: integer |
| | | quantity: |
| | | description: 采购数量 |
| | | type: number |
| | | remark: |
| | | description: 备注 |
| | | type: string |
| | |
| | | supplierId: |
| | | description: 供应商id |
| | | type: integer |
| | | warehouse: |
| | | description: 收货仓库 |
| | | type: string |
| | | type: object |
| | | purchase.PurchaseProducts: |
| | | properties: |
| | |
| | | price: |
| | | description: 采购单价 |
| | | type: number |
| | | product: |
| | | $ref: '#/definitions/test.Product' |
| | | productId: |
| | | description: 产品id |
| | | type: integer |
| | |
| | | type: object |
| | | purchase.PurchaseType: |
| | | properties: |
| | | created_at: |
| | | description: 创建时间 |
| | | type: string |
| | | id: |
| | | description: 主键ID |
| | | type: integer |
| | |
| | | $ref: '#/definitions/request.CasbinInfo' |
| | | type: array |
| | | type: object |
| | | response.PurchaseProducts: |
| | | properties: |
| | | amount: |
| | | description: 采购数量 |
| | | type: number |
| | | deliveryTime: |
| | | type: integer |
| | | modelNumber: |
| | | type: string |
| | | name: |
| | | type: string |
| | | number: |
| | | type: string |
| | | price: |
| | | description: 采购单价 |
| | | type: number |
| | | productId: |
| | | description: 产品id |
| | | type: integer |
| | | productType: |
| | | type: string |
| | | purchaseId: |
| | | description: 采购id |
| | | type: integer |
| | | purchasePrice: |
| | | type: number |
| | | shippingDuration: |
| | | type: integer |
| | | specifications: |
| | | type: string |
| | | total: |
| | | description: 采购总价 |
| | | type: number |
| | | unit: |
| | | type: string |
| | | type: object |
| | | response.PurchaseResponse: |
| | | properties: |
| | | productList: |
| | | items: |
| | | $ref: '#/definitions/purchase.PurchaseProducts' |
| | | $ref: '#/definitions/response.PurchaseProducts' |
| | | type: array |
| | | purchase: |
| | | $ref: '#/definitions/purchase.Purchase' |
| | |
| | | consumes: |
| | | - application/json |
| | | parameters: |
| | | - description: 采购单用户名, 采购单手机号码 |
| | | - description: 采购单,采购单产品 |
| | | in: body |
| | | name: data |
| | | required: true |
| | |
| | | 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:制单人"` //制单人 |
| | | OrderType string `json:"orderType" form:"orderType" gorm:"type:varchar(255);not null;default '';comment:单据类型"` //单据类型 |
| | | Warehouse string `json:"warehouse" form:"warehouse" gorm:"type:varchar(255);not null;default '';comment:收货仓库"` //收货仓库 |
| | | } |
| | | |
| | | type OrderStatus int |
| | |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "srm/global" |
| | | "srm/model/test" |
| | | ) |
| | | |
| | | type PurchaseProducts struct { |
| | | 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 |
| | | 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:采购总价"` // 采购总价 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"` //描述 |
| | | Product test.Product `json:"product" 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:采购总价"` // 采购总价 |
| | | Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:描述"` //描述 |
| | | } |
| | |
| | | package response |
| | | |
| | | import "srm/model/purchase" |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "srm/model/purchase" |
| | | ) |
| | | |
| | | type PurchaseResponse struct { |
| | | Purchase purchase.Purchase `json:"purchase"` |
| | | ProductList []*purchase.PurchaseProducts `json:"productList"` |
| | | Purchase purchase.Purchase `json:"purchase"` |
| | | ProductList []*PurchaseProducts `json:"productList"` |
| | | } |
| | | |
| | | type PurchaseProducts struct { |
| | | 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 |
| | | 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:采购总价"` // 采购总价 |
| | | Name string `json:"name" form:"name" gorm:"column:name;comment:名称;size:255;"` |
| | | Number string `json:"number" form:"number" gorm:"column:number;comment:编码;size:255;"` |
| | | Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:计量单位;size:255;"` |
| | | PurchasePrice *float64 `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:采购价格;"` |
| | | DeliveryTime *int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` |
| | | ShippingDuration *int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:物流时长;size:11;"` |
| | | Specifications string `json:"specifications" form:"specifications" gorm:"column:specifications;comment:规格;size:255;"` |
| | | ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:型号;size:255;"` |
| | | ProductType string `json:"productType" form:"productType" gorm:"column:product_type;comment:产品类别;size:255;"` |
| | | } |
| | |
| | | func (slf *PurchaseService) GetPurchaseProductList(purchaseId uint) (list []*purchase.PurchaseProducts, err error) { |
| | | db := global.GVA_DB.Model(&purchase.PurchaseProducts{}) |
| | | list = make([]*purchase.PurchaseProducts, 0) |
| | | err = db.Where("purchase_id = ?", purchaseId).Find(&list).Error |
| | | err = db.Where("purchase_id = ?", purchaseId).Preload("Product").Find(&list).Error |
| | | return list, err |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | func (slf *PurchaseService) SavePurchaseType(list []*purchase.PurchaseType) (err error) { |
| | | ids := make([]uint, 0) |
| | | newRecords := make([]*purchase.PurchaseType, 0) |
| | | for _, item := range list { |
| | | if item.ID != 0 { |
| | | ids = append(ids, item.ID) |
| | | } else { |
| | | newRecords = append(newRecords, item) |
| | | } |
| | | } |
| | | err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { |
| | | err = tx.Where("1 = ?", 1).Delete(&purchase.PurchaseType{}).Error |
| | | err = tx.Where("id not in ?", ids).Delete(&purchase.PurchaseType{}).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | for _, item := range list { |
| | | item.ID = 0 |
| | | if len(newRecords) > 0 { |
| | | err = tx.Create(newRecords).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | } |
| | | return tx.Create(list).Error |
| | | |
| | | for _, item := range list { |
| | | if item.ID != 0 { |
| | | err = tx.Save(item).Error |
| | | if err != nil { |
| | | return err |
| | | } |
| | | } |
| | | } |
| | | return nil |
| | | }) |
| | | return err |
| | | } |