Пример #1
0
        public APIResultBase AddOrUpdate(HS_GameTable gameTable, GameStyleEnum GameStyle)
        {
            if (gameTable.CreateUserCode.IsNullOrEmpty() || gameTable.TableName.IsNullOrEmpty())
            {
                return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误));
            }
            if (_repository.Get(c => (c.CreateUserCode == gameTable.CreateUserCode || c.PlayerUserCode == gameTable.CreateUserCode) && gameTable.ID < 1 && c.TableStatus == (int)TableStatusEnum.正常).Result.TotalItemsCount > 0)
            {
                return(JsonModelResult.PackageFail(OperateResCodeEnum.时只能创建或占用一个游戏房间));
            }
            if (gameTable.ID > 0)
            {
                //gameTable.AddTime = _repository.GetByKey(gameTable.ID).Result.AddTime;
                _repository.Update(gameTable);
                return(JsonModelResult.PackageSuccess(gameTable.ID.ToString()));
            }
            else
            {
                DateTime now = DateTime.Now;
                gameTable.PlayerUserCode = "";
                gameTable.TableCode      = SignUtil.CreateSign(UsersBll.Instance.GetUserByAdmin(gameTable.CreateUserCode).SecretCode + RandomUtil.CreateRandomStr(8) + now.Ticks);
                gameTable.AddTime        = DateTime.Now;
                using (FriendshipFirstContext context = new FriendshipFirstContext())
                {
                    gameTable.BankerCode = gameTable.CreateUserCode;
                    context.hs_gametable.Add(gameTable);
                    FF_Game game = new FF_Game();
                    game.AddTime          = now;
                    game.BankerCode       = gameTable.CreateUserCode;
                    game.GameStatus       = GameStyle == GameStyleEnum.庄家模式 ? (int)GameStatusEnum.初始化 : (int)GameStatusEnum.已开始;
                    game.CurrentRoundCode = SignUtil.CreateSign(gameTable.CreateUserCode + RandomUtil.CreateRandomStr(8) + game.AddTime.Ticks);
                    game.NextRoundCode    = SignUtil.CreateSign(gameTable.CreateUserCode + RandomUtil.CreateRandomStr(8) + game.AddTime.AddMinutes(5).Ticks);
                    game.GameCode         = gameTable.TableCode;
                    game.GameStyle        = (int)GameStyle;
                    context.ff_game.Add(game);

                    FF_GameRecord record = new FF_GameRecord
                    {
                        AddTime      = now,
                        BetMoney     = 0,
                        IsBanker     = true,
                        PlayerStatus = (int)PlayerStatusEnum.已下注,
                        RoundCode    = game.CurrentRoundCode,
                        UserCode     = game.BankerCode,
                        WinMoney     = 0,
                        Balance      = 0,
                        GameCode     = game.GameCode,
                        IsActivity   = false,
                        RoomIndex    = 0
                    };
                    context.ff_gamerecord.Add(record);

                    context.SaveChanges();
                }
                return(JsonModelResult.PackageSuccess <HS_GameTable>(gameTable));
            }
        }
Пример #2
0
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <typeparam name="T">返回的Response类</typeparam>
        /// <param name="request">请求对象</param>
        /// <param name="accessToken">accessToken</param>
        /// <returns>返回Response类</returns>
        public virtual T Execute <T>(BaseRequest <T> request, string accessToken) where T : BaseResponse
        {
            RequestForm requestForm          = request.CreateRequestForm(this.openConfig);
            Dictionary <string, string> form = requestForm.Form;

            if (!string.IsNullOrEmpty(accessToken))
            {
                form[this.openConfig.AccessTokenName] = accessToken;
            }
            form[this.openConfig.AppKeyName] = this.appId;
            string sign = SignUtil.CreateSign(form, privateKey, openConfig.Charset, openConfig.SignType);

            form[this.openConfig.SignName] = sign;

            string resp = this.DoExecute(url, requestForm, header);

            return(this.ParseResponse <T>(resp, request));
        }
Пример #3
0
        /// <summary>
        /// 接口用户签名认证
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AuthenticationSign(APIReciveData im)
        {
            if (im.sign.IsNullOrEmpty() || im.nonce_str.IsNullOrEmpty() || im.usercode.IsNullOrEmpty() || im.apitime.IsNullOrEmpty())
            {
                return(false);
            }
            FF_User user = UsersBll.Instance.GetUserByAdmin(im.usercode);

            if (user == null)
            {
                return(false);
            }
            if (im.sign != SignUtil.CreateSign(im.apitime + user.SecretCode + im.nonce_str))
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginName">用户名或手机号</param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public CUsers Login(string loginName, string pwd)
        {
            pwd = SignUtil.CreateSign(pwd);
            var res = _repository.Get(c => (c.UserName == loginName || c.Mobile == loginName) && c.Password == pwd).Result;

            if (res.TotalItemsCount > 0)
            {
                return(res.Items.Select(c => new CUsers()
                {
                    UserCode = c.UserCode,
                    AddTime = c.AddTime,
                    Email = c.Email,
                    HeadImg = c.HeadImg,
                    Mobile = c.Mobile,
                    NickName = c.NickName,
                    UserName = c.UserName
                }).First());
            }
            return(null);
        }
Пример #5
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <param name="invitationCode"></param>
        /// <param name="nickName"></param>
        /// <param name="headImg"></param>
        /// <returns></returns>
        public string Register(string userName, string pwd, string mobile, string email, string nickName, string headImg = "")
        {
            if (userName.IsNullOrEmpty() || pwd.IsNullOrEmpty() || nickName.IsNullOrEmpty())
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (!StringUtil.IsNatural_Number(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.参数错误));
            }
            if (IsRepeat(userName))
            {
                return(JsonStringResult.Error(OperateResCodeEnum.用户名重复));
            }
            //if (!mobile.IsNullOrEmpty() && IsMobileRepeat(mobile))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.手机号重复);
            //}
            //if (!email.IsNullOrEmpty() && IsEmailRepeat(email))
            //{
            //    return OperateJsonRes.Error(OperateResCodeEnum.邮箱重复);
            //}
            string userCode = SignUtil.CreateSign(userName + RandomUtil.CreateRandomStr(10) + DateTime.Now.ToString("yyyyMMddHHmmss"));

            FF_User user = new FF_User();

            user.AddTime    = DateTime.Now;
            user.Email      = email.TryParseString();
            user.Mobile     = mobile.TryParseString();
            user.Password   = SignUtil.CreateSign(pwd);
            user.UserCode   = userCode;
            user.UserName   = userName;
            user.NickName   = nickName;
            user.HeadImg    = headImg.TryParseString();
            user.SecretCode = SignUtil.CreateSign(user.UserName + user.UserCode + RandomUtil.CreateRandomStr(10) + DateTime.Now.Ticks);
            user.OpenID     = "";
            _repository.Insert(user);


            return(JsonStringResult.SuccessResult(user.UserCode));
        }
Пример #6
0
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <typeparam name="T">返回的Response类</typeparam>
        /// <param name="request">请求对象</param>
        /// <param name="jwt">jwt字符串</param>
        /// <returns>返回Response类</returns>
        public virtual T Execute <T>(BaseRequest <T> request, string jwt)
        {
            RequestForm requestForm          = request.CreateRequestForm();
            Dictionary <string, object> form = requestForm.Form;
            string dataName = this.openConfig.DataName;
            object data     = form[dataName];

            string dataJson = JsonUtil.ToJSONString(data);

            dataJson = HttpUtility.UrlEncode(dataJson, System.Text.Encoding.UTF8);

            form[dataName] = dataJson;
            form.Add(this.openConfig.AppKeyName, this.appKey);
            // 添加秘钥
            string sign = SignUtil.CreateSign(form, this.secret);

            form.Add(this.openConfig.SignName, sign);

            Dictionary <string, string> header = this.buildHeader(jwt);

            string resp = this.doExecute(url, requestForm, header);

            return(this.parseResponse <T>(resp, request));
        }
Пример #7
0
        /// <summary>
        /// 结算
        /// </summary>
        /// <param name="userCode"></param>
        /// <param name="targetUserCode"></param>
        /// <param name="gameCode"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public APIResultBase Settlement(string userCode, string targetUserCode, string gameCode, decimal money)
        {
            FF_Game   game     = null;
            CGameUser gameUser = null;

            using (FriendshipFirstContext context = new FriendshipFirstContext())
            {
                game = context.ff_game.Where(c => c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault();
                if (game.GameStatus != (int)GameStatusEnum.已开始 && game.GameStatus != (int)GameStatusEnum.结算中)
                {
                    return(JsonModelResult.PackageFail(OperateResCodeEnum.参数错误));
                }
                game.GameStatus = (int)GameStatusEnum.结算中;
                var lstRec       = context.ff_gamerecord.Where(c => c.RoundCode == game.CurrentRoundCode);
                var record       = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == userCode);
                var targetRecord = lstRec.FirstOrDefault(c => c.RoundCode == game.CurrentRoundCode && c.UserCode == targetUserCode);
                record.BetMoney  = 0;
                record.Balance  += money;
                record.WinMoney += money;

                bool isAllSettlemented = false;
                if (game.GameStyle == (int)GameStyleEnum.庄家模式)
                {
                    if (record.IsBanker == false)
                    {
                        record.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1)
                    {
                        record.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }

                    targetRecord.Balance  -= money;
                    targetRecord.WinMoney -= money;
                    if (targetRecord.IsBanker == false)
                    {
                        targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    else if (lstRec.Count(c => c.IsBanker == false && c.PlayerStatus != (int)PlayerStatusEnum.已结算) <= 1)
                    {
                        targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;
                    }
                    isAllSettlemented = (record.PlayerStatus == (int)PlayerStatusEnum.已结算 && targetRecord.PlayerStatus == (int)PlayerStatusEnum.已结算);
                }
                else
                {
                    record.PlayerStatus = (int)PlayerStatusEnum.已结算;

                    targetRecord.Balance     -= money;
                    targetRecord.WinMoney    -= money;
                    targetRecord.PlayerStatus = (int)PlayerStatusEnum.已结算;

                    isAllSettlemented = !lstRec.Any(c => c.PlayerStatus != (int)PlayerStatusEnum.已结算 && c.UserCode != userCode && c.UserCode != targetUserCode);
                }

                if (isAllSettlemented)
                {
                    DateTime now = DateTime.Now;
                    var      lst = lstRec.ToList();
                    game.CurrentRoundCode = game.NextRoundCode;
                    game.NextRoundCode    = SignUtil.CreateSign(game.BankerCode + RandomUtil.CreateRandomStr(8) + now.Ticks);

                    if (game.GameStyle == (int)GameStyleEnum.庄家模式)
                    {
                        game.GameStatus = (int)GameStatusEnum.已结算;
                        AddUserToNextBankerRound(lst, game, now, context);
                    }
                    else
                    {
                        game.GameStatus = (int)GameStatusEnum.已开始;
                        AddUserToNextFreeModelRound(lst, game, now, context);
                    }
                }
                context.SaveChanges();
                gameUser = GameRecordBll.Instance.GetUser(userCode, game.GameCode, context);

                //gameUser = data.Where(c => c.UserCode == userCode && c.GameCode == gameCode).OrderByDescending(c => c.AddTime).FirstOrDefault();
            }
            return(JsonModelResult.PackageSuccess(gameUser));
        }