| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Module\Task\Models;
- use UCore\ModelCore;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- /**
- * 任务达成条件模型
- *
- * field start
- * @property int $id 主键
- * @property int $task_id 任务ID,外键关联task_tasks表
- * @property int $condition_id 条件ID,外键关联task_conditions表
- * @property string $condition_type 条件类型(prerequisite=前置条件,progress=进度条件)
- * @property int $target_value 目标值,如需要完成的次数
- * @property object|array $params 条件参数,如特定物品ID、特定作物ID等
- * @property string $operator 运算符,如=, >=, <=
- * @property int $sort_order 排序顺序,用于多条件任务
- * @property int $is_required 是否必须满足此条件(0:否, 1:是)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class TaskAchievementCondition extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'task_achievement_conditions';
- /**
- * 主键
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'params' => 'array',
- 'is_required' => 'boolean',
- ];
- // attrlist start
- protected $fillable = [
- 'id',
- 'task_id',
- 'condition_id',
- 'condition_type',
- 'target_value',
- 'params',
- 'operator',
- 'sort_order',
- 'is_required',
- ];
- // attrlist end
- /**
- * 获取关联的任务
- *
- * @return BelongsTo
- */
- public function task(): BelongsTo
- {
- return $this->belongsTo(Task::class, 'task_id', 'id');
- }
- /**
- * 获取关联的条件
- *
- * @return BelongsTo
- */
- public function condition(): BelongsTo
- {
- return $this->belongsTo(TaskCondition::class, 'condition_id', 'id');
- }
- /**
- * 获取用户任务进度
- *
- * @return HasMany
- */
- public function userProgress(): HasMany
- {
- return $this->hasMany(TaskUserProgress::class, 'achievement_condition_id', 'id');
- }
- }
|