예제 #1
0
 public void SaveUserIntegral(UserGetPrizeInfo info, IntegralExchangeType opraType)
 {
     try
     {
         var manage = new UserIntegralManager();
         UserIntegralBalance entity = manage.GetUserIntegralBalance(info.UserId);
         if (entity != null && !string.IsNullOrEmpty(entity.UserId)) //修改
         {
             if (opraType == IntegralExchangeType.IntegralIn)        //增加积分
             {
                 entity.CurrIntegralBalance += info.PayInegral;
                 manage.UpdateUserIntegralBalance(entity);
             }
             else if (opraType == IntegralExchangeType.IntegralOut)//兑换奖品
             {
                 if (info.PayInegral > entity.CurrIntegralBalance)
                 {
                     return;
                 }
                 ExchangePresent(info);
                 entity.CurrIntegralBalance -= info.PayInegral;
                 entity.UseIntegralBalance  += info.PayInegral;
                 manage.UpdateUserIntegralBalance(entity);//修改总的资金明细
             }
         }
         else//新增
         {
             if (opraType == IntegralExchangeType.IntegralIn)
             {
                 entity = new UserIntegralBalance();
                 entity.CurrIntegralBalance += info.PayInegral;
                 entity.UseIntegralBalance   = 0;
                 entity.CreateTime           = DateTime.Now;
                 entity.UserId = info.UserId;
                 manage.AddUserIntegralBalance(entity);
             }
             else
             {
                 throw new Exception("您还没有积分,不能兑换奖品或领取彩金!");
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }