public static Dictionary <int, GetPCodeModel> GetPCodeModelByRulePKIDS(IEnumerable <int> pkids)
        {
            System.Data.DataTable dt = DataAccess.DAO.DALActivity.CouponVlidateForPKIDS(pkids);
            if (dt != null && dt.Rows.Count > 0)
            {
                var dic = new Dictionary <int, GetPCodeModel>(dt.Rows.Count);
                foreach (DataRow dr in dt.Rows)
                {
                    var result   = new GetPCodeModel();
                    var firstRow = dr;
                    result.GETPKID       = firstRow.IsNull("PKID") ? -1 : Convert.ToInt32(firstRow["PKID"]);
                    result.RuleID        = firstRow.IsNull("RuleID") ? -1 : Convert.ToInt32(firstRow["RuleID"]);
                    result.PromtionName  = firstRow.IsNull("PromtionName") ? string.Empty : firstRow["PromtionName"].ToString();
                    result.Description   = firstRow.IsNull("Description") ? string.Empty : firstRow["Description"].ToString();
                    result.Minmoney      = firstRow.IsNull("Minmoney") ? 0 : Convert.ToDecimal(firstRow["Minmoney"]);
                    result.Discount      = firstRow.IsNull("Discount") ? 0 : Convert.ToDecimal(firstRow["Discount"]);
                    result.ValiStartDate = firstRow.IsNull("ValiStartDate") ? (DateTime?)null :
                                           Convert.ToDateTime(firstRow["ValiStartDate"]);
                    result.ValiEndDate = firstRow.IsNull("ValiEndDate") ? (DateTime?)null :
                                         Convert.ToDateTime(firstRow["ValiEndDate"]);
                    result.Term             = firstRow.IsNull("Term") ? 0 : Convert.ToInt32(firstRow["Term"]);
                    result.Quantity         = firstRow.IsNull("Quantity") ? 0 : Convert.ToInt32(firstRow["Quantity"]);
                    result.SupportUserRange = firstRow.IsNull("SupportUserRange") ? 0 : Convert.ToInt32(firstRow["SupportUserRange"]);
                    if (!dic.ContainsKey(result.GETPKID))
                    {
                        dic.Add(result.GETPKID, result);
                    }
                    return(dic);
                }
            }

            return(new Dictionary <int, GetPCodeModel>());
        }
        public static GetPCodeModel GetPCodeModelByRulePKID(int pkid)
        {
            var result = new GetPCodeModel();

            System.Data.DataTable dt = DataAccess.DAO.DALActivity.CouponVlidateForPKID(pkid);
            if (dt != null && dt.Rows.Count > 0)
            {
                var firstRow = dt.Rows[0];
                result.GETPKID       = firstRow.IsNull("PKID") ? -1 : Convert.ToInt32(firstRow["PKID"]);
                result.RuleID        = firstRow.IsNull("RuleID") ? -1 : Convert.ToInt32(firstRow["RuleID"]);
                result.PromtionName  = firstRow.IsNull("PromtionName") ? string.Empty : firstRow["PromtionName"].ToString();
                result.Description   = firstRow.IsNull("Description") ? string.Empty : firstRow["Description"].ToString();
                result.Minmoney      = firstRow.IsNull("Minmoney") ? 0 : Convert.ToDecimal(firstRow["Minmoney"]);
                result.Discount      = firstRow.IsNull("Discount") ? 0 : Convert.ToDecimal(firstRow["Discount"]);
                result.ValiStartDate = firstRow.IsNull("ValiStartDate") ? (DateTime?)null :
                                       Convert.ToDateTime(firstRow["ValiStartDate"]);
                result.ValiEndDate = firstRow.IsNull("ValiEndDate") ? (DateTime?)null :
                                     Convert.ToDateTime(firstRow["ValiEndDate"]);
                result.Term             = firstRow.IsNull("Term") ? 0 : Convert.ToInt32(firstRow["Term"]);
                result.Quantity         = firstRow.IsNull("Quantity") ? 0 : Convert.ToInt32(firstRow["Quantity"]);
                result.SupportUserRange = firstRow.IsNull("SupportUserRange") ? 0 : Convert.ToInt32(firstRow["SupportUserRange"]);
            }

            return(result);
        }
        /// <summary>
        /// 返回可用当前券的产品
        /// </summary>
        /// <returns></returns>
        public IEnumerable <QueryProductsModel> GetAvailableCouponProducts(IEnumerable <QueryProductsModel> products,
                                                                           GetPCodeModel rule, decimal grossProfit)
        {
            var result = new List <QueryProductsModel>();

            foreach (var p in products)
            {
                var useCouponEffect = CalculateUseCouponEffect(p, rule);
                if (useCouponEffect != null && useCouponEffect.GrossProfit >= grossProfit)
                {
                    result.Add(p);
                }
            }

            return(result);
        }
Exemple #4
0
 public static int UpdateGetPCodeRule(GetPCodeModel model)
 {
     return(DALPromotion.UpdateGetPCodeRule(model));
 }
Exemple #5
0
        //public static int DeleteRecord(string type, int PKID)
        //{
        //	return DALPromotion.DeleteRecord(type,PKID);
        //}

        public static int SaveGetPCodeRule(GetPCodeModel model)
        {
            return(DALPromotion.SaveGetPCodeRule(model));
        }
        public static UseCouponEffect CalculateUseCouponEffect(QueryProductsModel product, GetPCodeModel rule)
        {
            UseCouponEffect result = null;

            if (product != null && rule != null)
            {
                int length = 10;
                if (product.PID.StartsWith("FU-", StringComparison.OrdinalIgnoreCase))
                {
                    length = 22;                                                                   //如果是喷漆服务,则可以多买很多
                }
                for (var i = 1; i <= length; i++)
                {
                    var price = product.cy_list_price * i;
                    if (price >= rule.Minmoney || price <= 0)
                    {
                        var status = string.Empty;
                        var now    = DateTime.Now;
                        if (rule.ValiStartDate != null && rule.ValiEndDate != null)
                        {
                            if (rule.ValiStartDate > now)
                            {
                                status = "NotStart";
                            }
                            else if (now >= rule.ValiStartDate && now < rule.ValiEndDate)
                            {
                                status = "OnGoing";
                            }
                            else if (now >= rule.ValiEndDate)
                            {
                                status = "Overdue";
                            }
                        }
                        else
                        {
                            if (rule.Term > 0)
                            {
                                status = "ValidDays";
                            }
                            else
                            {
                                status = "Other";
                            }
                        }
                        var priceAfterCoupon = decimal.Round((price - rule.Discount.GetValueOrDefault()) / i, 2);
                        result = new UseCouponEffect()
                        {
                            ProductCount      = i,
                            CouponPkId        = rule.GETPKID,
                            CouponDescription = rule.Description,
                            Discount          = rule.Discount,
                            Minmoney          = rule.Minmoney,
                            PriceAfterCoupon  = priceAfterCoupon,
                            GrossProfit       = priceAfterCoupon - product.cy_cost,
                            StartTime         = rule.ValiStartDate,
                            EndTime           = rule.ValiEndDate,
                            CouponDuration    = rule.Term,
                            Status            = status
                        };
                        break;
                    }
                }
            }

            return(result);
        }