TaskUserProgress.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Module\Task\Models;
  3. use UCore\ModelCore;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. /**
  6. * 用户任务进度模型
  7. *
  8. * field start
  9. * @property int $id 主键
  10. * @property int $user_id 用户ID
  11. * @property int $task_id 任务ID,外键关联task_tasks表
  12. * @property int $achievement_condition_id 达成条件ID,外键关联task_achievement_conditions表
  13. * @property int $current_value 当前值
  14. * @property int $target_value 目标值
  15. * @property string $last_update_time 最后更新时间
  16. * @property \Carbon\Carbon $created_at 创建时间
  17. * @property \Carbon\Carbon $updated_at 更新时间
  18. * field end
  19. */
  20. class TaskUserProgress extends ModelCore
  21. {
  22. /**
  23. * 与模型关联的表名
  24. *
  25. * @var string
  26. */
  27. protected $table = 'task_user_progress';
  28. /**
  29. * 主键
  30. *
  31. * @var string
  32. */
  33. protected $primaryKey = 'id';
  34. /**
  35. * 应该被转换为日期的属性
  36. *
  37. * @var array
  38. */
  39. protected $dates = [
  40. 'last_update_time',
  41. 'created_at',
  42. 'updated_at',
  43. ];
  44. // attrlist start
  45. protected $fillable = [
  46. 'id',
  47. 'user_id',
  48. 'task_id',
  49. 'achievement_condition_id',
  50. 'current_value',
  51. 'target_value',
  52. 'last_update_time',
  53. ];
  54. // attrlist end
  55. /**
  56. * 获取关联的任务
  57. *
  58. * @return BelongsTo
  59. */
  60. public function task(): BelongsTo
  61. {
  62. return $this->belongsTo(Task::class, 'task_id', 'id');
  63. }
  64. /**
  65. * 获取关联的达成条件
  66. *
  67. * @return BelongsTo
  68. */
  69. public function achievementCondition(): BelongsTo
  70. {
  71. return $this->belongsTo(TaskAchievementCondition::class, 'achievement_condition_id', 'id');
  72. }
  73. /**
  74. * 获取关联的用户任务
  75. *
  76. * @return BelongsTo
  77. */
  78. public function userTask(): BelongsTo
  79. {
  80. // 简化关联,在控制器中手动处理条件
  81. return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id');
  82. }
  83. }