Ejemplo n.º 1
0
        private List <OrderEntity> ResolveOrders(CsvReader csv, string file, List <OrderEntity> items)
        {
            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                OrderDTO orderDTO = new OrderDTO();
                orderDTO.fileName   = file;
                orderDTO.source     = this.Name;
                orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(orderDTO.source);
                orderDTO.sourceSN   = csv.GetField <string>("订单编号").Trim();
                orderDTO.orderType  = 0;
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);

                    continue;
                }



                var orderDate = csv.GetField <string>("行权日期");
                var orderTime = csv.GetField <string>("行权时间");
                orderDTO.createdDate = DateTime.ParseExact(string.Format("{0}{1}", orderDate, orderTime), "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                // orderDTO.orderSN_old = string.Format("{0}-{1}", orderDTO.source, orderDTO.sourceSN); //订单SN=来源+原来的SN
                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));

                orderDTO.orderStatus = OrderStatus.Confirmed;

                var sourceStatus = csv.GetField <string>("订单状态").Trim();
                if (sourceStatus.Contains("撤消"))
                {
                    orderDTO.orderStatus = OrderStatus.Cancelled;
                    orderDTO.orderType   = 2;
                }


                orderDTO.productName = csv.GetField <string>("服务项目").Trim();
                orderDTO.count       = csv.GetField <int>("本人次数");

                orderDTO.consigneeName = csv.GetField <string>("使用人姓名").Trim();
                if (string.IsNullOrEmpty(orderDTO.consigneeName))
                {
                    orderDTO.consigneeName = csv.GetField <string>("姓名").Trim();
                }

                orderDTO.consigneePhone = csv.GetField <string>("手机号").Trim();



                orderDTO.consigneeAddress = csv.GetField <string>("地址").Trim();

                if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                    string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                {
                    var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                    orderDTO.consigneeProvince = addrInfo.Province;
                    orderDTO.consigneeCity     = addrInfo.City;
                    orderDTO.consigneeCounty   = addrInfo.County;
                }
                //数据库中查找订单,如果找到订单了就跳过
                if (CheckOrderInDataBase(orderDTO))
                {
                    continue;
                }
                //内存中查找,没找到就新增对象,找到就关联新的商品
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    //处理订单与地址、收货人、商品的关联关系。消除重复项
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }


                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);

                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                        db.SaveChanges();
                    }
                }
                else
                {
                    using (var db = new OMSContext())
                    {
                        var bar = db.ProductDictionarySet.FirstOrDefault(p => p.ProductNameInPlatform == orderDTO.productName);
                        if (bar == null || string.IsNullOrEmpty(bar.ProductCode))
                        {
                            Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品:{orderDTO.productName}未找到");
                            //  Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Debug($"订单文件:{file}中平台商品:{productName}未找到.order:{Util.Helpers.Json.ToJson(item)}");
                            if (bar == null)
                            {
                                ProductDictionary productDictionary = new ProductDictionary()
                                {
                                    ProductNameInPlatform = orderDTO.productName
                                };
                                db.ProductDictionarySet.Add(productDictionary);
                                db.SaveChanges();
                            }
                            items.Remove(item);
                            continue;
                        }
                        var foo = db.ProductsSet.Include(p => p.weightModel).FirstOrDefault(p => p.sku == bar.ProductCode);
                        if (foo == null)
                        {
                            Util.Logs.Log.GetLog(nameof(CIBVIPCSVOrderOption)).Error($"订单文件:{file}中平台商品名称:{orderDTO.productName}对应系统商品未找到");

                            items.Remove(item);
                            continue;
                        }

                        decimal weight = foo == null ? 0 : foo.QuantityPerUnit * orderDTO.count;
                        if (orderDTO.orderStatus == OrderStatus.Cancelled)
                        {
                            var p = item.Products.FirstOrDefault(o => o.sku == foo.sku);
                            if (p != null)
                            {
                                p.ProductCount  -= orderDTO.count;
                                p.ProductWeight -= weight;
                            }
                        }
                        else
                        {
                            if (item.Products.FirstOrDefault(p => p.sku == foo.sku) == null)
                            {
                                OrderProductInfo orderProductInfo = new OrderProductInfo()
                                {
                                    ProductPlatId   = orderDTO.productsku,
                                    ProductPlatName = orderDTO.productName.Trim(),
                                    //   Warehouse = item.OrderLogistics.Logistics,
                                    MonthNum       = orderDTO.createdDate.Month,
                                    weightCode     = foo.weightModel == null ? 0 : foo.weightModel.Code,
                                    weightCodeDesc = foo.weightModel == null ? string.Empty : $"{foo.weightModel.Value}g",
                                    OrderSn        = orderDTO.orderSN,
                                    //  TotalAmount = totalAmount,
                                    ProductCount  = orderDTO.count,
                                    ProductWeight = weight,
                                    Source        = orderDTO.source,
                                    sku           = foo.sku
                                };
                                item.Products.Add(orderProductInfo);
                            }
                        }
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 2
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Predelivery;
            orderDTO.fileName    = file;
            orderDTO.orderType   = 0;



            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                var row = excelTable.Rows[i];


                orderDTO.createdDate = DateTime.Now;

                orderDTO.source     = Name;
                orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(Name);

                orderDTO.sourceSN = Convert.ToString(row["订单号"]); //订单号
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);
                    continue;
                }


                orderDTO.productName = Convert.ToString(row["商品名称"]); //商品名称
                // orderDTO.productsku = Convert.ToString(row[2]); //商品编号
                orderDTO.count = Convert.ToInt32(row["数量"]);          //数量


                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));
                if (CheckOrderInDataBase(orderDTO))//是否是重复订单
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    // var productProps = Convert.ToString(row[5]); //商品属性


                    orderDTO.consigneeName   = Convert.ToString(row["收货人姓名"]);  //收件人
                    orderDTO.consigneePhone  = Convert.ToString(row["收货人手机号"]); //联系电话
                    orderDTO.consigneePhone2 = string.Empty;


                    orderDTO.consigneeProvince = Convert.ToString(row["收货地址省份"]);
                    orderDTO.consigneeCity     = Convert.ToString(row["收货地址城市"]);
                    orderDTO.consigneeCounty   = Convert.ToString(row["收货地址区/县"]);
                    orderDTO.consigneeAddress  = Convert.ToString(row["详细收货地址"]); //收货地区+详细地址
                    //  orderDTO.consigneeZipCode = Convert.ToString(row["邮编"]); //邮编

                    //
                    if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                        string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                    {
                        var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                        orderDTO.consigneeProvince = addrInfo.Province;
                        orderDTO.consigneeCity     = addrInfo.City;
                        orderDTO.consigneeCounty   = addrInfo.County;
                        //   consigneeAddress = addrInfo.Address;
                    }


                    var totalQuantity = orderDTO.count;



                    orderDTO.PayType = PayType.None;
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);
                        if (orderItem.OrderRepurchase == null)
                        {
                            orderItem.OrderRepurchase = new OrderRepurchase();
                        }
                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);

                        db.SaveChanges();
                    }
                }
                else
                {
                    orderDTO.productName = Convert.ToString(row["商品名称"]); //商品名称

                    orderDTO.count = Convert.ToInt32(row["数量"]);          //数量

                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 3
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, DataFileInfo file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file.FullName;
            orderDTO.orderType   = 0;
            orderDTO.orderStatus = OrderStatus.Confirmed;


            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                var row = excelTable.Rows[i];

                var orderDateStr = Convert.ToString(row["制单时间"]); //订单创建时间
                orderDTO.createdDate = DateTime.Parse(orderDateStr);
                // orderDTO.createdDate = file.FileDate;

                /*金文的订单整合在一个EXCEL中。
                 * 根据店铺名称解析为银行-金文科技代发和银行-金文(工行代发)
                 */
                string shopName = Convert.ToString(row["店铺"]);
                if (shopName == "金文网络-中国工商银行积分商城" || shopName == "金文网络-工商银行工银e生活合作项目(积分模块)".Trim())
                {
                    orderDTO.source     = OrderSource.ICBC_JINWEN;
                    orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.ICBC_JINWEN);
                }
                else
                {
                    orderDTO.source     = OrderSource.BANK_JINWEN;
                    orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.BANK_JINWEN);
                }


                orderDTO.sourceSN = Convert.ToString(row["交易号"]); //订单号
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);
                    continue;
                }


                orderDTO.productName = Convert.ToString(row["商品名称"]); //商品名称
                // orderDTO.productsku = Convert.ToString(row[2]); //商品编号

                try
                {
                    orderDTO.count = Convert.ToInt32(row["通知数量"]); //数量
                }
                catch (Exception)
                {
                    orderDTO.count = Convert.ToInt32(row["数量"]); //数量
                }

                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));
                if (CheckOrderInDataBase(orderDTO))//是否是重复订单
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    orderDTO.consigneeName   = Convert.ToString(row["收货人"]); //收件人
                    orderDTO.consigneePhone  = Convert.ToString(row["手机"]);  //联系电话
                    orderDTO.consigneePhone2 = string.Empty;


                    orderDTO.consigneeProvince = string.Empty;
                    orderDTO.consigneeCity     = string.Empty;
                    orderDTO.consigneeCounty   = string.Empty;
                    orderDTO.consigneeAddress  = Convert.ToString(row["地址"]); //收货地区+详细地址
                    // orderDTO.consigneeZipCode = Convert.ToString(row[9]); //邮编

                    //
                    if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                        string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                    {
                        var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                        orderDTO.consigneeProvince = addrInfo.Province;
                        orderDTO.consigneeCity     = addrInfo.City;
                        orderDTO.consigneeCounty   = addrInfo.County;
                        //   consigneeAddress = addrInfo.Address;
                    }


                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);
                        if (orderItem.OrderRepurchase == null)
                        {
                            orderItem.OrderRepurchase = new OrderRepurchase();
                        }
                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);

                        db.SaveChanges();
                    }
                }
                else
                {
                    orderDTO.consigneeName  = Convert.ToString(row["收货人"]); //收件人
                    orderDTO.consigneePhone = Convert.ToString(row["手机"]);  //联系电话

                    try
                    {
                        orderDTO.count = Convert.ToInt32(row["通知数量"]); //数量
                    }
                    catch (Exception)
                    {
                        orderDTO.count = Convert.ToInt32(row["数量"]); //数量
                    }

                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 4
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file;
            orderDTO.source      = Name;
            orderDTO.orderType   = 0;
            orderDTO.sourceDesc  = Util.Helpers.Reflection.GetDescription <OrderSource>(Name);
            foreach (DataRow row in excelTable.Rows)
            {
                var id = orderDTO.sourceSN = Convert.ToString(row["兑换流水编号"]).Trim();
                if (row["礼品名称"] == DBNull.Value ||
                    row["兑换礼品数量"] == DBNull.Value)

                {
                    InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown);
                    continue;
                }

                var sOrderDate = Convert.ToString(row["兑换登记日期"]);
                orderDTO.createdDate = DateTime.Parse(sOrderDate.Insert(4, "-").Insert(7, "-"));

                var sourceAccount = string.Empty;
                if (excelTable.Columns.Contains("持卡人证件号码"))
                {
                    sourceAccount = Convert.ToString(row["持卡人证件号码"]);
                }

                orderDTO.productName = Convert.ToString(row["礼品名称"]);
                orderDTO.productsku  = Convert.ToString(row["礼品编号"]);
                orderDTO.count       = Convert.ToInt32(row["兑换礼品数量"]);

                var customerName   = string.Empty;
                var customerPhone  = string.Empty;
                var customerPhone2 = string.Empty;

                orderDTO.consigneeName = Convert.ToString(row["领取人姓名"]);

                orderDTO.consigneeAddress = Convert.ToString(row["递送地址"]);

                var consigneeAddressUnit = string.Empty;
                if (excelTable.Columns.Contains("单位"))
                {
                    consigneeAddressUnit = Convert.ToString(row["单位"]);
                }

                //特殊处理:

                //合并详细地址和单位地址,并且将单位地址设置为空(解决地址被分开,识别度降低问题)

                if (!string.IsNullOrEmpty(consigneeAddressUnit))
                {
                    orderDTO.consigneeAddress = string.Format("{0}{1}", orderDTO.consigneeAddress, consigneeAddressUnit);
                }

                orderDTO.consigneeZipCode = Convert.ToString(row["递送地址邮编"]);

                if (excelTable.Columns.Contains("持卡人姓名"))
                {
                    customerName = Convert.ToString(row["持卡人姓名"]);
                }
                else
                {
                    customerName = Convert.ToString(row["领取人姓名"]);
                }



                if (excelTable.Columns.Contains("分机"))
                {
                    orderDTO.consigneePhone2 = Convert.ToString(row["分机"]);
                }

                if (excelTable.Columns.Contains("手机号码"))
                {
                    customerPhone = orderDTO.consigneePhone = Convert.ToString(row["手机号码"]);
                }
                else
                {
                    customerPhone = orderDTO.consigneePhone;//NOTE: no necessery!
                }
                //兑换流水+下单日期+手机号+商品编号
                var sourceSN = $"{id.Trim()}_{orderDTO.createdDate.ToString("yyyyMMdd")}_{customerPhone}_{orderDTO.productsku}";
                //  orderDTO.orderSN_old= string.Format("{0}-{1}", orderDTO.source, orderDTO.sourceSN);
                orderDTO.sourceSN = Util.Helpers.Encrypt.Md5By16(sourceSN);
                orderDTO.orderSN  = string.Format("{0}-{1}", orderDTO.source, orderDTO.sourceSN); //订单SN=来源+原来的SN

                if (excelTable.Columns.Contains("领取人所在省份"))
                {
                    orderDTO.consigneeProvince = Convert.ToString(row["领取人所在省份"]);
                }

                if (excelTable.Columns.Contains("领取人所在城市"))
                {
                    orderDTO.consigneeCity = Convert.ToString(row["领取人所在城市"]);
                }

                if (excelTable.Columns.Contains("领取人所在县区"))
                {
                    orderDTO.consigneeCounty = Convert.ToString(row["领取人所在县区"]);
                }

                //
                if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                    string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                {
                    var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                    orderDTO.consigneeProvince = addrInfo.Province;
                    orderDTO.consigneeCity     = addrInfo.City;
                    orderDTO.consigneeCounty   = addrInfo.County;
                    //  consigneeAddress = addrInfo.Address;
                }

                orderDTO.consigneeName = orderDTO.consigneeName.Split(' ').First();
                customerName           = customerName.Split(' ').First();

                //修正处理:
                //当持卡人和领取人一致的时候,领取人的联系号码比较乱(银行的输入/客户填写问题)
                //我们使用持卡人的号码修正领取人的联系号码,以确保领取人的联系号码更有效!
                //if (customerName.Equals(consigneeName) && string.IsNullOrEmpty(consigneePhone))
                //    consigneePhone = customerPhone;


                if (CheckOrderInDataBase(orderDTO))
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //处理收货人相关的业务逻辑
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        else
                        {
                            items.Add(orderItem);
                            db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                            db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 5
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file;
            orderDTO.source      = Name;
            orderDTO.orderType   = 0;
            orderDTO.sourceDesc  = Util.Helpers.Reflection.GetDescription <OrderSource>(Name);
            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                var row = excelTable.Rows[i];
                if (row["姓名"] == DBNull.Value ||
                    row["产品名称"] == DBNull.Value ||
                    row["联系电话"] == DBNull.Value ||
                    row["兑奖申请日期"] == DBNull.Value ||
                    string.IsNullOrEmpty(row["兑奖申请日期"].ToString().Trim()))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);

                    continue;
                }

                var id = orderDTO.sourceSN = Convert.ToString(row["交易流水号"]).Trim();
                if (row["产品名称"] == DBNull.Value ||
                    row["产品数量"] == DBNull.Value)

                {
                    InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown);
                    continue;
                }
                else
                {
                    orderDTO.productName = Convert.ToString(row["产品名称"]);

                    orderDTO.count = Convert.ToInt32(row["产品数量"]);
                }

                var sOrderDate = Convert.ToString(row["兑奖申请日期"]);
                if (string.IsNullOrEmpty(sOrderDate))
                {
                    continue;
                }
                orderDTO.createdDate = DateTime.Parse(sOrderDate);


                var customerName   = string.Empty;
                var customerPhone  = string.Empty;
                var customerPhone2 = string.Empty;

                orderDTO.consigneeName = Convert.ToString(row["姓名"]);

                orderDTO.consigneeAddress = Convert.ToString(row["收件人地址"]).Replace("中国", "").Trim();

                orderDTO.consigneeZipCode = Convert.ToString(row["邮编"]);

                customerName = Convert.ToString(row["姓名"]);



                customerPhone = orderDTO.consigneePhone = Convert.ToString(row["联系电话"]);


                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));



                //
                if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                    string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                {
                    var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                    orderDTO.consigneeProvince = addrInfo.Province;
                    orderDTO.consigneeCity     = addrInfo.City;
                    orderDTO.consigneeCounty   = addrInfo.County;
                    //  consigneeAddress = addrInfo.Address;
                }



                if (CheckOrderInDataBase(orderDTO))
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //处理收货人相关的业务逻辑
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        else
                        {
                            items.Add(orderItem);
                            db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                            db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 6
0
        protected List <OrderEntity> ResolveOrders_ABC(DataTable excelTable, DataFileInfo file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file.FullName;
            orderDTO.orderType   = 0;
            orderDTO.orderStatus = OrderStatus.Confirmed;


            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                var row = excelTable.Rows[i];

                var orderDateStr = Convert.ToString(row[1]); //订单创建时间 20200411 23:03:32
                orderDTO.createdDate = DateTime.ParseExact(orderDateStr, "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture);


                orderDTO.source     = this.Name;
                orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(this.Name);

                orderDTO.sourceSN = Convert.ToString(row[0]); //订单号
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);
                    continue;
                }


                orderDTO.productName = Convert.ToString(row["商品名称"]); //商品名称
                                                                      // orderDTO.productsku = Convert.ToString(row[2]); //商品编号



                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));
                if (CheckOrderInDataBase(orderDTO))//是否是重复订单
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    orderDTO.count = Convert.ToInt32(row["数量"]); //数量



                    orderDTO.consigneeName   = Convert.ToString(row["收件人姓名"]);   //收件人
                    orderDTO.consigneePhone  = Convert.ToString(row["收件人联系方式"]); //联系电话
                    orderDTO.consigneePhone2 = string.Empty;


                    orderDTO.consigneeProvince = string.Empty;
                    orderDTO.consigneeCity     = string.Empty;
                    orderDTO.consigneeCounty   = string.Empty;
                    orderDTO.consigneeAddress  = Convert.ToString(row["收件人地址"]); //收货地区+详细地址
                                                                                 // orderDTO.consigneeZipCode = Convert.ToString(row[9]); //邮编

                    //
                    if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                        string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                    {
                        var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                        orderDTO.consigneeProvince = addrInfo.Province;
                        orderDTO.consigneeCity     = addrInfo.City;
                        orderDTO.consigneeCounty   = addrInfo.County;
                        //   consigneeAddress = addrInfo.Address;
                    }


                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);
                        if (orderItem.OrderRepurchase == null)
                        {
                            orderItem.OrderRepurchase = new OrderRepurchase();
                        }
                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);

                        db.SaveChanges();
                    }
                }
                else
                {
                    orderDTO.consigneeName  = Convert.ToString(row["收件人姓名"]);   //收件人
                    orderDTO.consigneePhone = Convert.ToString(row["收件人联系方式"]); //联系电话

                    orderDTO.count = Convert.ToInt32(row["数量"]);                //数量

                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 7
0
        private OrderEntity ResolveOrdersFromJD(CsvReader csv, OrderDTO orderDTO, List <OrderEntity> items)
        {
            orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, DateTime.Now.ToString("yyyyMMdd"));
            var orderDate = csv.GetField <string>("付款确认时间");

            if (string.IsNullOrEmpty(orderDate))
            {
                orderDate = csv.GetField <string>("下单时间");
            }

            orderDTO.createdDate = DateTime.Parse(orderDate);


            orderDTO.productName = csv.GetField <string>("商品名称").Trim();
            orderDTO.productsku  = csv.GetField <string>("商品ID").Trim();
            var quantity = orderDTO.count = csv.GetField <string>("订购数量").ToInt();

            // decimal weight = csv.GetField<string>("总重量").ToInt();
            orderDTO.consigneeName       = csv.GetField <string>("客户姓名").Trim();
            orderDTO.consigneePersonCard = csv.GetField <string>("下单帐号").Trim();
            orderDTO.consigneePhone      = string.Empty;
            //京东天猫订单独有的金额信息
            orderDTO.pricePerUnit = csv.GetField <decimal>("京东价") / quantity;
            orderDTO.totalAmount  = csv.GetField <decimal>("应付金额");
            orderDTO.discountFee  = csv.GetField <decimal>("订单金额") - orderDTO.totalAmount;

            orderDTO.consigneeAddress = csv.GetField <string>("客户地址").Trim();


            var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);

            orderDTO.consigneeProvince = addrInfo.Province;
            orderDTO.consigneeCity     = addrInfo.City;
            orderDTO.consigneeCounty   = addrInfo.County;
            //   consigneeAddress = addrInfo.Address;

            orderDTO.consigneeZipCode = string.Empty;
            //int weightcode = 0;
            //csv.TryGetField<int>("规格代码", out weightcode);
            //orderDTO.weightCode = weightcode;
            //orderDTO.weightCodeDesc = csv.GetField<string>("规格名称");

            orderDTO.OrderComeFrom = 0;


            /* 生成订单对象,从items集合中查找是否已经录入该订单对象
             * 如果items中已经有该订单对象则创建商品子对象及物流商品对象
             * 如果items中没有该订单对象则创建并关联各个子对象,将订单对象录入items
             * 重要提示:本方法解析csv对象,并转化为全新的订单对象,需要将订单的所有内容(重点是商品对象)都完整录入OMS系统中
             *
             */
            var item = items.Find(o => o.OrderSn == orderDTO.orderSN);

            if (item == null)//集合中不存在该订单对象
            {
                var orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                orderItem.Consignee.PersonCard = orderDTO.consigneePersonCard;

                if (orderItem.OrderType == 0)
                {
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone) || !string.IsNullOrEmpty(orderItem.Consignee.PersonCard))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            return(null);
                        }



                        if (!InputProductInfoWithoutSaveChange_JD(db, orderDTO, orderItem))
                        {
                            return(null);
                        }

                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);

                        //  db.OrderProductSet.Add(orderProductInfo);
                        db.SaveChanges();
                        items.Add(orderItem);
                        return(orderItem);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                orderDTO.consigneeName  = csv.GetField <string>("客户姓名").Trim();
                orderDTO.consigneePhone = string.Empty;

                orderDTO.count = csv.GetField <string>("订购数量").ToInt();

                using (var db = new OMSContext())
                {
                    InputProductInfoWithoutSaveChange_JD(db, orderDTO, item);
                }
                return(null);
            }
        }
Ejemplo n.º 8
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file;
            orderDTO.orderType   = 0;



            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                var row = excelTable.Rows[i];

                var orderDateStr = Convert.ToString(row[0]); //订单创建时间
                orderDTO.createdDate = DateTime.Parse(orderDateStr);

                orderDTO.source     = OrderSource.CIBAPP;
                orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.CIBAPP);

                orderDTO.sourceSN = Convert.ToString(row[1]); //订单号
                if (string.IsNullOrEmpty(orderDTO.sourceSN))
                {
                    InputExceptionOrder(orderDTO, ExceptionType.SourceSnIsNull);
                    continue;
                }


                orderDTO.productName = Convert.ToString(row[3]); //商品名称
                orderDTO.productsku  = Convert.ToString(row[2]); //商品编号
                orderDTO.count       = Convert.ToInt32(row[4]);  //数量


                orderDTO.orderSN = string.Format("{0}-{1}_{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate.ToString("yyyyMMdd"));
                if (CheckOrderInDataBase(orderDTO))//是否是重复订单
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    // var productProps = Convert.ToString(row[5]); //商品属性


                    orderDTO.consigneeName   = Convert.ToString(row[6]); //收件人
                    orderDTO.consigneePhone  = Convert.ToString(row[7]); //联系电话
                    orderDTO.consigneePhone2 = string.Empty;


                    orderDTO.consigneeProvince = string.Empty;
                    orderDTO.consigneeCity     = string.Empty;
                    orderDTO.consigneeCounty   = string.Empty;
                    orderDTO.consigneeAddress  = Convert.ToString(row[8]); //收货地区+详细地址
                    orderDTO.consigneeZipCode  = Convert.ToString(row[9]); //邮编

                    //
                    if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                        string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                    {
                        var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                        orderDTO.consigneeProvince = addrInfo.Province;
                        orderDTO.consigneeCity     = addrInfo.City;
                        orderDTO.consigneeCounty   = addrInfo.County;
                        //   consigneeAddress = addrInfo.Address;
                    }


                    var totalQuantity = orderDTO.count;


                    //是否需要发票
                    var invoiceFlag = Convert.ToString(row["是否需要发票"]); //是否需要发票
                    var invoiceType = string.Empty;
                    var invoiceName = Convert.ToString(row["发票抬头"]);   //发票抬头
                    if (invoiceFlag.Equals("否"))
                    {
                        invoiceType = invoiceName = string.Empty;
                    }
                    string paystr = Convert.ToString(row["支付方式"]);
                    switch (paystr)
                    {
                    case "积分支付":
                        orderDTO.PayType = PayType.Integral;

                        break;

                    case "积分+自付金支付":
                        orderDTO.PayType    = PayType.IntegralAndMoney;
                        orderDTO.source     = OrderSource.CIBEVT;
                        orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.CIBEVT);

                        break;

                    case "分期支付":
                        orderDTO.PayType    = PayType.installments;
                        orderDTO.source     = OrderSource.CIBSTM;
                        orderDTO.sourceDesc = Util.Helpers.Reflection.GetDescription <OrderSource>(OrderSource.CIBSTM);

                        break;

                    default:
                        orderDTO.PayType = PayType.None;
                        break;
                    }
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //查找联系人
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        items.Add(orderItem);
                        if (orderItem.OrderRepurchase == null)
                        {
                            orderItem.OrderRepurchase = new OrderRepurchase();
                        }
                        db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                        db.OrderDateInfos.Add(orderItem.OrderDateInfo);

                        db.SaveChanges();
                    }
                }
                else
                {
                    orderDTO.productName = Convert.ToString(row[3]); //商品名称
                    orderDTO.productsku  = Convert.ToString(row[2]); //商品编号

                    orderDTO.count = Convert.ToInt32(row[4]);        //数量

                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }

            return(items);
        }
Ejemplo n.º 9
0
        protected List <OrderEntity> ResolveOrders(DataTable excelTable, string file, List <OrderEntity> items)
        {
            OrderDTO orderDTO = new OrderDTO();

            orderDTO.orderStatus = OrderStatus.Confirmed;
            orderDTO.fileName    = file;
            orderDTO.source      = Name;
            orderDTO.orderType   = 0;
            orderDTO.sourceDesc  = Util.Helpers.Reflection.GetDescription <OrderSource>(Name);
            foreach (DataRow row in excelTable.Rows)
            {
                orderDTO.sourceSN = Convert.ToString(row["订单号"]).Trim();
                if (row["产品"] == DBNull.Value)

                {
                    InputExceptionOrder(orderDTO, ExceptionType.ProductNameUnKnown);
                    continue;
                }

                var sOrderDate = Convert.ToString(row["订单时间"]);
                orderDTO.createdDate = DateTime.Parse(sOrderDate);



                orderDTO.productName = Convert.ToString(row["产品"]);

                orderDTO.count = 2;

                var customerName   = string.Empty;
                var customerPhone  = string.Empty;
                var customerPhone2 = string.Empty;

                orderDTO.consigneeName = Convert.ToString(row["姓名"]);

                orderDTO.consigneeAddress = Convert.ToString(row["地址"]);



                //特殊处理:

                //合并详细地址和单位地址,并且将单位地址设置为空(解决地址被分开,识别度降低问题)

                customerPhone = orderDTO.consigneePhone = Convert.ToString(row["电话"]);



                orderDTO.orderSN = string.Format("{0}-{1}-{2}", orderDTO.source, orderDTO.sourceSN, orderDTO.createdDate); //订单SN=来源+原来的SN



                //
                if (string.IsNullOrEmpty(orderDTO.consigneeProvince) &&
                    string.IsNullOrEmpty(orderDTO.consigneeCity) && !string.IsNullOrEmpty(orderDTO.consigneeAddress))
                {
                    var addrInfo = DistrictService.DistrictService.ResolveAddress(orderDTO.consigneeAddress);
                    orderDTO.consigneeProvince = addrInfo.Province;
                    orderDTO.consigneeCity     = addrInfo.City;
                    orderDTO.consigneeCounty   = addrInfo.County;
                    //  consigneeAddress = addrInfo.Address;
                }



                if (CheckOrderInDataBase(orderDTO))
                {
                    continue;
                }
                var item = items.Find(o => o.OrderSn == orderDTO.orderSN);
                if (item == null)
                {
                    OrderEntity orderItem = OrderEntityService.CreateOrderEntity(orderDTO);
                    using (var db = new OMSContext())
                    {
                        //处理收货人相关的业务逻辑
                        if (!string.IsNullOrEmpty(orderItem.Consignee.Phone))
                        {
                            OrderEntityService.InputConsigneeInfo(orderItem, db);
                        }
                        else //异常订单
                        {
                            InputExceptionOrder(orderDTO, ExceptionType.PhoneNumOrPersonNameIsNull);
                            continue;
                        }

                        if (!InputProductInfoWithoutSaveChange(db, orderDTO, orderItem))
                        {
                            continue;
                        }
                        else
                        {
                            items.Add(orderItem);
                            db.OrderRepurchases.Add(orderItem.OrderRepurchase);
                            db.OrderDateInfos.Add(orderItem.OrderDateInfo);


                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    using (var db = new OMSContext())
                    {
                        InputProductInfoWithoutSaveChange(db, orderDTO, item);
                    }
                }
            }
            return(items);
        }