enterprise/server/controller/qyweixin.go

76 lines
1.7 KiB
Go
Raw Normal View History

2023-08-13 21:24:54 +08:00
package controller
import (
"enterprise/common/config"
2025-01-08 12:35:29 +08:00
"enterprise/common/dao"
2025-01-15 12:27:44 +08:00
"enterprise/common/model"
2024-01-22 22:58:56 +08:00
"enterprise/server/service"
2024-01-24 16:19:06 +08:00
"enterprise/server/session"
2024-08-09 13:57:03 +08:00
"git.u8t.cn/open/gosdk/qyweixin"
2023-08-13 21:24:54 +08:00
"github.com/gin-gonic/gin"
2024-01-24 16:19:06 +08:00
"github.com/spf13/cast"
"net/http"
2023-08-13 21:24:54 +08:00
)
type QyWeixin struct {
}
2025-03-11 10:59:41 +08:00
func NewQyWeixin() *QyWeixin {
return &QyWeixin{}
}
2023-08-13 21:24:54 +08:00
func (q *QyWeixin) Approve(ctx *gin.Context) {
2025-03-11 10:59:41 +08:00
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
2025-03-14 17:56:55 +08:00
cid := cast.ToInt64(ctx.Param("cid"))
corp, err := dao.NewCorpDao().Get(cid)
2025-03-11 10:59:41 +08:00
session.CheckDBError(err)
if corp == nil {
2025-03-14 17:56:55 +08:00
corp, err = dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
2025-03-11 10:59:41 +08:00
session.CheckDBError(err)
session.CheckNilError(corp, "企业不存在")
2025-01-08 12:53:00 +08:00
}
2024-01-22 22:50:20 +08:00
2025-01-08 12:53:00 +08:00
corpConfig := corp.GetConfig()
approve := service.NewApprove(corp)
2025-01-08 12:35:29 +08:00
reply := approve.Reply
2024-01-22 22:50:20 +08:00
qyApp := qyweixin.NewApp(&qyweixin.AppConfig{
2025-01-08 12:53:00 +08:00
Corpid: corpConfig.CorpId,
Secret: corpConfig.ApproveSecret,
Agent: corpConfig.ApproveAgent,
2024-01-22 22:50:20 +08:00
Token: config.QyWeixinAgentToken,
AesKey: config.QyWeixinAgentAesKey,
2024-01-22 22:58:56 +08:00
Replay: reply,
2023-08-13 21:24:54 +08:00
})
2024-01-22 22:50:20 +08:00
qyApp.Callback(ctx)
2023-08-13 21:24:54 +08:00
}
2024-01-24 16:19:06 +08:00
2025-01-15 12:27:44 +08:00
func (q *QyWeixin) HandleRefund(ctx *gin.Context) {
2025-01-15 12:24:32 +08:00
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("没有数据")
}
2025-01-15 12:27:44 +08:00
if approve.Status == model.ApprovalRefundStatusPayed {
panic("已支付")
}
2025-01-15 12:24:32 +08:00
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())
}