/// <summary> /// 更新一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(UserGift model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("update UserGift set "); strSql.Append("GiftID=@GiftID,GType=@GType,GiftFeeId=@GiftFeeId,Fee=@Fee,FeeType=@FeeType,BuyUserID=@BuyUserID,BuyTime=@BuyTime,BuyCount=@BuyCount,IsPay=@IsPay,LinkMan=@LinkMan,LinkTel=@LinkTel"); strSql.Append(" where UserGiftId=@UserGiftId"); SqlParameter[] parameters = { new SqlParameter("@GiftID", model.GiftID), new SqlParameter("@GType", model.GType), new SqlParameter("@GiftFeeId", model.GiftFeeId), new SqlParameter("@Fee", model.Fee), new SqlParameter("@FeeType", model.FeeType), new SqlParameter("@BuyUserID", model.BuyUserID), new SqlParameter("@BuyTime", model.BuyTime), new SqlParameter("@BuyCount", model.BuyCount), new SqlParameter("@IsPay", model.IsPay), new SqlParameter("@LinkMan", model.LinkMan), new SqlParameter("@LinkTel", model.LinkTel), new SqlParameter("@UserGiftId", model.UserGiftId) }; if (tran == null) { return(SqlHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters) > 0); } else { return(SqlHelper.ExecuteSql(tran, CommandType.Text, strSql.ToString(), parameters) > 0); } }
public void GenerateMakeGifts() { var repository = DependencyResolver.Current.GetService <IRepository>(); var users = repository.Users.OrderByDescending(p => p.ID).ToList(); var gifts = repository.Gifts.ToList(); foreach (var user in users) { var countGifts = rand.Next(2) + 1; for (int i = 0; i < countGifts; i++) { var gift = gifts.OrderBy(p => Guid.NewGuid()).FirstOrDefault(); var otherUser = users.Where(p => p.ID != user.ID).OrderBy(p => Guid.NewGuid()).FirstOrDefault(); var userGift = new UserGift() { SenderID = user.ID, ReceiverID = otherUser.ID, GiftID = gift.ID, Text = Textarium.GetRandomText(2), Visible = rand.Next(100) % 2 == 0 }; repository.CreateUserGift(userGift); Console.WriteLine("Человечек " + user.FirstName + " подарил подарок : " + otherUser.FirstName); } } Assert.AreEqual(0, 0); }
/// <summary> /// 添加一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(UserGift model, SqlTransaction tran = null) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into UserGift("); strSql.Append(" GiftID,GType,GiftFeeId,Fee,FeeType,BuyUserID,BuyTime,BuyCount,IsPay,LinkMan,LinkTel )"); strSql.Append(" values ("); strSql.Append("@GiftID,@GType,@GiftFeeId,@Fee,@FeeType,@BuyUserID,@BuyTime,@BuyCount,@IsPay,@LinkMan,@LinkTel);select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@GiftID", model.GiftID), new SqlParameter("@GType", model.GType), new SqlParameter("@GiftFeeId", model.GiftFeeId), new SqlParameter("@Fee", model.Fee), new SqlParameter("@FeeType", model.FeeType), new SqlParameter("@BuyUserID", model.BuyUserID), new SqlParameter("@BuyTime", model.BuyTime), new SqlParameter("@BuyCount", model.BuyCount), new SqlParameter("@IsPay", model.IsPay), new SqlParameter("@LinkMan", model.LinkMan), new SqlParameter("@LinkTel", model.LinkTel), }; 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(UserGift model, SqlTransaction tran) { ResultInfo ri = new ResultInfo(); if (Edit(model, tran)) { ri.Ok = true; ri.Msg = "修改成功"; } return(ri); }
private async void GiftDebouncedEvent(object sender, UserGift e) { ALog($"合并礼物: 来自 {e.User} ({e.UserId}) 的 {e.Qty} 个 {e.Gift},直接路由到礼物路线..."); var constructedArgs = new ReceivedMessageArgs(); constructedArgs.Message = new MessageModel(); constructedArgs.Message.GiftName = e.Gift; constructedArgs.Message.GiftCount = e.Qty; constructedArgs.Message.UserName = e.User; constructedArgs.Message.UserID = e.UserId; constructedArgs.Message.MsgType = MsgTypeEnum.GiftSend; await GiftRoute(null, constructedArgs); }
public async Task SelectGiftByUserAsync(Gift gift, ClaimsPrincipal user) { var appUser = await userService.FindUserByNameOrEmailAsync(user.Identity.Name); var userGift = new UserGift() { Gift = gift, BuyerUser = appUser }; await applicationDbContext.UserGifts.AddAsync(userGift); await applicationDbContext.SaveChangesAsync(); }
public ActionResult AddGift(List <GiftViewModel> tobeadded, int memberId) { var member = db.Users.Find(memberId); foreach (var gift in tobeadded) { var g = new UserGift() { GiftID = gift.GiftId, UserID = memberId, }; member.UserGifts.Add(g); } db.SaveChanges(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 保存 (可能有其他业务逻辑检查) /// </summary> /// <param name="model">实体</param> /// <returns></returns> public ResultInfo Create(UserGift 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); }
public ActionResult Pay(decimal fee, string desc, List <UserJoinItemViewModel> joinItems, long id = 0, int type = 0, int count = 1) { ResultInfo ri = new ResultInfo(); int result = 0; string seq = string.Empty; string returnUri = string.Empty; JoinItemTypeEnum jointype = JoinItemTypeEnum.None; try { BeginTran(); long buyItemID = 0; var now = DateTime.Now; #region 校验 if (fee <= 0) { ri.Msg = "金额不正常(如何支付为0的金额呢?),请刷新页面重试"; return(Result(ri)); } if (type == 0) { ri.Msg = "支付异常,请刷新页面重试"; return(Result(ri)); } if (type == 1) { if (id == 0) { seq = "CZ"; returnUri = "http://www.baixiaotangtop.com/User"; } else { ri.Msg = "支付异常,请刷新页面重试"; return(Result(ri)); } } else { if (id == 0) { ri.Msg = "支付异常,请刷新页面重试"; return(Result(ri)); } if (type == 2) { #region 礼物、课程、数据相关逻辑 //先根据ID获取费用信息 var feeInfo = GiftFeeBLL.Instance.GetModel(id); if (feeInfo != null) { long giftId = GetRequest <long>("mid"); if (giftId != feeInfo.GiftID) { ri.Msg = "商品信息不正确!"; return(Result(ri)); } if (feeInfo.FeeType != 30) { ri.Msg = "商品价格信息有误!"; return(Result(ri)); } else if (feeInfo.Fee != fee) { ri.Msg = "商品价格被篡改,请刷新页面重新支付"; return(Result(ri)); } if (feeInfo.FeeCount > 0) { if (feeInfo.FeeCount >= count) { id = giftId; returnUri = "http://www.baixiaotangtop.com/gift/detail/{0}".FormatWith(id); Gift gift = GiftBLL.Instance.GetModel(giftId); if (gift != null) { #region 创建购买商品信息 string linkMan = GetRequest("LinkMan"); string linktel = GetRequest("LinkTel"); UserGift buygift = new UserGift() { BuyCount = count, BuyTime = now, BuyUserID = UserID, Fee = feeInfo.Fee * count, FeeType = feeInfo.FeeType, GiftFeeId = feeInfo.GiftFeeId, GiftID = giftId, GType = gift.GType, IsPay = 0, }; if (linkMan.IsNotNullOrEmpty()) { buygift.LinkMan = linkMan; } if (linktel.IsNotNullOrEmpty()) { buygift.LinkTel = linktel; } if ((buyItemID = UserGiftBLL.Instance.Add(buygift, Tran)) < 1) { RollBack(); ri.Msg = "创建订单失败!"; return(Result(ri)); } if (gift.GType == 1) { seq = "LP"; jointype = JoinItemTypeEnum.Gift; } else if (gift.GType == 2) { seq = "SJ"; type = 4; jointype = JoinItemTypeEnum.DataAnalysis; } else { seq = "KC"; type = 8; jointype = JoinItemTypeEnum.KeCheng; } #endregion } else { ri.Msg = "商品不存在"; return(Result(ri)); } } else { ri.Msg = "当前余票不足{0}份,请重新选择数量!".FormatWith(count); return(Result(ri)); } } else { ri.Msg = "该票种已无余票!请购买其它票种或联系主办方!"; return(Result(ri)); } } else { ri.Msg = "商品不存在"; return(Result(ri)); } #endregion } else { #region 活动相关逻辑 seq = "HD"; jointype = JoinItemTypeEnum.Party; ActivityFee activityfee = ActivityFeeBLL.Instance.GetModel(id); if (activityfee != null) { long activityId = GetRequest <long>("mid"); if (activityId != activityfee.ActivityId) { ri.Msg = "活动信息不正确!"; return(Result(ri)); } if (activityfee.FeeType != 30) { ri.Msg = "活动价格信息有误!"; return(Result(ri)); } else if (activityfee.Fee != fee) { ri.Msg = "活动价格被篡改,请刷新页面重新支付"; return(Result(ri)); } if (activityfee.FeeCount > 0) { if (activityfee.FeeCount >= count) { #region 判断活动是否能够报名 Activity party = ActivityBLL.Instance.GetModel(activityId); if (party != null && party.IsDelete == 0) { if (!ActivityBLL.Instance.CanJoinParty(party).Ok) { return(Result(ri)); } } else { ri.Msg = "活动不存在!"; return(Result(ri)); } #endregion id = activityId; returnUri = "http://www.baixiaotangtop.com/party/detail/{0}".FormatWith(id); #region 创建报名活动信息 string linkMan = GetRequest("LinkMan"); string linktel = GetRequest("LinkTel"); ActivityJoin ajoin = new ActivityJoin(); ajoin.ActivityId = activityId; ajoin.FeeType = activityfee.FeeType; ajoin.IsFeed = 0; ajoin.RealPayFee = activityfee.Fee * count; ajoin.JoinCount = count; ajoin.JoinTime = now; ajoin.JoinUserID = UserID; ajoin.JoinUserName = UserInfo.UserName; ajoin.ActivityFeeId = activityfee.ActivityFeeId; if (linkMan.IsNotNullOrEmpty()) { ajoin.LinkMan = linkMan; } if (linktel.IsNotNullOrEmpty()) { ajoin.LinkTel = linktel; } if ((buyItemID = ActivityJoinBLL.Instance.Add(ajoin, Tran)) < 1) { RollBack(); ri.Msg = "创建订单失败!"; return(Result(ri)); } } else { ri.Msg = "当前余票不足{0}份,请重新选择数量!".FormatWith(count); return(Result(ri)); } } else { ri.Msg = "该票种已无余票!请购买其它票种或联系主办方!"; return(Result(ri)); } #endregion } else { ri.Msg = "活动不存在"; return(Result(ri)); } #endregion } } #endregion #region 记录报名填写项 bool insertOk = true; //记录报名填写项 if (joinItems != null && joinItems.Count > 0) { foreach (var join in joinItems) { JoinItemAnswerExt model = new JoinItemAnswerExt() { BuyerID = UserID, CreateTime = now, ItemAnswer = join.Value, JoinItemQuestionExtId = join.Id, JoinMainID = id, JoinType = jointype.GetHashCode() }; if (JoinItemAnswerExtBLL.Instance.Add(model, Tran) <= 0) { insertOk = false; break; } } } if (!insertOk) { RollBack(); ri.Msg = "创建订单失败!"; return(Result(ri)); } #endregion #region 创建订单 string payOrderID = string.Empty; string _msg_ = _orderService.CreateOrder(UserID, fee, id, type, desc, seq, count, now, Tran, out result, out payOrderID); if (result < 1) { ri.Msg = _msg_; RollBack(); return(Result(ri)); } #endregion //记录用户购买单号 SessionHelper.Set(payOrderID, buyItemID); #region 跳转支付 ri = Redirect2Pay(desc, fee * count, payOrderID, returnUri, ConfigHelper.AppSettings("AliPayNotify")); if (ri.Ok) { Commit(); } else { RollBack(); } #endregion } catch { RollBack(); ri.Msg = "支付异常,请重试!"; } return(Result(ri)); }
public ActionResult Submit(long id, int fee, long feeid, int count, string LinkMan, string LinkTel, List <UserJoinItemViewModel> JoinItems) { ResultInfo ri = new ResultInfo(); if (id > 0) { //获取礼物详情 var model = GiftBLL.Instance.GetDetail(id, UserID, JoinItemTypeEnum.Gift, false); if (model != null) { BeginTran(); #region 获取购买费用 List <GiftFee> feelist = model.FeeList; var feeInfo = feelist.FirstOrDefault(a => { return(a.GiftFeeId == feeid && a.Fee == fee); }); #endregion if (feeInfo != null) { if (feeInfo.FeeCount > 0) { if (feeInfo.FeeCount >= count) { //判断是否需要扣费 int coinType = feeInfo.FeeType == 10 ? 1 : feeInfo.FeeType == 20 ? 2 : 0; int coin = Convert.ToInt32(feeInfo.Fee.Value) * count; bool canJoin = true; if (fee != 0) { //判断积分是否足够 canJoin = UserExtBLL.Instance.HasEnoughCoin(coinType, coin, UserID); } if (canJoin) { UserGift buyModel = new UserGift() { BuyCount = count, BuyTime = DateTime.Now, BuyUserID = UserID, Fee = coin, FeeType = feeInfo.FeeType, GiftFeeId = feeInfo.GiftFeeId, GiftID = model.GiftID, GType = model.GType, IsPay = 1, }; if (LinkMan.IsNotNullOrEmpty()) { buyModel.LinkMan = LinkMan; } if (LinkTel.IsNotNullOrEmpty()) { buyModel.LinkTel = LinkTel; } var usergiftId = 0; if ((usergiftId = UserGiftBLL.Instance.Add(buyModel, Tran)) > 0) { bool insertOk = true; if (JoinItems != null && JoinItems.Count > 0) { foreach (var join in JoinItems) { JoinItemAnswerExt joinModel = new JoinItemAnswerExt() { BuyerID = UserID, CreateTime = DateTime.Now, ItemAnswer = join.Value, JoinItemQuestionExtId = join.Id, JoinMainID = model.GiftID, JoinType = (model.GType == 1 ? JoinItemTypeEnum.Gift : model.GType == 2 ? JoinItemTypeEnum.DataAnalysis : JoinItemTypeEnum.KeCheng).GetHashCode() }; if (JoinItemAnswerExtBLL.Instance.Add(joinModel, Tran) <= 0) { insertOk = false; break; } } } if (insertOk) { //更新剩余名额 feeInfo.FeeCount -= count; if (GiftFeeBLL.Instance.Update(feeInfo, Tran).Ok) { var ordertype = (model.GType == 1 ? OrderEnumType.Gift : model.GType == 2 ? OrderEnumType.Data : OrderEnumType.KeCheng).GetHashCode(); string orderDesc = GetRequest("desc", "购买" + model.GiftName); //添加订单 //int _orderResult = 0; //string _orderNo = string.Empty; //var addOrder = _orderService.CreateOrder(UserID, fee, id, ordertype, orderDesc, model.GType == 1 ? "LP" : model.GType == 2 ? "SJ" : "KC", count, Tran, out _orderResult, out _orderNo); //if (_orderResult > 0) //{ if (fee == 0) { var auto = _autoSendService.AutoSendReply(UserID, ordertype, usergiftId, id); if (auto.Item1) { Commit(); ri.Msg = "购买成功,待发货产品将由管理员发出,请在个人中心查看我的订单"; ri.Ok = true; ri.Data = auto.Item2; } else { ri.Msg = "购买失败"; RollBack(); } } else { //购买成功 //扣除相应数据 //用户帐户减去相应的积分或金钱 if (UserExtBLL.Instance.SubScore(UserID, coin, coinType, Tran)) { if (ScoreCoinLogBLL.Instance.Log(-coin, coinType, CoinSourceEnum.BuyGift, UserID, UserInfo.UserName, Tran)) { var auto = _autoSendService.AutoSendReply(UserID, ordertype, usergiftId, id); if (auto.Item1) { Commit(); ri.Ok = true; ri.Msg = "购买成功,待发货产品将由管理员发出,请在个人中心查看我的订单"; ri.Data = auto.Item2; } else { ri.Msg = "购买失败"; RollBack(); } } else { ri.Msg = "购买失败"; RollBack(); } } else { ri.Msg = "购买失败"; RollBack(); } } if (ri.Ok) { //通知 NoticeBLL.Instance.OnBuySuccess_Notice_Buyer(UserID, DateTime.Now, fee == 0 ? true : false, "{0}{1}".FormatWith(coin, feeInfo.FeeType == 10 ? "积分" : feeInfo.FeeType == 20 ? "VIP分" : string.Empty), count, ConfigHelper.AppSettings("GiftDetail").FormatWith(id), model.GiftName, true, NoticeTypeEnum.Gift_Buy); } //} //else //{ // RollBack(); // ri.Msg = addOrder; //} } else { RollBack(); } } else { RollBack(); } } else { RollBack(); } } else { ri.Msg = "你的积分不足以购买此礼物"; } } else { ri.Type = 1; ri.Msg = "当前余票不足{0}份,请重新选择数量!".FormatWith(count); } } else { ri.Msg = "该票种已无余票!请购买其它票种或联系主办方!"; } } else { ri.Msg = "费用异常!"; } } else { ri.Msg = "该礼物不存在"; } } return(Result(ri)); }
/// <summary> /// 修改一条记录 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public bool Edit(UserGift model, SqlTransaction tran = null) { return(dal.Update(model, tran)); }
/// <summary> /// 添加一条记录,没有任何逻辑 /// </summary> /// <param name="model">实体对象</param> /// <returns></returns> public int Add(UserGift model, SqlTransaction tran = null) { return(dal.Add(model, tran)); }