Example #1
0
        public void InsertReward(int agencyId, int customerid, decimal?price, int orderid, decimal date, decimal prizeMoney)
        {
            var customer  = _customerDa.GetCustomerAwad(customerid);
            var bonusItem = _ordersDa.GetBonusTypeItem();
            var now       = DateTime.Now.TotalSeconds();

            //Tích lũy trực tiếp
            if (bonusItem.Percent > 0)
            {
                var reward = new RewardHistory
                {
                    Price      = price * (bonusItem.Percent / 100),
                    CustomerID = customerid,
                    Date       = now,
                    OrderID    = orderid,
                    Type       = (int)Reward.Cus,
                    Percent    = bonusItem.Percent,
                    IsDeleted  = false
                };
                var json = new JavaScriptSerializer().Serialize(reward);
                _rewardHistoryApi.AddRewardLocal(json);
                //_rewardHistoryDa.Add(reward);
            }
            //Tích lũy giới thiệu
            //if (customer.ParentID != null && customer.ParentID != bonusItem.RootID)
            //{
            //    var reward1 = new RewardHistory
            //    {
            //        Price = price * (bonusItem.PercentParent / 100),
            //        CustomerID = customer.ParentID,
            //        AgencyId = Agencyid(),
            //        Date = now,
            //        OrderID = orderid,
            //        Type = (int)Reward.Parent,
            //        Percent = bonusItem.PercentParent,
            //        IsDeleted = false
            //    };
            //    var json = new JavaScriptSerializer().Serialize(reward1);
            //    _rewardHistoryApi.AddRewardLocal(json);
            //    //_rewardHistoryDa.Add(reward1);
            //}
            //trừ tích lũy
            if (prizeMoney > 0)
            {
                var recive = new ReceiveHistory
                {
                    CustomerID = customerid,
                    AgencyId   = agencyId,
                    Price      = prizeMoney,
                    Date       = now,
                    OrderID    = orderid,
                    Type       = (int)Reward.Receive1,
                    IsDeleted  = false
                };
                //_rewardHistoryDa.Add();
                var json = new JavaScriptSerializer().Serialize(recive);
                _receiveHistoryApi.AddReciveLocal(json);
            }
            //_rewardHistoryDa.Save();
        }
Example #2
0
 private void Upgrade(OnRewardRedeemedArgs e, bool isExp, int sum)
 {
     using (var context = new AppDbContext())
     {
         var user = context.Users.GetByLogin(e.Login);
         if (user == null)
         {
             LogInfo(e);
             return;
         }
         if (isExp)
         {
             user.Experience += sum;
         }
         else
         {
             user.Money += sum;
         }
         var rewardHistory = new RewardHistory()
         {
             User   = user,
             Name   = e.RewardTitle,
             Guid   = e.RewardId,
             Cost   = e.RewardCost,
             Date   = DateTime.Now,
             FactUp = sum,
             IsExp  = isExp
         };
         context.RewardHistories.Add(rewardHistory);
         context.SaveChanges();
     }
 }
Example #3
0
        public void InsertRewardCheckBarcode(int cusId, decimal price, Guid id)
        {
            var reward = new RewardHistory
            {
                Price      = price,
                CustomerID = cusId,
                ImportID   = id,
                Date       = DateTime.Now.TotalSeconds(),
                Type       = (int)Reward.Cus,
                Percent    = 2,
                IsDeleted  = false
            };

            _rewardHistoryDa.Add(reward);
            _rewardHistoryDa.Save();
        }
Example #4
0
        public async Task <RewardHistory> CreateRewardAsync(CreateRewardRequest rewardRequest)
        {
            // validate target user exists
            var existUser = await _uow.UserRepository.GetAsync(rewardRequest.UserId);

            if (existUser == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "User");
            }

            // get/validate-exist reward type
            var rewardCategory = await _rewardCategoryService.GetRewardCategoryByCategoryAsync(rewardRequest.RewardCategoryEnum);

            var rewardAcomulate = await GetOrCreateRewardAcomulate(existUser, rewardCategory);

            var allowedPoints = 0;

            if (rewardCategory.Category == RewardCategoryEnum.SOLO_QUESTION_ANSWERED)
            {
                var data       = JsonConvert.DeserializeObject <RewardHistoryData>(rewardRequest.Data);
                var userAnswer = JsonConvert.DeserializeObject <UserSoloAnswerResponse>(data.Entity1);
                allowedPoints = userAnswer.Points;
            }
            else
            {
                allowedPoints = await AllowedPointsAsync(rewardCategory, rewardAcomulate, rewardRequest.IsPlus);
            }

            if (allowedPoints == 0)
            {
                return(null);
            }

            var rewardPoints = rewardRequest.IsPlus ? rewardCategory.PointsToIncrement : rewardCategory.PointsToDecrement;

            if (rewardCategory.Category == RewardCategoryEnum.SOLO_QUESTION_ANSWERED)
            {
                rewardPoints = allowedPoints;
            }

            var dbReward = new RewardHistory();

            dbReward.User           = existUser;
            dbReward.RewardCategory = rewardCategory;
            dbReward.IsPlus         = rewardRequest.IsPlus;
            dbReward.Points         = allowedPoints;
            dbReward.RewardPoints   = rewardPoints;
            dbReward.Data           = rewardRequest.Data;
            dbReward.CreatedAt      = DateTime.UtcNow;

            await _uow.RewardHistoryRepository.AddAsync(dbReward);

            allowedPoints              = rewardRequest.IsPlus ? allowedPoints : allowedPoints * -1;
            rewardAcomulate.Points     = rewardAcomulate.Points + allowedPoints;
            rewardAcomulate.ModifiedAt = DateTime.UtcNow;

            await _uow.RewardAcumulateRepository.UpdateAsync(rewardAcomulate, rewardAcomulate.Id);

            await _userStatisticsService.UpdateTotalPoints(existUser, allowedPoints);

            await _userStatisticsService.UpdateTotalCoinsAsync(existUser, allowedPoints);

            await _uow.CommitAsync();

            return(dbReward);
        }
Example #5
0
        public async Task <ActionResult> PaymentMoMoServer(dataItem item)
        {
            var refId     = Guid.NewGuid();
            var requestId = Guid.NewGuid();
            var model     = new HashMoMoItem
            {
                amount       = item.amount ?? 0,
                partnerRefId = refId.ToString(),
                partnerCode  = PartnerCode,
                //partnerName = "Công ty cổ phần công nghệ G-store",
                partnerTransId = DateTime.Now.TotalSeconds().ToString(),
                description    = item.description ?? "",
            };
            var json = new JavaScriptSerializer().Serialize(model);

            byte[] data   = Encoding.UTF8.GetBytes(json);
            string result = null;

            using (var rsa = new RSACryptoServiceProvider(4096)) //KeySize
            {
                try
                {
                    // MoMo's public key has format PEM.
                    // You must convert it to XML format. Recommend tool: https://superdry.apphb.com/tools/online-rsa-key-converter
                    rsa.FromXmlString(publickey);
                    var encryptedData   = rsa.Encrypt(data, false);
                    var base64Encrypted = Convert.ToBase64String(encryptedData);
                    result = base64Encrypted;
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
            var data1 = new ProcessMoMoItem
            {
                customerNumber = item.customerNumber ?? "",
                partnerCode    = PartnerCode,
                partnerRefId   = refId.ToString(),
                appData        = item.token ?? "",
                hash           = result,
                payType        = 3,
                description    = item.description ?? "",
                version        = 2
            };
            var                      url = Momo + "pay/app";
            ResultMoMoItem           kq;
            ResultDataMoMoAppIG4Item resutl;

            new ResultDataMoMoAppIG4Item();
            try
            {
                kq = await PostDataAsync <ResultMoMoItem>(url, data1);

                var requestType = "";
                var obj         = new ConfirmMoMoItem();
                if (kq.status == 0)
                {
                    obj.requestType = "capture";
                    requestType     = "capture";
                }
                else
                {
                    obj.requestType = "revertAuthorize";
                    requestType     = "revertAuthorize";
                }
                var    sign      = string.Format("partnerCode={0}&partnerRefId={1}&requestType={2}&requestId={3}&momoTransId={4}", PartnerCode, refId.ToString(), requestType, requestId.ToString(), kq.transid);
                string signature = signSHA256(sign, serectkey);
                obj.partnerCode    = PartnerCode;
                obj.partnerRefId   = refId.ToString();
                obj.customerNumber = item.customerNumber;
                obj.description    = item.description;
                obj.momoTransId    = kq.transid;
                obj.requestId      = requestId.ToString();
                obj.signature      = signature;
                var urlconfirm = Momo + "pay/confirm";
                try
                {
                    resutl = await PostDataAsync <ResultDataMoMoAppIG4Item>(urlconfirm, obj);

                    if (resutl.status == 0)
                    {
                        // thêm tiền vào ví chính
                        var wallet = new WalletCustomer
                        {
                            //Price = (decimal)resutl.data.amount,
                            TotalPrice     = (decimal)resutl.data.amount,
                            CustomerID     = item.CustomerId,
                            DateCreate     = DateTime.Now.TotalSeconds(),
                            IsDelete       = false,
                            IsActive       = true,
                            Note           = item.description,
                            Transaction_no = resutl.transid,
                            Type           = 1,
                        };
                        _walletCustomerDa.Add(wallet);
                        _walletCustomerDa.Save();
                        var gettoken = _customerDa.GetItemByID(item.CustomerId);
                        // % khuyến mãi vào ví thưởng.
                        var config = _walletCustomerDa.GetConfig();
                        var reward = new RewardHistory
                        {
                            CustomerID  = item.CustomerId,
                            Price       = config.Percent * ((decimal)resutl.data.amount) / 100,
                            IsActive    = true,
                            IsDeleted   = false,
                            Date        = DateTime.Now.TotalSeconds(),
                            WalletCusId = wallet.ID,
                            Type        = (int)Reward.Dep,
                            Percent     = config.Percent,
                        };
                        _rewardHistoryDa.Add(reward);
                        _rewardHistoryDa.Save();
                        var sucess = orderDA.GetNotifyById(4);
                        var token  = gettoken.tokenDevice;
                        Pushnotifycation(sucess.Title.Replace("{percent}", config.Percent.ToString()), sucess.Content.Replace("{price}", reward.Price.Money()).Replace("{total}", resutl.data.amount.MoneyDouble()), token, sucess.ID.ToString());
                    }
                    return(Json(resutl, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    resutl = new ResultDataMoMoAppIG4Item
                    {
                        status  = -1,
                        message = ex.ToString()
                    };
                    return(Json(resutl, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                resutl = new ResultDataMoMoAppIG4Item
                {
                    status  = -1,
                    message = ex.ToString()
                };
                return(Json(resutl, JsonRequestBehavior.AllowGet));
            }
        }
Example #6
0
 public void Delete(RewardHistory item)
 {
     FDIDB.RewardHistories.Remove(item);
 }
Example #7
0
 public void Add(RewardHistory item)
 {
     FDIDB.RewardHistories.Add(item);
 }
Example #8
0
        public void InsertRewardOrderPacket(CustomerAppIG4Item shop, ConfigExchange config, decimal?totalprice, int OrderId, List <BonusTypeItem> bonusItems, int type = 0, int idkho = 0, decimal discountKH = 60)
        {
            var now      = DateTime.Now.TotalSeconds();
            var today    = DateTime.Today.TotalSeconds();
            var totalD   = totalprice * config.DiscountOrderPacket / 100;
            var ltsArrId = FDIUtils.StringToListInt(shop.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,
                            DateCreate    = today,
                            OrderPacketID = OrderId,
                            Type          = (int)Reward.Packet,
                            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,
                DateCreate    = today,
                OrderPacketID = OrderId,
                Type          = (int)Reward.Packet,
                //BonusTypeId = i,
                Percent   = 100 - per,
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = shop.AgencyID,
                TotalCp   = totalD,
            };

            _rewardHistoryDa.Add(reward0);
            var reward1 = new RewardHistory
            {
                Price = totalprice * (100 - config.DiscountOrderPacket) / 100,
                //CustomerID = item.ID,
                Date          = now,
                DateCreate    = today,
                OrderPacketID = OrderId,
                Type          = (int)Reward.Packet,
                //BonusTypeId = i,
                Percent   = 100 - config.DiscountOrderPacket,
                IsDeleted = false,
                IsActive  = true,
                AgencyId  = 1006,
                TotalCp   = totalprice * (100 - config.DiscountOrderPacket) / 100,
            };

            _rewardHistoryDa.Add(reward1);
            _rewardHistoryDa.Save();
        }
Example #9
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();
        }