Esempio n. 1
0
        /// <summary>
        /// 对最终需要提交的退款服务单,做进一步的验证
        /// </summary>
        /// <param name="orderRefund"></param>
        /// <param name="needRefundMoney">本次服务单需退款的金额</param>
        /// <returns></returns>
        public static JWRefundMsg VerifySubmitOrderRefund(OrderRefundInfo orderRefund, decimal needRefundMoney)
        {
            var refundMsg = new JWRefundMsg {
                CanRefund = false
            };

            //退款金额必须大于0
            if (needRefundMoney <= 0)
            {
                refundMsg.ErrorCode = JWRefundErrorCode.REFUND_MONEY_MUST_GT0_ERROR;
                return(refundMsg);
            }

            var order = OrderBLL.Read(orderRefund.OrderId);

            OrderDetailInfo orderDetail = null;

            if (orderRefund.OrderDetailId > 0)
            {
                orderDetail = OrderDetailBLL.Read(orderRefund.OrderDetailId);
            }

            //验证该退款单能否被退款
            refundMsg = CanRefund(order, orderDetail, orderRefund.RefundCount, needRefundMoney);
            if (!refundMsg.CanRefund)
            {
                return(refundMsg);
            }

            orderRefund.OrderNumber   = order.OrderNumber;
            orderRefund.RefundPayKey  = order.PayKey;
            orderRefund.RefundPayName = order.PayName;
            orderRefund.OrderDetailId = orderDetail == null ? 0 : orderDetail.Id;
            orderRefund.OwnerId       = order.UserId;

            /*-----退款金额分配(余额与第三方支付金额) start----------------------------------------------------*/

            //已退余额金额
            var     orderRefundList  = OrderRefundBLL.ReadListValid(orderRefund.OrderId);
            decimal hasRefundBalance = orderRefundList.Sum(k => k.RefundBalance);

            //退商品
            if (orderRefund.OrderDetailId > 0)
            {
                //如果需要退款的金额不大于剩余未退的余额金额,则全部退到余额账户
                if (needRefundMoney <= (order.Balance - hasRefundBalance))
                {
                    orderRefund.RefundBalance = needRefundMoney;
                    orderRefund.RefundMoney   = 0;
                }
                else
                {
                    orderRefund.RefundBalance = (order.Balance - hasRefundBalance);
                    orderRefund.RefundMoney   = needRefundMoney - (order.Balance - hasRefundBalance);
                }
            }
            //退订单
            else
            {
                orderRefund.RefundBalance = (order.Balance - hasRefundBalance);
                orderRefund.RefundMoney   = needRefundMoney - (order.Balance - hasRefundBalance);
            }
            /*-----退款金额分配(余额与第三方支付金额) end------------------------------------------------------*/

            refundMsg.CanRefund = true;
            return(refundMsg);
        }
Esempio n. 2
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }