Task.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace App\Module\Task\Models;
  3. use UCore\ModelCore;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use App\Module\Game\Models\GameRewardGroup;
  7. /**
  8. * 任务模型
  9. *
  10. * field start
  11. * @property int $id 主键
  12. * @property int $category_id 任务分类ID,外键关联task_categories表
  13. * @property string $name 任务名称
  14. * @property string $description 任务描述
  15. * @property string $type 任务类型(daily, weekly, achievement, event, tutorial, team)
  16. * @property array $prerequisite_tasks 前置任务ID(JSON格式)
  17. * @property int $level_required 所需等级
  18. * @property int $time_limit 时间限制(秒,NULL表示无限制)
  19. * @property int $max_completions 最大完成次数(用于限制任务可完成的次数)
  20. * @property string $reset_type 重置类型(none, daily, weekly, monthly)
  21. * @property array $display_params 显示参数(JSON格式,存储与任务显示相关的参数)
  22. * @property int $sort_order 排序权重(数值越大越靠前)
  23. * @property bool $is_active 是否激活(0:否, 1:是)
  24. * @property string $start_time 开始时间(NULL表示立即开始)
  25. * @property string $end_time 结束时间(NULL表示永不结束)
  26. * @property \Carbon\Carbon $created_at 创建时间
  27. * @property \Carbon\Carbon $updated_at 更新时间
  28. * @property int $reset_interval 重置间隔(秒),根据重置类型自动计算
  29. * @property string $reset_time_field 重置时间字段,如"daily_reset_time",用于存储具体重置时间点
  30. * @property int $reward_group_id 奖励组ID,关联game_reward_groups表
  31. * field end
  32. */
  33. class Task extends ModelCore
  34. {
  35. /**
  36. * 与模型关联的表名
  37. *
  38. * @var string
  39. */
  40. protected $table = 'task_tasks';
  41. /**
  42. * 主键
  43. *
  44. * @var string
  45. */
  46. protected $primaryKey = 'id';
  47. /**
  48. * 应该被转换为原生类型的属性
  49. *
  50. * @var array
  51. */
  52. protected $casts = [
  53. 'prerequisite_tasks' => 'array',
  54. 'display_params' => 'array',
  55. 'is_active' => 'boolean',
  56. ];
  57. /**
  58. * 应该被转换为日期的属性
  59. *
  60. * @var array
  61. */
  62. protected $dates = [
  63. 'start_time',
  64. 'end_time',
  65. 'created_at',
  66. 'updated_at',
  67. ];
  68. // attrlist start
  69. protected $fillable = [
  70. 'id',
  71. 'category_id',
  72. 'name',
  73. 'description',
  74. 'type',
  75. 'prerequisite_tasks',
  76. 'level_required',
  77. 'time_limit',
  78. 'max_completions',
  79. 'reset_type',
  80. 'display_params',
  81. 'sort_order',
  82. 'is_active',
  83. 'start_time',
  84. 'end_time',
  85. 'reset_interval',
  86. 'reset_time_field',
  87. 'reward_group_id',
  88. ];
  89. // attrlist end
  90. /**
  91. * 获取任务所属分类
  92. *
  93. * @return BelongsTo
  94. */
  95. public function category(): BelongsTo
  96. {
  97. return $this->belongsTo(TaskCategory::class, 'category_id', 'id');
  98. }
  99. /**
  100. * 获取任务的奖励(已废弃,使用rewardGroup替代)
  101. *
  102. * @return HasMany
  103. * @deprecated
  104. */
  105. public function rewards(): HasMany
  106. {
  107. return $this->hasMany(TaskReward::class, 'task_id', 'id');
  108. }
  109. /**
  110. * 获取任务关联的奖励组
  111. *
  112. * @return BelongsTo
  113. */
  114. public function rewardGroup(): BelongsTo
  115. {
  116. return $this->belongsTo(GameRewardGroup::class, 'reward_group_id', 'id');
  117. }
  118. /**
  119. * 获取任务的消耗
  120. *
  121. * @return HasMany
  122. */
  123. public function costs(): HasMany
  124. {
  125. return $this->hasMany(TaskCost::class, 'task_id', 'id');
  126. }
  127. /**
  128. * 获取任务的达成条件
  129. *
  130. * @return HasMany
  131. */
  132. public function achievementConditions(): HasMany
  133. {
  134. return $this->hasMany(TaskAchievementCondition::class, 'task_id', 'id');
  135. }
  136. /**
  137. * 获取用户任务关联
  138. *
  139. * @return HasMany
  140. */
  141. public function userTasks(): HasMany
  142. {
  143. return $this->hasMany(TaskUserTask::class, 'task_id', 'id');
  144. }
  145. }