| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Module\GameItems\Models;
- use App\Module\GameItems\Enums\CHEST_COST_TYPE;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 宝箱开启消耗配置
- *
- * field start
- * @property int $id 记录ID,主键
- * @property int $chest_id 宝箱ID,外键关联item_items表
- * @property int $cost_type 消耗类型(1:物品, 2:货币, 3:其他资源)
- * @property int $cost_id 消耗的物品/货币/资源ID
- * @property int $cost_quantity 消耗数量
- * @property bool $is_active 是否激活(0:否, 1:是)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ItemChestOpenCost extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'item_chest_open_costs';
- // attrlist start
- protected $fillable = [
- 'id',
- 'chest_id',
- 'cost_type',
- 'cost_id',
- 'cost_quantity',
- 'is_active',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'cost_type' => 'integer',
- 'cost_id' => 'integer',
- 'cost_quantity' => 'integer',
- 'is_active' => 'boolean',
- ];
- /**
- * 获取关联的宝箱物品
- *
- * @return BelongsTo
- */
- public function chest(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'chest_id', 'id');
- }
- /**
- * 获取关联的消耗物品(如果消耗类型为物品)
- *
- * @return BelongsTo|null
- */
- public function costItem(): ?BelongsTo
- {
- return $this->belongsTo(Item::class, 'cost_id');
- }
- /**
- * 获取消耗类型的文本描述
- *
- * @return string
- */
- public function getCostTypeTextAttribute(): string
- {
- return CHEST_COST_TYPE::getAll()[$this->cost_type] ?? '未知';
- }
- }
|