| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace App\Module\Mex\Models;
- use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
- use App\Module\GameItems\Models\Item;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 农贸市场每日价格趋势模型
- *
- * field start
- * @property int $id 趋势记录ID,主键
- * @property int $item_id 商品ID,关联物品表
- * @property \App\Module\Fund\Enums\FUND_CURRENCY_TYPE $currency_type 币种类型,关联FUND_CURRENCY_TYPE枚举,默认2为钻石
- * @property \Carbon\Carbon $trade_date 交易日期
- * @property float $open_price 开盘价(当日第一笔成交价格)
- * @property float $close_price 收盘价(当日最后一笔成交价格)
- * @property float $high_price 最高价(当日最高成交价格)
- * @property float $low_price 最低价(当日最低成交价格)
- * @property float $avg_price 平均价(当日成交均价)
- * @property float $buy_open_price 买入开盘价(当日第一笔买入成交价格)
- * @property float $buy_close_price 买入收盘价(当日最后一笔买入成交价格)
- * @property float $buy_high_price 买入最高价(当日买入最高成交价格)
- * @property float $buy_low_price 买入最低价(当日买入最低成交价格)
- * @property float $buy_avg_price 买入平均价(当日买入成交均价)
- * @property float $sell_open_price 卖出开盘价(当日第一笔卖出成交价格)
- * @property float $sell_close_price 卖出收盘价(当日最后一笔卖出成交价格)
- * @property float $sell_high_price 卖出最高价(当日卖出最高成交价格)
- * @property float $sell_low_price 卖出最低价(当日卖出最低成交价格)
- * @property float $sell_avg_price 卖出平均价(当日卖出成交均价)
- * @property int $total_volume 成交量(当日总成交数量)
- * @property float $total_amount 成交额(当日总成交金额)
- * @property int $transaction_count 成交笔数(当日总成交次数)
- * @property int $buy_volume 买入量(用户买入总数量)
- * @property int $sell_volume 卖出量(用户卖出总数量)
- * @property float $buy_amount 买入额(用户买入总金额)
- * @property float $sell_amount 卖出额(用户卖出总金额)
- * @property int $admin_inject_volume 管理员注入量
- * @property int $admin_recycle_volume 管理员回收量
- * @property float $admin_inject_amount 管理员注入金额
- * @property float $admin_recycle_amount 管理员回收金额
- * @property float $price_change 价格变化(相对前一日收盘价)
- * @property float $price_change_percent 价格变化百分比
- * @property float $volatility 波动率((最高价-最低价)/开盘价*100)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class MexDailyPriceTrend extends ModelCore
- {
- protected $table = 'mex_daily_price_trends';
- protected $fillable = [
- 'item_id',
- 'currency_type',
- 'trade_date',
- 'open_price',
- 'close_price',
- 'high_price',
- 'low_price',
- 'avg_price',
- 'buy_open_price',
- 'buy_close_price',
- 'buy_high_price',
- 'buy_low_price',
- 'buy_avg_price',
- 'sell_open_price',
- 'sell_close_price',
- 'sell_high_price',
- 'sell_low_price',
- 'sell_avg_price',
- 'total_volume',
- 'total_amount',
- 'transaction_count',
- 'buy_volume',
- 'sell_volume',
- 'buy_amount',
- 'sell_amount',
- 'admin_inject_volume',
- 'admin_recycle_volume',
- 'admin_inject_amount',
- 'admin_recycle_amount',
- 'price_change',
- 'price_change_percent',
- 'volatility',
- ];
- protected $casts = [
- 'item_id' => 'integer',
- 'currency_type' => FUND_CURRENCY_TYPE::class,
- 'trade_date' => 'date',
- 'open_price' => 'decimal:5',
- 'close_price' => 'decimal:5',
- 'high_price' => 'decimal:5',
- 'low_price' => 'decimal:5',
- 'avg_price' => 'decimal:5',
- 'buy_open_price' => 'decimal:5',
- 'buy_close_price' => 'decimal:5',
- 'buy_high_price' => 'decimal:5',
- 'buy_low_price' => 'decimal:5',
- 'buy_avg_price' => 'decimal:5',
- 'sell_open_price' => 'decimal:5',
- 'sell_close_price' => 'decimal:5',
- 'sell_high_price' => 'decimal:5',
- 'sell_low_price' => 'decimal:5',
- 'sell_avg_price' => 'decimal:5',
- 'total_volume' => 'integer',
- 'total_amount' => 'decimal:5',
- 'transaction_count' => 'integer',
- 'buy_volume' => 'integer',
- 'sell_volume' => 'integer',
- 'buy_amount' => 'decimal:5',
- 'sell_amount' => 'decimal:5',
- 'admin_inject_volume' => 'integer',
- 'admin_recycle_volume' => 'integer',
- 'admin_inject_amount' => 'decimal:5',
- 'admin_recycle_amount' => 'decimal:5',
- 'price_change' => 'decimal:5',
- 'price_change_percent' => 'decimal:4',
- 'volatility' => 'decimal:4',
- ];
- /**
- * 获取关联的商品信息
- */
- public function item(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'item_id');
- }
- /**
- * 获取价格变化趋势描述
- */
- public function getPriceTrendDescriptionAttribute(): string
- {
- if ($this->price_change_percent === null) {
- return '无变化';
- }
- $percent = abs($this->price_change_percent);
- $direction = $this->price_change_percent > 0 ? '上涨' : '下跌';
-
- return "{$direction} {$percent}%";
- }
- /**
- * 获取波动率等级
- */
- public function getVolatilityLevelAttribute(): string
- {
- if ($this->volatility === null) {
- return '无数据';
- }
- if ($this->volatility < 5) {
- return '低波动';
- } elseif ($this->volatility < 15) {
- return '中等波动';
- } elseif ($this->volatility < 30) {
- return '高波动';
- } else {
- return '极高波动';
- }
- }
- }
|