增加通过excel批量添加用户的功能,支持导入后自动发邮件

This commit is contained in:
wsczx
2022-10-22 20:36:10 +08:00
parent c6ef0a28b4
commit a77fe77e79
12 changed files with 168 additions and 22 deletions

View File

@@ -5,9 +5,10 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"text/template"
@@ -80,7 +81,7 @@ func UserDetail(w http.ResponseWriter, r *http.Request) {
func UserSet(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm()
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
RespError(w, RespInternalErr, err)
return
@@ -111,7 +112,28 @@ func UserSet(w http.ResponseWriter, r *http.Request) {
sessdata.CloseUserLimittimeSession()
RespSucess(w, nil)
}
func UserUpload(w http.ResponseWriter, r *http.Request) {
r.ParseMultipartForm(8 << 20)
file, header, err := r.FormFile("file")
if err != nil || !strings.Contains(header.Filename, ".xlsx") || !strings.Contains(header.Filename, ".xls") {
RespError(w, RespInternalErr, "文件解析失败:仅支持xlsx或xls文件")
return
}
defer file.Close()
newFile, err := os.Create(base.Cfg.FilesPath + header.Filename)
if err != nil {
RespError(w, RespInternalErr, "创建文件失败:", err)
return
}
defer newFile.Close()
io.Copy(newFile, file)
if err = UploadUser(newFile.Name()); err != nil {
RespError(w, RespInternalErr, err)
return
}
os.Remove(base.Cfg.FilesPath + header.Filename)
RespSucess(w, "批量添加成功")
}
func UserDel(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm()
idS := r.FormValue("id")