JisuGame.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\JisuGameplay;
  5. use Exception;
  6. use App\Constants\HttpStatus;
  7. class JisuGame extends Controller
  8. {
  9. /**
  10. * 足球游戏列表,树形结构
  11. */
  12. public function list()
  13. {
  14. try {
  15. $params = request()->validate([
  16. 'type' => ['required','integer'],
  17. ]);
  18. $list = JisuGameplay::getGame($params['type']);
  19. } catch (Exception $e) {
  20. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  21. }
  22. return $this->success([ 'data' => $list]);
  23. }
  24. //设置赔率
  25. public function setOdds()
  26. {
  27. try {
  28. $params = request()->validate([
  29. 'id' => ['nullable','integer'],
  30. 'gameplay' => ['nullable','string'],
  31. 'type' => ['nullable','integer'],
  32. 'odds' => ['required','numeric'],
  33. 'maxinum' => ['required','numeric'],
  34. 'mininum' => ['required','numeric'],
  35. ]);
  36. if (!empty($params['id'])) {
  37. $info = JisuGameplay::where('id', $params['id'])->first();
  38. if (!$info) throw new Exception('数据不存在');
  39. $info->odds = $params['odds'];
  40. $info->maxinum = $params['maxinum'];
  41. $info->mininum = $params['mininum'];
  42. $info->save();
  43. } elseif (!empty($params['gameplay']) && !empty($params['type'])) {
  44. JisuGameplay::where('gameplay', $params['gameplay'])->where('type', $params['type'])->update([
  45. 'odds' => $params['odds'],
  46. 'maxinum' => $params['maxinum'],
  47. 'mininum' => $params['mininum'],
  48. ]);
  49. } else {
  50. throw new Exception('参数错误');
  51. }
  52. return $this->success();
  53. } catch (Exception $e) {
  54. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  55. }
  56. }
  57. }