TaskCostLog.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 $cost_type 消耗类型(currency, item, energy, ticket等)
  13. * @property string $cost_param1 消耗参数1(如货币类型、物品类型等)
  14. * @property string $cost_param2 消耗参数2(如货币ID、物品ID等)
  15. * @property int $quantity 消耗数量
  16. * @property string $cost_at 消耗时间
  17. * @property string $ip_address IP地址
  18. * @property string $device_info 设备信息
  19. * @property \Carbon\Carbon $created_at 创建时间
  20. * field end
  21. */
  22. class TaskCostLog extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'task_cost_logs';
  30. /**
  31. * 主键
  32. *
  33. * @var string
  34. */
  35. protected $primaryKey = 'id';
  36. /**
  37. * 应该被转换为日期的属性
  38. *
  39. * @var array
  40. */
  41. protected $dates = [
  42. 'cost_at',
  43. 'created_at',
  44. ];
  45. /**
  46. * 指示模型是否应该被打上时间戳
  47. *
  48. * @var bool
  49. */
  50. public $timestamps = false;
  51. // attrlist start
  52. protected $fillable = [
  53. 'id',
  54. 'user_id',
  55. 'task_id',
  56. 'cost_type',
  57. 'cost_param1',
  58. 'cost_param2',
  59. 'quantity',
  60. 'cost_at',
  61. 'ip_address',
  62. 'device_info',
  63. ];
  64. // attrlist end
  65. /**
  66. * 获取关联的任务
  67. *
  68. * @return BelongsTo
  69. */
  70. public function task(): BelongsTo
  71. {
  72. return $this->belongsTo(Task::class, 'task_id', 'id');
  73. }
  74. /**
  75. * 获取关联的用户任务
  76. *
  77. * @return BelongsTo
  78. */
  79. public function userTask(): BelongsTo
  80. {
  81. return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id')
  82. ->where('user_id', $this->user_id);
  83. }
  84. }