MexDailyPriceTrend.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace App\Module\Mex\Models;
  3. use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
  4. use App\Module\GameItems\Models\Item;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use UCore\ModelCore;
  7. /**
  8. * 农贸市场每日价格趋势模型
  9. *
  10. * field start
  11. * @property int $id 趋势记录ID,主键
  12. * @property int $item_id 商品ID,关联物品表
  13. * @property \App\Module\Fund\Enums\FUND_CURRENCY_TYPE $currency_type 币种类型,关联FUND_CURRENCY_TYPE枚举,默认2为钻石
  14. * @property \Carbon\Carbon $trade_date 交易日期
  15. * @property float $open_price 开盘价(当日第一笔成交价格)
  16. * @property float $close_price 收盘价(当日最后一笔成交价格)
  17. * @property float $high_price 最高价(当日最高成交价格)
  18. * @property float $low_price 最低价(当日最低成交价格)
  19. * @property float $avg_price 平均价(当日成交均价)
  20. * @property float $buy_open_price 买入开盘价(当日第一笔买入成交价格)
  21. * @property float $buy_close_price 买入收盘价(当日最后一笔买入成交价格)
  22. * @property float $buy_high_price 买入最高价(当日买入最高成交价格)
  23. * @property float $buy_low_price 买入最低价(当日买入最低成交价格)
  24. * @property float $buy_avg_price 买入平均价(当日买入成交均价)
  25. * @property float $sell_open_price 卖出开盘价(当日第一笔卖出成交价格)
  26. * @property float $sell_close_price 卖出收盘价(当日最后一笔卖出成交价格)
  27. * @property float $sell_high_price 卖出最高价(当日卖出最高成交价格)
  28. * @property float $sell_low_price 卖出最低价(当日卖出最低成交价格)
  29. * @property float $sell_avg_price 卖出平均价(当日卖出成交均价)
  30. * @property int $total_volume 成交量(当日总成交数量)
  31. * @property float $total_amount 成交额(当日总成交金额)
  32. * @property int $transaction_count 成交笔数(当日总成交次数)
  33. * @property int $buy_volume 买入量(用户买入总数量)
  34. * @property int $sell_volume 卖出量(用户卖出总数量)
  35. * @property float $buy_amount 买入额(用户买入总金额)
  36. * @property float $sell_amount 卖出额(用户卖出总金额)
  37. * @property int $admin_inject_volume 管理员注入量
  38. * @property int $admin_recycle_volume 管理员回收量
  39. * @property float $admin_inject_amount 管理员注入金额
  40. * @property float $admin_recycle_amount 管理员回收金额
  41. * @property float $price_change 价格变化(相对前一日收盘价)
  42. * @property float $price_change_percent 价格变化百分比
  43. * @property float $volatility 波动率((最高价-最低价)/开盘价*100)
  44. * @property \Carbon\Carbon $created_at 创建时间
  45. * @property \Carbon\Carbon $updated_at 更新时间
  46. * field end
  47. */
  48. class MexDailyPriceTrend extends ModelCore
  49. {
  50. protected $table = 'mex_daily_price_trends';
  51. protected $fillable = [
  52. 'item_id',
  53. 'currency_type',
  54. 'trade_date',
  55. 'open_price',
  56. 'close_price',
  57. 'high_price',
  58. 'low_price',
  59. 'avg_price',
  60. 'buy_open_price',
  61. 'buy_close_price',
  62. 'buy_high_price',
  63. 'buy_low_price',
  64. 'buy_avg_price',
  65. 'sell_open_price',
  66. 'sell_close_price',
  67. 'sell_high_price',
  68. 'sell_low_price',
  69. 'sell_avg_price',
  70. 'total_volume',
  71. 'total_amount',
  72. 'transaction_count',
  73. 'buy_volume',
  74. 'sell_volume',
  75. 'buy_amount',
  76. 'sell_amount',
  77. 'admin_inject_volume',
  78. 'admin_recycle_volume',
  79. 'admin_inject_amount',
  80. 'admin_recycle_amount',
  81. 'price_change',
  82. 'price_change_percent',
  83. 'volatility',
  84. ];
  85. protected $casts = [
  86. 'item_id' => 'integer',
  87. 'currency_type' => FUND_CURRENCY_TYPE::class,
  88. 'trade_date' => 'date',
  89. 'open_price' => 'decimal:5',
  90. 'close_price' => 'decimal:5',
  91. 'high_price' => 'decimal:5',
  92. 'low_price' => 'decimal:5',
  93. 'avg_price' => 'decimal:5',
  94. 'buy_open_price' => 'decimal:5',
  95. 'buy_close_price' => 'decimal:5',
  96. 'buy_high_price' => 'decimal:5',
  97. 'buy_low_price' => 'decimal:5',
  98. 'buy_avg_price' => 'decimal:5',
  99. 'sell_open_price' => 'decimal:5',
  100. 'sell_close_price' => 'decimal:5',
  101. 'sell_high_price' => 'decimal:5',
  102. 'sell_low_price' => 'decimal:5',
  103. 'sell_avg_price' => 'decimal:5',
  104. 'total_volume' => 'integer',
  105. 'total_amount' => 'decimal:5',
  106. 'transaction_count' => 'integer',
  107. 'buy_volume' => 'integer',
  108. 'sell_volume' => 'integer',
  109. 'buy_amount' => 'decimal:5',
  110. 'sell_amount' => 'decimal:5',
  111. 'admin_inject_volume' => 'integer',
  112. 'admin_recycle_volume' => 'integer',
  113. 'admin_inject_amount' => 'decimal:5',
  114. 'admin_recycle_amount' => 'decimal:5',
  115. 'price_change' => 'decimal:5',
  116. 'price_change_percent' => 'decimal:4',
  117. 'volatility' => 'decimal:4',
  118. ];
  119. /**
  120. * 获取关联的商品信息
  121. */
  122. public function item(): BelongsTo
  123. {
  124. return $this->belongsTo(Item::class, 'item_id');
  125. }
  126. /**
  127. * 获取价格变化趋势描述
  128. */
  129. public function getPriceTrendDescriptionAttribute(): string
  130. {
  131. if ($this->price_change_percent === null) {
  132. return '无变化';
  133. }
  134. $percent = abs($this->price_change_percent);
  135. $direction = $this->price_change_percent > 0 ? '上涨' : '下跌';
  136. return "{$direction} {$percent}%";
  137. }
  138. /**
  139. * 获取波动率等级
  140. */
  141. public function getVolatilityLevelAttribute(): string
  142. {
  143. if ($this->volatility === null) {
  144. return '无数据';
  145. }
  146. if ($this->volatility < 5) {
  147. return '低波动';
  148. } elseif ($this->volatility < 15) {
  149. return '中等波动';
  150. } elseif ($this->volatility < 30) {
  151. return '高波动';
  152. } else {
  153. return '极高波动';
  154. }
  155. }
  156. }