public static void Update(OrderRefundInfo entity) { dal.Update(entity); //服务工单审核不通过,或被取消。回滚在处理的退款的商品数量 if (entity.Status == (int)OrderRefundStatus.Reject || entity.Status == (int)OrderRefundStatus.Cancel) { //退商品 if (entity.OrderDetailId > 0) { OrderDetailBLL.ChangeRefundCount(entity.OrderDetailId, entity.RefundCount, ChangeAction.Minus); } //退订单 else { var orderRefundList = ReadListValid(entity.OrderId); foreach (var orderDetail in OrderDetailBLL.ReadList(entity.OrderId)) { //逐一退商品 //如果前面有提交过该商品的退款服务单,则不能回滚这个商品的数量(orderDetail.RefundCount - refundCount) int refundCount = orderRefundList.Where(k => k.OrderDetailId == orderDetail.Id).Sum(k => k.RefundCount); OrderDetailBLL.ChangeRefundCount(orderDetail.Id, orderDetail.RefundCount - refundCount, ChangeAction.Minus); } } } //退款完成,更新原订单(商品)的退款状态,库存回滚 var order = OrderBLL.Read(entity.OrderId); if (entity.Status == (int)OrderRefundStatus.HasReturn) { //退单个商品 if (entity.OrderDetailId > 0) { //计算已退商品总数是否与订单商品总数相同,如相同则更改订单状态 var orderRefundList = ReadList(entity.OrderId); orderRefundList = orderRefundList.Where(k => k.Status == (int)OrderRefundStatus.HasReturn).ToList(); var orderDetailList = OrderDetailBLL.ReadList(entity.OrderId); if (orderRefundList.Sum(k => k.RefundCount) == orderDetailList.Sum(k => k.BuyCount)) { UpdateOrderRefundStatus(order); } //库存回滚 var orderDetail = OrderDetailBLL.Read(entity.OrderDetailId); ProductBLL.ChangeOrderCount(orderDetail.ProductId, -orderDetail.RefundCount); if (!string.IsNullOrEmpty(orderDetail.StandardValueList)) { ProductTypeStandardRecordBLL.ChangeOrderCount(orderDetail.ProductId, orderDetail.StandardValueList, orderDetail.RefundCount, ChangeAction.Minus); } if (order.OrderStatus >= (int)OrderStatus.HasShipping) { ProductBLL.ChangeSendCount(orderDetail.ProductId, -orderDetail.RefundCount); if (!string.IsNullOrEmpty(orderDetail.StandardValueList)) { ProductTypeStandardRecordBLL.ChangeSendCount(orderDetail.ProductId, orderDetail.StandardValueList, orderDetail.RefundCount, ChangeAction.Minus); } } } //退订单 else { UpdateOrderRefundStatus(order); //库存回滚 var orderRefundList = ReadListValid(entity.OrderId); foreach (var orderDetail in OrderDetailBLL.ReadList(entity.OrderId)) { //逐一处理 //如果前面有提交过该商品的退款服务单,则不能回滚这个商品的数量 int refundCount = orderRefundList.Where(k => k.OrderDetailId == orderDetail.Id).Sum(k => k.RefundCount); int buyCount = orderDetail.BuyCount - refundCount; if (buyCount > 0) { ProductBLL.ChangeOrderCount(orderDetail.ProductId, -buyCount); if (!string.IsNullOrEmpty(orderDetail.StandardValueList)) { ProductTypeStandardRecordBLL.ChangeOrderCount(orderDetail.ProductId, orderDetail.StandardValueList, buyCount, ChangeAction.Minus); } if (order.OrderStatus >= (int)OrderStatus.HasShipping) { ProductBLL.ChangeSendCount(orderDetail.ProductId, -buyCount); if (!string.IsNullOrEmpty(orderDetail.StandardValueList)) { ProductTypeStandardRecordBLL.ChangeSendCount(orderDetail.ProductId, orderDetail.StandardValueList, buyCount, ChangeAction.Minus); } } } } } } }