//tag(string):SupplyGold
        //uid(string)
        //todayCount(int)
        //goldNum(int)
        public static void SendSupplyGold(string uid)
        {
            UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid);

            if (userInfo.Gold < 1500)
            {
                var config = NHibernateHelper.commonConfigManager.GetByUid(uid);
                if (config == null)
                {
                    config = ModelFactory.CreateConfig(uid);
                }
                if (config.free_gold_count > 0)
                {
                    userInfo.Gold += 2000;
                    config.free_gold_count--;
                    NHibernateHelper.commonConfigManager.Update(config);
                    NHibernateHelper.userInfoManager.Update(userInfo);

                    MySqlService.log.Info($"{uid}发放补助金");
                    //给logic服务器推送
                    IntPtr connId;
                    if (MySqlService.serviceDic.TryGetValue(TljServiceType.LogicService, out connId))
                    {
                        var jObject = new JObject();
                        jObject.Add(MyCommon.TAG, Consts.Tag_SupplyGold);
                        jObject.Add(MyCommon.UID, uid);
                        int temp = 0;
                        if (config.free_gold_count == 2)
                        {
                            temp = 1;
                        }
                        else if (config.free_gold_count == 1)
                        {
                            temp = 2;
                        }
                        else if (config.free_gold_count == 0)
                        {
                            temp = 3;
                        }
                        jObject.Add("todayCount", temp);
                        jObject.Add("goldNum", 2000);
                        MySqlService.Instance().sendMessage(connId, jObject.ToString());
                        MySqlService.log.Info($"主动发送给logic:{jObject.ToString()}");


                        //记录玩家财富变化日志
                        int afterGold  = userInfo.Gold;
                        int changeGold = 2000;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, "奖励金发放", afterGold - changeGold, changeGold, afterGold);
                    }
                }
            }
        }
        private bool AddYuanbao(Goods goods, UserInfo userInfo, int num, float price, string orderid)
        {
            string[] strings = goods.props.Split(':');
            int      propId  = Convert.ToInt32(strings[0]);
            int      propNum = Convert.ToInt32(strings[1]);

            if (propId == 2)
            {
                userInfo.YuanBao += propNum * num;
                //之前的vip等级
                int vipFirstLevel = VipUtil.GetVipLevel(userInfo.RechargeVip);

                userInfo.RechargeVip += goods.price * num;
                //充值之后的vip等级
                int vipLevel = VipUtil.GetVipLevel(userInfo.RechargeVip);
                if (NHibernateHelper.userInfoManager.Update(userInfo))
                {
                    //记录玩家财富变化日志
                    int after  = userInfo.YuanBao;
                    int change = propNum * num;
                    StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, "人民币购买元宝", after - change, change, after);
                    var format = string.Format("花费了{0}元,购买了{1}元宝,订单号:{2}", price, propNum * num, orderid);
                    LogUtil.Log(userInfo.Uid, MyCommon.OpType.BUYYUANBAO, format);

                    var result = vipLevel - vipFirstLevel;

                    //vip等级发生
                    if (result > 0)
                    {
                        for (int i = vipFirstLevel; i < vipLevel; i++)
                        {
                            var reward = $"1:{MySqlService.VipDatas[i].vipOnce.goldNum};{MySqlService.VipDatas[i].vipOnce.prop}";

                            //发送vip一次福利
                            SendEmailUtil.SendEmail(userInfo.Uid, $"贵族一次性福利", $"恭喜您升级到贵族{i + 1}", reward);

                            var temp = string.Format($"恭喜你升级到Vip{i + 1},发送邮件奖励:{reward}");
                            LogUtil.Log(userInfo.Uid, MyCommon.OpType.VIP_ONCE_REWARD, temp);
                        }

                        var level1 = GetLevel(vipFirstLevel);
                        var level2 = GetLevel(vipLevel);

                        userInfo.freeCount += level2 - level1;
                        MySqlService.log.Info($"{userInfo.Uid} vip等级变化:{result},加了转盘次数:{level2 - level1}");
                        NHibernateHelper.userInfoManager.Update(userInfo);
                    }
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
        private bool AddJinbi(Goods goods, UserInfo userInfo, int num, string reason, out string temp)
        {
            string[] strings = goods.props.Split(':');
            int      propId  = Convert.ToInt32(strings[0]);
            int      propNum = Convert.ToInt32(strings[1]);

            if (propId == 1)
            {
                temp           = propNum * num + "";
                userInfo.Gold += propNum * num;
                if (NHibernateHelper.userInfoManager.Update(userInfo))
                {
                    //记录玩家财富变化日志
                    int after  = userInfo.Gold;
                    int change = propNum * num;
                    StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, reason,
                                                  after - change, change, after);
                    return(true);
                }
            }

            temp = null;
            return(false);
        }
Beispiel #4
0
        //购买金币
        private bool BuyJin(Goods goods, int num, string uid, int moneyType)
        {
            bool     IsSuccess = false;
            int      sumPrice  = goods.price * num;
            UserInfo userInfo  = NHibernateHelper.userInfoManager.GetByUid(uid);

            switch (moneyType)
            {
            //元宝购买
            case 2:
                if (userInfo.YuanBao >= sumPrice)
                {
                    userInfo.YuanBao -= sumPrice;
                    //先扣钱,添加金币
                    MySqlService.log.Info("先扣钱,添加金币");
                    string temp = "";
                    if (NHibernateHelper.userInfoManager.Update(userInfo) &&
                        AddJinbi(goods, userInfo, num, "元宝购买金币", out temp))
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.YuanBao;
                        int change = -sumPrice;
                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, "元宝购买金币", after - change, change, after);


                        string s = string.Format("花费{0}元宝,购买了{1}个{2}", sumPrice, num, goods.goods_name);
                        LogUtil.Log(uid, MyCommon.OpType.BUYGOLD, s);
                        IsSuccess = true;
                    }
                }

                break;

            case 4:
                sumPrice = goods.price2 * num;

                if (userInfo.Medel >= sumPrice)
                {
                    userInfo.Medel -= sumPrice;
                    //先扣钱,添加金币
                    MySqlService.log.Info("先扣徽章,添加金币");
                    string temp = "";
                    if (NHibernateHelper.userInfoManager.Update(userInfo) && AddJinbi(goods, userInfo, num, "徽章购买金币", out temp))
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.Medel;
                        int change = -sumPrice;
                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.Medal, "徽章购买金币", after - change, change, after);

                        string s = string.Format("花费{0}徽章,购买了{1}个{2}", sumPrice, num, goods.goods_name);
                        LogUtil.Log(uid, MyCommon.OpType.BUYGOLD, s);
                        IsSuccess = true;
                    }
                }

                break;
            }


            return(IsSuccess);
        }
        /// <summary>
        /// 1.是金币,2.是话费,4徽章
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="propId">1,2...</param>
        /// <param name="propNum"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        public static bool ChangeProp(string uid, int propId, int propNum, string reason)
        {
            UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid);

            if (userInfo == null)
            {
                MySqlService.log.Warn("用户不存在");
                return(false);
            }

            if (propId == 1)
            {
                userInfo.Gold += propNum;
                if (userInfo.Gold <= 0)
                {
                    User user = NHibernateHelper.userManager.GetByUid(uid);
                    if (user.IsRobot == 1)
                    {
                        userInfo.Gold = new Random().Next(80000, 100000);
                    }
                    else
                    {
                        userInfo.Gold = 0;
                    }
                }

                if (userInfo.Gold >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn("添加金币失败");
                        return(false);
                    }
                    else
                    {
                        int afterGold  = userInfo.Gold;
                        int changeGold = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.GOLD, reason, afterGold - changeGold, changeGold, afterGold);

//                        string msg = $"改变了{propNum}金币";
//                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                    //发送奖励金;
                    SendSupplyGold(uid);
                }
                else
                {
                    MySqlService.log.Warn("金币不足");
                    return(false);
                }
            }
            else if (propId == 2)
            {
                userInfo.YuanBao += propNum;

                if (userInfo.YuanBao >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn("添加元宝失败");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.YuanBao;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.YUANBAO, reason, after - change, change, after);
                        //                        string msg = $"改变了{propNum}元宝";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    MySqlService.log.Warn("元宝不足");
                    return(false);
                }
            }
            else if (propId == 110)
            {
                userInfo.Medel += propNum;
                if (userInfo.Medel >= 0)
                {
                    if (!NHibernateHelper.userInfoManager.Update(userInfo))
                    {
                        MySqlService.log.Warn($"添加徽章失败-medal:{userInfo.Medel}-改变的数量:{propNum}");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = userInfo.Medel;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, MyCommon.Medal, reason, after - change, change, after);
                        //                        string msg = $"改变了{propNum}徽章";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    MySqlService.log.Warn($"徽章不足-medal:{userInfo.Medel}-改变的数量:{propNum}");
                    return(false);
                }
            }
            else
            {
                UserProp userProp = NHibernateHelper.userPropManager.GetUserProp(uid, propId);
                if (userProp == null)
                {
                    userProp = new UserProp()
                    {
                        Uid     = uid,
                        PropId  = propId,
                        PropNum = propNum
                    };
                    if (!NHibernateHelper.userPropManager.Add(userProp))
                    {
                        MySqlService.log.Warn($"添加道具失败-propId:{propId}-propNum:{propNum}");
                        return(false);
                    }
                    else
                    {
                        //记录玩家财富变化日志
                        int after  = propNum;
                        int change = propNum;

                        StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, propId + "", reason, after - change, change, after);
                        //                        string msg = $"改变了{propId}道具,{propNum}个";
                        //                        LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                    }
                }
                else
                {
                    userProp.PropNum += propNum;
                    if (userProp.PropNum >= 0)
                    {
                        if (!NHibernateHelper.userPropManager.Update(userProp))
                        {
                            MySqlService.log.Warn("更新道具失败");
                            return(false);
                        }
                        else
                        {
                            //记录玩家财富变化日志
                            int after  = userProp.PropNum;
                            int change = propNum;

                            StatictisLogUtil.ChangeWealth(userInfo.Uid, userInfo.NickName, propId + "", reason, after - change, change, after);
                            //string msg = $"改变了{propId}道具,{propNum}个";
                            //LogUtil.Log(uid, MyCommon.OpType.CHANGE_WEALTH, msg);
                        }
                    }
                    else
                    {
                        MySqlService.log.Warn("道具不足");
                        return(false);
                    }
                }
            }
            return(true);
        }