TaskUserProgress.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 string $last_update_time 最后更新时间
  15. * @property \Carbon\Carbon $created_at 创建时间
  16. * @property \Carbon\Carbon $updated_at 更新时间
  17. * field end
  18. */
  19. class TaskUserProgress extends ModelCore
  20. {
  21. /**
  22. * 与模型关联的表名
  23. *
  24. * @var string
  25. */
  26. protected $table = 'task_user_progress';
  27. /**
  28. * 主键
  29. *
  30. * @var string
  31. */
  32. protected $primaryKey = 'id';
  33. /**
  34. * 应该被转换为日期的属性
  35. *
  36. * @var array
  37. */
  38. protected $dates = [
  39. 'last_update_time',
  40. 'created_at',
  41. 'updated_at',
  42. ];
  43. // attrlist start
  44. protected $fillable = [
  45. 'id',
  46. 'user_id',
  47. 'task_id',
  48. 'achievement_condition_id',
  49. 'current_value',
  50. 'last_update_time',
  51. ];
  52. // attrlist end
  53. /**
  54. * 获取关联的任务
  55. *
  56. * @return BelongsTo
  57. */
  58. public function task(): BelongsTo
  59. {
  60. return $this->belongsTo(Task::class, 'task_id', 'id');
  61. }
  62. /**
  63. * 获取关联的达成条件
  64. *
  65. * @return BelongsTo
  66. */
  67. public function achievementCondition(): BelongsTo
  68. {
  69. return $this->belongsTo(TaskAchievementCondition::class, 'achievement_condition_id', 'id');
  70. }
  71. /**
  72. * 获取关联的用户任务
  73. *
  74. * @return BelongsTo
  75. */
  76. public function userTask(): BelongsTo
  77. {
  78. return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id')
  79. ->where('user_id', $this->user_id);
  80. }
  81. }