73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"enterprise/common/config"
|
|
"enterprise/server/api"
|
|
"enterprise/server/service"
|
|
"enterprise/server/session"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/cast"
|
|
"net/http"
|
|
)
|
|
|
|
type Salary struct {
|
|
}
|
|
|
|
func NewSalary() *Salary {
|
|
return &Salary{}
|
|
}
|
|
|
|
func (s *Salary) List(ctx *gin.Context) {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
var req api.ListSalaryReq
|
|
session.CheckParamError(ctx.ShouldBind(&req))
|
|
total, summary, items := service.NewStaffSalary().List(sess, &req)
|
|
ctx.JSON(http.StatusOK, session.NewSummaryRsp(total, summary, items))
|
|
}
|
|
|
|
func (s *Salary) Create(ctx *gin.Context) {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
if !sess.GetAdmin().GetConfig().IsFinance() {
|
|
panic(config.ErrPriv.New())
|
|
}
|
|
var req api.CreateSalaryReq
|
|
session.CheckParamError(ctx.ShouldBind(&req))
|
|
ctx.Keys[session.ContextRequest] = req
|
|
service.NewStaffSalary().Create(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
|
}
|
|
|
|
func (s *Salary) Update(ctx *gin.Context) {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
if !sess.GetAdmin().GetConfig().IsFinance() {
|
|
panic(config.ErrPriv.New())
|
|
}
|
|
var req api.UpdateSalaryReq
|
|
session.CheckParamError(ctx.ShouldBind(&req))
|
|
ctx.Keys[session.ContextRequest] = req
|
|
service.NewStaffSalary().Update(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
|
}
|
|
|
|
func (s *Salary) Pay(ctx *gin.Context) {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
if !sess.GetAdmin().GetConfig().IsFinance() {
|
|
panic(config.ErrPriv.New())
|
|
}
|
|
var req api.PaySalaryReq
|
|
session.CheckParamError(ctx.ShouldBind(&req))
|
|
ctx.Keys[session.ContextRequest] = req
|
|
service.NewStaffSalary().Pay(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
|
}
|
|
|
|
func (s *Salary) Delete(ctx *gin.Context) {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
if !sess.GetAdmin().GetConfig().IsFinance() {
|
|
panic(config.ErrPriv.New())
|
|
}
|
|
id := cast.ToInt64(ctx.Query("id"))
|
|
service.NewStaffSalary().Delete(ctx.Keys[session.ContextSession].(*session.AdminSession), id)
|
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
|
}
|