Exemplo n.º 1
0
        /// <summary>
        /// 获取最多的退款信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetMaxRefundInfo(HttpContext context)
        {
            string        orderDetailId = context.Request["order_detail_id"];
            MaxRefundInfo model         = GetMaxRefundInfoModel(orderDetailId);

            return(ZentCloud.Common.JSONHelper.ObjectToJson(new
            {
                errcode = 0,
                model.max_refund_amount,
                model.max_refund_score,
                model.max_refund_account_amount,
                model.is_contain_transport_fee
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 处理最后一件运费退款情况
        /// </summary>
        /// <param name="model"></param>
        /// <param name="orderInfo"></param>
        /// <param name="refundList"></param>
        /// <param name="overTransportFee"></param>
        /// <param name="canRefundAmount"></param>
        /// <param name="canRefundAccountAmount"></param>
        private void DealTransportFeeRefund(
            ref MaxRefundInfo model,
            WXMallOrderInfo orderInfo,
            List <WXMallRefund> refundList

            )
        {
            var overTransportFee       = orderInfo.Transport_Fee;                                            //当前已计算抵掉的运费
            var canRefundAmount        = orderInfo.TotalAmount - refundList.Sum(p => p.RefundAmount);        //当前可退最大金额
            var canRefundAccountAmount = orderInfo.UseAmount - (refundList.Sum(p => p.RefundAccountAmount)); //当前可退最大余额

            //把金额、余额、积分都退掉,并且保证可退金额跟余额不大于邮费,剩余的积分则可以全部都退掉
            if (overTransportFee > 0)
            {
                if (canRefundAmount >= overTransportFee)
                {
                    model.max_refund_amount += overTransportFee;
                    overTransportFee         = 0;
                }
                else
                {
                    model.max_refund_amount += canRefundAmount;
                    overTransportFee        -= canRefundAmount;
                }
            }
            if (overTransportFee > 0)
            {
                if (canRefundAccountAmount >= overTransportFee)
                {
                    model.max_refund_account_amount += overTransportFee;
                    overTransportFee = 0;
                }
                else
                {
                    model.max_refund_account_amount += canRefundAccountAmount;
                    overTransportFee -= canRefundAccountAmount;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取最大退款金额
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetMaxRefundAmount(HttpContext context)
        {
            string orderDetailId = context.Request["order_detail_id"];
            //WXMallOrderDetailsInfo orderDetail = bllMall.GetOrderDetail(int.Parse(orderDetailId));
            MaxRefundInfo model = GetMaxRefundInfoModel(orderDetailId);

            return(ZentCloud.Common.JSONHelper.ObjectToJson(new
            {
                errcode = 0,
                model.max_refund_amount,
                model.max_refund_score,
                model.max_refund_account_amount,
                model.is_contain_transport_fee
            }));
            //return ZentCloud.Common.JSONHelper.ObjectToJson(new
            //{
            //    errcode = 0,
            //    errmsg = "ok",
            //    max_refund_amount = orderDetail.MaxRefundAmount

            //});
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取最多的退款信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private MaxRefundInfo GetMaxRefundInfoModel(string orderDetailId)
        {
            MaxRefundInfo                 model           = new MaxRefundInfo();
            WXMallOrderDetailsInfo        orderDetail     = bllMall.GetOrderDetail(int.Parse(orderDetailId));
            WXMallOrderInfo               orderInfo       = bllMall.GetOrderInfo(orderDetail.OrderID);
            List <WXMallOrderDetailsInfo> orderDetailList = bllMall.GetOrderDetailsList(orderInfo.OrderID);
            List <WXMallRefund>           refundList      = bllMall.GetList <WXMallRefund>(string.Format(" OrderId='{0}'", orderInfo.OrderID));

            var     productTotalProce = ((decimal)orderDetailList.Sum(p => p.OrderPrice * p.TotalCount));
            decimal rate = 0;

            if (productTotalProce > 0)
            {
                rate = ((decimal)orderDetail.OrderPrice * orderDetail.TotalCount) / ((decimal)orderDetailList.Sum(p => p.OrderPrice * p.TotalCount));//此商品所占的比例
            }
            model.max_refund_amount = orderDetail.MaxRefundAmount;

            //商品单独需要的积分不在均摊计算范围内
            int singelProductTotalScore = orderDetail.OrderScore * orderDetail.TotalCount,
                allProductTotalScore    = orderDetailList.Sum(p => p.OrderScore * p.TotalCount);

            //foreach (var item in orderDetailList)
            //{
            //    allProductTotalScore += item.OrderScore * item.TotalCount;
            //}

            orderInfo.UseScore -= allProductTotalScore;

            if (orderInfo.UseScore > 0)
            {
                model.max_refund_score = (int)(orderInfo.UseScore * rate);//可退积分
            }
            else
            {
                orderInfo.UseScore = 0;
            }

            if (orderInfo.UseAmount > 0)
            {
                model.max_refund_account_amount = Math.Round(orderInfo.UseAmount * rate, 2, MidpointRounding.AwayFromZero); //可退余额
            }
            if (orderDetailList.Count == 1 && (string.IsNullOrEmpty(orderInfo.ExpressNumber)))                              //只买了一种商品且未发货
            {
                //model.max_refund_amount += orderInfo.Transport_Fee;
                DealTransportFeeRefund(ref model, orderInfo, refundList);

                model.max_refund_score = orderInfo.UseScore;

                //if (orderInfo.UseScore > 0)
                //{
                //    if (refundList != null && refundList.Count > 0)
                //    {
                //        model.max_refund_score = orderInfo.UseScore - (refundList.Sum(p => p.RefundScore));
                //        if (model.max_refund_score < 0)
                //        {
                //            model.max_refund_score = 0;
                //        }
                //    }
                //}

                if ((bllMall.GetCount <WXMallRefund>(string.Format(" OrderId='{0}'", orderInfo.OrderID)) == orderDetailList.Count - 1) && (string.IsNullOrEmpty(orderInfo.ExpressNumber)))//只有一种商品且未发货
                {
                    model.is_contain_transport_fee = 1;
                }
            }
            else
            {
                #region 处理最后一种商品的情况
                if ((refundList != null) && (refundList.Count == (orderDetailList.Count - 1))) //最后一种商品
                {
                    if (string.IsNullOrEmpty(orderInfo.ExpressNumber))                         //最后一件商品未发货
                    {
                        //model.max_refund_amount += orderInfo.Transport_Fee;
                        DealTransportFeeRefund(ref model, orderInfo, refundList);

                        model.is_contain_transport_fee = 1;
                    }

                    #region 最后一种商品的退还积分
                    if (orderInfo.UseScore > 0)
                    {
                        if (refundList != null && refundList.Count > 0)
                        {
                            model.max_refund_score = orderInfo.UseScore - (refundList.Sum(p => p.RefundScore));
                            if (model.max_refund_score < 0)
                            {
                                model.max_refund_score = 0;
                            }
                        }
                    }
                    #endregion

                    #region 最后一种商品的余额退款
                    if (orderInfo.UseAmount > 0)
                    {
                        if (refundList != null && refundList.Count > 0)
                        {
                            model.max_refund_account_amount = orderInfo.UseAmount - (refundList.Sum(p => p.RefundAccountAmount));
                            if (model.max_refund_account_amount < 0)
                            {
                                model.max_refund_account_amount = 0;
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }

            if (singelProductTotalScore > 0)
            {
                model.max_refund_score += singelProductTotalScore;
            }

            //如果最大退款金额比实付金额还大,则说明有问题,最大退款金额重置为 0,在处理老的订单运费逻辑,重置为0是正确的,其他情况如有不对根据具体情况再分析

            if (model.max_refund_amount > orderInfo.TotalAmount + orderInfo.Transport_Fee)
            {
                model.max_refund_amount = 0;
            }

            return(model);
        }