JisuGame.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. 'game' => ['nullable','string'],
  31. 'gameplay' => ['nullable','string'],
  32. 'type' => ['nullable','integer'],
  33. 'odds' => ['required','numeric'],
  34. 'maxinum' => ['required','numeric'],
  35. 'mininum' => ['required','numeric'],
  36. ]);
  37. if (!empty($params['id'])) {
  38. $info = JisuGameplay::where('id', $params['id'])->first();
  39. if (!$info) throw new Exception('数据不存在');
  40. $info->odds = $params['odds'];
  41. $info->maxinum = $params['maxinum'];
  42. $info->mininum = $params['mininum'];
  43. $info->save();
  44. } elseif (!empty($params['game']) && !empty($params['type'])) {
  45. JisuGameplay::where('game', $params['game'])->where('type', $params['type'])->update([
  46. 'odds' => $params['odds'],
  47. 'maxinum' => $params['maxinum'],
  48. 'mininum' => $params['mininum'],
  49. ]);
  50. } elseif (!empty($params['gameplay']) && !empty($params['type'])) {
  51. JisuGameplay::where('gameplay', $params['gameplay'])->where('type', $params['type'])->update([
  52. 'odds' => $params['odds'],
  53. 'maxinum' => $params['maxinum'],
  54. 'mininum' => $params['mininum'],
  55. ]);
  56. } else {
  57. throw new Exception('参数错误');
  58. }
  59. return $this->success();
  60. } catch (Exception $e) {
  61. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  62. }
  63. }
  64. }