diff --git a/common/config/config.go b/common/config/config.go index 8787078..c275943 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -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"` diff --git a/common/model/checkin_money.go b/common/model/checkin_money.go index 9e2c027..0ac8ea2 100644 --- a/common/model/checkin_money.go +++ b/common/model/checkin_money.go @@ -7,6 +7,7 @@ type CheckinMoney struct { CheckinId int64 CheckinType string BillNo string + BillAmount int64 CreateTime int64 UpdateTime int64 } diff --git a/conf/server.conf.dev b/conf/server.conf.dev index c7d61c5..db96aed 100644 --- a/conf/server.conf.dev +++ b/conf/server.conf.dev @@ -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" diff --git a/conf/server.conf.prod b/conf/server.conf.prod index 97b5209..bb05f9d 100644 --- a/conf/server.conf.prod +++ b/conf/server.conf.prod @@ -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" diff --git a/worker/autopay.go b/worker/autopay.go index aabc67a..eab4738 100644 --- a/worker/autopay.go +++ b/worker/autopay.go @@ -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