GameplayRule.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\GameplayRuleService;
  6. use Exception;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Validation\ValidationException;
  9. class GameplayRule extends Controller
  10. {
  11. /**
  12. * @api {get} /admin/role 角色列表
  13. * @apiGroup 玩法规则管理
  14. *
  15. * @apiUse result
  16. * @apiUse header
  17. * @apiVersion 1.0.0
  18. *
  19. * @apiParam {int} [page=1]
  20. * @apiParam {int} [limit=10]
  21. * @apiParam {string} [display_name] 角色名称
  22. *
  23. * @apiSuccess (data) {Object} data
  24. * @apiSuccess (data) {int} data.total 数量
  25. * @apiSuccess (data) {Object[]} data.data 列表
  26. * @apiSuccess (data) {int} data.data.id
  27. * @apiSuccess (data) {string} data.data.display_name 角色名称(显示用)
  28. * @apiSuccess (data) {string} data.data.description 角色描述
  29. * @apiSuccess (data) {array} data.data.menus_ids 角色拥有的菜单
  30. * @apiSuccess (data) {string} data.data.updated_at
  31. * @apiSuccess (data) {string} data.data.created_at
  32. */
  33. public function index()
  34. {
  35. try {
  36. request()->validate([
  37. 'title' => ['nullable', 'string'],
  38. 'permission_name' => ['nullable', 'string'],
  39. ]);
  40. $search = request()->all();
  41. $result = GameplayRuleService::paginate($search);
  42. } catch (ValidationException $e) {
  43. return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  44. } catch (Exception $e) {
  45. return $this->error(intval($e->getCode()));
  46. }
  47. return $this->success($result);
  48. }
  49. /**
  50. * @api {post} /admin/role/submit 修改角色
  51. * @apiGroup 玩法规则管理
  52. *
  53. * @apiUse result
  54. * @apiUse header
  55. * @apiVersion 1.0.0
  56. *
  57. * @apiParam {int} id 角色ID
  58. * @apiParam {string} display_name 角色名称(显示用)
  59. * @apiParam {string} description 角色描述
  60. * @apiParam {array} [menus_ids] 角色菜单
  61. */
  62. public function store()
  63. {
  64. // try {
  65. $params = request()->all();
  66. $validator = [
  67. 'keywords' => 'required|string|max:50',
  68. 'group' => 'required|string|max:50',
  69. 'maxinum' => 'required|integer|min:1',
  70. 'mininum' => 'required|integer|min:0',
  71. 'odds' => 'required|numeric|min:0',
  72. ];
  73. request()->validate($validator);
  74. $ret = GameplayRuleService::submit($params);
  75. if ($ret['code'] == GameplayRuleService::NOT) {
  76. return $this->error($ret['code'], $ret['msg']);
  77. }
  78. // } catch (ValidationException $e) {
  79. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  80. // } catch (Exception $e) {
  81. // return $this->error(intval($e->getCode()));
  82. // }
  83. return $this->success([], $ret['msg']);
  84. }
  85. /**
  86. * @api {post} /admin/role/delete 删除角色
  87. * @apiGroup 玩法规则管理
  88. *
  89. * @apiUse result
  90. * @apiUse header
  91. * @apiVersion 1.0.0
  92. *
  93. * @apiParam {int} id 角色ID
  94. */
  95. public function destroy()
  96. {
  97. $id = request()->post('id');
  98. // 示例:通过 ID 删除菜单
  99. $info = GameplayRuleService::findOne(['id' => $id]);
  100. if (!$info) {
  101. return $this->error(0, '角色不存在');
  102. }
  103. $info->delete();
  104. return $this->success([], '删除成功');
  105. }
  106. }