| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace App\Module\Task\Models;
- use UCore\ModelCore;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use App\Module\Game\Models\GameRewardGroup;
- use App\Module\Game\Models\GameConsumeGroup;
- use App\Module\Game\Models\GameConditionGroup;
- /**
- * 任务模型
- *
- * 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 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 array $display_params 显示参数(JSON格式,存储与任务显示相关的参数)
- * @property int $sort_order 排序权重(数值越大越靠前)
- * @property bool $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",用于存储具体重置时间点
- * @property int $reward_group_id 奖励组ID,关联game_reward_groups表
- * @property int $consume_group_id 消耗组ID,关联game_consume_groups表
- * @property int $prerequisite_condition_group_id 前置条件组ID,关联game_condition_groups表
- * @property int $achievement_condition_group_id 达成条件组ID,关联game_condition_groups表
- * @property bool $auto_accept 是否自动接取任务(0:否, 1:是)
- * @property bool $auto_complete 是否自动完成任务(0:否, 1:是)
- * @property bool $auto_reward 是否自动发放奖励(0:否, 1:是)
- * @property bool $auto_reset 是否自动重置任务(0:否, 1:是)
- * 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',
- 'auto_accept' => 'boolean',
- 'auto_complete' => 'boolean',
- 'auto_reward' => 'boolean',
- 'auto_reset' => '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',
- 'reward_group_id',
- 'consume_group_id',
- 'prerequisite_condition_group_id',
- 'achievement_condition_group_id',
- 'auto_accept',
- 'auto_complete',
- 'auto_reward',
- 'auto_reset',
- ];
- // attrlist end
- /**
- * 获取任务所属分类
- *
- * @return BelongsTo
- */
- public function category(): BelongsTo
- {
- return $this->belongsTo(TaskCategory::class, 'category_id', 'id');
- }
- /**
- * 获取任务的奖励(已废弃,使用rewardGroup替代)
- *
- * @return HasMany
- * @deprecated
- */
- public function rewards(): HasMany
- {
- return $this->hasMany(TaskReward::class, 'task_id', 'id');
- }
- /**
- * 获取任务关联的奖励组
- *
- * @return BelongsTo
- */
- public function rewardGroup(): BelongsTo
- {
- return $this->belongsTo(GameRewardGroup::class, 'reward_group_id', 'id');
- }
- /**
- * 获取任务关联的消耗组
- *
- * @return BelongsTo
- */
- public function consumeGroup(): BelongsTo
- {
- return $this->belongsTo(GameConsumeGroup::class, 'consume_group_id', 'id');
- }
- /**
- * 获取任务关联的前置条件组
- *
- * @return BelongsTo
- */
- public function prerequisiteConditionGroup(): BelongsTo
- {
- return $this->belongsTo(GameConditionGroup::class, 'prerequisite_condition_group_id', 'id');
- }
- /**
- * 获取任务关联的达成条件组
- *
- * @return BelongsTo
- */
- public function achievementConditionGroup(): BelongsTo
- {
- return $this->belongsTo(GameConditionGroup::class, 'achievement_condition_group_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');
- }
- }
|