예제 #1
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/10/21 13:43:52</remarks>
        public bool Update(ShareManagerEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_ShareManager_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@ShareType", DbType.Int32, entity.ShareType);
            database.AddInParameter(commandWrapper, "@ShareNumber", DbType.Int32, entity.ShareNumber);
            database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Int32)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
예제 #2
0
        /// <summary>
        /// 将IDataReader的当前记录读取到ShareManagerEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public ShareManagerEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new ShareManagerEntity();

            obj.Idx         = (System.Int32)reader["Idx"];
            obj.ManagerId   = (System.Guid)reader["ManagerId"];
            obj.ShareType   = (System.Int32)reader["ShareType"];
            obj.ShareNumber = (System.Int32)reader["ShareNumber"];
            obj.UpdateTime  = (System.DateTime)reader["UpdateTime"];
            obj.RowTime     = (System.DateTime)reader["RowTime"];

            return(obj);
        }
예제 #3
0
 /// <summary>
 /// 刷新每日分享次数
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 private MessageCode RefreshRecord(ShareManagerEntity record, ConfigShareEntity config)
 {
     if (!config.IsRepetition)
     {
         return(MessageCode.Success);
     }
     record.ShareNumber = 0;
     record.UpdateTime  = DateTime.Now;
     if (ShareManagerMgr.Update(record))
     {
         return(MessageCode.Success);
     }
     return(MessageCode.NbUpdateFail);
 }
예제 #4
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>ShareManagerEntity</returns>
        /// <remarks>2016/10/21 13:43:52</remarks>
        public ShareManagerEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_ShareManager_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, idx);


            ShareManagerEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
예제 #5
0
 /// <summary>
 /// 分享游戏奖励(发放奖励)
 /// </summary>
 /// <param name="record"></param>
 /// <param name="mail"></param>
 /// <returns></returns>
 private MessageCode SavePrize(ShareManagerEntity record, MailBuilder mail)
 {
     using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
     {
         transactionManager.BeginTransaction();
         var messageCode = MessageCode.NbUpdateFail;
         do
         {
             if (record.Idx == 0)
             {
                 if (!ShareManagerMgr.Insert(record, transactionManager.TransactionObject))
                 {
                     break;
                 }
             }
             else
             {
                 if (!ShareManagerMgr.Update(record, transactionManager.TransactionObject))
                 {
                     break;
                 }
             }
             if (!mail.Save(transactionManager.TransactionObject))
             {
                 break;
             }
             messageCode = MessageCode.Success;
         } while (false);
         if (messageCode == MessageCode.Success)
         {
             transactionManager.Commit();
         }
         else
         {
             transactionManager.Rollback();
         }
     }
     return(MessageCode.Success);
 }
예제 #6
0
 /// <summary>
 /// 分享游戏奖励(分类)
 /// </summary>
 /// <param name="managerId"></param>
 /// <param name="shareType"></param>
 /// <returns></returns>
 public MessageCodeResponse DoShare(Guid managerId, int shareType)
 {
     try
     {
         DateTime date    = DateTime.Now;
         var      manager = NbManagerMgr.GetById(managerId);
         if (manager == null)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.MissManager));
         }
         var shareConfig = CacheFactory.ManagerDataCache.GetShare(shareType);
         if (shareConfig.Count <= 0)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
         }
         var entity = ShareManagerMgr.GetByManagerId(managerId, shareType);
         if (entity != null && !shareConfig[0].IsRepetition) //不可重复领取
         {
             TaskHandler.Instance.Share(managerId);
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.AlreadyShare));
         }
         if (entity != null && entity.ShareNumber >= shareConfig[0].MaxShareNumber)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.MaxShareNumber));
         }
         if (shareType == 1) //第一种特殊处理
         {
             if (entity != null)
             {
                 if (entity.ShareNumber > 0 && (date - entity.UpdateTime).Seconds < 3600)
                 {
                     return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NowShareNotPrize));
                 }
             }
         }
         int  point   = 0;
         int  coin    = 0;
         bool isFirst = false;
         if (entity == null) //首次分享
         {
             isFirst = true;
             entity  = new ShareManagerEntity(0, managerId, shareType, 1, date, date);
         }
         else
         {
             entity.ShareNumber++;
             entity.UpdateTime = date;
         }
         var itemList    = new Dictionary <int, int>();
         var messageCode = SendPrize(shareConfig, isFirst, ref itemList, ref point, ref coin);
         var mail        = new MailBuilder(managerId, point, coin, itemList, EnumMailType.Share);
         if (messageCode != MessageCode.Success)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(messageCode));
         }
         messageCode = SavePrize(entity, mail);
         return(ResponseHelper.Create <MessageCodeResponse>(messageCode));
     }
     catch (Exception ex)
     {
         SystemlogMgr.Error("分享游戏", ex);
         return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
     }
 }
예제 #7
0
        public static bool Update(ShareManagerEntity shareManagerEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new ShareManagerProvider(zoneId);

            return(provider.Update(shareManagerEntity, trans));
        }