Exemplo n.º 1
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="singlePromotionList">单品促销活动列表</param>
        /// <param name="fullShipAddressInfo">配送地址</param>
        /// <param name="payMode">支付方式(0代表货到付款,1代表在线支付)</param>
        /// <param name="shipPluginInfo">配送方式</param>
        /// <param name="payCreditCount">支付积分数</param>
        /// <param name="couponList">优惠劵列表</param>
        /// <param name="fullCut">满减</param>
        /// <param name="buyerRemark">买家备注</param>
        /// <param name="bestTime">最佳配送时间</param>
        /// <param name="ip">ip地址</param>
        /// <returns>订单信息</returns>
        public static OrderInfo CreateOrder(PartUserInfo partUserInfo, List <OrderProductInfo> orderProductList, List <SinglePromotionInfo> singlePromotionList, FullShipAddressInfo fullShipAddressInfo, int payMode, PluginInfo shipPluginInfo, int payCreditCount, List <CouponInfo> couponList, int fullCut, string buyerRemark, DateTime bestTime, string ip)
        {
            DateTime    nowTime    = DateTime.Now;
            IShipPlugin shipPlugin = (IShipPlugin)shipPluginInfo.Instance;

            OrderInfo orderInfo = new OrderInfo();

            orderInfo.OSN = GenerateOSN(partUserInfo.Uid, fullShipAddressInfo.RegionId, nowTime);
            orderInfo.Uid = partUserInfo.Uid;

            orderInfo.Weight        = Carts.SumOrderProductWeight(orderProductList);
            orderInfo.ProductAmount = Carts.SumOrderProductAmount(orderProductList);
            orderInfo.FullCut       = fullCut;

            orderInfo.ShipFee        = shipPlugin.GetShipFee(orderInfo.Weight, (orderInfo.ProductAmount - orderInfo.FullCut), orderProductList, nowTime, fullShipAddressInfo.ProvinceId, fullShipAddressInfo.CityId, fullShipAddressInfo.RegionId, partUserInfo);
            orderInfo.OrderAmount    = orderInfo.ProductAmount - orderInfo.FullCut + orderInfo.ShipFee;
            orderInfo.PayCreditCount = payCreditCount;
            orderInfo.PayCreditMoney = Credits.PayCreditsToMoney(payCreditCount);
            orderInfo.CouponMoney    = Coupons.SumCouponMoney(couponList);
            orderInfo.SurplusMoney   = orderInfo.OrderAmount - orderInfo.PayCreditMoney - orderInfo.CouponMoney;
            if (orderInfo.SurplusMoney < 0)
            {
                orderInfo.SurplusMoney = 0;
            }

            orderInfo.OrderState = (orderInfo.SurplusMoney <= 0 || payMode == 0) ? (int)OrderState.Confirming : (int)OrderState.WaitPaying;

            orderInfo.IsReview       = 0;
            orderInfo.AddTime        = nowTime;
            orderInfo.ShipSystemName = shipPluginInfo.SystemName;
            orderInfo.ShipFriendName = shipPluginInfo.FriendlyName;
            orderInfo.ShipTime       = new DateTime(1900, 1, 1);
            orderInfo.PaySystemName  = payMode == 0 ? "cod" : "";
            orderInfo.PayFriendName  = payMode == 0 ? "货到付款" : "";
            orderInfo.PayMode        = payMode;
            orderInfo.PayTime        = new DateTime(1900, 1, 1);

            orderInfo.RegionId  = fullShipAddressInfo.RegionId;
            orderInfo.Consignee = fullShipAddressInfo.Consignee;
            orderInfo.Mobile    = fullShipAddressInfo.Mobile;
            orderInfo.Phone     = fullShipAddressInfo.Phone;
            orderInfo.Email     = string.IsNullOrWhiteSpace(fullShipAddressInfo.Email)? partUserInfo.Email: fullShipAddressInfo.Email;
            orderInfo.ZipCode   = fullShipAddressInfo.ZipCode;
            orderInfo.Address   = fullShipAddressInfo.Address;
            orderInfo.BestTime  = bestTime;

            orderInfo.BuyerRemark = buyerRemark;
            orderInfo.IP          = ip;

            try
            {
                //添加订单
                int oid = _iorderstrategy.CreateOrder(orderInfo, Carts.IsPersistOrderProduct, orderProductList);
                if (oid > 0)
                {
                    orderInfo.Oid = oid;

                    //减少商品库存数量
                    Products.DecreaseProductStockNumber(orderProductList);
                    //更新限购库存
                    if (singlePromotionList.Count > 0)
                    {
                        Promotions.UpdateSinglePromotionStock(singlePromotionList);
                    }
                    //使用支付积分
                    Credits.PayOrder(ref partUserInfo, orderInfo, orderInfo.PayCreditCount, nowTime);
                    //使用优惠劵
                    foreach (CouponInfo couponInfo in couponList)
                    {
                        if (couponInfo.Uid > 0)
                        {
                            Coupons.UseCoupon(couponInfo.CouponId, oid, nowTime, ip);
                        }
                        else
                        {
                            Coupons.ActivateAndUseCoupon(couponInfo.CouponId, partUserInfo.Uid, oid, nowTime, ip);
                        }
                    }

                    return(orderInfo);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 退货
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderInfo">订单信息</param>
        /// <param name="operatorId">操作人id</param>
        /// <param name="returnTime">退货时间</param>
        public static void ReturnOrder(ref PartUserInfo partUserInfo, OrderInfo orderInfo, int operatorId, DateTime returnTime)
        {
            UpdateOrderState(orderInfo.Oid, OrderState.Returned); //将订单状态设为退货状态

            if (orderInfo.OrderState == (int)OrderState.Sended)   //用户收货时退货
            {
                if (orderInfo.CouponMoney > 0)                    //退回用户使用的优惠劵
                {
                    Coupons.ReturnUserOrderUseCoupons(orderInfo.Oid);
                }

                if (orderInfo.PayCreditCount > 0)//退回用户使用的积分
                {
                    Credits.ReturnUserOrderUseCredits(ref partUserInfo, orderInfo, operatorId, returnTime);
                }

                if (orderInfo.PaySN.Length > 0)//退回用户支付的金钱(此操作只是将退款记录保存到表'orderrefunds'中,实际退款还需要再次操作)
                {
                    OrderRefunds.ApplyRefund(new OrderRefundInfo
                    {
                        Oid           = orderInfo.Oid,
                        OSN           = orderInfo.OSN,
                        Uid           = orderInfo.Uid,
                        State         = 0,
                        ApplyTime     = returnTime,
                        PayMoney      = orderInfo.SurplusMoney,
                        RefundMoney   = orderInfo.SurplusMoney,
                        PaySN         = orderInfo.PaySN,
                        PaySystemName = orderInfo.PaySystemName,
                        PayFriendName = orderInfo.PayFriendName
                    });
                }
            }
            else if (orderInfo.OrderState == (int)OrderState.Completed) //订单完成后退货
            {
                if (orderInfo.CouponMoney > 0)                          //退回用户使用的优惠劵
                {
                    Coupons.ReturnUserOrderUseCoupons(orderInfo.Oid);
                }

                if (orderInfo.PayCreditCount > 0)//退回用户使用的积分
                {
                    Credits.ReturnUserOrderUseCredits(ref partUserInfo, orderInfo, operatorId, returnTime);
                }

                //应退金钱
                decimal returnMoney = orderInfo.SurplusMoney;

                //订单发放的积分
                DataTable sendCredits      = Credits.GetUserOrderSendCredits(orderInfo.Oid);
                int       payCreditAmount  = TypeHelper.ObjectToInt(sendCredits.Rows[0]["paycreditamount"]);
                int       rankCreditAmount = TypeHelper.ObjectToInt(sendCredits.Rows[0]["rankcreditamount"]);
                //判断用户当前积分是否足够退回,如果不足够就将差额核算成金钱并在应退金钱中减去
                if (partUserInfo.PayCredits < payCreditAmount)
                {
                    returnMoney     = returnMoney - Credits.PayCreditsToMoney(payCreditAmount - partUserInfo.PayCredits);
                    payCreditAmount = partUserInfo.PayCredits;
                }
                //收回订单发放的积分
                Credits.ReturnUserOrderSendCredits(ref partUserInfo, orderInfo, payCreditAmount, rankCreditAmount, operatorId, returnTime);

                StringBuilder couponIdList = new StringBuilder();
                //订单发放的优惠劵列表
                List <CouponInfo> couponList = Coupons.GetUserOrderSendCouponList(orderInfo.Oid);
                //判断优惠劵是否已经被使用,如果已经使用就在应退金钱中减去优惠劵金额
                foreach (CouponInfo couponInfo in couponList)
                {
                    if (couponInfo.Oid > 0)
                    {
                        returnMoney = returnMoney - couponInfo.Money;
                    }
                    else
                    {
                        couponIdList.AppendFormat("{0},", couponInfo.CouponId);
                    }
                }
                //收回订单发放的优惠劵
                if (couponIdList.Length > 0)
                {
                    Coupons.DeleteCouponById(couponIdList.Remove(couponIdList.Length - 1, 1).ToString());
                }

                if (returnMoney > 0)//退回用户支付的金钱(此操作只是将退款记录保存到表'orderrefunds'中,实际退款还需要再次操作)
                {
                    OrderRefunds.ApplyRefund(new OrderRefundInfo
                    {
                        Oid           = orderInfo.Oid,
                        OSN           = orderInfo.OSN,
                        Uid           = orderInfo.Uid,
                        State         = 0,
                        ApplyTime     = returnTime,
                        PayMoney      = orderInfo.SurplusMoney,
                        RefundMoney   = returnMoney,
                        PaySN         = orderInfo.PaySN,
                        PaySystemName = orderInfo.PaySystemName,
                        PayFriendName = orderInfo.PayFriendName
                    });
                }
            }

            Products.IncreaseProductStockNumber(GetOrderProductList(orderInfo.Oid));//增加商品库存数量
        }