开始'; /** * 判断是否允许显示此操作 * * @return bool */ public function allowed() { return $this->row->status === ACTIVITY_STATUS::NOT_STARTED; } /** * 处理请求 * * @param Request $request * @return mixed */ public function handle(Request $request) { try { $id = $this->getKey(); $activity = ActivityConfig::findOrFail($id); if ($activity->status !== ACTIVITY_STATUS::NOT_STARTED) { return $this->response()->error('只有未开始的活动才能开始'); } $activity->status = ACTIVITY_STATUS::IN_PROGRESS; $activity->save(); // 触发活动状态变更事件 event(new \App\Module\Activity\Events\ActivityStatusChangedEvent( $activity->id, ACTIVITY_STATUS::NOT_STARTED, ACTIVITY_STATUS::IN_PROGRESS )); return $this->response() ->success("活动 [{$activity->name}] 已开始") ->refresh(); } catch (\Exception $e) { return $this->response() ->error('操作失败: ' . $e->getMessage()); } } /** * 确认信息 * * @return array|string|void */ public function confirm() { return ['确定要开始此活动吗?', '开始后活动将对用户可见并可参与']; } }