|
@@ -13,7 +13,7 @@ class ActionBar extends Model
|
|
|
{
|
|
|
protected $table = "action_bars";
|
|
|
public $timestamps = false;
|
|
|
- protected $fillable = ["name"];
|
|
|
+ protected $fillable = ["parent", "icon", "link_type", "link", "name", "description"];
|
|
|
|
|
|
/**
|
|
|
* @param array $params
|
|
@@ -60,7 +60,7 @@ class ActionBar extends Model
|
|
|
$update = [];
|
|
|
$id = $params["id"];
|
|
|
if ($id == "") {
|
|
|
- return "invalid id";
|
|
|
+ return EMPTY_ACTION_BAR_ID;
|
|
|
}
|
|
|
if ($params["parent"] > 0) {
|
|
|
$update["parent"] = $params["parent"];
|
|
@@ -82,35 +82,37 @@ class ActionBar extends Model
|
|
|
$update["description"] = $params["description"];
|
|
|
}
|
|
|
if (count($update) == 0) {
|
|
|
- return "nothing to update";
|
|
|
+ return NOTHING_UPDATE;
|
|
|
}
|
|
|
|
|
|
- $num = $this->where("id", $id)
|
|
|
- ->where("status", "normal")
|
|
|
- ->where("is_del", false)
|
|
|
- ->update($update);
|
|
|
- return "success";
|
|
|
- }
|
|
|
+ // check the data if exist in system.
|
|
|
+ $actionBar = $this->where("id", $id)->where("is_del", false)->first();
|
|
|
+ if (!$actionBar) {
|
|
|
+ return INVALID_ACTION_BAR_ID;
|
|
|
+ }
|
|
|
|
|
|
- // todo.
|
|
|
+ $this->where("id", $id)->where("is_del", false)->update($update);
|
|
|
+ return SUCCESS;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * 删除一个菜单项目,这里存在一个问题,就是如果删除上层的菜单,下层的菜单也应该都被删掉。先留空。
|
|
|
+ * 删除一个菜单项目,这里存在一个问题,就是如果删除上层的菜单,下层的菜单也应该都被删掉。但是可以通过parent来控制
|
|
|
+ * 下层菜单不被加载出来
|
|
|
*
|
|
|
* @param array $params
|
|
|
- * @return string
|
|
|
+ * @return int
|
|
|
*/
|
|
|
public function DeleteActionBar(array $params)
|
|
|
{
|
|
|
$id = $params["id"];
|
|
|
- if ($id == "") {
|
|
|
- return "invalid 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;
|
|
|
}
|
|
|
- $num = $this->where("id", $id)
|
|
|
- ->where("status", "normal")
|
|
|
- ->where("is_del", false)
|
|
|
- ->update(["is_del" => true]);
|
|
|
- return "success";
|
|
|
+ return SUCCESS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -125,18 +127,16 @@ class ActionBar extends Model
|
|
|
|
|
|
// 收集当前用户有权限的bar_id
|
|
|
$userActionBar = new UserActionBar();
|
|
|
- $bar_ids = $userActionBar->ListActionBarIds($uid);
|
|
|
+ $bar_ids = $userActionBar->ListActionBarIds("", $uid);
|
|
|
if (count($bar_ids) == 0) {
|
|
|
- return [];
|
|
|
+ return ["code" => SUCCESS, "data" => []];
|
|
|
}
|
|
|
|
|
|
// 查出bars的信息
|
|
|
- $result = $this->select("id", "parent", "level", "name", "description", "icon", "link_type", "link")
|
|
|
+ $result = $this->select("id", "parent", "name", "description", "icon", "link_type", "link")
|
|
|
->where("id", $bar_ids)
|
|
|
- ->where("status", "normal")
|
|
|
- ->where("is_del", false)
|
|
|
- ->all();
|
|
|
- return $result;
|
|
|
+ ->where("status", "normal")->where("is_del", false)->get();
|
|
|
+ return ["code" => SUCCESS, "data" => $result];
|
|
|
}
|
|
|
}
|
|
|
|