| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Module\Activity\AdminControllers\Actions;
- use App\Module\Activity\Enums\REWARD_STATUS;
- use App\Module\Activity\Models\ActivityParticipation;
- use Dcat\Admin\Grid\RowAction;
- use Illuminate\Http\Request;
- /**
- * 标记活动奖励为已过期操作
- */
- class ExpireRewardAction extends RowAction
- {
- /**
- * 操作按钮标题
- *
- * @var string
- */
- protected $title = '<i class="fa fa-clock-o"></i> 标记已过期';
- /**
- * 判断是否允许显示此操作
- *
- * @return bool
- */
- public function allowed()
- {
- return $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->reward_status !== REWARD_STATUS::NOT_CLAIMED) {
- return $this->response()->error('只有未领取的奖励才能标记为已过期');
- }
-
- $participation->reward_status = REWARD_STATUS::EXPIRED;
- $participation->save();
-
- return $this->response()
- ->success("参与记录 [{$id}] 的奖励已标记为已过期")
- ->refresh();
- } catch (\Exception $e) {
- return $this->response()
- ->error('操作失败: ' . $e->getMessage());
- }
- }
- /**
- * 确认信息
- *
- * @return array|string|void
- */
- public function confirm()
- {
- return ['确定要标记此奖励为已过期吗?', '标记已过期后,用户将无法领取奖励'];
- }
- }
|