calc test

This commit is contained in:
jiangyong27 2025-03-26 20:22:25 +08:00
parent 259b212030
commit 1f56a9fbec
8 changed files with 73 additions and 0 deletions

View File

@ -8,6 +8,11 @@ import (
"strings"
)
var (
StaffSalaryStatusWait = 1
StaffSalaryStatusPayed = 2
)
type StaffSalary struct {
Id int64
CorpId int64
@ -30,6 +35,7 @@ type StaffSalary struct {
UpdateTime int64
Extra string
Comment string
Status int
}
func (s *StaffSalary) GetShouldSalary() float64 {

View File

@ -25,6 +25,11 @@ type CreateCalculatorReq struct {
Expression string `json:"expression"`
}
type TestCalculatorReq struct {
StaffId string `json:"staff_id"`
Expression string `json:"expression"`
}
type UpdateCalculatorReq struct {
Id string `json:"id"`
Name string `json:"name"`

View File

@ -40,6 +40,7 @@ type UpdateSalaryReq struct {
OtherIncome string `json:"other_income"`
OtherDeduct string `json:"other_deduct"`
PersonalDeduct string `json:"personal_deduct"`
Status string `json:"status"`
}
type ListSalaryReq struct {

View File

@ -4,6 +4,7 @@ import (
"enterprise/common/dao"
"enterprise/common/model"
"enterprise/server/api"
"enterprise/server/service"
"enterprise/server/session"
"github.com/gin-gonic/gin"
"github.com/smbrave/goutil"
@ -75,3 +76,11 @@ func (c *Calculator) List(ctx *gin.Context) {
ctx.JSON(http.StatusOK, session.NewListRsp(total, items))
}
// Delete 删除指定的计算项
func (c *Calculator) Test(ctx *gin.Context) {
var req api.TestCalculatorReq
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
data := service.NewCalculator().Test(sess, &req)
ctx.JSON(http.StatusOK, session.NewRsp(data))
}

View File

@ -44,6 +44,7 @@ func initRoutge(engine *gin.Engine) {
apiGroup.GET("/staff", controller.NewStaff().List)
apiGroup.GET("/calculator", controller.NewCalculator().List)
apiGroup.POST("/calculator", controller.NewCalculator().Create)
apiGroup.POST("/calculator/test", controller.NewCalculator().Test)
apiGroup.PUT("/calculator", controller.NewCalculator().Update)
apiGroup.DELETE("/calculator", controller.NewCalculator().Delete)

View File

@ -0,0 +1,42 @@
package service
import (
"enterprise/common/dao"
"enterprise/server/api"
"enterprise/server/session"
CommonService "enterprise/service"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
"time"
)
type Calculator struct {
}
func NewCalculator() *Calculator {
return &Calculator{}
}
func (c *Calculator) Test(sess *session.AdminSession, req *api.TestCalculatorReq) interface{} {
staffUser, err := dao.NewStaffUserDao().Get(cast.ToInt64(req.StaffId))
session.CheckDBError(err)
session.CheckNilError(staffUser, "员工不存在")
salaryServ := CommonService.NewStaffSalary(staffUser)
salary, err := salaryServ.CalcSalary(nil, time.Now().AddDate(0, -1, 0).Format("200601"))
if err != nil {
log.Errorf("CalcSalary error :%s", err.Error())
panic(err.Error())
}
if salary == nil {
panic("没有工资")
}
apiSalary := new(api.Salary)
apiSalary.From(salary)
userSalary := staffUser.GetSalary()
apiSalary.Realname = staffUser.Realname
apiSalary.TargetSalary = userSalary.Target
apiSalary.BaseSalary = userSalary.Base
return apiSalary
}

View File

@ -116,6 +116,9 @@ func (s *StaffSalary) Update(sess *session.AdminSession, req *api.UpdateSalaryRe
if req.PersonalDeduct != "" {
salary.PersonalDeduct = cast.ToFloat64(req.PersonalDeduct)
}
if req.Status != "" {
salary.Status = cast.ToInt(req.Status)
}
err = dao.NewStaffSalaryDao().Update(salary)
session.CheckDBError(err)
}

View File

@ -60,7 +60,13 @@ func (s *StaffSalary) CalcSalary(salary *model.StaffSalary, month string) (*mode
salary.CorpId = s.user.CorpId
salary.UserId = s.user.Id
salary.Username = s.user.Username
salary.Status = model.StaffSalaryStatusWait
}
//已支付过的工资不能再计算了
if salary != nil && salary.Status == model.StaffSalaryStatusPayed {
return salary, nil
}
//社保和公积金
salary.SocialDeduct = 0
salary.HouseDeduct = 0