game])) { $tree[$item->game] = [ 'name' => $item->game, 'children' => [] ]; } // 二级节点:gameplay if (!isset($tree[$item->game]['children'][$item->gameplay])) { $tree[$item->game]['children'][$item->gameplay] = [ 'name' => $item->gameplay, 'children' => [] ]; } // 三级:把数据放入 children $tree[$item->game]['children'][$item->gameplay]['children'][] = ['id' => $item->id,'number' => $item->number, 'odds' => $item->odds]; } // 重新索引,返回纯数组结构 $tree = array_values($tree); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage()); } return $this->success([ 'data' => $tree]); } //设置赔率 public function setOdds() { try { $params = request()->validate([ 'id' => ['nullable','integer'], 'game' => ['nullable','string'], 'gameplay' => ['nullable','string'], 'odds' => ['required','numeric'] ]); $id = $params['id'] ?? 0; if ($id) { $info = LhcNumberModel::where('id', $id)->first(); if (!$info) throw new Exception('数据不存在'); $info->odds = $params['odds']; $info->updated_by = auth()->id(); $info->save(); } else if (!empty($params['game']) ) { $where[] = ['game', $params['game']]; if (!empty($params['gameplay'])) { $where[] = ['gameplay', $params['gameplay']]; } LhcNumberModel::where($where)->update(['odds' => $params['odds'], 'updated_by' => auth()->id()]); } else { throw new Exception('参数错误'); } return $this->success(); } catch (Exception $e) { return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage()); } } }