/// <summary> /// 取消关注时间 /// </summary> /// <param name="requestMessage"></param> public void UnSubscribe(RequestMessageEvent_Unsubscribe requestMessage) { OfficialAccount_BLL obll = new OfficialAccount_BLL(); OfficialAccount model = obll.Get(a => a.OriginalID == requestMessage.ToUserName); Subscriber_BLL sbll = new Subscriber_BLL(); if (sbll.GetCount(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID) > 0) { Subscriber sub = sbll.Get(a => a.OpenID == requestMessage.FromUserName && a.AccountID == model.AccountID); sub.IsOK = false; sub.UnSubscribeTime = DateTime.Now; if (sub.UnSubscribeCount != null) { sub.UnSubscribeCount += 1; } else { sub.UnSubscribeCount = 1; } sub.Score = 0; sbll.Update(sub); if (sub.FromOpenID != null) { //if (sub.UnSubscribeCount > 1) //{ Subscriber sup = sbll.Get(a => a.OpenID == sub.FromOpenID && a.AccountID == model.AccountID); if (sup.IsOK == true) { sup.Score -= model.UnSubscribeReduceScore; sup.DirectScore -= model.UnSubscribeReduceScore; sbll.Update(sup); StringBuilder sbparent = new StringBuilder(); sbparent.Append("您好,你的粉丝【" + sub.NickName + "】取消关注了本公众号!\n"); sbparent.Append("减少积分:" + model.UnSubscribeReduceScore + "分,累计积分:" + sup.Score.ToString() + "分\n"); CustomApi.SendText(model.AppID, sup.OpenID, sbparent.ToString()); } //} } } }
public ActionResult List(string code, string state) { if (string.IsNullOrEmpty(code)) { return(Content("您拒绝了授权!")); } Guid accountid = Guid.Parse(state.Trim()); OfficialAccount off = new OfficialAccount_BLL().Get(a => a.AccountID == accountid); OAuthAccessTokenResult result = new OAuthAccessTokenResult(); //通过,用code换取access_token try { result = OAuthApi.GetAccessToken(off.AppID.Trim(), off.AppSecret.Trim(), code); } catch (Exception ex) { if (Session["OAuthAccessToken"] != null) { result = Session["OAuthAccessToken"] as OAuthAccessTokenResult; try { result = OAuthApi.RefreshToken(off.AppID.Trim(), result.refresh_token); } catch (Exception) { return(Content("错误:" + result.errmsg)); } } else { return(Content("错误:" + result.errmsg)); } } if (result.errcode != ReturnCode.请求成功) { return(Content("错误:" + result.errmsg)); } Session["OAuthAccessTokenStartTime"] = DateTime.Now; Session["OAuthAccessToken"] = result; OAuthUserInfo info = OAuthApi.GetUserInfo(result.access_token, result.openid); Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.OpenID == info.openid); List <Goods_Order> list = new Goods_Order_BLL().GetList(a => a.SubscribeID == mysub.SubscribeID).OrderByDescending(a => a.CreateTime).ToList(); return(View("MyList", list)); }
// // GET: /WeiXin/Score/ public ActionResult MyScore(string code, string state) { //string aaa = "code:" + code + " ; state:" + state; //return Content(aaa); OfficialAccount_BLL obll = new OfficialAccount_BLL(); Guid id = Guid.Parse(state); OfficialAccount off = obll.Get(a => a.AccountID == id); //return Content(off.AppID.Trim()+";"+ off.AppSecret.Trim()); OAuthAccessTokenResult result = OAuthApi.GetAccessToken(off.AppID.Trim(), off.AppSecret.Trim(), code); OAuthUserInfo info = OAuthApi.GetUserInfo(result.access_token, result.openid); //ViewBag.aaa = info.nickname; //ViewBag.bbb = info.openid; //return Content(info.nickname + info.openid); //return Content(result.openid); //string openid = "oqbOQs7w9UNUdksAEnd5zwIxUNCE"; Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.OpenID == info.openid); if (mysub != null) { //获取我的粉丝 List <Subscriber> fans = subbll.GetList(a => a.FromOpenID == info.openid).OrderBy(a => a.SubscribeTime).ToList(); ViewBag.FansList = fans; //获取的我的分数 if (mysub.Score != null) { ViewBag.MyScore = mysub.Score; } else { ViewBag.MyScore = 0; } } else { ViewBag.FansList = new List <Subscriber>(); ViewBag.MyScore = 0; } return(View()); }
public ActionResult Test(int id = 1) { if (Session["CurrentAccountID"] == null) { return(RedirectToAction("Select", "OfficialAccount", new { Area = "Admin" })); } Guid AccountID = Guid.Parse(Session["CurrentAccountID"].ToString()); Subscriber_BLL bll = new Subscriber_BLL(); //List<Subscriber> list = bll.GetListOrderBys(a => a.AccountID == AccountID, false,a => a.Score,a=>a.SubscribeTime).ToList(); List <Subscriber> list = bll.GetPageListOrderBy(id, 50, a => a.AccountID == AccountID, a => a.Score, false).ToList(); return(View(list)); }
public ActionResult Add(Goods_Order_ViewModel model) { AutoMapper.Mapper.CreateMap <Goods_Order_ViewModel, Goods_Order>(); Goods_Order order = AutoMapper.Mapper.Map <Goods_Order>(model); order.State = "未发货"; if (model.CategoryName == "虚拟商品") { order.State = "已发货"; } order.CreateTime = DateTime.Now; Goods_Order_BLL bll = new Goods_Order_BLL(); bll.Add(order); Goods_BLL gbll = new Goods_BLL(); Goods good = gbll.Get(a => a.GoodID == model.GoodID); Subscriber_BLL sbll = new Subscriber_BLL(); Subscriber sub = sbll.Get(a => a.SubscribeID == model.SubscribeID); if (sub.Score >= 0 && sub.Score >= good.CostScore) { sub.Score = sub.Score - good.CostScore; if (sub.ScoreUsed != null) { sub.ScoreUsed += good.CostScore; } else { sub.ScoreUsed = good.CostScore; } sbll.Update(sub); good.Count = good.Count - 1; gbll.Update(good); //Subscriber sub = new Subscriber_BLL().Get(a => a.SubscribeID == model.SubscribeID); //string link = WeiXinHelper.AuthorizeUrl(sub.OfficialAccount.AppID, Url.Content("~/WeiXin/Order/MyList"), // sub.AccountID.ToString()); return(RedirectToAction("MyList", "Order", new { SubscribeID = model.SubscribeID })); } else { ModelState.AddModelError("", "抱歉,您的积分不够!"); return(View(model)); } }
public ActionResult Subscribe(string openid, int id = 1) { Subscriber_BLL bll = new Subscriber_BLL(); Subscriber parent = bll.Get(a => a.OpenID == openid); ViewBag.Parent = parent; List <Subscriber> childlist = bll.GetList(a => a.FromOpenID == openid).OrderByDescending(a => a.SubscribeTime).ToList(); AutoMapper.Mapper.CreateMap <Subscriber, Subscriber_ViewModel>(); List <Subscriber_ViewModel> vlist = AutoMapper.Mapper.Map <List <Subscriber_ViewModel> >(childlist); return(View(vlist.ToPagedList(id, 50))); }
public ActionResult IndexById(Guid SubscribeID) { Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.SubscribeID == SubscribeID); if (mysub != null) { ViewBag.SubscribeID = mysub.SubscribeID; } else { return(Content("对不起,您尚未关注该公众号!")); } return(View("Index", mysub)); }
// // GET: /WeiXin/Goods/ public ActionResult List(Guid SubscribeID) { ViewBag.SubscribeID = SubscribeID; Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.SubscribeID == SubscribeID); ViewBag.MyScore = mysub.Score; Goods_BLL bll = new Goods_BLL(); List <Goods> sourselist = bll.GetList(a => a.AccountID == mysub.AccountID && a.IsSelling == true && a.Count > 0).OrderByDescending(a => a.CreateTime).ToList(); AutoMapper.Mapper.CreateMap <Goods, Goods_ViewModel>(); List <Goods_ViewModel> list = AutoMapper.Mapper.Map <List <Goods_ViewModel> >(sourselist); return(View(list)); }
public ActionResult _LayoutHeader(Guid SubscribeID) { Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.SubscribeID == SubscribeID); LayoutHeader_ViewModel vm = new LayoutHeader_ViewModel(); vm.SubscribeID = mysub.SubscribeID; vm.Score = mysub.Score == null ? 0 : (int)mysub.Score; vm.SubscribeTime = (DateTime)mysub.SubscribeTime; vm.NickName = mysub.NickName; vm.HeadImgUrl = mysub.HeadImgUrl; vm.ChildSubscribeCount = subbll.GetCount(a => a.FromOpenID == mysub.OpenID); vm.IsYouZan = mysub.OfficialAccount.YouZanEnable; return(PartialView(vm)); }
public JsonResult GetSubscriberList(Guid accountid) { Subscriber_BLL bll = new Subscriber_BLL(); List <Subscriber> list = bll.GetList(a => a.AccountID == accountid && a.Longitude != null && a.Latitude != null).OrderByDescending(a => a.SubscribeTime).ToList(); AutoMapper.Mapper.CreateMap <Subscriber, Subscriber_ViewModel>(); List <Subscriber_ViewModel> vlist = AutoMapper.Mapper.Map <List <Subscriber_ViewModel> >(list); foreach (var item in vlist) { if (item.FromOpenID != null) { Subscriber sub = list.Where(a => a.AccountID == accountid && a.OpenID == item.FromOpenID).FirstOrDefault(); item.FromNickName = sub.NickName; item.FromHeadImgUrl = sub.HeadImgUrl; } } return(Json(vlist, JsonRequestBehavior.AllowGet)); }
public ActionResult ScoreRanking(Guid SubscribeID) { Subscriber_BLL bll = new Subscriber_BLL(); Subscriber my = bll.Get(a => a.SubscribeID == SubscribeID); List <Subscriber> list = bll.GetPageListOrderBy(1, 20, a => a.AccountID == my.AccountID && a.Score > 0, a => a.Score, false).ToList(); AutoMapper.Mapper.CreateMap <Subscriber, Subscriber_ViewModel>(); List <Subscriber_ViewModel> vlist = AutoMapper.Mapper.Map <List <Subscriber_ViewModel> >(list); foreach (var item in vlist) { item.FansCount = bll.GetCount(a => a.FromOpenID == item.OpenID); } ViewBag.SubscribeID = SubscribeID; return(View(vlist)); }
public ActionResult MyScoreBySubscribeID(Guid SubscribeID) { Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.SubscribeID == SubscribeID); if (mysub != null) { //获取我的粉丝 List <Subscriber> fans = subbll.GetList(a => a.FromOpenID == mysub.OpenID).OrderBy(a => a.SubscribeTime).ToList(); ViewBag.FansList = fans; //获取的我的分数 if (mysub.Score != null) { ViewBag.MyScore = mysub.Score; } else { ViewBag.MyScore = 0; } } else { ViewBag.FansList = new List <Subscriber>(); ViewBag.MyScore = 0; } //Subscriber_ViewModel mysubvm = new Subscriber_ViewModel //{ // SubscribeID = mysub.SubscribeID, // NickName = info.nickname, // HeadImgUrl=info.headimgurl //}; return(View("MyScore")); }
// GET: Admin/Subscriber public ActionResult List(string n, int so = 0, int id = 1) { if (Session["CurrentAccountID"] == null) { return(RedirectToAction("Select", "OfficialAccount", new { Area = "Admin" })); } Guid AccountID = Guid.Parse(Session["CurrentAccountID"].ToString()); ViewBag.SearchParam = n ?? ""; ViewBag.OrderType = so; ViewBag.AccountID = AccountID; Subscriber_BLL bll = new Subscriber_BLL(); List <Subscriber> yuanlist = new List <Subscriber>(); int totalCount = 0; int pageSize = 20; if (so == 0) { if (!String.IsNullOrEmpty(n)) { yuanlist = bll.GetPageListOrderBy(id, pageSize, a => a.AccountID == AccountID && a.NickName.Contains(n), a => a.SubscribeTime, false).ToList(); totalCount = bll.GetCount(a => a.AccountID == AccountID && a.NickName.Contains(n)); } else { yuanlist = bll.GetPageListOrderBy(id, pageSize, a => a.AccountID == AccountID, a => a.SubscribeTime, false).ToList(); totalCount = bll.GetCount(a => a.AccountID == AccountID); } } else { if (!String.IsNullOrEmpty(n)) { yuanlist = bll.GetPageListOrderBy(id, pageSize, a => a.AccountID == AccountID && a.NickName.Contains(n), a => a.Score, false).ToList(); totalCount = bll.GetCount(a => a.AccountID == AccountID && a.NickName.Contains(n)); } else { yuanlist = bll.GetPageListOrderBy(id, pageSize, a => a.AccountID == AccountID, a => a.Score, false).ToList(); totalCount = bll.GetCount(a => a.AccountID == AccountID); } } List <Subscriber> newlist = yuanlist; ViewBag.CurrentQuery = ""; AutoMapper.Mapper.CreateMap <Subscriber, Subscriber_ViewModel>(); List <Subscriber_ViewModel> vlist = AutoMapper.Mapper.Map <List <Subscriber_ViewModel> >(newlist); foreach (var item in vlist) { if (item.FromOpenID != null) { try { Subscriber sub = bll.Get(a => a.AccountID == AccountID && a.OpenID == item.FromOpenID); item.FromNickName = sub.NickName; item.FromHeadImgUrl = sub.HeadImgUrl; } catch (Exception ex) { var aaa = ex; } } item.FansCount = bll.GetCount(a => a.AccountID == AccountID && a.FromOpenID == item.OpenID); item.FansStayCount = bll.GetCount(a => a.AccountID == AccountID && a.FromOpenID == item.OpenID && a.IsOK == true); item.FansLeaveCount = bll.GetCount(a => a.AccountID == AccountID && a.FromOpenID == item.OpenID && a.IsOK != true); double staypercent = 1.00; double leavepercent = 0.00; if (item.FansCount != 0) { staypercent = Math.Round(Convert.ToDouble(item.FansStayCount) / Convert.ToDouble(item.FansCount), 2); leavepercent = Math.Round(Convert.ToDouble(item.FansLeaveCount) / Convert.ToDouble(item.FansCount), 2); } item.FansStayPercent = (staypercent * 100).ToString() + "%"; item.FansLeavePercent = (leavepercent * 100).ToString() + "%"; } var list = new StaticPagedList <Subscriber_ViewModel>(vlist, id, pageSize, totalCount); return(View(list)); }
/// <summary> /// 关注事件 /// </summary> /// <param name="requestMessage"></param> public void Subscribe(RequestMessageEvent_Subscribe requestMessage) { OfficialAccount_BLL obll = new OfficialAccount_BLL(); OfficialAccount model = obll.Get(a => a.OriginalID == requestMessage.ToUserName); if (!AccessTokenContainer.CheckRegistered(model.AppID)) //检查是否已经注册 { AccessTokenContainer.Register(model.AppID, model.AppSecret); //如果没有注册则进行注册 } Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson uij = UserApi.Info(model.AppID, requestMessage.FromUserName); bool isInArea = false; if (model.AreaLimit != null) { if (model.AreaLevel == "国家" && model.AreaLimit.Contains(uij.country)) { isInArea = true; } if (model.AreaLevel == "省份" && model.AreaLimit.Contains(uij.province)) { isInArea = true; } if (model.AreaLevel == "城市" && model.AreaLimit.Contains(uij.city)) { isInArea = true; } } else { isInArea = true; } if (!isInArea) { try { Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, uij.openid, "对不起,该活动只限" + model.AreaLimit + "地区用户!"); } catch (Exception e) { } } //判断返回体是否带有参数 bool hasPara = !string.IsNullOrWhiteSpace(requestMessage.EventKey); string popenid = hasPara ? requestMessage.EventKey.Substring(8) : null; Subscriber_BLL bll = new Subscriber_BLL(); //扫码者是否存在 if (bll.GetCount(a => a.OpenID == uij.openid && a.AccountID == model.AccountID) > 0) { //如果存在(指的是数据库中有没有用的信息) Subscriber sub = bll.Get(a => a.OpenID == uij.openid && a.AccountID == model.AccountID); if (sub.IsOK == true) { sub.FromOpenID = popenid; bll.Update(sub); //如果已关注 //Senparc.Weixin.MP.AdvancedAPIs.CustomApi.SendText(model.AppID, sub.OpenID, model.ReSubscribeWelcome);//吃菊 } else { //如果已取消关注 sub.FromOpenID = popenid; sub.IsOK = true; bll.Update(sub); try { CustomApi.SendText(model.AppID, sub.OpenID, model.ReSubscribeWelcome); } catch (Exception e) { } //再次关注发送消息 } } else { //如果不存在 //添加扫码者信息 Subscriber sub = new Subscriber { SubscribeID = Guid.NewGuid(), AccountID = model.AccountID, NickName = uij.nickname, Province = uij.province, City = uij.city, Country = uij.country, OpenID = uij.openid, Sex = uij.sex, HeadImgUrl = uij.headimgurl, FromOpenID = popenid, SubscribeTime = DateTime.Parse("1970-01-01 08:00").AddSeconds(uij.subscribe_time), Score = 0, SignScore = 0, DirectScore = 0, IndirectScore = 0, SignContinuityCount = 0, UnSubscribeCount = 0, IsOK = true }; bll.Add(sub); //发送首次关注欢迎信息 try { CustomApi.SendText(model.AppID, sub.OpenID, model.SubscribeWelcome); } catch (Exception e) { } if (hasPara) { //判断参数对应用户是否存在(第一级) if (bll.GetCount(a => a.OpenID == popenid && a.AccountID == model.AccountID) > 0) { if (isInArea) { Subscriber psub = bll.Get(a => a.OpenID == popenid && a.AccountID == model.AccountID); if (psub.DirectScore != null) { psub.DirectScore += model.SubscribeAddScore; } else { psub.DirectScore = model.SubscribeAddScore; } psub.DirectScoreUpdateTime = DateTime.Parse("1970-01-01 08:00").AddSeconds(uij.subscribe_time); if (psub.Score != null) { psub.Score += model.SubscribeAddScore; } else { psub.Score = model.SubscribeAddScore; } bll.Update(psub); //发送第一级 StringBuilder msgp = new StringBuilder(); msgp.Append("恭喜,您有新的粉丝【" + uij.nickname + "】加入!\n"); msgp.Append("获得推广积分:" + model.SubscribeAddScore + "分,累计积分:" + psub.Score.ToString() + "分\n"); CustomApi.SendText(model.AppID, psub.OpenID, msgp.ToString()); } } else { if (isInArea) { //第一级用户不存在,需要补充信息 Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson puij = UserApi.Info(model.AppID, popenid); //补充上一级信息 Subscriber psub = new Subscriber { SubscribeID = Guid.NewGuid(), AccountID = model.AccountID, NickName = puij.nickname, Province = puij.province, City = puij.city, Country = puij.country, OpenID = puij.openid, Sex = puij.sex, HeadImgUrl = puij.headimgurl, SubscribeTime = DateTime.Parse("1970-01-01 08:00").AddSeconds(puij.subscribe_time), Score = model.SubscribeAddScore, SignScore = 0, DirectScore = model.SubscribeAddScore, DirectScoreUpdateTime = sub.SubscribeTime, IndirectScore = 0, SignContinuityCount = 0, UnSubscribeCount = 0, IsOK = true }; bll.Add(psub); //发送第一级 StringBuilder msgp = new StringBuilder(); msgp.Append("恭喜,您有新的粉丝【" + uij.nickname + "】加入!\n"); msgp.Append("获得推广积分:" + model.SubscribeAddScore + "分,累计积分:" + psub.Score.ToString() + "分\n"); CustomApi.SendText(model.AppID, psub.OpenID, msgp.ToString()); } else { //第一级用户不存在,需要补充信息 Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson puij = UserApi.Info(model.AppID, popenid); //补充上一级信息 Subscriber psub = new Subscriber { SubscribeID = Guid.NewGuid(), AccountID = model.AccountID, NickName = puij.nickname, Province = puij.province, City = puij.city, Country = puij.country, OpenID = puij.openid, Sex = puij.sex, HeadImgUrl = puij.headimgurl, SubscribeTime = DateTime.Parse("1970-01-01 08:00").AddSeconds(puij.subscribe_time), Score = 0, SignScore = 0, DirectScore = 0, DirectScoreUpdateTime = sub.SubscribeTime, IndirectScore = 0, SignContinuityCount = 0, UnSubscribeCount = 0, IsOK = true }; bll.Add(psub); //发送第一级 } } } } }
// // GET: /WeiXin/Subscriber/ public ActionResult Index(string code, string state) { if (string.IsNullOrEmpty(code)) { return(Content("您拒绝了授权!")); } Guid accountid = Guid.Parse(state.Trim()); OfficialAccount off = new OfficialAccount_BLL().Get(a => a.AccountID == accountid); OAuthAccessTokenResult result = new OAuthAccessTokenResult(); //通过,用code换取access_token try { result = OAuthApi.GetAccessToken(off.AppID.Trim(), off.AppSecret.Trim(), code); } catch (Exception ex) { if (Session["OAuthAccessToken"] != null) { result = Session["OAuthAccessToken"] as OAuthAccessTokenResult; try { result = OAuthApi.RefreshToken(off.AppID.Trim(), result.refresh_token); } catch (Exception) { return(Content("错误:" + result.errmsg)); } } else { return(Content("错误:" + result.errmsg)); } } if (result.errcode != ReturnCode.请求成功) { return(Content("错误:" + result.errmsg)); } Session["OAuthAccessTokenStartTime"] = DateTime.Now; Session["OAuthAccessToken"] = result; OAuthUserInfo info = OAuthApi.GetUserInfo(result.access_token, result.openid); Subscriber_BLL subbll = new Subscriber_BLL(); Subscriber mysub = subbll.Get(a => a.OpenID == info.openid); if (mysub != null) { ViewBag.SubscribeID = mysub.SubscribeID; } else { return(Content("对不起,您尚未关注该公众号!")); } return(View(mysub)); }