57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class StockLog extends Model
|
|
{
|
|
protected $table = 'stock_logs';
|
|
|
|
protected $fillable = [
|
|
'sku_code',
|
|
'warehouse_id',
|
|
'change_quantity',
|
|
'type',
|
|
'related_no',
|
|
'order_id',
|
|
'delivery_no',
|
|
'remark',
|
|
];
|
|
|
|
protected $casts = [
|
|
'change_quantity' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 关联仓库
|
|
*/
|
|
public function warehouse()
|
|
{
|
|
return $this->belongsTo(Warehouse::class);
|
|
}
|
|
|
|
/**
|
|
* 关联订单(可选)
|
|
*/
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
/**
|
|
* 获取类型标签
|
|
*/
|
|
public function getTypeLabelAttribute()
|
|
{
|
|
$map = [
|
|
'inbound' => '入库',
|
|
'outbound' => '出库',
|
|
'lock' => '占用',
|
|
'unlock' => '释放占用',
|
|
'ship' => '发货出库',
|
|
'defective_inbound' => '残次品入库',
|
|
'adjust' => '手动调整',
|
|
];
|
|
return $map[$this->type] ?? $this->type;
|
|
}
|
|
} |