/// <summary> /// CPS退佣支付接口 /// </summary> /// <param name="request"></param> /// <returns></returns> private static async Task <bool> CpsSendRefundAsync(CpsSendRefundRequest request) { var result = false; try { using (var client = new PayClient()) { var response = await client.CpsSendRefundAsync(request); if (!response.Success) { Logger.Info($"{request.OutBizNo} CPS退佣支付请求Pay服务失败"); } else { result = response.Result.Success; Logger.Info($"{request.OutBizNo} CPS退佣支付请求Pay服务成功"); } } } catch (Exception ex) { Logger.Error($"{request.OutBizNo} CPS退佣支付请求Pay服务失败异常;异常信息:{ex.Message};堆栈信息:{ex.StackTrace}"); } return(result); }
/// <summary> /// 退佣金计算 /// </summary> /// <param name="model"></param> private static async Task DeductionCommission(CalculateCommissionModel model) { var commissionFlowCount = await DalTuboAlliance.GetCommissionFlowRecordDal("", nameof(CpsEnum.CpsRunningType.IMPAIRMENT), model.OrderItem.OrderListId, "" + model.OrderItem.OrderId); if (commissionFlowCount <= 0) { var outBizNo = model.OrderItem.OrderId + "_" + (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000; var actutalAmount = (model.OrderItem.PayPrice * model.OrderItem.Num) * (model.CommissionRatio / 100); ; var minuteActutalAmount = actutalAmount * 100; //转换为单位分 var requestNo = Guid.NewGuid(); minuteActutalAmount = Math.Ceiling(minuteActutalAmount); var commissionFlowRecordSumAmount = DalTuboAlliance.GetCommissionFlowRecordSumAmountDal(model.OriOrderId); var comissionSumAmount = commissionFlowRecordSumAmount + minuteActutalAmount; if (comissionSumAmount >= 0) { var cpsCommissionFlowRecordModel = new CpsCommissionFlowRecordModel(); cpsCommissionFlowRecordModel.CommissionFlowRecordNo = outBizNo; cpsCommissionFlowRecordModel.OrderId = model.OriOrderId; cpsCommissionFlowRecordModel.OrderItemPKID = model.OrderItem.OrderListId; cpsCommissionFlowRecordModel.RedRushOrderId = "" + model.OrderItem.OrderId; cpsCommissionFlowRecordModel.CpsId = model.CpsId; cpsCommissionFlowRecordModel.DarenID = model.DarenId; cpsCommissionFlowRecordModel.Pid = model.Pid; cpsCommissionFlowRecordModel.PayPrice = model.OrderItem.PayPrice; cpsCommissionFlowRecordModel.Number = model.Number; cpsCommissionFlowRecordModel.CommissionRatio = model.CommissionRatio; cpsCommissionFlowRecordModel.ActutalAmount = minuteActutalAmount; cpsCommissionFlowRecordModel.Type = nameof(CpsEnum.CpsRunningType.IMPAIRMENT); cpsCommissionFlowRecordModel.RequestNo = requestNo; cpsCommissionFlowRecordModel.TransactionNo = model.OriPayInstructionId; cpsCommissionFlowRecordModel.Status = nameof(CpsEnum.CpsRunningStatus.NOTSENT); int cpsCreateRunningCount = await DalTuboAlliance.CpsCommissionFlowRecordDal(cpsCommissionFlowRecordModel); if (cpsCreateRunningCount > 0) { var cpsSendRefundRequest = new CpsSendRefundRequest(); cpsSendRefundRequest.OutBizNo = outBizNo; cpsSendRefundRequest.OriPayInstructionId = model.OriPayInstructionId; cpsSendRefundRequest.RefundType = nameof(CpsEnum.CpsRefundType.NORMAL); cpsSendRefundRequest.RefundRoute = nameof(CpsEnum.CpsRefundRoute.ORIGINAL); cpsSendRefundRequest.RequestNo = "" + requestNo; cpsSendRefundRequest.RefundAmount = Math.Abs(minuteActutalAmount); await CpsSendRefundAsync(cpsSendRefundRequest); } else { Logger.Info($"CommodityDeductionManager -->DeductionCommission:【orderId:{model.OriOrderId}】【RedRushOrderId:{ model.OrderItem.OrderId}】【DarenID:{model.DarenId}】【CPSID:{model.CpsId}】【PID:{model.Pid}】退款流水创建失败"); } } else { Logger.Info($"CommodityDeductionManager -->DeductionCommission:【orderId:{model.OriOrderId}】【RedRushOrderId:{ model.OrderItem.OrderId}】【DarenID:{model.DarenId}】【CPSID:{model.CpsId}】【PID:{model.Pid}】退款金额大于支付金额"); } } else { Logger.Info($"CommodityDeductionManager -->DeductionCommission:【orderId:{model.OriOrderId}】【RedRushOrderId:{ model.OrderItem.OrderId}】【DarenID:{model.DarenId}】【CPSID:{model.CpsId}】【PID:{model.Pid}】退款流水已存在"); } }