EMPTY_OWNER_TYPE]; } if ($ownerId < 1) { return ["code" => EMPTY_OWNER_ID]; } // 删除所有ownerType 和 ownerId $this->where("owner_type", $ownerType)->where("owner_id", $ownerId)->where("is_del", false) ->update(["is_del" => true]); // 重新添加ownerType 和 ownerId的数据 if (count($barIds) < 1) { return ["code" => SUCCESS, "data" => []]; } $data = []; foreach ($barIds as $barId) { array_push($data, array("owner_type" => $ownerType, "owner_id" => $ownerId, "bar_id" => $barId, "is_del" => false)); } $this->insert($data); // 查出批量插入的数据,并返回给前端 $new_data = $this->select("id", "owner_type", "owner_id", "bar_id", "status") ->where("owner_type", $ownerType)->where("owner_id", $ownerId)->where("is_del", false)->get(); return ["code" => SUCCESS, "data" => $new_data]; } /** * 根据多个类型,和多个id,加载菜单栏信息 * * @param array $ownerTypes * @param array $ownerIds * @return array */ public function ListActionBarIds(array $ownerTypes, array $ownerIds) { $opera = $this->select("owner_type", "owner_id", "bar_id"); if (count($ownerTypes) > 0) { $opera = $opera->whereIn("owner_type", $ownerTypes); } if (count($ownerIds) > 0) { $opera = $opera->whereIn("owner_id", $ownerIds); } $userBars = $opera->where("is_del", false)->get(); if (count($userBars) == 0) { return ["useBars" => []]; } $barIds = []; foreach ($userBars as $bar) { array_push($barIds, $bar["bar_id"]); } // 加载actionBar 的信息 $bar = new ActionBar(); $barInfo = $bar->LoadActionBarByIds_Format($barIds); return ["userBars" => $userBars, "barInfo" => $barInfo]; } public function ListActionBarIds_Format(array $ownerTypes, array $ownerIds) { $data = $this->ListActionBarIds($ownerTypes, $ownerIds); $userBars = $data["userBars"]; if (count($userBars) < 1) { return ["userBars" => (object)[]]; } $userBarFormat = []; foreach ($userBars as $userBar) { $key = $userBar["owner_id"]; if (!key_exists($userBar["owner_id"], $userBarFormat)) { $userBarFormat[$key] = []; } $tempArr = $userBarFormat[$key]; array_push($tempArr, $userBar); $userBarFormat[$key] = $tempArr; } $result = ["userBars" => $userBarFormat, "barInfo" => (object)[]]; if (key_exists("barInfo", $data)) { $result["barInfo"] = $data["barInfo"]; } return $result; } }