/// <summary> /// 充值 /// </summary> /// <param name="userID"></param> /// <param name="points"></param> /// <returns></returns> public bool UpdatePointShow(AuthUser operatorUser, int addPoints, int price, string content, out PointShow pointShowInfo) { PointShowSettings settings = AllSettings.Current.PointShowSettings; pointShowInfo = null; int updateState = 4; if (addPoints < 0) { ThrowError(new CustomError("addPoints", "充值积分值不能小于0")); return(false); } if (price <= 0) { ThrowError(new InvalidPriceError("price", price.ToString())); return(false); } else { int price1, price2; price1 = settings.MinPrice; price2 = settings.MaxPrice; if (price < price1 || price > price2) { ThrowError(new CustomError("price", string.Format("单价必须在{0}~{1}之间", price1, price2))); return(false); } } if (addPoints > 0) { int userPointValue = operatorUser.ExtendedPoints[(int)settings.UsePointType]; if (userPointValue - addPoints < settings.PointBalance) { ThrowError(new PointBalanceLowError("addpoint", AllSettings.Current.PointSettings.GetUserPoint(settings.UsePointType).Name , settings.PointBalance)); return(false); } } if (addPoints > 0) { lock (operatorUser.UpdateUserPointLocker) { int[] Points = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; Points[(int)AllSettings.Current.PointShowSettings.UsePointType] = -Math.Abs(addPoints); if (!UserBO.Instance.UpdateUserPoint(operatorUser.UserID, true, true, Points, "竞价排名", "竞价排名充值")) { return(false); } } } updateState = PointShowDao.Instance.UpdatePointShow(operatorUser.UserID, addPoints, price, content, out pointShowInfo); if (updateState == -1) { ThrowError(new UserNotExistInPointShowError()); } else if (updateState == 1) { ThrowError(new InvalidPriceError("price", price.ToString())); } if (updateState == 0) { ClearTopUserShowsCache(); } return(updateState == 0); }
public bool CreatePointShow(AuthUser operatorUser, int pointcount, int price, string content, out PointShow pointShowInfo) { PointShowSettings settings = AllSettings.Current.PointShowSettings; pointShowInfo = null; if (pointcount <= 0) { ThrowError(new InvalidPointError("pointcount", pointcount.ToString())); return(false); } if (price <= 0 || price > pointcount) { ThrowError(new InvalidPriceError("price", price.ToString())); return(false); } else { int price1, price2; price1 = settings.MinPrice; price2 = settings.MaxPrice; if (price < price1 || price > price2) { ThrowError(new CustomError("price", string.Format("单价必须在{0}~{1}之间", price1, price2))); return(false); } } string bannedWord = string.Empty; if (AllSettings.Current.ContentKeywordSettings.BannedKeywords.IsMatch(content, out bannedWord)) { ThrowError(new CustomError("content", string.Format("上榜宣言包含被禁止的关键词:{0}", bannedWord))); return(false); } using (new ErrorScope()) { bool success = false; lock (operatorUser.UpdateUserPointLocker) { int userPointValue = operatorUser.ExtendedPoints[(int)settings.UsePointType]; if (userPointValue - pointcount < settings.PointBalance) { ThrowError(new PointBalanceLowError("pointcount", AllSettings.Current.PointSettings.GetUserPoint(settings.UsePointType).Name , settings.PointBalance)); return(false); } int[] Points = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; Points[(int)AllSettings.Current.PointShowSettings.UsePointType] = -Math.Abs(pointcount); success = UserBO.Instance.UpdateUserPoint(operatorUser.UserID, true, true, Points, "竞价排行", "竞价排名充值"); } if (success) { pointShowInfo = PointShowDao.Instance.CreatePointShow(operatorUser.UserID, pointcount, price, content); if (pointShowInfo != null) { FeedBO.Instance.CreateBidUpSelfFeed(operatorUser.UserID, pointcount, content); } ClearTopUserShowsCache(); } return(success); //bool success = PointShowPointAction.Instance.UpdateUserPointValue(userID, PointShowType.AddPointShow, -pointcount, delegate(PointActionManager.TryUpdateUserPointState state) //{ // if (state == PointActionManager.TryUpdateUserPointState.CheckSucceed) // { // } // else // return false; //}); } }