Files
fdesk/app/common/model/VehMoneyValue.php
T

87 lines
1.8 KiB
PHP
Raw Normal View History

2025-09-16 10:53:57 +08:00
<?php
namespace app\common\model;
use support\Model;
class VehMoneyValue extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'veh_money_value';
/**
* 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';
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
protected $fillable = [
'object_scene','object_id','field','currency','amount','exchange_rate',
'remark','created_at','updated_at'
];
protected $casts = [
'amount' => 'string',
'exchange_rate' => 'string',
];
/** 按本行汇率换到结算币;无汇率返回 null */
public function amountInSettlement(int $scale = 2): ?string
{
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);
}
}