ExpireRewardAction.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Module\Activity\AdminControllers\Actions;
  3. use App\Module\Activity\Enums\REWARD_STATUS;
  4. use App\Module\Activity\Models\ActivityParticipation;
  5. use Dcat\Admin\Grid\RowAction;
  6. use Illuminate\Http\Request;
  7. /**
  8. * 标记活动奖励为已过期操作
  9. */
  10. class ExpireRewardAction extends RowAction
  11. {
  12. /**
  13. * 操作按钮标题
  14. *
  15. * @var string
  16. */
  17. protected $title = '<i class="fa fa-clock-o"></i> 标记已过期';
  18. /**
  19. * 判断是否允许显示此操作
  20. *
  21. * @return bool
  22. */
  23. public function allowed()
  24. {
  25. return $this->row->reward_status === REWARD_STATUS::NOT_CLAIMED;
  26. }
  27. /**
  28. * 处理请求
  29. *
  30. * @param Request $request
  31. * @return mixed
  32. */
  33. public function handle(Request $request)
  34. {
  35. try {
  36. $id = $this->getKey();
  37. $participation = ActivityParticipation::findOrFail($id);
  38. if ($participation->reward_status !== REWARD_STATUS::NOT_CLAIMED) {
  39. return $this->response()->error('只有未领取的奖励才能标记为已过期');
  40. }
  41. $participation->reward_status = REWARD_STATUS::EXPIRED;
  42. $participation->save();
  43. return $this->response()
  44. ->success("参与记录 [{$id}] 的奖励已标记为已过期")
  45. ->refresh();
  46. } catch (\Exception $e) {
  47. return $this->response()
  48. ->error('操作失败: ' . $e->getMessage());
  49. }
  50. }
  51. /**
  52. * 确认信息
  53. *
  54. * @return array|string|void
  55. */
  56. public function confirm()
  57. {
  58. return ['确定要标记此奖励为已过期吗?', '标记已过期后,用户将无法领取奖励'];
  59. }
  60. }