diff --git a/server/controller/salary.go b/server/controller/salary.go index be1c2fa..ee6a96c 100644 --- a/server/controller/salary.go +++ b/server/controller/salary.go @@ -53,6 +53,13 @@ func (s *Salary) Update(ctx *gin.Context) { ctx.JSON(http.StatusOK, session.NewRspOk()) } +func (s *Salary) Upload(ctx *gin.Context) { + + rsp := service.NewStaffSalary().Upload(ctx) + ctx.Keys[session.ContextResponse] = rsp + ctx.JSON(http.StatusOK, session.NewRsp(rsp)) +} + func (s *Salary) Pay(ctx *gin.Context) { sess := ctx.Keys[session.ContextSession].(*session.AdminSession) if !sess.GetAdmin().GetConfig().IsAdmin() { diff --git a/server/server.go b/server/server.go index 6786443..f7686b3 100644 --- a/server/server.go +++ b/server/server.go @@ -37,6 +37,7 @@ func initRoutge(engine *gin.Engine) { apiGroup.POST("/staff/salary/pay", controller.NewSalary().Pay) apiGroup.POST("/salary/pay", controller.NewSalary().Pay) apiGroup.PUT("/staff/salary", controller.NewSalary().Update) + apiGroup.POST("/staff/salary/upload", controller.NewSalary().Upload) apiGroup.DELETE("/staff/salary", controller.NewSalary().Delete) noTokenGroup.GET("/staff/salary/bill", controller.NewSalary().Bill) diff --git a/server/service/staff_salary.go b/server/service/staff_salary.go index bffc9b2..87768a4 100644 --- a/server/service/staff_salary.go +++ b/server/service/staff_salary.go @@ -33,6 +33,32 @@ func NewStaffSalary() *StaffSalary { return &StaffSalary{} } +func (s *StaffSalary) Upload(ctx *gin.Context) interface{} { + + var err error + saveFile := "/tmp/" + fileName := "" + + file, _ := ctx.FormFile("file") + if file == nil { + panic(config.ErrParam.New().Append("未获取到文件信息")) + } + + // 保存本地临时文件 + fileName = time.Now().Format("20060102150405") + saveFile = "/tmp/" + fileName + err = ctx.SaveUploadedFile(file, saveFile) + if err != nil { + panic(config.ErrInternal.New().Append(err)) + } + + defer os.Remove(saveFile) + data := make(map[string]interface{}) + data["count"] = 10 + data["amount"] = "12.34" + return data +} + func (s *StaffSalary) List(sess *session.AdminSession, req *api.ListSalaryReq) (int64, interface{}, interface{}) { if !sess.GetAdmin().GetConfig().IsFinance() { return 0, nil, nil