Exemplo n.º 1
0
        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="openId">微信openId</param>
        /// <returns></returns>
        public bool User_Sign()
        {
            var user   = CookieHelper.GetCurrentWxUser();
            var person = CookieHelper.GetCurrentPeople();

            if (user == null || person == null)
            {
                return(false);
            }
            using (DbRepository entities = new DbRepository())
            {
                var userEntity = entities.User.Find(user.openid);
                if (userEntity == null)
                {
                    return(false);
                }
                var yesterday = DateTime.Now.AddDays(-1).Date;
                var lastSign  = entities.UserSign.Where(x => x.OpenId.Equals(user.openid) && x.PersonId.Equals(person.UNID)).OrderByDescending(x => x.SignDate).FirstOrDefault();


                //判断是否连续签到
                if (lastSign != null)
                {
                    //判断今天是否已签到
                    if (lastSign.SignDate > yesterday)
                    {
                        return(false);
                    }

                    var todaySign = new UserSign()
                    {
                        UNID     = Guid.NewGuid().ToString("N"),
                        SignDate = DateTime.Now,
                        OpenId   = user.openid,
                        PersonId = person.UNID
                    };
                    if (lastSign.SignDate == yesterday)
                    {
                        todaySign.SignNum = lastSign.SignNum + 1;

                        //签到10天判断
                        if (todaySign.SignNum % 10 == 0 && todaySign.SignNum >= 10)
                        {
                            var tenScoreDetials = new ScoreDetails()
                            {
                                UNID        = Guid.NewGuid().ToString("N"),
                                OpenId      = user.openid,
                                CreatedTime = DateTime.Now,
                                Description = "连续签到10天获得积分",
                                IsAdd       = (int)YesOrNoCode.Yes,
                                Value       = Params.TendayScore,
                                Type        = (int)ScoreType.Sign,
                                PersonId    = person.UNID
                            };
                            entities.ScoreDetails.Add(tenScoreDetials);

                            //是否初次签到
                            var userScore = entities.UserScore.FirstOrDefault(x => x.OpenId.Equals(user.openid) && x.PersonId.Equals(person.UNID));
                            if (userScore == null)
                            {
                                var addUserScore = new UserScore()
                                {
                                    UNID     = Guid.NewGuid().ToString("N"),
                                    OpenId   = user.openid,
                                    PersonId = person.UNID,
                                    Score    = Params.TendayScore
                                };
                                entities.UserScore.Add(addUserScore);
                            }
                            else
                            {
                                userScore.Score += Params.TendayScore;
                            }
                        }
                    }
                    else
                    {
                        todaySign.SignNum = 1;
                    }


                    entities.UserSign.Add(todaySign);
                }
                else
                {
                    var todaySign = new UserSign()
                    {
                        UNID     = Guid.NewGuid().ToString("N"),
                        SignDate = DateTime.Now,
                        SignNum  = 1,
                        OpenId   = user.openid,
                        PersonId = person.UNID
                    };
                    entities.UserSign.Add(todaySign);
                }

                //日常签到积分
                var scoreDetials = new ScoreDetails()
                {
                    UNID        = Guid.NewGuid().ToString("N"),
                    OpenId      = user.openid,
                    CreatedTime = DateTime.Now,
                    Description = "签到获得积分",
                    IsAdd       = (int)YesOrNoCode.Yes,
                    Value       = Params.SignScore,
                    Type        = (int)ScoreType.Sign,
                    PersonId    = person.UNID
                };
                //用户积分增加
                var updateUserScore = entities.UserScore.FirstOrDefault(x => x.OpenId.Equals(user.openid) && x.PersonId.Equals(person.UNID));
                if (updateUserScore == null)
                {
                    var addUserScore = new UserScore()
                    {
                        UNID     = Guid.NewGuid().ToString("N"),
                        OpenId   = user.openid,
                        PersonId = person.UNID,
                        Score    = Params.SignScore
                    };
                    entities.UserScore.Add(addUserScore);
                }
                else
                {
                    updateUserScore.Score += Params.SignScore;
                }
                entities.ScoreDetails.Add(scoreDetials);

                return(entities.SaveChanges() > 0 ? true : false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 完成拼图结果
        /// </summary>
        /// <returns>操作结果  提示语句  是否绑定平台活动  平台活动名 绑定地址</returns>
        public Tuple <bool, string, bool, string, string> Complete(string unid)
        {
            var user   = CookieHelper.GetCurrentWxUser();
            var person = CookieHelper.GetCurrentPeople();

            if (user == null || person == null)
            {
                return(new Tuple <bool, string, bool, string, string>(false, "身份过期", false, "", ""));
            }
            using (DbRepository entities = new DbRepository())
            {
                var puzzle = entities.Puzzle.Find(unid);
                if (puzzle == null)
                {
                    return(new Tuple <bool, string, bool, string, string>(false, "参数错误", false, "", ""));
                }
                var dateTime = DateTime.Now.Date;

                if (entities.UserPuzzle.FirstOrDefault(x => x.PuzzleId.Equals(unid) && x.PuzzleDate == dateTime) != null)
                {
                    return(new Tuple <bool, string, bool, string, string>(false, "该拼图已玩过", false, "", ""));
                }
                var userPuzzle = new UserPuzzle()
                {
                    UNID       = Guid.NewGuid().ToString("N"),
                    OpenId     = user.openid,
                    PuzzleDate = dateTime,
                    PuzzleId   = unid
                };
                entities.UserPuzzle.Add(userPuzzle);

                if (puzzle.IsBindScore == (int)YesOrNoCode.Yes)
                {
                    //日常签到积分
                    var scoreDetials = new ScoreDetails()
                    {
                        UNID        = Guid.NewGuid().ToString("N"),
                        OpenId      = user.openid,
                        CreatedTime = DateTime.Now,
                        Description = "完成拼图获得积分",
                        IsAdd       = (int)YesOrNoCode.Yes,
                        Value       = puzzle.Score,
                        Type        = (int)ScoreType.Puzzle,
                        PersonId    = person.UNID,
                        TargetId    = unid
                    };

                    entities.ScoreDetails.Add(scoreDetials);
                    //用户积分增加
                    var updateUserScore = entities.UserScore.FirstOrDefault(x => x.OpenId.Equals(user.openid) && x.PersonId.Equals(person.UNID));
                    if (updateUserScore == null)
                    {
                        var addUserScore = new UserScore()
                        {
                            UNID     = Guid.NewGuid().ToString("N"),
                            OpenId   = user.openid,
                            PersonId = person.UNID,
                            Score    = puzzle.Score
                        };
                        entities.UserScore.Add(addUserScore);
                    }
                    else
                    {
                        updateUserScore.Score += puzzle.Score;
                    }

                    return(entities.SaveChanges() > 0?new Tuple <bool, string, bool, string, string>(true, string.Format("恭喜你获得:{0}积分", puzzle.Score), false, "", ""):new Tuple <bool, string, bool, string, string>(false, "保存出错", false, "", ""));
                }
                else
                {
                    return(entities.SaveChanges() > 0?new Tuple <bool, string, bool, string, string>(true, puzzle.BindTitle, true, puzzle.BindName, puzzle.BindUrl): new Tuple <bool, string, bool, string, string>(false, "保存出错", false, "", ""));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string Add_Order(GoodsOrder model)
        {
            if (model == null ||
                !model.GoodsId.IsNotNullOrEmpty() ||
                model.Count == 0
                )
            {
                return("数据错误");
            }
            var user   = CookieHelper.GetCurrentWxUser();
            var person = CookieHelper.GetCurrentPeople();

            if (user == null || person == null)
            {
                return("身份验证过期");
            }
            using (DbRepository entities = new DbRepository())
            {
                var userEntity = entities.User.Find(user.openid);
                if (userEntity == null)
                {
                    return("用户不存在");
                }

                var goods = entities.Goods.Find(model.GoodsId);
                if (goods == null)
                {
                    return("数据错误");
                }

                if (goods.OngoingTime > DateTime.Now)
                {
                    return("还没到活动时间");
                }
                if (goods.OverTime < DateTime.Now)
                {
                    return("已过活动时间");
                }

                if (goods.SurplusNum < model.Count)
                {
                    return("商品库存不足");
                }

                //商品库存减少
                goods.SurplusNum -= (int)model.Count;
                //积分总计
                model.ScoreNum = model.Count * goods.ScoreNum;

                var userScore = entities.UserScore.FirstOrDefault(x => x.OpenId.Equals(user.openid) && x.PersonId.Equals(person.UNID));
                if (userScore == null || userScore.Score < model.ScoreNum)
                {
                    return("用户积分不足");
                }

                //扣减用户积分
                userScore.Score -= (int)model.ScoreNum;

                //消费积分
                var scoreDetials = new ScoreDetails()
                {
                    UNID        = Guid.NewGuid().ToString("N"),
                    OpenId      = user.openid,
                    CreatedTime = DateTime.Now,
                    Description = string.Format("购买商品:{0},数量{1},消费积分{2}", goods.Name, model.Count, model.Count * goods.ScoreNum),
                    IsAdd       = (int)YesOrNoCode.No,
                    Value       = (int)(model.Count * goods.ScoreNum),
                    Type        = (int)ScoreType.Mall,
                    PersonId    = person.UNID
                };
                entities.ScoreDetails.Add(scoreDetials);


                model.UNID        = Guid.NewGuid().ToString("N");
                model.OpenId      = user.openid;
                model.PersonId    = person.UNID;
                model.AllPrice    = model.Count * goods.SellingPrice;
                model.CreatedTime = DateTime.Now;

                entities.GoodsOrder.Add(model);

                return(entities.SaveChanges() > 0 ? "" : "保存出错");
            }
        }