コード例 #1
0
ファイル: Orders.cs プロジェクト: hzl091/BrnShop-1
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="singlePromotionList">单品促销活动列表</param>
        /// <param name="fullShipAddressInfo">配送地址</param>
        /// <param name="payPluginInfo">支付方式</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, PluginInfo payPluginInfo, PluginInfo shipPluginInfo, int payCreditCount, List <CouponInfo> couponList, int fullCut, string buyerRemark, DateTime bestTime, string ip)
        {
            DateTime    nowTime    = DateTime.Now;
            IShipPlugin shipPlugin = (IShipPlugin)shipPluginInfo.Instance;
            IPayPlugin  payPlugin  = (IPayPlugin)payPluginInfo.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;

            decimal amount = orderInfo.ProductAmount - orderInfo.FullCut;

            orderInfo.ShipFee = shipPlugin.GetShipFee(orderInfo.Weight, amount, orderProductList, nowTime, fullShipAddressInfo.ProvinceId, fullShipAddressInfo.CityId, fullShipAddressInfo.RegionId, partUserInfo);
            if (payPlugin.PayMode == 0)
            {
                orderInfo.PayFee = shipPlugin.GetCODPayFee(amount, nowTime, fullShipAddressInfo.ProvinceId, fullShipAddressInfo.CityId, fullShipAddressInfo.RegionId, partUserInfo);
            }
            else
            {
                orderInfo.PayFee = payPlugin.GetPayFee(amount, nowTime, partUserInfo);
            }

            orderInfo.OrderAmount    = orderInfo.ProductAmount - orderInfo.FullCut + orderInfo.ShipFee + orderInfo.PayFee;
            orderInfo.PayCreditCount = payCreditCount;
            orderInfo.PayCreditMoney = Credits.PayCreditsToMoney(payCreditCount);
            orderInfo.CouponMoney    = Coupons.SumCouponMoney(couponList);
            orderInfo.SurplusMoney   = orderInfo.OrderAmount - orderInfo.PayCreditMoney - orderInfo.CouponMoney;

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

            orderInfo.ParentId       = 0;
            orderInfo.IsReview       = 0;
            orderInfo.AddTime        = nowTime;
            orderInfo.ShipSystemName = shipPluginInfo.SystemName;
            orderInfo.ShipFriendName = shipPluginInfo.FriendlyName;
            orderInfo.ShipTime       = new DateTime(1900, 1, 1);
            orderInfo.PaySystemName  = payPluginInfo.SystemName;
            orderInfo.PayFriendName  = payPluginInfo.FriendlyName;
            orderInfo.PayMode        = payPlugin.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     = 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);
        }
コード例 #2
0
ファイル: Orders.cs プロジェクト: xiaoshihr/CMall
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="partUserInfo">用户信息</param>
        /// <param name="storeInfo">店铺信息</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="singlePromotionList">单品促销活动列表</param>
        /// <param name="fullShipAddressInfo">配送地址</param>
        /// <param name="payPluginInfo">支付方式</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, StoreInfo storeInfo, List <OrderProductInfo> orderProductList, List <SinglePromotionInfo> singlePromotionList, FullShipAddressInfo fullShipAddressInfo, PluginInfo payPluginInfo, ref int payCreditCount, List <CouponInfo> couponList, int fullCut, string buyerRemark, DateTime bestTime, string ip)
        {
            DateTime   nowTime   = DateTime.Now;
            IPayPlugin payPlugin = (IPayPlugin)payPluginInfo.Instance;

            OrderInfo orderInfo = new OrderInfo();

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

            orderInfo.Weight        = Carts.SumOrderProductWeight(orderProductList);
            orderInfo.ProductAmount = Carts.SumOrderProductAmount(orderProductList);
            //折扣
            //折扣
            decimal disc = 1.00m;

            if (partUserInfo.UserLevel == 1)
            {
                disc = 0.95m;
                orderInfo.Discount      = orderInfo.ProductAmount - (orderInfo.ProductAmount * disc);
                orderInfo.ProductAmount = orderInfo.ProductAmount - orderInfo.Discount;
            }
            if (partUserInfo.UserLevel == 2)
            {
                disc = 0.9m;
                orderInfo.Discount      = orderInfo.ProductAmount - (orderInfo.ProductAmount * disc);
                orderInfo.ProductAmount = orderInfo.ProductAmount - orderInfo.Discount;
            }
            if (partUserInfo.UserLevel == 3)
            {
                disc = 0.85m;
                orderInfo.Discount      = orderInfo.ProductAmount - (orderInfo.ProductAmount * disc);
                orderInfo.ProductAmount = orderInfo.ProductAmount - orderInfo.Discount;
            }
            orderInfo.FullCut     = fullCut;
            orderInfo.ShipFee     = GetShipFee(fullShipAddressInfo.ProvinceId, fullShipAddressInfo.CityId, orderProductList);
            orderInfo.PayFee      = payPlugin.GetPayFee(orderInfo.ProductAmount - orderInfo.FullCut, nowTime, partUserInfo);
            orderInfo.OrderAmount = orderInfo.ProductAmount - orderInfo.FullCut + orderInfo.ShipFee + orderInfo.PayFee;
            //折扣
            //折扣
            //decimal disc = 1.00m;
            //if (partUserInfo.UserLevel == 1)
            //{
            //    disc = 0.95m;
            //    orderInfo.Discount = orderInfo.OrderAmount * disc;
            //    orderInfo.OrderAmount = orderInfo.OrderAmount - orderInfo.Discount;
            //}
            //if (partUserInfo.UserLevel == 2)
            //{
            //    disc = 0.9m;
            //    orderInfo.Discount = orderInfo.OrderAmount * disc;
            //    orderInfo.OrderAmount = orderInfo.OrderAmount - orderInfo.Discount;
            //}
            //if (partUserInfo.UserLevel == 3)
            //{
            //    disc = 0.85m;
            //    orderInfo.Discount = orderInfo.OrderAmount * disc;
            //    orderInfo.OrderAmount = orderInfo.OrderAmount - orderInfo.Discount;
            //}
            decimal payCreditMoney = Credits.PayCreditsToMoney(payCreditCount);

            if (orderInfo.OrderAmount >= payCreditMoney)
            {
                orderInfo.PayCreditCount = payCreditCount;
                orderInfo.PayCreditMoney = payCreditMoney;
                payCreditCount           = 0;
            }
            else
            {
                int orderPayCredits = Credits.MoneyToPayCredits(orderInfo.OrderAmount);
                orderInfo.PayCreditCount = orderPayCredits;
                orderInfo.PayCreditMoney = orderInfo.OrderAmount;
                payCreditCount           = payCreditCount - orderPayCredits;
            }

            orderInfo.CouponMoney  = Coupons.SumCouponMoney(couponList);
            orderInfo.SurplusMoney = orderInfo.OrderAmount - orderInfo.PayCreditMoney - orderInfo.CouponMoney;



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

            orderInfo.ParentId      = 0;
            orderInfo.IsReview      = 0;
            orderInfo.AddTime       = nowTime;
            orderInfo.StoreId       = storeInfo.StoreId;
            orderInfo.StoreName     = storeInfo.Name;
            orderInfo.PaySystemName = payPluginInfo.SystemName;
            orderInfo.PayFriendName = payPluginInfo.FriendlyName;
            orderInfo.PayMode       = payPlugin.PayMode;

            orderInfo.RegionId  = fullShipAddressInfo.RegionId;
            orderInfo.Consignee = fullShipAddressInfo.Consignee;
            orderInfo.Mobile    = fullShipAddressInfo.Mobile;
            orderInfo.Phone     = fullShipAddressInfo.Phone;
            orderInfo.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);
                //int oid = _iorderstrategy.CreateOrder(orderInfo, false, 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;
                BMALog.Instance.Write(ex.ToString());
            }

            return(null);
        }