public static bool RefundCoupon(ContextSession contextSession, CommodityOrder commodityOrder) { var result = Instance.RefundCoupon(new SpendCouponRequestDTO { EsAppId = commodityOrder.EsAppId ?? Guid.Empty, ShopID = commodityOrder.AppId, OrderID = commodityOrder.Id, UserID = commodityOrder.UserId }); if (result.IsSuccess) { return(result.IsSuccess); } LogHelper.Error(string.Format("取消订单时回退优惠券失败。OrderId:{0},", commodityOrder.Id)); ErrorCommodityOrder errorOrder = new ErrorCommodityOrder { Id = Guid.NewGuid(), ErrorOrderId = commodityOrder.Id, ResourceType = 8, Description = "取消订单时回退优惠券失败", Source = commodityOrder.State, State = 0, AppId = commodityOrder.EsAppId.HasValue ? commodityOrder.EsAppId.Value : commodityOrder.AppId, UserId = commodityOrder.UserId, OrderCode = commodityOrder.Code, CouponId = Guid.Empty, SubTime = DateTime.Now, ModifiedOn = DateTime.Now, EntityState = System.Data.EntityState.Added }; contextSession.SaveObject(errorOrder); return(result.IsSuccess); }
/// <summary> /// Job自动处理取消订单时回退积分 /// </summary> public void AutoDealOrderCancelSroreExt() { LogHelper.Info(string.Format("Job处理取消订单时回退积分的服务开始")); //处理订单状态为已退款 try { ContextSession contextSession = ContextFactory.CurrentThreadContext; int pageSize = 20; while (true) { List <int> state = new List <int>() { 4, 5, 6 }; //DateTime lastday = now; var errorCommodityOrderList = ErrorCommodityOrder.ObjectSet().Where(t => t.State == 0 && state.Contains(t.Source) && t.ResourceType == 1).Take(pageSize).ToList(); if (!errorCommodityOrderList.Any()) { break; } LogHelper.Info(string.Format("Job处理取消订单时回退积分的服务处理订单数:{0}", errorCommodityOrderList.Count)); foreach (ErrorCommodityOrder errorCommodityOrder in errorCommodityOrderList) { bool result = SignSV.Instance.RefundScore(errorCommodityOrder.UserId, errorCommodityOrder.AppId, errorCommodityOrder.Score, errorCommodityOrder.ErrorOrderId, errorCommodityOrder.OrderCode, (ScoreTypeEnum)errorCommodityOrder.ScoreType); if (!result) { continue; } errorCommodityOrder.State = 1; errorCommodityOrder.ModifiedOn = DateTime.Now; errorCommodityOrder.EntityState = System.Data.EntityState.Modified; contextSession.SaveChanges(); } if (errorCommodityOrderList.Count < pageSize) { break; } } LogHelper.Info("Job处理取消订单时回退积分的服务成功"); } catch (Exception ex) { LogHelper.Error("Job处理取消订单时回退积分的服务异常。", ex); } }
/// <summary> /// 售后完成渠道打积分 /// </summary> /// <param name="contextSession"></param> /// <param name="commodityOrder"></param> /// <param name="commodityOrderService"></param> /// <returns></returns> public static bool ChannelShareSaleGiveScore(ContextSession contextSession, CommodityOrder commodityOrder, CommodityOrderService commodityOrderService) { if (!commodityOrder.EsAppId.HasValue) { return(true); } //使用了积分 if (commodityOrder.ChannelShareMoney > 0) { //取商货众销的收款人 var shareModel = OrderShare.ObjectSet().FirstOrDefault(t => t.OrderId == commodityOrder.Id && t.PayeeType == 12); //没有收款人 if (shareModel == null || shareModel.PayeeId == Guid.Empty) { LogHelper.Error(string.Format("售后完成渠道打积,找不到收款人。OrderId:{0}", commodityOrder.Id)); return(false); } //获取当时的积分比例 CostScoreInfoDTO scoreCostDto; if (new ScoreSV().GetScoreCost(commodityOrder.EsAppId.Value, out scoreCostDto, commodityOrder.SubTime)) { int srore = (int)(commodityOrder.ChannelShareMoney * scoreCostDto.Cost); bool refundScoreResult = Instance.GiveScoreBtpShare(shareModel.PayeeId, commodityOrder.EsAppId.Value, srore, commodityOrder.Id, commodityOrder.Code, ScoringType.BtpChannelBrokerage, commodityOrder.ChannelShareMoney, scoreCostDto.Cost, scoreCostDto.ScoreType); if (!refundScoreResult) { LogHelper.Error(string.Format("售后完成渠道打积分失败。UserId:{0},AppId:{1},srore:{2},OrderId:{3}", shareModel.PayeeId, commodityOrder.AppId, srore, commodityOrder.Id)); ErrorCommodityOrder errorOrder = new ErrorCommodityOrder { Id = Guid.NewGuid(), ErrorOrderId = commodityOrder.Id, ResourceType = 6, Source = 3, State = 0, AppId = commodityOrder.EsAppId.Value, UserId = shareModel.PayeeId, OrderCode = commodityOrder.Code, CouponId = Guid.Empty, Score = srore, SubTime = DateTime.Now, ModifiedOn = DateTime.Now, ScoreType = (int)scoreCostDto.ScoreType, EntityState = System.Data.EntityState.Added }; contextSession.SaveObject(errorOrder); } return(refundScoreResult); } } return(true); }
/// <summary> /// 取消订单时回退积分 /// </summary> /// <param name="contextSession"></param> /// <param name="commodityOrder"></param> /// <returns></returns> public static bool CommodityOrderCancelSrore(ContextSession contextSession, CommodityOrder commodityOrder) { if (!commodityOrder.EsAppId.HasValue) { return(true); } //获取下订单时用的积分金额 var sroreMoney = OrderPayDetail.ObjectSet().Where(t => t.OrderId == commodityOrder.Id && t.ObjectType == 2 && t.Amount > 0).Select(t => t.Amount).FirstOrDefault(); if (sroreMoney <= 0) { return(true); } //获取当时的积分汇率 CostScoreInfoDTO scoreCostDto; bool isscsc = new ScoreSV().GetScoreCost(commodityOrder.EsAppId.Value, out scoreCostDto, commodityOrder.SubTime); if (!isscsc) { return(true); } int srore = (int)(sroreMoney * scoreCostDto.Cost); bool refundScoreResult = Instance.RefundScore(commodityOrder.UserId, commodityOrder.EsAppId.Value, srore, commodityOrder.Id, commodityOrder.Code, scoreCostDto.ScoreType); if (refundScoreResult) { return(refundScoreResult); } LogHelper.Error(string.Format("取消订单时回退积分失败。UserId:{0},EsAppId:{1},srore:{2}", commodityOrder.UserId, commodityOrder.EsAppId.Value, srore)); ErrorCommodityOrder errorOrder = new ErrorCommodityOrder(); errorOrder.Id = Guid.NewGuid(); errorOrder.ErrorOrderId = commodityOrder.Id; errorOrder.ResourceType = 1; errorOrder.Source = commodityOrder.State; errorOrder.State = 0; errorOrder.AppId = commodityOrder.EsAppId.Value; errorOrder.UserId = commodityOrder.UserId; errorOrder.OrderCode = commodityOrder.Code; errorOrder.CouponId = Guid.Empty; errorOrder.Score = srore; errorOrder.SubTime = DateTime.Now; errorOrder.ModifiedOn = DateTime.Now; errorOrder.ScoreType = (int)scoreCostDto.ScoreType; errorOrder.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(errorOrder); return(refundScoreResult); }
/// <summary> /// 记录易捷币错误信息 /// </summary> /// <param name="contextSession"></param> /// <param name="commodityOrder"></param> /// <param name="description"></param> private static void LogOrderErrorInfo(ContextSession contextSession, CommodityOrder commodityOrder, string description) { ErrorCommodityOrder errorOrder = new ErrorCommodityOrder(); errorOrder.Id = Guid.NewGuid(); errorOrder.ErrorOrderId = commodityOrder.Id; errorOrder.ResourceType = 7; errorOrder.Description = description; errorOrder.Source = commodityOrder.State; errorOrder.State = 0; errorOrder.AppId = commodityOrder.EsAppId.Value; errorOrder.UserId = commodityOrder.UserId; errorOrder.OrderCode = commodityOrder.Code; errorOrder.SubTime = DateTime.Now; errorOrder.ModifiedOn = DateTime.Now; errorOrder.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(errorOrder); }
/// <summary> /// 售中退款时回退积分 /// </summary> /// <param name="contextSession"></param> /// <param name="commodityOrder"></param> /// <param name="orderRefund"></param> /// <returns></returns> public static bool CommodityOrderRefundScore(ContextSession contextSession, CommodityOrder commodityOrder, OrderRefund orderRefund) { if (!commodityOrder.EsAppId.HasValue) { return(true); } //使用了积分 if (orderRefund.RefundScoreMoney > 0) { //获取当时的积分比例 CostScoreInfoDTO scoreCostDto; if (new ScoreSV().GetScoreCost(commodityOrder.EsAppId.Value, out scoreCostDto, commodityOrder.SubTime)) { int srore = (int)(orderRefund.RefundScoreMoney * scoreCostDto.Cost); bool refundScoreResult = SignSV.Instance.RefundScore(commodityOrder.UserId, commodityOrder.EsAppId.Value, srore, commodityOrder.Id, commodityOrder.Code, scoreCostDto.ScoreType); if (!refundScoreResult) { LogHelper.Error(string.Format("售中退款时回退积分失败。UserId:{0},EsAppId:{1},srore:{2}", commodityOrder.UserId, commodityOrder.EsAppId.Value, srore)); ErrorCommodityOrder errorOrder = new ErrorCommodityOrder(); errorOrder.Id = Guid.NewGuid(); errorOrder.ErrorOrderId = commodityOrder.Id; errorOrder.ResourceType = 1; errorOrder.Source = 7; errorOrder.State = 0; errorOrder.AppId = commodityOrder.EsAppId.Value; errorOrder.UserId = commodityOrder.UserId; errorOrder.OrderCode = commodityOrder.Code; errorOrder.CouponId = Guid.Empty; errorOrder.Score = srore; errorOrder.SubTime = DateTime.Now; errorOrder.ModifiedOn = DateTime.Now; errorOrder.ScoreType = (int)scoreCostDto.ScoreType; errorOrder.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(errorOrder); } return(refundScoreResult); } } return(true); }
/// <summary> /// 售后完成三级分销打积分 /// </summary> /// <param name="contextSession"></param> /// <param name="commodityOrder"></param> /// <param name="commodityOrderService"></param> /// <returns></returns> public static bool DistributeSaleGiveScore(ContextSession contextSession, CommodityOrder commodityOrder, CommodityOrderService commodityOrderService) { if (!commodityOrder.EsAppId.HasValue) { return(true); } List <int> payeeTypeList = new List <int>() { 9, 10, 11 }; //取得三级分销应分的积分记录 var osQuery = OrderShare.ObjectSet() .Where( t => t.OrderId == commodityOrder.Id && t.Commission > 0 && payeeTypeList.Contains(t.PayeeType)) .ToList(); //使用了积分 if (osQuery.Any()) { //获取当时的积分比例 CostScoreInfoDTO scoreCostDto; if (new ScoreSV().GetScoreCost(commodityOrder.EsAppId.Value, out scoreCostDto, commodityOrder.SubTime)) { bool isAllSuccess = true; foreach (var orderShare in osQuery) { int srore = (int)(orderShare.Commission * scoreCostDto.Cost); bool refundScoreResult = SignSV.Instance.GiveScoreBtpShare(orderShare.PayeeId, commodityOrder.AppId, srore, commodityOrder.Id, commodityOrder.Code, Jinher.AMP.Sign.Deploy.Enum.ScoringType.BtpDistributeSale, orderShare.Commission, scoreCostDto.Cost, scoreCostDto.ScoreType); if (!refundScoreResult) { isAllSuccess = false; LogHelper.Error(string.Format("售售后完成三级分销打积分失败。UserId:{0},AppId:{1},srore:{2},OrderId:{3}", orderShare.PayeeId, commodityOrder.AppId, srore, commodityOrder.Id)); ErrorCommodityOrder errorOrder = new ErrorCommodityOrder(); errorOrder.Id = Guid.NewGuid(); errorOrder.ErrorOrderId = commodityOrder.Id; if (orderShare.PayeeType == 9) { errorOrder.ResourceType = 2; } else if (orderShare.PayeeType == 10) { errorOrder.ResourceType = 3; } else if (orderShare.PayeeType == 11) { errorOrder.ResourceType = 4; } errorOrder.Source = 3; errorOrder.State = 0; errorOrder.AppId = commodityOrder.AppId; errorOrder.UserId = orderShare.PayeeId; errorOrder.OrderCode = commodityOrder.Code; errorOrder.CouponId = Guid.Empty; errorOrder.Score = srore; errorOrder.SubTime = DateTime.Now; errorOrder.ModifiedOn = DateTime.Now; errorOrder.ScoreType = (int)scoreCostDto.ScoreType; errorOrder.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(errorOrder); } } return(isAllSuccess); } } return(true); }