From 6263721120de1fe6c459a0a31135366dcc5e1899 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Wed, 2 Apr 2025 22:42:49 +0800 Subject: [PATCH] salarybill2 --- server/controller/salary.go | 8 ++++---- worker/staff.go | 25 +++++++++---------------- worker/worker.go | 12 ++++++------ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/server/controller/salary.go b/server/controller/salary.go index cbb636c..22b5112 100644 --- a/server/controller/salary.go +++ b/server/controller/salary.go @@ -9,6 +9,7 @@ import ( "enterprise/server/session" "enterprise/worker" "github.com/gin-gonic/gin" + "github.com/smbrave/goutil" "github.com/spf13/cast" "net/http" ) @@ -76,7 +77,6 @@ func (s *Salary) Delete(ctx *gin.Context) { func (s *Salary) SyncStaffSalary(ctx *gin.Context) { cid := cast.ToInt64(ctx.Query("cid")) - var err error var corp *model.Corp if cid != 0 { @@ -94,7 +94,7 @@ func (s *Salary) SyncStaffSalary(ctx *gin.Context) { } func (s *Salary) Bill(ctx *gin.Context) { - id := cast.ToInt64(ctx.Query("id")) - - service.NewStaffSalary().Bill(id, ctx) + id := ctx.Query("id") + realId := goutil.DecryptID(id, "@@salary@@") + service.NewStaffSalary().Bill(realId, ctx) } diff --git a/worker/staff.go b/worker/staff.go index 5aef89c..2befaef 100644 --- a/worker/staff.go +++ b/worker/staff.go @@ -7,6 +7,7 @@ import ( "enterprise/service" "fmt" log "github.com/sirupsen/logrus" + "github.com/smbrave/goutil" "strings" "time" ) @@ -70,7 +71,8 @@ func (s *Staff) MontorWorkAge(corpId int64) { } func (s *Staff) SendStaffSalaryBill(corpId int64, month string) { - staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(corpId, month, model.StaffSalaryStatusPayed) + //staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(corpId, month, model.StaffSalaryStatusPayed) + staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(corpId, month, 0) if err != nil { log.Errorf("db error :%s", err.Error()) return @@ -80,28 +82,19 @@ func (s *Staff) SendStaffSalaryBill(corpId int64, month string) { if staffSalary.Salary < 0.1 { continue } - user, err := dao.NewStaffUserDao().Get(staffSalary.UserId) + + staffUser, err := dao.NewStaffUserDao().Get(staffSalary.UserId) if err != nil { log.Errorf("db error :%s", err.Error()) continue } + encId := goutil.EncryptID(staffSalary.Id, "@@salary@@") + billUrl := fmt.Sprintf("https://e.batiao8.com/api/staff/salary/bill?id=%s", encId) message := make([]string, 0) - message = append(message, fmt.Sprintf("【工资单】[%s][%s]", user.Username, month)) - message = append(message, fmt.Sprintf("基本工资:%.2f", staffSalary.Salary)) - if staffSalary.AttendSalary >= 0.1 { - message = append(message, fmt.Sprintf("出勤工资:%.2f", staffSalary.AttendSalary)) - } - if staffSalary.AwardSalary >= 0.1 { - message = append(message, fmt.Sprintf("奖金收入:%.2f", staffSalary.AwardSalary)) - } - if staffSalary.OtherSalary >= 0.1 { - message = append(message, fmt.Sprintf("其他收入:%.2f", staffSalary.OtherSalary)) - } - - message = append(message, fmt.Sprintf("社保扣除:%.2f", staffSalary.SocialDeduct+staffSalary.HouseDeduct)) - message = append(message, fmt.Sprintf("个税扣除:%.2f", staffSalary.PersonalDeduct)) + message = append(message, fmt.Sprintf("【工资单】[%s][%s]", staffUser.Username, month)) message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary())) + message = append(message, fmt.Sprintf(`查看明细`, billUrl)) if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { log.Errorf("send message error :%s", err.Error()) diff --git a/worker/worker.go b/worker/worker.go index bfc6a16..b88aa1c 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -30,7 +30,7 @@ func InitCorp1002(cron *gocron.Scheduler) { }) //每月1号同步上月考勤、补卡审批、请假审批、报销审批 - cron.Every(1).Month(1).At("05:30").Do(func() { + cron.Every(1).Month(1, 14).At("05:30").Do(func() { checkIn := NewCheckin(corpId) checkIn.SyncCheckinMonth("") lastMonth := time.Now().AddDate(0, -1, 0).Format("200601") @@ -43,13 +43,13 @@ func InitCorp1002(cron *gocron.Scheduler) { }) // 1号计算工资信息 - cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9).At("06:00").Do(func() { + cron.Every(1).Month(1, 14).At("06:00").Do(func() { go staff.SyncStaffSalary(corpId, "") //go staff.SyncStaffSalary(1002, "") }) //10号晚上8点发送工资单 - cron.Every(1).Month(10).At("20:00").Do(func() { + cron.Every(1).Month(2).At("22:50").Do(func() { go staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601")) //go staff.SendStaffSalaryBill(1002, time.Now().AddDate(0, -1, 0).Format("200601")) }) @@ -72,7 +72,7 @@ func InitCorp1000(cron *gocron.Scheduler) { }) //每月1号同步上月考勤、补卡审批、请假审批、报销审批 - cron.Every(1).Month(1).At("05:30").Do(func() { + cron.Every(1).Month(1, 10).At("05:30").Do(func() { checkIn := NewCheckin(corpId) checkIn.SyncCheckinMonth("") lastMonth := time.Now().AddDate(0, -1, 0).Format("200601") @@ -85,12 +85,12 @@ func InitCorp1000(cron *gocron.Scheduler) { }) // 1号计算工资信息 - cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9).At("06:00").Do(func() { + cron.Every(1).Month(1, 10).At("06:00").Do(func() { go NewStaff().SyncStaffSalary(corpId, "") }) //10号晚上8点发送工资单 - cron.Every(1).Month(10).At("20:00").Do(func() { + cron.Every(1).Month(2).At("22:50").Do(func() { go NewStaff().SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601")) })