| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?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 $user_id 用户ID
- * @property int $task_id 任务ID,外键关联task_tasks表
- * @property int $status 状态(0:未接取, 1:进行中, 2:已完成, 3:已领取奖励, 4:已失败, 5:已过期)
- * @property int $progress 当前进度
- * @property string $completed_at 完成时间
- * @property string $rewarded_at 奖励发放时间
- * @property string $expire_at 过期时间
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class TaskUserTask extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'task_user_tasks';
- /**
- * 主键
- *
- * @var string
- */
- protected $primaryKey = 'id';
- /**
- * 应该被转换为日期的属性
- *
- * @var array
- */
- protected $dates = [
- 'completed_at',
- 'rewarded_at',
- 'expire_at',
- 'created_at',
- 'updated_at',
- ];
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'task_id',
- 'status',
- 'progress',
- 'completed_at',
- 'rewarded_at',
- 'expire_at',
- ];
- // attrlist end
- /**
- * 获取关联的任务
- *
- * @return BelongsTo
- */
- public function task(): BelongsTo
- {
- return $this->belongsTo(Task::class, 'task_id', 'id');
- }
- /**
- * 获取用户任务进度
- *
- * @return HasMany
- */
- public function progress(): HasMany
- {
- return $this->hasMany(TaskUserProgress::class, 'task_id', 'task_id')
- ->where('user_id', $this->user_id);
- }
- /**
- * 获取任务完成日志
- *
- * @return HasMany
- */
- public function completionLogs(): HasMany
- {
- return $this->hasMany(TaskCompletionLog::class, 'user_id', 'user_id')
- ->where('task_id', $this->task_id);
- }
- /**
- * 获取任务奖励日志
- *
- * @return HasMany
- */
- public function rewardLogs(): HasMany
- {
- return $this->hasMany(TaskRewardLog::class, 'user_task_id', 'id');
- }
- /**
- * 获取任务消耗日志
- *
- * @return HasMany
- */
- public function costLogs(): HasMany
- {
- return $this->hasMany(TaskCostLog::class, 'user_id', 'user_id')
- ->where('task_id', $this->task_id);
- }
- }
|