| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Http\Controllers\Controller;
- use App\Models\SportGame as SportGameModel;
- use App\Models\SportGameplay;
- use Exception;
- use App\Constants\HttpStatus;
- class SportGame extends Controller
- {
- /**
- * 足球游戏列表,树形结构
- */
- public function list()
- {
- try {
- $list = SportGameModel::with(['children'])->field('id,name,name_en,end_time,is_locked')->get()->toArray();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- return $this->success([ 'data' => $list]);
- }
- //设置赔率
- public function setOdds()
- {
- try {
- $params = request()->validate([
- 'id' => ['nullable','integer'],
- 'game_id' => ['nullable','integer'],
- 'odds' => ['required','numeric'],
- 'maxinum' => ['required','numeric'],
- 'mininum' => ['required','numeric'],
- ]);
- $id = $params['id'] ?? 0;
- if ($id) {
- $info = SportGameplay::where('id', $id)->first();
- if (!$info) throw new Exception('数据不存在');
- $info->odds = $params['odds'];
- $info->maxinum = $params['maxinum'];
- $info->mininum = $params['mininum'];
- $info->save();
- } else if (!empty($params['game_id']) ) {
- $where[] = ['game_id', $params['game_id']];
- SportGameplay::where($where)->update(['odds' => $params['odds'], 'maxinum' => $params['maxinum'], 'mininum' => $params['mininum']]);
- } else {
- throw new Exception('参数错误');
- }
-
- return $this->success();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- }
- }
|