approve refund

This commit is contained in:
jiangyong27 2025-01-15 12:24:32 +08:00
parent 0f0c63972f
commit d9a2fbf690
3 changed files with 74 additions and 4 deletions

View File

@ -42,6 +42,30 @@ func (q *QyWeixin) Approve(ctx *gin.Context) {
qyApp.Callback(ctx)
}
func (q *QyWeixin) ApproveRefund(ctx *gin.Context) {
id := cast.ToInt64(ctx.Query("id"))
approve, err := dao.NewApprovalRefundDao().Get(id)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
if approve == nil {
panic("没有数据")
}
corp, err := dao.NewCorpDao().Get(approve.CorpId)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
if corp == nil {
panic("没有数据")
}
serv := service.NewApprove(corp)
err = serv.HandleRefundApprove(approve)
if err != nil {
panic(config.ErrDb.New().Append(err))
}
ctx.JSON(http.StatusOK, session.NewRspOk())
}
func (q *QyWeixin) Pay(ctx *gin.Context) {
cid := cast.ToInt64(ctx.Param("cid"))
userid := ctx.Query("userid")

View File

@ -16,6 +16,7 @@ func initRoutge(engine *gin.Engine) {
group.Use(base.Recovery)
apiGroup.Any("/qyweixin/approve/:cid", qyweixin.Approve)
apiGroup.Any("/qyweixin/pay/:cid", qyweixin.Pay)
apiGroup.Any("/qyweixin/pay/refund", qyweixin.ApproveRefund)
group.GET("/staff/salary", staff.Salary)
group.GET("/staff/salary/history", staff.SalaryHistory)

View File

@ -198,7 +198,7 @@ func (a *Approve) handleCheckin(detail *qyweixin.ApproveDetail, spStatus int) {
}
}
func (a *Approve) handleRefundWxpay(data *model.ApprovalRefund) error {
func (a *Approve) refundWxpay(data *model.ApprovalRefund) error {
openid, err := a.approveClient.GetOpenid(data.Username)
if err != nil {
log.Errorf("GetOpenid error :%s", err.Error())
@ -227,7 +227,7 @@ func (a *Approve) handleRefundWxpay(data *model.ApprovalRefund) error {
return nil
}
func (a *Approve) handleRefundAlipay(staff *model.StaffInfo, data *model.ApprovalRefund) error {
func (a *Approve) refundAlipay(staff *model.StaffInfo, data *model.ApprovalRefund) error {
cli := config.GetAliPayClient("batiao")
var req alipay.FundTransUniTransfer
@ -298,10 +298,10 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail, spStatus int) {
// 支付费用
var payType = "weixin"
if staff != nil && staff.AlipayUid != "" {
err = a.handleRefundAlipay(staff, newData)
err = a.refundAlipay(staff, newData)
payType = "alipay"
} else {
err = a.handleRefundWxpay(newData)
err = a.refundWxpay(newData)
}
var title string = "【报销成功】"
if err == nil {
@ -330,6 +330,51 @@ func (a *Approve) handleRefund(detail *qyweixin.ApproveDetail, spStatus int) {
}
}
func (a *Approve) HandleRefundApprove(approve *model.ApprovalRefund) error {
staff, err := dao.NewStaffInfoDao().GetByUsername(approve.Username)
if err != nil {
return err
}
if staff == nil {
return errors.New("staff is not exist")
}
// 支付费用
var payType = "weixin"
if staff != nil && staff.AlipayUid != "" {
err = a.refundAlipay(staff, approve)
payType = "alipay"
} else {
err = a.refundWxpay(approve)
}
var title string = "【报销成功】"
if err == nil {
approve.Status = model.ApprovalRefundStatusPayed
} else {
title = "【报销失败】"
}
message := make([]string, 0)
message = append(message, title)
message = append(message, fmt.Sprintf("发放金额:%s", fmt.Sprintf("%.2f", approve.RefundAmount)))
message = append(message, fmt.Sprintf("费用类型:%s", approve.RefundType))
message = append(message, fmt.Sprintf("支付方式:%s", payType))
message = append(message, fmt.Sprintf("员工名称:%s", approve.Username))
message = append(message, fmt.Sprintf("费用说明:%s", approve.RefundRemark))
if err != nil {
message = append(message, fmt.Sprintf("异常:%s", err.Error()))
}
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
log.Errorf("send message error :%s", err.Error())
}
if err := dao.NewApprovalRefundDao().Update(approve); err != nil {
log.Errorf("db error :%s", err.Error())
}
return nil
}
func (a *Approve) handleText(msg *message.MixMessage) {
}