示例#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();
        }