/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="state"></param> /// <returns></returns> public ActionResult ChangeUserApplyState(Guid id, int state) { var config = Config_ruleService.LoadEntities(n => n.name == "提现费用").FirstOrDefault(); var item = User_score_recordService.LoadEntities(n => n.id == id).FirstOrDefault(); if (item != null) { item.state = state; if (state == 4) { Decimal.TryParse(config.value, out decimal score); item.score -= score; } if (User_score_recordService.EditEntity(item)) { int type = (int)Score_type.提现; CacheHelper.RemoveCache($"usr_type={type}"); SaveSyslog($"管理员{nowManager.name}修改了{item.user.name}的提现积分记录", SysLogType.后台日志, nowManager.name); return(Json(SysEnum.成功, new { item.user_id, sid = id }, "修改状态成功", 1)); } return(Json(SysEnum.失败, "修改状态失败")); } return(Json(SysEnum.失败, "没有找到该对象")); }
/// <summary> /// 主页菜单积分统计数据 /// </summary> /// <returns></returns> public ActionResult Menu_Score() { var config_rule = Config_ruleService.LoadEntities(n => n.name == "总积分数").FirstOrDefault(); var total_systemScore = config_rule != null ? config_rule.value : "300000000"; var user_score_recordList = User_score_recordService.LoadEntities(n => n.state == (int)User_score_record_state.已完成).ToList(); var total_userScore = user_score_recordList.Any() ? user_score_recordList.Where(n => n.type == (int)Score_type.收益).Sum(n => n.score) : 0; var total_applyScore = user_score_recordList.Any() ? user_score_recordList.Where(n => n.type == (int)Score_type.提现).Sum(n => n.score) : 0; var total_system_deductScore = user_score_recordList.Any() ? user_score_recordList.Where(n => n.type == (int)Score_type.系统扣除).Sum(n => n.score) : 0; return(Json(SysEnum.成功, new { total_systemScore, total_userScore, total_applyScore, total_system_deductScore }, "获取数据成功")); }
/// <summary> /// 用户提现成功后 /// </summary> /// <param name="id">用户id</param> /// <param name="sid"></param> /// <returns></returns> public ActionResult AfterApplySuccess(int id, Guid sid) { var userItem = UserService.LoadEntities(n => n.id == id).FirstOrDefault(); var config = Config_ruleService.LoadEntities(n => n.name == "提现费用").FirstOrDefault(); var us = User_score_recordService.LoadEntities(n => n.id == sid).FirstOrDefault(); if (us != null && us.score > 0) { userItem.usable_score -= us.score; } if (config != null) { Decimal.TryParse(config.value, out decimal score); if (userItem != null) { var nUsr = new user_score_record(); nUsr.id = Guid.NewGuid(); nUsr.user_id = id; nUsr.type = (int)Score_type.系统扣除; nUsr.score = score; nUsr.state = (int)User_score_record_state.已完成; nUsr.source_name = $"{userItem.name}提现扣除积分{score}"; nUsr.add_time = DateTime.Now; nUsr.remark = ((int)Score_source_remark.系统扣除积分).ToString(); //userItem.total_score -= nUsr.score; userItem.usable_score -= nUsr.score; userItem.user_score_record.Add(nUsr); if (UserService.EditEntity(userItem)) { CacheHelper.RemoveCache("all_user_list"); CacheHelper.RemoveCache($"usr_type={nUsr.type}"); SaveSyslog($"添加了一条用户{userItem.id}的积分记录", SysLogType.后台日志, nowManager.name); return(Json(SysEnum.成功, "添加扣除积分记录成功")); } return(Json(SysEnum.失败, "添加用户总积分失败")); } return(Json(SysEnum.失败, "没有找到对象规则")); } return(Json(SysEnum.失败, "没有提现费用规则")); }
/// <summary> /// 公众号授权回调 /// </summary> /// <param name="code">The code.</param> /// <param name="state">The state.</param> /// <param name="goUrl">要跳转的url地址</param> /// <returns>跳转的url地址会带上Token</returns> public ActionResult UserInfoCallback(string code, string state, string goUrl) { goUrl = Common.EncryptHelper.Decrypt(goUrl); var temp = Request; string parms = string.Empty; string strpid = string.Empty; if (goUrl.IndexOf('?') > -1) { parms = goUrl.Substring(goUrl.IndexOf('?')); if (parms.Contains("pid")) { strpid = parms.Substring(parms.IndexOf("pid")).Split('=')[1]; } } //var strpid = goUrl.Substring(goUrl.IndexOf('?'), goUrl.Length).Split('=')[1]; if (string.IsNullOrEmpty(code)) { return(Content("您拒绝了授权!")); } OAuthAccessTokenResult result = null; string token = string.Empty; //通过,用code换取access_token try { result = OAuthApi.GetAccessToken(appId, secret, code); token = Common.EncryptHelper.Encrypt(string.Format("{0}|{1}|{2}", result.openid, Request.UserHostAddress, RequestCategory.微信公众号)); } catch (Exception ex) { if (ex.Message.Contains("40163")) { return(Redirect(goUrl)); } return(Content(ex.Message)); } if (result.errcode != ReturnCode.请求成功) { return(Redirect(goUrl)); } try { var wxUser = OAuthApi.GetUserInfo(result.access_token, result.openid); var tempUser = Wx_userService.LoadEntities(u => u.unionid == wxUser.unionid || u.gzh_openid == wxUser.openid).FirstOrDefault(); if (!int.TryParse(strpid, out int pid)) { pid = 0; } if (tempUser != null) { if (tempUser.state == (int)WXUserState.取消关注) { tempUser.state = (int)WXUserState.未关注; tempUser.add_time = DateTime.Now; } //if (tempUser.unsubscribe_time==null||tempUser.unsubscribe_time<=DateTime.Now.AddDays(-7)) if (true) { if (tempUser.user == null) { //新用户 var user = new user(); user.pid = pid; user.name = wxUser.nickname; user.sex = wxUser.sex; user.state = (int)User_state.正常; user.isbuy = (int)Isbuy.未购买; //首次关注赠送积分 var config_ruleItem = Config_ruleService.LoadEntities(n => n.name == "首次关注" && n.state == (int)State.可用).FirstOrDefault(); if (config_ruleItem != null) { var usr = new user_score_record(); usr.id = Guid.NewGuid(); usr.score = config_ruleItem.value != null?Convert.ToDecimal(config_ruleItem.value) : 0; usr.type = (int)Score_type.收益; usr.state = (int)User_score_record_state.已完成; usr.source_name = "首次关注系统赠送"; usr.add_time = DateTime.Now; usr.remark = ((int)Score_source_remark.系统赠送).ToString(); user.total_score += usr.score; user.usable_score += user.total_score; user.user_score_record.Add(usr); } tempUser.user = user; } tempUser.unionid = wxUser.unionid; tempUser.gzh_openid = wxUser.openid; tempUser.nickname = wxUser.nickname; tempUser.wx_head_protrait = wxUser.headimgurl; tempUser.sex = wxUser.sex; tempUser.city = wxUser.city; tempUser.province = wxUser.province; tempUser.country = wxUser.country; tempUser.unsubscribe_time = DateTime.Now; Wx_userService.EditEntity(tempUser); } } else { //新用户 var user = new user(); user.pid = pid; user.name = wxUser.nickname; user.sex = wxUser.sex; user.state = (int)User_state.正常; user.isbuy = (int)Isbuy.未购买; //首次关注赠送积分 var config_ruleItem = Config_ruleService.LoadEntities(n => n.name == "首次关注" && n.state == (int)State.可用).FirstOrDefault(); if (config_ruleItem != null) { var usr = new user_score_record(); usr.id = Guid.NewGuid(); usr.score = config_ruleItem.value != null?Convert.ToDecimal(config_ruleItem.value) : 0; usr.type = (int)Score_type.收益; usr.state = (int)User_score_record_state.已完成; usr.source_name = "首次关注系统赠送"; usr.add_time = DateTime.Now; usr.remark = ((int)Score_source_remark.系统赠送).ToString(); user.total_score += usr.score; user.usable_score += user.total_score; user.user_score_record.Add(usr); } var newUser = new wx_user() { city = wxUser.city, country = wxUser.country, wx_head_protrait = wxUser.headimgurl, nickname = wxUser.nickname, gzh_openid = wxUser.openid, province = wxUser.province, sex = wxUser.sex, add_time = DateTime.Now, unionid = wxUser.unionid, state = (int)WXUserState.未关注,//未关注 user = user, }; Wx_userService.AddEntity(newUser); //SaveSyslog($"{wxUser.nickname}=>({Url})加入系统,pid={pid}", SysLogType.前台日志, "授权系统"); } var url = $"{goUrl}?state={Guid.NewGuid().ToString().Substring(0, 4)}#token={token}"; return(Redirect(url)); } catch (ErrorJsonResultException ex) { return(Content(ex.Message)); } }