public void Check()
        {
            if (!_time.IsBusinessDay(_time.GetAppNowTime().Date))
            {
                return;
            }

            var warningPeriod = _time.AddBusinessDays(_time.GetAppNowTime().Date, -1);
            var minDate       = DateTime.Now.AddMonths(-3);

            _log.Info("warningPeriod=" + warningPeriod);

            var messages = new List <string>();

            using (var db = _dbFactory.GetRWDb())
            {
                var items = db.Items.GetAll().Where(i => i.CreateDate > warningPeriod &&
                                                    i.ItemPublishedStatus == (int)PublishedStatuses.PublishingErrors &&
                                                    i.CreatedBy.HasValue)
                            .ToList();

                var users = db.Users.GetAllAsDto().ToList();

                var userIds = items.Select(i => i.CreatedBy).Distinct().ToList();

                foreach (var userId in userIds)
                {
                    var user = users.FirstOrDefault(u => u.Id == userId);
                    if (user == null)
                    {
                        continue;
                    }

                    var userItems = items.Where(i => i.CreatedBy == userId)
                                    .OrderBy(i => i.CreateDate)
                                    .ToList();

                    var message = String.Format("The following listings (created by {0}) have publishing errors: <br/>", user.Name)
                                  + String.Join("<br/>", userItems.Select(i => DateHelper.ToDateTimeString(i.CreateDate) + " - " + i.ASIN));// + " - " + i.ItemPublishedStatusReason));

                    _log.Info(user.Email + " - " + message);
                    _emailService.SendSystemEmail("System Notification: " + Name + " - To Review (" + userItems.Count() + ")",
                                                  message,
                                                  user.Email,
                                                  EmailHelper.RafiEmail + ", " + EmailHelper.SupportDgtexEmail);
                }
            }
        }
Esempio n. 2
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var now   = _time.GetAppNowTime();
            var today = _time.GetAppNowTime().Date;

            var lastRecord    = records.FirstOrDefault();
            var packageGoBack = (lastRecord != null ? _addressService.IsMine(lastRecord.AsAddressDto()) : false) ||
                                orderToTrackInfo.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender;

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            if (packageGoBack)
            {
                return(false); //No actions if package go back
            }
            if (orderToTrackInfo.Carrier == ShippingServiceUtils.USPSCarrier)
            {
                if (statusDate.HasValue &&
                    !_time.IsBusinessDay(statusDate.Value) &&
                    _time.GetBizDaysCount(statusDate.Value, today) < 2)
                {
                    //TASK: Let’s not send Exception messages for First Class packages if they were not delivered on Weekends/holidays.
                    if (orderToTrackInfo.ShippingMethodId.HasValue
                        &&
                        ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) ==
                        ShippingTypeCode.Standard)
                    {
                        //Don’t send notice to first class orders which USPS tried to deliver on Saturday.
                        //They will automatically will redeliver it on the next business day.
                        return(false);
                    }


                    //TASK: if any package couldn’t be delivered to FF on weekends/holidays
                    if (AddressHelper.IsFFAddress(orderToTrackInfo.ShippingAddress))
                    {
                        return(false);
                    }
                }

                //TASK: If First Class order wasn’t delivered like 102-1600419-5915438 check again in 24 hours, and only then send notifications.
                if (orderToTrackInfo.ShippingMethodId.HasValue
                    &&
                    ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) == ShippingTypeCode.Standard)
                {
                    var statusNextBusiessDay = _time.AddBusinessDays(statusDate, 1);
                    if (statusNextBusiessDay > now)
                    {
                        return(false);
                    }
                }

                if (!String.IsNullOrEmpty(status) &&
                    (status.IndexOf("Notice Left", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Receptacle Blocked", StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Available for Pickup", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Business Closed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Undeliverable as Addressed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Addressee not available", StringComparison.OrdinalIgnoreCase) >= 0) &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            if (orderToTrackInfo.Carrier == ShippingServiceUtils.DHLCarrier ||
                orderToTrackInfo.Carrier == ShippingServiceUtils.DHLMXCarrier)
            {
                if (!String.IsNullOrEmpty(status) &&
                    status.IndexOf("Delivery attempted; recipient not home", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            return(false);
        }