Ejemplo n.º 1
0
        public void Inser(UserSignDto dto)
        {
            var entity = _mapper.Map <UserSignDto, UserSignEntity>(dto);

            _funHaiNanContext.UserSign.Add(entity);
            _funHaiNanContext.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 记录用户签到信息
        /// author:陶林辉
        /// </summary>
        /// <param name="userSign"></param>
        /// <returns></returns>
        public async Task <bool> RecordUserSignAsync(UserSignDto userSign)
        {
            var entity = _mapper.Map <UserSignDto, UserSignEntity>(userSign);

            _context.UserSign.Add(entity);
            return(await _context.SaveChangesAsync() > 0);
        }
Ejemplo n.º 3
0
        public async Task <H5ResponseViewModel <UserSignViewModel> > UserSignInfo([FromBody] H5RequestViewModel Parameters)
        {
            var sysCode = _sys.CheckParameters(Parameters.data, "userverify");
            H5ResponseViewModel <UserSignViewModel> response = null;

            sysCode = SysCode.Ok;
            UserSignViewModel result = new UserSignViewModel
            {
                Multiple = 1,
                Number   = 1,
                state    = true,
            };

            if (sysCode == SysCode.Ok)
            {
                string token = Parameters.data.token;
                //token是否有效
                bool isLog = _token.VerifyToken(token);
                if (isLog)
                {
                    UserLoginDto userLogin   = JsonHelper.DeserializeJsonToObject <UserLoginDto>(RedisHelper.StringGet($"{CacheKey.Token}{token}", RedisFolderEnum.token, RedisEnum.Five));
                    long         userId      = long.Parse(userLogin.Userid.ToString());
                    UserSignDto  userSignDto = await _userTask.QueryUserSignAsync(userId);

                    DateTime nowTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));//当前时间
                    if (userSignDto != null)
                    {
                        DateTime time = Convert.ToDateTime(userSignDto.Createtime.ToString("yyyy-MM-dd")); //用户最后一次签到时间
                        if (time == nowTime)
                        {
                            result.Multiple = userSignDto.Multiple;
                            result.Number   = userSignDto.Number;
                            result.state    = false;
                        }
                        else
                        {
                            if (TimeHelper.Dateday(nowTime, Convert.ToDateTime(time)) == 1)
                            {
                                result.Multiple = userSignDto.Multiple;
                                result.Number   = userSignDto.Number;
                                result.state    = true;
                            }
                        }
                    }
                }
                else
                {
                    sysCode = SysCode.TokenLose;
                }
            }
            response = new H5ResponseViewModel <UserSignViewModel>(sysCode, result);
            return(response);
        }
Ejemplo n.º 4
0
        public async Task <H5ResponseViewModel <userSignInfoViewModel> > UserSign_v1([FromBody] H5RequestViewModel Parameters)
        {
            H5ResponseViewModel <userSignInfoViewModel> response = null;
            string userId  = _biz.IsNoLogin((string)Parameters.data.token, (string)Parameters.data.userOpenId);
            var    sysCode = SysCode.Ok;
            userSignInfoViewModel userSignInfo = null;

            if (userId != "0")
            {
                int     day      = 0;
                decimal multiple = 0.00m;
                decimal amout    = 0.00m;
                long    user_id  = long.Parse(userId);
                var     userSign = await _userTask.QueryUserSignAsync(user_id);

                UserSignDto userSignDto = null;
                DateTime    nowTime     = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); //当前时间
                Random      rd          = new Random();
                int         num         = rd.Next(10, 16);                                         //随机数
                if (userSign != null)
                {
                    //有签到信息
                    DateTime time = Convert.ToDateTime(userSign.Createtime.ToString("yyyy-MM-dd")); //用户最后一次签到时间
                    if (nowTime != time)
                    {
                        if (TimeHelper.Dateday(nowTime, time) == 1)                          //当前时间和签到时间相差一天
                        {
                            if (userSign.Number < 6)                                         //小于六天
                            {
                                multiple = Convert.ToDecimal((userSign.Number * 0.5) + 0.5); //从新计算倍数
                                amout    = num * multiple;
                            }
                            else
                            {
                                multiple = 3;
                                amout    = num * multiple;
                            }
                            day = userSign.Number + 1;
                        }
                        else
                        {
                            //签到中断,从第一天开始计算
                            multiple = Convert.ToDecimal((1 * 0.5) + 0.5);//签到倍数
                            amout    = num * multiple;
                            day      = 1;
                        }
                    }
                    else
                    {
                        sysCode = SysCode.RepeatToReceive;
                    }
                }
                else
                {
                    multiple = Convert.ToDecimal((1 * 0.5) + 0.5);//签到倍数
                    amout    = num * multiple;
                    day      = 1;
                }
                if (sysCode == SysCode.Ok)
                {
                    userSignDto = new UserSignDto
                    {
                        Amount     = amout,
                        Createtime = DateTime.Now,
                        Multiple   = multiple,
                        Number     = day,
                        UserId     = long.Parse(userId)
                    };
                    if (await _userTask.RecordUserSignAsync(userSignDto)) //记录签到记录
                    {
                        GiveCurrencyDto giveCurrencyDto = new GiveCurrencyDto
                        {
                            amount   = double.Parse(userSignDto.Amount.ToString()),
                            forderId = Guid.NewGuid().ToString(),
                            fuserId  = userId.ToString(),
                            key      = _currencyKey.Sign,
                        };
                        bool isNo = false;
                        //关闭章鱼赠币
                        //isNo = await _biz.GiveCurrencyAsync(giveCurrencyDto);
                        //从php 赠币
                        isNo = await _accout.GiveCurrencyAsync_php(giveCurrencyDto);

                        userSignInfo = new userSignInfoViewModel
                        {
                            Amount         = amout.ToString(),
                            Multiple       = multiple.ToString(),
                            SignTime       = DateTime.Now,
                            UserSignNumber = userSignDto.Number.ToString()
                        };
                        _log.InfoFormat("签到,用户id:{0},金额:{1},签到时间{2},订单号:{3},签到结果:{4}"
                                        , userId, userSignDto.Amount, userSignDto.Createtime, giveCurrencyDto.forderId, isNo);
                    }
                }
            }
            else
            {
                sysCode = SysCode.SessionTokenLose;
            }
            response = new H5ResponseViewModel <userSignInfoViewModel>(sysCode, sysCode == SysCode.Ok ? userSignInfo : null);
            return(response);
        }
Ejemplo n.º 5
0
        public async Task <H5ResponseViewModel <userSignInfoViewModel> > UserSign([FromBody] H5RequestViewModel Parameters)
        {
            var sysCode = _sys.CheckParameters(Parameters.data, "userverify");
            H5ResponseViewModel <userSignInfoViewModel> response = null;
            userSignInfoViewModel userSignInfo = null;

            if (sysCode == SysCode.Ok)
            {
                string token = Parameters.data.token;
                //token是否有效
                bool isLog = _token.VerifyToken(token);
                if (isLog)
                {
                    UserLoginDto userLogin = JsonHelper.DeserializeJsonToObject <UserLoginDto>(RedisHelper.StringGet($"{CacheKey.Token}{token}", RedisFolderEnum.token, RedisEnum.Five));
                    long         userId    = long.Parse(userLogin.Userid.ToString());
                    UserSignDto  userSign  = await _userTask.QueryUserSignAsync(userId);

                    UserSignDto userSignDto = null;
                    DateTime    nowTime     = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));//当前时间
                    Random      rd          = new Random();
                    int         day         = 0;
                    decimal     multiple    = 0.00m;
                    decimal     amout       = 0.00m;
                    int         num         = rd.Next(10, 16);//随机数
                    if (userSign != null)
                    {
                        //有签到信息
                        DateTime time = Convert.ToDateTime(userSign.Createtime.ToString("yyyy-MM-dd")); //用户最后一次签到时间
                        if (nowTime != time)
                        {
                            if (TimeHelper.Dateday(nowTime, time) == 1)                          //当前时间和签到时间相差一天
                            {
                                if (userSign.Number < 6)                                         //小于六天
                                {
                                    multiple = Convert.ToDecimal((userSign.Number * 0.5) + 0.5); //从新计算倍数
                                    amout    = num * multiple;
                                }
                                else
                                {
                                    multiple = 3;
                                    amout    = num * multiple;
                                }
                                day = userSign.Number + 1;
                            }
                            else
                            {
                                //签到中断,从第一天开始计算
                                multiple = Convert.ToDecimal((1 * 0.5) + 0.5);//签到倍数
                                amout    = num * multiple;
                                day      = 1;
                            }
                        }
                        else
                        {
                            sysCode = SysCode.RepeatToReceive;
                        }
                    }
                    else
                    {
                        multiple = Convert.ToDecimal((1 * 0.5) + 0.5);//签到倍数
                        amout    = num * multiple;
                        day      = 1;
                    }
                    if (sysCode == SysCode.Ok)
                    {
                        userSignDto = new UserSignDto
                        {
                            Amount     = amout,
                            Createtime = DateTime.Now,
                            Multiple   = multiple,
                            Number     = day,
                            UserId     = userId
                        };
                        if (await _userTask.RecordUserSignAsync(userSignDto)) //记录签到记录
                        {
                            GiveCurrencyDto giveCurrencyDto = new GiveCurrencyDto
                            {
                                amount   = double.Parse(userSignDto.Amount.ToString()),
                                forderId = Guid.NewGuid().ToString(),
                                fuserId  = userId.ToString(),
                                key      = _currencyKey.Sign,
                            };
                            bool isNo = false;
                            //关闭章鱼赠币
                            //isNo = await _biz.GiveCurrencyAsync(giveCurrencyDto);
                            //从php赠币
                            isNo = await _accout.GiveCurrencyAsync_php(giveCurrencyDto);

                            userSignInfo = new userSignInfoViewModel
                            {
                                Amount         = amout.ToString(),
                                Multiple       = multiple.ToString(),
                                SignTime       = DateTime.Now,
                                UserSignNumber = userSignDto.Number.ToString()
                            };
                            _log.InfoFormat("签到,用户id:{0},金额:{1},签到时间{2},订单号:{3},签到结果:{4}"
                                            , userId, userSignDto.Amount, userSignDto.Createtime, giveCurrencyDto.forderId, isNo);
                        }
                    }
                }
                else
                {
                    sysCode = SysCode.TokenLose;
                }
            }
            response = new H5ResponseViewModel <userSignInfoViewModel>(sysCode, sysCode == SysCode.Ok ? userSignInfo : null);
            return(response);
        }