Merge branch 'feat-zjy-issue-008' into main

# Conflicts:
#	api/bundle/bundle.pb.go
#	api/bundle/bundle_triple.pb.go
#	docs/dev/dubbogo.yaml
#	pkg/router/bundle.go
#	pkg/service/init.go
This commit is contained in:
周俊耀 2025-06-26 17:07:16 +08:00
commit bbf093e104
8 changed files with 2441 additions and 2291 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-triple. DO NOT EDIT. // Code generated by protoc-gen-go-triple. DO NOT EDIT.
// versions: // versions:
// - protoc-gen-go-triple v1.0.8 // - protoc-gen-go-triple v1.0.8
// - protoc v4.24.0--rc1 // - protoc v3.20.3
// source: pb/bundle.proto // source: pb/bundle.proto
package bundle package bundle
@ -36,7 +36,6 @@ type BundleClient interface {
BundleListV2(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) BundleListV2(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment)
BundleDetailV2(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponseV2, common.ErrorWithAttachment) BundleDetailV2(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponseV2, common.ErrorWithAttachment)
BundleListH5V2(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) BundleListH5V2(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment)
BundleLangDetailV2(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleProfileLang, common.ErrorWithAttachment)
BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment)
BundleDetail(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponse, common.ErrorWithAttachment) BundleDetail(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleDetailResponse, common.ErrorWithAttachment)
CreateOrderRecord(ctx context.Context, in *OrderCreateRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) CreateOrderRecord(ctx context.Context, in *OrderCreateRecord, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment)
@ -95,7 +94,6 @@ type BundleClientImpl struct {
BundleListV2 func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error) BundleListV2 func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error)
BundleDetailV2 func(ctx context.Context, in *BundleDetailRequest) (*BundleDetailResponseV2, error) BundleDetailV2 func(ctx context.Context, in *BundleDetailRequest) (*BundleDetailResponseV2, error)
BundleListH5V2 func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error) BundleListH5V2 func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error)
BundleLangDetailV2 func(ctx context.Context, in *BundleDetailRequest) (*BundleProfileLang, error)
BundleList func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error) BundleList func(ctx context.Context, in *BundleListRequest) (*BundleListResponse, error)
BundleDetail func(ctx context.Context, in *BundleDetailRequest) (*BundleDetailResponse, error) BundleDetail func(ctx context.Context, in *BundleDetailRequest) (*BundleDetailResponse, error)
CreateOrderRecord func(ctx context.Context, in *OrderCreateRecord) (*CommonResponse, error) CreateOrderRecord func(ctx context.Context, in *OrderCreateRecord) (*CommonResponse, error)
@ -196,12 +194,6 @@ func (c *bundleClient) BundleListH5V2(ctx context.Context, in *BundleListRequest
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleListH5V2", in, out) return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleListH5V2", in, out)
} }
func (c *bundleClient) BundleLangDetailV2(ctx context.Context, in *BundleDetailRequest, opts ...grpc_go.CallOption) (*BundleProfileLang, common.ErrorWithAttachment) {
out := new(BundleProfileLang)
interfaceKey := ctx.Value(constant.InterfaceKey).(string)
return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/BundleLangDetailV2", in, out)
}
func (c *bundleClient) BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) { func (c *bundleClient) BundleList(ctx context.Context, in *BundleListRequest, opts ...grpc_go.CallOption) (*BundleListResponse, common.ErrorWithAttachment) {
out := new(BundleListResponse) out := new(BundleListResponse)
interfaceKey := ctx.Value(constant.InterfaceKey).(string) interfaceKey := ctx.Value(constant.InterfaceKey).(string)
@ -442,7 +434,6 @@ type BundleServer interface {
BundleListV2(context.Context, *BundleListRequest) (*BundleListResponse, error) BundleListV2(context.Context, *BundleListRequest) (*BundleListResponse, error)
BundleDetailV2(context.Context, *BundleDetailRequest) (*BundleDetailResponseV2, error) BundleDetailV2(context.Context, *BundleDetailRequest) (*BundleDetailResponseV2, error)
BundleListH5V2(context.Context, *BundleListRequest) (*BundleListResponse, error) BundleListH5V2(context.Context, *BundleListRequest) (*BundleListResponse, error)
BundleLangDetailV2(context.Context, *BundleDetailRequest) (*BundleProfileLang, error)
BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error) BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error)
BundleDetail(context.Context, *BundleDetailRequest) (*BundleDetailResponse, error) BundleDetail(context.Context, *BundleDetailRequest) (*BundleDetailResponse, error)
CreateOrderRecord(context.Context, *OrderCreateRecord) (*CommonResponse, error) CreateOrderRecord(context.Context, *OrderCreateRecord) (*CommonResponse, error)
@ -518,9 +509,6 @@ func (UnimplementedBundleServer) BundleDetailV2(context.Context, *BundleDetailRe
func (UnimplementedBundleServer) BundleListH5V2(context.Context, *BundleListRequest) (*BundleListResponse, error) { func (UnimplementedBundleServer) BundleListH5V2(context.Context, *BundleListRequest) (*BundleListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BundleListH5V2 not implemented") return nil, status.Errorf(codes.Unimplemented, "method BundleListH5V2 not implemented")
} }
func (UnimplementedBundleServer) BundleLangDetailV2(context.Context, *BundleDetailRequest) (*BundleProfileLang, error) {
return nil, status.Errorf(codes.Unimplemented, "method BundleLangDetailV2 not implemented")
}
func (UnimplementedBundleServer) BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error) { func (UnimplementedBundleServer) BundleList(context.Context, *BundleListRequest) (*BundleListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BundleList not implemented") return nil, status.Errorf(codes.Unimplemented, "method BundleList not implemented")
} }
@ -895,35 +883,6 @@ func _Bundle_BundleListH5V2_Handler(srv interface{}, ctx context.Context, dec fu
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Bundle_BundleLangDetailV2_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(BundleDetailRequest)
if err := dec(in); err != nil {
return nil, err
}
base := srv.(dubbo3.Dubbo3GrpcService)
args := []interface{}{}
args = append(args, in)
md, _ := metadata.FromIncomingContext(ctx)
invAttachment := make(map[string]interface{}, len(md))
for k, v := range md {
invAttachment[k] = v
}
invo := invocation.NewRPCInvocation("BundleLangDetailV2", args, invAttachment)
if interceptor == nil {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
info := &grpc_go.UnaryServerInfo{
Server: srv,
FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string),
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
result := base.XXX_GetProxyImpl().Invoke(ctx, invo)
return result, result.Error()
}
return interceptor(ctx, in, info, handler)
}
func _Bundle_BundleList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) { func _Bundle_BundleList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) {
in := new(BundleListRequest) in := new(BundleListRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
@ -2065,10 +2024,6 @@ var Bundle_ServiceDesc = grpc_go.ServiceDesc{
MethodName: "BundleListH5V2", MethodName: "BundleListH5V2",
Handler: _Bundle_BundleListH5V2_Handler, Handler: _Bundle_BundleListH5V2_Handler,
}, },
{
MethodName: "BundleLangDetailV2",
Handler: _Bundle_BundleLangDetailV2_Handler,
},
{ {
MethodName: "BundleList", MethodName: "BundleList",
Handler: _Bundle_BundleList_Handler, Handler: _Bundle_BundleList_Handler,

View File

@ -21,6 +21,7 @@ func BundleRouter(r *gin.RouterGroup) {
bundleClientRoute.POST("update", bundle.UpdateBundle) bundleClientRoute.POST("update", bundle.UpdateBundle)
bundleClientRoute.POST("remove", bundle.DeleteBundle) bundleClientRoute.POST("remove", bundle.DeleteBundle)
bundleClientRoute.POST("bundle-list", bundle.BundleList) bundleClientRoute.POST("bundle-list", bundle.BundleList)
bundleClientRoute.POST("add-value/only", bundle.OnlyAddValueListByOrderNo)
bundleExtend := bundleClientRoute.Group("extend") bundleExtend := bundleClientRoute.Group("extend")
{ {
@ -33,9 +34,16 @@ func BundleRouter(r *gin.RouterGroup) {
bundleBalance.POST("used-record", bundle.GetUsedRecordList) bundleBalance.POST("used-record", bundle.GetUsedRecordList)
} }
} }
bundleClientRouteV2 := bundleRoute.Group("system/v2")
bundleAppRoute = bundleAppRoute.Group("common")
{ {
bundleClientRouteV2.POST("save", bundle.SaveBundleV2)
bundleClientRouteV2.POST("update/shelfStatus", bundle.HandShelf)
bundleClientRouteV2.POST("bundle-list", bundle.BundleListV2)
bundleClientRouteV2.POST("bundle-detail", bundle.BundleDetailV2)
}
bundleAppRouteV1 := bundleAppRoute.Group("common")
{
bundleAppRouteV1.POST("bundle-list", bundle.BundleList)
bundleAppRoute.POST("bundle-list", bundle.BundleList) bundleAppRoute.POST("bundle-list", bundle.BundleList)
bundleAppRoute.POST("pending-confirmation-list", bundle.GetToBeComfirmedWorks) // 作品状态变更的待确认记录 bundleAppRoute.POST("pending-confirmation-list", bundle.GetToBeComfirmedWorks) // 作品状态变更的待确认记录
@ -45,6 +53,17 @@ func BundleRouter(r *gin.RouterGroup) {
bundleAppRoute.POST("work-detail", bundle.GetWorkDetail) bundleAppRoute.POST("work-detail", bundle.GetWorkDetail)
bundleAppRoute.POST("work-confirm", bundle.WorkConfirm) bundleAppRoute.POST("work-confirm", bundle.WorkConfirm)
} }
bundleAppRouteV2 := bundleAppRoute.Group("app/system/v2")
{
bundleAppRouteV2.POST("bundle-list", bundle.BundleListV2)
bundleAppRouteV2.POST("bundle-detail", bundle.BundleDetailV2)
bundleAppRouteV2.POST("add-value/only", bundle.OnlyAddValueListByOrderNo)
bundleAppRoute.POST("pending-confirmation-list", bundle.GetToBeComfirmedWorks)
bundleAppRoute.POST("balance", bundle.GetUserBalance)
bundleAppRoute.POST("work-detail", bundle.GetWorkDetail)
bundleAppRoute.POST("work-confirm", bundle.WorkConfirm)
}
} }

View File

@ -43,6 +43,7 @@ func BundleOrderRouter(r *gin.RouterGroup) {
{ {
bundleOrderAppRoute.POST("order-signature", bundle.CreateBundleOrderSignature) bundleOrderAppRoute.POST("order-signature", bundle.CreateBundleOrderSignature)
bundleOrderAppRoute.POST("order-add-signature", bundle.CreateBundleOrderAddSignature) bundleOrderAppRoute.POST("order-add-signature", bundle.CreateBundleOrderAddSignature)
bundleOrderAppRoute.POST("order-del", bundle.DeleteBundleOrder)
bundleOrderAppRoute.POST("update-pay", bundle.UpdateBundleOrderStatusPaid) bundleOrderAppRoute.POST("update-pay", bundle.UpdateBundleOrderStatusPaid)
bundleOrderAppRoute.POST("order-detail", bundle.OrderRecordsDetail) bundleOrderAppRoute.POST("order-detail", bundle.OrderRecordsDetail)

View File

@ -156,7 +156,7 @@ func SendMsg(c *gin.Context) {
service.Error(c, err) service.Error(c, err)
return return
} }
service.Success(c, res) service.Success1(c, "发送成功", res)
return return
} else { } else {
res, err := service.AccountFieeProvider.SendMsg(context.Background(), &req) res, err := service.AccountFieeProvider.SendMsg(context.Background(), &req)
@ -165,7 +165,7 @@ func SendMsg(c *gin.Context) {
return return
} }
service.Success(c, res) service.Success1(c, "发送成功", res)
return return
} }

View File

@ -77,3 +77,83 @@ func BundleList(c *gin.Context) {
service.Success(c, res) service.Success(c, res)
} }
func SaveBundleV2(c *gin.Context) {
var req bundle.BundleProfile
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.BundleProvider.SaveBundle(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func BundleListV2(c *gin.Context) {
var req bundle.BundleListRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.BundleProvider.BundleListV2(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func BundleDetailV2(c *gin.Context) {
var req bundle.BundleDetailRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.BundleProvider.BundleDetailV2(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func HandShelf(c *gin.Context) {
var req bundle.HandShelfRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.BundleProvider.HandShelf(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}
func OnlyAddValueListByOrderNo(c *gin.Context) {
var req bundle.OnlyAddValueListByOrderNoRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, err)
return
}
res, err := service.BundleProvider.OnlyAddValueListByOrderNo(context.Background(), &req)
if err != nil {
service.Error(c, err)
return
}
service.Success(c, res)
}

View File

@ -47,6 +47,10 @@ func SignContractV2(customerNum, contract string, price float32, expirationDate
} }
func InsertSignatureV2(templatePath, outputPath string, price float32, expirationDate string) error { func InsertSignatureV2(templatePath, outputPath string, price float32, expirationDate string) error {
fmt.Println("================================templatePath:", templatePath)
fmt.Println("================================outputPath:", outputPath)
fmt.Println("================================price:", price)
fmt.Println("================================expirationDate:", expirationDate)
pdf := gopdf.GoPdf{} pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4}) pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})

View File

@ -2,6 +2,7 @@ package bundle
import ( import (
"context" "context"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -141,41 +142,46 @@ func CreateAntomPay(c *gin.Context) {
// 获取 用户信息 // 获取 用户信息
userInfo := login.GetUserInfoFromC(c) userInfo := login.GetUserInfoFromC(c)
// 检查 订单信息 // outTradeNo就是orderNo根据这个去查询子表的source,如果是2就时单独的子套餐如果是1就是主套餐
orderLimit, err := service.BundleProvider.OrderListByOrderNo(context.Background(), &bundle.OrderInfoByOrderNoRequest{
OrderNo: req.OutTradeNo,
})
if err != nil {
fmt.Println("=============== antom创建支付查询订单source报错", err)
logger.Errorf("=============== antom创建支付查询订单source报错", err)
service.Error(c, err)
return
}
currencyType := 0
if req.ProductPriceCurrency == "cny" || req.ProductPriceCurrency == "CNY" {
currencyType = 1
}
if req.ProductPriceCurrency == "usd" || req.ProductPriceCurrency == "USD" {
currencyType = 2
}
bundleName := "" // 套餐名称
if orderLimit != nil && orderLimit.Type == 1 { // 这儿的type实际就是source
// 检查 订单信息 type是1说明既有主套餐又有增值服务
detail, detailErr := service.BundleProvider.OrderRecordsDetail(context.Background(), &bundle.OrderRecordsDetailRequest{ detail, detailErr := service.BundleProvider.OrderRecordsDetail(context.Background(), &bundle.OrderRecordsDetailRequest{
OrderNo: req.OutTradeNo, OrderNo: req.OutTradeNo,
}) })
if detailErr != nil { if detailErr != nil {
fmt.Println("=============== antom创建支付查询主订单信息报错", detailErr)
logger.Errorf("=============== antom创建支付查询主订单信息报错", detailErr)
service.Error(c, detailErr) service.Error(c, detailErr)
return return
} }
fmt.Println("detail.OrderRecord.CustomerID :", detail.OrderRecord.CustomerID)
// 判断 是否是 本人操作
if strconv.FormatUint(userInfo.ID, 10) != detail.OrderRecord.CustomerID {
service.Error(c, errors.New(common.NotMatchOrderInfo))
return
}
fmt.Println("detail.OrderRecord.TotalAmount :", detail.OrderRecord.TotalAmount)
fmt.Println("req.ProductAllPrice :", req.ProductAllPrice)
fmt.Println("detail.OrderRecord.TotalAmount*100 :", detail.OrderRecord.TotalAmount*100)
//金额校验
orderAmountInCents := int64(math.Round(float64(detail.OrderRecord.TotalAmount * 100)))
reqAmountInCents := int64(math.Round(float64(req.ProductAllPrice)))
if orderAmountInCents != reqAmountInCents {
fmt.Println("111111111111111111111111111111111111")
service.Error(c, errors.New(common.InvalidOrderAmount))
return
}
fmt.Println("detail.OrderRecord.Status :", detail.OrderRecord.Status) fmt.Println("detail.OrderRecord.Status :", detail.OrderRecord.Status)
fmt.Println("detail.OrderRecord.CheckoutSessionId :", detail.OrderRecord.CheckoutSessionId) fmt.Println("detail.OrderRecord.CheckoutSessionId :", detail.OrderRecord.CheckoutSessionId)
fmt.Println("detail.OrderRecord.PayTime :", detail.OrderRecord.PayTime) fmt.Println("detail.OrderRecord.PayTime :", detail.OrderRecord.PayTime)
bundleName = detail.OrderRecord.BundleName
// 主套餐
// 如果 当前订单 是 已签未支付 且 存在 checkoutSessionId 需要 查询 支付结果 // 如果 当前订单 是 已签未支付 且 存在 checkoutSessionId 需要 查询 支付结果
if detail.OrderRecord.Status == bundleModel.OrderSigned && detail.OrderRecord.CheckoutSessionId != "" && detail.OrderRecord.PayTime == "" { if detail.OrderRecord.Status == bundleModel.OrderSigned && detail.OrderRecord.CheckoutSessionId != "" && detail.OrderRecord.PayTime == "" {
// 查询支付结果 // 查询支付结果
@ -191,14 +197,18 @@ func CreateAntomPay(c *gin.Context) {
if stripeInfosRes != nil && len(stripeInfosRes.Infos) > 0 { if stripeInfosRes != nil && len(stripeInfosRes.Infos) > 0 {
for _, info := range stripeInfosRes.Infos { for _, info := range stripeInfosRes.Infos {
if info.OutTradeNo == detail.OrderRecord.OrderNo && info.Status == "paid" { if info.OutTradeNo == detail.OrderRecord.OrderNo && info.Status == "paid" {
_, updateOrderRecordErr := service.BundleProvider.UpdateOrderRecord(context.Background(), &bundle.OrderRecord{ // 更新主套餐和子套餐 TODO
Uuid: detail.OrderRecord.Uuid, // 更新子套餐TODO
Status: bundleModel.OrderPaid, _, updateStatusErr := service.BundleProvider.UpdateOrderRecordByOrderNo(context.Background(), &bundle.OrderRecord{
OrderNo: req.OutTradeNo,
PayTime: common.GetBeijingTime(), PayTime: common.GetBeijingTime(),
Status: bundleModel.OrderPaid,
}) })
fmt.Println("detail.OrderRecord.Uuid :", detail.OrderRecord.Uuid) fmt.Println("detail.OrderRecord.Uuid :", detail.OrderRecord.Uuid)
if updateOrderRecordErr != nil { if updateStatusErr != nil {
service.Error(c, detailErr) fmt.Println("=============== antom创建支付更新主套餐和子套餐支付状态报错", updateStatusErr)
logger.Errorf("=============== antom创建支付更新主套餐和子套餐支付状态报错", updateStatusErr)
service.Error(c, updateStatusErr)
return return
} }
service.Success(c, &service.Response{ service.Success(c, &service.Response{
@ -211,6 +221,213 @@ func CreateAntomPay(c *gin.Context) {
} }
} }
fmt.Println("detail.OrderRecord.CustomerID :", detail.OrderRecord.CustomerID)
// 判断 是否是 本人操作
if strconv.FormatUint(userInfo.ID, 10) != detail.OrderRecord.CustomerID {
service.Error(c, errors.New(common.NotMatchOrderInfo))
return
}
fmt.Println("detail.OrderRecord.TotalAmount :", detail.OrderRecord.TotalAmount)
fmt.Println("req.ProductAllPrice :", req.ProductAllPrice)
fmt.Println("detail.OrderRecord.TotalAmount*100 :", detail.OrderRecord.TotalAmount*100)
//金额校验
orderAmountInCents := int64(math.Round(float64(detail.OrderRecord.TotalAmount) * 100))
reqAmountInCents := req.ProductAllPrice
if orderAmountInCents != reqAmountInCents {
fmt.Println("111111111111111111111111111111111111")
service.Error(c, errors.New(common.InvalidOrderAmount))
return
}
}
if orderLimit != nil && orderLimit.Type == 2 {
res, listErr := service.BundleProvider.OnlyAddValueListByOrderNo(context.Background(), &bundle.OnlyAddValueListByOrderNoRequest{
OrderNo: req.OutTradeNo,
})
if listErr != nil {
fmt.Println("=============== antom创建支付查询单独增值服务列表报错", listErr)
logger.Errorf("=============== antom创建支付查询单独增值服务列表报错", listErr)
service.Error(c, listErr)
return
}
if res != nil && len(res.AddBundleInfos) > 0 {
firstAddBundle := res.AddBundleInfos[0]
// 如果 当前订单 是 已签未支付 且 存在 checkoutSessionId 需要 查询 支付结果
if firstAddBundle.PaymentStatus == bundleModel.OrderSigned && firstAddBundle.CheckOutSessionId != "" {
// 查询支付结果
stripeInfosRes, stripeInfosErr := service.PaymentProvider.QueryAntomPayByCheckoutSessionId(context.Background(), &payment.AntomPayQueryRequest{
CheckoutSessionIds: []string{firstAddBundle.CheckOutSessionId},
})
if stripeInfosErr != nil {
service.Error(c, errors.New(common.ErrorQueryStripeInfo))
return
}
if stripeInfosRes != nil && len(stripeInfosRes.Infos) > 0 {
for _, info := range stripeInfosRes.Infos {
if info.OutTradeNo == firstAddBundle.OrderNo && info.Status == "paid" {
// 更新子套餐TODO
_, updateStatusErr := service.BundleProvider.UpdateOrderRecordByOrderNo(context.Background(), &bundle.OrderRecord{
OrderNo: req.OutTradeNo,
PayTime: common.GetBeijingTime(),
Status: bundleModel.OrderPaid,
})
fmt.Println("req.OutTradeNo :", req.OutTradeNo)
if updateStatusErr != nil {
fmt.Println("=============== antom创建支付更新子套餐支付状态报错", updateStatusErr)
logger.Errorf("=============== antom创建支付更新子套餐支付状态报错", updateStatusErr)
service.Error(c, updateStatusErr)
return
}
service.Success(c, &service.Response{
Msg: common.HadPay,
Code: 0,
})
return
}
}
}
}
fmt.Println("firstAddBundle.CustomerID :", firstAddBundle.CustomerID)
// 判断 是否是 本人操作
if strconv.FormatUint(userInfo.ID, 10) != firstAddBundle.CustomerID {
service.Error(c, errors.New(common.NotMatchOrderInfo))
return
}
orderAmountInCents := int64(0.0)
for _, info := range res.AddBundleInfos {
temp := int64(math.Round(float64(info.Amount) * 100))
orderAmountInCents += temp
}
fmt.Println("orderAmountInCents :", orderAmountInCents)
fmt.Println("req.ProductAllPrice :", req.ProductAllPrice)
//金额校验
reqAmountInCents := req.ProductAllPrice
if orderAmountInCents != reqAmountInCents {
fmt.Println("111111111111111111111111111111111111")
service.Error(c, errors.New(common.InvalidOrderAmount))
return
}
}
}
if req.ProductAllPrice == 0 {
////创建对账单 todo 待修改
_, err = service.BundleProvider.CreateReconciliation(context.Background(), &bundle.ReconciliationInfo{
BundleOrderOn: req.OutTradeNo,
BundleAddOrderOn: req.OutTradeNo,
UserName: userInfo.Name,
UserTel: userInfo.TelNum,
BundleName: bundleName,
PayAmount: float32(req.ProductAllPrice),
CurrencyType: int32(currencyType),
PayStatus: 2,
PayTime: common.GetBeijingTime(),
UserID: userInfo.ID,
SerialNumber: "zero-price-serial-number",
})
if err != nil {
fmt.Println("=============== antom创建支付创建对账单报错", err)
logger.Errorf("=============== antom创建支付创建对账单报错", err)
service.Error(c, err)
return
}
_, updateStatusErr := service.BundleProvider.UpdateOrderRecordByOrderNo(context.Background(), &bundle.OrderRecord{
OrderNo: req.OutTradeNo,
PayTime: common.GetBeijingTime(),
Status: bundleModel.OrderPaid,
})
if updateStatusErr != nil {
fmt.Println("=============== antom创建支付更新订单报错", updateStatusErr)
logger.Errorf("=============== antom创建支付更新订单报错", updateStatusErr)
service.Error(c, updateStatusErr)
return
}
switch orderLimit.Type {
case common.OrderTypePackage:
//如果是购买套餐 1:创建新的余量信息CreateBundleBalance 2 添加扩展记录BundleExtend
_, err = service.BundleProvider.CreateBundleBalance(context.Background(), &bundle.CreateBundleBalanceReq{
UserId: int32(orderLimit.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)
logger.Errorf("=============== antom创建支付OrderTypePackage报错", err)
service.Error(c, err)
return
}
case common.OrderTypeAddon:
//如果是购买增值服务 1:修改余量信息AddBundleBalance 2 添加扩展记录BundleExtend
//_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{
// UserId: int32(orderLimit.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)
// logger.Errorf("=============== antom创建支付OrderTypePackage报错", err)
// service.Error(c, err)
// return
//}
default:
fmt.Println("=============== antom创建支付无效的订单类型", err)
logger.Errorf("=============== antom创建支付无效的订单类型", err)
service.Error(c, errors.New("无效的订单类型"))
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: req.OutTradeNo, //增值服务订单号
Type: 2, //自行购买
})
if err != nil {
service.Error(c, err)
return
}
service.Success(c)
return
}
var antomReq payment.CreatePayRequest var antomReq payment.CreatePayRequest
antomReq.Payee = "Antom" antomReq.Payee = "Antom"
antomReq.Platform = "antom" antomReq.Platform = "antom"
@ -233,9 +450,9 @@ func CreateAntomPay(c *gin.Context) {
fmt.Println("result.CheckoutSessionId :", result.CheckoutSessionId) fmt.Println("result.CheckoutSessionId :", result.CheckoutSessionId)
fmt.Println("result.Url :", result.Url) fmt.Println("result.Url :", result.Url)
//更新订单状态 //更新订单url和checkSessionId
_, updateOrderRecordErr := service.BundleProvider.UpdateOrderRecord(context.Background(), &bundle.OrderRecord{ _, updateStatusErr := service.BundleProvider.UpdateOrderRecordByOrderNo(context.Background(), &bundle.OrderRecord{
Uuid: detail.OrderRecord.Uuid, OrderNo: req.OutTradeNo,
CheckoutSessionId: result.CheckoutSessionId, CheckoutSessionId: result.CheckoutSessionId,
CheckoutSessionUrl: result.Url, CheckoutSessionUrl: result.Url,
}) })
@ -243,25 +460,35 @@ func CreateAntomPay(c *gin.Context) {
resp := &order.CreateStripeCheckoutSessionResponse{} resp := &order.CreateStripeCheckoutSessionResponse{}
resp.CheckoutSessionUrl = result.Url resp.CheckoutSessionUrl = result.Url
resp.CheckoutSessionId = result.CheckoutSessionId resp.CheckoutSessionId = result.CheckoutSessionId
fmt.Println("resp:", resp) fmt.Println("req.OutTradeNo :", req.OutTradeNo)
if updateStatusErr != nil {
if updateOrderRecordErr != nil { fmt.Println("=============== antom创建支付更新订单的请求id报错", updateStatusErr)
fmt.Println("有更新报错:", updateOrderRecordErr) logger.Errorf("=============== antom创建支付更新订单的请求id报错", updateStatusErr)
service.Error(c, updateOrderRecordErr) service.Error(c, updateStatusErr)
return return
} }
fmt.Println("resp:", resp)
////创建对账单 todo 待修改 ////创建对账单 todo 待修改
//_, err = service.BundleProvider.CreateReconciliation(context.Background(), &bundle.ReconciliationInfo{ _, err = service.BundleProvider.CreateReconciliation(context.Background(), &bundle.ReconciliationInfo{
// BundleOrderOn: detail.OrderRecord.OrderNo, BundleOrderOn: req.OutTradeNo,
// BundleAddOrderOn: detail.OrderRecord.OrderNo, BundleAddOrderOn: req.OutTradeNo,
// UserName: userInfo.Name, UserName: userInfo.Name,
// UserTel: userInfo.TelNum, UserTel: userInfo.TelNum,
// BundleName: detail.OrderRecord.BundleName, BundleName: bundleName,
// Amount: detail.OrderRecord.TotalAmount, PayAmount: float32(req.ProductAllPrice),
// CurrencyType: int32(detail.OrderRecord.AmountType), CurrencyType: int32(currencyType),
// PayStatus: 1, PayStatus: 1,
// UserId: userInfo.ID, UserID: userInfo.ID,
//}) SerialNumber: result.CheckoutSessionId,
})
if err != nil {
fmt.Println("=============== antom创建支付创建对账单报错", err)
logger.Errorf("=============== antom创建支付创建对账单报错", err)
service.Error(c, err)
return
}
service.Success(c, resp) service.Success(c, resp)
} }
@ -374,6 +601,19 @@ func AntomWebhook(c *gin.Context) {
service.Error(c, err) service.Error(c, err)
return return
} }
// 更新对账单
_, err = service.BundleProvider.UpdateReconciliationStatusBySerialNumber(context.Background(), &bundle.UpdateStatusAndPayTimeBySerialNumber{
PayTime: paymentTime,
PaymentStatus: 2,
SerialNumber: requestId,
})
if err != nil {
fmt.Println("=============== antom回调更新对账单报错", err)
logger.Errorf("=============== antom回调更新对账单报错", err)
service.Error(c, err)
return
}
//添加余额 //添加余额
orderLimit, err := service.BundleProvider.OrderListByOrderNo(context.Background(), &bundle.OrderInfoByOrderNoRequest{ orderLimit, err := service.BundleProvider.OrderListByOrderNo(context.Background(), &bundle.OrderInfoByOrderNoRequest{
OrderNo: resp.OutTradeNo, OrderNo: resp.OutTradeNo,
@ -389,10 +629,10 @@ func AntomWebhook(c *gin.Context) {
_, err = service.BundleProvider.CreateBundleBalance(context.Background(), &bundle.CreateBundleBalanceReq{ _, err = service.BundleProvider.CreateBundleBalance(context.Background(), &bundle.CreateBundleBalanceReq{
UserId: int32(orderLimit.UserId), UserId: int32(orderLimit.UserId),
OrderUUID: orderLimit.OrderUUID, OrderUUID: orderLimit.OrderUUID,
AccountNumber: orderLimit.AccountNumber, //AccountNumber: orderLimit.AccountNumber,
VideoNumber: orderLimit.VideoNumber, //VideoNumber: orderLimit.VideoNumber,
ImageNumber: orderLimit.ImageNumber, //ImageNumber: orderLimit.ImageNumber,
DataAnalysisNumber: orderLimit.DataNumber, //DataAnalysisNumber: orderLimit.DataNumber,
ExpansionPacksNumber: 1, ExpansionPacksNumber: 1,
}) })
if err != nil { if err != nil {
@ -401,19 +641,19 @@ func AntomWebhook(c *gin.Context) {
} }
case common.OrderTypeAddon: case common.OrderTypeAddon:
//如果是购买增值服务 1:修改余量信息AddBundleBalance 2 添加扩展记录BundleExtend //如果是购买增值服务 1:修改余量信息AddBundleBalance 2 添加扩展记录BundleExtend
_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{ //_, err = service.BundleProvider.AddBundleBalance(context.Background(), &bundle.AddBundleBalanceReq{
UserId: int32(orderLimit.UserId), // UserId: int32(orderLimit.UserId),
OrderUUID: orderLimit.OrderUUID, // OrderUUID: orderLimit.OrderUUID,
AccountNumber: orderLimit.AccountNumber, // AccountNumber: orderLimit.AccountNumber,
VideoNumber: orderLimit.VideoNumber, // VideoNumber: orderLimit.VideoNumber,
ImageNumber: orderLimit.ImageNumber, // ImageNumber: orderLimit.ImageNumber,
DataAnalysisNumber: orderLimit.DataNumber, // DataAnalysisNumber: orderLimit.DataNumber,
ExpansionPacksNumber: 1, // ExpansionPacksNumber: 1,
}) //})
if err != nil { //if err != nil {
service.Error(c, err) // service.Error(c, err)
return // return
} //}
default: default:
service.Error(c, errors.New("无效的订单类型")) service.Error(c, errors.New("无效的订单类型"))
return return
@ -438,6 +678,7 @@ func AntomWebhook(c *gin.Context) {
AvailableDurationAdditional: uint32(orderLimit.Duration), AvailableDurationAdditional: uint32(orderLimit.Duration),
TimeUnit: timeUnit, TimeUnit: timeUnit,
AssociatedorderNumber: resp.OutTradeNo, //增值服务订单号 AssociatedorderNumber: resp.OutTradeNo, //增值服务订单号
Type: 2, //自行购买
}) })
if err != nil { if err != nil {
service.Error(c, err) service.Error(c, err)
@ -485,15 +726,21 @@ func HomePageRoll(c *gin.Context) {
var roll []Roll var roll []Roll
for _, i := range res.BundleInfo { for _, i := range res.BundleInfo {
maskedTel := userMap[i.CustomerId].TelNum tel := ""
if len(userMap[i.CustomerId].TelNum) >= 11 { // 标准11位手机号 name := i.BundleName // Use bundle name as fallback
maskedTel = userMap[i.CustomerId].TelNum[:3] + "****" + userMap[i.CustomerId].TelNum[7:] if userInfo, exists := userMap[i.CustomerId]; exists && userInfo != nil {
} else if len(userMap[i.CustomerId].TelNum) >= 7 { // 短号处理 tel = userInfo.TelNum
maskedTel = userMap[i.CustomerId].TelNum[:3] + "****" + userMap[i.CustomerId].TelNum[7:] if len(tel) >= 2 {
masked := ""
for j := 0; j < len(tel)-2; j++ {
masked += "*"
}
tel = masked + tel[len(tel)-2:]
}
} }
roll = append(roll, Roll{ roll = append(roll, Roll{
Tel: maskedTel, Tel: tel,
Name: i.BundleName, Name: name,
}) })
} }
service.Success(c, roll) service.Success(c, roll)