2025-02-20 12:55:54 +00:00
|
|
|
package bundle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2025-05-09 03:12:33 +00:00
|
|
|
"fmt"
|
2025-05-26 08:31:38 +00:00
|
|
|
"fonchain-fiee/api/accountFiee"
|
2025-02-20 12:55:54 +00:00
|
|
|
"fonchain-fiee/api/bundle"
|
2025-02-23 02:42:41 +00:00
|
|
|
"fonchain-fiee/api/order"
|
2025-02-21 13:09:29 +00:00
|
|
|
"fonchain-fiee/pkg/model/login"
|
2025-02-20 12:55:54 +00:00
|
|
|
"fonchain-fiee/pkg/service"
|
2025-02-21 13:09:29 +00:00
|
|
|
"fonchain-fiee/pkg/service/bundle/common"
|
2025-02-22 07:31:21 +00:00
|
|
|
"fonchain-fiee/pkg/service/bundle/logic"
|
2025-02-21 13:09:29 +00:00
|
|
|
bundleModel "fonchain-fiee/pkg/service/bundle/model"
|
2025-05-27 02:46:36 +00:00
|
|
|
"fonchain-fiee/pkg/service/upload"
|
2025-03-25 08:30:58 +00:00
|
|
|
"strconv"
|
2025-05-09 03:12:33 +00:00
|
|
|
"strings"
|
2025-06-12 08:38:55 +00:00
|
|
|
"time"
|
2025-03-25 08:30:58 +00:00
|
|
|
|
2025-02-20 12:55:54 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin/binding"
|
|
|
|
)
|
|
|
|
|
2025-06-12 08:38:55 +00:00
|
|
|
func CreateBundleOrderAddSignature(c *gin.Context) {
|
|
|
|
var req bundle.OrderAddRecord
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if req.Language == "" {
|
|
|
|
service.Error(c, errors.New(common.MissLanguageTypes))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if req.BundleUuid == "" {
|
|
|
|
service.Error(c, errors.New(common.MissOrderNo))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// 获取用户信息
|
|
|
|
userInfo := login.GetUserInfoFromC(c)
|
|
|
|
if msg, exists := map[int32]string{
|
|
|
|
1: common.Unnamed,
|
|
|
|
2: common.UnderReview,
|
|
|
|
3: common.ReviewFailed,
|
|
|
|
}[userInfo.Status]; userInfo.Status != 4 {
|
|
|
|
if exists {
|
|
|
|
service.Error(c, errors.New(msg))
|
|
|
|
} else {
|
|
|
|
service.Error(c, errors.New(common.UnknownStatus))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 校验套餐是否已购买
|
|
|
|
orderRecordReq := bundle.OrderRecordsDetailRequest{
|
2025-06-12 10:15:28 +00:00
|
|
|
BundleUUID: req.BundleUuid,
|
2025-06-12 08:38:55 +00:00
|
|
|
CustomerID: strconv.FormatUint(userInfo.ID, 10),
|
|
|
|
}
|
|
|
|
orderRecordResp, err := service.BundleProvider.OrderRecordsDetail(context.Background(), &orderRecordReq)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
2025-06-12 10:15:28 +00:00
|
|
|
if orderRecordResp.OrderRecord.ExpirationTime == "" || orderRecordResp.OrderRecord.ExpirationTime < time.Now().Format("2006-01-02") {
|
2025-06-12 08:38:55 +00:00
|
|
|
service.Error(c, errors.New(common.ThePackageHasExpired))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// 获取套餐详情(待替换逻辑)
|
|
|
|
bundleDetail, err := service.BundleProvider.BundleDetail(context.Background(), &bundle.BundleDetailRequest{
|
|
|
|
Uuid: req.BundleUuid,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// todo 需要判断购买的增值服务是否为可用时长 如果为可以用时长 合同截止日期为购买时长时间 否则合同截止日期为主套餐截止日期
|
|
|
|
// 处理多个增值服务
|
|
|
|
type ValueAddServiceInfo struct {
|
|
|
|
Service *bundle.ValueAddServiceLang
|
|
|
|
Options *bundle.ValueAddPriceOptions
|
|
|
|
ID int32
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
valueAddServices []ValueAddServiceInfo
|
|
|
|
totalAmount float64
|
|
|
|
mainDeadline = orderRecordResp.OrderRecord.ExpirationTime
|
|
|
|
)
|
2025-06-12 10:50:28 +00:00
|
|
|
//for _, opt := range req.AddPriceOptionsList {
|
|
|
|
// valueAddInfo, err := service.BundleProvider.ValueAddServiceDetail(context.Background(), &bundle.ValueAddServiceDetailRequest{
|
|
|
|
// Uuid: opt.ValueUid,
|
|
|
|
// Language: req.Language,
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// service.Error(c, err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// // 找到匹配的选项
|
|
|
|
// var selectedOption *bundle.ValueAddPriceOptions
|
|
|
|
// for _, option := range valueAddInfo.ValueAddServiceLang.Options {
|
|
|
|
// if int32(option.Id) == opt.Id {
|
|
|
|
// selectedOption = option
|
|
|
|
// break
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if selectedOption == nil {
|
|
|
|
// service.Error(c, errors.New("未找到匹配的价格选项"))
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// valueAddServices = append(valueAddServices, ValueAddServiceInfo{
|
|
|
|
// Service: valueAddInfo.ValueAddServiceLang,
|
|
|
|
// Options: selectedOption,
|
|
|
|
// ID: opt.Id,
|
|
|
|
// })
|
|
|
|
//}
|
2025-06-12 08:38:55 +00:00
|
|
|
// 计算总金额和确定截止日期
|
|
|
|
var expirationDate string
|
2025-06-12 10:15:28 +00:00
|
|
|
var addPriceList []*bundle.AddPriceOptionsInfo
|
2025-06-12 08:38:55 +00:00
|
|
|
for _, svc := range valueAddServices {
|
|
|
|
price, err := strconv.ParseFloat(svc.Options.Price, 64)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, errors.New("价格格式错误"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var nowAmount float64
|
|
|
|
switch svc.Service.PriceMode {
|
|
|
|
case 1: // 数量×单价模式
|
|
|
|
nowAmount = float64(svc.Options.Num) * price
|
|
|
|
totalAmount += float64(svc.Options.Num) * price
|
|
|
|
case 2: // 固定价格模式
|
|
|
|
nowAmount = price
|
|
|
|
totalAmount += price
|
|
|
|
}
|
|
|
|
|
2025-06-12 10:15:28 +00:00
|
|
|
addPriceList = append(addPriceList, &bundle.AddPriceOptionsInfo{
|
2025-06-12 08:38:55 +00:00
|
|
|
ValueUid: svc.Service.Uuid,
|
|
|
|
ServiceType: svc.Service.ServiceType,
|
|
|
|
CurrencyType: svc.Service.PriceType,
|
|
|
|
Amount: float32(nowAmount),
|
|
|
|
Num: svc.Options.Num,
|
|
|
|
Unit: svc.Service.Unit,
|
|
|
|
})
|
|
|
|
// 如果是可用时长服务,计算新的截止日期
|
|
|
|
if svc.Service.ServiceType == 5 {
|
|
|
|
newDeadline := calculateExpirationDate(svc.Options.Num, svc.Service.Unit)
|
|
|
|
if expirationDate == "" || newDeadline > expirationDate {
|
|
|
|
expirationDate = newDeadline
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果没有可用时长服务,使用主套餐截止日期
|
|
|
|
if expirationDate == "" {
|
|
|
|
expirationDate = mainDeadline
|
|
|
|
}
|
|
|
|
req.CustomerNum = userInfo.SubNum
|
|
|
|
req.CustomerName = userInfo.Name
|
|
|
|
req.CustomerID = strconv.FormatUint(userInfo.ID, 10)
|
|
|
|
req.Source = 2
|
|
|
|
req.SignedTime = common.GetBeijingTime()
|
|
|
|
req.ExpirationDate = expirationDate
|
2025-06-12 10:15:28 +00:00
|
|
|
req.AddPriceOptionsList = addPriceList
|
2025-06-12 08:38:55 +00:00
|
|
|
// 当前 未将 签名 写入合同中
|
|
|
|
signContract, signContractErr := logic.SignContractV2(req.CustomerNum, bundleDetail.Bundle.Contract, float32(totalAmount), expirationDate)
|
|
|
|
if signContractErr != nil {
|
|
|
|
service.Error(c, signContractErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.SignContract = signContract
|
|
|
|
// 创建增值服务订单记录
|
|
|
|
res, err := service.BundleProvider.CreateOrderAddRecord(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
service.Success(c, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 计算截止日期辅助函数
|
|
|
|
func calculateExpirationDate(num int32, unit string) string {
|
|
|
|
now := time.Now()
|
|
|
|
switch unit {
|
|
|
|
case "天":
|
|
|
|
return now.AddDate(0, 0, int(num)).Format("2006-01-02")
|
|
|
|
case "月":
|
|
|
|
return now.AddDate(0, int(num), 0).Format("2006-01-02")
|
|
|
|
case "年":
|
|
|
|
return now.AddDate(int(num), 0, 0).Format("2006-01-02")
|
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
2025-02-21 13:09:29 +00:00
|
|
|
func CreateBundleOrderSignature(c *gin.Context) {
|
2025-02-20 12:55:54 +00:00
|
|
|
var req bundle.OrderRecord
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.BundleUuid == "" {
|
|
|
|
service.Error(c, errors.New(common.MissBundleUUID))
|
|
|
|
return
|
|
|
|
}
|
2025-06-10 08:15:57 +00:00
|
|
|
if req.Language == "" {
|
|
|
|
service.Error(c, errors.New(common.MissLanguageTypes))
|
|
|
|
return
|
|
|
|
}
|
2025-03-28 11:07:20 +00:00
|
|
|
// 不去校验 签名
|
|
|
|
/*if req.Signature == "" {
|
2025-02-20 12:55:54 +00:00
|
|
|
service.Error(c, errors.New(common.MissOrderSignature))
|
|
|
|
return
|
2025-03-28 11:07:20 +00:00
|
|
|
}*/
|
2025-06-12 08:38:55 +00:00
|
|
|
statusMessages := map[int32]string{
|
|
|
|
1: common.Unnamed,
|
|
|
|
2: common.UnderReview,
|
|
|
|
3: common.ReviewFailed,
|
|
|
|
}
|
2025-02-20 12:55:54 +00:00
|
|
|
// 获取 用户信息
|
2025-02-21 13:09:29 +00:00
|
|
|
userInfo := login.GetUserInfoFromC(c)
|
2025-06-12 08:38:55 +00:00
|
|
|
if userInfo.Status != 4 {
|
|
|
|
if msg, exists := statusMessages[userInfo.Status]; exists {
|
|
|
|
service.Error(c, errors.New(msg))
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
service.Error(c, errors.New(common.UnknownStatus))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2025-02-22 12:37:56 +00:00
|
|
|
// 校验 当前用户只能买一次套餐
|
|
|
|
orderRecordsListReq := bundle.OrderRecordsRequest{
|
|
|
|
CustomerID: strconv.FormatUint(userInfo.ID, 10),
|
|
|
|
}
|
|
|
|
orderRecordsList, orderRecordsListErr := service.BundleProvider.OrderRecordsList(context.Background(), &orderRecordsListReq)
|
|
|
|
if orderRecordsListErr != nil {
|
|
|
|
service.Error(c, orderRecordsListErr)
|
|
|
|
return
|
|
|
|
}
|
2025-06-12 08:38:55 +00:00
|
|
|
//有套餐并且套餐未过期
|
2025-02-22 12:37:56 +00:00
|
|
|
if orderRecordsList.OrderRecords != nil {
|
2025-06-12 08:38:55 +00:00
|
|
|
for _, orderInfo := range orderRecordsList.OrderRecords {
|
|
|
|
if orderInfo.CustomerID == strconv.FormatUint(userInfo.ID, 10) && orderInfo.ExpirationTime > time.Now().Format("2006-01-02") {
|
2025-02-22 12:37:56 +00:00
|
|
|
service.Error(c, errors.New(common.HadOrder))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-12 02:56:27 +00:00
|
|
|
// 获取 最后一次的 合同编号
|
|
|
|
lastOrderRecord, lastOrderRecordErr := service.BundleProvider.OrderRecordsList(context.Background(), &bundle.OrderRecordsRequest{
|
|
|
|
PageSize: 1,
|
|
|
|
Page: 1,
|
|
|
|
})
|
|
|
|
|
|
|
|
if lastOrderRecordErr != nil {
|
|
|
|
service.Error(c, lastOrderRecordErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lastContractNo := ""
|
|
|
|
|
|
|
|
if lastOrderRecord.OrderRecords != nil {
|
|
|
|
for _, lastOrder := range lastOrderRecord.OrderRecords {
|
|
|
|
lastContractNo = lastOrder.ContractNo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-21 13:09:29 +00:00
|
|
|
req.CustomerNum = userInfo.SubNum
|
|
|
|
req.CustomerName = userInfo.Name
|
|
|
|
req.CustomerID = strconv.FormatUint(userInfo.ID, 10)
|
2025-02-20 12:55:54 +00:00
|
|
|
|
|
|
|
// 获取 套餐信息
|
|
|
|
bundleDetailReq := &bundle.BundleDetailRequest{
|
|
|
|
Uuid: req.BundleUuid,
|
|
|
|
}
|
|
|
|
bundleDetail, detailErr := service.BundleProvider.BundleDetail(context.Background(), bundleDetailReq)
|
|
|
|
if detailErr != nil {
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-25 08:30:58 +00:00
|
|
|
//获取增值套餐信息
|
2025-06-11 06:33:48 +00:00
|
|
|
//if req.ValueAddBundleUuid != "" {
|
|
|
|
// valueAddBundleDetail, err := service.BundleProvider.ValueAddBundleDetail(context.Background(), &bundle.ValueAddBundleDetailRequest{
|
|
|
|
// Uuid: req.ValueAddBundleUuid,
|
|
|
|
// })
|
|
|
|
// if err != nil {
|
|
|
|
// service.Error(c, err)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// req.ValueAddBundleUuid = valueAddBundleDetail.Data.Uuid
|
|
|
|
// req.ValueAddOriginalPrice = valueAddBundleDetail.Data.OriginalPrice
|
|
|
|
// req.ValueAddDiscountPrice = valueAddBundleDetail.Data.DiscountPrice
|
|
|
|
// req.AddBundleCommonUid = valueAddBundleDetail.Data.AddBundleCommonUid
|
|
|
|
//
|
|
|
|
// if valueAddBundleDetail.Data.Choose { // 可选条数
|
|
|
|
// req.ValueAddBundleAmount = valueAddBundleDetail.Data.DiscountPrice * float32(req.Num)
|
|
|
|
// discount, _ := new(big.Float).Sub(big.NewFloat(float64(valueAddBundleDetail.Data.OriginalPrice)), big.NewFloat(float64(valueAddBundleDetail.Data.DiscountPrice))).Float32()
|
|
|
|
// req.ValueAddSavedAmount = discount * float32(req.Num)
|
|
|
|
// } else { // 固定条数
|
|
|
|
// req.ValueAddBundleAmount = valueAddBundleDetail.Data.TotalPrice
|
|
|
|
// req.ValueAddSavedAmount = valueAddBundleDetail.Data.SavedAmount
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// req.TotalAmount, _ = new(big.Float).Add(big.NewFloat(float64(req.ValueAddBundleAmount)), big.NewFloat(float64(bundleDetail.Bundle.Price))).Float32()
|
|
|
|
//}
|
2025-03-25 08:30:58 +00:00
|
|
|
|
2025-02-20 12:55:54 +00:00
|
|
|
req.BundleName = bundleDetail.Bundle.Name
|
|
|
|
req.Amount = bundleDetail.Bundle.Price
|
|
|
|
req.AmountType = bundleDetail.Bundle.PriceType
|
2025-03-28 21:02:05 +00:00
|
|
|
req.BundleCommonUid = bundleDetail.Bundle.BundleCommonUid
|
2025-06-12 08:38:55 +00:00
|
|
|
req.TotalAmount = bundleDetail.Bundle.Price
|
2025-02-22 12:31:26 +00:00
|
|
|
req.PayType = 1 // 默认 人民币
|
2025-06-12 08:38:55 +00:00
|
|
|
//获取过期时间和增值服务金额
|
|
|
|
PriceAndTime, err := service.BundleProvider.PackagePriceAndTime(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//套餐金额+增值服务金额
|
|
|
|
totalAmount := PriceAndTime.Price + bundleDetail.Bundle.Price
|
2025-03-12 02:56:27 +00:00
|
|
|
req.ContractNo = common.GenerateContractNo(lastContractNo)
|
|
|
|
|
2025-06-12 08:38:55 +00:00
|
|
|
// 当前 未将 签名 写入合同中 todo 金额和有效时间待修改
|
|
|
|
signContract, signContractErr := logic.SignContractV2(req.CustomerNum, bundleDetail.Bundle.Contract, totalAmount, PriceAndTime.Time)
|
2025-02-22 07:31:21 +00:00
|
|
|
if signContractErr != nil {
|
|
|
|
service.Error(c, signContractErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
req.SignContract = signContract
|
2025-02-20 12:55:54 +00:00
|
|
|
|
|
|
|
req.SignedTime = common.GetBeijingTime()
|
|
|
|
|
2025-02-21 13:09:29 +00:00
|
|
|
req.Status = bundleModel.OrderSigned
|
|
|
|
|
2025-02-20 12:55:54 +00:00
|
|
|
res, err := service.BundleProvider.CreateOrderRecord(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service.Success(c, res)
|
|
|
|
}
|
|
|
|
|
2025-02-21 13:09:29 +00:00
|
|
|
func UpdateBundleOrderStatusPaid(c *gin.Context) {
|
2025-02-20 12:55:54 +00:00
|
|
|
var req bundle.OrderRecord
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取 用户信息
|
2025-02-21 13:09:29 +00:00
|
|
|
userInfo := login.GetUserInfoFromC(c)
|
|
|
|
|
|
|
|
if req.Uuid == "" {
|
2025-02-22 11:36:25 +00:00
|
|
|
service.Error(c, errors.New(common.MissOrderUUID))
|
2025-02-21 13:09:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
detail, detailErr := service.BundleProvider.OrderRecordsDetail(context.Background(), &bundle.OrderRecordsDetailRequest{
|
|
|
|
Uuid: req.Uuid,
|
|
|
|
})
|
|
|
|
|
|
|
|
if detailErr != nil {
|
2025-02-22 11:36:25 +00:00
|
|
|
service.Error(c, detailErr)
|
2025-02-21 13:09:29 +00:00
|
|
|
return
|
|
|
|
}
|
2025-02-20 12:55:54 +00:00
|
|
|
|
|
|
|
// 判断 是否是 本人操作
|
2025-02-21 13:09:29 +00:00
|
|
|
if strconv.FormatUint(userInfo.ID, 10) != detail.OrderRecord.CustomerID {
|
|
|
|
service.Error(c, errors.New(common.NotMatchOrderInfo))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-02-23 02:42:41 +00:00
|
|
|
// 如果 当前订单 是 已签未支付 且 存在 checkoutSessionId 需要 查询 支付结果
|
|
|
|
if detail.OrderRecord.Status == bundleModel.OrderSigned && detail.OrderRecord.CheckoutSessionId != "" && detail.OrderRecord.PayTime == "" {
|
|
|
|
// 查询支付结果
|
|
|
|
stripeInfosRes, stripeInfosErr := service.OrderProvider.QueryStripeInfoByCheckSessionIds(context.Background(), &order.QueryStripeInfoRequest{
|
|
|
|
CheckoutSessionIds: []string{detail.OrderRecord.CheckoutSessionId},
|
|
|
|
})
|
2025-02-21 13:09:29 +00:00
|
|
|
|
2025-02-23 02:42:41 +00:00
|
|
|
if stripeInfosErr != nil {
|
|
|
|
service.Error(c, errors.New(common.ErrorQueryStripeInfo))
|
|
|
|
return
|
|
|
|
}
|
2025-02-20 12:55:54 +00:00
|
|
|
|
2025-02-23 03:11:31 +00:00
|
|
|
totalStripe := 0
|
|
|
|
|
2025-02-23 02:42:41 +00:00
|
|
|
if stripeInfosRes != nil && len(stripeInfosRes.StripeInfos) > 0 {
|
2025-02-23 03:11:31 +00:00
|
|
|
totalStripe = len(stripeInfosRes.StripeInfos)
|
2025-02-23 02:42:41 +00:00
|
|
|
for _, stripeInfo := range stripeInfosRes.StripeInfos {
|
|
|
|
if stripeInfo.OutTradeNo == detail.OrderRecord.OrderNo && stripeInfo.PaymentIntentStatus == "paid" {
|
|
|
|
_, updateOrderRecordErr := service.BundleProvider.UpdateOrderRecord(context.Background(), &bundle.OrderRecord{
|
|
|
|
Uuid: detail.OrderRecord.Uuid,
|
|
|
|
Status: bundleModel.OrderPaid,
|
|
|
|
PayTime: common.GetBeijingTime(),
|
|
|
|
})
|
|
|
|
if updateOrderRecordErr != nil {
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
return
|
|
|
|
}
|
2025-02-23 03:11:31 +00:00
|
|
|
totalStripe--
|
2025-02-23 02:42:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-02-23 03:11:31 +00:00
|
|
|
|
|
|
|
if totalStripe != 0 && totalStripe == len(stripeInfosRes.StripeInfos) {
|
|
|
|
_, updateOrderRecordErr := service.BundleProvider.UpdateOrderRecord(context.Background(), &bundle.OrderRecord{
|
|
|
|
Uuid: detail.OrderRecord.Uuid,
|
|
|
|
CheckoutSessionId: "",
|
|
|
|
CheckoutSessionUrl: "",
|
|
|
|
})
|
|
|
|
if updateOrderRecordErr != nil {
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2025-02-20 12:55:54 +00:00
|
|
|
}
|
|
|
|
|
2025-02-23 02:42:41 +00:00
|
|
|
service.Success(c, nil)
|
2025-02-20 12:55:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func OrderRecordsList(c *gin.Context) {
|
|
|
|
var req bundle.OrderRecordsRequest
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取 用户信息
|
2025-02-23 06:24:02 +00:00
|
|
|
//userInfo := login.GetUserInfoFromC(c)
|
2025-02-23 05:42:23 +00:00
|
|
|
|
2025-02-23 06:24:02 +00:00
|
|
|
//req.CustomerID = strconv.FormatUint(userInfo.ID, 10)
|
2025-02-20 12:55:54 +00:00
|
|
|
|
|
|
|
res, err := service.BundleProvider.OrderRecordsList(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-28 10:51:15 +00:00
|
|
|
for _, orderRecord := range res.OrderRecords {
|
|
|
|
if orderRecord.CustomerID != "" {
|
|
|
|
var userID uint64
|
|
|
|
userID, err = strconv.ParseUint(orderRecord.CustomerID, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = nil
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2025-05-26 08:31:38 +00:00
|
|
|
userInfo, _ := service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
|
2025-03-28 10:51:15 +00:00
|
|
|
Domain: "app",
|
|
|
|
ID: userID,
|
|
|
|
})
|
|
|
|
if userInfo != nil {
|
|
|
|
orderRecord.Sex = userInfo.Sex
|
|
|
|
orderRecord.Nationality = userInfo.Nationality
|
|
|
|
orderRecord.CertificatePicture = userInfo.CertificatePicture
|
|
|
|
orderRecord.PlaceOfResidence = userInfo.PlaceOfResidence
|
|
|
|
orderRecord.GroupPhoto = userInfo.GroupPhoto
|
2025-05-09 03:12:33 +00:00
|
|
|
orderRecord.TelNum = userInfo.TelNum
|
2025-03-28 10:51:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-02-20 12:55:54 +00:00
|
|
|
service.Success(c, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OrderRecordsDetail(c *gin.Context) {
|
|
|
|
var req bundle.OrderRecordsDetailRequest
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-03-28 16:39:15 +00:00
|
|
|
/*// 获取 用户信息
|
2025-02-23 12:57:14 +00:00
|
|
|
userInfo := login.GetUserInfoFromC(c)
|
|
|
|
|
2025-03-28 16:39:15 +00:00
|
|
|
req.CustomerID = strconv.FormatUint(userInfo.ID, 10)*/
|
2025-02-20 12:55:54 +00:00
|
|
|
|
|
|
|
res, err := service.BundleProvider.OrderRecordsDetail(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service.Success(c, res)
|
|
|
|
}
|
2025-05-09 03:12:33 +00:00
|
|
|
|
|
|
|
// web
|
|
|
|
func UpdateFinancialConfirmationStatus(c *gin.Context) {
|
|
|
|
var req bundle.FinancialConfirmationRequest
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-05-12 03:22:22 +00:00
|
|
|
// 不限制 支付状态 未支付 也可确认
|
|
|
|
//detail, err := service.BundleProvider.OrderRecordsDetail(context.Background(), &bundle.OrderRecordsDetailRequest{
|
|
|
|
// OrderNo: req.OrderNo,
|
|
|
|
//})
|
|
|
|
//if err != nil {
|
|
|
|
// service.Error(c, err)
|
|
|
|
// return
|
|
|
|
//}
|
|
|
|
//if detail.OrderRecord.Status != bundleModel.OrderPaid {
|
|
|
|
// service.Error(c, errors.New("订单未支付,不可确认"))
|
|
|
|
// return
|
|
|
|
//}
|
2025-05-09 07:40:35 +00:00
|
|
|
|
2025-05-09 03:12:33 +00:00
|
|
|
res, err := service.BundleProvider.UpdateFinancialConfirmationStatus(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service.Success(c, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExportOrderInfo(c *gin.Context) {
|
|
|
|
var req bundle.OrderRecordsRequest
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := service.BundleProvider.OrderRecordsList(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-05-12 05:44:09 +00:00
|
|
|
rows := make([][]interface{}, 0)
|
2025-05-09 03:12:33 +00:00
|
|
|
|
|
|
|
for _, orderRecord := range res.OrderRecords {
|
|
|
|
if orderRecord.CustomerID != "" {
|
|
|
|
var userID uint64
|
|
|
|
userID, err = strconv.ParseUint(orderRecord.CustomerID, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = nil
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2025-05-26 08:31:38 +00:00
|
|
|
userInfo, _ := service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
|
2025-05-09 03:12:33 +00:00
|
|
|
Domain: "app",
|
|
|
|
ID: userID,
|
|
|
|
})
|
|
|
|
if userInfo != nil {
|
|
|
|
orderRecord.Sex = userInfo.Sex
|
|
|
|
orderRecord.Nationality = userInfo.Nationality
|
|
|
|
orderRecord.TelNum = userInfo.TelNum
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status := ""
|
2025-05-09 08:24:39 +00:00
|
|
|
if orderRecord.Status == bundleModel.OrderSigned {
|
2025-05-09 03:12:33 +00:00
|
|
|
status = "未支付"
|
2025-05-09 08:24:39 +00:00
|
|
|
} else if orderRecord.Status == bundleModel.OrderPaid {
|
2025-05-09 03:12:33 +00:00
|
|
|
status = "已支付"
|
|
|
|
}
|
|
|
|
financialConfirmation := ""
|
2025-05-09 08:24:39 +00:00
|
|
|
if orderRecord.FinancialConfirmation == bundleModel.UnConfirm {
|
2025-05-09 03:12:33 +00:00
|
|
|
financialConfirmation = "未确认"
|
2025-05-09 08:24:39 +00:00
|
|
|
} else if orderRecord.FinancialConfirmation == bundleModel.Confirmed {
|
2025-05-09 03:12:33 +00:00
|
|
|
financialConfirmation = "已确认"
|
|
|
|
}
|
|
|
|
|
|
|
|
rows = append(rows, []interface{}{
|
|
|
|
orderRecord.OrderNo,
|
|
|
|
orderRecord.CustomerNum,
|
|
|
|
orderRecord.CustomerName,
|
|
|
|
orderRecord.Sex,
|
|
|
|
orderRecord.TelNum,
|
|
|
|
orderRecord.Nationality,
|
|
|
|
orderRecord.BundleName,
|
|
|
|
orderRecord.SignedTime,
|
|
|
|
orderRecord.Amount,
|
|
|
|
orderRecord.Num,
|
|
|
|
orderRecord.ValueAddBundleAmount,
|
|
|
|
orderRecord.TotalAmount,
|
|
|
|
status,
|
|
|
|
orderRecord.PayTime,
|
|
|
|
financialConfirmation,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
dirPath := "./runtime"
|
|
|
|
|
|
|
|
filePath, err := logic.WriteToExcel(dirPath, rows)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-05-09 08:48:45 +00:00
|
|
|
var httpType string = "http" // Default to http
|
|
|
|
|
|
|
|
// Safely check if Origin exists in c.Keys
|
|
|
|
if origin, exists := c.Keys["Origin"]; exists && origin != nil {
|
|
|
|
originStr, ok := origin.(string)
|
|
|
|
if ok && originStr != "" {
|
|
|
|
fmt.Printf("c.Request.Origin %+v\n", originStr)
|
|
|
|
parts := strings.Split(originStr, ":")
|
|
|
|
if len(parts) > 0 {
|
|
|
|
httpType = parts[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Fallback: Check if the request was made over TLS
|
|
|
|
if c.Request.TLS != nil || c.Request.Header.Get("X-Forwarded-Proto") == "https" {
|
|
|
|
httpType = "https"
|
|
|
|
}
|
|
|
|
}
|
2025-05-09 08:38:21 +00:00
|
|
|
|
2025-05-27 02:46:36 +00:00
|
|
|
var exportUrl = strings.Replace(strings.Replace(filePath, ".", fmt.Sprintf("%s://%s", httpType, c.Request.Host), 1), "runtime", "api/fiee/static", 1)
|
2025-05-09 03:12:33 +00:00
|
|
|
//var exportUrl = fmt.Sprintf("%s%s/%s", httpType, c.Request.Host, dirPath + path)
|
2025-05-09 08:58:59 +00:00
|
|
|
fmt.Println("exportUrl : ", exportUrl)
|
2025-05-09 08:52:42 +00:00
|
|
|
service.Success(c, &bundleModel.ExportResponse{ExportUrl: exportUrl})
|
2025-05-09 03:12:33 +00:00
|
|
|
}
|
2025-05-27 02:46:36 +00:00
|
|
|
|
|
|
|
func ExportOrderInfoOss(c *gin.Context) {
|
|
|
|
var req bundle.OrderRecordsRequest
|
|
|
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := service.BundleProvider.OrderRecordsList(context.Background(), &req)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
rows := make([][]interface{}, 0)
|
|
|
|
|
|
|
|
for _, orderRecord := range res.OrderRecords {
|
|
|
|
if orderRecord.CustomerID != "" {
|
|
|
|
var userID uint64
|
|
|
|
userID, err = strconv.ParseUint(orderRecord.CustomerID, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
err = nil
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2025-05-27 02:56:19 +00:00
|
|
|
userInfo, _ := service.AccountFieeProvider.Info(context.Background(), &accountFiee.InfoRequest{
|
2025-05-27 02:46:36 +00:00
|
|
|
Domain: "app",
|
|
|
|
ID: userID,
|
|
|
|
})
|
|
|
|
if userInfo != nil {
|
|
|
|
orderRecord.Sex = userInfo.Sex
|
|
|
|
orderRecord.Nationality = userInfo.Nationality
|
|
|
|
orderRecord.TelNum = userInfo.TelNum
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status := ""
|
|
|
|
if orderRecord.Status == bundleModel.OrderSigned {
|
|
|
|
status = "未支付"
|
|
|
|
} else if orderRecord.Status == bundleModel.OrderPaid {
|
|
|
|
status = "已支付"
|
|
|
|
}
|
|
|
|
financialConfirmation := ""
|
|
|
|
if orderRecord.FinancialConfirmation == bundleModel.UnConfirm {
|
|
|
|
financialConfirmation = "未确认"
|
|
|
|
} else if orderRecord.FinancialConfirmation == bundleModel.Confirmed {
|
|
|
|
financialConfirmation = "已确认"
|
|
|
|
}
|
|
|
|
|
|
|
|
rows = append(rows, []interface{}{
|
|
|
|
orderRecord.OrderNo,
|
|
|
|
orderRecord.CustomerNum,
|
|
|
|
orderRecord.CustomerName,
|
|
|
|
orderRecord.Sex,
|
|
|
|
orderRecord.TelNum,
|
|
|
|
orderRecord.Nationality,
|
|
|
|
orderRecord.BundleName,
|
|
|
|
orderRecord.SignedTime,
|
|
|
|
orderRecord.Amount,
|
|
|
|
orderRecord.Num,
|
|
|
|
orderRecord.ValueAddBundleAmount,
|
|
|
|
orderRecord.TotalAmount,
|
|
|
|
status,
|
|
|
|
orderRecord.PayTime,
|
|
|
|
financialConfirmation,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
dirPath := "./runtime"
|
|
|
|
|
|
|
|
filePath, err := logic.WriteToExcel(dirPath, rows)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
exportUrl, err := upload.PutBos(filePath, "excel", true)
|
|
|
|
if err != nil {
|
|
|
|
service.Error(c, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service.Success(c, &bundleModel.ExportResponse{ExportUrl: exportUrl})
|
|
|
|
}
|