| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Module\GameItems\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 用户物品关联
- *
- * field start
- * @property int $id 记录ID,主键
- * @property int $user_id 用户ID
- * @property int $item_id 统一属性物品ID,外键关联kku_item_items表
- * @property int $instance_id 单独属性物品ID,外键关联kku_item_instances表(可为空)
- * @property int $quantity 数量(对于单独属性物品,该值始终为1)
- * @property string $expire_at 用户物品过期时间(可为空)
- * @property \Carbon\Carbon $created_at 获取时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ItemUser extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'item_users';
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'item_id',
- 'instance_id',
- 'quantity',
- 'expire_at',
- ];
- // attrlist end
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'expire_at',
- 'created_at',
- 'updated_at',
- ];
- /**
- * 获取关联的物品
- *
- * @return BelongsTo
- */
- public function item(): BelongsTo
- {
- return $this->belongsTo(Item::class, 'item_id');
- }
- /**
- * 获取关联的物品实例(如果有)
- *
- * @return BelongsTo
- */
- public function instance(): BelongsTo
- {
- return $this->belongsTo(ItemInstance::class, 'instance_id');
- }
- /**
- * 检查是否为单独属性物品
- *
- * @return bool
- */
- public function isUniqueItem(): bool
- {
- return !empty($this->instance_id);
- }
- }
|