作者 lyh

gx

@@ -8,6 +8,8 @@ use App\Helper\FormGlobalsoApi; @@ -8,6 +8,8 @@ use App\Helper\FormGlobalsoApi;
8 use App\Models\Domain\DomainInfo; 8 use App\Models\Domain\DomainInfo;
9 use App\Models\HomeCount\Count; 9 use App\Models\HomeCount\Count;
10 use App\Models\Inquiry\InquiryFormData; 10 use App\Models\Inquiry\InquiryFormData;
  11 +use App\Models\Nav\BNav;
  12 +use App\Models\Nav\BNavGroup;
11 use App\Models\Project\Project; 13 use App\Models\Project\Project;
12 use App\Services\ProjectServer; 14 use App\Services\ProjectServer;
13 use Illuminate\Console\Command; 15 use Illuminate\Console\Command;
@@ -52,6 +54,17 @@ class Test extends Command @@ -52,6 +54,17 @@ class Test extends Command
52 */ 54 */
53 public function handle() 55 public function handle()
54 { 56 {
  57 + ProjectServer::useProject(1);
  58 + $group =BNavGroup::where(['id' => 1])->first();
  59 + $sort_list = json_decode($group->sort_list, true);
  60 + $nav = new BNav();
  61 + $map = [
  62 + 'project_id' => 1,
  63 + 'group_id' => 1
  64 + ];
  65 + $list = $nav->list($map, ['sort','id']);
  66 + $ids = array_column($group, 'id');
  67 + dd($list, $sort_list);
55 $projects = Project::all(); 68 $projects = Project::all();
56 foreach ($projects as $project){ 69 foreach ($projects as $project){
57 echo "project " . $project->id; 70 echo "project " . $project->id;
@@ -31,13 +31,8 @@ class NavController extends BaseController @@ -31,13 +31,8 @@ class NavController extends BaseController
31 public function index(BNav $nav,BNavGroup $navGroup){ 31 public function index(BNav $nav,BNavGroup $navGroup){
32 $this->map['project_id'] = $this->user['project_id']; 32 $this->map['project_id'] = $this->user['project_id'];
33 $lists = $nav->list($this->map,$this->order = ['sort','id']); 33 $lists = $nav->list($this->map,$this->order = ['sort','id']);
34 - //获取菜单组排序字段  
35 - $groupInfo = $navGroup->read(['id'=>$this->param['group_id']]);  
36 - if(!empty($groupInfo['sort_list'])){  
37 - $sort_list = json_decode($groupInfo['sort_list']);  
38 - $data = $this->findDetailsList($sort_list,$lists);  
39 - }else{  
40 - $data = array(); 34 + $data = array();
  35 + if(!empty($lists)){
41 foreach ($lists as $v){ 36 foreach ($lists as $v){
42 $v = (array)$v; 37 $v = (array)$v;
43 if ($v['pid'] == 0) { 38 if ($v['pid'] == 0) {
@@ -45,6 +40,12 @@ class NavController extends BaseController @@ -45,6 +40,12 @@ class NavController extends BaseController
45 $data[] = $v; 40 $data[] = $v;
46 } 41 }
47 } 42 }
  43 + //获取菜单组排序字段
  44 + $groupInfo = $navGroup->read(['id'=>$this->param['group_id']]);
  45 + if(!empty($groupInfo['sort_list'])){
  46 + $sort_list = json_decode($groupInfo['sort_list']);
  47 + $data = $this->findDetailsLists($sort_list,$data);
  48 + }
48 } 49 }
49 $this->response('success',Code::SUCCESS,$data); 50 $this->response('success',Code::SUCCESS,$data);
50 } 51 }
@@ -56,53 +57,28 @@ class NavController extends BaseController @@ -56,53 +57,28 @@ class NavController extends BaseController
56 * @method :post 57 * @method :post
57 * @time :2023/12/18 14:54 58 * @time :2023/12/18 14:54
58 */ 59 */
59 - public function findDetailsList($data, $detailsList) {  
60 - $result = [];  
61 - foreach ($data as $item) {  
62 - $items = $item = (array)$item;  
63 - $id = $item['id'];  
64 - // 在给定的详情列表中查找匹配的id  
65 - $matchingDetail = array_filter($detailsList, function ($detail) use ($id) {  
66 - return $detail['id'] == $id;  
67 - });  
68 - if (!empty($matchingDetail)) {  
69 - $items = reset($matchingDetail);  
70 - }  
71 - if (!empty($item['sub'])) {  
72 - $items['sub'] = $this->findDetailsList((array)$item['sub'], $detailsList); 60 + public function findDetailsLists($sort_list, $data)
  61 + {
  62 + $detailsList = [];
  63 + foreach ($data as $v) {
  64 + if (!empty($v['sub'])){
  65 + $v['sub'] = $this->custom($v['sub']);
73 } 66 }
74 - $result[] = $items; 67 + $detailsList[$v['id']] = $v;
75 } 68 }
76 - foreach ($detailsList as $v){  
77 - if($v['pid'] == 0){  
78 - $result[] = $v;  
79 - }else{//放到对应的上级下面  
80 - $this->addUnderParent($result,$v);  
81 - }  
82 - }  
83 - return $result;  
84 - }  
85 -  
86 - /**  
87 - * Add the current item under its parent in the result array  
88 - *  
89 - * @param array $result  
90 - * @param array $item  
91 - */  
92 - private function addUnderParent(&$result, $item) {  
93 - $parentId = $item['pid'];  
94 - foreach ($result as &$parent) {  
95 - if ($parent['id'] == $parentId) {  
96 - if (!isset($parent['sub'])) {  
97 - $parent['sub'] = [];  
98 - }  
99 - $parent['sub'][] = $item;  
100 - return; 69 + $result = [];
  70 + foreach ($sort_list as $val) {
  71 + if (!empty($val['sub'])){
  72 + $this->customSort($val['sub'], $detailsList[$val['id']]['sub']);
101 } 73 }
102 - if (!empty($parent['sub'])) {  
103 - $this->addUnderParent($parent['sub'], $item); 74 + if (empty($detailsList[$val['id']])){
  75 + continue;
104 } 76 }
  77 + $result[] = $detailsList[$val['id']];
  78 + unset($detailsList[$val['id']]);
105 } 79 }
  80 + $result = array_merge($result, $detailsList);
  81 + return $this->success($result);
106 } 82 }
107 83
108 /** 84 /**
@@ -80,7 +80,7 @@ class CustomTemplateLogic extends BaseLogic @@ -80,7 +80,7 @@ class CustomTemplateLogic extends BaseLogic
80 $this->model->edit(['url'=>$route],['id'=>$id]); 80 $this->model->edit(['url'=>$route],['id'=>$id]);
81 } 81 }
82 }catch (\Exception $e){ 82 }catch (\Exception $e){
83 - $this->fail('error'); 83 + $this->fail('保存失败,请联系管理员');
84 } 84 }
85 return $this->success(); 85 return $this->success();
86 } 86 }