Example #1
0
        /// <summary>
        /// 用户参团(支付回调时调用)
        /// </summary>
        /// <returns></returns>
        public ResultModel JoinGroup(int GroupId, int uid, string outtradeno, string transaction_id)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    bsp_groups Group = context.bsp_groups.SingleOrDefault(t => t.groupid == GroupId);
                    Group.nowcount += 1;
                    //拼团成功,发放优惠券
                    if (Group.needcount <= Group.nowcount)
                    {
                        Group.isfinish = true;
                        Group.endtime  = DateTime.Now;
                        var groupdetails = context.bsp_groupdetails.Where(t => t.groupid == GroupId).ToList();
                        foreach (var groupdetail in groupdetails)
                        {
                            if (!groupdetail.isgetcoupon.Value)
                            {
                                coupon.RecpientCoupon(groupdetail.uid, Group.groupoid);
                                groupdetail.isgetcoupon = true;
                            }
                        }
                    }

                    bsp_groupdetails newGroupetail = new bsp_groupdetails();
                    newGroupetail.groupid        = Group.groupid;
                    newGroupetail.paytime        = DateTime.Now;
                    newGroupetail.sno            = Group.nowcount;
                    newGroupetail.uid            = uid;
                    newGroupetail.isgetcoupon    = false;
                    newGroupetail.paytime        = DateTime.Parse("1997-01-27");
                    newGroupetail.transaction_id = transaction_id;
                    newGroupetail.outtradeno     = outtradeno;
                    if (Group.needcount <= Group.nowcount)
                    {
                        coupon.RecpientCoupon(newGroupetail.uid, Group.groupoid);
                        newGroupetail.isgetcoupon = true;
                    }
                    context.bsp_groupdetails.Add(newGroupetail);
                    context.SaveChanges();

                    ORDER.AddStatistics(true, Group, newGroupetail, context);
                    tran.Commit();
                    return(ResultModel.Success("参团成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error("JoinGroup方法,", ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }
Example #2
0
        /// <summary>
        /// 用户开团(支付回调时调用)
        /// </summary>
        /// <returns></returns>
        public ResultModel StartGroup(int groupInfoId, int uid, string outtradeno, string transaction_id)
        {
            using (brnshopEntities context = new brnshopEntities())
            {
                var tran = context.Database.BeginTransaction();
                try
                {
                    bsp_groupinfos GroupInfo = context.bsp_groupinfos.SingleOrDefault(t => t.groupinfoid == groupInfoId);
                    bsp_groups     newGroup  = new bsp_groups();
                    newGroup.endtime     = DateTime.Now.AddSeconds(GroupInfo.maxtime);
                    newGroup.failtype    = 0;
                    newGroup.groupoid    = GroupInfo.groupoid;
                    newGroup.groupprice  = GroupInfo.groupprice;
                    newGroup.grouptype   = GroupInfo.grouptype;
                    newGroup.isfail      = false;
                    newGroup.isfinish    = false;
                    newGroup.maxtime     = GroupInfo.maxtime;
                    newGroup.needcount   = GroupInfo.needcount;
                    newGroup.nowcount    = 1;
                    newGroup.shopprice   = GroupInfo.shopprice;
                    newGroup.starttime   = DateTime.Now;
                    newGroup.startuid    = uid;
                    newGroup.groupinfoid = groupInfoId;
                    context.bsp_groups.Add(newGroup);
                    context.SaveChanges();

                    bsp_groupdetails newGroupetail = new bsp_groupdetails();
                    newGroupetail.groupid        = newGroup.groupid;
                    newGroupetail.paytime        = DateTime.Now;
                    newGroupetail.sno            = 1;
                    newGroupetail.uid            = uid;
                    newGroupetail.isgetcoupon    = false;
                    newGroupetail.paytime        = DateTime.Parse("1997-01-27");
                    newGroupetail.transaction_id = transaction_id;
                    newGroupetail.outtradeno     = outtradeno;
                    context.bsp_groupdetails.Add(newGroupetail);
                    context.SaveChanges();
                    ORDER.AddStatistics(true, newGroup, newGroupetail, context);
                    tran.Commit();
                    return(ResultModel.Success("开团成功"));
                }
                catch (Exception ex)
                {
                    Logger._.Error("StartGroup方法,", ex);
                    tran.Rollback();
                    return(ResultModel.Error(ex.ToString()));
                }
            }
        }