/// <summary> ///生成商品文案 /// </summary> /// <param name="userid">The userid.</param> /// <param name="taskid">The taskid.</param> /// <param name="templateText">The template text.</param> /// <param name="data">The data.</param> /// <param name="group">The group.</param> /// <returns>true if XXXX, false otherwise.</returns> private bool BuildShareText(string loginToken, int userid, int taskid, string templateText, List <GoodsModel> data, weChatGroupModel group, string appkey, string appsecret, out JoinGoodsList joinList, Action <weChatShareTextModel> result = null, bool isJoinImage = false) { joinList = null; if (data == null) { return(false); } weChatShareTextModel share = new weChatShareTextModel() { userid = userid, taskid = taskid, status = -1, title = group.title }; if (isJoinImage) { joinList = new JoinGoodsList(); } List <int> ids = new List <int>(); List <JoinGoodsInfo> imageList = new List <JoinGoodsInfo>(); foreach (var item in data) { if (item.goodsPrice - item.couponPrice <= 0) { continue; } string url = GlobalConfig.couponUrl; url += "?src=ht_hot&activityId=" + item.couponId; url += "&itemId=" + item.goodsId.Replace("=", ""); url += "&pid=" + (string.IsNullOrEmpty(group.pid) ? "mm_33648229_22032774_73500078" : group.pid); item.shareLink = url; string shortUrl = string.Empty; //将淘口令改成pid,2017-04-07 修改,淘口令改到分享时生产 string tpwd = (string.IsNullOrEmpty(group.pid) ? "mm_33648229_22032774_73500078" : group.pid);// "[二合一淘口令]";// HotTaoApiService.Instance.taobao_wireless_share_tpwd_create(item.goodsMainImgUrl, item.shareLink, item.goodsName, appkey, appsecret); string text = templateText; if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(tpwd)) { if (text.Contains("[商品标题]")) { text = text.Replace("[商品标题]", item.goodsName); } if (text.Contains("[商品价格]")) { text = text.Replace("[商品价格]", item.goodsPrice.ToString()); } if (text.Contains("[券后价格]")) { text = text.Replace("[券后价格]", (item.goodsPrice - item.couponPrice).ToString()); } if (text.Contains("[来源]")) { text = text.Replace("[来源]", item.goodsSupplier); } if (text.Contains("[销量]")) { text = text.Replace("[销量]", item.goodsSalesAmount.ToString()); } if (text.Contains("[优惠券价格]")) { text = text.Replace("[优惠券价格]", item.couponPrice.ToString()); } if (text.Contains("[分隔符]")) { text = text.Replace("[分隔符]", "-----------------"); } if (text.Contains("[简介描述]")) { text = text.Replace("[简介描述]", string.IsNullOrEmpty(item.goodsIntro) ? "" : item.goodsIntro); } if (text.Contains("[商品地址]")) { text = text.Replace("[商品地址]", item.goodsDetailUrl); } if (text.Contains("[优惠券地址]")) { text = text.Replace("[优惠券地址]", item.couponUrl); } } else { share.status = 2; } share.goodsid = Convert.ToInt32(item.id); share.text = text; share.tpwd = tpwd; share.field1 = item.goodslocatImgPath; if (isJoinImage) { string _url = GlobalConfig.couponUrl; _url += "?src=ht_hot&activityId=" + item.couponId; _url += "&itemId=" + item.goodsId.Replace("=", ""); _url += "&pid=" + tpwd; var _tpwd = ""; share.field2 = _tpwd; bool isLogin = true; Tuple <string, string> resultTuple = TaobaoHelper.GetGaoYongToken(item.goodsDetailUrl, item.goodsId, tpwd, MyUserInfo.GetTbToken(), MyUserInfo.cookies, out isLogin); string shareText = ""; if (resultTuple != null) { if (isLogin) { shareText = resultTuple.Item1; } } //商品数据 joinList.collectionGoodsList.Add(new CollectionGoods() { goodsId = item.goodsId, goodsName = item.goodsName, price = item.goodsPrice, discountAmount = item.couponPrice, goodsPromotionUrl = _url, goodsPrimaryImg = item.goodsMainImgUrl, shareText = shareText }); //图片 joinList.ImageList.Add(new JoinGoodsInfo() { GoodsName = item.goodsName, GoodsPrice = item.goodsPrice, CouponPrice = item.couponPrice, imagePath = item.goodslocatImgPath, GoodsIntro = item.goodsIntro }); } share.field6 = isJoinImage ? 1 : 0; share.field3 = group.id.ToString(); AddUserWechatSharetext(share); result?.Invoke(share); } if (isJoinImage) { joinList.TaskId = taskid; joinList.id = Convert.ToInt32(group.id); } return(true); }
/// <summary> /// 自动合成图片 /// </summary> /// <param name="loginToken"></param> /// <param name="wechatlist"></param> /// <param name="appkey"></param> /// <param name="appsecret"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="JoinImageCount"></param> /// <returns></returns> public bool AutoJoinImage(string loginToken, List <UserWechatListModel> wechatlist, string appkey, string appsecret, DateTime startTime, DateTime endTime, int JoinImageCount) { string templateText = "[二合一淘口令]"; List <UserPidTaskModel> pidList = new List <UserPidTaskModel>(); List <UserPidTaskModel> goodsList = new List <UserPidTaskModel>(); //判断群是否存在 if (wechatlist == null || wechatlist.Count() <= 0) { return(false); } else { foreach (var item in wechatlist) { if (!pidList.Exists(r => r.id == item.id)) { pidList.Add(new UserPidTaskModel() { id = item.id }); } } } //获取需要合成图片的商品数据 var goodslist = FindByUserGoodsListThree(JoinImageCount); List <int> ids = new List <int>(); if (goodslist != null && goodslist.Count() == JoinImageCount) { foreach (var item in goodslist) { if (!goodsList.Exists(r => r.id == Convert.ToInt32(item.id))) { goodsList.Add(new UserPidTaskModel() { id = Convert.ToInt32(item.id) }); } ids.Add(Convert.ToInt32(item.id)); } } else { return(false); } string goodsText = JsonConvert.SerializeObject(goodsList); string pidsText = JsonConvert.SerializeObject(pidList); TaskPlanModel model = new TaskPlanModel() { userid = uid, title = "【合成图片转发】", startTime = startTime, endTime = endTime, pidsText = pidsText, goodsText = goodsText, id = 0, status = 0, isTpwd = 0 }; TaskPlanModel data = AddUserTaskPlan(model); if (data == null) { return(false); } List <JoinGoodsList> joinLists = new List <JoinGoodsList>(); foreach (var group in wechatlist) { weChatGroupModel g = new weChatGroupModel() { id = group.id, title = group.wechattitle, pid = group.pid, userid = group.userid }; JoinGoodsList joinList = new JoinGoodsList(); //生成商品分享文本 BuildShareText(loginToken, uid, Convert.ToInt32(data.id), templateText, goodslist, g, appkey, appsecret, out joinList, null, true); if (joinList != null) { joinLists.Add(joinList); } } int flag = BuildJoinImage(loginToken, joinLists, data.title, Convert.ToInt32(data.id), JoinImageCount); if (flag == 0) { UpdateUserTaskPlanIsTpwd(Convert.ToInt32(data.id)); UpdateGoodsJoinImageStatusByIds(uid, ids); } else { DeleteUserTaskPlan(flag); } return(false); }
/// <summary> /// 生成淘口令 /// </summary> /// <param name="loginToken">The login token.</param> /// <param name="userid">The userid.</param> /// <param name="taskid">The taskid.</param> /// <param name="templateText">文案</param> /// <param name="result">The result.</param> /// <returns>true if XXXX, false otherwise.</returns> public bool BuildTaskTpwd(string loginToken, int userid, int taskid, string templateText, string appkey, string appsecret, Action <weChatShareTextModel> result = null, bool append = false, bool isJoinImage = false) { var taskData = FindByUserTaskPlanInfo(taskid); if (taskData == null || taskData.ExecStatus != 0) { return(false); } if (string.IsNullOrEmpty(taskData.pidsText) || string.IsNullOrEmpty(taskData.goodsText)) { return(false); } List <UserPidTaskModel> lst = JsonConvert.DeserializeObject <List <UserPidTaskModel> >(taskData.pidsText); List <UserPidTaskModel> lst2 = JsonConvert.DeserializeObject <List <UserPidTaskModel> >(taskData.goodsText); List <int> ids = new List <int>(); //如果群数据和商品数据都为空时 if (lst == null || lst2 == null) { return(false); } lst2.ForEach(item => { if (!ids.Contains(item.id)) { ids.Add(item.id); } }); //获取商品数据 var goodslist = FindByUserGoodsList(ids); if (!append) { ids.Clear(); lst.ForEach(item => { if (!ids.Contains(item.id)) { ids.Add(item.id); } }); //获取微信群数据 var wechatlist = FindByUserWeChatGroup(userid, ids); //删除现有数据 dal.DeleteUserWechatShareText(userid, taskid); List <JoinGoodsList> joinLists = new List <JoinGoodsList>(); foreach (var group in wechatlist) { JoinGoodsList joinList = new JoinGoodsList(); //生成商品分享文本 BuildShareText(loginToken, userid, taskid, templateText, goodslist, group, appkey, appsecret, out joinList, result, isJoinImage); if (isJoinImage && joinList != null) { joinLists.Add(joinList); } } if (isJoinImage) { int flag = BuildJoinImage(loginToken, joinLists, taskData.title, Convert.ToInt32(taskData.id), goodslist.Count()); if (flag > 0) { DeleteUserTaskPlan(flag); } } UpdateUserTaskPlanIsTpwd(taskid); } else { var data = FindByUserWechatShareTextList(userid, taskid); if (data != null) { //获取商品数据 var goods = goodslist[0]; data.ForEach(item => { item.text += templateText; item.text = BuildShareText(item.text, goods); //修改内容 dal.UpdateUserShareText(item.id, item.text); result?.Invoke(item); }); } } return(true); }