| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?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 $category_id 任务分类ID,外键关联task_categories表
- * @property string $name 任务名称
- * @property string $description 任务描述
- * @property string $type 任务类型(daily, weekly, achievement, event, tutorial, team)
- * @property object|array $prerequisite_tasks 前置任务ID(JSON格式)
- * @property int $level_required 所需等级
- * @property int $time_limit 时间限制(秒,NULL表示无限制)
- * @property int $max_completions 最大完成次数(用于限制任务可完成的次数)
- * @property string $reset_type 重置类型(none, daily, weekly, monthly)
- * @property object|array $display_params 显示参数(JSON格式,存储与任务显示相关的参数)
- * @property int $sort_order 排序权重(数值越大越靠前)
- * @property int $is_active 是否激活(0:否, 1:是)
- * @property string $start_time 开始时间(NULL表示立即开始)
- * @property string $end_time 结束时间(NULL表示永不结束)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * @property int $reset_interval 重置间隔(秒),根据重置类型自动计算
- * @property string $reset_time_field 重置时间字段,如"daily_reset_time",用于存储具体重置时间点
- * field end
- */
- class Task extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'task_tasks';
- /**
- * 主键
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'prerequisite_tasks' => 'array',
- 'display_params' => 'array',
- 'is_active' => 'boolean',
- ];
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'start_time',
- 'end_time',
- 'created_at',
- 'updated_at',
- ];
- // attrlist start
- protected $fillable = [
- 'id',
- 'category_id',
- 'name',
- 'description',
- 'type',
- 'prerequisite_tasks',
- 'level_required',
- 'time_limit',
- 'max_completions',
- 'reset_type',
- 'display_params',
- 'sort_order',
- 'is_active',
- 'start_time',
- 'end_time',
- 'reset_interval',
- 'reset_time_field',
- ];
- // attrlist end
- /**
- * 获取任务所属分类
- *
- * @return BelongsTo
- */
- public function category(): BelongsTo
- {
- return $this->belongsTo(TaskCategory::class, 'category_id', 'id');
- }
- /**
- * 获取任务的奖励
- *
- * @return HasMany
- */
- public function rewards(): HasMany
- {
- return $this->hasMany(TaskReward::class, 'task_id', 'id');
- }
- /**
- * 获取任务的消耗
- *
- * @return HasMany
- */
- public function costs(): HasMany
- {
- return $this->hasMany(TaskCost::class, 'task_id', 'id');
- }
- /**
- * 获取任务的达成条件
- *
- * @return HasMany
- */
- public function achievementConditions(): HasMany
- {
- return $this->hasMany(TaskAchievementCondition::class, 'task_id', 'id');
- }
- /**
- * 获取用户任务关联
- *
- * @return HasMany
- */
- public function userTasks(): HasMany
- {
- return $this->hasMany(TaskUserTask::class, 'task_id', 'id');
- }
- }
|