| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Controllers\api;
- use App\Models\GameplayRule;
- use Illuminate\Validation\ValidationException;
- use Exception;
- class Game extends BaseController
- {
- /**
- * @api {get} /game/rule 玩法规则
- */
- function rule()
- {
- try {
- request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'from' => ['nullable', 'string'],
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 10);
- $from = request()->input('from', '');
- $list = GameplayRule::forPage($page, $limit)
- ->orderBy('groups')
- ->orderByDesc('created_at')
- ->get();
- if ($from == 'football') {
- foreach($list as &$item) {
- if ($item['id'] <= 8) {
- $item['groups'] = '热门';
- }
- $item['groups'] = lang($item['groups']);
- //去掉数字
- $special_keywords = preg_replace('/[0-9]/u', '', $item['keywords']);
- if (in_array($special_keywords, ['操','尾'])) {
- $item['keywords'] = intval($item['keywords']).lang($special_keywords);
- } else {
- $item['keywords'] = lang($item['keywords']);
- }
- }
- }
-
- } catch (ValidationException $e) {
- return $this->error($e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success($list);
- }
- }
|