name = $params["name"]; $this->description = $params["description"]; $this->icon = $params["icon"]; $this->status = "normal"; if ($this->name == "") { return ["code" => EMPTY_GROUP_NAME]; } // check and isn't allowed same name of group $group = $this->where("name", $this->name)->where("is_del", false)->first(); if ($group) { return ["code" => REPEAT_GROUP_NAME]; } $this->save(); $params["id"] = $this->getQueueableId(); return ["code" => SUCCESS, "data" => $params]; } public function ModifyGroup(array $params) { $update = []; $gid = $params["id"]; if ($gid == "") { return EMPTY_GROUP_ID; } if ($params["name"] != "") { $update["name"] = $params["name"]; } if ($params["description"] != "") { $update["description"] = $params["description"]; } if ($params["icon"] != "") { $update["icon"] = $params["icon"]; } if (count($update) == 0) { return NOTHING_UPDATE; } $group = $this->where("id", $gid)->where("is_del", false)->first(); if (!$group) { return INVALID_GROUP_ID; } $this->where("id", $gid)->where("is_del", false)->update($update); return SUCCESS; } public function DeleteGroup(array $params) { $gid = $params["id"]; if ($gid == "") { return EMPTY_GROUP_ID; } $row = $this->where("id", $gid)->where("is_del", false)->update(["is_del" => true]); if ($row == 0) { return INVALID_GROUP_ID; } return SUCCESS; } // public function LoadGroup(array $params){ // $gid = $params["gid"]; // if ($gid == ""){ // return"empty group id"; // } // } public function ListGroup(array $params) { $uid = $params["uid"]; $groupUser = new GroupUser(); $groupIds = $groupUser->ListGroupIds($uid); if (count($groupIds) == 0) { return []; } // $result = $this->select("id", "name", "description", "icon", "status") ->where("id", $groupIds) ->where("is_del", false) ->all(); return $result; } }