| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace App\Module\Mex\Models;
- use App\Module\GameItems\Models\Item;
- use App\Module\Mex\Enums\PriceAdjustmentType;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 农贸市场价格调整记录模型
- *
- * field start
- * @property int $id 调整记录ID,主键
- * @property int $price_config_id 价格配置ID,关联mex_price_configs表
- * @property int $item_id 商品ID,关联物品表
- * @property int $admin_user_id 操作管理员用户ID
- * @property \App\Module\Mex\Enums\PriceAdjustmentType $adjustment_type 调整类型:MIN_PRICE最低价,MAX_PRICE最高价,PROTECTION_THRESHOLD保护阈值,STATUS启用状态,BATCH批量调整
- * @property float $old_min_price 调整前最低价
- * @property float $new_min_price 调整后最低价
- * @property float $old_max_price 调整前最高价
- * @property float $new_max_price 调整后最高价
- * @property int $old_protection_threshold 调整前保护阈值
- * @property int $new_protection_threshold 调整后保护阈值
- * @property bool $old_is_enabled 调整前启用状态
- * @property bool $new_is_enabled 调整后启用状态
- * @property string $adjustment_reason 调整原因
- * @property string $market_impact_note 市场影响说明
- * @property \Carbon\Carbon $created_at 调整时间
- * field end
- */
- class MexPriceAdjustment extends ModelCore
- {
- protected $table = 'mex_price_adjustments';
- // 禁用updated_at字段的自动管理,因为表中只有created_at字段
- public const UPDATED_AT = null;
- protected $fillable = [
- 'price_config_id',
- 'item_id',
- 'admin_user_id',
- 'adjustment_type',
- 'old_min_price',
- 'new_min_price',
- 'old_max_price',
- 'new_max_price',
- 'old_protection_threshold',
- 'new_protection_threshold',
- 'old_is_enabled',
- 'new_is_enabled',
- 'adjustment_reason',
- 'market_impact_note',
- ];
- protected $casts = [
- 'price_config_id' => 'integer',
- 'item_id' => 'integer',
- 'admin_user_id' => 'integer',
- 'adjustment_type' => PriceAdjustmentType::class,
- 'old_min_price' => 'decimal:5',
- 'new_min_price' => 'decimal:5',
- 'old_max_price' => 'decimal:5',
- 'new_max_price' => 'decimal:5',
- 'old_protection_threshold' => 'integer',
- 'new_protection_threshold' => 'integer',
- 'old_is_enabled' => 'boolean',
- 'new_is_enabled' => 'boolean',
- ];
- /**
- * 获取关联的价格配置
- */
- public function priceConfig(): BelongsTo
- {
- return $this->belongsTo(MexPriceConfig::class, 'price_config_id');
- }
- /**
- * 获取关联的商品信息
- */
- public function item(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'item_id');
- }
- /**
- * 获取价格变化摘要
- */
- public function getPriceChangeSummaryAttribute(): string
- {
- $changes = [];
-
- if ($this->old_min_price !== $this->new_min_price) {
- $changes[] = "最低价: {$this->old_min_price} → {$this->new_min_price}";
- }
-
- if ($this->old_max_price !== $this->new_max_price) {
- $changes[] = "最高价: {$this->old_max_price} → {$this->new_max_price}";
- }
-
- if ($this->old_protection_threshold !== $this->new_protection_threshold) {
- $changes[] = "保护阈值: {$this->old_protection_threshold} → {$this->new_protection_threshold}";
- }
-
- if ($this->old_is_enabled !== $this->new_is_enabled) {
- $oldStatus = $this->old_is_enabled ? '启用' : '禁用';
- $newStatus = $this->new_is_enabled ? '启用' : '禁用';
- $changes[] = "状态: {$oldStatus} → {$newStatus}";
- }
-
- return implode('; ', $changes);
- }
- }
|