Task.php 3.5 KB

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