2025-09-02 17:22:56 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\common\model;
|
|
|
|
|
|
|
|
|
|
|
|
use support\Model;
|
2025-09-04 10:26:28 +08:00
|
|
|
|
use app\common\traits\HasMoneyJournal;
|
2025-09-02 17:22:56 +08:00
|
|
|
|
|
|
|
|
|
|
class StockOrderItems extends Model
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The connection name for the model.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @var string|null
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $connection = 'mysql';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The table associated with the model.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @var string
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $table = 'stock_order_items';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The primary key associated with the table.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @var string
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Indicates if the model should be timestamped.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @var bool
|
|
|
|
|
|
*/
|
|
|
|
|
|
public $timestamps = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected $dateFormat = 'U';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 允许自动填充模型字段
|
|
|
|
|
|
*/
|
2025-09-04 10:26:28 +08:00
|
|
|
|
protected $fillable = [
|
|
|
|
|
|
'id', 'order_id', 'product_code', 'sku_id', 'sku_snapshot',
|
2025-09-04 18:22:24 +08:00
|
|
|
|
'model_snapshot', 'quantity', 'color_interior_code', 'color_interior_snapshot',
|
2025-09-08 20:00:12 +08:00
|
|
|
|
'color_exterior_code', 'color_exterior_snapshot', 'remark', 'vin', 'created_at', 'updated_at',
|
2026-08-06 15:01:03 +08:00
|
|
|
|
'mileage', 'unique_id', 'attachment'
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 字段类型转换:attachment 以 JSON 数组存取(写自动 json_encode、读自动 decode)
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
|
'attachment' => 'array',
|
2025-09-04 10:26:28 +08:00
|
|
|
|
];
|
2025-09-02 17:22:56 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 不允许自动填充模型字段
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected $guarded = [];
|
|
|
|
|
|
|
2025-09-04 10:26:28 +08:00
|
|
|
|
/* ========= 关系 ========= */
|
2025-09-02 17:22:56 +08:00
|
|
|
|
|
2025-09-04 10:26:28 +08:00
|
|
|
|
use HasMoneyJournal;
|
|
|
|
|
|
// 实现抽象方法
|
|
|
|
|
|
protected static function moneyObjectScene(): string
|
2025-09-02 17:22:56 +08:00
|
|
|
|
{
|
2025-09-04 10:26:28 +08:00
|
|
|
|
return 'stock_order_items';
|
2025-09-02 17:22:56 +08:00
|
|
|
|
}
|
2025-09-04 10:26:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 便捷访问器(最新一条的原币金额)
|
|
|
|
|
|
public function getUnitPriceAmountAttribute() { return $this->moneyLatest('unit_price')?->amount; }
|
|
|
|
|
|
public function getHandlingFeeAmountAttribute() { return $this->moneyLatest('handling_fee')?->amount; }
|
|
|
|
|
|
public function getFobTransportFeeAmountAttribute() { return $this->moneyLatest('fob_transport_fee')?->amount; }
|
|
|
|
|
|
public function getPortMiscFeeAmountAttribute() { return $this->moneyLatest('port_misc_fee')?->amount; }
|
|
|
|
|
|
public function getRetrofitFeeAmountAttribute() { return $this->moneyLatest('retrofit_fee')?->amount; }
|
|
|
|
|
|
public function getTotalPriceAmountAttribute() { return $this->moneyLatest('total_price')?->amount; }
|
2025-09-04 11:52:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关联主订单
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function order()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->belongsTo(StockOrders::class, 'order_id', 'id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关联订单项选项
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function options()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasMany(StockOrderItemOptions::class, 'order_item_id', 'id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 关联货币价值信息(一个订单项可以有多个货币价值记录)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function moneyValues()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')
|
|
|
|
|
|
->where('object_scene', 'stock_order_items'); // 场景标识区分不同对象类型
|
|
|
|
|
|
}
|
2025-09-02 17:22:56 +08:00
|
|
|
|
}
|