feat: 代付做完了
This commit is contained in:
@@ -531,13 +531,38 @@ func MiniprogramPayNotify(c *gin.Context) {
|
||||
fmt.Printf("[PayNotify] 支付成功: orderSn=%s, transactionId=%s, amount=%.2f\n", orderSn, transactionID, totalAmount)
|
||||
|
||||
var attach struct {
|
||||
ProductType string `json:"productType"`
|
||||
ProductID string `json:"productId"`
|
||||
UserID string `json:"userId"`
|
||||
GiftPayRequestSn string `json:"giftPayRequestSn"`
|
||||
ProductType string `json:"productType"`
|
||||
ProductID string `json:"productId"`
|
||||
UserID string `json:"userId"`
|
||||
GiftPayRequestSn string `json:"giftPayRequestSn"`
|
||||
GiftPayInitiatorPay bool `json:"giftPayInitiatorPay"`
|
||||
PT string `json:"pt"`
|
||||
PID string `json:"pid"`
|
||||
UID string `json:"uid"`
|
||||
SN string `json:"sn"`
|
||||
IP int `json:"ip"`
|
||||
}
|
||||
if attachStr != "" {
|
||||
_ = json.Unmarshal([]byte(attachStr), &attach)
|
||||
if attach.ProductType == "" {
|
||||
if attach.PT == "gpb" {
|
||||
attach.ProductType = "gift_pay_batch"
|
||||
} else {
|
||||
attach.ProductType = attach.PT
|
||||
}
|
||||
}
|
||||
if attach.ProductID == "" {
|
||||
attach.ProductID = attach.PID
|
||||
}
|
||||
if attach.UserID == "" {
|
||||
attach.UserID = attach.UID
|
||||
}
|
||||
if attach.GiftPayRequestSn == "" {
|
||||
attach.GiftPayRequestSn = attach.SN
|
||||
}
|
||||
if attach.IP != 0 {
|
||||
attach.GiftPayInitiatorPay = true
|
||||
}
|
||||
}
|
||||
|
||||
db := database.DB()
|
||||
@@ -605,13 +630,23 @@ func MiniprogramPayNotify(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 代付订单:更新 gift_pay_request、订单 payer_user_id
|
||||
// 权益归属与分佣:代付时归发起人(order.UserID),普通订单归 buyerUserID
|
||||
beneficiaryUserID := buyerUserID
|
||||
if attach.GiftPayRequestSn != "" && order.UserID != "" {
|
||||
beneficiaryUserID = order.UserID
|
||||
fmt.Printf("[PayNotify] 代付订单,权益归属发起人: %s\n", beneficiaryUserID)
|
||||
// 权益归属与分佣:旧版好友付归发起人;新版发起人付不发放权益(好友领取时再发)
|
||||
giftPayRequestSn := attach.GiftPayRequestSn
|
||||
if giftPayRequestSn == "" && order.GiftPayRequestID != nil && *order.GiftPayRequestID != "" {
|
||||
var gpr model.GiftPayRequest
|
||||
if err := db.Where("id = ?", *order.GiftPayRequestID).Select("request_sn").First(&gpr).Error; err == nil {
|
||||
giftPayRequestSn = gpr.RequestSN
|
||||
}
|
||||
}
|
||||
if attach.GiftPayRequestSn != "" {
|
||||
beneficiaryUserID := buyerUserID
|
||||
if giftPayRequestSn != "" && order.UserID != "" && !attach.GiftPayInitiatorPay {
|
||||
beneficiaryUserID = order.UserID
|
||||
fmt.Printf("[PayNotify] 代付订单(好友付),权益归属发起人: %s\n", beneficiaryUserID)
|
||||
}
|
||||
if attach.GiftPayInitiatorPay {
|
||||
fmt.Printf("[PayNotify] 代付订单(发起人付),不发放权益,好友领取时再发\n")
|
||||
}
|
||||
if giftPayRequestSn != "" {
|
||||
var payerUserID string
|
||||
if openID != "" {
|
||||
var payer model.User
|
||||
@@ -620,7 +655,7 @@ func MiniprogramPayNotify(c *gin.Context) {
|
||||
db.Model(&order).Update("payer_user_id", payerUserID)
|
||||
}
|
||||
}
|
||||
db.Model(&model.GiftPayRequest{}).Where("request_sn = ?", attach.GiftPayRequestSn).
|
||||
db.Model(&model.GiftPayRequest{}).Where("request_sn = ?", giftPayRequestSn).
|
||||
Updates(map[string]interface{}{
|
||||
"status": "paid",
|
||||
"payer_user_id": payerUserID,
|
||||
|
||||
Reference in New Issue
Block a user