This commit is contained in:
jiangyong27 2023-08-10 21:24:54 +08:00
parent cafc163b5e
commit a3236808fa
5 changed files with 36 additions and 12 deletions

View File

@ -41,7 +41,6 @@ type QyWeixin struct {
CheckinAgent string `toml:"checkin_agent"`
CheckinSecret string `toml:"checkin_secret"`
CheckinGroup string `toml:"checkin_group"`
CheckinPayMoney string `toml:"checkin_pay_money"`
CheckinPayTitle string `toml:"checkin_pay_title"`
CheckinPayThresold float64 `toml:"checkin_pay_thresold"`

View File

@ -7,6 +7,7 @@ type CheckinMoney struct {
CheckinId int64
CheckinType string
BillNo string
BillAmount int64
CreateTime int64
UpdateTime int64
}

View File

@ -15,6 +15,7 @@ addr="127.0.0.1:6379"
db=0
password=""
[qyweixin]
corpid = "ww43c49db2e88a17f8"
hr_agent = "3010185"
@ -24,6 +25,7 @@ enterprise_secret = "oMB24UhKe50-XPTg7vhnwoTuhEXaq5XeiHPAUtF4hOs"
checkin_agent = "3010011"
checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU"
checkin_group = "1,2"
checkin_pay_title = "工作餐补贴"
checkin_pay_thresold = 11
pay_secret = "JCGsxntR4E7wrEEQvWGr8_wdKtRlw48n-W6zd8lbwc4"
pay_agent = "3010046"

View File

@ -24,7 +24,6 @@ enterprise_secret = "oMB24UhKe50-XPTg7vhnwoTuhEXaq5XeiHPAUtF4hOs"
checkin_agent = "3010011"
checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU"
checkin_group = "1,2"
checkin_pay_money = 20
checkin_pay_title = "工作餐补贴"
checkin_pay_thresold = 11
pay_secret = "JCGsxntR4E7wrEEQvWGr8_wdKtRlw48n-W6zd8lbwc4"

View File

@ -40,11 +40,12 @@ func NotifyCheckinOnDuty(checkin *model.Checkin) {
return
}
if cast.ToBool(userConfig.Get(model.CheckinOndutyMoneyEnable)) == true {
if isOndutyPay(checkin, userConfig) {
payMoney := cast.ToInt64(userConfig.Get(model.CheckinOndutyMoney))
if payMoney >= 100 && payMoney <= 20000 {
autoPayMoney(checkin, checkOndutyName, payMoney)
if payMoney == 0 {
payMoney = 2000
}
autoPayMoney(checkin, checkOndutyName, payMoney)
}
}
@ -68,16 +69,35 @@ func NotifyCheckinOffDuty(checkin *model.Checkin) {
return
}
if cast.ToBool(userConfig.Get(model.CheckinOffdutyMoneyEnable)) == true {
payMoney := cast.ToInt64(userConfig.Get(model.CheckinOffdutyMoney))
if payMoney >= 100 && payMoney <= 20000 {
autoPayMoney(checkin, checkOffdutyName, payMoney)
}
payMoney := cast.ToInt64(userConfig.Get(model.CheckinOffdutyMoney))
if payMoney == 0 {
payMoney = 2000
}
autoPayMoney(checkin, checkOffdutyName, payMoney)
}
func isOndutyPay(checkin *model.Checkin, userConfig *model.UserConfig) bool {
hour := time.Unix(checkin.StartTime, 0).Hour()
if hour >= 10 {
return false
}
// 配置了上班打卡的直接发放
if cast.ToBool(userConfig.Get(model.CheckinOndutyMoneyEnable)) == true {
return true
}
// 周六加班也直接发放
if time.Now().Weekday() == time.Saturday {
return true
}
return false
}
func autoPayMoney(checkin *model.Checkin, checkinType string, payMoney int64) error {
cfg := config.GetConfig()
//cfg := config.GetConfig()
checkinMoneyDao := dao.NewCheckinMoneyDao()
checkinMoney, err := checkinMoneyDao.GetByDay(checkin.Username, checkin.Day, checkinType)
@ -91,7 +111,8 @@ func autoPayMoney(checkin *model.Checkin, checkinType string, payMoney int64) er
var req weixin.RedMoneyReq
req.TotalAmount = payMoney
req.Title = cfg.QyWeixin.CheckinPayTitle
req.Title = checkinType
req.BillNo = fmt.Sprintf("QY%s%s", time.Now().Format("20060102150405"), butil.RandomStr(6))
req.Userid = checkin.Username
if err := weixin.NewQyPay().PayRedMoney(&req); err != nil {
@ -102,6 +123,7 @@ func autoPayMoney(checkin *model.Checkin, checkinType string, payMoney int64) er
message := make([]string, 0)
duration := checkin.EndTime - checkin.StartTime
message = append(message, fmt.Sprintf("【红包发放】[%s]", checkinType))
message = append(message, fmt.Sprintf("发放金额:%s", fmt.Sprintf("%.2f", payMoney)))
message = append(message, fmt.Sprintf("员工名称:%s", checkin.Username))
message = append(message, fmt.Sprintf("考勤日期:%s", checkin.Day))
message = append(message, fmt.Sprintf("开始时间:%s", goutil.TimeToDateTime(checkin.StartTime)))
@ -118,6 +140,7 @@ func autoPayMoney(checkin *model.Checkin, checkinType string, payMoney int64) er
checkinMoney.BillNo = req.BillNo
checkinMoney.CheckinType = checkinType
checkinMoney.Day = checkin.Day
checkinMoney.BillAmount = payMoney
if _, err := checkinMoneyDao.Create(checkinMoney); err != nil {
log.Errorf("create checkinMoney model error :%s", err.Error())
return err