TaskAchievementCondition.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 $task_id 任务ID,外键关联task_tasks表
  12. * @property int $condition_id 条件ID,外键关联task_conditions表
  13. * @property string $condition_type 条件类型(prerequisite=前置条件,progress=进度条件)
  14. * @property int $target_value 目标值,如需要完成的次数
  15. * @property array $params 条件参数,如特定物品ID、特定作物ID等
  16. * @property string $operator 运算符,如=, >=, <=
  17. * @property int $sort_order 排序顺序,用于多条件任务
  18. * @property bool $is_required 是否必须满足此条件(0:否, 1:是)
  19. * @property \Carbon\Carbon $created_at 创建时间
  20. * @property \Carbon\Carbon $updated_at 更新时间
  21. * field end
  22. */
  23. class TaskAchievementCondition extends ModelCore
  24. {
  25. /**
  26. * 与模型关联的表名
  27. *
  28. * @var string
  29. */
  30. protected $table = 'task_achievement_conditions';
  31. /**
  32. * 主键
  33. *
  34. * @var string
  35. */
  36. protected $primaryKey = 'id';
  37. /**
  38. * 应该被转换为原生类型的属性
  39. *
  40. * @var array
  41. */
  42. protected $casts = [
  43. 'params' => 'array',
  44. 'is_required' => 'boolean',
  45. ];
  46. // attrlist start
  47. protected $fillable = [
  48. 'id',
  49. 'task_id',
  50. 'condition_id',
  51. 'condition_type',
  52. 'target_value',
  53. 'params',
  54. 'operator',
  55. 'sort_order',
  56. 'is_required',
  57. ];
  58. // attrlist end
  59. /**
  60. * 获取关联的任务
  61. *
  62. * @return BelongsTo
  63. */
  64. public function task(): BelongsTo
  65. {
  66. return $this->belongsTo(Task::class, 'task_id', 'id');
  67. }
  68. /**
  69. * 获取关联的条件
  70. *
  71. * @return BelongsTo
  72. */
  73. public function condition(): BelongsTo
  74. {
  75. return $this->belongsTo(TaskCondition::class, 'condition_id', 'id');
  76. }
  77. /**
  78. * 获取用户任务进度
  79. *
  80. * @return HasMany
  81. */
  82. public function userProgress(): HasMany
  83. {
  84. return $this->hasMany(TaskUserProgress::class, 'achievement_condition_id', 'id');
  85. }
  86. }