101 lines
3.0 KiB
Go
101 lines
3.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"enterprise/common/config"
|
|
"enterprise/common/dao"
|
|
"enterprise/common/model"
|
|
"enterprise/server/api"
|
|
"enterprise/server/service"
|
|
"enterprise/server/session"
|
|
"enterprise/worker"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/smbrave/goutil"
|
|
"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().IsAdmin() {
|
|
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())
|
|
}
|
|
|
|
func (s *Salary) SyncStaffSalary(ctx *gin.Context) {
|
|
cid := cast.ToInt64(ctx.Query("cid"))
|
|
var err error
|
|
var corp *model.Corp
|
|
if cid != 0 {
|
|
corp, err = dao.NewCorpDao().Get(cid)
|
|
session.CheckDBError(err)
|
|
} else {
|
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
|
corp, err = dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
|
session.CheckDBError(err)
|
|
}
|
|
|
|
session.CheckNilError(corp, "域名未绑定")
|
|
go new(worker.Staff).SyncStaffSalary(corp.Id, "")
|
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
|
}
|
|
|
|
func (s *Salary) Bill(ctx *gin.Context) {
|
|
id := ctx.Query("id")
|
|
realId := goutil.DecryptID(id, "@@salary@@")
|
|
service.NewStaffSalary().Bill(realId, ctx)
|
|
}
|