Exemplo n.º 1
0
        /// <summary>
        /// 订单价格校验
        /// </summary>
        /// <param name="shopList"></param>
        /// <param name="oAmount"></param>
        /// <returns></returns>
        public bool OrderAmountCheck(List <Shop> shopList, decimal oAmount, decimal ratio, out decimal shopListTotle)
        {
            shopListTotle = 0;
            decimal       normTotle = 0;
            decimal       ActTotle  = 0;
            PartExtendBll pbll      = new PartExtendBll();
            ProductBll    proBll    = new ProductBll();

            foreach (Shop item in shopList)
            {
                var qty = 0;
                if (int.TryParse(item.Qty, out qty))
                {
                    //产品
                    DAO.Parts product = proBll.GetPartModel(item.ID);
                    //先检查产品是否有属性,是否是最后一个属性
                    if (!string.IsNullOrEmpty(item.Attrs))
                    {
                        //先检查是否是最终属性,没有子属性
                        DAO.PartsExtend childAttr = pbll.GetChildAttrModel(item.ID, item.Attrs);
                        if (childAttr == null)
                        { //没有子属性为有效的属性
                            DAO.PartsExtend currAttr = pbll.GetPartAttrModel(item.ID, item.Attrs);
                            if (currAttr == null)
                            {
                                //属性没有效
                                return(false);
                            }
                            else
                            {
                                if (item.Type != "-1")
                                {
                                    int            aid = int.Parse(item.Type);
                                    int            pid = int.Parse(item.ID);
                                    int            tid = int.Parse(item.Attrs);
                                    DAO.ActiveAttr att = db.ActiveAttr.Where(m => m.ActiveID == aid && m.AProID == pid && m.AtrrID == tid).FirstOrDefault();
                                    if (att != null)
                                    {
                                        ActTotle += qty * att.NewPrice;
                                    }
                                    else
                                    {
                                        normTotle += qty * currAttr.AttrPrice;
                                    }
                                }
                                else
                                {
                                    normTotle += qty * currAttr.AttrPrice;
                                }
                            }
                        }
                        else
                        {
                            //不是最终属性 错误
                            return(false);
                        }
                    }
                    else
                    {
                        //没有属性
                        if (item.Type != "-1")
                        {
                            int            aid = int.Parse(item.Type);
                            int            pid = int.Parse(item.ID);
                            DAO.ActivePros pro = db.ActivePros.Where(m => m.ActiveID == aid && m.ProID == pid).FirstOrDefault();
                            if (pro != null)
                            {
                                ActTotle += qty * pro.NewPrice;
                            }
                            else
                            {
                                normTotle += qty * product.Price;
                            }
                        }
                        else
                        {
                            //没有活动
                            normTotle += qty * product.Price;
                        }
                    }
                }
                else
                {
                    //数量不是数字
                    return(false);
                }
            }
            //获取会员等级折扣
            shopListTotle = Math.Round(ActTotle + Math.Round(normTotle * 1, 2), 2);
            if (shopListTotle == oAmount)
            {
                //价格验证成功
                return(true);
            }
            else
            {
                //价格验证失败
                return(false);
            }
        }