/// <summary> /// 模型转换 /// </summary> /// <param name="item"></param> /// <returns></returns> public static async Task <List <CommentItem> > ConvertToCommentVM(List <Comment> item) { if (item == null) { return(new List <CommentItem>()); } using (var userClient = new Tuhu.Service.UserAccount.UserAccountClient()) { List <CommentItem> list = new List <CommentItem>(); string defaultImg = "http://resource.tuhu.cn/Image/Product/zhilaohu.png"; foreach (var m in item) { var cm = (CommentItem)m; var u = await userClient.GetUserByIdAsync(Guid.Parse(m.UserId)); if (u.Result != null) { cm.UserId = u.Result.UserId; cm.NickName = Tools.ConvertPhoneSecret(u.Result.Profile.NickName) == u.Result.MobileNumber ? u.Result.MobileNumber.Replace(u.Result.MobileNumber.Substring(3, 4), "****") : Tools.ConvertPhoneSecret(u.Result.Profile.NickName); cm.UserGrade = ""; cm.CellPhone = Tools.ConvertPhoneSecret(u.Result.MobileNumber); cm.HeadImage = !string.IsNullOrEmpty(u.Result.Profile.HeadUrl) ? u.Result.Profile.HeadUrl : defaultImg; } else { cm.UserId = Guid.Parse(m.UserId); cm.NickName = "游客"; cm.HeadImage = defaultImg; //continue; } if (cm.ReplyComment != null) { var us = await userClient.GetUserByIdAsync(Guid.Parse(m.ReplyComment.UserId)); if (us.Result != null) { cm.ReplyComment.UserId = us.Result.UserId; cm.ReplyComment.NickName = Tools.ConvertPhoneSecret(us.Result.Profile.NickName) == us.Result.MobileNumber ? us.Result.MobileNumber.Replace(us.Result.MobileNumber.Substring(3, 4), "****") : Tools.ConvertPhoneSecret(us.Result.Profile.NickName); cm.ReplyComment.UserGrade = ""; cm.ReplyComment.CellPhone = Tools.ConvertPhoneSecret(us.Result.MobileNumber); cm.ReplyComment.HeadImage = !string.IsNullOrEmpty(us.Result.Profile.HeadUrl) ? us.Result.Profile.HeadUrl : defaultImg; } } list.Add(cm); } return(list); } }
/// <summary> /// 发送优惠券 /// </summary> /// <param name="fightGroupsIdentity"></param> /// <returns></returns> public static async Task <FightGroupsPacketsProvideResponse> CreateFightGroupsPacketByPromotion(Guid fightGroupsIdentity) { using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) { List <FightGroupsPacketsLogModel> list = null; var result = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(fightGroupsIdentity.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity), TimeSpan.FromDays(1)); list = result?.Value; if (list == null) { list = await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity); } if (list?.Where(_ => _.UserId == null)?.Count() <= 0 && list?.Where(_ => _.PromotionPKID != null)?.Count() <= 0) { using (var memberClient = new Tuhu.Service.Member.PromotionClient()) { List <CreatePromotionModel> promotionModelList = new List <CreatePromotionModel>(); foreach (var item in list) { promotionModelList.Add(new CreatePromotionModel() { Author = item.UserId.ToString(), GetRuleGUID = item.GetRuleGuid, UserID = item.UserId, Channel = "小程序分享红包", DeviceID = "", Operation = "小程序分享红包", IssueChannle = "小程序分享红包", IssueChannleId = fightGroupsIdentity.ToString(), Issuer = "李维童" }); } var memberResult = await memberClient.CreatePromotionsNewAsync(promotionModelList); if (memberResult.Result.IsSuccess) { for (int i = 0; i < list?.Count; i++) { if (memberResult?.Result?.promotionIds?.Count > i) { list[i].PromotionPKID = memberResult?.Result?.promotionIds[i]; } } await DalFightGroupsPacketsLog.UpdateCreatePromotionPKID(list); // 先注释掉,因为读写库原因,删掉之后,下次从数据库读取不到 //using (var reditClient = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey)) //{ // reditClient.Remove(list?.Where(_ => _.IsLeader == true)?.FirstOrDefault()?.UserId.ToString()); // reditClient.Remove(fightGroupsIdentity.ToString()); //} using (var pushClient = new Tuhu.Service.Push.TemplatePushClient()) { foreach (var item in list) { using (var userClient = new Tuhu.Service.UserAccount.UserAccountClient()) { var userResult = await userClient.GetUserByIdAsync(item.UserId.Value); var pushResult = await pushClient.PushByUserIDAndBatchIDAsync(new List <string>() { item.UserId.Value.ToString() }, 1643, new Service.Push.Models.Push.PushTemplateLog() { Replacement = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string>() { { "{{nickname}}", userResult.Result.Profile.NickName }, { "{{packetgroupno}}", item.FightGroupsIdentity.ToString() } }) }); if (!pushResult.Success || !pushResult.Result) { Logger.ErrorException("拆红包推送失败", pushResult.Exception); } } } } return(new FightGroupsPacketsProvideResponse() { IsSuccess = memberResult.Result.IsSuccess, Msg = "优惠券领取成功" }); } else { return(new FightGroupsPacketsProvideResponse() { IsSuccess = memberResult.Result.IsSuccess, Msg = memberResult?.Result?.ErrorMessage }); } } } else { return new FightGroupsPacketsProvideResponse() { IsSuccess = false, Msg = string.Format("分享红包组没有拼组完成还差{0}个或者已经发放过", list?.Where(_ => _.UserId == null)?.Count()) } }; } }
/// <summary> /// 查询问答板块中我关注的标签和问题列表 /// </summary> /// <param name="userId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public async Task <ActionResult> GetAttentionQuestionForQAndAHomePage(string userId, int pageIndex = 1, int pageSize = 10) { var dic = new Dictionary <string, object>(); try { //查询热门问答 if (string.IsNullOrWhiteSpace(userId)) { await GetPopularQAndAForQuestionBrand(pageIndex, pageSize, dic); } else { var dataList = await DiscoverBLL.GetAttentionQuestionForQAndAHomePage(userId, pageIndex, pageSize); if (dataList.Any() == false) { await GetPopularQAndAForQuestionBrand(pageIndex, pageSize, dic); } else { dic.Add("Code", "1"); var timeLineList = new List <object>(); foreach (var timeLine in dataList) { //if (timeLine.UserIdentity > 0) // continue; Tuhu.Service.UserAccount.Models.User userInfo = null; if (!string.IsNullOrWhiteSpace(timeLine.UserId)) { Guid UserID; if (Guid.TryParse(timeLine.UserId, out UserID)) { using (var userClient = new Tuhu.Service.UserAccount.UserAccountClient()) { var userInfoResult = await userClient.GetUserByIdAsync(new Guid(timeLine.UserId)); if (userInfoResult.Result != null) { userInfo = userInfoResult.Result; } } } else { //WebLog.LogException(new Exception(JsonConvert.SerializeObject(timeLine))); } } if (userInfo != null && userInfo.Profile != null) { userInfo.Profile.HeadUrl = userInfo.Profile.HeadUrl ?? string.Empty; } timeLineList.Add(new { PKID = timeLine.PKID, Content = timeLine.Question, FirstAttentionUserId = timeLine.UserId, UserId = timeLine.UserId, AnswerId = timeLine.AnswerId, AnswerContent = timeLine.AnswerContent, CommentImage = timeLine.CommentImage, UserHead = userInfo == null ? (timeLine.UserIdentity > 0 ? timeLine.UserHead : GetDefaultUserHeadByUserGrade(string.Empty)) : (userInfo.Profile.HeadUrl.Contains("http") ? userInfo.Profile.HeadUrl : DomainConfig.ImageSite + userInfo.Profile.HeadUrl), UserName = userInfo == null ? (timeLine.UserIdentity > 0 ? timeLine.UserName : "******") : (GetUserName(userInfo.Profile.NickName, userInfo.Profile.NickName, userInfo.MobileNumber)), Type = timeLine.Type, UserIdentity = timeLine.UserIdentity, Praise = timeLine.Praise }); } dic.Add("Data", new { TimeLineList = timeLineList }); } } } catch (Exception ex) { WebLog.LogException("GetAttentionQuestionForQAndAHomePage", ex); dic.Clear(); dic.Add("Messages", ex.Message); dic.Add("Code", "0"); } return(Json(dic, JsonRequestBehavior.AllowGet)); }