feat:完善项目
This commit is contained in:
66
app/controller/manage/material_warehouse.go
Normal file
66
app/controller/manage/material_warehouse.go
Normal file
@ -0,0 +1,66 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MaterialWarehouse struct{ *service.Session }
|
||||
|
||||
type MaterialWarehouseHandle func(session *service.Session) *MaterialWarehouse
|
||||
|
||||
func (c *MaterialWarehouse) List() (*basic.PageDataResponse, error) {
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
||||
// Launch 入库发起
|
||||
func (c *MaterialWarehouse) Launch(materialPurchaseID uint64, number int, remark string) error {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
mManageMaterialPurchase.ID = materialPurchaseID
|
||||
|
||||
isExist, err := model2.FirstWhere(mManageMaterialPurchase.ManageMaterialPurchase)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,未找到相应的采购单")
|
||||
}
|
||||
mManageMaterialWarehouse := model.NewManageMaterialWarehouse()
|
||||
mManageMaterialWarehouse.UID = c.UID
|
||||
mManageMaterialWarehouse.MaterialPurchaseID = materialPurchaseID
|
||||
mManageMaterialWarehouse.Number = number
|
||||
mManageMaterialWarehouse.Remark = remark
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mManageMaterialWarehouse.ManageMaterialWarehouse); err != nil {
|
||||
return err
|
||||
}
|
||||
// 同步库存
|
||||
mManageMaterial := model.NewManageMaterial()
|
||||
|
||||
if err = model2.Updates(mManageMaterial.ManageMaterial, map[string]interface{}{
|
||||
"stock": gorm.Expr("stock + ?", number),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *MaterialWarehouse) Delete(id uint64) error {
|
||||
mManageMaterialWarehouse := model.NewManageMaterialWarehouse()
|
||||
mManageMaterialWarehouse.ID = id
|
||||
return model2.Delete(mManageMaterialWarehouse.ManageMaterialWarehouse)
|
||||
}
|
||||
|
||||
func NewMaterialWarehouse() MaterialWarehouseHandle {
|
||||
return func(session *service.Session) *MaterialWarehouse {
|
||||
return &MaterialWarehouse{session}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user