Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置默认插件
        /// </summary>
        /// <param name="systemName">插件系统名称</param>
        public static void Default(string systemName)
        {
            lock (_locker)
            {
                if (string.IsNullOrEmpty(systemName))
                {
                    return;
                }

                PluginInfo             pluginInfo = null;
                Predicate <PluginInfo> condition  = x => x.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase);
                pluginInfo = _oauthpluginlist.Find(condition);
                if (pluginInfo == null)
                {
                    pluginInfo = _paypluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _shippluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _uninstalledpluginlist.Find(condition);
                }

                //当插件为空时直接返回
                if (pluginInfo == null)
                {
                    return;
                }

                List <PluginInfo> updatePluginList = new List <PluginInfo>();
                if (pluginInfo.Type == 0)
                {
                    foreach (PluginInfo info in _oauthpluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }
                else if (pluginInfo.Type == 1)
                {
                    foreach (PluginInfo info in _paypluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }
                else
                {
                    foreach (PluginInfo info in _shippluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }

                foreach (PluginInfo info in _uninstalledpluginlist)
                {
                    if (info.Type == pluginInfo.Type && info.IsDefault == 1)
                    {
                        info.IsDefault = 0;
                        updatePluginList.Add(info);
                    }
                }

                pluginInfo.IsDefault = 1;
                updatePluginList.Add(pluginInfo);

                //将插件信息持久化到对应文件中
                foreach (PluginInfo info in updatePluginList)
                {
                    IOHelper.SerializeToXml(info, IOHelper.GetMapPath("/plugins/" + info.Folder + "/plugin.config"));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载插件程序集到应用程序域中
        /// </summary>
        public static void Load()
        {
            try
            {
                //插件目录
                DirectoryInfo pluginFolder = new DirectoryInfo(IOHelper.GetMapPath(_pluginfolderpath));
                if (!pluginFolder.Exists)
                {
                    pluginFolder.Create();
                }
                //插件bin目录
                DirectoryInfo shadowFolder = new DirectoryInfo(IOHelper.GetMapPath(_shadowfolderpath));
                if (!shadowFolder.Exists)
                {
                    shadowFolder.Create();
                }
                else
                {
                    //清空影子复制目录中的dll文件
                    foreach (FileInfo fileInfo in shadowFolder.GetFiles())
                    {
                        fileInfo.Delete();
                    }
                }

                //获得安装的插件系统名称列表
                List <string> installedPluginSystemNameList = GetInstalledPluginSystemNameList();
                //获得全部插件
                List <KeyValuePair <FileInfo, PluginInfo> > allPluginFileAndInfo = GetAllPluginFileAndInfo(pluginFolder);
                foreach (KeyValuePair <FileInfo, PluginInfo> fileAndInfo in allPluginFileAndInfo)
                {
                    FileInfo   pluginFile = fileAndInfo.Key;
                    PluginInfo pluginInfo = fileAndInfo.Value;

                    if (String.IsNullOrWhiteSpace(pluginInfo.SystemName))
                    {
                        throw new BSPException(string.Format("插件'{0}'没有\"systemName\", 请输入一个唯一的\"systemName\"", pluginFile.FullName));
                    }
                    if (pluginInfo.Type < 0 || pluginInfo.Type > 2)
                    {
                        throw new BSPException(string.Format("插件'{0}'不属于任何一种类型, 请输入正确的的\"type\"", pluginFile.FullName));
                    }

                    //加载插件dll文件
                    FileInfo[] dllFiles = pluginFile.Directory.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
                    foreach (FileInfo dllFile in dllFiles)
                    {
                        //部署dll文件
                        DeployDllFile(dllFile, shadowFolder);
                    }

                    if (IsInstalledlPlugin(pluginInfo.SystemName, installedPluginSystemNameList))//安装的插件
                    {
                        //根据插件类型将插件添加到相应列表
                        switch (pluginInfo.Type)
                        {
                        case 0:
                            _oauthpluginlist.Add(pluginInfo);
                            break;

                        case 1:
                            _paypluginlist.Add(pluginInfo);
                            break;

                        case 2:
                            _shippluginlist.Add(pluginInfo);
                            break;
                        }
                    }
                    else//未安装的插件
                    {
                        _uninstalledpluginlist.Add(pluginInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new BSPException("加载BrnShop插件时出错", ex);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 编辑插件信息
        /// </summary>
        /// <param name="systemName">插件系统名称</param>
        /// <param name="friendlyName">插件友好名称</param>
        /// <param name="description">插件描述</param>
        /// <param name="displayOrder">插件排序</param>
        public static void Edit(string systemName, string friendlyName, string description, int displayOrder)
        {
            lock (_locker)
            {
                bool                   isInstalled = true;//是否安装
                PluginInfo             pluginInfo  = null;
                Predicate <PluginInfo> condition   = x => x.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase);

                pluginInfo = _oauthpluginlist.Find(condition);
                if (pluginInfo == null)
                {
                    pluginInfo = _paypluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _shippluginlist.Find(condition);
                }

                //当插件为空时直接返回
                if (pluginInfo == null)
                {
                    pluginInfo = _uninstalledpluginlist.Find(condition);;
                    //当插件为空时直接返回
                    if (pluginInfo == null)
                    {
                        return;
                    }
                    else
                    {
                        isInstalled = false;
                    }
                }

                pluginInfo.FriendlyName = friendlyName;
                pluginInfo.Description  = description;
                pluginInfo.DisplayOrder = displayOrder;

                //将插件信息持久化到对应文件中
                IOHelper.SerializeToXml(pluginInfo, IOHelper.GetMapPath("/plugins/" + pluginInfo.Folder + "/plugin.config"));

                //插件列表重新排序
                if (isInstalled)
                {
                    switch (pluginInfo.Type)
                    {
                    case 0:
                        _oauthpluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;

                    case 1:
                        _paypluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;

                    case 2:
                        _shippluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;
                    }
                }
                else
                {
                    _uninstalledpluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                }
            }
        }