Beispiel #1
0
        /// <summary>
        /// 获取彩种开奖信息
        /// </summary>
        /// <param name="lType">彩种Id</param>
        /// <returns></returns>
        public ApiResult <IndexLotteryInfoResDto> GetLotteryInfo(int lType)
        {
            var lotteryInfo = GetLotteryType2(lType);

            if (lotteryInfo == null)
            {
                throw new ApiException(40000, "该彩种不存在");
            }

            var info = new IndexLotteryInfoResDto()
            {
                LType     = lType,
                LTypeName = Util.GetLotteryTypeName(lType),
            };

            var lastLotteryRecord = GetLotteryRecord(lotteryInfo.lType);

            if (lastLotteryRecord != null)
            {
                info.OpenNum      = lastLotteryRecord.Num;
                info.Issue        = lastLotteryRecord.Issue;
                info.OpenTime     = lastLotteryRecord.ShowOpenTime;
                info.OpenNumAlias = Util.GetShowInfo(lastLotteryRecord.lType, lastLotteryRecord.Num, lastLotteryRecord.SubTime);
                info.CurrentIssue = LuoUtil.GetCurrentIssue(lType);
            }
            info.Logo = Util.GetLotteryIconUrl(lotteryInfo.lType);

            return(new ApiResult <IndexLotteryInfoResDto>()
            {
                Data = info
            });
        }
Beispiel #2
0
        /// <summary>
        /// 获取用户点阅计划所需金币数
        /// </summary>
        public ApiResult <dynamic> GetReadCoin(int lType, long uid, long userId)
        {
            //step6.查询用户彩种积分,
            int totalIntegral = LuoUtil.GetUserIntegral(uid, lType);
            //step7.根据用户该彩种积分,查询点阅所需金币
            var setting = GetLotteryCharge().FirstOrDefault(
                x => x.MinIntegral <= totalIntegral &&
                x.MaxIntegral > totalIntegral &&
                x.LType == lType
                );

            int readCoin      = setting != null ? setting.Coin : 0;
            int userCouponNum = GetUserCouponNum(userId);
            int userCoin      = new UserInfoService().GetUserInfo(userId).Coin;

            return(new ApiResult <dynamic>()
            {
                Code = 100, Desc = "", Data = new { ReadCoin = readCoin, UserCouponNum = userCouponNum, UserCoin = userCoin }
            });
        }
Beispiel #3
0
        public void GetCurrentIssueTest1()
        {
            var result = LuoUtil.GetCurrentIssue(51, DateTime.Now);

            Console.WriteLine(result);
        }
Beispiel #4
0
        /// <summary>
        /// 发布计划
        /// </summary>
        public ApiResult Bet(int lType, string currentIssue, string betInfo, long userId)
        {
            #region 校验
            //获取当前状态
            string time = LotteryTime.GetTime(lType.ToString());
            if (time == "正在开奖")
            {
                return(new ApiResult(400, "发帖失败,当期已封盘"));
            }

            if (LuoUtil.GetRemainingTime(lType) == "已封盘")
            {
                return(new ApiResult(400, "发帖失败,当期已封盘"));
            }

            //校验当前这期是否已开奖
            string isOpenSql = "select count(1) from dbo.LotteryRecord where lType=" + lType + " and Issue=@Issue";
            object obj       = SqlHelper.ExecuteScalar(isOpenSql, new SqlParameter("@Issue", currentIssue));
            if (obj != null && Convert.ToInt32(obj) > 0)
            {
                return(new ApiResult(400, "发帖失败,当期已封盘"));
            }

            //获取当前最新期
            string currentLastIssue = LuoUtil.GetCurrentIssue(lType);
            if (string.IsNullOrEmpty(currentLastIssue) && currentIssue != currentLastIssue)
            {
                return(new ApiResult(400, "发帖失败,当期已封盘"));
            }

            #endregion

            //数据清理
            string sql = "delete from BettingRecord where UserId=" + userId + " and lType =" + lType + " and Issue=@Issue";
            SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@Issue", currentIssue));



            string[] betInfoArr = betInfo.Split('$');

            string playName  = "";
            string playName2 = "";            //单双  大小 五码
            string betNum    = "";
            string s1        = "";


            foreach (string s in betInfoArr)
            {
                string[] arr = s.Split('*');

                playName = arr[0];
                betNum   = arr[1];

                string[] betNumArr = betNum.Split('|');

                for (int i = 0; i < betNumArr.Length; i++)
                {
                    s1 = betNumArr[i];

                    if (!string.IsNullOrEmpty(s1))
                    {
                        playName2 = Util.GetPlayName(lType, playName, s1, i);

                        sql = "insert into BettingRecord(UserId,lType,Issue,BigPlayName,PlayName,BetNum,SubTime) values(" + userId + "," + lType + ",@Issue,@BigPlayName,@PlayName,@BetNum,GETDATE())";

                        SqlParameter[] pms =
                        {
                            new SqlParameter("@Issue",       currentIssue),
                            new SqlParameter("@BigPlayName", playName),
                            new SqlParameter("@PlayName",    playName + playName2),
                            new SqlParameter("@BetNum",      s1),
                        };

                        SqlHelper.ExecuteNonQuery(sql, pms);
                    }
                }
            }
            return(new ApiResult());
        }
Beispiel #5
0
        /// <summary>
        /// 获取当前用户某个彩种当前期号计划集合
        /// </summary>
        public ApiResult <List <BettingRecord> > AlreadyPostData(int lType, long userId)
        {
            string sql = "select * from BettingRecord where UserId  =" + userId + " and lType=" + lType + " and Issue = '" + LuoUtil.GetCurrentIssue(lType) + "'";
            List <BettingRecord> list = Util.ReaderToList <BettingRecord>(sql);

            return(new ApiResult <List <BettingRecord> >()
            {
                Code = 100, Data = list
            });
        }
Beispiel #6
0
        /// <summary>
        /// 获取该用户最新计划(同时会插入点阅记录,收费专家扣除用户金币数、获得佣金)
        /// </summary>
        public ApiResult <BettingRecord> GetLastPlay(int lType, long uid, string playName, long userId, int paytype = 1)
        {
            if (string.IsNullOrWhiteSpace(playName))
            {
                return(new ApiResult <BettingRecord>()
                {
                    Code = 6001, Desc = "彩种名称不能为空", Data = null
                });
            }
            //if (uid == userId)
            //{
            //    return new ApiResult<BettingRecord>() { Code = 6002, Desc = "相同用户,不能获取", Data = null };
            //}

            #region 校验,添加点阅记录,扣费,分佣
            UserInfo user = PersonalService.GetUser(userId);
            //step1.查询最新发帖
            string lastBettingSql       = @" select top 1 * from BettingRecord where UserId=@UserId 
                 and lType=@lType and WinState=1 and PlayName=@PlayName order by SubTime desc";
            var    lastBettingParameter = new[]
            {
                new SqlParameter("@UserId", uid),
                new SqlParameter("@lType", lType),
                new SqlParameter("@PlayName", playName),
            };
            var records           = Util.ReaderToList <BettingRecord>(lastBettingSql, lastBettingParameter);
            var lastBettingRecord = records.FirstOrDefault();

            if (lastBettingRecord == null)
            {
                return(new ApiResult <BettingRecord>()
                {
                    Code = 6003, Desc = "未获取到数据", Data = null
                });
            }

            if (uid == userId)
            {
                return(new ApiResult <BettingRecord>()
                {
                    Data = lastBettingRecord
                });
            }

            //如果是使用金币查看,否则使用查看劵查看
            if (paytype == 1)
            {
                //step2:查询用户是否点阅过该帖子。若未点阅过,则校验金币是否充足
                string readRecordSql = @"select count(1) from ComeOutRecord 
                    where [Type]=@Type and UserId=@UserId and OrderId=@Id";

                var readRecordParameter = new[]
                {
                    new SqlParameter("@Type", (int)TransactionTypeEnum.点阅),
                    new SqlParameter("@UserId", userId),
                    new SqlParameter("@Id", lastBettingRecord.Id),
                };

                object objReadRecord = SqlHelper.ExecuteScalar(readRecordSql, readRecordParameter);

                //用户未点阅过该帖子
                if (objReadRecord == null || Convert.ToInt32(objReadRecord) <= 0)
                {
                    //step3.1:查询点阅所需金币
                    int totalIntegral = LuoUtil.GetUserIntegral(uid, lType);
                    var setting       = GetLotteryCharge().FirstOrDefault(
                        x => x.MinIntegral <= totalIntegral &&
                        x.MaxIntegral > totalIntegral &&
                        x.LType == lType
                        );

                    int readCoin = 0; //点阅所需金币

                    if (setting != null)
                    {
                        readCoin = setting.Coin;
                    }

                    StringBuilder executeSql = new StringBuilder();
                    if (readCoin > 0)
                    {
                        //step3.2:校验用户金币是否充足
                        if (user.Coin < readCoin)
                        {
                            //金币不足
                            return(new ApiResult <BettingRecord>()
                            {
                                Code = 6004, Desc = "收费帖子,金币不足", Data = null
                            });
                        }
                        else
                        {
                            //1.扣除用户金币
                            executeSql.AppendFormat("update UserInfo set Coin-={0} where Id={1};", readCoin, user.Id);
                            //2.添加点阅记录
                            executeSql.AppendFormat(@"INSERT INTO [dbo].[ComeOutRecord]([UserId],[OrderId],[Type] ,[Money],[State],[SubTime])
                            VALUES({0},{1},{2},{3}, 1, GETDATE());", user.Id, lastBettingRecord.Id, (int)TransactionTypeEnum.点阅, readCoin);


                            //3:查询用户分佣比例
                            var userRateSetting = GetCommissionSetting().FirstOrDefault(x => x.LType == GetlType(lType) && x.Type == (int)CommissionTypeEnum.点阅佣金);

                            if (userRateSetting != null && userRateSetting.Percentage > 0)
                            {
                                int commission = (int)(userRateSetting.Percentage * readCoin);
                                executeSql.AppendFormat("update UserInfo set Money+={0} where Id={1}", commission, uid);

                                executeSql.AppendFormat(@"INSERT INTO [dbo].[ComeOutRecord]([UserId],[OrderId],[Type] ,[Money],[State],[SubTime])
                                    VALUES({0},{1},{2},{3}, 1, GETDATE());", user.Id, lastBettingRecord.Id, (int)TransactionTypeEnum.点阅佣金, commission);
                            }
                        }
                    }
                    else
                    {
                        //免费专家,仅记录点阅记录
                        executeSql.AppendFormat(@"INSERT INTO [dbo].[ComeOutRecord]([UserId],[OrderId],[Type] ,[Money],[State],[SubTime])
                                            VALUES({0},{1},{2},{3}, 1, GETDATE());", user.Id, lastBettingRecord.Id, (int)TransactionTypeEnum.点阅, 0);
                    }

                    try
                    {
                        SqlHelper.ExecuteTransaction(executeSql.ToString());
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteLog(string.Format("查看最新帖子异常。帖子Id:{0},查看人:{1},异常消息:{2},异常堆栈:{3}",
                                                         lastBettingRecord.Id, user.Id, ex.Message, ex.StackTrace));

                        return(new ApiResult <BettingRecord>()
                        {
                            Code = -999, Desc = "数据库错误", Data = null
                        });
                    }
                }
            }
            else if (paytype == 2)
            {
                int couponNum = GetUserCouponNum(userId);
                if (couponNum > 0)
                {
                    UpdateUserCoupon(lastBettingRecord.Id, userId);
                }
                else
                {
                    return(new ApiResult <BettingRecord>()
                    {
                        Code = 6004, Desc = "收费帖子,查看劵不足", Data = null
                    });
                }
            }

            return(new ApiResult <BettingRecord>()
            {
                Code = 100, Desc = "", Data = lastBettingRecord
            });

            #endregion
        }