TaskCompletionLog.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 string $completed_at 完成时间
  13. * @property int $time_spent 完成耗时(秒)
  14. * @property string $ip_address IP地址
  15. * @property string $device_info 设备信息
  16. * @property \Carbon\Carbon $created_at 创建时间
  17. * field end
  18. */
  19. class TaskCompletionLog extends ModelCore
  20. {
  21. /**
  22. * 与模型关联的表名
  23. *
  24. * @var string
  25. */
  26. protected $table = 'task_completion_logs';
  27. /**
  28. * 主键
  29. *
  30. * @var string
  31. */
  32. protected $primaryKey = 'id';
  33. /**
  34. * 应该被转换为日期的属性
  35. *
  36. * @var array
  37. */
  38. protected $dates = [
  39. 'completed_at',
  40. 'created_at',
  41. ];
  42. /**
  43. * 指示模型是否应该被打上时间戳
  44. *
  45. * @var bool
  46. */
  47. public $timestamps = false;
  48. // attrlist start
  49. protected $fillable = [
  50. 'id',
  51. 'user_id',
  52. 'task_id',
  53. 'completed_at',
  54. 'time_spent',
  55. 'ip_address',
  56. 'device_info',
  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 userTask(): BelongsTo
  74. {
  75. return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id')
  76. ->where('user_id', $this->user_id);
  77. }
  78. }