LhcNumber.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\LhcNumber as LhcNumberModel;
  5. use Exception;
  6. use App\Constants\HttpStatus;
  7. class LhcNumber extends Controller
  8. {
  9. /**
  10. * 号码管理列表
  11. */
  12. public function list()
  13. {
  14. try {
  15. $list = LhcNumberModel::get();
  16. // 2. 格式化树形结构
  17. $tree = [];
  18. foreach ($list as $item) {
  19. // 一级节点:game
  20. if (!isset($tree[$item->game])) {
  21. $tree[$item->game] = [
  22. 'name' => $item->game,
  23. 'children' => []
  24. ];
  25. }
  26. // 二级节点:gameplay
  27. if (!isset($tree[$item->game]['children'][$item->gameplay])) {
  28. $tree[$item->game]['children'][$item->gameplay] = [
  29. 'name' => $item->gameplay,
  30. 'children' => []
  31. ];
  32. }
  33. // 三级:把数据放入 children
  34. $tree[$item->game]['children'][$item->gameplay]['children'][] = ['id' => $item->id,'number' => $item->number, 'odds' => $item->odds, 'maxinum' => $item->maxinum, 'mininum' => $item->mininum];
  35. }
  36. // 重新索引,返回纯数组结构
  37. $tree = array_values($tree);
  38. } catch (Exception $e) {
  39. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  40. }
  41. return $this->success([ 'data' => $tree]);
  42. }
  43. //设置赔率
  44. public function setOdds()
  45. {
  46. return $this->error(HttpStatus::CUSTOM_ERROR, '请前往赔率管理选择具体六合彩彩种和模板');
  47. }
  48. }