Example #1
0
        /// <summary>
        /// 检查是否看过该帖子,没看过,金币是否足够查看
        /// </summary>
        public ApiResult CanViewPlan(int id, int ltype, int uid, int coin)
        {
            //step1.查询用户是否点阅过该帖子
            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", uid),
                new SqlParameter("@Id", id),
            };

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

            if (objReadRecord != null && Convert.ToInt32(objReadRecord) > 0)
            {
                //已经点阅过,直接跳转
                return(new ApiResult());
            }
            UserInfo user = PersonalService.GetUser(uid);

            //step2.判断当前用户积分是否小于查看帖子所需金币
            if (coin > user.Coin)
            {
                return(new ApiResult(60015, "金币数不足"));
            }
            return(new ApiResult());
        }
Example #2
0
        /// <summary>
        /// 打赏
        /// </summary>
        public ApiResult GiftCoin(int id, int coin, long userId)
        {
            var user = PersonalService.GetUser(userId);

            #region 校验
            //step1.验证金币输入是否正确
            if (coin < 10)
            {
                return(new ApiResult(60016, "最低打赏10金币"));
            }
            //step2.验证帖子是否存在
            var model = Util.GetEntityById <BettingRecord>(id);
            if (model == null)
            {
                return(new ApiResult(60017, "该计划不存在"));
            }

            if (model.UserId == userId)
            {
                return(new ApiResult(60019, "不能打赏你自己"));
            }

            //step3.验证用户金币是否充足
            if (user.Coin < coin)
            {
                return(new ApiResult(60018, "金币余额不足"));
            }
            #endregion


            StringBuilder sqlBuilder = new StringBuilder();
            //step4.扣除打赏人账户金币
            sqlBuilder.AppendFormat("UPDATE dbo.UserInfo SET Coin-={1} WHERE Id={0};", user.Id, coin);
            //step5.添加打赏记录
            sqlBuilder.AppendFormat(@"INSERT INTO [dbo].[ComeOutRecord]([UserId],[OrderId],[Type] ,[Money],[State],[SubTime])
                                        VALUES({0},{1},{2},{3}, 1, GETDATE());", user.Id, id, (int)TransactionTypeEnum.打赏, coin);

            var userRateSetting = GetCommissionSetting().FirstOrDefault(x => x.LType == GetlType(model.lType) && x.Type == (int)CommissionTypeEnum.打赏佣金);
            if (userRateSetting != null && userRateSetting.Percentage > 0)
            {
                int commission = (int)(userRateSetting.Percentage * coin);
                //step6.发放发帖人金币账户
                sqlBuilder.AppendFormat("UPDATE dbo.UserInfo SET Money+={1} WHERE Id={0};", model.UserId, commission);
                //step7.添加打赏佣金记录
                sqlBuilder.AppendFormat(@"INSERT INTO [dbo].[ComeOutRecord]([UserId],[OrderId],[Type] ,[Money],[State],[SubTime])
                                            VALUES({0},{1},{2},{3}, 1, GETDATE());", user.Id, id, (int)TransactionTypeEnum.打赏佣金, commission);
            }

            //LogHelper.WriteLog(sqlBuilder.ToString());
            SqlHelper.ExecuteTransaction(sqlBuilder.ToString());

            return(new ApiResult(100, "打赏成功"));
        }
Example #3
0
        /// <summary>
        /// 插入搜索数据
        /// </summary>
        public ApiResult InsertHotSearch(long uid, int lType, long userId)
        {
            //ReturnMessageJson msg = new ReturnMessageJson();
            string countsql = string.Format("select count(1) from ExpertHotSearch where UserId ={0} and lType = {1}", uid, lType);
            int    count    = Convert.ToInt32(SqlHelper.ExecuteScalar(countsql));
            string strsql   = "";

            if (count > 0)
            {
                strsql = @"update ExpertHotSearch  set Count=Count+1 where UserId=@UserId and lType=@lType ";
            }
            else
            {
                strsql = @"insert into ExpertHotSearch(UserId, Count, lType)
                           values(@UserId,1,@lType)";
            }
            SqlParameter[] sp = new SqlParameter[] {
                new SqlParameter("@UserId", uid),
                new SqlParameter("@lType", lType)
            };

            int data = SqlHelper.ExecuteNonQuery(strsql, sp);

            if (data > 0)
            {
                List <ExpertSearchModel> list = new List <ExpertSearchModel>();

                long   MyUserId  = userId;
                string memberKey = string.Format(RedisKeyConst.Plan_ExpertHistory, lType, MyUserId);// "history_" + MyUserId + "_" + lType;
                list = CacheHelper.GetCache <List <ExpertSearchModel> >(memberKey) ?? new List <ExpertSearchModel>();

                UserInfo u = PersonalService.GetUser(uid);

                ExpertSearchModel e = new ExpertSearchModel();
                e.Avater   = u.Avater;
                e.UserId   = (int)uid;
                e.Name     = u.NickName;
                e.lType    = lType;
                e.isFollow = 0;
                if (list.Count > 0)
                {
                    ExpertSearchModel e1 = list.Where(x => x.UserId == uid && x.lType == lType).FirstOrDefault();
                    if (e1 == null)
                    {
                        list.Add(e);
                    }
                }
                else
                {
                    list.Add(e);
                }

                // CacheHelper.WriteCache(memberKey, list, 144000);
                CacheHelper.AddCache(memberKey, list, 144000);
                return(new ApiResult());
            }
            else
            {
                return(new ApiResult(-999, "数据库错误"));
            }
        }
Example #4
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
        }