ItemChestOpenLog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use UCore\ModelCore;
  5. /**
  6. * 宝箱开启记录
  7. *
  8. * field start
  9. * @property int $id 记录ID,主键
  10. * @property int $user_id 用户ID
  11. * @property int $chest_id 宝箱ID,外键关联kku_item_items表
  12. * @property string $open_time 开启时间
  13. * @property int $open_quantity 开启数量
  14. * @property object|array $result_items 获得的物品列表,包含物品ID、数量等信息
  15. * @property int $pity_triggered 是否触发保底机制(0:否, 1:是)
  16. * @property int $pity_content_id 触发保底的内容ID,外键关联kku_item_chest_contents表(可为空)
  17. * @property string $ip_address 操作的IP地址(用于安全审计)
  18. * @property string $device_info 设备信息(用于安全审计)
  19. * @property \Carbon\Carbon $created_at 创建时间
  20. * field end
  21. */
  22. class ItemChestOpenLog extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'item_chest_open_logs';
  30. // attrlist start
  31. protected $fillable = [
  32. 'id',
  33. 'user_id',
  34. 'chest_id',
  35. 'open_time',
  36. 'open_quantity',
  37. 'result_items',
  38. 'pity_triggered',
  39. 'pity_content_id',
  40. 'ip_address',
  41. 'device_info',
  42. ];
  43. // attrlist end
  44. /**
  45. * 应该被转换为日期的属性
  46. *
  47. * @var array
  48. */
  49. protected $dates = [
  50. 'open_time',
  51. 'created_at',
  52. ];
  53. /**
  54. * 应该被转换为原生类型的属性
  55. *
  56. * @var array
  57. */
  58. protected $casts = [
  59. 'results' => \App\Module\GameItems\Casts\ChestOpenResultsCast::class,
  60. 'quantity' => 'integer',
  61. 'pity_triggered' => 'boolean',
  62. ];
  63. /**
  64. * 获取关联的宝箱
  65. *
  66. * @return BelongsTo
  67. */
  68. public function chest(): BelongsTo
  69. {
  70. return $this->belongsTo(Item::class, 'chest_id');
  71. }
  72. /**
  73. * 获取触发保底的宝箱内容(如果有)
  74. *
  75. * @return BelongsTo
  76. */
  77. public function pityContent(): BelongsTo
  78. {
  79. return $this->belongsTo(ItemChestContent::class, 'pity_content_id');
  80. }
  81. }