Game.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Models\GameplayRule;
  4. use Illuminate\Validation\ValidationException;
  5. use Exception;
  6. class Game extends BaseController
  7. {
  8. /**
  9. * @api {get} /game/rule 玩法规则
  10. */
  11. function rule()
  12. {
  13. try {
  14. request()->validate([
  15. 'page' => ['nullable', 'integer', 'min:1'],
  16. 'limit' => ['nullable', 'integer', 'min:1'],
  17. 'from' => ['nullable', 'string'],
  18. ]);
  19. $page = request()->input('page', 1);
  20. $limit = request()->input('limit', 10);
  21. $from = request()->input('from', '');
  22. $list = GameplayRule::forPage($page, $limit)
  23. ->orderBy('groups')
  24. ->orderByDesc('created_at')
  25. ->get();
  26. if ($from == 'football') {
  27. foreach($list as &$item) {
  28. if ($item['id'] <= 8) {
  29. $item['groups'] = '热门';
  30. }
  31. $item['groups'] = lang($item['groups']);
  32. //去掉数字
  33. $special_keywords = preg_replace('/[0-9]/u', '', $item['keywords']);
  34. if (in_array($special_keywords, ['操','尾'])) {
  35. $item['keywords'] = intval($item['keywords']).lang($special_keywords);
  36. } else {
  37. $item['keywords'] = lang($item['keywords']);
  38. }
  39. }
  40. }
  41. } catch (ValidationException $e) {
  42. return $this->error($e->validator->errors()->first());
  43. } catch (Exception $e) {
  44. return $this->error($e->getMessage());
  45. }
  46. return $this->success($list);
  47. }
  48. }