Beispiel #1
0
        public void InsertRewardOrderCustomer(CustomerAppIG4Item customer, ConfigExchange config, decimal?totalprice, int OrderId, List <BonusTypeItem> bonusItems, int type = 0, int idkho = 0, decimal discountKH = 60)
        {
            var now = DateTime.Now.TotalSeconds();
            //hoa hong cho shop ky gui
            //if (type == 2)
            //{
            //    // chinh sach them cho don hang ban tu kho.
            //    var customer = _customerDa.GetItemByID(idkho);
            //    var bonusItem = bonusItems.FirstOrDefault(m => m.ID == 1);
            //    if (bonusItem != null)
            //    {
            //        var reward = new RewardHistory
            //        {
            //            Price = (totalprice ?? 0) * (bonusItem.Percent / 100),
            //            CustomerID = customer.ID,
            //            Date = now,
            //            OrderID = OrderId,
            //            Type = (int)Reward.Kho,
            //            BonusTypeId = 1,
            //            Percent = bonusItem.Percent,
            //            IsDeleted = false,
            //            IsActive = true,
            //            AgencyId = 1006,
            //            TotalCp = totalprice,
            //        };
            //        _rewardHistoryDa.Add(reward);
            //        var shopsucess = _orderDa.GetNotifyById(9);
            //        var tokenshop = customer.tokenDevice;
            //        Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", reward.Price.Money()), tokenshop);
            //    }
            //    var listcustomer = _customerDa.GetItemByID(parentId);
            //    var bonusItemparent = bonusItems.FirstOrDefault(m => m.ID == 2);
            //    if (bonusItemparent != null)
            //    {
            //        var reward = new RewardHistory
            //        {
            //            Price = (totalprice ?? 0) * (bonusItemparent.Percent / 100),
            //            CustomerID = listcustomer.ID,
            //            Date = now,
            //            OrderID = OrderId,
            //            Type = (int)Reward.Kho,
            //            BonusTypeId = 2,
            //            Percent = bonusItemparent.Percent,
            //            IsDeleted = false,
            //            IsActive = true,
            //            AgencyId = 1006,
            //            TotalCp = totalprice,
            //        };
            //        _rewardHistoryDa.Add(reward);
            //        var shopsucess = _orderDa.GetNotifyById(9);
            //        var tokenshop = listcustomer.tokenDevice;
            //        Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", reward.Price.Money()), tokenshop);
            //    }
            //    var bonusItemroot = bonusItems.FirstOrDefault(m => m.ID == 3);
            //    if (bonusItemroot != null)
            //    {
            //        var reward = new RewardHistory
            //        {
            //            Price = (totalprice ?? 0) * (bonusItemroot.Percent / 100),
            //            CustomerID = 1,
            //            Date = now,
            //            OrderID = OrderId,
            //            Type = (int)Reward.Kho,
            //            BonusTypeId = 3,
            //            Percent = bonusItemroot.Percent,
            //            IsDeleted = false,
            //            IsActive = true,
            //            AgencyId = 1006,
            //            TotalCp = totalprice,
            //        };
            //        _rewardHistoryDa.Add(reward);
            //        //var shopsucess = _orderDa.GetNotifyById(9);
            //        //var tokenshop = root.tokenDevice;
            //        //Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", reward.Price.Money()), tokenshop);
            //    }
            //    _rewardHistoryDa.Save();
            //}
            //else
            //{
            var totalD   = totalprice * config.DiscountCTV / 100;
            var ltsArrId = FDIUtils.StringToListInt(customer.ListAgencyId);

            ltsArrId = ltsArrId.Take(bonusItems.Count).ToList();
            var     listcustomer = _agencyDa.GetListAgencyListID(ltsArrId);
            decimal per          = 0;
            var     i            = 1;

            foreach (var item in listcustomer)
            {
                if (i <= bonusItems.Count)
                {
                    //if (item.LevelAdd >= i)
                    //{
                    var bonusItem = bonusItems.FirstOrDefault(m => m.ID == i);
                    if (bonusItem != null)
                    {
                        var reward = new RewardHistory
                        {
                            Price = totalD * (bonusItem.Percent / 100),
                            //CustomerID = item.ID,
                            Date        = now,
                            OrderID     = OrderId,
                            Type        = (int)Reward.Cus,
                            BonusTypeId = i,
                            Percent     = bonusItem.Percent,
                            IsDeleted   = false,
                            IsActive    = true,
                            AgencyId    = item.ID,
                            TotalCp     = totalD,
                        };
                        _rewardHistoryDa.Add(reward);
                        //var cus = _customerDa.GetItemByID(item.ID);
                        //var shopsucess = _orderDa.GetNotifyById(6);
                        //var tokenshop = cus.tokenDevice;
                        //Pushnotifycation(shopsucess.Title, shopsucess.Content.Replace("{price}", reward.Price.Money().Replace("{hoahong}", bonusItem.Name).Replace("{customer}", item.Fullname)), tokenshop);
                        per += bonusItem.Percent ?? 0;
                    }
                    //}
                }
                i++;
            }
            var reward0 = new RewardHistory
            {
                Price = totalD * ((100 - per) / 100),
                //CustomerID = item.ID,
                Date        = now,
                OrderID     = OrderId,
                Type        = (int)Reward.Cus,
                BonusTypeId = i,
                Percent     = 100 - per,
                IsDeleted   = false,
                IsActive    = true,
                AgencyId    = customer.AgencyID,
                TotalCp     = totalD,
            };

            _rewardHistoryDa.Add(reward0);
            //}

            // % chiết khấu cho công ty
            var reward1 = new RewardHistory
            {
                Price      = (totalprice ?? 0) * config.DiscountOrder / 100,
                CustomerID = 1,
                Date       = now,
                OrderID    = OrderId,
                Type       = (int)Reward.Cus,
                //BonusTypeId = i,
                Percent   = config.DiscountOrder,
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = 1006,
                TotalCp   = totalprice,
            };

            _rewardHistoryDa.Add(reward1);
            // % chiết khấu cho mã QR truy xuất nguồn gốc
            var reward2 = new RewardHistory
            {
                Price      = (totalprice ?? 0) * config.DiscountQR / 100,
                CustomerID = 1,
                Date       = now,
                OrderID    = OrderId,
                Type       = (int)Reward.QR,
                //BonusTypeId = i,
                Percent   = config.DiscountQR,
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = 1006,
                TotalCp   = totalprice,
            };

            _rewardHistoryDa.Add(reward2);
            // % chiết khấu cho quỹ khuyến mãi KH
            var reward3 = new RewardHistory
            {
                Price      = (totalprice ?? 0) * config.DiscountSale / 100,
                CustomerID = 1,
                Date       = now,
                OrderID    = OrderId,
                Type       = (int)Reward.Sale,
                //BonusTypeId = i,
                Percent   = config.DiscountSale,
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = 1006,
                TotalCp   = totalprice,
            };

            _rewardHistoryDa.Add(reward3);

            // % phát triển cty
            var reward4 = new RewardHistory
            {
                Price      = (totalprice ?? 0) * (100 - discountKH - config.DiscountQR - config.DiscountOrder - config.DiscountSale - config.DiscountCTV - config.DiscountOrderAgency) / 100,
                CustomerID = 1,
                Date       = now,
                OrderID    = OrderId,
                Type       = (int)Reward.Depvelop,
                //BonusTypeId = i,
                Percent   = (100 - discountKH - config.DiscountQR - config.DiscountOrder - config.DiscountSale - config.DiscountCTV - config.DiscountOrderAgency),
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = 1006,
                TotalCp   = totalprice,
            };

            _rewardHistoryDa.Add(reward4);
            _rewardHistoryDa.Save();
        }