salary read
This commit is contained in:
parent
25c9ba1649
commit
78429cfd9c
|
@ -27,6 +27,7 @@ type CorpConfig struct {
|
|||
SocialDeduct string `json:"social_deduct"`
|
||||
HouseDeduct string `json:"house_deduct"`
|
||||
WorkerHour string `json:"worker_hour"`
|
||||
SalaryDay string `json:"salary_day"`
|
||||
}
|
||||
|
||||
type Corp struct {
|
||||
|
|
|
@ -47,6 +47,7 @@ type StaffSalary struct {
|
|||
OtherDeduct float64
|
||||
CreateTime int64
|
||||
UpdateTime int64
|
||||
ReadTime int64
|
||||
Extra string
|
||||
Comment string
|
||||
Status int
|
||||
|
@ -67,9 +68,14 @@ func (s *StaffSalary) SetExtra(key string, value interface{}) {
|
|||
s.Extra = goutil.EncodeJSON(extra)
|
||||
}
|
||||
|
||||
func (s *StaffSalary) GetBillUrl() string {
|
||||
func (s *StaffSalary) GetBillUrl(test bool) string {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ func (s *Salary) SyncStaffSalary(ctx *gin.Context) {
|
|||
|
||||
func (s *Salary) Bill(ctx *gin.Context) {
|
||||
id := ctx.Query("id")
|
||||
test := ctx.Query("test")
|
||||
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) {
|
||||
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, "", "", "")
|
||||
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"))
|
||||
if cast.ToInt(req.Month) < lastMonth ||
|
||||
|
@ -437,7 +442,7 @@ func (s *StaffSalary) toExcel(filePath string, header []string, datas [][]string
|
|||
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)
|
||||
session.CheckDBError(err)
|
||||
|
@ -449,6 +454,11 @@ func (s *StaffSalary) Bill(id int64, ctx *gin.Context) {
|
|||
session.CheckDBError(err)
|
||||
session.CheckNilError(user, "用户不存在")
|
||||
|
||||
if !test && salary.ReadTime == 0 {
|
||||
salary.ReadTime = time.Now().Unix()
|
||||
dao.NewStaffSalaryDao().Update(salary)
|
||||
}
|
||||
|
||||
datas := make([]*model.SalaryBillSection, 0)
|
||||
|
||||
baseDetail := make([]*model.SalaryBillLine, 0)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"enterprise/service"
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -70,13 +71,22 @@ 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, 0)
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
if staffSalary.Salary < 0.1 {
|
||||
continue
|
||||
|
@ -87,16 +97,24 @@ func (s *Staff) SendStaffSalaryBill(corpId int64, month string) {
|
|||
log.Errorf("db error :%s", err.Error())
|
||||
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 = append(message, fmt.Sprintf("【工资单】[%s][%s]", staffUser.Username, month))
|
||||
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
||||
message = append(message, fmt.Sprintf(`<a href="%s">查看明细</a>`, staffSalary.GetBillUrl()))
|
||||
|
||||
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
|
||||
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 {
|
||||
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())
|
||||
return
|
||||
}
|
||||
totalPayFee := float64(0)
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【支付宝工资发放】[%s]", month))
|
||||
for _, staffSalary := range staffSalarys {
|
||||
if staffSalary.Salary < 0.1 {
|
||||
continue
|
||||
|
@ -125,12 +146,10 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
|
|||
if staffUser.GetConfig().PayChannel != model.StaffSalaryPaymentAlipay {
|
||||
continue
|
||||
}
|
||||
message := make([]string, 0)
|
||||
message = append(message, fmt.Sprintf("【支付宝工资发放】[%s]", staffUser.Realname))
|
||||
message = append(message, fmt.Sprintf("实发工资:%.2f", staffSalary.GetRealSalary()))
|
||||
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)
|
||||
|
||||
salaryDay := cast.ToInt(corp.GetConfig().SalaryDay)
|
||||
isSend := time.Now().Day() == salaryDay
|
||||
|
||||
if isSend || staffUser.Username == "jiangyong" {
|
||||
err = service.NewPay().Pay(corp, staffUser,
|
||||
fmt.Sprintf("[%s]工资", staffSalary.Month),
|
||||
|
@ -139,18 +158,19 @@ func (s *Staff) PayStaffSalary(corpId int64, month string) {
|
|||
staffSalary.GetOutTradeNo())
|
||||
if err == nil {
|
||||
staffSalary.Status = model.StaffSalaryStatusPayed
|
||||
message = append(message, "发放成功")
|
||||
message = append(message, fmt.Sprintf("[%s]:%.2f", staffSalary.Username, staffSalary.GetRealSalary()))
|
||||
totalPayFee += staffSalary.GetRealSalary()
|
||||
} else {
|
||||
message = append(message, fmt.Sprintf("[%s]:%s", staffSalary.Username, err.Error()))
|
||||
staffSalary.SetExtra("pay_error", err.Error())
|
||||
message = append(message, fmt.Sprintf("发动失败:%.2f", err.Error()))
|
||||
}
|
||||
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号计算工资信息
|
||||
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(1002, "")
|
||||
})
|
||||
|
||||
//10号晚上8点发送工资单
|
||||
cron.Every(1).Month(14).At("20:00").Do(func() {
|
||||
go staff.SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||
go staff.PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||
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点发送工资单
|
||||
cron.Every(1).Month(7).At("20:00").Do(func() {
|
||||
go NewStaff().SendStaffSalaryBill(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||
go NewStaff().PayStaffSalary(corpId, time.Now().AddDate(0, -1, 0).Format("200601"))
|
||||
cron.Every(1).Month(8).At("12:30").Do(func() {
|
||||
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