@ -273,10 +273,7 @@ func OrderRecordDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.Order
if req . BundleUUID != "" {
if req . BundleUUID != "" {
query = query . Where ( "bundle_uuid = ?" , req . BundleUUID )
query = query . Where ( "bundle_uuid = ?" , req . BundleUUID )
}
}
if req . Status != 0 {
err = query . Order ( "expiration_time desc" ) . First ( & orderRecord ) . Error
query = query . Where ( "status = ?" , req . Status )
}
err = query . Order ( "created_at desc" ) . First ( & orderRecord ) . Error
if err != nil {
if err != nil {
return res , commonErr . ReturnError ( err , msg . ErrorGetOrderInfo , "获取订单信息失败: " )
return res , commonErr . ReturnError ( err , msg . ErrorGetOrderInfo , "获取订单信息失败: " )
}
}
@ -467,7 +464,6 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
}
}
for _ , record := range records {
for _ , record := range records {
customerID , _ := strconv . ParseInt ( record . CustomerID , 10 , 64 )
customerID , _ := strconv . ParseInt ( record . CustomerID , 10 , 64 )
orderItem := & bundle . OrderBundleRecordInfo {
orderItem := & bundle . OrderBundleRecordInfo {
OrderNo : record . OrderNo ,
OrderNo : record . OrderNo ,
BundleName : record . BundleName ,
BundleName : record . BundleName ,
@ -479,20 +475,28 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
CustomerId : customerID ,
CustomerId : customerID ,
}
}
// 聚合子订单
// 构建子订单 map, 按 orderAddNo 聚合
addMap := make ( map [ string ] * bundle . OrderAddBundleRecordInfo )
addMap := make ( map [ string ] * bundle . OrderAddBundleRecordInfo )
for _ , sub := range record . BundleOrderValueAdd {
for _ , sub := range record . BundleOrderValueAdd {
orderAddNo := sub . OrderNo
orderAddNo := sub . OrderNo
amount := float32 ( sub . Amount )
// SettlementAmount 规则
settlementAmount := float32 ( sub . Amount )
if sub . OrderNo == record . OrderNo {
settlementAmount = record . TotalAmount
}
if existing , ok := addMap [ orderAddNo ] ; ok {
if existing , ok := addMap [ orderAddNo ] ; ok {
existing . Amount += amount
existing . Amount += float32 ( sub . Amount )
existing . SettlementAmount += settlementAmount
} else {
} else {
addMap [ orderAddNo ] = & bundle . OrderAddBundleRecordInfo {
addMap [ orderAddNo ] = & bundle . OrderAddBundleRecordInfo {
OrderAddNo : orderAddNo ,
OrderAddNo : orderAddNo ,
Amount : amount ,
Amount : float32 ( sub . Amount ) ,
SettlementAmount : settlementAmount ,
CurrencyType : int32 ( sub . CurrencyType ) ,
CurrencyType : int32 ( sub . CurrencyType ) ,
//HandlingFee: float32(sub.HandlingFee),
//ExchangeRate: float32(sub.ExchangeRate),
OrderAddCreateAt : sub . CreatedAt . Format ( "2006-01-02 15:04:05" ) ,
OrderAddCreateAt : sub . CreatedAt . Format ( "2006-01-02 15:04:05" ) ,
AddPayStatus : int32 ( sub . PaymentStatus ) ,
AddPayStatus : int32 ( sub . PaymentStatus ) ,
Contract : sub . SignContract ,
Contract : sub . SignContract ,
@ -503,16 +507,10 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
}
}
}
}
// 设置 SettlementAmount 并追加到主订单中
// 将聚合后的子订单添加到主订单返回结构中
for orderAddNo , addInfo := range addMap {
for _ , v := range addMap {
if orderAddNo == record . OrderNo {
orderItem . AddBundleInfo = append ( orderItem . AddBundleInfo , v )
addInfo . SettlementAmount = record . TotalAmount
} else {
addInfo . SettlementAmount = addInfo . Amount
}
}
orderItem . AddBundleInfo = append ( orderItem . AddBundleInfo , addInfo )
}
res . BundleInfo = append ( res . BundleInfo , orderItem )
res . BundleInfo = append ( res . BundleInfo , orderItem )
}
}
res . Total = int32 ( count )
res . Total = int32 ( count )
@ -542,7 +540,6 @@ func OrderListByOrderNo(req *bundle.OrderInfoByOrderNoRequest) (*bundle.OrderInf
Type : int32 ( addOrder [ 0 ] . Source ) ,
Type : int32 ( addOrder [ 0 ] . Source ) ,
UserId : uint64 ( userID ) ,
UserId : uint64 ( userID ) ,
OrderUUID : addOrder [ 0 ] . OrderUUID ,
OrderUUID : addOrder [ 0 ] . OrderUUID ,
UserName : addOrder [ 0 ] . CustomerName ,
}
}
for _ , item := range addOrder {
for _ , item := range addOrder {
switch item . ServiceType {
switch item . ServiceType {
@ -586,10 +583,7 @@ func GetReconciliationList(req *bundle.GetReconciliationListReq) (*bundle.GetRec
modelObj = modelObj . Where ( "pay_channel = ?" , req . PayChannel )
modelObj = modelObj . Where ( "pay_channel = ?" , req . PayChannel )
}
}
if req . BundleOrderOn != "" {
if req . BundleOrderOn != "" {
modelObj = modelObj . Where ( "bundle_order_on like ?" , "%" + req . BundleOrderOn + "%" )
modelObj = modelObj . Where ( "order_no like ?" , "%" + req . BundleOrderOn + "%" )
}
if req . BundleAddOrderOn != "" {
modelObj = modelObj . Where ( "bundle_add_order_on like ?" , "%" + req . BundleAddOrderOn + "%" )
}
}
if req . CreatedStart != "" && req . CreatedEnd != "" {
if req . CreatedStart != "" && req . CreatedEnd != "" {
modelObj = modelObj . Where ( "created_at between ? and ?" , req . CreatedStart , req . CreatedEnd )
modelObj = modelObj . Where ( "created_at between ? and ?" , req . CreatedStart , req . CreatedEnd )
@ -608,7 +602,7 @@ func GetReconciliationList(req *bundle.GetReconciliationListReq) (*bundle.GetRec
return res , nil
return res , nil
}
}
offset := ( req . Page - 1 ) * req . PageSize
offset := ( req . Page - 1 ) * req . PageSize
if err := modelObj . Offset ( int ( offset ) ) . Limit ( int ( req . PageSize ) ) . Order( "created_at desc" ) . Find( & records ) . Error ; err != nil {
if err := modelObj . Offset ( int ( offset ) ) . Limit ( int ( req . PageSize ) ) . Find( & records ) . Error ; err != nil {
return nil , fmt . Errorf ( "查询记录失败: %v" , err )
return nil , fmt . Errorf ( "查询记录失败: %v" , err )
}
}
@ -720,43 +714,3 @@ func UpdateReconciliationStatusBySerialNumber(req *bundle.UpdateStatusAndPayTime
// 返回成功响应
// 返回成功响应
return & bundle . CommonResponse { Msg : "更新成功" } , nil
return & bundle . CommonResponse { Msg : "更新成功" } , nil
}
}
func DeleteValueAddService ( req * bundle . DeleteValueAddServiceRequest ) ( res * bundle . CommonResponse , err error ) {
res = new ( bundle . CommonResponse )
var paidServices [ ] * model . BundleOrderValueAdd
if err = app . ModuleClients . BundleDB . Model ( & model . BundleOrderValueAdd { } ) .
Where ( "order_no = ? AND payment_status = 2 and customer_id = ?" , req . OrderNo , req . UserID ) .
Find ( & paidServices ) . Error ; err != nil {
res . Msg = msg . ErrorUpdateOrderInfo
return res , commonErr . ReturnError ( err , msg . ErrorUpdateOrderInfo , "查询增值服务支付状态失败: " )
}
if len ( paidServices ) > 0 {
res . Msg = "订单已支付,无法删除"
return res , nil
}
if err = app . ModuleClients . BundleDB . Where ( "order_no = ?" , req . OrderNo ) .
Delete ( & model . BundleOrderValueAdd { } ) . Error ; err != nil {
res . Msg = msg . ErrorDeleteOrderInfo
return res , commonErr . ReturnError ( err , msg . ErrorDeleteOrderInfo , "删除增值服务失败: " )
}
var order model . BundleOrderRecords
if err = app . ModuleClients . BundleDB . Model ( & model . BundleOrderRecords { } ) .
Where ( "order_no = ? and customer_id = ?" , req . OrderNo , req . UserID ) .
First ( & order ) . Error ; err != nil {
if ! errors . Is ( err , gorm . ErrRecordNotFound ) {
return nil , nil
}
} else if order . PayType == 2 {
res . Msg = "订单已支付,无法删除"
return res , nil
}
if err = app . ModuleClients . BundleDB . Where ( "order_no = ?" , order . OrderNo ) .
Delete ( & model . BundleOrderRecords { } ) . Error ; err != nil {
res . Msg = msg . ErrorDeleteOrderInfo
return res , commonErr . ReturnError ( err , msg . ErrorDeleteOrderInfo , "删除套餐订单服务失败: " )
}
res . Msg = msg . SuccessDeletedOrderInfo
return res , nil
}