Example #1
0
        public bool ProcessChatCash(UserInfo userInfo, RoomInfo roomInfo, bool bMeeting)
        {
            //List<UserInfo> users = Users.GetInstance().GetRoomUsers(roomInfo.Id);

            //if (users == null)
            //{
            //    ErrorView.AddErrorString();
            //    return false;
            //}

            //bool bUpdate = false;

            //for (int i = 0; i < users.Count; i++)
            //{
            //    UserInfo userInfo = users[i];

            if (userInfo.Kind == (int)UserKind.Manager ||
                userInfo.Kind == (int)UserKind.ServiceWoman ||
                userInfo.Kind == (int)UserKind.ServiceOfficer)
            {
                return(true);
            }

            //bUpdate = true;

            if (roomInfo.Cash > 0)
            {
                if (GiveChatSum(userInfo.Id, -roomInfo.Cash) == false)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                if (userInfo.Auto > 0)
                {
                    return(true);
                }

                //GiveChatSum(userInfo.Id, -roomInfo.Cash);

                if (bMeeting == true)
                {
                    userInfo.CashTime = userInfo.CashTime.AddMinutes(1);
                }
                else
                {
                    userInfo.CashTime = userInfo.CashTime.AddYears(1);
                }

                UserInfo servicer       = Database.GetInstance().FindUser(roomInfo.Owner);
                UserInfo serviceOfficer = Database.GetInstance().FindUser(servicer.Recommender); // Database.GetInstance().GetManager(UserKind.ServiceOfficer);
                UserInfo manager        = Database.GetInstance().GetManager(UserKind.Manager)[0];

                int servicePercent        = servicer.ChatPercent;
                int serviceOfficerPercent = serviceOfficer.ChatPercent;

                if (servicePercent > 100)
                {
                    servicePercent = 100;
                }

                if (serviceOfficerPercent > 100)
                {
                    serviceOfficerPercent = 100;
                }

                if (servicePercent > serviceOfficerPercent)
                {
                    servicePercent = serviceOfficerPercent;
                }

                serviceOfficerPercent -= servicePercent;

                int serviceCash        = ProcessCashPercent(servicer, servicePercent, roomInfo.Cash);
                int serviceOfficerCash = ProcessCashPercent(serviceOfficer, serviceOfficerPercent, roomInfo.Cash);
                int managerCash        = roomInfo.Cash - serviceOfficerCash - serviceCash;

                if (servicer != null)
                {
                    GiveChatSum(servicer.Id, serviceCash);
                }

                if (serviceOfficer != null)
                {
                    GiveChatSum(serviceOfficer.Id, serviceOfficerCash);
                }

                GiveChatSum(manager.Id, managerCash);

                ChatHistoryInfo chatHistoryInfo = Database.GetInstance().FindChatHistory(userInfo.ChatHistoryId);

                if (chatHistoryInfo != null)
                {
                    chatHistoryInfo.OfficerId = serviceOfficer.Id;
                    chatHistoryInfo.ManagerId = manager.Id;

                    chatHistoryInfo.BuyerTotal          -= roomInfo.Cash;
                    chatHistoryInfo.ServicemanTotal     += serviceCash;
                    chatHistoryInfo.ServiceOfficerTotal += serviceOfficerCash;
                    chatHistoryInfo.ManagerTotal        += managerCash;
                    chatHistoryInfo.EndTime              = DateTime.Now;

                    Database.GetInstance().UpdateChatHistory(chatHistoryInfo);
                }

                View._isUpdateRoomList = true;
            }

            if (roomInfo.Point > 0)
            {
                if (userInfo.Point < roomInfo.Point)
                {
                    SetError(ErrorType.Notenough_Point, string.Format("因{0}的账号余额不足 退出聊天频道.", userInfo.Id));
                    Main.ReplyError(userInfo.Socket);

                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                UserInfo updateInfo = Database.GetInstance().FindUser(userInfo.Id);

                if (updateInfo == null)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                updateInfo.Point -= roomInfo.Point;

                if (Database.GetInstance().UpdateUser(updateInfo) == false)
                {
                    Chat.GetInstance().OutMeeting(userInfo.Socket, roomInfo);
                    return(false);
                }

                userInfo.Point = updateInfo.Point;

                PointHistoryInfo pointHistoryInfo = Database.GetInstance().FindPointHistory(userInfo.PointHistoryId);

                if (pointHistoryInfo != null)
                {
                    pointHistoryInfo.Point    -= roomInfo.Point;
                    pointHistoryInfo.AgreeTime = DateTime.Now;

                    Database.GetInstance().UpdatePointHistory(pointHistoryInfo);
                }

                userInfo.CashTime = userInfo.CashTime.AddMinutes(1);

                View._isUpdateUserList = true;
                View._isUpdateRoomList = true;
            }
            //}

            //if( bUpdate == true )
            Chat.GetInstance().ReplyRoomDetailInfo(roomInfo.Id);

            return(true);
        }