private void GetAllTuiGuangReward(string uid, JObject jObject) { List <UserExtend> userExtends = MySqlManager <UserExtend> .Instance.GetMyExtendDataByUid(uid).ToList(); StringBuilder sb = new StringBuilder(); foreach (var userExtend in userExtends) { if (userExtend.task1 == 2) { MySqlUtil.AddProp(uid, "121:1", $"领取{userExtend.Uid}的任务1奖励"); sb.Append("121:1"); sb.Append(";"); userExtend.task1 = 3; } if (userExtend.task2 == 2) { MySqlUtil.AddProp(uid, "111:1", $"领取{userExtend.Uid}的任务2奖励"); sb.Append("111:1"); sb.Append(";"); userExtend.task2 = 3; } MySqlManager <UserExtend> .Instance.Update(userExtend); } jObject.Add("reward", sb.ToString()); jObject.Add(MyCommon.CODE, (int)Consts.Code.Code_OK); }
/// <summary> /// 加赠元宝 /// </summary> /// <param name="uid"></param> /// <param name="goods"></param> private void AddExtraYuanBao(string uid, Goods goods) { //更新userRecharge数据 var userRecharge = NHibernateHelper.userRechargeManager.GetUserRecharge(uid, goods.goods_id); if (userRecharge == null) { userRecharge = ModelFactory.CreateUserRecharge(uid, goods.goods_id); } //首次充值,加送元宝 if (userRecharge.recharge_count == 0) { if (!string.IsNullOrWhiteSpace(goods.extra_reward)) { if (MySqlUtil.AddProp(uid, goods.extra_reward, "元宝加赠")) { LogUtil.Log(uid, MyCommon.OpType.EXTRA_YUANBAO, $"购买了{goods.goods_id},{goods.goods_name},加赠了{goods.extra_reward}"); } else { MySqlService.log.Warn($"{uid},{goods.goods_id} 加赠元宝失败,数据库内部错误"); } } } userRecharge.recharge_count++; NHibernateHelper.userRechargeManager.Update(userRecharge); }
private void Get51ActivityRewardSql(string uid, int id, JObject responseData) { List <string> loginLists = new List <string>(); for (int i = 0; i < MySqlService.activity51Datas.Count; i++) { Activity51Data activity51Data = MySqlService.activity51Datas[i]; List <Log_Login> loginByDate = MySqlManager <Log_Login> .Instance.GetLoginByDate(uid, activity51Data.Time); //当天登陆过 if (loginByDate.Count > 0) { loginLists.Add(activity51Data.Time); } } MySqlService.log.Warn($"id:{id},count:{loginLists.Count}"); if (id > loginLists.Count) { OperatorFail(responseData, "未达到天数要求"); } else { if (MySqlManager <UserActivity51> .Instance.Add(new UserActivity51() { Uid = uid, activity_id = id })) { Activity51Data activity51Data = new Activity51Data(); foreach (var item in MySqlService.activity51Datas) { if (item.Id == id) { activity51Data = item; break; } } MySqlUtil.AddProp(uid, activity51Data.Reward, "51活动"); OperatorSuccess(responseData, activity51Data.Reward); } else { OperatorFail(responseData, "奖励已领取"); } } }
private void OneKeyReadEmailSql(string uid, JObject responseData) { //得到未读取的邮件 List <UserEmail> userEmails = NHibernateHelper.userEmailManager.GetListByUid(uid).OrderByDescending(i => i.CreateTime).Take(50).ToList(); if (userEmails == null) { MySqlService.log.Warn("没有未读取的邮件"); OperatorFail(responseData); return; } int temp = 0; temp = userEmails.Count >= 50 ? 50 : userEmails.Count; for (int i = 0; i < temp; i++) { var email = userEmails[i]; //没有奖励的不能一键读取 if (string.IsNullOrWhiteSpace(email.Reward)) { continue; } if (email.State == 0) { email.State = 1; if (!string.IsNullOrWhiteSpace(email.Reward)) { bool addProp = MySqlUtil.AddProp(uid, email.Reward, "读邮件"); if (!addProp) { MySqlService.log.Warn("读邮件加道具失败:" + uid + " " + email.Reward); } } if (!NHibernateHelper.userEmailManager.Update(email)) { MySqlService.log.Warn("读取失败"); OperatorFail(responseData); return; } } } OperatorSuccess(responseData); }
private void BindCode(string uid, string code, JObject responseData) { UserInfo userInfo = MySqlManager <UserInfo> .Instance.GetUserInfoByCode(code); if (userInfo == null) { OperatorFail(responseData, "该推广码不存在"); } else { UserExtend userExtend = MySqlManager <UserExtend> .Instance.GetByUid(uid); if (userExtend != null) { OperatorFail(responseData, "您已绑定推广码"); } else { if (userInfo.Uid == uid) { OperatorFail(responseData, "不能绑定自己的推广码"); return; } userExtend = new UserExtend() { Uid = uid, extend_uid = userInfo.Uid, task1 = 1, task2 = 1 }; if (MySqlManager <UserExtend> .Instance.Add(userExtend)) { responseData.Add("reward", "121:1"); MySqlUtil.AddProp(uid, "121:1", "绑定推广码奖励"); OperatorSuccess(responseData, "绑定成功"); } else { OperatorFail(responseData, "添加数据失败"); } } } }
/// <summary> /// 查询签到数据库 /// </summary> /// <param name="signUid"></param> /// <param name="responseData"></param> private void SignSql(string signUid, JObject responseData) { Sign signByUid = NHibernateHelper.signManager.GetByName(signUid); if (signByUid == null) { OperatorFail(responseData); MySqlService.log.Warn("传入的uid有误"); } else { DateTime updateTime = signByUid.UpdateTime; int updateTimeYear = updateTime.Year; int updateTimeMonth = updateTime.Month; int updateTimeDay = updateTime.Day; int nowYear = DateTime.Now.Year; int nowMonth = DateTime.Now.Month; int nowDay = DateTime.Now.Day; //已经签到过了,不能签到 if (updateTimeYear == nowYear && updateTimeMonth == nowMonth && updateTimeDay == nowDay && signByUid.SignWeekDays != 0) { OperatorFail(responseData); MySqlService.log.Warn("已签到:" + signUid); } //未签到,可以签到 else { SignConfig signConfig = MySqlService.SignConfigs[signByUid.SignWeekDays]; signByUid.SignWeekDays++; signByUid.UpdateTime = DateTime.Now; MySqlService.log.Info(signConfig.goods_prop); if (NHibernateHelper.signManager.Update(signByUid) && MySqlUtil.AddProp(signUid, signConfig.goods_prop, "签到奖励")) { OperatorSuccess(responseData); } else { OperatorFail(responseData); } } } }
private void CompleteTaskSql(int task_id, string uid, JObject responseData) { UserTask userTask = NHibernateHelper.userTaskManager.GetUserTask(uid, task_id); if (userTask == null) { var user = NHibernateHelper.userManager.GetByUid(uid); if (user.IsRobot != 1) { MySqlService.log.Warn($"没有该用户的任务:{uid}"); OperatorFail(responseData); } } else { if (userTask.isover == 0) { Task task = NHibernateHelper.taskManager.GetTask(task_id); if (userTask.progress == task.target) { userTask.isover = 1; if (NHibernateHelper.userTaskManager.Update(userTask) && MySqlUtil.AddProp(uid, task.reward, "领取任务")) { OperatorSuccess(responseData); } else { MySqlService.log.Warn("更新任务奖励数据库失败"); OperatorFail(responseData); } } else { MySqlService.log.Warn("任务未完成"); OperatorFail(responseData); } } else { MySqlService.log.Warn("任务奖励已领取"); OperatorFail(responseData); } } }
private void ExchangeTeleFarePiece(string uid, int duihuanId, JObject responseData) { TeleFarePieceData pieceData = null; foreach (var data in MySqlService.teleFarePieceDatas) { if (data.duihuan_id == duihuanId) { pieceData = data; break; } } if (pieceData == null) { OperatorFail(responseData, $"兑换id有误:{duihuanId}"); } else { UserProp userProp = MySqlManager <UserProp> .Instance.GetUserProp(uid, pieceData.material_id); if (userProp == null) { OperatorFail(responseData, $"材料不足"); } else { if (userProp.PropNum < pieceData.material_num) { OperatorFail(responseData, $"材料不足:{ pieceData.material_num}"); } else { userProp.PropNum -= pieceData.material_num; MySqlManager <UserProp> .Instance.Update(userProp); string propReward = pieceData.Synthesis_id + ":" + pieceData.Synthesis_num; MySqlUtil.AddProp(uid, propReward, "话费碎片兑换"); OperatorSuccess(responseData, "兑换成功"); } } } }
private void ReadEmailSql(int emailId, string uid, JObject responseData) { UserEmail userEmail = NHibernateHelper.userEmailManager.GetEmail(emailId, uid); if (userEmail == null) { MySqlService.log.Warn("该邮件不存在"); OperatorFail(responseData); } else { //未读 if (userEmail.State == 0) { userEmail.State = 1; if (!string.IsNullOrWhiteSpace(userEmail.Reward)) { bool addProp = MySqlUtil.AddProp(uid, userEmail.Reward, "领取邮件奖励"); if (!addProp) { MySqlService.log.Warn("读邮件加道具失败:" + uid + " " + userEmail.Reward); } } if (NHibernateHelper.userEmailManager.Update(userEmail)) { OperatorSuccess(responseData); } else { MySqlService.log.Warn("读邮件失败"); OperatorFail(responseData); } } else { MySqlService.log.Warn("该邮件已读过"); OperatorFail(responseData); } } }
private void MedalExchange(string uid, int goodsId, int num, JObject responseData) { try { MedalExchargeRewardData exchargeRewardData = null; foreach (var medalExchargeRewardData in MySqlService.medalExchargeRewardDatas) { if (medalExchargeRewardData.goods_id == goodsId) { exchargeRewardData = medalExchargeRewardData; break; } } if (exchargeRewardData == null) { OperatorFail(responseData, "goodsId:" + goodsId); return; } int cost = exchargeRewardData.price * num; UserInfo userInfo = MySqlManager <UserInfo> .Instance.GetByUid(uid); if (userInfo.Medel < cost) { OperatorFail(responseData, "徽章不足"); } else { //徽章限额 List <UserExchange> medalLimitMonth = MySqlManager <UserExchange> .Instance.GetMedalLimitMonth(uid); int total = 0; foreach (var exchange in medalLimitMonth) { total += exchange.medal_cost; } if (total >= 300) { OperatorFail(responseData, $"当月已达限额300,已花费{total}"); return; } UserInfo info = MySqlManager <UserInfo> .Instance.GetByUid(uid); int vipLevel = VipUtil.GetVipLevel(info.RechargeVip); if (vipLevel < exchargeRewardData.vipLevel) { OperatorFail(responseData, "贵族等级不足"); return; } string reward = $"110:{-cost}"; string curYearMonth = CommonUtil.getCurYearMonth(); string day = curYearMonth + "/" + DateTime.Now.Day; List <JDCard> tenJDCard = MySqlManager <JDCard> .Instance.GetByPorperty("price", "10", "state", "0"); List <JDCard> twentyJDCard = MySqlManager <JDCard> .Instance.GetByPorperty("price", "20", "state", "0"); //判断是否兑换京东卡 if (exchargeRewardData.goods_id == 4) { if (tenJDCard.Count == 0) { OperatorFail(responseData, "10元京东卡数量不足"); return; } } if (exchargeRewardData.goods_id == 5) { if (twentyJDCard.Count == 0) { OperatorFail(responseData, "20元京东卡数量不足"); return; } } if (MySqlManager <UserExchange> .Instance.Add(new UserExchange() { Uid = uid, goods_id = goodsId, num = num, day = day, medal_cost = cost, create_time = DateTime.Now })) { for (int i = 0; i < num; i++) { MySqlUtil.AddProp(uid, exchargeRewardData.reward_prop, "徽章兑换话费"); } if (MySqlUtil.AddProp(uid, reward, "徽章兑换话费")) { responseData.Add("reward", exchargeRewardData.reward_prop); OperatorSuccess(responseData, "兑换成功"); switch (exchargeRewardData.goods_id) { case 4: tenJDCard[0].state = 1 + ""; tenJDCard[0].Uid = uid; MySqlManager <JDCard> .Instance.Update(tenJDCard[0]); break; case 5: twentyJDCard[0].state = 1 + ""; twentyJDCard[0].Uid = uid; MySqlManager <JDCard> .Instance.Update(twentyJDCard[0]); break; } } else { OperatorFail(responseData, "该道具已兑换,当天只能兑换一次"); } } else { OperatorFail(responseData, "该道具已兑换,当天只能兑换一次"); } } } catch (Exception e) { OperatorFail(responseData, "goodsId:" + goodsId); MySqlService.log.Warn(e); } }
private void AddSignReward(string uid, string dataContentRewardProp) { MySqlUtil.AddProp(uid, dataContentRewardProp, "每月签到奖励"); }
private bool BuyProp(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 1: MySqlUtil.ConfigExpenseGold(uid, sumPrice); if (userInfo.Gold >= sumPrice) { userInfo.Gold -= sumPrice; //先扣钱,添加道具 string cost = $"1:{-sumPrice}"; if (MySqlUtil.AddProp(uid, cost, "金币购买道具")) { string[] strings = goods.props.Split(':'); string props = strings[0] + ":" + int.Parse(strings[1]) * num; if (!MySqlUtil.AddProp(uid, props, "金币购买道具")) { return(false); } string s = string.Format("花费{0}金币,购买了{1}个{2}", sumPrice, num, goods.goods_name); LogUtil.Log(uid, MyCommon.OpType.BUYPROP, s); IsSuccess = true; } // if (NHibernateHelper.userInfoManager.Update(userInfo)) // { // for (int i = 0; i < num; i++) // { // if (!AddProp(goods, uid)) // { // return false; // } // } // string s = string.Format("花费{0}金币,购买了{1}个{2}", sumPrice, num, goods.goods_name); // LogUtil.Log(uid, MyCommon.OpType.BUYPROP, s); // IsSuccess = true; // } } break; //元宝付款 case 2: if (userInfo.YuanBao >= sumPrice) { userInfo.YuanBao -= sumPrice; //先扣钱,添加道具 string cost = $"2:{-sumPrice}"; if (MySqlUtil.AddProp(uid, cost, "元宝购买道具")) { string[] strings = goods.props.Split(':'); string props = strings[0] + ":" + int.Parse(strings[1]) * num; if (!MySqlUtil.AddProp(uid, props, "元宝购买道具")) { return(false); } string s = string.Format("花费{0}元宝,购买了{1}个{2}", sumPrice, num, goods.goods_name); LogUtil.Log(uid, MyCommon.OpType.BUYPROP, s); IsSuccess = true; } } break; //徽章付款 case 4: sumPrice = goods.price2 * num; if (userInfo.Medel >= sumPrice) { userInfo.Medel -= sumPrice; //先扣钱,添加道具 string cost = $"110:{-sumPrice}"; if (MySqlUtil.AddProp(uid, cost, "徽章购买道具")) { string[] strings = goods.props.Split(':'); string props = strings[0] + ":" + int.Parse(strings[1]) * num; if (!MySqlUtil.AddProp(uid, props, "徽章购买道具")) { return(false); } string s = string.Format("花费{0}元宝,购买了{1}个{2}", sumPrice, num, goods.goods_name); LogUtil.Log(uid, MyCommon.OpType.BUYPROP, s); IsSuccess = true; } } break; } return(IsSuccess); }
private void UseTurnTableDataSql(string uid, int type, bool isIosCheck, JObject responseData) { UserInfo userInfo = NHibernateHelper.userInfoManager.GetByUid(uid); bool isSuccess = false; int subHuiZhangNum = 0; int reward = 0; if (type == 1) { reward = GetProbabilityReward(MySqlService.FreeTurnTables); if (userInfo.freeCount <= 0) { MySqlService.log.Warn($"{uid},转盘免费使用次数不足,当前{userInfo.freeCount}"); isSuccess = false; } else { if (userInfo.luckyValue >= 98) { reward = 10; userInfo.luckyValue = 0; } userInfo.freeCount--; userInfo.luckyValue++; if (NHibernateHelper.userInfoManager.Update(userInfo)) { TurnTable turnTable; MySqlService.log.Info($"{uid} 增加:{reward}"); List <Log_Change_Wealth> logChangeWealths = MySqlManager <Log_Change_Wealth> .Instance.GetLogByReason(uid, "免费转盘抽奖"); //TODO 转盘概率和第一次得,以后不得 bool isFirst = false; foreach (var logWealth in logChangeWealths) { if (logWealth.type == "120") { isFirst = true; break; } } MySqlService.log.Info($"isfirst:{isFirst},reward:{reward}"); while (isFirst && reward == 6) { MySqlService.log.Info($"我循环···"); reward = GetProbabilityReward(MySqlService.FreeTurnTables); } MySqlService.log.Info($"isfirst:{isFirst},reward:{reward}"); //第三次不得 // if (logChangeWealths?.Count == 2) // { // if (logChangeWealths[0].type != "120" && logChangeWealths[1].type != "120") // { // reward = 6; // } // } if (reward == 10) { reward = 1; turnTable = MySqlService.MedalTurnTables[reward - 1]; reward = 51; } else { turnTable = MySqlService.FreeTurnTables[reward - 1]; } MySqlService.log.Info($"{uid} 增加转盘奖励{turnTable.reward}"); bool addProp = MySqlUtil.AddProp(uid, turnTable.reward, "免费转盘抽奖"); if (addProp) { isSuccess = true; } else { isSuccess = false; } } } } else if (type == 2) { reward = GetProbabilityReward(MySqlService.MedalTurnTables); if (userInfo.huizhangCount > 0) { if (userInfo.huizhangCount == 3) { subHuiZhangNum = 3; } else if (userInfo.huizhangCount == 2) { subHuiZhangNum = 5; } else if (userInfo.huizhangCount == 1) { subHuiZhangNum = 10; } else { subHuiZhangNum = 10; } if (userInfo.Medel >= subHuiZhangNum) { if (userInfo.luckyValue >= 98) { reward = 1; userInfo.luckyValue = 0; } userInfo.huizhangCount--; userInfo.Medel -= subHuiZhangNum; userInfo.luckyValue++; if (NHibernateHelper.userInfoManager.Update(userInfo)) { TurnTable turnTable; turnTable = MySqlService.MedalTurnTables[reward - 1]; MySqlService.log.Info($"{uid} 增加转盘奖励{turnTable.reward}"); bool addProp = MySqlUtil.AddProp(uid, turnTable.reward, "徽章转盘抽奖"); if (addProp) { isSuccess = true; reward += 50; } else { isSuccess = false; } } } } else { MySqlService.log.Warn($"{uid},转盘徽章使用次数不足,当前{userInfo.huizhangCount}"); } } if (isSuccess) { OperatorSuccess(uid, reward, subHuiZhangNum, userInfo.NickName, responseData); } else { OperatorFail(responseData); } }