/// <summary> /// 更新一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(ScoreCoinLog model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ScoreCoinLog set "); strSql.Append("UserID=@UserID,UserName=@UserName,CoinType=@CoinType,Coin=@Coin,CoinSource=@CoinSource,CoinTime=@CoinTime,CreateUser=@CreateUser"); strSql.Append(" where ScoreCoinLogId=@ScoreCoinLogId"); SqlParameter[] parameters = { new SqlParameter("@UserID", model.UserID), new SqlParameter("@UserName", model.UserName), new SqlParameter("@CoinType", model.CoinType), new SqlParameter("@Coin", model.Coin), new SqlParameter("@CoinSource", model.CoinSource), new SqlParameter("@CoinTime", model.CoinTime), new SqlParameter("@CreateUser", model.CreateUser), new SqlParameter("@ScoreCoinLogId", model.ScoreCoinLogId) }; if (tran == null) { return(SqlHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters) > 0); } else { return(SqlHelper.ExecuteSql(tran, CommandType.Text, strSql.ToString(), parameters) > 0); } }
/// <summary> /// 添加一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(ScoreCoinLog model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ScoreCoinLog("); strSql.Append(" UserID,UserName,CoinType,Coin,CoinSource,CoinTime,CreateUser )"); strSql.Append(" values ("); strSql.Append("@UserID,@UserName,@CoinType,@Coin,@CoinSource,@CoinTime,@CreateUser)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserID", model.UserID), new SqlParameter("@UserName", model.UserName), new SqlParameter("@CoinType", model.CoinType), new SqlParameter("@Coin", model.Coin), new SqlParameter("@CoinSource", model.CoinSource), new SqlParameter("@CoinTime", model.CoinTime), new SqlParameter("@CreateUser", model.CreateUser), }; object obj; if (tran == null) { obj = SqlHelper.GetSingle(strSql.ToString(), CommandType.Text, parameters); } else { obj = SqlHelper.GetSingle(tran, CommandType.Text, strSql.ToString(), parameters); } return(obj == null ? 0 : Convert.ToInt32(obj)); }
/// <summary> /// 修改 (可能有其他业务逻辑检查) /// </summary> /// <param name="model"></param> /// <returns></returns> public ResultInfo Update(ScoreCoinLog model, SqlTransaction tran = null) { ResultInfo ri = new ResultInfo(); if (Edit(model, tran)) { ri.Ok = true; ri.Msg = "修改成功"; } return(ri); }
/// <summary> /// 记录消费积分/VIP分的流水 /// </summary> public bool Log(int coin, int coinType, CoinSourceEnum coinSource, long feeUserID, string feeUserName, SqlTransaction tran, long createUser = 0) { ScoreCoinLog model = new ScoreCoinLog() { Coin = coin, UserID = feeUserID, CoinSource = coinSource.GetHashCode(), CoinTime = DateTime.Now, CoinType = coinType, CreateUser = createUser == 0 ? feeUserID.ToString() : createUser.ToString(), UserName = feeUserName }; return(ScoreCoinLogBLL.Instance.Add(model, tran) > 0); }
/// <summary> /// 判断用户是否拥有足够的积分/VIP分 ,并扣除相应金钱 并记录消费流水 /// </summary> /// <param name="type">1积分 2金钱/VIP分</param> /// <param name="coin">数量</param> /// <param name="userID">用户ID</param> /// <param name="coinSourceEnum">coinSourceEnum</param> /// <param name="needSave">是否保存DBContext</param> /// <returns></returns> public Tuple <bool, string> HasEnoughCoinAndSubCoin(int type, int coin, long userID, CoinSourceEnum coinSourceEnum, bool needSave = false) { bool ok = false; string msg = string.Empty; var ext = _amazonBBSDBContext.UserExt.FirstOrDefault(a => a.UserID == userID); if (type == 1) { ok = ext.TotalScore >= coin; } else { ok = ext.TotalCoin >= coin; } if (ok) { //扣除 if (type == 1) { ext.TotalScore -= coin; } else { ext.TotalCoin -= coin; } //记录流水 ScoreCoinLog scorecoinlog = new ScoreCoinLog() { UserID = userID, Coin = -coin, CoinSource = coinSourceEnum.GetHashCode(), CoinTime = DateTime.Now, CoinType = type, CreateUser = userID.ToString(), UserName = _amazonBBSDBContext.UserBase.FirstOrDefault(a => a.UserID == userID).UserName, }; _amazonBBSDBContext.ScoreCoinLog.Add(scorecoinlog); if (needSave) { _amazonBBSDBContext.SaveChanges(); } } else { msg = $"你的{(type == 1 ? "积分" : "金钱")}不足够"; } return(new Tuple <bool, string>(ok, msg)); }
/// <summary> /// 保存 (可能有其他业务逻辑检查) /// </summary> /// <param name="model">实体</param> /// <returns></returns> public ResultInfo Create(ScoreCoinLog model, SqlTransaction tran = null) { ResultInfo ri = new ResultInfo(); if (model == null) { return(ri); } int result = Add(model, tran); if (result > 0) { ri.Ok = true; ri.Msg = "添加成功"; } return(ri); }
//[HttpPost] public void AliPayNotify(string requestParams) { string result = PayCallBack(order => { BeginTran(); long payUserId = order.CreateUser.ToInt64(); var orderPayTime = order.CreateTime.Value; //VIP分充值 if (order.OrderType == 1) { //VIP分充值 //获取充值比例 int vipFee = Convert.ToInt32(ConfigHelper.AppSettings("vipScorePayByRMB")) * Convert.ToInt32(order.Fee); //order.Fee* vipscoreConfig //vipscoreConfig = 10; if (UserExtBLL.Instance.AddScore(payUserId, vipFee, 2)) { //记录流水 //记录变更明细 ScoreCoinLog sclModel = new ScoreCoinLog() { Coin = vipFee, CoinSource = CoinSourceEnum.VipScorePay.GetHashCode(), CoinTime = DateTime.Now, CoinType = 2, CreateUser = "******", UserID = payUserId, UserName = UserInfo.UserName, }; if (ScoreCoinLogBLL.Instance.Add(sclModel, Tran) > 0) { Commit(); NoticeBLL.Instance.OnPayVIPScoreSuccess_Notice_User(payUserId, orderPayTime, vipFee.ToString(), NoticeTypeEnum.PayVipScore); } else { RollBack(); } } else { RollBack(); } } else { //参加活动、购买礼物等等 //更新相应商品的数量 if (UpdateCount(order, Tran)) { object userBuyItemID = SessionHelper.Get(order.PayOrderID); if (userBuyItemID == null) { if (order.OrderType == 2 || order.OrderType == 4 || order.OrderType == 8) { userBuyItemID = UserGiftBLL.Instance.GetUserBuyItemID(order.Fee, order.BuyCount, order.CreateUser, Tran); } } var auto = _autoSendService.AutoSendReply(payUserId, order.OrderType.Value, (long)userBuyItemID, order.ItemID.Value); if (auto.Item1) { Commit(); #region 通知 bool buyorjoin = false; var noticeType = NoticeTypeEnum.None; string mainName = string.Empty; string mainUrl = GetDomainName; if (order.OrderType == 3) { //活动 var model = ActivityBLL.Instance.GetModel(order.ItemID.Value); mainName = model.Title; noticeType = NoticeTypeEnum.Party_Join; mainUrl += ConfigHelper.AppSettings("PartyDetail").FormatWith(order.ItemID); } else { //order.OrderType == 3 4 8 礼物 数据 课程 var model = GiftBLL.Instance.GetModel(order.ItemID.Value); mainName = model.GiftName; buyorjoin = true; noticeType = order.OrderType == 2 ? NoticeTypeEnum.Gift_Buy : order.OrderType == 4 ? NoticeTypeEnum.DatAnalysis_Buy : NoticeTypeEnum.KeCheng_Buy; mainUrl += ConfigHelper.AppSettings("GiftDetail").FormatWith(order.ItemID); } //通知用户 NoticeBLL.Instance.OnBuySuccess_Notice_Buyer(payUserId, orderPayTime, false, "{0}元".FormatWith(order.Fee), order.BuyCount.Value, mainUrl, mainName, buyorjoin, noticeType); #endregion } else { RollBack(); } } else { RollBack(); } } }, requestParams); Response.Write(result); }
/// <summary> /// 修改一条记录 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public bool Edit(ScoreCoinLog model, SqlTransaction tran = null) { return(dal.Update(model, tran)); }
/// <summary> /// 添加一条记录,没有任何逻辑 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public int Add(ScoreCoinLog model, SqlTransaction tran = null) { return(dal.Add(model, tran)); }