增加关联关系
This commit is contained in:
@@ -46,4 +46,13 @@ class StockOrderAccounts extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* 关联主订单
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(StockOrders::class, 'order_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -46,4 +46,13 @@ class StockOrderItemOptions extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* 关联订单项
|
||||
*/
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo(StockOrderItems::class, 'order_item_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -81,4 +81,31 @@ class StockOrderItems extends Model
|
||||
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; }
|
||||
|
||||
|
||||
/**
|
||||
* 关联主订单
|
||||
*/
|
||||
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'); // 场景标识区分不同对象类型
|
||||
}
|
||||
}
|
||||
@@ -56,4 +56,29 @@ class StockOrders extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* 关联订单项
|
||||
*/
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(StockOrderItems::class, 'order_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联订单账户信息
|
||||
*/
|
||||
public function accounts()
|
||||
{
|
||||
return $this->hasMany(StockOrderAccounts::class, 'order_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联货币价值信息(一个订单可以有多个货币价值记录)
|
||||
*/
|
||||
public function moneyValues()
|
||||
{
|
||||
return $this->hasMany(VehMoneyValue::class, 'object_id', 'id')->where('object_scene', 'stock_orders');
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,29 @@ class VehMoneyValue extends Model
|
||||
if ($this->exchange_rate === null) return null;
|
||||
return (string) bcmul((string)$this->amount, (string)$this->exchange_rate, $scale);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联订单
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(StockOrders::class, 'object_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联订单项(一个货币价值记录可能关联到订单项)
|
||||
*/
|
||||
public function orderItem()
|
||||
{
|
||||
return $this->belongsTo(StockOrderItems::class, 'object_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 限定查询特定对象类型的货币价值记录
|
||||
*/
|
||||
public function scopeOfScene($query, $scene)
|
||||
{
|
||||
return $query->where('object_scene', $scene);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user