public void CommodityRebateTest() { using (var client = new TuboAllianceClient()) { var model = new CommodityRebateRequest(); model.OrderId = "123502852"; var result = client.CommodityRebateAsync(model); Assert.IsNotNull(result.Result); } }
/// <summary> /// 订单商品返佣接口 /// </summary> /// <param name="request"></param> /// <returns></returns> public static async Task <CommodityRebateResponse> CommodityRebateManager(CommodityRebateRequest request) { var resultModule = new CommodityRebateResponse(); resultModule.Success = true; try { var orderId = string.IsNullOrWhiteSpace(request.OrderId) ? 0 : Convert.ToInt32(request.OrderId); //获取拆单订单号集合 var relatedSplitOrderIds = await GetRelatedSplitOrderIDs(orderId); //拆单是需要获取主订单号ID,关联订单集合最小的一位是主订单ID var mainOrderId = relatedSplitOrderIds.OrderBy(splitOrderId => splitOrderId).FirstOrDefault() + ""; var orderItemRecordList = await DalTuboAlliance.GetOrderItemRecordListDal(mainOrderId); //主订单ID在下单记录表中存在的,进行佣金计算 if (orderItemRecordList?.Count > 0) { var orderModel = FetchOrderInfoByID(orderId).Result; if (IsOrderCompleted(orderModel)) { await orderModel.OrderListModel?.ForEachAsync(async orderItem => { //去除套餐的子产品与赠品 if (orderItem.PayPrice > 0 && (orderItem.ParentId == null || orderItem.ParentId == 0)) { //当前订单的PID在主订单商品集合中查询 var orderItemRecord = orderItemRecordList.Where(p => p.PID == orderItem.Pid).FirstOrDefault(); if (orderItemRecord != null) { var pid = orderItem.Pid; var number = orderItem.Num; //计算佣金使用实体 var calculateCommissionModel = new CalculateCommissionModel(); calculateCommissionModel.OrderItem = orderItem; calculateCommissionModel.CpsId = orderItemRecord.CpsId; calculateCommissionModel.DarenId = orderItemRecord.DarenID; calculateCommissionModel.Pid = pid; calculateCommissionModel.Number = number; Logger.Info($"CommodityRebateManager:【OrderId:{orderId}】【MainOrderId:{mainOrderId}】"); if (orderItem.OrderId + "" == mainOrderId) //主订单逻辑 { await CalculateCommission(calculateCommissionModel); } else //拆单订单 { var cpsSplitOrderItemRecordModel = new CpsSplitOrderItemRecordModel(); cpsSplitOrderItemRecordModel.OrderId = "" + orderItem.OrderId; cpsSplitOrderItemRecordModel.CpsOrderItemRecordID = orderItemRecord.PkId; cpsSplitOrderItemRecordModel.PID = pid; cpsSplitOrderItemRecordModel.Number = number; var splitOrderItemRecordCount = await DalTuboAlliance.GetSplitOrderItemRecordCountManager(cpsSplitOrderItemRecordModel); if (splitOrderItemRecordCount <= 0) { await DalTuboAlliance.CreateSplitOrderItemRecordManager(cpsSplitOrderItemRecordModel); } await CalculateCommission(calculateCommissionModel); } } else { Logger.Info($"CommodityRebateManager:【OrderId:{orderId}】【MainOrderId:{mainOrderId}】【PID:{orderItem.Pid}】该商品未在下单记录表中存在"); } } else { Logger.Info($"CommodityRebateManager:【orderId:{orderId}】" + $"【mainOrderId:{mainOrderId}】【PID:{orderItem.Pid}】【ParentId:{orderItem.ParentId}】为套装子产品或者是赠品"); } }); } else { Logger.Info($"CommodityRebateManager:【OrderId:{orderId}】【MainOrderId】:{mainOrderId}订单未完成"); } } else { Logger.Info($"CommodityRebateManager:【OrderId:{orderId}】【MainOrderId】:{mainOrderId}未在下单记录表中存在"); } } catch (Exception ex) { Logger.Error($"CommodityRebateManager订单商品返佣接口异常:{ex.Message};堆栈信息:{ex.StackTrace}"); resultModule.ErrorMessage = ex.Message; resultModule.Success = false; } return(resultModule); }
/// <summary> /// 订单商品返佣接口 /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <OperationResult <CommodityRebateResponse> > CommodityRebateAsync(CommodityRebateRequest request) { if (request == null || string.IsNullOrEmpty(request.OrderId)) { return(OperationResult.FromError <CommodityRebateResponse> (nameof(Resource.ParameterError), Resource.ParameterError)); } else { return(OperationResult.FromResult(await TuboAllianceManager.CommodityRebateManager(request))); } }