From b301698ec975d225d44f5cf6193153ea795162c7 Mon Sep 17 00:00:00 2001 From: xjh <2423579486@qq.com> Date: Sat, 22 Apr 2023 15:18:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=8E=B7=E5=8F=96=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Works/WorksType.php | 62 ++++++++++++------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/app/admin/controller/Works/WorksType.php b/app/admin/controller/Works/WorksType.php index 3c49b2a..a691715 100644 --- a/app/admin/controller/Works/WorksType.php +++ b/app/admin/controller/Works/WorksType.php @@ -35,37 +35,39 @@ class WorksType extends BaseController ->order('works_type_order') ->column('works_type_guid'); - $works_type = ModelWorksType::whereOr([ - [["a.works_type_guid", 'in', $works_type_guids]], - [["a.works_type_ancestors_guid", 'REGEXP', implode('|', $works_type_guids)]], - ]) - ->where([['b.works_type_delete_time', 'NULL', null]]) - ->field([ - 'a.works_type_id', - 'a.works_type_guid', - 'a.works_type_name', - 'a.works_type_order', - 'a.works_type_parent_guid', - 'a.works_type_ancestors_guid', - 'b.works_type_name' => "works_type_parent_name", - ])->alias('a') - ->leftjoin('works_type b', 'a.works_type_parent_guid = b.works_type_guid') - ->order('works_type_order') - ->select() - ->toArray(); - - $Traverse = new Traverse('works_type_guid', 'works_type_parent_guid'); - $works_type_tree = $Traverse->tree($works_type, '0', function ($v) { - return [ - 'works_type_name' => $v['works_type_name'], - 'works_type_parent_name' => $v['works_type_parent_name'], - 'works_type_guid' => $v['works_type_guid'], - 'works_type_parent_guid' => $v['works_type_parent_guid'], - 'works_type_ancestors_guid' => $v['works_type_ancestors_guid'], - 'works_type_order' => $v['works_type_order'], - ]; - }); + $works_type_tree = []; + if ($works_type_guids) { + $works_type = ModelWorksType::whereOr([ + [["a.works_type_guid", 'in', $works_type_guids]], + [["a.works_type_ancestors_guid", 'REGEXP', implode('|', $works_type_guids)]], + ]) + ->where([['b.works_type_delete_time', 'NULL', null]]) + ->field([ + 'a.works_type_id', + 'a.works_type_guid', + 'a.works_type_name', + 'a.works_type_order', + 'a.works_type_parent_guid', + 'a.works_type_ancestors_guid', + 'b.works_type_name' => "works_type_parent_name", + ])->alias('a') + ->leftjoin('works_type b', 'a.works_type_parent_guid = b.works_type_guid') + ->order('works_type_order') + ->select() + ->toArray(); + $Traverse = new Traverse('works_type_guid', 'works_type_parent_guid'); + $works_type_tree = $Traverse->tree($works_type, '0', function ($v) { + return [ + 'works_type_name' => $v['works_type_name'], + 'works_type_parent_name' => $v['works_type_parent_name'], + 'works_type_guid' => $v['works_type_guid'], + 'works_type_parent_guid' => $v['works_type_parent_guid'], + 'works_type_ancestors_guid' => $v['works_type_ancestors_guid'], + 'works_type_order' => $v['works_type_order'], + ]; + }); + } return msg(0, "获取作品类型列表成功!", [ 'data' => $works_type_tree, 'count' => ModelWorksType::where('works_type_parent_guid', '0')->count()