Exemple #1
0
 /// <summary>
 /// 验证
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 protected virtual bool CheckOrder(SettlementDto dto)
 {
     if (dto.AddressId > 0 && dto.Address == null)
     {
         dto.AddError("NoAddress");
         return(false);
     }
     if (dto.CouponId > 0 && dto.Coupon == null)
     {
         dto.AddError("NoCoupon");
         return(false);
     }
     if (dto.InvoiceId > 0 && dto.Invoice == null)
     {
         dto.AddError("NoInvoice");
         return(false);
     }
     if (dto.Products != null &&
         dto.Products.Count(it => it.ErrorMsg != null) > 0)
     {
         foreach (var settlementProduct in dto.Products)
         {
             dto.AddError(settlementProduct.ErrorMsg);
         }
         return(false);
     }
     if (dto.OrderType == OrderType.Custom && dto.Products != null && dto.Products.Count(it => it.Product != null && !it.Product.IsCustom) > 0)
     {
         dto.AddError("NotAllowCustomOrder");
         return(false);
     }
     return(CheckOrderLimitCount(dto) && CheckUnpayOrderCount(dto));
 }
Exemple #2
0
        /// <summary>
        /// 检查未支付订单数量
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        protected virtual bool CheckOrderLimitCount(SettlementDto dto)
        {
            if (dto.Products == null)
            {
                return(true);
            }
            var promotions   = dto.Products.Where(it => it.Product != null && it.Product.Promotion != null && it.Product.Promotion.OrderLimitCount > 0);
            var promotionIds = promotions.Select(it => it.Product.Promotion.Id).ToArray();

            if (promotionIds.Length == 0)
            {
                return(true);
            }
            var query = new QueryInfo();

            query.Query <OrderProductEntity>()
            .Where(it => it.Order.Account.Id == dto.AccountId && it.IsCount && promotionIds.Contains(it.Promotion.Id))
            .Select(it => new object[] { it.Count, it.Promotion.Id });
            var infos = Repository.GetEntities <OrderProductEntity>(query);

            if (infos == null || infos.Count == 0)
            {
                return(true);
            }
            if (promotions.Count(it =>
                                 infos.Where(s => s.Promotion != null && s.Promotion.Id == it.Product.Promotion.Id).Sum(s => s.Count) + it.Count > it.OrderLimitCount)
                > 0)
            {
                dto.AddError("ProductOrderLimitCountError");
                return(false);
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 检查未支付订单数量
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        protected virtual bool CheckUnpayOrderCount(SettlementDto dto)
        {
            if (dto.Account != null)
            {
                return(true);
            }
            var query = new QueryInfo();

            query.Query <OrderEntity>()
            .Where(it => it.Account.Id == dto.AccountId && it.PayAmount == 0)
            .Select(it => it.Id);
            Repository.GetEntities <OrderEntity>(query);
            var json       = Configuration.ConfigurationManager.GetSetting <string>("Order").DeserializeJson <dynamic>();
            int unpayCount = json == null ? 5 : json.UnpayCount;

            if (query.DataCount >= unpayCount)
            {
                dto.AddError("UnpayCountOver", query.DataCount);
                return(false);
            }
            return(true);
        }