private IEnumerable <VIPUpTactic> GetVIPUpTacticsWhenCash()
 {
     if (_vipInfo == null)
     {
         return(null);
     }
     else
     {
         List <VIPUpTactic> reTactics = new List <VIPUpTactic>();
         var lp       = VMGlobal.DistributionQuery.LinqOP;
         var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct();
         var kindIDs  = _vipInfo.VIPKinds.Where(o => brandIDs.Contains(o.BrandID)).Select(o => o.ID);
         var tactics  = lp.Search <VIPUpTactic>(o => kindIDs.Contains(o.FormerKindID) && o.IsEnabled).ToList();
         foreach (var tactic in tactics)
         {
             if (tactic.OnceConsume != 0)
             {
                 var pids      = GridDataItems.Where(o => o.BrandID == tactic.BrandID).Select(o => o.ProductID);
                 var costMoney = Details.Where(o => pids.Contains(o.ProductID)).Sum(o => o.Quantity * o.Price * o.Discount / 100.0M - o.CutMoney);
                 if (costMoney >= tactic.OnceConsume)
                 {
                     reTactics.Add(tactic);
                     continue;
                 }
             }
             if (tactic.DateSpan != 0 && tactic.SpanConsume != 0)
             {
                 var beginDate = DateTime.Now.AddDays(tactic.DateSpan * (-1)).Date;
                 var retails   = lp.Search <BillRetail>(o => o.CreateTime >= beginDate && o.VIPID == _vipInfo.ID);
                 var details   = lp.GetDataContext <BillRetailDetails>();
                 var products  = lp.Search <ViewProduct>(o => o.BrandID == tactic.BrandID);
                 var data      = from detail in details
                                 from retail in retails
                                 where retail.ID == detail.BillID
                                 from product in products
                                 where detail.ProductID == product.ProductID
                                 select detail;
                 var totalCost = data.Sum(o => o.Quantity * o.Price * o.Discount / 100.0M - o.CutMoney);
                 if (totalCost >= tactic.SpanConsume)
                 {
                     reTactics.Add(tactic);
                     continue;
                 }
             }
         }
         return(reTactics.OrderBy(o => o.FormerKindID));
     }
 }
Beispiel #2
0
        protected virtual BillRetailBO GenerateRetailBO()
        {
            var bo = new BillRetailBO {
                Bill = this.Master, Details = this.Details
            };
            var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct().ToList();

            bo.BillStoreOuts = new List <BillBO <BillStoreOut, BillStoreOutDetails> >();
            bo.BillStorings  = new List <BillBO <BillStoring, BillStoringDetails> >();
            foreach (var bid in brandIDs)
            {
                var storeout = this.GenerateStoreOut(bid);
                if (storeout.Details.Count > 0)
                {
                    bo.BillStoreOuts.Add(storeout);
                }
                var storing = this.GenerateStoring(bid);
                if (storing.Details.Count > 0)
                {
                    bo.BillStorings.Add(storing);
                }
            }
            return(bo);
        }
        public override OPResult Save()
        {
            var lp = VMGlobal.DistributionQuery.LinqOP;

            var brandIDs = GridDataItems.Select(o => o.BrandID).Distinct().ToList();
            List <BillStoreOutVM> storeouts = new List <BillStoreOutVM>();
            List <BillStoringVM>  storings  = new List <BillStoringVM>();

            foreach (var bid in brandIDs)
            {
                var storeout = this.GenerateStoreOut(bid);
                if (storeout.Details.Count > 0)
                {
                    storeouts.Add(storeout);
                }
                var storing = this.GenerateStoring(bid);
                if (storing.Details.Count > 0)
                {
                    storings.Add(storing);
                }
            }
            Action storeAction = () =>
            {
                foreach (var storeout in storeouts)
                {
                    storeout.Master.RefrenceBillCode = Master.Code;
                    storeout.SaveWithNoTran();
                }
                foreach (var storing in storings)
                {
                    storing.Master.RefrenceBillCode = Master.Code;
                    storing.SaveWithNoTran();
                }
            };

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    base.SaveWithNoTran();
                    storeAction();
                    if (this._vipInfo != null)
                    {
                        //添加VIP积分记录
                        VIPPointTrack pointTrack = new VIPPointTrack
                        {
                            CreateTime = DateTime.Now,
                            Point      = _vipInfo.PointTimes * ((int)Master.CostMoney),
                            VIPID      = _vipInfo.ID,
                            Remark     = "零售单产生,小票号" + Master.Code
                        };
                        lp.Add <VIPPointTrack>(pointTrack);
                        if (_vipUpgradeInfo != null)
                        {
                            var tactics = _vipUpgradeInfo.UpTactics.Where(o => o.IsChecked);
                            if (tactics != null && tactics.Count() > 0)
                            {
                                IEnumerable <int> kindIDs = tactics.Select(o => o.FormerKindID).ToList();
                                IEnumerable <VIPCardKindMapping> mappings = lp.Search <VIPCardKindMapping>(o => o.CardID == _vipInfo.ID && kindIDs.Contains(o.KindID)).ToList();
                                foreach (var mapping in mappings)
                                {
                                    var t = tactics.First(o => o.FormerKindID == mapping.KindID);
                                    mapping.KindID = t.AfterKindID;
                                    if (t.CutPoint != 0)
                                    {
                                        pointTrack = new VIPPointTrack
                                        {
                                            CreateTime = DateTime.Now,
                                            Point      = (-1 * t.CutPoint),
                                            VIPID      = _vipInfo.ID,
                                            Remark     = "VIP升级产生," + t.Description
                                        };
                                        lp.Add <VIPPointTrack>(pointTrack);
                                    }
                                }
                                lp.Update <VIPCardKindMapping>(mappings);
                            }
                        }
                        if (_vipInfo.IsBirthday && this._vipInfo.CostMoney != 0 && this._vipInfo.Quantity != 0)
                        {
                            lp.Delete <VIPBirthdayConsumption>(o => o.VIPID == _vipInfo.ID && o.ConsumeDay == DateTime.Now.Date);
                            lp.Add <VIPBirthdayConsumption>(new VIPBirthdayConsumption
                            {
                                VIPID      = _vipInfo.ID,
                                Quantity   = _vipInfo.Quantity,
                                CostMoney  = _vipInfo.CostMoney,
                                ConsumeDay = DateTime.Now.Date
                            });
                        }
                    }
                    scope.Complete();
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = e.Message
                    });
                }
            }
            var users = IMHelper.OnlineUsers.Where(o => o.OrganizationID == OrganizationListVM.CurrentOrganization.ParentID).ToArray();

            IMHelper.AsyncSendMessageTo(users, new IMessage
            {
                Message = string.Format("{2}销售{0}件,单号{1},金额{3:C}.", Details.Sum(o => o.Quantity), Master.Code, OrganizationListVM.CurrentOrganization.Name, Master.CostMoney)
            }, IMReceiveAccessEnum.零售单);
            return(new OPResult {
                IsSucceed = true
            });
        }