Files
czl231 3ef33b531d 已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
2026-09-13 00:57:32 +08:00

42 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述供气订单支付完成后原子生成正式押金事实版本1.0.0。
package payment
import (
"fmt"
"time"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
// CompleteGasDeposits 将下单时锁定的押金快照转为用户押金记录,重复回调不会重复入账。
func CompleteGasDeposits(tx *gorm.DB, orderIdentity string, paidAt time.Time) error {
var order models.GasorderBasic
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("identity = ?", orderIdentity).First(&order).Error; err != nil {
return err
}
var snapshots []models.GasorderDeposit
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("gasorder_basic_id = ? AND deposit_status = ?", order.ID, 10).Find(&snapshots).Error; err != nil {
return err
}
for _, snapshot := range snapshots {
var existing int64
if err := tx.Model(&models.DepositRecord{}).Where("gasorder_id = ? AND product_info_id = ? AND status <> ?", order.ID, snapshot.ProductInfoID, 3).Count(&existing).Error; err != nil {
return err
}
if existing == 0 {
record := models.DepositRecord{Entity: models.Entity{Identity: models.NewIdentity(), Status: 1}, DepositStatus: 10,
DepositNo: fmt.Sprintf("DEP%s-%s", paidAt.Format("20060102150405.000000"), snapshot.Identity), UserAccountID: order.UserAccountID, ProductInfoID: snapshot.ProductInfoID,
PolicyID: snapshot.PolicyID, GasorderID: order.ID, Amount: snapshot.Amount, PaidAt: paidAt}
if err := tx.Create(&record).Error; err != nil {
return err
}
}
if err := tx.Model(&snapshot).Where("deposit_status = ?", 10).Update("deposit_status", 23).Error; err != nil {
return err
}
}
return nil
}