/// <summary> /// 积分变动 /// </summary> /// <param name="openId"></param> /// <param name="score"></param> /// <returns></returns> public bool Update(string websiteOwner, string openId, double score, string remark, out string msg, string serialNumber = "") { msg = ""; ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { score = Math.Ceiling(score); UserInfo userInfo = bllUser.GetUserInfoByOpenId(openId); if (userInfo == null && (websiteOwner == "dongwu" || websiteOwner == "dongwudev")) { userInfo = bllUser.CreateNewUser(websiteOwner, openId, ""); } if (userInfo == null) { //创建新用户 msg = "openid不存在"; return(false); } if ((userInfo.TotalScore + score) < 0) { msg = "积分不足"; return(false); } StringBuilder sbSql = new StringBuilder(); double historyTotalScore = 0; if (score > 0) { historyTotalScore = score; } if (string.IsNullOrEmpty(remark)) { remark = string.Format("积分变动,变动值{0}", score); } sbSql.AppendFormat(" Update ZCJ_UserInfo Set TotalScore+={0},HistoryTotalScore+={1} Where WxOpenId='{2}' And WebsiteOwner='{3}' ;", score, historyTotalScore, openId, userInfo.WebsiteOwner);//积分变动 sbSql.AppendFormat(" Insert Into ZCJ_UserScoreDetailsInfo (UserID,OpenId,Score,AddTime,AddNote,ScoreType,WebSiteOwner,SerialNumber) values('{0}','{1}',{2},'{3}','{4}','{5}','{6}','{7}');", userInfo.UserID, openId, score, DateTime.Now.ToString(), remark, "Update", userInfo.WebsiteOwner, serialNumber); if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sbSql.ToString(), tran) < 2) { msg = "操作失败"; tran.Rollback(); return(false); } #region 日志记录 BLLApiLog bllApiLog = new BLLApiLog(); if (!bllApiLog.Add(userInfo.WebsiteOwner, Enums.EnumApiModule.Score, string.Format("积分变动,变动值{0}", score), userInfo.WXOpenId, userInfo.UserID, serialNumber)) { msg = "日志记录失败"; tran.Rollback(); return(false); } #endregion tran.Commit(); return(true); } catch (Exception ex) { msg = ex.ToString(); tran.Rollback(); } return(false); }
/// <summary> /// 积分事件触发 /// </summary> /// <param name="websiteOwner">站点所有者</param> /// <param name="openId">openId</param> /// <param name="value">原始值</param> /// <param name="scoreEvent">事件名称</param> /// <param name="remark">备注</param> /// <param name="msg">提示信息</param> /// <param name="addScore">增加积分</param> /// <param name="showName">显示名称</param> /// <returns></returns> public bool EventUpdate(string websiteOwner, string openId, decimal value, string scoreEvent, string remark, out string msg, out int addScore, string showName = "", string serialNumber = "") { int score = 0;//最终添加的积分 addScore = 0; msg = "";//返回消息 BLLApiLog bllApiLog = new BLLApiLog(); BLLScoreDefine bllScoreDefine = new BLLScoreDefine(); ScoreDefineInfo scoreDefineInfo = bllScoreDefine.GetScoreDefineInfoByScoreEvent(scoreEvent, WebsiteOwner); if (scoreDefineInfo == null) { msg = "积分规则不存在,请检查"; return(false); } if (scoreDefineInfo.IsHide == 1) { msg = "积分规则已停用"; return(false); } UserInfo userInfo = bllUser.GetUserInfoByOpenId(openId); if (userInfo == null && (websiteOwner == "dongwu" || websiteOwner == "dongwudev")) { userInfo = bllUser.CreateNewUser(websiteOwner, openId, showName); } if (userInfo == null) { msg = "openid不存在,请检查"; return(false); } List <ScoreDefineInfoExt> scoreDefineEx = bllScoreDefine.GetScoreDefineExList(scoreDefineInfo.ScoreId); //优先级: 扩展->基本比例-一般 if (scoreDefineEx != null && scoreDefineEx.Count > 0) { DateTime dtNow = DateTime.Now; var item = scoreDefineEx.FirstOrDefault(p => p.BeginTime <= DateTime.Now && p.EndTime >= DateTime.Now); if (item != null) { //score = (double)Math.Round(value / (item.RateValue / item.RateScore), 2); score = (int)Math.Ceiling(value / (item.RateValue / item.RateScore)); } } if (score == 0) { if (scoreDefineInfo.BaseRateScore > 0 && scoreDefineInfo.BaseRateValue > 0)//基础比例 { //score = (double)Math.Round(value / (scoreDefineInfo.BaseRateValue / scoreDefineInfo.BaseRateScore), 2); score = (int)Math.Ceiling(value / (scoreDefineInfo.BaseRateValue / scoreDefineInfo.BaseRateScore)); } } if (score == 0) { score = (int)scoreDefineInfo.Score; } //if (score == 0) //{ // msg = "增加积分不能为0"; // return false; //} if (scoreDefineInfo.DayLimit > 0) { double nTotal = bllUser.GetUserDayScoreSUMEvent(userInfo.UserID, scoreEvent, true); if (scoreDefineInfo.DayLimit < nTotal + score) { msg = scoreDefineInfo.ScoreEvent + "每日所得积分超限制"; return(false); } } if (scoreDefineInfo.TotalLimit > 0) { double nTotal = bllUser.GetUserDayScoreSUMEvent(userInfo.UserID, scoreEvent, false); if (scoreDefineInfo.TotalLimit < nTotal + score) { msg = scoreDefineInfo.ScoreEvent + "所得总积分超限制"; return(false); } } //积分记录 UserScoreDetailsInfo scoreModel = new UserScoreDetailsInfo(); scoreModel.AddNote = !string.IsNullOrEmpty(remark) ? remark : scoreDefineInfo.Description; scoreModel.AddTime = DateTime.Now; scoreModel.Score = score; scoreModel.UserID = userInfo.UserID; scoreModel.OpenId = userInfo.WXOpenId; scoreModel.ScoreType = scoreDefineInfo.ScoreType; scoreModel.WebSiteOwner = WebsiteOwner; scoreModel.ScoreEvent = scoreEvent; scoreModel.SerialNumber = serialNumber; BLLTransaction tran = new BLLTransaction(); try { int historyTotalScore = 0; if (score > 0) { historyTotalScore = score; } string sql = string.Format("TotalScore+={0},HistoryTotalScore+={1}", score, historyTotalScore); if (!string.IsNullOrEmpty(showName)) { sql += string.Format(",TrueName='{0}'", showName); } if (Update(userInfo, sql, string.Format(" AutoId={0}", userInfo.AutoID), tran) == 1 && Add(scoreModel, tran)) { #region 日志记录 if (!bllApiLog.Add(userInfo.WebsiteOwner, Enums.EnumApiModule.ScoreEvent, string.Format("积分事件,事件名称:{0}原始值{1}积分值:{2}", scoreDefineInfo.ScoreEvent, value, score), userInfo.WXOpenId, userInfo.UserID, serialNumber)) { msg = "日志记录失败"; tran.Rollback(); return(false); } #endregion tran.Commit(); addScore = score; return(true); } else { msg = "操作失败"; tran.Rollback(); return(false); } } catch (Exception ex) { msg = ex.ToString(); tran.Rollback(); return(false); } }
/// <summary> /// 积分转移 /// </summary> /// <param name="fromOpenId">原OpenId</param> /// <param name="toOpenId">新OpenId</param> /// <returns></returns> public bool Move(string websiteOwner, string fromOpenId, string toOpenId, out string msg, string serialNumber, string remark = "") { msg = ""; UserInfo fromUserInfo = bllUser.GetUserInfoByOpenId(fromOpenId); if (fromUserInfo == null && (websiteOwner == "dongwu" || websiteOwner == "dongwudev")) { fromUserInfo = bllUser.CreateNewUser(websiteOwner, fromOpenId, ""); } if (fromUserInfo == null) { msg = "from_openid不存在"; return(false); } if (fromUserInfo.TotalScore == 0) { msg = string.Format("{0}积分为0,不能转移", fromOpenId); return(false); } UserInfo toUserInfo = bllUser.GetUserInfoByOpenId(toOpenId); if (toUserInfo == null && (websiteOwner == "dongwu" || websiteOwner == "dongwudev")) { toUserInfo = bllUser.CreateNewUser(websiteOwner, toOpenId, ""); } if (toUserInfo == null) { msg = "to_openid不存在"; return(false); } ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { string scoreTitle1 = string.Format("积分转移,减掉积分{0}", fromUserInfo.TotalScore); string scoreTitle2 = string.Format("积分转移,增加积分{0}", fromUserInfo.TotalScore); if (!string.IsNullOrEmpty(remark)) { scoreTitle1 = remark; scoreTitle2 = remark; } StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat(" Update ZCJ_UserInfo Set TotalScore+=(Select TotalScore from ZCJ_UserInfo where AutoId={0}),HistoryTotalScore+=(Select HistoryTotalScore from ZCJ_UserInfo where AutoId={0}) Where AutoId={1};", fromUserInfo.AutoID, toUserInfo.AutoID); //把旧用户积分转移到新用户下 sbSql.AppendFormat(" Update ZCJ_UserInfo Set TotalScore=0 Where AutoId={0};", fromUserInfo.AutoID); //旧用户积分清零 sbSql.AppendFormat("Insert Into ZCJ_UserScoreDetailsInfo (UserID,OpenId,Score,AddTime,AddNote,ScoreType,WebSiteOwner,SerialNumber) values('{0}','{1}',{2},'{3}','{4}','{5}','{6}','{7}');", fromUserInfo.UserID, fromOpenId, -fromUserInfo.TotalScore, DateTime.Now.ToString(), scoreTitle1, "Move", WebsiteOwner, serialNumber); sbSql.AppendFormat("Insert Into ZCJ_UserScoreDetailsInfo (UserID,OpenId,Score,AddTime,AddNote,ScoreType,WebSiteOwner,SerialNumber) values('{0}','{1}',{2},'{3}','{4}','{5}','{6}','{7}');", toUserInfo.UserID, toOpenId, fromUserInfo.TotalScore, DateTime.Now.ToString(), scoreTitle2, "Move", WebsiteOwner, serialNumber); if (ZentCloud.ZCBLLEngine.BLLBase.ExecuteSql(sbSql.ToString(), tran) != 4) { msg = "操作失败"; tran.Rollback(); return(false); } #region 日志记录 BLLApiLog bllApiLog = new BLLApiLog(); if (!bllApiLog.Add(fromUserInfo.WebsiteOwner, Enums.EnumApiModule.Score, string.Format("积分清零,清除积分:{0}", fromUserInfo.TotalScore), fromUserInfo.WXOpenId, fromUserInfo.UserID, serialNumber)) { msg = "日志记录失败"; tran.Rollback(); return(false); } if (!bllApiLog.Add(toUserInfo.WebsiteOwner, Enums.EnumApiModule.Score, string.Format("积分转移,增加积分:{0}", fromUserInfo.TotalScore), toUserInfo.WXOpenId, toUserInfo.UserID, serialNumber)) { msg = "日志记录失败"; tran.Rollback(); return(false); } #endregion tran.Commit(); return(true); } catch (Exception ex) { msg = ex.ToString(); tran.Rollback(); } return(false); }