EMPTY_ACTION_BAR_NAME]; } if ($this->parent < 0) { return ["code" => INVALID_ACTION_PARENT]; } if ($this->link_type == "") { $this->link_type = LINK_TYPE_URL; } $name = $params["name"]; $result = $this->firstOrCreate(["name" => $name], $params); unset($result["is_del"]); unset($result["created_user_id"]); unset($result["updated_user_id"]); return ["code" => SUCCESS, "data" => $result]; } /** * 根据菜单的id更新一个菜单内容 * * @param array $params * @return string */ public function ModifyActionBar(array $params) { $update = []; $id = $params["id"]; if ($id == "") { return EMPTY_ACTION_BAR_ID; } if ($params["parent"] > 0) { $update["parent"] = $params["parent"]; } if (strlen($params["icon"]) > 0) { $update["icon"] = $params["icon"]; } if (strlen($params["link_type"]) > 0) { $update["link_type"] = $params["link_type"]; } if (strlen($params["link"]) > 0) { $update["link"] = $params["link"]; } if (strlen($params["name"]) > 0) { Log::debug("name is " . $params["name"]); $update["name"] = $params["name"]; } if (strlen($params["description"]) > 0) { $update["description"] = $params["description"]; } if (count($update) == 0) { return NOTHING_UPDATE; } // check the data if exist in system. $actionBar = $this->where("id", $id)->where("is_del", false)->first(); if (!$actionBar) { return INVALID_ACTION_BAR_ID; } $this->where("id", $id)->where("is_del", false)->update($update); return SUCCESS; } /** * 删除一个菜单项目,这里存在一个问题,就是如果删除上层的菜单,下层的菜单也应该都被删掉。但是可以通过parent来控制 * 下层菜单不被加载出来 * * @param array $params * @return int */ public function DeleteActionBar(array $params) { $id = $params["id"]; if ($id < 1) { return EMPTY_ACTION_BAR_ID; } $row = $this->where("id", $id)->where("is_del", false)->update(["is_del" => true]); if ($row == 0) { return INVALID_ACTION_BAR_ID; } return SUCCESS; } /** * 查出当前用户可以访问的所有action_bar的信息 * * @param array $params * @return array */ public function ListActionBar(array $params) { $uid = $params["uid"]; // 收集当前用户有权限的bar_id $userActionBar = new UserActionBar(); $bar_ids = $userActionBar->ListActionBarIds("", $uid); if (count($bar_ids) == 0) { return ["code" => SUCCESS, "data" => []]; } // 查出bars的信息 $result = $this->select("id", "parent", "name", "description", "icon", "link_type", "link") ->where("id", $bar_ids) ->where("status", "normal")->where("is_del", false)->get(); return ["code" => SUCCESS, "data" => $result]; } }