SportGame.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 App\Models\SportGameLog;
  7. use Exception;
  8. use App\Constants\HttpStatus;
  9. class SportGame extends Controller
  10. {
  11. /**
  12. * 足球游戏列表,树形结构
  13. */
  14. public function list()
  15. {
  16. try {
  17. $list = SportGameModel::with(['children'])->select(['id','name','name_en','end_time','is_locked'])->get()->toArray();
  18. } catch (Exception $e) {
  19. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  20. }
  21. return $this->success([ 'data' => $list]);
  22. }
  23. //设置赔率
  24. public function setOdds()
  25. {
  26. try {
  27. $params = request()->validate([
  28. 'id' => ['nullable','integer'],
  29. 'game_id' => ['nullable','integer'],
  30. 'odds' => ['required','numeric'],
  31. 'maxinum' => ['required','numeric'],
  32. 'mininum' => ['required','numeric'],
  33. ]);
  34. $id = $params['id'] ?? 0;
  35. if ($id) {
  36. $info = SportGameplay::where('id', $id)->first();
  37. if (!$info) throw new Exception('数据不存在');
  38. $info->odds = $params['odds'];
  39. $info->maxinum = $params['maxinum'];
  40. $info->mininum = $params['mininum'];
  41. $info->save();
  42. } else if (!empty($params['game_id']) ) {
  43. $where[] = ['game_id', $params['game_id']];
  44. SportGameplay::where($where)->update(['odds' => $params['odds'], 'maxinum' => $params['maxinum'], 'mininum' => $params['mininum']]);
  45. } else {
  46. throw new Exception('参数错误');
  47. }
  48. return $this->success();
  49. } catch (Exception $e) {
  50. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  51. }
  52. }
  53. //开奖
  54. public function openCode() {
  55. try {
  56. $params = request()->validate([
  57. 'id' => ['required','integer'],
  58. ]);
  59. $id = $params['id'];
  60. $info = SportGameModel::find($id);
  61. if (!$info) {
  62. return $this->error(HttpStatus::NOT_FOUND,'数据不存在');
  63. }
  64. //记录开奖日志
  65. $log = new SportGameLog();
  66. $log->game_id = $info->game_id;
  67. $log->gameplay_id = $info->id;
  68. $log->name = $info->name;
  69. $log->name_en = $info->name_en;
  70. $log->save();
  71. //订单结算
  72. return $this->success();
  73. } catch (Exception $e) {
  74. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  75. }
  76. }
  77. }