예제 #1
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            log4net.ILog log = log4net.LogManager.GetLogger("ColoredConsoleAppender");


            var info = RequestUserInfo.ParseFrom(requestInfo.Body);

            DAL.DAL.Business business = new DAL.DAL.Business();
            //获取用户积分消费卷信息
            IntegralInfo integralInfo = business.GetIntegralInfo(info.UserID);

            byte[] data = null;
            if (integralInfo == null)
            {
                log.Error("用户不存在");
                business.InsertIntegralInfo(info.UserID);
                data = ResponseUserInfo.CreateBuilder().SetUserID(info.UserID).SetRoomCard(0).SetIntegral(0).SetCoupons(0).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10041, data.Length, requestInfo.MessageNum, data)));
                session.Close();
                return;
            }
            data = ResponseUserInfo.CreateBuilder().SetUserID(integralInfo.userID).SetRoomCard((int)integralInfo.roomCard).SetIntegral((double)integralInfo.integral).SetCoupons((double)integralInfo.coupons).Build().ToByteArray();
            session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10041, data.Length, requestInfo.MessageNum, data)));
            session.Close();
            return;
        }
예제 #2
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            log4net.ILog log = log4net.LogManager.GetLogger("ColoredConsoleAppender");
            //  ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            var info = IntegralBusiness.ParseFrom(requestInfo.Body);

            DAL.DAL.Business business = new DAL.DAL.Business();



            //获取用户积分消费卷信息
            IntegralInfo integralInfo = business.GetIntegralInfo(info.UserID);

            if (integralInfo == null)
            {
                log.Error("用户不存在");
                business.InsertIntegralInfo(info.UserID);
                var data = Result.CreateBuilder().SetStatus(0).SetMessage("用户不存在").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, data.Length, requestInfo.MessageNum, data)));
                session.Close();
                return;
            }

            //获取业务信息
            BusinessModel businessInfo = business.SelectBusiness(info.BusinessID);

            if (businessInfo == null)
            {
                log.Error("该业务不存在");
                var data = Result.CreateBuilder().SetStatus(0).SetMessage("该业务不存在").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, data.Length, requestInfo.MessageNum, data)));
                session.Close();
                return;
            }


            //获取操作方式
            ActionModel actionInfo = business.SelectAction(businessInfo.action_id);

            // 处理业务 更新积分信息并返回
            integralInfo = business.UpdateIntegralInfo(info.UserID, businessInfo.type, actionInfo, info.Counts);
            log.Info("更新成功");
            var dataResult = Result.CreateBuilder().SetStatus(1).SetMessage("更新成功").Build().ToByteArray();

            session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, dataResult.Length, requestInfo.MessageNum, dataResult)));
            session.Send("更新成功");

            //写入日志
            var logModel = new LogModel
            {
                userID   = info.UserID,
                action   = actionInfo.title,
                business = businessInfo.tittle,
                type     = businessInfo.type,
                count    = info.Counts,
                dateTime = DateTime.Now,
            };

            business.WriteLog(logModel);
        }
예제 #3
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            log4net.ILog log = log4net.LogManager.GetLogger("ColoredConsoleAppender");
            //  ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

            var info = RoomCardBusiness.ParseFrom(requestInfo.Body);

            DAL.DAL.Business business = new DAL.DAL.Business();


            //获取用户积分消费卷信息
            IntegralInfo integralInfo = business.GetIntegralInfo(info.UserID);

            if (integralInfo == null)
            {
                log.Error("用户不存在");
                business.InsertIntegralInfo(info.UserID);
                var data = ResponseUserInfo.CreateBuilder().SetUserID(info.UserID).SetRoomCard(0).SetIntegral(0).SetCoupons(0).Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10041, data.Length, requestInfo.MessageNum, data)));
                session.Close();
                return;
            }
            #region 以前代码 可能有用
            ////获取业务信息
            //BusinessModel businessInfo = business.SelectBusiness(info.BusinessID);
            //if (businessInfo == null)
            //{

            //    log.Error("该业务不存在");
            //    var data = Result.CreateBuilder().SetStatus(0).SetMessage("该业务不存在").Build().ToByteArray();
            //    session.Send(new ArraySegment<byte>(CreateHead.CreateMessage(10001, data.Length, requestInfo.MessageNum, data)));
            //    session.Close();
            //    return;
            //}


            ////获取操作方式
            //ActionModel actionInfo = business.SelectAction(businessInfo.action_id);


            ////判断余额是否充足
            //if (actionInfo.action=="-")
            //{
            //    if (business.GetIntegralInfo(info.UserID, businessInfo.type) - info.Counts < 0)
            //    {
            //        var data = Result.CreateBuilder().SetStatus(0).SetMessage("当前余量不足").Build().ToByteArray();
            //        session.Send(new ArraySegment<byte>(CreateHead.CreateMessage(10001, data.Length, requestInfo.MessageNum, data)));
            //        session.Close();
            //        return;
            //    }

            //}
            //integralInfo = business.UpdateIntegralInfo(info.UserID, businessInfo.type, actionInfo, info.Counts);
            #endregion
            // 处理业务 更新积分信息并返回

            decimal newRoomCard = integralInfo.roomCard - info.Counts;

            if (newRoomCard < 0)
            {
                var data = Result.CreateBuilder().SetStatus(0).SetMessage("当前余量不足").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, data.Length, requestInfo.MessageNum, data)));
                session.Close();
                return;
            }

            bool reslut = business.UpdataRoomCard(info.UserID, newRoomCard);
            if (!reslut)
            {
                var dataResult1 = Result.CreateBuilder().SetStatus(0).SetMessage("更新失败").Build().ToByteArray();
                session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, dataResult1.Length, requestInfo.MessageNum, dataResult1)));
                session.Close();
                return;
            }


            log.Info("更新成功");
            var dataResult = Result.CreateBuilder().SetStatus(1).SetMessage("更新成功").Build().ToByteArray();
            session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(10001, dataResult.Length, requestInfo.MessageNum, dataResult)));
            //session.Send("更新成功");

            //写入日志
            //var logModel = new LogModel
            //{
            //    userID = info.UserID,
            //    action = info.BusinessID,
            //    business = info.BusinessID,
            //    type = info.BusinessID,
            //    count = info.Counts,
            //    dateTime = DateTime.Now,
            //};
            //business.WriteLog(logModel);
        }