2025-06-15 02:06:57 +00:00
|
|
|
|
package bundle
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-07-07 05:32:19 +00:00
|
|
|
|
"fmt"
|
|
|
|
|
"fonchain-fiee/api/accountFiee"
|
2025-06-15 02:06:57 +00:00
|
|
|
|
"fonchain-fiee/api/bundle"
|
|
|
|
|
"fonchain-fiee/pkg/service"
|
2025-07-07 05:32:19 +00:00
|
|
|
|
"fonchain-fiee/pkg/service/bundle/common"
|
|
|
|
|
bundleModel "fonchain-fiee/pkg/service/bundle/model"
|
2025-06-15 07:27:51 +00:00
|
|
|
|
"fonchain-fiee/pkg/utils"
|
2025-06-15 02:06:57 +00:00
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/gin-gonic/gin/binding"
|
2025-07-07 05:32:19 +00:00
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
2025-06-15 02:06:57 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GetReconciliationList(c *gin.Context) {
|
|
|
|
|
var req bundle.GetReconciliationListReq
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
detail, detailErr := service.BundleProvider.GetReconciliationList(context.Background(), &req)
|
|
|
|
|
if detailErr != nil {
|
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
service.Success(c, detail)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
}
|
2025-06-15 07:27:51 +00:00
|
|
|
|
|
|
|
|
|
func GetReconciliationListDownload(c *gin.Context) {
|
|
|
|
|
var req bundle.GetReconciliationListReq
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
detail, detailErr := service.BundleProvider.GetReconciliationList(context.Background(), &req)
|
|
|
|
|
if detailErr != nil {
|
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
titleList := []string{
|
|
|
|
|
"关联套餐订单号", "关联增值服务订单号", "对账单创建时间", "艺人", "艺人手机号", "套餐", "支付金额", "币种", "支付渠道", "支付时间", "支付状态", "流水号",
|
|
|
|
|
}
|
|
|
|
|
var dataList []interface{}
|
|
|
|
|
|
|
|
|
|
for _, i := range detail.List {
|
|
|
|
|
payStatus := GetPayStatusText(i.PayStatus)
|
|
|
|
|
currencyType := GetCurrencyTypeText(i.CurrencyType)
|
|
|
|
|
payChannel := "未知"
|
|
|
|
|
if i.PayChannel == 1 {
|
|
|
|
|
payChannel = "支付宝"
|
|
|
|
|
}
|
|
|
|
|
data := []any{
|
|
|
|
|
i.BundleOrderOn,
|
|
|
|
|
i.BundleAddOrderOn,
|
|
|
|
|
i.CreationTime,
|
|
|
|
|
i.UserName,
|
|
|
|
|
i.UserTel,
|
|
|
|
|
i.BundleName,
|
|
|
|
|
i.PayAmount,
|
|
|
|
|
currencyType,
|
|
|
|
|
payChannel,
|
|
|
|
|
i.PayTime,
|
|
|
|
|
payStatus,
|
|
|
|
|
i.SerialNumber,
|
|
|
|
|
}
|
|
|
|
|
dataList = append(dataList, &data)
|
|
|
|
|
}
|
|
|
|
|
content, err := utils.ToExcelByType(titleList, dataList, "slice", "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
utils.ResponseXls(c, content, "对账单")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
}
|
2025-07-07 05:32:19 +00:00
|
|
|
|
|
|
|
|
|
func AutoCreateUserAndOrder(c *gin.Context) {
|
|
|
|
|
var req bundle.AutoCreateUserAndOrderRequest
|
|
|
|
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("==================== 111111111111111")
|
|
|
|
|
data, listErr := service.BundleProvider.ListUnfinishedInfos(context.Background(), &req)
|
|
|
|
|
if listErr != nil {
|
|
|
|
|
service.Error(c, listErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if data != nil {
|
|
|
|
|
fmt.Println("待处理的数据量:", len(data.UnfinishedInfos))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, unfinishInfo := range data.UnfinishedInfos {
|
|
|
|
|
fmt.Println("==================== 2222222222222")
|
|
|
|
|
// TODO 1.创建实名用户 [ok]
|
|
|
|
|
userReq := new(accountFiee.CreateUserAndRealNameRequest)
|
|
|
|
|
userReq.UserNum = unfinishInfo.UserNum
|
|
|
|
|
userReq.UserName = unfinishInfo.UserName
|
|
|
|
|
userReq.UserTelArea = unfinishInfo.UserTelArea
|
|
|
|
|
userReq.UserTel = unfinishInfo.UserTel
|
|
|
|
|
userReq.UserSex = unfinishInfo.UserSex
|
|
|
|
|
userReq.Nationality = unfinishInfo.Nationality
|
|
|
|
|
userReq.PlaceOfResidence = unfinishInfo.PlaceOfResidence
|
|
|
|
|
userReq.DocumentType = unfinishInfo.DocumentType
|
|
|
|
|
userReq.UserIdCardFrontUrl = unfinishInfo.UserIdCardFrontUrl
|
|
|
|
|
userReq.UserIdCardReverseUrl = unfinishInfo.UserIdCardReverseUrl
|
|
|
|
|
userReq.UserIdCardValidity = unfinishInfo.UserIdCardValidity
|
|
|
|
|
// 解析时间字符串
|
|
|
|
|
loc, _ := time.LoadLocation("Local")
|
|
|
|
|
t, err := time.ParseInLocation("2006-01-02 15:04:05", unfinishInfo.PayTime, loc)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("解析时间失败:", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 减去一天
|
|
|
|
|
oneDayBefore := t.AddDate(0, 0, -1)
|
|
|
|
|
|
|
|
|
|
// 格式化为字符串
|
|
|
|
|
userReq.AuditTime = oneDayBefore.Format("2006-01-02 15:04:05")
|
|
|
|
|
userResp, userErr := service.AccountFieeProvider.CreateUserAndRealName(context.Background(), userReq)
|
|
|
|
|
if userErr != nil {
|
|
|
|
|
service.Error(c, userErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("==================== 3333333333333")
|
|
|
|
|
// TODO 2.匹配套餐并签约? []
|
|
|
|
|
|
|
|
|
|
//主套餐1500,固定的,uuid写死,不同金额对应uuiid
|
|
|
|
|
//
|
|
|
|
|
//增3条-30条,
|
|
|
|
|
//map【美元金额】=uuid
|
|
|
|
|
numMap := make(map[string]int)
|
|
|
|
|
numMap["3150"] = 3
|
|
|
|
|
numMap["5600"] = 8
|
|
|
|
|
numMap["6500"] = 10
|
|
|
|
|
numMap["8500"] = 15
|
|
|
|
|
numMap["10500"] = 20
|
|
|
|
|
numMap["11500"] = 25
|
|
|
|
|
numMap["14100"] = 30
|
|
|
|
|
|
|
|
|
|
fmt.Println("==================== 44444444444444444")
|
|
|
|
|
// TODO 3.创建成功的订单和回调 [ok]
|
|
|
|
|
////创建对账单 todo 待修改
|
|
|
|
|
|
|
|
|
|
// outTradeNo就是orderNo,根据这个去查询子表的source,如果是2就时单独的子套餐,如果是1就是主套餐
|
|
|
|
|
orderLimit, err := service.BundleProvider.OrderListByOrderNo(context.Background(), &bundle.OrderInfoByOrderNoRequest{
|
|
|
|
|
OrderNo: unfinishInfo.OrderNo,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("=============== antom创建支付,查询订单source报错:", err)
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bundleName := "" // 套餐名称
|
|
|
|
|
detail, detailErr := service.BundleProvider.OrderRecordsDetail(context.Background(), &bundle.OrderRecordsDetailRequest{
|
|
|
|
|
OrderNo: unfinishInfo.OrderNo,
|
|
|
|
|
})
|
|
|
|
|
if detailErr != nil {
|
|
|
|
|
fmt.Println("=============== antom创建支付,查询主订单信息报错:", detailErr)
|
|
|
|
|
service.Error(c, detailErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("detail.OrderRecord.Status :", detail.OrderRecord.Status)
|
|
|
|
|
fmt.Println("detail.OrderRecord.CheckoutSessionId :", detail.OrderRecord.CheckoutSessionId)
|
|
|
|
|
fmt.Println("detail.OrderRecord.PayTime :", detail.OrderRecord.PayTime)
|
|
|
|
|
|
|
|
|
|
bundleName = detail.OrderRecord.BundleName
|
|
|
|
|
payAmount, err := strconv.ParseFloat(unfinishInfo.OrderPayAmount, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("转换失败:", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = service.BundleProvider.CreateReconciliation(context.Background(), &bundle.ReconciliationInfo{
|
|
|
|
|
BundleOrderOn: unfinishInfo.OrderNo,
|
|
|
|
|
BundleAddOrderOn: unfinishInfo.OrderNo,
|
|
|
|
|
UserName: unfinishInfo.UserName,
|
|
|
|
|
UserTel: unfinishInfo.UserTel,
|
|
|
|
|
BundleName: bundleName,
|
|
|
|
|
PayAmount: float32(payAmount),
|
|
|
|
|
CurrencyType: 2,
|
|
|
|
|
PayStatus: 2,
|
|
|
|
|
PayTime: unfinishInfo.PayTime,
|
|
|
|
|
UserID: uint64(userResp.UserId),
|
|
|
|
|
SerialNumber: "zero-price-serial-number",
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("=============== antom创建支付,创建对账单报错:", err)
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, updateStatusErr := service.BundleProvider.UpdateOrderRecordByOrderNo(context.Background(), &bundle.OrderRecord{
|
|
|
|
|
OrderNo: unfinishInfo.OrderNo,
|
|
|
|
|
PayTime: unfinishInfo.PayTime,
|
|
|
|
|
Status: bundleModel.OrderPaid,
|
|
|
|
|
})
|
|
|
|
|
if updateStatusErr != nil {
|
|
|
|
|
fmt.Println("=============== antom创建支付,更新订单报错:", updateStatusErr)
|
|
|
|
|
service.Error(c, updateStatusErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//如果是购买套餐 1:创建新的余量信息CreateBundleBalance 2 添加扩展记录BundleExtend
|
|
|
|
|
_, err = service.BundleProvider.CreateBundleBalance(context.Background(), &bundle.CreateBundleBalanceReq{
|
|
|
|
|
UserId: int32(userResp.UserId),
|
|
|
|
|
OrderUUID: orderLimit.OrderUUID,
|
|
|
|
|
//AccountNumber: orderLimit.AccountNumber,
|
|
|
|
|
//VideoNumber: orderLimit.VideoNumber,
|
|
|
|
|
//ImageNumber: orderLimit.ImageNumber,
|
|
|
|
|
//DataAnalysisNumber: orderLimit.DataNumber,
|
|
|
|
|
ExpansionPacksNumber: 1,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("=============== antom创建支付,OrderTypePackage报错:", err)
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var timeUnit uint32
|
|
|
|
|
switch orderLimit.Unit {
|
|
|
|
|
case "天":
|
|
|
|
|
timeUnit = common.TimeUnitDay
|
|
|
|
|
case "月":
|
|
|
|
|
timeUnit = common.TimeUnitMonth
|
|
|
|
|
case "年":
|
|
|
|
|
timeUnit = common.TimeUnitYear
|
|
|
|
|
default:
|
|
|
|
|
timeUnit = 0
|
|
|
|
|
}
|
|
|
|
|
_, err = service.BundleProvider.BundleExtend(context.Background(), &bundle.BundleExtendRequest{
|
|
|
|
|
UserId: int64(orderLimit.UserId),
|
|
|
|
|
AccountAdditional: uint32(orderLimit.AccountNumber),
|
|
|
|
|
VideoAdditional: uint32(orderLimit.VideoNumber),
|
|
|
|
|
ImagesAdditional: uint32(orderLimit.ImageNumber),
|
|
|
|
|
DataAdditional: uint32(orderLimit.DataNumber),
|
|
|
|
|
AvailableDurationAdditional: uint32(orderLimit.Duration),
|
|
|
|
|
TimeUnit: timeUnit,
|
|
|
|
|
AssociatedorderNumber: unfinishInfo.OrderNo, //增值服务订单号
|
|
|
|
|
Type: 2, //自行购买
|
|
|
|
|
OperatorName: orderLimit.UserName,
|
|
|
|
|
OperatorId: orderLimit.UserId,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
service.Error(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("==================== 5555555555555555555")
|
|
|
|
|
// TODO 4.软删除未删除信息 [ok]
|
|
|
|
|
deleteReq := new(bundle.SoftDeleteUnfinishedInfoRequest)
|
|
|
|
|
deleteReq.ID = unfinishInfo.ID
|
|
|
|
|
_, deleteErr := service.BundleProvider.SoftDeleteUnfinishedInfo(context.Background(), deleteReq)
|
|
|
|
|
if deleteErr != nil {
|
|
|
|
|
service.Error(c, deleteErr)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("==================== 66666666666666666")
|
|
|
|
|
service.Success(c)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
}
|