Example #1
0
        /// <summary>
        /// 计算本次退款的可退数量
        /// </summary>
        /// <param name="order">订单</param>
        /// <param name="orderDetail">退商品时可用,如果是退订单可不传参</param>
        /// <param name="refundCount">退商品时可用,退款商品的数量</param>
        /// <returns></returns>
        private static JWRefundMsg CanRefundCount(OrderInfo order, OrderDetailInfo orderDetail = null, int refundCount = 0)
        {
            JWRefundMsg refundMsg = new JWRefundMsg {
                CanRefund = false
            };

            //退商品
            if (orderDetail != null && orderDetail.Id > 0)
            {
                //退款数量必须大于0
                if (refundCount < 1)
                {
                    refundMsg.ErrorCode = JWRefundErrorCode.REFUND_COUNT_MUST_GT0_ERROR;
                    return(refundMsg);
                }

                refundMsg.CanRefundCount = orderDetail.BuyCount - orderDetail.RefundCount;
            }
            //退订单
            else
            {
                var orderDetailList = OrderDetailBLL.ReadList(order.Id);
                refundMsg.CanRefundCount = orderDetailList.Sum(k => k.BuyCount - k.RefundCount);
            }

            //是否超过最大可退数量,并且保证还有商品可以退款
            if (refundMsg.CanRefundCount < 1 || refundCount > refundMsg.CanRefundCount)
            {
                refundMsg.ErrorCode = JWRefundErrorCode.CAN_REFUND_COUNT_ERROR;
                return(refundMsg);
            }

            refundMsg.CanRefund = true;
            return(refundMsg);
        }
Example #2
0
        /// <summary>
        /// 读取订单商品价格
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static decimal ReadOrderProductPrice(int id)
        {
            decimal result = 0;

            foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(id))
            {
                result += orderDetail.ProductPrice * orderDetail.BuyCount;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 读取订单赠送积分
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int ReadOrderSendPoint(int id)
        {
            int result = 0;

            foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(id))
            {
                result += orderDetail.SendPoint * orderDetail.BuyCount;
            }
            return(result);
        }
Example #4
0
        public static void ChangeSendCountByOrder(int orderId, ChangeAction action)
        {
            dal.ChangeSendCountByOrder(orderId, action);
            //购买的是该商品下面的具体规格产品
            var orderDetailList = OrderDetailBLL.ReadList(orderId);

            foreach (var orderDetail in orderDetailList)
            {
                if (!string.IsNullOrEmpty(orderDetail.StandardValueList))
                {
                    ProductTypeStandardRecordBLL.ChangeSendCount(orderDetail.ProductId, orderDetail.StandardValueList, orderDetail.BuyCount, action);
                }
            }
        }
Example #5
0
        /// <summary>
        /// 计算订单的邮费
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static decimal ReadOrderShippingMoney(OrderInfo order)
        {
            decimal            shippingMoney  = order.ShippingMoney;
            ShippingInfo       shipping       = ShippingBLL.Read(order.ShippingId);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(order.ShippingId, order.RegionId);

            switch (shipping.ShippingType)
            {
            case (int)ShippingType.Fixed:
                shippingMoney = shippingRegion.FixedMoeny;
                break;

            case (int)ShippingType.Weight:
                decimal orderProductWeight = 0;
                foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(order.Id))
                {
                    orderProductWeight += orderDetail.ProductWeight * orderDetail.BuyCount;
                }
                if (orderProductWeight <= shipping.FirstWeight)
                {
                    shippingMoney = shippingRegion.FirstMoney;
                }
                else
                {
                    shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((orderProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney;
                }
                break;

            case (int)ShippingType.ProductCount:
                int orderProductCount = 0;
                foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(order.Id))
                {
                    if (orderDetail.ParentId == 0)
                    {
                        orderProductCount += orderDetail.BuyCount;
                    }
                }
                shippingMoney = shippingRegion.OneMoeny + (orderProductCount - 1) * shippingRegion.AnotherMoeny;
                break;

            default:
                break;
            }
            return(shippingMoney);
        }
Example #6
0
        public static int Add(OrderRefundInfo entity)
        {
            int id = dal.Add(entity);

            //增加订单详细表中的退款商品数量
            if (id > 0)
            {
                //退商品
                if (entity.OrderDetailId > 0)
                {
                    OrderDetailBLL.ChangeRefundCount(entity.OrderDetailId, entity.RefundCount, ChangeAction.Plus);
                }
                //退订单
                else
                {
                    foreach (var orderDetail in OrderDetailBLL.ReadList(entity.OrderId))
                    {
                        OrderDetailBLL.ChangeRefundCount(orderDetail.Id, orderDetail.BuyCount - orderDetail.RefundCount, ChangeAction.Plus);
                    }
                }
            }

            return(id);
        }
Example #7
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);
                                }
                            }
                        }
                    }
                }
            }
        }