salary
This commit is contained in:
parent
d9da0951b5
commit
014917b6ce
|
@ -67,18 +67,13 @@ func (d *StaffSalaryDao) GetBy(corpId, userId int64, month string) (*model.Staff
|
|||
return &u, nil
|
||||
}
|
||||
|
||||
func (d *StaffSalaryDao) Query(corpId, userId int64, month string) ([]*model.StaffSalary, error) {
|
||||
func (d *StaffSalaryDao) QueryAll(corpId int64, month string) ([]*model.StaffSalary, error) {
|
||||
var u []*model.StaffSalary
|
||||
tx := GetDB().Table(d.TableName())
|
||||
|
||||
tx.Where("corp_id = ?", corpId)
|
||||
|
||||
if month != "" {
|
||||
tx = tx.Where("month = ?", month)
|
||||
}
|
||||
if userId != 0 {
|
||||
tx.Where("user_id = ?", userId)
|
||||
}
|
||||
|
||||
tx.Order("month DESC")
|
||||
|
||||
|
@ -92,3 +87,30 @@ func (d *StaffSalaryDao) Query(corpId, userId int64, month string) ([]*model.Sta
|
|||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (d *StaffSalaryDao) QueryAdmin(page, size int, corpId int64, username string, startMonth, endMonth string) ([]*model.StaffSalary, int64, error) {
|
||||
var u []*model.StaffSalary
|
||||
tx := GetDB().Table(d.TableName())
|
||||
tx.Where("corp_id = ?", corpId)
|
||||
if startMonth != "" {
|
||||
tx.Where("month >= ?", startMonth)
|
||||
}
|
||||
if endMonth != "" {
|
||||
tx.Where("month <= ?", endMonth)
|
||||
}
|
||||
if username != "" {
|
||||
tx.Where("username = ?", username)
|
||||
}
|
||||
|
||||
var count int64
|
||||
tx.Count(&count)
|
||||
tx.Order("month DESC")
|
||||
|
||||
tx.Offset((page - 1) * size).Limit(size)
|
||||
res := tx.Find(&u)
|
||||
|
||||
if res.Error != nil {
|
||||
return nil, 0, res.Error
|
||||
}
|
||||
return u, count, nil
|
||||
}
|
||||
|
|
12
go.mod
12
go.mod
|
@ -1,6 +1,8 @@
|
|||
module enterprise
|
||||
|
||||
go 1.21.6
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.23.2
|
||||
|
||||
require (
|
||||
git.u8t.cn/open/gosdk v0.0.0-20250309163531-2f47649d3dbd
|
||||
|
@ -16,13 +18,13 @@ require (
|
|||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/smartwalle/alipay/v3 v3.2.23
|
||||
github.com/smbrave/goutil v0.0.0-20240724121721-dd5a9ae0b015
|
||||
github.com/smbrave/goutil v0.0.0-20250312151244-845a8a40e8aa
|
||||
github.com/spf13/cast v1.7.0
|
||||
github.com/spf13/viper v1.19.0
|
||||
github.com/xuri/excelize/v2 v2.8.1
|
||||
golang.org/x/crypto v0.26.0
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
gorm.io/gorm v1.25.11
|
||||
gorm.io/gorm v1.25.12
|
||||
)
|
||||
|
||||
require (
|
||||
|
@ -90,8 +92,8 @@ require (
|
|||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sys v0.23.0 // indirect
|
||||
golang.org/x/text v0.17.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
google.golang.org/protobuf v1.34.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"enterprise/common/model"
|
||||
"github.com/smbrave/goutil"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Salary struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Month string `json:"month,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Realname string `json:"realname,omitempty"`
|
||||
SalaryBase string `json:"salary_base,omitempty"`
|
||||
SalaryTarget string `json:"salary_target,omitempty"`
|
||||
AttendSalary string `json:"attend_salary,omitempty"`
|
||||
TargetSalary string `json:"target_salary,omitempty"`
|
||||
AwardSalary string `json:"award_salary,omitempty"`
|
||||
OtherSalary string `json:"other_salary,omitempty"`
|
||||
ShouldDay string `json:"should_day,omitempty"`
|
||||
AttendDay string `json:"attend_day,omitempty"`
|
||||
HolidayDay string `json:"holiday_day,omitempty"`
|
||||
SocialDeduct string `json:"social_deduct,omitempty"`
|
||||
HouseDeduct string `json:"house_deduct,omitempty"`
|
||||
PersonalDeduct string `json:"personal_deduct,omitempty"`
|
||||
OtherDeduct string `json:"other_deduct,omitempty"`
|
||||
CreateTime string `json:"create_time,omitempty"`
|
||||
UpdateTime string `json:"update_time,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSalaryReq struct {
|
||||
Month string `json:"month"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type UpdateSalaryReq struct {
|
||||
Id string `json:"month"`
|
||||
OtherSalary string `json:"other_salary"`
|
||||
OtherDeduct string `json:"other_deduct"`
|
||||
}
|
||||
|
||||
type ListSalaryReq struct {
|
||||
BaseRequest
|
||||
StartMonth string `form:"start_month"`
|
||||
EndMonth string `form:"end_month"`
|
||||
Username string `form:"username"`
|
||||
}
|
||||
|
||||
func (s *Salary) From(m *model.StaffSalary) {
|
||||
s.Id = cast.ToString(m.Id)
|
||||
s.Username = m.Username
|
||||
s.Month = m.Month
|
||||
s.AttendSalary = goutil.FormatFloat(m.AttendSalary)
|
||||
s.TargetSalary = goutil.FormatFloat(m.TargetSalary)
|
||||
s.AwardSalary = goutil.FormatFloat(m.AwardSalary)
|
||||
s.OtherSalary = goutil.FormatFloat(m.OtherSalary)
|
||||
s.ShouldDay = cast.ToString(m.ShouldDay)
|
||||
s.AttendDay = goutil.FormatFloat(m.AttendDay)
|
||||
s.HolidayDay = goutil.FormatFloat(m.HolidayDay)
|
||||
s.SocialDeduct = goutil.FormatFloat(m.SocialDeduct)
|
||||
s.HouseDeduct = goutil.FormatFloat(m.HouseDeduct)
|
||||
s.PersonalDeduct = goutil.FormatFloat(m.PersonalDeduct)
|
||||
s.OtherDeduct = goutil.FormatFloat(m.OtherDeduct)
|
||||
s.CreateTime = goutil.TimeToDateTime(m.CreateTime)
|
||||
s.UpdateTime = goutil.TimeToDateTime(m.UpdateTime)
|
||||
}
|
||||
|
||||
func (s *Salary) Add(o *Salary) {
|
||||
s.SalaryTarget = goutil.FormatFloat(cast.ToFloat64(s.SalaryTarget) + cast.ToFloat64(o.SalaryTarget))
|
||||
s.SalaryBase = goutil.FormatFloat(cast.ToFloat64(s.SalaryBase) + cast.ToFloat64(o.SalaryBase))
|
||||
s.AttendSalary = goutil.FormatFloat(cast.ToFloat64(s.AttendSalary) + cast.ToFloat64(o.AttendSalary))
|
||||
s.TargetSalary = goutil.FormatFloat(cast.ToFloat64(s.TargetSalary) + cast.ToFloat64(o.TargetSalary))
|
||||
s.AwardSalary = goutil.FormatFloat(cast.ToFloat64(s.AwardSalary) + cast.ToFloat64(o.AwardSalary))
|
||||
s.OtherSalary = goutil.FormatFloat(cast.ToFloat64(s.OtherSalary) + cast.ToFloat64(o.OtherSalary))
|
||||
s.ShouldDay = cast.ToString(cast.ToInt(s.ShouldDay) + cast.ToInt(o.ShouldDay))
|
||||
s.AttendDay = goutil.FormatFloat(cast.ToFloat64(s.AttendDay) + cast.ToFloat64(o.AttendDay))
|
||||
s.HolidayDay = goutil.FormatFloat(cast.ToFloat64(s.HolidayDay) + cast.ToFloat64(o.HolidayDay))
|
||||
s.SocialDeduct = goutil.FormatFloat(cast.ToFloat64(s.SocialDeduct) + cast.ToFloat64(o.SocialDeduct))
|
||||
s.HouseDeduct = goutil.FormatFloat(cast.ToFloat64(s.HouseDeduct) + cast.ToFloat64(o.HouseDeduct))
|
||||
s.PersonalDeduct = goutil.FormatFloat(cast.ToFloat64(s.PersonalDeduct) + cast.ToFloat64(o.PersonalDeduct))
|
||||
s.OtherDeduct = goutil.FormatFloat(cast.ToFloat64(s.OtherDeduct) + cast.ToFloat64(o.OtherDeduct))
|
||||
|
||||
}
|
|
@ -1 +1,45 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
"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) {
|
||||
var req api.ListSalaryReq
|
||||
session.CheckParamError(ctx.ShouldBind(&req))
|
||||
total, summary, items := service.NewStaffSalary().List(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
||||
ctx.JSON(http.StatusOK, session.NewSummaryRsp(total, summary, items))
|
||||
}
|
||||
|
||||
func (s *Salary) Create(ctx *gin.Context) {
|
||||
var req api.CreateSalaryReq
|
||||
session.CheckParamError(ctx.ShouldBind(&req))
|
||||
service.NewStaffSalary().Create(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (s *Salary) Update(ctx *gin.Context) {
|
||||
var req api.UpdateSalaryReq
|
||||
session.CheckParamError(ctx.ShouldBind(&req))
|
||||
service.NewStaffSalary().Update(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (s *Salary) Delete(ctx *gin.Context) {
|
||||
id := cast.ToInt64(ctx.Query("id"))
|
||||
dao.NewStaffSalaryDao().Delete(id)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ func initRoutge(engine *gin.Engine) {
|
|||
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)
|
||||
apiGroup.POST("/staff/salary", controller.NewSalary().Create)
|
||||
apiGroup.PUT("/staff/salary", controller.NewSalary().Update)
|
||||
apiGroup.DELETE("/staff/salary", controller.NewSalary().Delete)
|
||||
|
||||
apiGroup.GET("/staff/suggest", controller.NewStaff().Suggest)
|
||||
apiGroup.POST("/staff", controller.NewStaff().Create)
|
||||
apiGroup.PUT("/staff", controller.NewStaff().Update)
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"enterprise/common/config"
|
||||
"enterprise/common/dao"
|
||||
"enterprise/common/model"
|
||||
"enterprise/server/api"
|
||||
"enterprise/server/session"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -26,9 +28,60 @@ var (
|
|||
type StaffSalary struct {
|
||||
}
|
||||
|
||||
func NewStaffSalary() *StaffSalary {
|
||||
return &StaffSalary{}
|
||||
}
|
||||
|
||||
func (s *StaffSalary) List(sess *session.AdminSession, req *api.ListSalaryReq) (int64, interface{}, interface{}) {
|
||||
salarys, total, err := dao.NewStaffSalaryDao().QueryAdmin(1, -1, sess.GetCorpId(), req.Username, req.StartMonth, req.EndMonth)
|
||||
session.CheckDBError(err)
|
||||
start := (req.Page - 1) * req.Size
|
||||
end := start + req.Size
|
||||
|
||||
items := make([]*api.Salary, 0)
|
||||
summary := new(api.Salary)
|
||||
for pos, m := range salarys {
|
||||
staffSalary := new(api.Salary)
|
||||
staffSalary.From(m)
|
||||
summary.Add(staffSalary)
|
||||
if pos < start || pos >= end {
|
||||
continue
|
||||
}
|
||||
staffUser, err := dao.NewStaffUserDao().Get(m.UserId)
|
||||
session.CheckDBError(err)
|
||||
if staffUser != nil {
|
||||
userSalary := staffUser.GetSalary()
|
||||
staffSalary.Realname = staffUser.Realname
|
||||
staffSalary.SalaryTarget = userSalary.Target
|
||||
staffSalary.SalaryBase = userSalary.Base
|
||||
}
|
||||
items = append(items, staffSalary)
|
||||
}
|
||||
|
||||
return total, summary, items
|
||||
}
|
||||
|
||||
func (s *StaffSalary) Create(sess *session.AdminSession, req *api.CreateSalaryReq) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *StaffSalary) Update(sess *session.AdminSession, req *api.UpdateSalaryReq) {
|
||||
salary, err := dao.NewStaffSalaryDao().Get(cast.ToInt64(req.Id))
|
||||
session.CheckDBError(err)
|
||||
session.CheckNilError(salary, "工资单不存在")
|
||||
if req.OtherSalary != "" {
|
||||
salary.OtherSalary = cast.ToFloat64(req.OtherSalary)
|
||||
}
|
||||
if req.OtherDeduct != "" {
|
||||
salary.OtherDeduct = cast.ToFloat64(req.OtherDeduct)
|
||||
}
|
||||
err = dao.NewStaffSalaryDao().Update(salary)
|
||||
session.CheckDBError(err)
|
||||
}
|
||||
|
||||
func (s *StaffSalary) Agent(cid int64, month string, ctx *gin.Context) {
|
||||
xls := ctx.Query("xls")
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(cid, 0, month)
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(cid, month)
|
||||
if err != nil {
|
||||
panic(config.ErrDb.New().Append(err))
|
||||
}
|
||||
|
@ -91,7 +144,7 @@ func (s *StaffSalary) Agent(cid int64, month string, ctx *gin.Context) {
|
|||
|
||||
func (s *StaffSalary) Bank(cid int64, month string, ctx *gin.Context) {
|
||||
xls := ctx.Query("xls")
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(cid, 0, month)
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(cid, month)
|
||||
if err != nil {
|
||||
panic(config.ErrDb.New().Append(err))
|
||||
}
|
||||
|
@ -152,7 +205,7 @@ func (s *StaffSalary) Bank(cid int64, month string, ctx *gin.Context) {
|
|||
|
||||
func (s *StaffSalary) Summary(cid int64, month string, ctx *gin.Context) {
|
||||
xls := ctx.Query("xls")
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(cid, 0, month)
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(cid, month)
|
||||
if err != nil {
|
||||
panic(config.ErrDb.New().Append(err))
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package session
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/smbrave/goutil"
|
||||
)
|
||||
|
||||
type BaseResponse struct {
|
||||
|
@ -25,6 +26,7 @@ type ListResponse struct {
|
|||
Total int64 `json:"total"`
|
||||
TotalAmount string `json:"totalAmount,omitempty"`
|
||||
Items interface{} `json:"items"`
|
||||
Summary interface{} `json:"summary,omitempty"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -64,6 +66,32 @@ func NewListRsp(total int64, items interface{}) *ListResponse {
|
|||
return rsp
|
||||
}
|
||||
|
||||
func NewSummaryRsp(total int64, summary interface{}, items interface{}) *ListResponse {
|
||||
rsp := &ListResponse{
|
||||
BaseResponse: BaseResponse{
|
||||
Code: rspOk.Code,
|
||||
Message: rspOk.Message,
|
||||
},
|
||||
}
|
||||
rsp.Data.Total = total
|
||||
rsp.Data.Items = items
|
||||
rsp.Data.Summary = summary
|
||||
return rsp
|
||||
}
|
||||
|
||||
func NewListAmountRsp(total int64, totalAmount int64, items interface{}) *ListResponse {
|
||||
rsp := &ListResponse{
|
||||
BaseResponse: BaseResponse{
|
||||
Code: rspOk.Code,
|
||||
Message: rspOk.Message,
|
||||
},
|
||||
}
|
||||
rsp.Data.Total = total
|
||||
rsp.Data.TotalAmount = goutil.FormatMoney(totalAmount)
|
||||
rsp.Data.Items = items
|
||||
return rsp
|
||||
}
|
||||
|
||||
func NewRsp(data interface{}) *CommonResponse {
|
||||
return &CommonResponse{
|
||||
BaseResponse: BaseResponse{
|
||||
|
|
|
@ -72,7 +72,7 @@ func (s *Staff) MontorWorkAge(corpId int64) {
|
|||
}
|
||||
|
||||
func (s *Staff) SendStaffSalaryBill(corpId int64, month string) {
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().Query(corpId, 0, month)
|
||||
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(corpId, month)
|
||||
if err != nil {
|
||||
log.Errorf("db error :%s", err.Error())
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue