SportGame.php 1.9 KB

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