package logic import ( "context" "fmt" "lone-services/pkg/utils" orderpb "lone-services/rpc/order/pb" "lone-services/services/payment/internal/svc" ) func getOrderInfo(ctx context.Context, orderSvcName string, userID int64, orderSn string, typ uint8) (*orderpb.OrderInfoResponse, error) { if orderSvcName == utils.StringEmpty { return nil, fmt.Errorf("order service not configured") } if userID < utils.NumberOne || orderSn == utils.StringEmpty || typ < utils.NumberOne { return nil, fmt.Errorf("invalid get order params") } cli, err := svc.GetRpcClient(orderSvcName) if err != nil { return nil, err } client := orderpb.NewOrderClient(cli.Conn()) info, err := client.GetOrderInfo(ctx, &orderpb.GetOrderInfoRequest{ UserId: userID, OrderSn: orderSn, Type: int32(typ), }) if err != nil { return nil, err } if info == nil || info.Id < utils.NumberOne { return nil, fmt.Errorf("order not found") } return info, nil } func updateOrderPayStatus(ctx context.Context, orderSvcName, orderSn string, status uint8, payPrice float64, remitNo string, typ uint8) error { if orderSvcName == utils.StringEmpty { return fmt.Errorf("order service not configured") } cli, err := svc.GetRpcClient(orderSvcName) if err != nil { return err } client := orderpb.NewOrderClient(cli.Conn()) _, err = client.UpdateOrderPayStatus(ctx, &orderpb.UpdateOrderPayStatusRequest{ OrderSn: orderSn, Status: int32(status), PayPrice: payPrice, RemitNo: remitNo, PayType: int32(typ), }) return err } func orderPayStatus(info *orderpb.OrderInfoResponse) uint8 { if info == nil { return 0 } return uint8(info.Status) } func orderOutTradeNo(info *orderpb.OrderInfoResponse) string { if info == nil { return utils.StringEmpty } if info.OutTradeNo != utils.StringEmpty { return info.OutTradeNo } return info.OrderSn }