Exemplo n.º 1
0
        public int Update(tbOrdersConfig OrdersConfig)
        {
            int Id = 0;

            IDbDataParameter[] parm = GetUpdateParam();
            parm[0].Value = OrdersConfig.ConfigId;
            parm[1].Value = OrdersConfig.ShopId;
            parm[2].Value = OrdersConfig.JudgePay;
            parm[3].Value = OrdersConfig.MergerOrder;
            parm[4].Value = OrdersConfig.RefundPrint;
            parm[5].Value = OrdersConfig.PayTime;
            parm[6].Value = OrdersConfig.RemarkFlag;
            parm[7].Value = OrdersConfig.Remark;
            parm[8].Value = OrdersConfig.CashDelivery;
            parm[9].Value = OrdersConfig.LogisticsDis;

            try {
                using (IDataReader MyReader = DBHelper.ExecuteReader(CommandType.StoredProcedure, SQL_UPDATE, parm)) {
                    if (MyReader.Read())
                    {
                        Id = MyReader.GetInt32(0);
                    }
                }
            } catch { }

            return(Id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 修改订单备注的旗帜
        /// </summary>
        /// <param name="Order">订单信息</param>
        /// <param name="SessionKey">用户授权</param>
        /// <returns></returns>
        private void UpdateDeital(tbOrdersInfo Order, tbOrdersConfig Config, string SessionKey)
        {
            string[] OutNumber = Order.OrdersOutNumber.Split(',');
            if (Order.ServiceNotes != null)
            {
                string[] Detail = Regex.Split(Order.ServiceNotes, "%Separation%");
                Order.ServiceNotes = Order.ServiceNotes.Replace("%Separation%", " ");
            }

            if (Config.ConfigId <= 0)
            {
                return;
            }
            if (String.IsNullOrEmpty(Config.Remark) && Config.RemarkFlag == 0)
            {
                return;
            }

            try
            {
                MYDZ.Business.TB_Logic.Order.GetTradeInfo gti = new MYDZ.Business.TB_Logic.Order.GetTradeInfo();
                for (int i = 0; i < OutNumber.Length; i++)
                {
                    gti.UpdateTradeMemo(SessionKey, OutNumber[i].ToString(), Config.Remark, Config.RemarkFlag, false);
                }
            }
            catch { }
        }
Exemplo n.º 3
0
        public tbOrdersConfig SelectByUserId(int UserId)
        {
            tbOrdersConfig Config = null;

            IDbDataParameter[] parm = GetSelectByUIdParam();
            parm[0].Value = UserId;

            using (IDataReader MyReader = DBHelper.ExecuteReader(CommandType.StoredProcedure, SQL_SELECT_UID, parm)) {
                if (MyReader.Read())
                {
                    Config = new tbOrdersConfig()
                    {
                        ConfigId     = MyReader.GetInt32(0),
                        ShopId       = MyReader.GetInt32(1),
                        JudgePay     = MyReader.GetBoolean(2),
                        MergerOrder  = MyReader.GetBoolean(3),
                        RefundPrint  = MyReader.GetBoolean(4),
                        PayTime      = MyReader.GetInt32(5),
                        RemarkFlag   = MyReader.GetInt32(6),
                        Remark       = MyReader.GetString(7),
                        CashDelivery = MyReader.GetString(8),
                        LogisticsDis = MyReader.GetBoolean(9)
                    };
                }
            }

            return(Config == null ? new tbOrdersConfig() : Config);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据用户编号查询订单获取配置信息
        /// </summary>
        /// <param name="UserId">用户</param>
        /// <returns></returns>
        public static tbOrdersConfig SelectByUserId(int UserId)
        {
            tbOrdersConfig Config = OrdersConfigDal.SelectByUserId(UserId);

            if (Config.ConfigId > 0)
            {
                Config.DetailList = ConfigDetail.Select(Config.ConfigId) as List <tbConfigDetail>;
            }

            return(Config);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 解析订单是否需要打印发货单
 /// </summary>
 /// <param name="Config">订单获取配置信息</param>
 /// <param name="ShopLogistics">店铺物流列表</param>
 /// <param name="Order">订单信息</param>
 public static void AnalyticalInvoice(tbOrdersConfig Config, IList <StoreLogistics> ShopLogistics, tbOrdersInfo Order)
 {
     //判断指定配送方式下的订单是否需要打印发货单
     if (ShopLogistics != null && ShopLogistics.Count > 0)
     {
         foreach (StoreLogistics SL in ShopLogistics)
         {
             if (SL.Logistics.LogisticsId == Order.Logistics.LogisticsId)
             {
                 int count = 0;
                 foreach (tbOrdersDetail od in Order.Details)
                 {
                     if (!od.IsCanceled)
                     {
                         if (!Config.RefundPrint)
                         {
                             if (!od.IsProductReFund)
                             {
                                 count++;
                             }
                         }
                         else
                         {
                             count++;
                         }
                     }
                 }
                 if (SL.Number >= count)
                 {
                     Order.IsInventory = false;
                 }
                 else
                 {
                     Order.IsInventory = true;
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        //开始执行操作
        private bool StartRun(object obj)
        {
            int StartIndex = 0;

            MYDZ.Business.Business_Logic.Order.InitTradeInfo iti = new Business_Logic.Order.InitTradeInfo();
            bool                   Result             = false;
            string                 ErrorMsg           = null;
            bool                   HasNext            = false;
            long                   TotalResults       = 0;
            Hashtable              ht                 = null;
            TradesSoldGet          TradesSold         = null;
            tbClientUser           clientuser         = null;
            tbOrdersConfig         ordersConfig       = null;
            List <Trade>           listtrade          = null;
            IList <StoreLogistics> StoreLogisticsList = null;
            tbOrdersInfo           OrdersInfo         = null;

            if (obj != null)
            {
                ht           = new Hashtable();
                TradesSold   = new TradesSoldGet();
                clientuser   = new tbClientUser();
                ordersConfig = new tbOrdersConfig();

                ht                 = obj as Hashtable;
                clientuser         = ht["clientuser"] as tbClientUser;
                TradesSold         = ht["TradesSoldGet"] as TradesSoldGet;
                StoreLogisticsList = ht["LogisticsList"] as List <StoreLogistics>;
                ordersConfig       = ht["Config"] as tbOrdersConfig;

                //获取从上一次同步到现在产生的订单,否则获取店铺一个星期的未完成订单
                DateTime LastModifyTime = ht["LastModifyTime"] == null ? new DateTime() : Convert.ToDateTime(ht["LastModifyTime"].ToString());
                if (LastModifyTime != new DateTime())
                {
                    TradesSold.StartCreated = Convert.ToDateTime(LastModifyTime.ToString("yyyy-MM-dd HH:mm:ss"));
                }
                else
                {
                    TradesSold.StartCreated = Convert.ToDateTime(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (TradesSold.EndCreated == null)
                {
                    TradesSold.EndCreated = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                while (true)
                {
                    string Errormsg = null;
                    List <tbOrdersInfo> listOrdersInfo = new List <tbOrdersInfo>();
                    listtrade = new List <Trade>();

                    //获取未完成订单
                    TradesSold.Status = "WAIT_SELLER_SEND_GOODS";

                    //获取淘宝默认数量的订单
                    listtrade = iti.GetTradesSold(clientuser.UserShops[0].SessionKey, TradesSold, out ErrorMsg, out HasNext, out TotalResults);

                    if (listtrade == null || TotalResults == 0)
                    {
                        break;
                    }
                    try
                    {
                        //这里写得到临时数据
                        //遍历订单
                        foreach (Trade trade in listtrade)
                        {
                            try
                            {
                                OrdersInfo = new tbOrdersInfo();

                                //获取订单的详细信息
                                OrdersInfo = iti.GetTradeFullinfo(clientuser.UserShops[0].SessionKey, trade.Tid.ToString(), clientuser.UserShops[0].Shop.ShopId, out Errormsg);

                                //这里做物流解析
                                string[] LogisticsList = Comm.Distribution(StoreLogisticsList, OrdersInfo.LogisticsStr);
                                if (LogisticsList != null)
                                {
                                    OrdersInfo.IsFree = bool.Parse(LogisticsList[0]);
                                    OrdersInfo.Logistics.LogisticsId = int.Parse(LogisticsList[1]);;
                                    if (OrdersInfo.OrdersFreight == 0)
                                    {
                                        OrdersInfo.IsFree = true;
                                    }
                                }

                                //拆单、并单
                                Comm.MergeOrder(ordersConfig, listOrdersInfo, OrdersInfo);

                                // 检查订单配置关系
                                Comm.StatusAssign(ordersConfig, OrdersInfo);

                                //物流分配
                                bool IsOk = Comm.DeliveryAssign(ordersConfig, StoreLogisticsList, OrdersInfo);
                                if (!IsOk && ordersConfig.LogisticsDis && StoreLogisticsList != null && StoreLogisticsList.Count > 0)
                                {
                                    string target = String.IsNullOrEmpty(OrdersInfo.Consignee.District) ? OrdersInfo.Consignee.City : OrdersInfo.Consignee.District;
                                    if (!String.IsNullOrEmpty(target))
                                    {
                                        List <string> CompayList = GetLogisticsIdList((OrdersInfo.CashOndelivery ? "cod" : "online"), "", target.Trim());

                                        //根据物流配送范围和物流优先级别分配订单物流信息
                                        Comm.RangeDelivery(StoreLogisticsList, OrdersInfo, CompayList);
                                    }
                                }

                                //解析订单是否需要打印发货单
                                Comm.AnalyticalInvoice(ordersConfig, StoreLogisticsList, OrdersInfo);

                                //修改订单备注旗帜
                                UpdateDeital(OrdersInfo, ordersConfig, clientuser.UserShops[0].SessionKey);
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                        }

                        StartIndex++;

                        //这里写插入数据库临时表
                        if (CheckAndInsertOrders(listOrdersInfo))
                        {
                            if (StartIndex == 1)
                            {
                                clientuser.StartIndex = StartIndex;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                    if (HasNext)
                    {
                        TradesSold.PageNo++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(Result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取淘宝未完成订单并插入数据库
        /// </summary>
        public void GetResquestBacklogOrder(TradesSoldGet TradesSold, tbClientUser clientuser, IList <StoreLogistics> StoreLogisticsList, tbOrdersConfig Config, DateTime?LastModifyTime)
        {
            Hashtable ht = new Hashtable();

            ht.Add("clientuser", clientuser);
            ht.Add("TradesSoldGet", TradesSold);
            ht.Add("LogisticsList", StoreLogisticsList);
            ht.Add("Config", Config);
            ht.Add("LastModifyTime", LastModifyTime);
            StartRun(ht);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 修改订单获取配置信息
 /// </summary>
 /// <param name="OrdersConfig">订单获取配置表</param>
 /// <returns></returns>
 public static int Update(tbOrdersConfig OrdersConfig)
 {
     return(OrdersConfigDal.Update(OrdersConfig));
 }
Exemplo n.º 9
0
        /// <summary>
        /// 合并同用户名、同地址订单(货到付款订单不合并)
        /// </summary>
        /// <param name="Config">配置信息</param>
        /// <param name="Orders">订单列表</param>
        /// <param name="Order">订单信息</param>
        public static void MergeOrder(tbOrdersConfig Config, List <tbOrdersInfo> Orders, tbOrdersInfo Order)
        {
            //货到付款的订单不合并
            if (Order.CashOndelivery)
            {
                Orders.Add(Order); return;
            }

            if (Orders != null && Orders.Count > 0)
            {
                bool Merger = false;
                if (Config.ConfigId > 0)
                {
                    Merger = Config.MergerOrder;
                }

                if (Merger)
                {
                    bool IsOk = false;
                    foreach (tbOrdersInfo TempOrder in Orders)
                    {
                        if (Config.ConfigId > 0)
                        {
                            if (Config.PayTime > 0)
                            {
                                //验证付款时间
                                TimeSpan TSpan = DateTime.Now.Subtract(Order.PayDate);
                                int      Span  = TSpan.Days * 1440 + TSpan.Hours * 60 + TSpan.Minutes;
                                if (Span < Config.PayTime)
                                {
                                    Orders.Clear();
                                    break;
                                }
                            }
                        }

                        if (TempOrder.CashOndelivery)
                        {
                            continue;
                        }

                        if (TempOrder.Consignee.Name.Trim() == Order.Consignee.Name.Trim() && TempOrder.Consignee.Provice.Trim() == Order.Consignee.Provice.Trim() && TempOrder.Consignee.City.Trim() == Order.Consignee.City.Trim() && TempOrder.Consignee.District.Trim() == Order.Consignee.District.Trim() && TempOrder.Consignee.ConsigneeAddress.Trim() == Order.Consignee.ConsigneeAddress.Trim())
                        {
                            TempOrder.OrdersFreight      += Order.OrdersFreight;                                                               //合并运费
                            TempOrder.OrdersProductTotal += Order.OrdersProductTotal;                                                          //合并商品总金额
                            TempOrder.OrdersAccounts     += Order.OrdersAccounts;                                                              //合并订单应收金额
                            TempOrder.OrdersPaid         += Order.OrdersPaid;                                                                  //合并订单实收金额
                            TempOrder.OrdersDiscount     += TempOrder.OrdersAccounts - TempOrder.OrdersProductTotal - TempOrder.OrdersFreight; //计算订单折扣
                            TempOrder.OrdersOutNumber    += "," + Order.OrdersOutNumber;                                                       //合并订单外部编码
                            TempOrder.ServiceNotes       += "%Separation%" + Order.ServiceNotes;                                               //合并客服备注
                            TempOrder.IsOrdersReFund      = TempOrder.IsOrdersReFund || Order.IsOrdersReFund ? true : false;

                            TempOrder.Details.AddRange(Order.Details);
                            IsOk = true;
                            break;
                        }
                    }

                    if (!IsOk)
                    {
                        Orders.Add(Order);
                    }
                }
                else
                {
                    Orders.Add(Order);
                }
            }
            else
            {
                Orders.Add(Order);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 物流分配
        /// </summary>
        /// <param name="Order">订单信息</param>
        public static bool DeliveryAssign(tbOrdersConfig Config, IList <StoreLogistics> ShopLogistics, tbOrdersInfo Order)
        {
            bool Isok = false;

            if (Config.ConfigId > 0)
            {
                if (Order.CashOndelivery && !String.IsNullOrEmpty(Config.CashDelivery))
                {
                    int LogisticsId = 0;
                    int.TryParse(Config.CashDelivery, out LogisticsId);
                    if (LogisticsId > 0)
                    {
                        Order.Logistics.LogisticsId = LogisticsId; Isok = true;
                    }
                }
            }

            if (Config.DetailList != null && !Isok && Config.DetailList.Count > 0)
            {
                int[] IdList = new int[] { 8, 1, 2 };

                foreach (int id in IdList)
                {
                    try
                    {
                        var items = Config.DetailList.Where((e) => { return(e.EnumId == id); });
                        if (items != null && items.Count() > 0)
                        {
                            foreach (var item in items)
                            {
                                switch (id)
                                {
                                case 8:
                                    if (Order.Consignee.Provice.IndexOf(item.Key.Split(',')[0]) != -1)
                                    {
                                        Order.Logistics.LogisticsId = int.Parse(item.Value.Split(',')[0]);
                                        Isok = true;
                                    }
                                    break;

                                case 1:
                                    if (Order.ServiceNotes.IndexOf(item.Key.Split(',')[0]) != -1)
                                    {
                                        Order.Logistics.LogisticsId = int.Parse(item.Value.Split(',')[0]);
                                        Isok = true;
                                    }
                                    break;

                                case 2:
                                    if (Order.BuyerMsg.IndexOf(item.Key.Split(',')[0]) != -1)
                                    {
                                        Order.Logistics.LogisticsId = int.Parse(item.Value.Split(',')[0]);
                                        Isok = true;
                                    }
                                    break;
                                }

                                if (Isok)
                                {
                                    break;
                                }
                            }
                        }

                        if (Isok)
                        {
                            break;
                        }
                    }
                    catch { }
                }
            }

            return(Isok);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 状态分配
        /// </summary>
        /// <param name="order">订单信息</param>
        public static void StatusAssign(tbOrdersConfig Config, tbOrdersInfo Order)
        {
            if (Config.DetailList == null)
            {
                return;
            }
            if (Config.DetailList.Count <= 0)
            {
                return;
            }
            int[] IdList = new int[] { 3, 4, 5, 6, 7 };

            foreach (int id in IdList)
            {
                try
                {
                    bool Isok  = false;
                    var  items = Config.DetailList.Where((e) => { return(e.EnumId == id); });
                    if (items != null && items.Count() > 0)
                    {
                        foreach (var item in items)
                        {
                            switch (id)
                            {
                            case 3:
                                if (Order.ServiceFlag == "op_memo_" + (int.Parse(item.Key.Split(',')[0]) - 1) + ".png")
                                {
                                    Order.Status.OrdersStatusId = int.Parse(item.Value.Split(',')[0]);
                                    Isok = true;
                                }
                                break;

                            case 4:
                                if (Order.ServiceNotes.IndexOf(item.Key.Split(',')[0]) != -1)
                                {
                                    Order.Status.OrdersStatusId = int.Parse(item.Value.Split(',')[0]);
                                    Isok = true;
                                }
                                break;

                            case 5:
                                if (Order.BuyerMsg.IndexOf(item.Key.Split(',')[0]) != -1)
                                {
                                    Order.Status.OrdersStatusId = int.Parse(item.Value.Split(',')[0]);
                                    Isok = true;
                                }
                                break;

                            case 6:
                                foreach (var subitem in Order.Details)
                                {
                                    if (subitem.ProductName.IndexOf(item.Key.Split(',')[0]) != -1)
                                    {
                                        Order.Status.OrdersStatusId = int.Parse(item.Value.Split(',')[0]);
                                        Isok = true;
                                        break;
                                    }
                                }
                                break;

                            case 7:
                                foreach (var subitem in Order.Details)
                                {
                                    if (subitem.ProductEncoding.IndexOf(item.Key.Split(',')[0]) != -1)
                                    {
                                        Order.Status.OrdersStatusId = int.Parse(item.Value.Split(',')[0]);
                                        Isok = true;
                                        break;
                                    }
                                }
                                break;
                            }

                            if (Isok)
                            {
                                break;
                            }
                        }
                    }

                    if (Isok)
                    {
                        break;
                    }
                }
                catch { }
            }
        }