'integer', 'locked_quantity' => 'integer', 'defective_quantity' => 'integer', 'warning_threshold' => 'integer', ]; /** * 可用库存(总库存 - 占用库存) */ public function getAvailableQuantityAttribute() { return $this->quantity - $this->locked_quantity; } /** * 关联仓库 */ public function warehouse() { return $this->belongsTo(Warehouse::class); } /** * 关联ERP商品 */ public function sku() { return $this->belongsTo(ErpSku::class, 'sku_code', 'sku_code'); } /** * 获取该SKU在该仓库的库存流水 */ public function logs() { return $this->hasMany(StockLog::class, 'sku_code', 'sku_code') ->where('warehouse_id', $this->warehouse_id); } }