erp-backend/app/Models/OrderItem.php
2026-04-01 17:07:04 +08:00

45 lines
963 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class OrderItem extends Model
{
protected $table = 'order_items';
protected $fillable = [
'order_id',
'goods_name',
'platform_sku',
'quantity',
'price',
'total_amount',
'match_status',
'erp_sku_id',
'goods_id',
];
// 添加访问器返回绑定后的ERP商品名称和SKU
protected $appends = ['erp_goods_name', 'erp_goods_sku'];
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
public function erpSku(): BelongsTo
{
return $this->belongsTo(ErpSku::class, 'erp_sku_id');
}
public function getErpGoodsNameAttribute()
{
return $this->erpSku?->name;
}
public function getErpGoodsSkuAttribute()
{
return $this->erpSku?->sku_code;
}
}