Esempio n. 1
0
        public static void Delete(int id)
        {
            OrderDetailBLL.DeleteByOrderId(new int[] { id });
            OrderActionBLL.DeleteByOrderId(new int[] { id });

            dal.Delete(id);
        }
Esempio n. 2
0
        public static void Delete(int[] ids, int userId)
        {
            OrderDetailBLL.DeleteByOrderId(ids);
            OrderActionBLL.DeleteByOrderId(ids);

            dal.Delete(ids, userId);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="ids"></param>
        public static void DeleteLogically(string ids)
        {
            string[] delArr = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (delArr.Length > 0)
            {
                foreach (string did in delArr)
                {
                    int id = 0;
                    if (int.TryParse(did, out id))
                    {
                        bool canDel = true;
                        if (OrderDetailBLL.ReadListByProductId(id).Count > 0)
                        {
                            foreach (OrderDetailInfo myOD in OrderDetailBLL.ReadListByProductId(id))
                            {
                                OrderInfo tempOrder = OrderBLL.Read(myOD.OrderId, 0);
                                if (tempOrder.IsDelete == 0)
                                {
                                    canDel = false;
                                    break;
                                }
                            }
                            if (!canDel)
                            {
                                ScriptHelper.Alert("该产品存在相关订单,不能删除。");
                            }
                            else
                            {
                                var product = Read(id);

                                if (product.Id > 0)
                                {
                                    dal.DeleteLogically(id);
                                    CacheHelper.Remove("ProductClass");
                                }
                            }
                        }
                        else
                        {
                            var product = Read(id);

                            if (product.Id > 0)
                            {
                                dal.DeleteLogically(id);
                                CacheHelper.Remove("ProductClass");
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 彻底删除
        /// </summary>
        /// <param name="id"></param>
        public static void Delete(int id)
        {
            bool canDel = true;

            if (OrderDetailBLL.ReadListByProductId(id).Count > 0)
            {
                foreach (OrderDetailInfo myOD in OrderDetailBLL.ReadListByProductId(id))
                {
                    OrderInfo tempOrder = OrderBLL.Read(myOD.OrderId, 0);
                    if (tempOrder.IsDelete == 0)
                    {
                        canDel = false;
                        break;
                    }
                }
                if (!canDel)
                {
                    ScriptHelper.Alert("该产品存在相关订单,不能删除。");
                }
                else
                {
                    var product = Read(id);

                    if (product.Id > 0)
                    {
                        UploadBLL.DeleteUploadByRecordID(TableID, id.ToString());
                        dal.Delete(id);
                        ProductPhotoBLL.DeleteList(id, 0);

                        int[] classIds = Array.ConvertAll <string, int>(product.ClassId.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
                        ProductClassBLL.ChangeProductCount(classIds, ChangeAction.Minus);
                        CacheHelper.Remove("ProductClass");
                    }
                }
            }
            else
            {
                var product = Read(id);

                if (product.Id > 0)
                {
                    UploadBLL.DeleteUploadByRecordID(TableID, id.ToString());
                    dal.Delete(id);
                    ProductPhotoBLL.DeleteList(id, 0);

                    int[] classIds = Array.ConvertAll <string, int>(product.ClassId.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
                    ProductClassBLL.ChangeProductCount(classIds, ChangeAction.Minus);
                    CacheHelper.Remove("ProductClass");
                }
            }
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        /// <summary>
        /// 逻辑删除--isdelete 置为1
        /// </summary>
        /// <param name="id"></param>
        public static void DeleteLogically(int id)
        {
            bool canDel = true;

            if (OrderDetailBLL.ReadListByProductId(id).Count > 0)
            {
                foreach (OrderDetailInfo myOD in OrderDetailBLL.ReadListByProductId(id))
                {
                    OrderInfo tempOrder = OrderBLL.Read(myOD.OrderId, 0);
                    if (tempOrder.IsDelete == 0)
                    {
                        canDel = false;
                        break;
                    }
                }
                if (!canDel)
                {
                    ScriptHelper.Alert("该产品存在相关订单,不能删除。");
                }
                else
                {
                    var product = Read(id);

                    if (product.Id > 0)
                    {
                        dal.DeleteLogically(id);

                        CacheHelper.Remove("ProductClass");
                    }
                }
            }
            else
            {
                var product = Read(id);

                if (product.Id > 0)
                {
                    dal.DeleteLogically(id);
                }
            }
        }
Esempio n. 11
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);
        }
Esempio n. 12
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. 13
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);
                                }
                            }
                        }
                    }
                }
            }
        }