public ActionResult Order([Bind(Include = "Title,Cash,UserId,Remark")] Order order) { order.OrderTime = DateTime.Now; var u = db.Users.AsNoTracking().FirstOrDefault(m => m.Id == order.UserId); if (u == null) { return(View()); } order.UserName = u.UserName; using (var context = new SeEntities()) using (var trans = context.Database.BeginTransaction()) { #region 第一代 if (u.ParentId > 0)//有上级 { User u1 = context.Users.FirstOrDefault(m => m.Id == u.ParentId); if (u1 != null) { BonusLog bonusLog1 = new BonusLog { UserName = u.UserName, UserId = u.Id, ToUserName = u1.UserName, ToUserId = u1.Id, BonusTime = DateTime.Now, BonusType = (int)BonusType.推荐奖, Cash = 900, OldCash = u1.Bonus, NewCash = u1.Bonus + 900, Remark = $"直推1代{u.UserName}->{u1.UserName}", }; u1.Bonus = bonusLog1.NewCash; context.BonusLogs.Add(bonusLog1); #region 第二代 if (u1.ParentId > 0) { User u2 = context.Users.FirstOrDefault(m => m.Id == u1.ParentId); if (u2 != null) { BonusLog bonusLog2 = new BonusLog { UserName = u1.UserName, UserId = u1.Id, ToUserName = u2.UserName, ToUserId = u2.Id, BonusTime = DateTime.Now, BonusType = (int)BonusType.推荐奖, Cash = 700, OldCash = u2.Bonus, NewCash = u2.Bonus + 700, Remark = $"直推2代{u.UserName}->{u1.UserName}->{u2.UserName}", }; u2.Bonus = bonusLog2.NewCash; context.BonusLogs.Add(bonusLog2); #region 第三代 if (u2.ParentId > 0) { User u3 = context.Users.FirstOrDefault(m => m.Id == u2.ParentId); if (u3 != null) { BonusLog bonusLog3 = new BonusLog { UserName = u2.UserName, UserId = u2.Id, ToUserName = u3.UserName, ToUserId = u3.Id, BonusTime = DateTime.Now, BonusType = (int)BonusType.推荐奖, Cash = 700, OldCash = u3.Bonus, NewCash = u3.Bonus + 700, Remark = $"直推3代{u.UserName}->{u1.UserName}->{u2.UserName}->{u3.UserName}", }; u3.Bonus = bonusLog3.NewCash; context.BonusLogs.Add(bonusLog3); } } #endregion } } #endregion } } #endregion context.Orders.Add(order); try { context.SaveChanges(); trans.Commit(); } catch { trans.Rollback(); } } return(RedirectToAction("OrderList")); }
protected override void ShowPage() { this.topic = base.GetTopicInfo(); if (this.topic == null) { return; } this.topicid = this.topic.ID; this.forumid = this.topic.Fid; this.forum = Forums.GetForumInfo(this.forumid); if (this.forum == null) { base.AddErrLine("不存在的版块ID"); return; } if (!base.ValidateInfo() || base.IsErr()) { return; } base.IsModer(); int topicPrice = this.GetTopicPrice(this.topic); if (this.topic.Special == 0 && topicPrice > 0) { HttpContext.Current.Response.Redirect(this.forumpath + "buytopic.aspx?topicid=" + this.topic.ID); return; } if (this.postid > 0 && Post.FindByID(this.postid) == null) { base.AddErrLine("该帖可能已被删除 " + string.Format("<a href=\"{0}\">[返回主题]</a>", base.ShowTopicAspxRewrite(this.topicid, 1))); return; } ForumUtils.SetVisitedForumsCookie(this.forumid.ToString()); if (this.userid > 0) { this.userInfo = BBX.Entity.User.FindByID(this.userid); } if (this.topic.Identify > 0) { this.topicidentify = TopicIdentify.FindByID(this.topic.Identify); } this.pagetitle = string.Format("{0} - {1}", this.topic.Title, Utils.RemoveHtml(this.forum.Name)); base.GetForumAds(this.forum.Fid); TopicType.GetTopicTypeArray().TryGetValue(this.topic.TypeID, out this.topictypes); this.topictypes = (this.topictypes.IsNullOrEmpty() ? "" : ("[" + this.topictypes + "]")); this.userextcreditsinfo = Scoresets.GetScoreSet(Scoresets.GetTopicAttachCreditsTrans()); this.score = Scoresets.GetValidScoreName(); this.scoreunit = Scoresets.GetValidScoreUnit(); this.navhomemenu = Caches.GetForumListMenuDivCache(this.usergroupid, this.userid, this.config.Extname); base.EditorState(); string[] array = this.config.Customauthorinfo.Split('|'); this.postleftshow = array[0].Split(','); this.userfaceshow = array[1].Split(','); this.onlyauthor = ((this.onlyauthor == "1" || this.onlyauthor == "2") ? this.onlyauthor : "0"); this.BindPageCountAndId(); base.GetPostAds(this.GetPostPramsInfo(topicPrice), this.postlist.Count); //this.bonuslogs = Bonus.GetLogs(this.topic); if (this.topic.Special == 3) { this.bonuslogs = BonusLog.GetLogs(this.topic.ID); } if (this.topic.Special == 1) { this.GetPollInfo(); } if (this.topic.Special == 4) { this.GetDebateInfo(); } this.enabletag = config.Enabletag && forum.AllowTag; if (this.postlist != null && this.postlist.Count > 0) { base.UpdateMetaInfo(Utils.RemoveHtml(this.postlist[0].Message)); } this.IsGuestCachePage(); //Topic.UpdateViewCount(this.topicid, 1); topic.Views++; topic.SaveAsync(10000); Topics.MarkOldTopic(this.topic); this.topicviews = this.topic.Views; Online.UpdateAction(this.olid, UserAction.ShowTopic, this.forumid, this.forum.Name, this.topicid, this.topic.Title); if (DNTRequest.GetInt("fromfav", 0) > 0) { //Favorites.UpdateUserFavoriteViewTime(this.userid, this.topicid); var fav = Favorite.FindByUidAndTid(userid, topicid); if (fav != null) { fav.ViewTime = DateTime.Now; fav.Update(); } } }