Ejemplo n.º 1
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.º 2
0
        public async Task <H5ResponseViewModel <userSignInfoViewModel> > UserSign([FromBody] H5RequestViewModel Parameters)
        {
            Thread.Sleep(3000);
            H5ResponseViewModel <userSignInfoViewModel> response = null;
            bool isLog   = _token.VerifyToken((string)Parameters.data.userOpenId, (string)Parameters.data.sessionToken);
            var  sysCode = SysCode.Ok;
            userSignInfoViewModel userSignInfo = null;

            if (isLog)
            {
                string strJson  = RedisHelper.StringGet($"{CacheKey.Token}{(string)Parameters.data.userOpenId}", RedisFolderEnum.token, RedisEnum.Three);
                var    userLog  = JsonHelper.DeserializeJsonToObject <UserLoginDto>(strJson);
                var    userSign = await _userTask.QueryUserSignAsync(userLog.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     = userLog.Userid
                    };
                    if (await _userTask.RecordUserSignAsync(userSignDto)) //记录签到记录
                    {
                        GiveCurrencyDto giveCurrencyDto = new GiveCurrencyDto
                        {
                            amount   = double.Parse(userSignDto.Amount.ToString()),
                            forderId = Guid.NewGuid().ToString(),
                            fuserId  = userLog.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}"
                                        , userLog.Userid, userSignDto.Amount, userSignDto.Createtime, giveCurrencyDto.forderId, isNo);
                    }
                }
            }
            else
            {
                sysCode = SysCode.SessionTokenLose;
            }
            response = new H5ResponseViewModel <userSignInfoViewModel>(sysCode, sysCode == SysCode.Ok ? userSignInfo : null);
            return(response);
        }