2024-11-21 12:18:28 +08:00
|
|
|
package pay
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2025-04-09 15:58:06 +08:00
|
|
|
"net/http"
|
2025-04-27 12:17:18 +08:00
|
|
|
"tyc-server/app/main/api/internal/svc"
|
2025-04-09 15:58:06 +08:00
|
|
|
|
2024-11-21 12:18:28 +08:00
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WechatPayRefundCallbackLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewWechatPayRefundCallbackLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WechatPayRefundCallbackLogic {
|
|
|
|
return &WechatPayRefundCallbackLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *WechatPayRefundCallbackLogic) WechatPayRefundCallback(w http.ResponseWriter, r *http.Request) error {
|
2025-05-27 18:35:01 +08:00
|
|
|
// notification, err := l.svcCtx.PayService.re(l.ctx, r)
|
|
|
|
// if err != nil {
|
|
|
|
// logx.Errorf("微信退款回调,%+v", err)
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
// order, findOrderErr := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, *notification.OutTradeNo)
|
|
|
|
// if findOrderErr != nil {
|
|
|
|
// logx.Errorf("微信退款回调,查找订单信息失败: %+v", findOrderErr)
|
|
|
|
// return nil
|
|
|
|
// }
|
2024-11-21 12:18:28 +08:00
|
|
|
|
2025-05-27 18:35:01 +08:00
|
|
|
// switch *notification.Status {
|
|
|
|
// case refunddomestic.STATUS_SUCCESS:
|
|
|
|
// order.Status = "refunded"
|
|
|
|
// order.RefundTime = sql.NullTime{
|
|
|
|
// Time: time.Now(),
|
|
|
|
// Valid: true,
|
|
|
|
// }
|
|
|
|
// case refunddomestic.STATUS_ABNORMAL:
|
|
|
|
// // 异常
|
|
|
|
// return nil
|
|
|
|
// default:
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
// if updateErr := l.svcCtx.OrderModel.UpdateWithVersion(l.ctx, nil, order); updateErr != nil {
|
|
|
|
// logx.Errorf("微信退款回调,更新订单失败%+v", updateErr)
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
// // 响应微信回调成功
|
|
|
|
// w.WriteHeader(http.StatusOK)
|
|
|
|
// _, _ = w.Write([]byte("success")) // 确保只写入一次响应
|
2024-11-21 12:18:28 +08:00
|
|
|
return nil
|
|
|
|
}
|