| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Module\Task\Models;
- use UCore\ModelCore;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 用户任务进度模型
- *
- * field start
- * @property int $id 主键
- * @property int $user_id 用户ID
- * @property int $task_id 任务ID,外键关联task_tasks表
- * @property int $achievement_condition_id 达成条件ID,外键关联task_achievement_conditions表
- * @property int $current_value 当前值
- * @property int $target_value 目标值
- * @property string $last_update_time 最后更新时间
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class TaskUserProgress extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'task_user_progress';
- /**
- * 主键
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'last_update_time',
- 'created_at',
- 'updated_at',
- ];
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'task_id',
- 'achievement_condition_id',
- 'current_value',
- 'target_value',
- 'last_update_time',
- ];
- // attrlist end
- /**
- * 获取关联的任务
- *
- * @return BelongsTo
- */
- public function task(): BelongsTo
- {
- return $this->belongsTo(Task::class, 'task_id', 'id');
- }
- /**
- * 获取关联的达成条件
- *
- * @return BelongsTo
- */
- public function achievementCondition(): BelongsTo
- {
- return $this->belongsTo(TaskAchievementCondition::class, 'achievement_condition_id', 'id');
- }
- /**
- * 获取关联的用户任务
- *
- * @return BelongsTo
- */
- public function userTask(): BelongsTo
- {
- // 简化关联,在控制器中手动处理条件
- return $this->belongsTo(TaskUserTask::class, 'task_id', 'task_id');
- }
- }
|