salary read
This commit is contained in:
parent
25c9ba1649
commit
78429cfd9c
|
@ -27,6 +27,7 @@ type CorpConfig struct {
|
||||||
SocialDeduct string `json:"social_deduct"`
|
SocialDeduct string `json:"social_deduct"`
|
||||||
HouseDeduct string `json:"house_deduct"`
|
HouseDeduct string `json:"house_deduct"`
|
||||||
WorkerHour string `json:"worker_hour"`
|
WorkerHour string `json:"worker_hour"`
|
||||||
|
SalaryDay string `json:"salary_day"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Corp struct {
|
type Corp struct {
|
||||||
|
|
|
@ -47,6 +47,7 @@ type StaffSalary struct {
|
||||||
OtherDeduct float64
|
OtherDeduct float64
|
||||||
CreateTime int64
|
CreateTime int64
|
||||||
UpdateTime int64
|
UpdateTime int64
|
||||||
|
ReadTime int64
|
||||||
Extra string
|
Extra string
|
||||||
Comment string
|
Comment string
|
||||||
Status int
|
Status int
|
||||||
|
@ -67,9 +68,14 @@ func (s *StaffSalary) SetExtra(key string, value interface{}) {
|
||||||
s.Extra = goutil.EncodeJSON(extra)
|
s.Extra = goutil.EncodeJSON(extra)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) GetBillUrl() string {
|
func (s *StaffSalary) GetBillUrl(test bool) string {
|
||||||
encId := goutil.EncryptID(s.Id, "@@salary@@")
|
encId := goutil.EncryptID(s.Id, "@@salary@@")
|
||||||
billUrl := fmt.Sprintf("https://e.yubanqy.com/api/staff/salary/bill?id=%s", encId)
|
var billUrl string
|
||||||
|
if test {
|
||||||
|
billUrl = fmt.Sprintf("https://e.yubanqy.com/api/staff/salary/bill?id=%s&test=true", encId)
|
||||||
|
} else {
|
||||||
|
billUrl = fmt.Sprintf("https://e.yubanqy.com/api/staff/salary/bill?id=%s", encId)
|
||||||
|
}
|
||||||
return billUrl
|
return billUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ func (s *Salary) SyncStaffSalary(ctx *gin.Context) {
|
||||||
|
|
||||||
func (s *Salary) Bill(ctx *gin.Context) {
|
func (s *Salary) Bill(ctx *gin.Context) {
|
||||||
id := ctx.Query("id")
|
id := ctx.Query("id")
|
||||||
|
test := ctx.Query("test")
|
||||||
realId := goutil.DecryptID(id, "@@salary@@")
|
realId := goutil.DecryptID(id, "@@salary@@")
|
||||||
service.NewStaffSalary().Bill(realId, ctx)
|
service.NewStaffSalary().Bill(realId, test, ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,9 +70,14 @@ func (s *StaffSalary) List(sess *session.AdminSession, req *api.ListSalaryReq) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) Create(sess *session.AdminSession, req *api.CreateSalaryReq) {
|
func (s *StaffSalary) Create(sess *session.AdminSession, req *api.CreateSalaryReq) {
|
||||||
|
corp, err := dao.NewCorpDao().Get(sess.GetCorpId())
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(corp, "企业不存在")
|
||||||
|
|
||||||
users, _, err := dao.NewStaffUserDao().Query(1, -1, sess.GetCorpId(), 0, req.Username, "", "", "")
|
users, _, err := dao.NewStaffUserDao().Query(1, -1, sess.GetCorpId(), 0, req.Username, "", "", "")
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
salaryLast := cast.ToInt(config.GetCorpConfig(sess.GetCorpId(), "salary_latest", 31))
|
|
||||||
|
salaryLast := cast.ToInt(corp.GetConfig().SalaryDay)
|
||||||
|
|
||||||
lastMonth := cast.ToInt(time.Now().AddDate(0, 0, -time.Now().Day()).Format("200601"))
|
lastMonth := cast.ToInt(time.Now().AddDate(0, 0, -time.Now().Day()).Format("200601"))
|
||||||
if cast.ToInt(req.Month) < lastMonth ||
|
if cast.ToInt(req.Month) < lastMonth ||
|
||||||
|
@ -437,7 +442,7 @@ func (s *StaffSalary) toExcel(filePath string, header []string, datas [][]string
|
||||||
ctx.File(filePath)
|
ctx.File(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) Bill(id int64, ctx *gin.Context) {
|
func (s *StaffSalary) Bill(id int64, test bool, ctx *gin.Context) {
|
||||||
|
|
||||||
salary, err := dao.NewStaffSalaryDao().Get(id)
|
salary, err := dao.NewStaffSalaryDao().Get(id)
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
|
@ -449,6 +454,11 @@ func (s *StaffSalary) Bill(id int64, ctx *gin.Context) {
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
session.CheckNilError(user, "用户不存在")
|
session.CheckNilError(user, "用户不存在")
|
||||||
|
|
||||||
|
if !test && salary.ReadTime == 0 {
|
||||||
|
salary.ReadTime = time.Now().Unix()
|
||||||
|
dao.NewStaffSalaryDao().Update(salary)
|
||||||
|
}
|
||||||
|
|
||||||
datas := make([]*model.SalaryBillSection, 0)
|
datas := make([]*model.SalaryBillSection, 0)
|
||||||
|
|
||||||
baseDetail := make([]*model.SalaryBillLine, 0)
|
baseDetail := make([]*model.SalaryBillLine, 0)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"enterprise/service"
|
"enterprise/service"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cast"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -70,13 +71,22 @@ func (s *Staff) MontorWorkAge(corpId int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Staff) SendStaffSalaryBill(corpId int64, month string) {
|
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)
|
//staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(corpId, month, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
corp, err := dao.NewCorpDao().Get(corpId)
|
||||||
|
if err != nil || corp == nil {
|
||||||
|
log.Errorf("corp is nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
salaryDay := cast.ToInt(corp.GetConfig().SalaryDay)
|
||||||
|
|
||||||
|
totalMessage := make([]string, 0)
|
||||||
|
totalMessage = append(totalMessage, fmt.Sprintf("【工资单】[%s]", month))
|
||||||
for _, staffSalary := range staffSalarys {
|
for _, staffSalary := range staffSalarys {
|
||||||
if staffSalary.Salary < 0.1 {
|
if staffSalary.Salary < 0.1 {
|
||||||
continue
|
continue
|
||||||
|
@ -87,16 +97,24 @@ func (s *Staff) SendStaffSalaryBill(corpId int64, month string) {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
totalMessage = append(totalMessage, fmt.Sprintf("%s:%s", staffSalary.Username, staffSalary.GetBillUrl(true)))
|
||||||
|
if time.Now().Day() != salaryDay {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if staffSalary.Status != model.StaffSalaryStatusPayed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
message := make([]string, 0)
|
message := make([]string, 0)
|
||||||
message = append(message, fmt.Sprintf("【工资单】[%s][%s]", staffUser.Username, month))
|
message = append(message, fmt.Sprintf("【工资单】[%s][%s]", staffUser.Username, month))
|
||||||
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
||||||
message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl()))
|
message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl(false)))
|
||||||
|
if err := global.SendMessage([]string{staffSalary.Username}, strings.Join(message, "\n")); err != nil {
|
||||||
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
|
||||||
log.Errorf("send message error :%s", err.Error())
|
log.Errorf("send message error :%s", err.Error())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(totalMessage, "\n")); err != nil {
|
||||||
|
log.Errorf("send message error :%s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,6 +130,9 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
|
||||||
log.Errorf("db error :%s", err.Error())
|
log.Errorf("db error :%s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
totalPayFee := float64(0)
|
||||||
|
message := make([]string, 0)
|
||||||
|
message = append(message, fmt.Sprintf("【支付宝工资发放】[%s]", month))
|
||||||
for _, staffSalary := range staffSalarys {
|
for _, staffSalary := range staffSalarys {
|
||||||
if staffSalary.Salary < 0.1 {
|
if staffSalary.Salary < 0.1 {
|
||||||
continue
|
continue
|
||||||
|
@ -125,12 +146,10 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
|
||||||
if staffUser.GetConfig().PayChannel != model.StaffSalaryPaymentAlipay {
|
if staffUser.GetConfig().PayChannel != model.StaffSalaryPaymentAlipay {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
message := make([]string, 0)
|
|
||||||
message = append(message, fmt.Sprintf("【支付宝工资发放】[%s]", staffUser.Realname))
|
salaryDay := cast.ToInt(corp.GetConfig().SalaryDay)
|
||||||
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
isSend := time.Now().Day() == salaryDay
|
||||||
message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl()))
|
|
||||||
nowDay := time.Now().Day()
|
|
||||||
isSend := (staffSalary.CorpId == 1000 && nowDay == 10) || (staffSalary.CorpId == 1002 && nowDay == 14)
|
|
||||||
if isSend || staffUser.Username == "jiangyong" {
|
if isSend || staffUser.Username == "jiangyong" {
|
||||||
err = service.NewPay().Pay(corp, staffUser,
|
err = service.NewPay().Pay(corp, staffUser,
|
||||||
fmt.Sprintf("[%s]工资", staffSalary.Month),
|
fmt.Sprintf("[%s]工资", staffSalary.Month),
|
||||||
|
@ -139,18 +158,19 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
|
||||||
staffSalary.GetOutTradeNo())
|
staffSalary.GetOutTradeNo())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
staffSalary.Status = model.StaffSalaryStatusPayed
|
staffSalary.Status = model.StaffSalaryStatusPayed
|
||||||
message = append(message, "发放成功")
|
message = append(message, fmt.Sprintf("[%s]:%.2f", staffSalary.Username, staffSalary.GetRealSalary()))
|
||||||
|
totalPayFee += staffSalary.GetRealSalary()
|
||||||
} else {
|
} else {
|
||||||
|
message = append(message, fmt.Sprintf("[%s]:%s", staffSalary.Username, err.Error()))
|
||||||
staffSalary.SetExtra("pay_error", err.Error())
|
staffSalary.SetExtra("pay_error", err.Error())
|
||||||
message = append(message, fmt.Sprintf("发动失败:%.2f", err.Error()))
|
|
||||||
}
|
}
|
||||||
dao.NewStaffSalaryDao().Update(staffSalary)
|
dao.NewStaffSalaryDao().Update(staffSalary)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := global.SendCorpMessage(staffSalary.CorpId, []string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
|
||||||
log.Errorf("send message error :%s", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = append(message, fmt.Sprintf("汇总:%.2f", totalPayFee))
|
||||||
|
if err := global.SendCorpMessage(corpId, []string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||||
|
log.Errorf("send message error :%s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,13 +48,12 @@ func InitCorp1002(cron *gocron.Scheduler) {
|
||||||
// 1号计算工资信息
|
// 1号计算工资信息
|
||||||
cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).At("06:00").Do(func() {
|
cron.Every(1).Month(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).At("06:00").Do(func() {
|
||||||
go staff.SyncStaffSalary(corpId, "")
|
go staff.SyncStaffSalary(corpId, "")
|
||||||
//go staff.SyncStaffSalary(1002, "")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
//10号晚上8点发送工资单
|
//10号晚上8点发送工资单
|
||||||
cron.Every(1).Month(14).At("20:00").Do(func() {
|
cron.Every(1).Month(14).At("20:00").Do(func() {
|
||||||
go staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
staff.PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||||
go staff.PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +92,9 @@ func InitCorp1000(cron *gocron.Scheduler) {
|
||||||
})
|
})
|
||||||
|
|
||||||
//10号晚上8点发送工资单
|
//10号晚上8点发送工资单
|
||||||
cron.Every(1).Month(7).At("20:00").Do(func() {
|
cron.Every(1).Month(8).At("12:30").Do(func() {
|
||||||
go NewStaff().SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
NewStaff().PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||||
go NewStaff().PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
NewStaff().SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue