This commit is contained in:
jiangyong27 2025-03-29 16:58:05 +08:00
parent 8d0669fc2f
commit b575e5e760
7 changed files with 116 additions and 38 deletions

View File

@ -1,11 +1,18 @@
package model
import "encoding/json"
import (
"encoding/json"
"github.com/spf13/cast"
"strings"
)
var (
StaffUserStatusOnline = 1 //在职
StaffUserStatusOffline = 2 //离职
StaffUserStatusAttach = 3 //挂靠
StaffUserRoleAdmin = 1 //管理员
StaffUserRoleFinance = 2 //财务
StaffUserRoleHr = 3 //人事
)
type UserSalary struct {
@ -25,6 +32,7 @@ type UserConfig struct {
HouseDeduct string `json:"house_deduct"` //公积金扣除
SalaryCalcutor string `json:"salary_calcutor"` //工资计算器
PerftTarget string `json:"perft_target"` //绩效目标
UserRole string `json:"user_role"` //员工角色
}
type StaffUser struct {
@ -63,3 +71,33 @@ func (u *StaffUser) GetPayee() *UserPayee {
json.Unmarshal([]byte(u.Payee), &salary)
return &salary
}
func (u *UserConfig) IsAdmin() bool {
arrs := strings.Split(u.UserRole, ",")
for _, a := range arrs {
if cast.ToInt(a) == StaffUserRoleAdmin {
return true
}
}
return false
}
func (u *UserConfig) IsFinance() bool {
arrs := strings.Split(u.UserRole, ",")
for _, a := range arrs {
if cast.ToInt(a) == StaffUserRoleFinance || cast.ToInt(a) == StaffUserRoleAdmin {
return true
}
}
return false
}
func (u *UserConfig) IsHr() bool {
arrs := strings.Split(u.UserRole, ",")
for _, a := range arrs {
if cast.ToInt(a) == StaffUserRoleHr || cast.ToInt(a) == StaffUserRoleAdmin {
return true
}
}
return false
}

View File

@ -1,6 +1,21 @@
{
"salary_latest": 9,
"staff_config": [
{
"name": "员工角色",
"key": "user_role",
"type": "checkbox",
"option": [{
"name": "管理员",
"value": "1"
},{
"name": "财务",
"value": "2"
},{
"name": "人事",
"value": "3"
}]
},
{
"name": "目标绩效",
"key": "perft_target"

View File

@ -2,7 +2,7 @@
"salary_latest": 14,
"staff_config": [
{
"name": "用户角色",
"name": "员工角色",
"key": "user_role",
"type": "checkbox",
"option": [{
@ -12,22 +12,10 @@
"name": "财务",
"value": "2"
},{
"name": "后勤",
"name": "人事",
"value": "3"
}]
},
{
"name": "性别",
"key": "user_sex",
"type": "radio",
"option": [{
"name": "男",
"value": "1"
},{
"name": "女",
"value": "2"
}]
},
{
"name": "目标绩效",
"key": "perft_target"

View File

@ -1,6 +1,7 @@
package controller
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/common/model"
"enterprise/server/api"
@ -25,6 +26,9 @@ func (c *Calculator) Create(ctx *gin.Context) {
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
if !sess.GetAdmin().GetConfig().IsAdmin() {
panic(config.ErrParam.New())
}
calculator := new(model.SalaryCalculator)
calculator.CorpId = sess.GetAdmin().CorpId
calculator.Name = req.Name
@ -36,9 +40,13 @@ func (c *Calculator) Create(ctx *gin.Context) {
// Update 更新已有的计算项
func (c *Calculator) Update(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
var req api.UpdateCalculatorReq
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
if !sess.GetAdmin().GetConfig().IsAdmin() {
panic(config.ErrParam.New())
}
calculator, err := dao.NewSalaryCalculatorDao().Get(cast.ToInt64(req.Id))
session.CheckDBError(err)
session.CheckNilError(calculator, "计算项不存在")
@ -53,6 +61,10 @@ func (c *Calculator) Update(ctx *gin.Context) {
// Delete 删除指定的计算项
func (c *Calculator) Delete(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if !sess.GetAdmin().GetConfig().IsAdmin() {
panic(config.ErrParam.New())
}
id := cast.ToInt64(ctx.Query("id"))
session.CheckDBError(dao.NewSalaryCalculatorDao().Delete(id))
ctx.JSON(http.StatusOK, session.NewRspOk())

View File

@ -1,6 +1,7 @@
package controller
import (
"enterprise/common/config"
"enterprise/server/api"
"enterprise/server/service"
"enterprise/server/session"
@ -17,6 +18,10 @@ func NewSalary() *Salary {
}
func (s *Salary) List(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetAdmin().GetConfig().IsFinance() {
panic(config.ErrPriv.New())
}
var req api.ListSalaryReq
session.CheckParamError(ctx.ShouldBind(&req))
total, summary, items := service.NewStaffSalary().List(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
@ -24,6 +29,10 @@ func (s *Salary) List(ctx *gin.Context) {
}
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
@ -32,6 +41,10 @@ func (s *Salary) Create(ctx *gin.Context) {
}
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
@ -40,6 +53,10 @@ func (s *Salary) Update(ctx *gin.Context) {
}
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
@ -48,6 +65,10 @@ func (s *Salary) Pay(ctx *gin.Context) {
}
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())

View File

@ -1,11 +1,11 @@
package controller
import (
"enterprise/common/config"
"enterprise/common/dao"
"enterprise/server/api"
"enterprise/server/service"
"enterprise/server/session"
"enterprise/worker"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"net/http"
@ -54,6 +54,10 @@ func (s *Staff) List(ctx *gin.Context) {
func (s *Staff) Create(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetAdmin().GetConfig().IsHr() {
panic(config.ErrPriv.New())
}
var req api.StaffCreateReq
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
@ -61,18 +65,13 @@ func (s *Staff) Create(ctx *gin.Context) {
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *Staff) Pay(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
var req api.StaffPayReq
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
service.NewStaffUser().Pay(sess, &req)
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *Staff) Update(ctx *gin.Context) {
var req api.StaffUpdateReq
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetAdmin().GetConfig().IsHr() {
panic(config.ErrPriv.New())
}
var req api.StaffUpdateReq
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
service.NewStaffUser().Update(sess, &req)
@ -80,15 +79,30 @@ func (s *Staff) Update(ctx *gin.Context) {
}
func (s *Staff) Delete(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetAdmin().GetConfig().IsHr() {
panic(config.ErrPriv.New())
}
id := cast.ToInt64(ctx.Query("id"))
session.CheckDBError(dao.NewStaffUserDao().Delete(id))
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *Staff) Salary(ctx *gin.Context) {
func (s *Staff) Pay(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
if sess.GetAdmin().GetConfig().IsFinance() {
panic(config.ErrPriv.New())
}
var req api.StaffPayReq
session.CheckParamError(ctx.ShouldBindJSON(&req))
ctx.Keys[session.ContextRequest] = req
service.NewStaffUser().Pay(sess, &req)
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (s *Staff) Salary(ctx *gin.Context) {
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
month := ctx.Query("month")
tp := ctx.Query("type")
@ -113,12 +127,3 @@ func (s *Staff) Salary(ctx *gin.Context) {
serv.Summary(corp.Id, month, ctx)
}
}
func (s *Staff) SyncStaffSalary(ctx *gin.Context) {
corpId := cast.ToInt64(ctx.Query("cid"))
if corpId == 0 {
corpId = 1000
}
go new(worker.Staff).SyncStaffSalary(corpId, "")
ctx.JSON(http.StatusOK, session.NewRspOk())
}

View File

@ -29,7 +29,6 @@ func initRoutge(engine *gin.Engine) {
apiGroup.Any("/checkin/sync", controller.NewStaffCheckin().Sync)
group.GET("/staff/salary", controller.NewStaff().Salary)
group.GET("/staff/sync/salary", controller.NewStaff().SyncStaffSalary)
noTokenGroup.POST("/staff/login", controller.NewStaff().Login)
apiGroup.GET("/staff/salary", controller.NewSalary().List)