上一期活动, * 'ing' => 正在进行中的活动(匹配结束到分销结束期间-1未不存在), * 'next' => 下一期活动(正在报名中的活动) * ] */ public static function getActivitys() { /** @var ActivityModel $ing */ $ing = self::where([['signend_time', '<', time()], ['close_time', '>', time()]])->first(); if (collect($ing)->isEmpty()) { /** @var ActivityModel $next */ $next = self::orderBy('stage_id', 'desc')->first(); if (collect($next)->isEmpty()) { return array( 'last' => 0, 'ing' => 0, 'next' => 0 ); } return [ 'last' => $next->stage_id - 1, 'ing' => -1, 'next' => $next->stage_id ]; } return [ 'last' => $ing->stage_id - 1, 'ing' => $ing->stage_id, 'next' => $ing->stage_id + 1 ]; } /** * 当前活动中的一期 * @param $query * @return mixed */ public function scopeCurrently($query) { /** @var Builder $query */ return $query->where('close_time', '>', time())->orderBy($this->primaryKey, 'asc'); } /** * 匹配中的一期 * @param $query * @return mixed */ public function scopeMatching($query) { $time = time(); return $query->where('signend_time', '<=', $time) ->where('open_time', '>', $time); } /** * 当前报名中的一期 */ public function scopeEnrolling($query) { $time = time(); return $query->where('signbegin_time', '<=', $time) ->where('signend_time', '>', $time); } /** * 活动ID * @return int */ public function getIdAttribute() { return $this->stage_id; } /** * 获取当前活动的进度 * @return int */ public function getProgress() { if (time() >= $this->signbegin_time && time() < $this->signend_time) { return self::ENROLLING; } elseif (time() >= $this->signend_time && time() < $this->open_time) { return self::MATCHING; } elseif (time() >= $this->open_time && time() < $this->rematch_begin_at) { return self::CONFIRMING; } elseif (time() >= $this->rematch_begin_at && time() < $this->rematched_at) { return self::REMATCHING; } elseif (time() >= $this->rematched_at && time() < $this->close_time) { return self::CHATTING; } else { return self::END; } } }