/// <summary> /// 退款结果回调 /// </summary> /// <param name="result"></param> public static void OrderRefundResult(RefundResult result) { try { Guid orderId; Guid.TryParse(result.orderId, out orderId); LogHelper.Debug("进入 YXOrderHelper.OrderRefundResult,Input:" + JsonConvert.SerializeObject(result)); var orderRefund = OrderRefundAfterSales.ObjectSet().Where(_ => _.ApplyId == result.applyId).FirstOrDefault(); if (orderRefund == null) { LogHelper.Error("YXOrderHelper.OrderRefundResult 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); } var orderItem = OrderItem.FindByID(orderRefund.OrderItemId.Value); string skuId; if (orderItem.CommodityStockId == null || orderItem.CommodityStockId.Value == Guid.Empty || orderItem.CommodityStockId == orderItem.CommodityId) { var commodity = Commodity.FindByID(orderItem.CommodityId); skuId = commodity.JDCode; } else { var comStock = CommodityStock.FindByID(orderItem.CommodityStockId.Value); skuId = comStock.JDCode; } var skuResult = result.refundSkuList.Where(_ => _.skuId == skuId).FirstOrDefault(); var skuOperateResult = skuResult.operateSkus.Where(_ => _.skuId == skuId).FirstOrDefault(); if (skuOperateResult.status == OrderRefundApplySkuOperateStatusEnum.审核通过) { var refundResult = OrderHelper.ApproveOrderRefundAfterSales(orderRefund.OrderId, orderRefund.OrderItemId ?? Guid.Empty); if (refundResult.ResultCode != 0) { // 失败 LogHelper.Error("YXOrderHelper.OrderRefundResult 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); } } else if (skuOperateResult.status == OrderRefundApplySkuOperateStatusEnum.已拒绝) { var refundResult = OrderHelper.RejectOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty, skuOperateResult.reason); if (refundResult.ResultCode != 0) { // 失败 LogHelper.Error("YXOrderHelper.RejectOrderRefund 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); } } else { LogHelper.Error("YXOrderHelper.RejectOrderRefund -> OrderId: " + orderId + ", ApplyId: " + result.applyId + ", 忽略的状态:" + skuOperateResult.status.ToString()); } } catch (Exception ex) { LogHelper.Error("YXOrderHelper.OrderRefundResult 异常,Input:" + JsonConvert.SerializeObject(result), ex); } }
/// <summary> /// 严选系统取消退货回调 /// </summary> /// <param name="result"></param> public static void SystemCancelOrderRefund(SystemCancel result) { try { Guid orderId; Guid.TryParse(result.orderId, out orderId); LogHelper.Debug("进入 YXOrderHelper.SystemCancelOrderRefund,Input:" + JsonConvert.SerializeObject(result)); var orderRefund = OrderRefundAfterSales.ObjectSet().Where(_ => _.ApplyId == result.applyId).FirstOrDefault(); if (orderRefund == null) { LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); } var refundResult = OrderHelper.RejectOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty, result.errorMsg); if (refundResult.ResultCode != 0) { // 失败 LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); } //if (result.applyId.StartsWith("s")) //{ // // 售后 // var orderRefund = OrderRefundAfterSales.FindByID(new Guid(result.applyId.Substring(1))); // if (orderRefund == null) // { // LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); // } // var refundResult = OrderHelper.RejectOrderRefund(orderId, orderRefund.OrderItemId ?? Guid.Empty, result.errorMsg); // if (refundResult.ResultCode != 0) // { // // 失败 // LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); // } //} //else //{ // //售前 // var orderRefund = OrderRefund.FindByID(new Guid(result.applyId)); // if (orderRefund == null) // { // LogHelper.Error("YXOrderHelper.v 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); // } // var refundResult = OrderHelper.RejectOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty, result.errorMsg); // if (refundResult.ResultCode != 0) // { // // 失败 // LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); // } //} } catch (Exception ex) { LogHelper.Error("YXOrderHelper.SystemCancelOrderRefund 异常,Input:" + JsonConvert.SerializeObject(result), ex); } }
/// <summary> /// 获取售后信息 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public static Jinher.AMP.BTP.Deploy.OrderRefundAfterSalesDTO GetOrderRefundAfterSalesInfo(Guid orderId) { var info = OrderRefundAfterSales.ObjectSet().Where(_ => _.OrderId == orderId).OrderByDescending(_ => _.SubTime).FirstOrDefault(); if (info == null) { return(null); } return(info.ToEntityData()); }
public ResultDTO <ListResult <Jinher.AMP.BTP.Deploy.CustomDTO.OrderRefundCompareDTO> > GetOrderRefundExt(Jinher.AMP.BTP.Deploy.CustomDTO.OrderRefundSearchDTO search) { var result = new ResultDTO <ListResult <OrderRefundCompareDTO> >(); try { var refunds = (from o in OrderRefund.ObjectSet() where o.OrderRefundMoneyAndCoupun != o.RefundYJCouponMoney + o.RefundFreightPrice + o.RefundYJBMoney + o.RefundMoney select new Deploy.CustomDTO.OrderRefundCompareDTO { SubTime = o.SubTime, OrderRefundMoneyAndCoupun = o.OrderRefundMoneyAndCoupun, RefundYJCouponMoney = o.RefundYJCouponMoney, RefundFreightPrice = o.RefundFreightPrice, RefundYJBMoney = o.RefundYJBMoney, RefundMoney = o.RefundMoney, OrderId = o.OrderId }) .Union(from a in OrderRefundAfterSales.ObjectSet() where a.OrderRefundMoneyAndCoupun != a.RefundYJCouponMoney + a.RefundFreightPrice + a.RefundYJBMoney + a.RefundMoney select new Deploy.CustomDTO.OrderRefundCompareDTO { SubTime = a.SubTime, OrderRefundMoneyAndCoupun = a.OrderRefundMoneyAndCoupun, RefundYJCouponMoney = a.RefundYJCouponMoney, RefundFreightPrice = a.RefundFreightPrice, RefundYJBMoney = a.RefundYJBMoney, RefundMoney = a.RefundMoney, OrderId = a.OrderId }); result.isSuccess = true; var data = refunds.OrderByDescending(x => x.SubTime).Skip(search.PageSize * (search.PageIndex - 1)).Take(search.PageSize).ToList(); result.Data = new ListResult <OrderRefundCompareDTO> { List = data, Count = refunds.Count() }; return(result); } catch (Exception ex) { LogHelper.Error("JdCommodityBP.GetJdCommodityListExt 异常", ex); return(new ResultDTO <ListResult <OrderRefundCompareDTO> > { isSuccess = false, Data = null }); } }
/// <summary> /// 根据订单生成待结算项 /// </summary> public static SettleAccountsDetails CreateSettleAccountDetails(ContextSession contextSession, CommodityOrder commodityOrder, MallApply mall, int?orderServiceState = null) { //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id); var currentDate = DateTime.Now; // 1:商家,2:金和众销(给金和分的钱),3:商贸众销(给分享者分的钱),4:商贸众筹,5:推广主分成,6:应用主分成,7金和分润,8买家,9一级分销,10二级分销,11三级分销,12渠道推广,20:一级代理,21:二级代理 //var payeeType = new List<int> { 3, 5, 9, 10, 11, 20, 21 }; //var orderitemlist = OrderItem.ObjectSet().Where(n => n.CommodityOrderId == commodityOrder.Id). // GroupJoin(OrderItemShare.ObjectSet().Where(s => payeeType.Contains(s.PayeeType)), o => o.Id, s => s.OrderItemId, (o, s) => // new { o.Id, o.Name, o.Number, o.RealPrice, o.CommodityId, o.ComCategoryId, Commission = s.Sum(_ => (decimal?)_.Commission) }).ToList(); // 暂不计算推广佣金 var orderitemlist = OrderItem.ObjectSet().Where(n => n.CommodityOrderId == commodityOrder.Id).Select(o => new { o.Id, o.Name, o.Number, o.RealPrice, o.CommodityId, o.ComCategoryId, o.CommodityAttributes }).ToList(); bool isSetSettleAmount = true; List <SettleAccountsOrderItem> items = new List <SettleAccountsOrderItem>(); var payTime = commodityOrder.PaymentTime.Value; foreach (var orderItem in orderitemlist) { // 结算单订单项 SettleAccountsOrderItem saItem = new SettleAccountsOrderItem(); saItem.Id = saItem.OrderItemId = orderItem.Id; saItem.ModifiedOn = saItem.SubTime = currentDate; saItem.OrderId = commodityOrder.Id; saItem.OrderItemRefundAmount = 0; // 暂无单品退货 saItem.OrderItemPromotionCommissionAmount = 0M; // orderItem.Commission ?? 0M; saItem.OrderItemName = orderItem.Name; saItem.OrderItemNumber = orderItem.Number; saItem.OrderItemPrice = orderItem.RealPrice.Value; // 自营他配 if (mall.Type == 0) { var commoditySettleAmount = CommoditySettleAmount.ObjectSet() .Where(c => c.CommodityId == orderItem.CommodityId && c.EffectiveTime < payTime) .OrderByDescending(c => c.SubTime) .ThenByDescending(c => c.EffectiveTime) .FirstOrDefault(); if (commoditySettleAmount == null) { // 未设置结算价,暂不结算 //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id + ",自营商家,未设置结算价,商品ID:" + orderItem.CommodityId); return(null); } //LogHelper.Info("开始生成结算项,订单ID:" + commodityOrder.Id + ",自营商家,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价:" + commoditySettleAmount.CommodityAttrJson); var saAttrs = JsonHelper.JsonDeserialize <List <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityAttributePrice> >(commoditySettleAmount.CommodityAttrJson); var attrs = (orderItem.CommodityAttributes ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (attrs.Length == 0) { // 无属性 saItem.SettleAmount = saAttrs[0].SettlePrice.Value; } else if (attrs.Length == 1) { // 单属性 var settlePrice = saAttrs.Where(a => a.AttributeValue == attrs[0]).FirstOrDefault(); if (settlePrice == null) { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,结算价设置异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价ID:" + commoditySettleAmount.Id + ",结算价属性:" + commoditySettleAmount.CommodityAttrJson); return(null); } saItem.SettleAmount = settlePrice.SettlePrice.Value; } else if (attrs.Length == 2) { // 双属性 var settlePrice = saAttrs.Where(a => (a.AttributeValue == attrs[0] && a.SecAttributeValue == attrs[1]) || (a.AttributeValue == attrs[1] && a.SecAttributeValue == attrs[0])) .FirstOrDefault(); if (settlePrice == null) { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,结算价设置异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes + ",结算价ID:" + commoditySettleAmount.Id + ",结算价属性:" + commoditySettleAmount.CommodityAttrJson); return(null); } saItem.SettleAmount = settlePrice.SettlePrice.Value; } else { LogHelper.Error("SettleAccountHelper.CreateSettleAccountDetails 生成结算单失败,商品属性异常,商品ID:" + orderItem.CommodityId + ",商品属性:" + orderItem.CommodityAttributes); return(null); } //orderItem.com } // 第三方 else if (mall.Type == 1) { // 查询商品易捷币抵用数量 var yjbInfo = YJBSV.GetOrderItemYJBInfo(commodityOrder.EsAppId.Value, commodityOrder.Id); if (!yjbInfo.IsSuccess) { saItem.OrderItemYJBAmount = 0; } else { var currentCommodityYJBInfo = yjbInfo.Data.Items.Where(c => c.CommodityId == orderItem.CommodityId).FirstOrDefault(); if (currentCommodityYJBInfo != null && currentCommodityYJBInfo.IsMallYJB) { saItem.OrderItemYJBAmount = currentCommodityYJBInfo.InsteadCashAmount; } } // 计算实际成交价 #region 计算商品佣金比例 // 获取佣金比例:按结算日期获取有效的(启用日期小于等于结算日期的最近一次设置的佣金比例)佣金比例【基础、类目、商品】; saItem.BaseCommission = BaseCommission.ObjectSet().Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && t.EffectiveTime < payTime). OrderByDescending(t => t.SubTime).Select(t => (decimal?)t.Commission).FirstOrDefault(); // 查询当前商品的类目 List <Guid> categoryIds = new List <Guid>(); var tempCategories = CommodityCategory.ObjectSet().Where(c => c.AppId == commodityOrder.EsAppId && c.CommodityId == orderItem.CommodityId).Join(Category.ObjectSet(), cc => cc.CategoryId, c => c.Id, (cc, c) => new { c.Id, c.CurrentLevel, c.ParentId, cc.IsDel }).ToList(); foreach (var item in tempCategories) { if (item.IsDel.HasValue && item.IsDel.Value) { continue; } if (item.CurrentLevel == 3 || item.CurrentLevel == 4 || item.CurrentLevel == 5) { var lv2 = Category.FindByID(item.ParentId.Value); if (item.CurrentLevel == 3) { categoryIds.Add(lv2.ParentId.Value); continue; } var lv3 = Category.FindByID(lv2.ParentId.Value); if (item.CurrentLevel == 4) { categoryIds.Add(lv3.ParentId.Value); continue; } var lv4 = Category.FindByID(lv3.ParentId.Value); categoryIds.Add(lv4.ParentId.Value); } else if (item.CurrentLevel == 2) { categoryIds.Add(item.ParentId.Value); } else if (item.CurrentLevel == 1) { categoryIds.Add(item.Id); } } var commissions = CategoryCommission.ObjectSet(). Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.CategoryId, b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && categoryIds.Contains(t.CategoryId) && t.EffectiveTime < payTime). GroupBy(t => t.CategoryId). Select(group => group.OrderByDescending(g => g.SubTime).Select(g => g.Commission).FirstOrDefault()). ToList(); if (commissions.Count > 0) { saItem.CategoryCommission = commissions.Min(); } saItem.CommodityCommission = CommodityCommission.ObjectSet().Join(MallApply.ObjectSet(), b => b.MallApplyId, m => m.Id, (b, m) => new { b.CommodityId, b.Commission, b.EffectiveTime, b.SubTime, m.AppId, m.EsAppId }). Where(t => t.EsAppId == commodityOrder.EsAppId && t.AppId == commodityOrder.AppId && t.CommodityId == orderItem.CommodityId && t.EffectiveTime < payTime). OrderByDescending(t => t.SubTime).Select(t => (decimal?)t.Commission).FirstOrDefault(); #endregion // 商城佣金计算公式:商品销售价*佣金比例【商品佣金优先,类目佣金其次、基础佣金最后,三选一计算】* 购买数量; saItem.PromotionAmount = Math.Truncate( (saItem.CommodityCommission.HasValue ? saItem.CommodityCommission.Value : (saItem.CategoryCommission.HasValue ? saItem.CategoryCommission.Value : (saItem.BaseCommission.HasValue ? saItem.BaseCommission.Value : 0) )) * saItem.OrderItemPrice * saItem.OrderItemNumber) / 100; } saItem.EntityState = EntityState.Added; items.Add(saItem); } // 结算单订单详情 SettleAccountsDetails sad = new SettleAccountsDetails(); sad.Id = sad.OrderId = commodityOrder.Id; sad.EntityState = EntityState.Added; sad.ModifiedOn = sad.SubTime = currentDate; sad.IsSettled = false; sad.AppId = commodityOrder.AppId; sad.EsAppId = commodityOrder.EsAppId.Value; sad.OrderCode = commodityOrder.Code; sad.OrderSubTime = payTime; sad.OrderAmount = commodityOrder.Price; sad.OrderRealAmount = commodityOrder.RealPrice.Value; sad.OrderFreight = commodityOrder.Freight; sad.IsSetSettleAmount = isSetSettleAmount; // 导入订单时,记录退款金额 if (commodityOrder.State == 7 || orderServiceState == 7) { var refund = OrderRefundAfterSales.ObjectSet().Where(o => o.OrderId == commodityOrder.Id).FirstOrDefault(); // 全额退款 不计入结算单 if (refund.IsFullRefund == 1) { sad.IsSettled = true; if (contextSession != null) { foreach (var item in items) { contextSession.SaveObject(item); } contextSession.SaveObject(sad); } return(sad); } else { sad.OrderRefundAmount = refund.RefundMoney; } } else { sad.OrderRefundAmount = 0; // 暂无单品退货 } //// 计算商城优惠券金额 //var orderP ayDetailId = OrderPayDetail.ObjectSet().Where(c => c.OrderId == commodityOrder.Id && c.ObjectType == 1).Select(c => c.ObjectId).FirstOrDefault(); //if (orderPayDetailId != Guid.Empty) //{ // var request = new Coupon.Deploy.CustomDTO.ListCouponNewRequestDTO // { // CouponIds = new List<Guid> { orderPayDetailId }, // UserId = commodityOrder.UserId // }; // var coupons = CouponSV.Instance.GetUserCouponsByIds(request); // if (coupons.IsSuccess) // { // var firstCoupon = coupons.Data[0]; // sad.OrderCouponAmount = firstCoupon.Cash; // // 判断是否为电商馆 // sad.IsMallCoupon = ZPHSV.Instance.IsAppPavilion(firstCoupon.ShopId); // } // else // { // LogHelper.Error(string.Format("CouponSV.GetUserCouponsByIds返回结果不成功,入参 CouponIds: {0} UserId: {1},出参 Code: {2} Info: {3}。", orderPayDetailId, commodityOrder.UserId, coupons.Code, coupons.Info)); // } //} // 计算商家结算金额 decimal spreadMoney = 0; if (commodityOrder.SpreadGold > 0) { spreadMoney = commodityOrder.SpreadGold.ToMoney(); } sad.OrderSpreadAmount = spreadMoney; // 1.第三方 if (mall.Type == 1) { sad.OrderYJBAmount = items.Sum(i => i.OrderItemYJBAmount); // 商城佣金 sad.PromotionAmount = items.Sum(i => i.PromotionAmount); // 优先级:1推广主、2三级分销、 3众销 //sad.OrderPromotionCommissionAmount = commodityOrder.SpreadGold > 0 ? commodityOrder.SpreadGold.ToMoney() : // commodityOrder.DistributeMoney > 0 ? commodityOrder.DistributeMoney : commodityOrder.Commission; // 老版本,已弃 商家结算金额 = 订单总额 + 商城优惠券总金额 - 退款总金额 - 推广佣金总额 - 商城佣金总额 // 版本1:商家结算金额 = 实收款 + 商城易捷币抵用金额 - 退款金额 - 商城佣金 // 版本2:商家结算金额 = 实收款 + 商城易捷币抵用金额 - 退款金额 - 商城佣金 - 推广佣金总额 // 商家结算金额 sad.SellerAmount = Math.Truncate((sad.OrderRealAmount + sad.OrderYJBAmount - sad.OrderRefundAmount - sad.PromotionAmount - sad.OrderSpreadAmount.Value) * 100) / 100; } // 0.自营他配 else if (mall.Type == 0) { // 商品结算价 decimal totalsSettlePrice = 0; foreach (var item in items) { totalsSettlePrice += item.SettleAmount * item.OrderItemNumber; } sad.SettleAmount = totalsSettlePrice; // 商家结算金额 = 商品结算价*数量 + 运费 - 退款金额 sad.SellerAmount = Math.Truncate((sad.SettleAmount + sad.OrderFreight - sad.OrderRefundAmount) * 100) / 100; // 商城佣金 sad.PromotionAmount = Math.Truncate((sad.OrderRealAmount - sad.SellerAmount - sad.OrderSpreadAmount.Value) * 100) / 100; } // 2.自营自配自采 // 3.自营自配统采 if (contextSession != null) { foreach (var item in items) { contextSession.SaveObject(item); } contextSession.SaveObject(sad); } return(sad); }
/// <summary> /// 第三方电商售后服务退货结果回调 /// </summary> /// <param name="resultJsonStr"></param> /// <returns></returns> public static ThirdResponse RefundResultCallback(string resultJsonStr) { LogHelper.Debug("ThirdECommerceServiceHelper.RefundResultCallback第三方电商售后服务退货结果回调,Input:" + resultJsonStr); if (string.IsNullOrEmpty(resultJsonStr)) { return new ThirdResponse { Code = 20500, Msg = "缺少参数serviceRefundResult" } } ; var result = new ThirdResponse { Code = 200, Msg = "ok" }; try { var serviceResult = JsonConvert.DeserializeObject <ThirdServiceRefundResult>(resultJsonStr); if (serviceResult == null) { return new ThirdResponse { Code = 20501, Msg = "非法参数serviceRejectResult" } } ; Guid orderId, serviceId; DateTime auditTime; Guid.TryParse(serviceResult.OrderId, out orderId); Guid.TryParse(serviceResult.ServiceId, out serviceId); DateTime.TryParse(serviceResult.AuditTime, out auditTime); if (orderId == Guid.Empty) { return new ThirdResponse { Code = 20502, Msg = "非法参数OrderId" } } ; if (serviceId == Guid.Empty) { return new ThirdResponse { Code = 20503, Msg = "非法参数ServiceId" } } ; if (string.IsNullOrEmpty(serviceResult.SkuId)) { return new ThirdResponse { Code = 20504, Msg = "非法参数SkuId" } } ; if (auditTime == DateTime.MinValue) { return new ThirdResponse { Code = 20505, Msg = "非法参数AuditTime" } } ; if (serviceResult.RefundStatus < 0 || serviceResult.RefundStatus > 1) { return new ThirdResponse { Code = 20506, Msg = "非法参数RefundStatus" } } ; if (serviceResult.RefundStatus == 1 && string.IsNullOrEmpty(serviceResult.RejectReason)) { return new ThirdResponse { Code = 20507, Msg = "缺少参数RejectReason" } } ; #region 判断是否第三方电商售后服务单及获取售后服务单信息 var service = ThirdECService.ObjectSet().FirstOrDefault(o => o.OrderId == orderId && o.OrderRefundAfterSalesId == serviceId && o.SkuId == serviceResult.SkuId); if (service == null) { return new ThirdResponse { Code = 20508, Msg = "未找到此服务单" } } ; var orderRefund = OrderRefundAfterSales.ObjectSet().FirstOrDefault(p => p.Id == service.OrderRefundAfterSalesId); if (service == null) { return new ThirdResponse { Code = 20509, Msg = "未找到此服务单" } } ; if (service.AgreeRefundTime.HasValue || service.RejectRefundTime.HasValue) { return(result); } #endregion #region 退款处理 var errorMessage = string.Empty; if (serviceResult.RefundStatus == 0) { var refundResult = OrderHelper.ApproveOrderRefundAfterSales(orderRefund.OrderId, orderRefund.OrderItemId ?? Guid.Empty); if (refundResult.ResultCode == 0) { service.AgreeRefundTime = auditTime; service.StateName = "允许退货"; service.StateDesc = "售后服务退货结果回调:允许退货"; } else { errorMessage = refundResult.Message; result = new ThirdResponse { Code = 20510, Msg = "内部异常" }; } } else { var refundResult = OrderHelper.RejectOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty, serviceResult.RejectReason); if (refundResult.ResultCode == 0) { service.RejectRefundTime = auditTime; service.StateName = "拒绝退货"; service.StateDesc = "售后服务退货结果回调:拒绝退货," + serviceResult.RejectReason; } else { errorMessage = refundResult.Message; result = new ThirdResponse { Code = 20511, Msg = "内部异常" }; } } #endregion #region 保存ThirdECOrderJournal var journal = new ThirdECServiceJournal { Id = Guid.NewGuid(), OrderId = service.OrderId, OrderCode = service.OrderCode, OrderItemId = service.OrderItemId, OrderRefundAfterSalesId = service.OrderRefundAfterSalesId, Name = serviceResult.RefundStatus == 0 ? "允许退货" : "拒绝退货", Details = string.IsNullOrEmpty(errorMessage) ? service.StateDesc : errorMessage, Json = resultJsonStr, EntityState = EntityState.Added }; ContextFactory.CurrentThreadContext.SaveObject(journal); #endregion int count = ContextFactory.CurrentThreadContext.SaveChanges(); if (count == 0) { LogHelper.Error(string.Format("ThirdECommerceServiceHelper.RefundResultCallback第三方电商售后服务退货结果回调数据保存失败,入参:{0}", resultJsonStr)); result = new ThirdResponse { Code = 20512, Msg = "内部异常" }; } } catch (Exception ex) { LogHelper.Error("ThirdECommerceServiceHelper.RefundResultCallback第三方电商售后服务退货结果回调异常,Input:" + resultJsonStr, ex); result = new ThirdResponse { Code = 20513, Msg = "内部异常" }; } return(result); } #endregion }
/// <summary> /// 第三方电商允许售后结果回调 /// </summary> /// <param name="resultJsonStr"></param> public static ThirdResponse AgreeServiceCallback(string resultJsonStr) { LogHelper.Debug("ThirdECommerceServiceHelper.AgreeServiceCallback第三方电商允许售后结果回调,Input:" + resultJsonStr); if (string.IsNullOrEmpty(resultJsonStr)) { return new ThirdResponse { Code = 20100, Msg = "缺少参数serviceAgreeResult" } } ; var result = new ThirdResponse { Code = 200, Msg = "ok" }; try { var serviceResult = JsonConvert.DeserializeObject <ThirdServiceAgreeResult>(resultJsonStr); if (serviceResult == null) { return new ThirdResponse { Code = 20101, Msg = "非法参数serviceAgreeResult" } } ; Guid orderId, serviceId; DateTime agreeTime; Guid.TryParse(serviceResult.OrderId, out orderId); Guid.TryParse(serviceResult.ServiceId, out serviceId); DateTime.TryParse(serviceResult.AgreeTime, out agreeTime); if (orderId == Guid.Empty) { return new ThirdResponse { Code = 20102, Msg = "非法参数OrderId" } } ; if (serviceId == Guid.Empty) { return new ThirdResponse { Code = 20103, Msg = "非法参数ServiceId" } } ; if (agreeTime == DateTime.MinValue) { return new ThirdResponse { Code = 20104, Msg = "非法参数AgreeTime" } } ; if (serviceResult.Address == null) { return new ThirdResponse { Code = 20105, Msg = "非法参数Address" } } ; if (string.IsNullOrEmpty(serviceResult.Address.Name)) { return new ThirdResponse { Code = 20106, Msg = "缺少参数Address.Name" } } ; if (string.IsNullOrEmpty(serviceResult.Address.Phone)) { return new ThirdResponse { Code = 20107, Msg = "缺少参数Address.Phone" } } ; //if (string.IsNullOrEmpty(serviceResult.Address.ProvinceName)) return new ThirdResponse { Code = 20108, Msg = "缺少参数Address.ProvinceName" }; //if (string.IsNullOrEmpty(serviceResult.Address.CityName)) return new ThirdResponse { Code = 20109, Msg = "缺少参数Address.CityName" }; //if (string.IsNullOrEmpty(serviceResult.Address.CountyName)) return new ThirdResponse { Code = 20110, Msg = "缺少参数Address.CountyName" }; //if (string.IsNullOrEmpty(serviceResult.Address.TownName)) return new ThirdResponse { Code = 20111, Msg = "缺少参数Address.TownName" }; //if (string.IsNullOrEmpty(serviceResult.Address.AddressDetail)) return new ThirdResponse { Code = 20112, Msg = "缺少参数Address.AddressDetail" }; if (string.IsNullOrEmpty(serviceResult.Address.FullAddress)) { return new ThirdResponse { Code = 20113, Msg = "缺少参数Address.FullAddress" } } ; #region 判断是否第三方电商售后服务单及获取售后服务单信息 var service = ThirdECService.ObjectSet().FirstOrDefault(o => o.OrderId == orderId && o.OrderRefundAfterSalesId == serviceId); if (service == null) { return new ThirdResponse { Code = 20114, Msg = "未找到此服务单" } } ; var orderRefund = OrderRefundAfterSales.ObjectSet().FirstOrDefault(p => p.Id == service.OrderRefundAfterSalesId); if (service == null) { return new ThirdResponse { Code = 20115, Msg = "未找到此服务单" } } ; if (service.AgreeApplyTime.HasValue) { return(result); } #endregion #region 退款处理 var refundResult = OrderHelper.ApproveOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty); if (refundResult.ResultCode == 0) { service.AgreeApplyTime = agreeTime; service.StateName = "允许售后"; service.StateDesc = "售后服务申请审核结果回调:允许售后"; orderRefund.RefundReceiveFullAddress = serviceResult.Address.FullAddress; orderRefund.RefundReceiveMobile = serviceResult.Address.Phone; orderRefund.RefundReceiveName = serviceResult.Address.Name; } else { result = new ThirdResponse { Code = 20116, Msg = "内部异常" } }; #endregion #region 保存ThirdECOrderJournal var journal = new ThirdECServiceJournal { Id = Guid.NewGuid(), OrderId = service.OrderId, OrderCode = service.OrderCode, OrderItemId = service.OrderItemId, OrderRefundAfterSalesId = service.OrderRefundAfterSalesId, Name = "售后服务申请审核结果回调:允许售后", Details = refundResult.ResultCode == 0 ? "售后服务申请审核结果回调:允许售后" : refundResult.Message, Json = resultJsonStr, EntityState = EntityState.Added }; ContextFactory.CurrentThreadContext.SaveObject(journal); #endregion int count = ContextFactory.CurrentThreadContext.SaveChanges(); if (count == 0) { LogHelper.Error(string.Format("ThirdECommerceServiceHelper.AgreeServiceCallback第三方电商允许售后结果回调数据保存失败,入参:{0}", resultJsonStr)); result = new ThirdResponse { Code = 20117, Msg = "内部异常" }; } } catch (Exception ex) { LogHelper.Error("ThirdECommerceServiceHelper.AgreeServiceCallback第三方电商允许售后结果回调异常,Input:" + resultJsonStr, ex); result = new ThirdResponse { Code = 20118, Msg = "内部异常" }; } return(result); }
/// <summary> /// 退货地址回调 /// </summary> /// <param name="result"></param> public static void OrderRefundAddress(RefundAddress result) { try { Guid orderId; Guid.TryParse(result.orderId, out orderId); LogHelper.Debug("进入 YXOrderHelper.OrderRefundAddress,Input:" + JsonConvert.SerializeObject(result)); var orderRefund = OrderRefundAfterSales.ObjectSet().Where(_ => _.ApplyId == result.applyId).FirstOrDefault(); if (orderRefund == null) { LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); } var refundResult = OrderHelper.ApproveOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty); if (refundResult.ResultCode != 0) { // 失败 LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); } else { ContextSession contextSession = ContextFactory.CurrentThreadContext; orderRefund.RefundReturnType = result.type; orderRefund.RefundReceiveFullAddress = result.returnAddr.fullAddress; orderRefund.RefundReceiveMobile = result.returnAddr.mobile; orderRefund.RefundReceiveName = result.returnAddr.name; //orderRefund.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(orderRefund); contextSession.SaveChanges(); } //if (result.applyId.StartsWith("s")) //{ // // 售后 // var orderRefund = OrderRefundAfterSales.FindByID(new Guid(result.applyId.Substring(1))); // if (orderRefund == null) // { // LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); // } // var refundResult = OrderHelper.ApproveOrderRefund(orderId, orderRefund.OrderItemId ?? Guid.Empty); // if (refundResult.ResultCode != 0) // { // // 失败 // LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); // } //} //else //{ // //售前 // var orderRefund = OrderRefund.FindByID(new Guid(result.applyId)); // if (orderRefund == null) // { // LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败,未找到退款记录,Input:" + JsonConvert.SerializeObject(result)); // } // var refundResult = OrderHelper.ApproveOrderRefundAfterSales(orderId, orderRefund.OrderItemId ?? Guid.Empty); // if (refundResult.ResultCode != 0) // { // // 失败 // LogHelper.Error("YXOrderHelper.OrderRefundAddress 失败," + refundResult.Message + ",Input:" + JsonConvert.SerializeObject(result)); // } //} } catch (Exception ex) { LogHelper.Error("YXOrderHelper.OrderRefundAddress 异常,Input:" + JsonConvert.SerializeObject(result), ex); } }
/// <summary> /// 进销存-同步京东服务单状态 /// </summary> /// <param name="arg"></param> /// <returns></returns> public ResultDTO SynchronizeJDServiceStateExt(SynchronizeJDServiceStateDTO arg) { var json = string.Empty; var result = new ResultDTO(); try { json = JsonHelper.JsonSerializer(arg); LogHelper.Debug("进销存-同步京东服务单状态,入参:" + json); var service = JDEclpOrderRefundAfterSales.ObjectSet() .Where(p => p.Id == arg.JDEclpOrderRefundAfterSalesId) .FirstOrDefault(); if (service == null) { return new ResultDTO { isSuccess = true, Message = "京东服务单不存在" } } ; var refund = OrderRefundAfterSales.ObjectSet().Where(p => p.Id == service.OrderRefundAfterSalesId).FirstOrDefault(); if (refund == null) { return new ResultDTO { isSuccess = true, Message = "售后退款单不存在" } } ; if (JDEclpOrderRefundAfterSalesJournal.ObjectSet().Any(p => p.Code == arg.Code)) { return new ResultDTO { isSuccess = true, Message = "已同步过" } } ; switch ((JDEclpServicesStateEnum)arg.StateTo) { case JDEclpServicesStateEnum.EclpServiceState20080: //正常入库 case JDEclpServicesStateEnum.EclpServiceState20100: //异常入库 var goodNum = arg.ServiceItemList.Count(p => p.WareType == 1 && p.GoodsStatus == 1); //可退商品数量 if (goodNum != arg.ServiceItemList.Count) { if (goodNum == 0) { refund.RefundMoney = 0; } refund.RefundMoney = Math.Round(refund.RefundMoney * goodNum / arg.ServiceItemList.Count, 2); } break; } var journal = new JDEclpOrderRefundAfterSalesJournal { Id = Guid.NewGuid(), OrderId = service.OrderId, OrderCode = service.OrderCode, OrderItemId = service.OrderItemId, OrderRefundAfterSalesId = service.OrderRefundAfterSalesId, EclpOrderNo = service.EclpOrderNo, EclpServicesNo = arg.EclpServicesNo, SubTime = arg.SubTime, Name = new EnumHelper().GetDescription((JDEclpServicesStateEnum)arg.StateTo), Details = arg.Name, StateFrom = service.EclpServicesState, StateTo = arg.StateTo, JDEclpOrderRefundAfterSalesId = service.Id, WarehouseNo = arg.WarehouseNo, WarehouseName = arg.WarehouseName, EntityState = System.Data.EntityState.Added }; ContextFactory.CurrentThreadContext.SaveObject(journal); if (arg.ServiceItemList != null && arg.ServiceItemList.Count > 0) { arg.ServiceItemList.ForEach(p => { var item = new JDEclpOrderRefundAfterSalesItem { Id = Guid.NewGuid(), JDEclpOrderRefundAfterSalesId = service.Id, IsvGoodsNo = p.IsvGoodsNo, SpareCode = p.SpareCode ?? string.Empty, PartReceiveType = p.PartReceiveType, GoodsStatus = p.GoodsStatus, WareType = p.WareType, ApproveNotes = p.ApproveNotes, EntityState = System.Data.EntityState.Added }; ContextFactory.CurrentThreadContext.SaveObject(item); }); } service.EclpServicesState = arg.StateTo; service.EclpServicesStateName = new EnumHelper().GetDescription((JDEclpServicesStateEnum)arg.StateTo); if (ContextFactory.CurrentThreadContext.SaveChanges() > 0) { result.isSuccess = true; result.Message = "同步成功"; } else { LogHelper.Error("进销存-同步京东服务单状态:数据保存失败,入参:" + json); result.Message = "数据保存失败"; } } catch (Exception ex) { LogHelper.Error("进销存-同步京东服务单状态异常,入参:" + json, ex); result.Message = "同步异常"; } return(result); }