GameRewardLogController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Module\Game\AdminControllers;
  3. use App\Module\Game\Enums\REWARD_SOURCE_TYPE;
  4. use App\Module\Game\Enums\REWARD_TYPE;
  5. use App\Module\Game\Models\GameRewardGroup;
  6. use App\Module\Game\Repositorys\GameRewardLogRepository;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. use Dcat\Admin\Widgets\Card;
  11. use Dcat\Admin\Widgets\Table;
  12. /**
  13. * 奖励日志管理控制器
  14. */
  15. class GameRewardLogController extends AdminController
  16. {
  17. /**
  18. * 标题
  19. *
  20. * @return string
  21. */
  22. protected function title()
  23. {
  24. return '奖励日志管理';
  25. }
  26. /**
  27. * 创建表格
  28. *
  29. * @return Grid
  30. */
  31. protected function grid()
  32. {
  33. return Grid::make(new GameRewardLogRepository(), function (Grid $grid) {
  34. $grid->column('id', 'ID')->sortable();
  35. $grid->column('user_id', '用户ID');
  36. $grid->column('group_id', '奖励组')->display(function ($groupId) {
  37. $group = GameRewardGroup::find($groupId);
  38. return $group ? "{$group->name} ({$group->code})" : "未知 ({$groupId})";
  39. });
  40. $grid->column('source_type', '来源类型')->display(function ($type) {
  41. return REWARD_SOURCE_TYPE::getName($type);
  42. });
  43. $grid->column('source_id', '来源ID');
  44. $grid->column('reward_items', '奖励项')->display(function ($items) {
  45. $items = json_decode($items, true);
  46. if (empty($items)) {
  47. return '无奖励项';
  48. }
  49. $count = count($items);
  50. return "<span class=\"badge badge-primary\">{$count}个奖励项</span>";
  51. });
  52. $grid->column('created_at', '创建时间');
  53. $grid->filter(function (Grid\Filter $filter) {
  54. $filter->equal('id', 'ID');
  55. $filter->equal('user_id', '用户ID');
  56. $filter->equal('group_id', '奖励组')->select(
  57. GameRewardGroup::pluck('name', 'id')
  58. );
  59. $filter->equal('source_type', '来源类型')->select(REWARD_SOURCE_TYPE::getAll());
  60. $filter->equal('source_id', '来源ID');
  61. $filter->between('created_at', '创建时间')->datetime();
  62. });
  63. // 禁用创建按钮
  64. $grid->disableCreateButton();
  65. // 禁用编辑和删除
  66. $grid->actions(function (Grid\Displayers\Actions $actions) {
  67. $actions->disableEdit();
  68. $actions->disableDelete();
  69. });
  70. });
  71. }
  72. /**
  73. * 创建详情页
  74. *
  75. * @param mixed $id
  76. * @return Show
  77. */
  78. protected function detail($id)
  79. {
  80. return Show::make($id, new GameRewardLogRepository(), function (Show $show) {
  81. $show->field('id', 'ID');
  82. $show->field('user_id', '用户ID');
  83. $show->field('group_id', '奖励组')->as(function ($groupId) {
  84. $group = GameRewardGroup::find($groupId);
  85. return $group ? "{$group->name} ({$group->code})" : "未知 ({$groupId})";
  86. });
  87. $show->field('source_type', '来源类型')->as(function ($type) {
  88. return REWARD_SOURCE_TYPE::getName($type);
  89. });
  90. $show->field('source_id', '来源ID');
  91. $show->field('created_at', '创建时间');
  92. // 显示奖励项
  93. $show->divider();
  94. $show->field('奖励项')->as(function () {
  95. $items = json_decode($this->reward_items, true);
  96. if (empty($items)) {
  97. return '无奖励项';
  98. }
  99. $headers = ['奖励类型', '目标ID', '参数1', '参数2', '数量', '额外数据'];
  100. $rows = [];
  101. foreach ($items as $item) {
  102. $rows[] = [
  103. REWARD_TYPE::getName($item['reward_type']),
  104. $item['target_id'],
  105. $item['param1'] ?? 0,
  106. $item['param2'] ?? 0,
  107. $item['quantity'],
  108. json_encode($item['extra_data'] ?? null)
  109. ];
  110. }
  111. return Card::make(
  112. Table::make($headers, $rows)
  113. );
  114. });
  115. });
  116. }
  117. }