when(!empty($show), function ($query){ $query->where('is_show',1); })->order("seq","desc")->select(); $data = []; foreach ($cateData as $item) { $data[] = $item->getData(); } $menuAr = Arr::getTree($data); return $menuAr; } /** * 保存分类 * @param $post * @return bool */ public function cateSave($post){ if(!empty($post['id'])) { $this->where('id',$post['id'])->save($post); return true; } else { unset($post['id']); $bool = $this->insert($post); return $bool; } } /** * 删除分类 * @param $id */ public function cateDel($id){ $this->where('pid',$id)->delete(); $this->where('id',$id)->delete(); return true; } /** * 设置显示状态 * @param $id * @param $status */ public function cateShowSet($id,$status) { self::beginTrans(); try{ $this->where('id', $id)->save(['is_show'=>$status]); $this->where('pid',$id)->save(['is_show'=>$status]); self::commitTrans(); return true; }catch (DbException $db) { self::rollbackTrans(); return false; } } }