TaskRewardLog.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 $user_task_id 用户任务ID,外键关联task_user_tasks表
  13. * @property object|array $rewards 奖励内容(JSON格式)
  14. * @property string $rewarded_at 奖励发放时间
  15. * @property string $ip_address IP地址
  16. * @property string $device_info 设备信息
  17. * @property \Carbon\Carbon $created_at 创建时间
  18. * field end
  19. */
  20. class TaskRewardLog extends ModelCore
  21. {
  22. /**
  23. * 与模型关联的表名
  24. *
  25. * @var string
  26. */
  27. protected $table = 'task_reward_logs';
  28. /**
  29. * 主键
  30. *
  31. * @var string
  32. */
  33. protected $primaryKey = 'id';
  34. /**
  35. * 应该被转换为原生类型的属性
  36. *
  37. * @var array
  38. */
  39. protected $casts = [
  40. 'rewards' => 'array',
  41. ];
  42. /**
  43. * 应该被转换为日期的属性
  44. *
  45. * @var array
  46. */
  47. protected $dates = [
  48. 'rewarded_at',
  49. 'created_at',
  50. ];
  51. /**
  52. * 指示模型是否应该被打上时间戳
  53. *
  54. * @var bool
  55. */
  56. public $timestamps = false;
  57. // attrlist start
  58. protected $fillable = [
  59. 'id',
  60. 'user_id',
  61. 'task_id',
  62. 'user_task_id',
  63. 'rewards',
  64. 'rewarded_at',
  65. 'ip_address',
  66. 'device_info',
  67. ];
  68. // attrlist end
  69. /**
  70. * 获取关联的任务
  71. *
  72. * @return BelongsTo
  73. */
  74. public function task(): BelongsTo
  75. {
  76. return $this->belongsTo(Task::class, 'task_id', 'id');
  77. }
  78. /**
  79. * 获取关联的用户任务
  80. *
  81. * @return BelongsTo
  82. */
  83. public function userTask(): BelongsTo
  84. {
  85. return $this->belongsTo(TaskUserTask::class, 'user_task_id', 'id');
  86. }
  87. }