| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Module\Game\AdminControllers\Actions;
- use App\Module\Game\AdminControllers\LazyRenderable\RandomRewardResultLazyRenderable;
- use App\Module\Game\Models\GameRewardGroup;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Widgets\Modal;
- use Illuminate\Http\Request;
- /**
- * 批量随机奖励操作
- */
- class BatchRandomRewardAction extends RowAction
- {
- /**
- * 模拟次数
- *
- * @var int
- */
- protected int $count;
- /**
- * 构造函数
- *
- * @param int $count 模拟次数
- */
- public function __construct(int $count = 10)
- {
- $this->count = $count;
- $this->title = "<i class=\"fa fa-gift\"></i> {$count}次随机奖励";
- }
- /**
- * 渲染操作按钮
- *
- * @return string
- */
- public function render()
- {
- $group = GameRewardGroup::find($this->getKey());
- if (!$group) {
- return '<span class="text-muted">奖励组不存在</span>';
- }
- // 创建弹窗表格
- $modal = Modal::make()
- ->xl()
- ->title("{$this->count}次随机奖励模拟结果 - {$group->name}")
- ->body(RandomRewardResultLazyRenderable::make()->payload([
- 'group_id' => $this->getKey(),
- 'count' => $this->count
- ]))
- ->button($this->title);
- return $modal->render();
- }
- /**
- * 处理请求(这个方法在使用Modal时不会被调用)
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- // 使用Modal时此方法不会被调用
- return $this->response()->success('操作完成');
- }
- }
|