username = $params["username"]; $this->password = $params["password"]; $this->nickname = $params["nickname"]; $this->icon = $params["icon"]; $this->tel = $params["tel"]; $this->email = $params["email"]; if ($this->username == "") { return ["code" => EMPTY_USER_NAME]; } if ($this->password == "") { return ["code" => EMPTY_USER_PASSWORD]; } if ($this->nickname == "") { $this->nickname = $this->username; $params["nickname"] = $this->username; } // todo 这里需要对密码加密 $this->save(); unset($params["password"]); $params["id"] = $this->getQueueableId(); return ["code" => SUCCESS, "data" => $params]; } public function ChangePassword($uid, $oldPwd, $newPwd) { } public function ModifyUser(array $params) { $update = []; $uid = $params["id"]; if ($uid == "") { return "empty user id"; } // check if user exist $user = $this->where("id", $uid)->where("is_del", false)->first(); if (!$user) { return INVALID_USER_ID; } if ($params["username"] != "") { $update["username"] = $params["username"]; } if ($params["nickname"] != "") { $update["nickname"] = $params["nickname"]; } if ($params["icon"] != "") { $update["icon"] = $params["icon"]; } if ($params["tel"] != "") { $update["tel"] = $params["tel"]; } if ($params["email"] != "") { $update["email"] = $params["email"]; } if (count($update) == 0) { return "nothing to update"; } $this->where("id", $uid)->where("is_del", false)->update($update); return SUCCESS; } public function DeleteUser($uid) { if ($uid == "") { return "empty user id"; } $user = $this->where("id", $uid)->where("is_del", false)->first(); if (!$user) { return 110; } $this->where("id", $uid)->where("is_del", false)->update(["is_del" => true]); return 0; } public function ListUser($page, $pageCount, $keyword) { if ($page < 1) { $page = 15; } if ($pageCount > 15 || $pageCount < 1) { $pageCount = 15; } $data = $this->select("id", "username", "nickname", "icon", "tel", "email") ->where("is_del", false)->orderBy("created_at", "asc") ->paginate($pageCount, ["*"], "page", $page); return $data; } public function ListUserByIds($ids) { $users = $this->select("id", "username", "nickname", "icon") ->whereIn("id", $ids)->where("is_del", false)->get(); return $users; } public function ListUserByIds_KV($ids) { $users = $this->ListUserByIds($ids); $data = []; foreach ($users as $user) { $data[$user["id"]] = $user; } return $data; } }