| | |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | | |
| | |
| | | // OperationDetails 操作明细表 |
| | | OperationDetails struct { |
| | | WmsModel |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | OperationID int `json:"operationId" gorm:"index;type:int;not null;comment:操作记录id"` //操作id |
| | | ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | OperationID int `json:"operationId" gorm:"index;type:int;not null;comment:操作记录id"` //操作id |
| | | BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"` //基础作业类型 |
| | | ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id |
| | | //ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称 |
| | | Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"` //数量 |
| | | //Unit string `json:"unit" gorm:"type:varchar(31);comment:单位"` //单位 |
| | |
| | | TotalNetWeight decimal.Decimal `json:"totalNetWeight" gorm:"type:decimal(20,3);comment:总净重"` |
| | | AuxiliaryAmount decimal.Decimal `json:"auxiliaryAmount" gorm:"type:decimal(20,3);comment:辅助数量"` |
| | | AuxiliaryUnit string `json:"auxiliaryUnit" gorm:"type:varchar(191);comment:辅助单位"` |
| | | Note string `gorm:"type:varchar(1024);comment:备注" json:"note"` |
| | | Remark string `gorm:"type:varchar(1024);comment:备注" json:"remark"` |
| | | IsInternalOutput bool `json:"isInternalOutput"` //是否调拨产生的出库 |
| | | DealerType string `json:"dealerType"` //出入库类型 |
| | | |
| | | Cost decimal.Decimal `json:"cost" ` //成本单价 |
| | | SalePrice decimal.Decimal `json:"salePrice" ` //销售单价 |
| | | } |
| | | |
| | | OperationDetailsSearch struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationDetailsSearch { |
| | | slf.BaseOperationType = baseOperationType |
| | | return slf |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&OperationDetails{}) |
| | | |
| | |
| | | |
| | | if slf.Fields != "" { |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if slf.BaseOperationType != 0 { |
| | | db = db.Where("base_operation_type = ?", slf.BaseOperationType) |
| | | } |
| | | |
| | | return db |
| | |
| | | } |
| | | return result, nil |
| | | } |
| | | |
| | | type GroupByDealerTypeWarehouse struct { |
| | | DealerType string |
| | | ProductID string |
| | | Sum decimal.Decimal |
| | | } |
| | | |
| | | func (slf *OperationDetailsSearch) GroupMultiSumAmount() ([]*GroupByDealerTypeWarehouse, error) { |
| | | var ( |
| | | db = slf.build() |
| | | result = make([]*GroupByDealerTypeWarehouse, 0) |
| | | ) |
| | | if err := db.Select("sum(amount) as sum, dealer_type, product_id").Group("product_id, dealer_type").Scan(&result).Error; err != nil { |
| | | return nil, fmt.Errorf("select group err: %v", err) |
| | | } |
| | | return result, nil |
| | | } |