GameplayRule.php 3.9 KB

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