Merge branch 'feat-zjy-fixbug-033' into dev
# Conflicts: # internal/logic/orderRecordsLogic.go # pb/bundle.proto # pb/bundle/bundle.pb.go # pb/bundle/bundle.validator.pb.go # pb/bundle/bundle_triple.pb.go
This commit is contained in:
commit
a822149b30
@ -134,3 +134,10 @@ func (b *BundleProvider) SoftDeleteUnfinishedInfo(_ context.Context, req *bundle
|
||||
func (b *BundleProvider) ReSignTheContract(_ context.Context, req *bundle.ReSignTheContractRequest) (res *bundle.CommonResponse, err error) {
|
||||
return logic.ReSignTheContract(req)
|
||||
}
|
||||
func (b *BundleProvider) OrderListByOrderUuid(_ context.Context, req *bundle.OrderInfoByOrderUuidRequest) (res *bundle.OrderInfoByOrderNoResp, err error) {
|
||||
return logic.OrderListByOrderUuid(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) UpdateOrderRecordByOrderUuid(_ context.Context, req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||
return logic.UpdateOrderRecordByOrderUuid(req)
|
||||
}
|
||||
|
||||
@ -1003,3 +1003,108 @@ func ReSignTheContract(req *bundle.ReSignTheContractRequest) (*bundle.CommonResp
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func UpdateOrderRecordByOrderUuid(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
||||
res = new(bundle.CommonResponse)
|
||||
// Step 1: 先更新子订单(增值服务)的支付状态
|
||||
valueAdd := &model.BundleOrderValueAdd{
|
||||
PaymentStatus: int(orderRecord.Status),
|
||||
PaymentTime: orderRecord.PayTime,
|
||||
}
|
||||
if orderRecord.CheckoutSessionId != "" {
|
||||
valueAdd.CheckoutSessionId = orderRecord.CheckoutSessionId
|
||||
valueAdd.CheckoutSessionUrl = orderRecord.CheckoutSessionUrl
|
||||
}
|
||||
|
||||
if orderRecord.Status == 2 {
|
||||
tempValues := make([]*model.BundleOrderValueAdd, 0)
|
||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
||||
Where("order_uuid = ?", orderRecord.UUID).
|
||||
Find(&tempValues).Error
|
||||
if len(tempValues) > 0 {
|
||||
for _, value := range tempValues {
|
||||
if value.PaymentStatus == 2 {
|
||||
fmt.Println("====================已经付过了")
|
||||
return nil, errors.New("已付款了")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tempRecord := new(model.BundleOrderRecords)
|
||||
if err := app.ModuleClients.BundleDB.Where("deleted_at is null and uuid = ?", orderRecord.UUID).First(&tempRecord).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.New("订单记录不存在")
|
||||
}
|
||||
return nil, fmt.Errorf("查询订单失败: %v", err)
|
||||
}
|
||||
if orderRecord.Status == 2 && tempRecord.AmountType == 2 && tempRecord.TotalAmount > 0 {
|
||||
// 当回调支付成功,币种是美元,且订单金额大于0,计算美元手续费:订单金额*0.019(四舍五入保留两位小数字)+0.1
|
||||
amount := decimal.NewFromFloat32(tempRecord.TotalAmount)
|
||||
rate, _ := decimal.NewFromString("0.019")
|
||||
fee := amount.Mul(rate)
|
||||
// 4. 四舍五入保留两位小数
|
||||
feeRounded := fee.Round(2)
|
||||
addition, _ := decimal.NewFromString("0.1")
|
||||
result := feeRounded.Add(addition)
|
||||
valueAdd.HandlingFee = result.String()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
||||
Where("order_uuid = ?", orderRecord.UUID).
|
||||
Updates(valueAdd).Error
|
||||
if err != nil {
|
||||
res.Msg = msg.ErrorUpdateOrderInfo
|
||||
return res, commonErr.ReturnError(err, msg.ErrorUpdateOrderInfo, "更新增值服务支付状态失败: ")
|
||||
}
|
||||
// Step 2: 再更新主订单信息(如果存在)
|
||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
||||
Where("uuid = ?", orderRecord.UUID).
|
||||
Updates(orderRecord).Error
|
||||
// Step 3: 返回结果(即使主订单更新失败,也视为成功)
|
||||
res.Uuid = orderRecord.UUID
|
||||
res.Msg = msg.SuccessUpdateOrderInfo
|
||||
return res, nil
|
||||
}
|
||||
func OrderListByOrderUuid(req *bundle.OrderInfoByOrderUuidRequest) (*bundle.OrderInfoByOrderNoResp, error) {
|
||||
if req == nil || req.OrderUuid == "" {
|
||||
return nil, errors.New("invalid request")
|
||||
}
|
||||
var addOrder []*model.BundleOrderValueAdd
|
||||
if err := app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
||||
Where("order_uuid = ?", req.OrderUuid).
|
||||
Find(&addOrder).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(addOrder) == 0 {
|
||||
return &bundle.OrderInfoByOrderNoResp{}, nil
|
||||
}
|
||||
//订单类型 1:套餐 2:单独购买
|
||||
userID, err := strconv.ParseInt(addOrder[0].CustomerID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := &bundle.OrderInfoByOrderNoResp{
|
||||
Type: int32(addOrder[0].Source),
|
||||
UserId: uint64(userID),
|
||||
OrderUUID: addOrder[0].OrderUUID,
|
||||
UserName: addOrder[0].CustomerName,
|
||||
}
|
||||
for _, item := range addOrder {
|
||||
switch item.ServiceType {
|
||||
case 1:
|
||||
res.VideoNumber += item.Num // 使用 += 而不是直接赋值
|
||||
case 2:
|
||||
res.ImageNumber += item.Num
|
||||
case 3:
|
||||
res.DataNumber += item.Num
|
||||
case 4:
|
||||
res.AccountNumber += item.Num
|
||||
case 5:
|
||||
res.Duration += item.Num
|
||||
res.Unit = item.Unit // 如果有多个duration记录,最后一个unit会覆盖前面的
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"micro-bundle/internal/dao"
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
@ -14,7 +16,13 @@ import (
|
||||
|
||||
func CreateOrderRecord(req *bundle.OrderCreateRecord) (res *bundle.CommonResponse, err error) {
|
||||
res = new(bundle.CommonResponse)
|
||||
orderUUID := app.ModuleClients.SfNode.Generate().Base64()
|
||||
//orderUUID := app.ModuleClients.SfNode.Generate().Base64()
|
||||
uuidV4, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
fmt.Println("生成错误", err)
|
||||
return nil, errors.New("生成uuid失败")
|
||||
}
|
||||
orderUUID := uuidV4.String()
|
||||
orderNo := utils.GetOrderNo()
|
||||
if req.OrderNo != "" {
|
||||
orderNo = req.OrderNo
|
||||
@ -95,6 +103,8 @@ func UpdateOrderRecordByOrderNo(req *bundle.OrderRecord) (res *bundle.CommonResp
|
||||
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
||||
orderRecord.UUID = req.Uuid
|
||||
orderRecord.BundleUUID = req.BundleUuid
|
||||
orderRecord.Status = req.Status
|
||||
fmt.Println("UpdateOrderRecordByOrderNo Status:", req.Status)
|
||||
res, err = dao.UpdateOrderRecordByOrderNO(orderRecord)
|
||||
return
|
||||
}
|
||||
@ -205,3 +215,20 @@ func ReSignTheContract(req *bundle.ReSignTheContractRequest) (res *bundle.Common
|
||||
res, err = dao.ReSignTheContract(req)
|
||||
return
|
||||
}
|
||||
|
||||
func UpdateOrderRecordByOrderUuid(req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||
res = new(bundle.CommonResponse)
|
||||
orderRecord := new(model.BundleOrderRecords)
|
||||
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
||||
orderRecord.UUID = req.Uuid
|
||||
orderRecord.BundleUUID = req.BundleUuid
|
||||
orderRecord.Status = req.Status
|
||||
fmt.Println("UpdateOrderRecordByOrderUuid Status:", req.Status)
|
||||
res, err = dao.UpdateOrderRecordByOrderUuid(orderRecord)
|
||||
return
|
||||
}
|
||||
func OrderListByOrderUuid(req *bundle.OrderInfoByOrderUuidRequest) (res *bundle.OrderInfoByOrderNoResp, err error) {
|
||||
res = new(bundle.OrderInfoByOrderNoResp)
|
||||
res, err = dao.OrderListByOrderUuid(req)
|
||||
return
|
||||
}
|
||||
|
||||
@ -141,6 +141,10 @@ service Bundle {
|
||||
rpc GetContractDetail(ContractDetailRequest) returns (ContractDetailResponse) {} // 根据合同UUID查询详情
|
||||
rpc GetDevelopmentCyclesByContractUUID(GetDevelopmentCyclesByContractUUIDRequest) returns (GetDevelopmentCyclesByContractUUIDResponse) {} // 根据合同UUID查询开发周期
|
||||
rpc GetPaymentCyclesByContractUUID(GetPaymentCyclesByContractUUIDRequest) returns (GetPaymentCyclesByContractUUIDResponse) {} // 根据合同UUID查询支付周期
|
||||
|
||||
|
||||
rpc UpdateOrderRecordByOrderUuid(OrderRecord) returns (CommonResponse) {}
|
||||
rpc OrderListByOrderUuid(OrderInfoByOrderUuidRequest) returns (OrderInfoByOrderNoResp) {}
|
||||
}
|
||||
message GetInEffectOrderRecordRequest{
|
||||
uint64 userID = 1;
|
||||
@ -2295,3 +2299,7 @@ message GetLastInvoiceNoReq{
|
||||
message GetLastInvoiceNoResp{
|
||||
string lastNo = 1;
|
||||
}
|
||||
|
||||
message OrderInfoByOrderUuidRequest{
|
||||
string orderUuid = 1;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user