| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Module\Activity\AdminControllers\Actions;
- use App\Module\Activity\Enums\PARTICIPATION_STATUS;
- use App\Module\Activity\Enums\REWARD_STATUS;
- use App\Module\Activity\Models\ActivityParticipation;
- use Dcat\Admin\Grid\RowAction;
- use Illuminate\Http\Request;
- /**
- * 标记活动奖励为已领取操作
- */
- class ClaimRewardAction extends RowAction
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- protected $title = '<i class="fa fa-gift"></i> 标记已领取';
- /**
- * 判断是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- return $this->row->completion_status === PARTICIPATION_STATUS::COMPLETED
- && $this->row->reward_status === REWARD_STATUS::NOT_CLAIMED;
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- try {
- $id = $this->getKey();
-
- $participation = ActivityParticipation::findOrFail($id);
-
- if ($participation->completion_status !== PARTICIPATION_STATUS::COMPLETED) {
- return $this->response()->error('只有已完成的参与记录才能领取奖励');
- }
-
- if ($participation->reward_status !== REWARD_STATUS::NOT_CLAIMED) {
- return $this->response()->error('只有未领取的奖励才能标记为已领取');
- }
-
- $participation->reward_status = REWARD_STATUS::CLAIMED;
- $participation->reward_time = now();
- $participation->save();
-
- // 触发奖励领取事件
- event(new \App\Module\Activity\Events\ActivityRewardClaimedEvent(
- $participation->user_id,
- $participation->activity_id
- ));
-
- return $this->response()
- ->success("参与记录 [{$id}] 的奖励已标记为已领取")
- ->refresh();
- } catch (\Exception $e) {
- return $this->response()
- ->error('操作失败: ' . $e->getMessage());
- }
- }
- /**
- * 确认信息
- *
- * @return array|string|void
- */
- public function confirm()
- {
- return ['确定要标记此奖励为已领取吗?', '标记已领取后,用户将无法再次领取奖励'];
- }
- }
|