Beispiel #1
0
 /// <summary>
 /// 添加评价信息
 /// </summary>
 /// <param name="msg"></param>
 public void WareMessageAdd(ProductMessage msg)
 {
     if (msg == null)
     {
         return;
     }
     OtDB db = GetDb();
     try
     {
         db.Begin();
         //db.Exec(string.Format("delete from ProductMessage where PID = '{0}'", msg.PID));
         db.ExecInsert(msg, "ProductMessage", new string[] { "PID", "MsgType", "MsgContent", "MsgUser", "MsgUserLevel", "MsgProvince", "MsgDate" });
         db.Commit();
     }
     catch (Exception ex)
     {
         OtCom.XLogErr(ex.Message);
         db.Rollback();
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取评价详细信息
        /// </summary>
        /// <param name="tID"></param>
        public void GetEvaluateMsg(string tID, bool needAllComment)
        {
            //差评
            //http://club.jd.com/productpage/p-255742-s-1-t-3-p-0.html?callback=fetchJSON_comment98vv17736
            //中评
            //http://club.jd.com/productpage/p-255742-s-2-t-3-p-0.html?callback=fetchJSON_comment98vv17736
            //好评
            //http://club.jd.com/productpage/p-255742-s-3-t-3-p-0.html?callback=fetchJSON_comment98vv17736
            try
            {
                string url = string.Format("http://club.jd.com/productpage/p-{0}-s-1-t-3-p-0.html", tID);
                string rtnMsg = HttpHelper.GetResponseGBK(url, "get", string.Empty);

                List<EvaluateMsg> getMsgs = new List<EvaluateMsg>();
                EvaluateMsg badMsg = JsonConvert.DeserializeObject<EvaluateMsg>(rtnMsg);
                if (badMsg != null && badMsg.comments != null && badMsg.comments.Count > 0)
                {
                    _myProduct.ProductEvaluateCount = badMsg.productCommentSummary.commentCount;
                    _myProduct.ProductGoodRate = badMsg.productCommentSummary.goodCount;
                    _myProduct.ProductPoorRate = badMsg.productCommentSummary.poorCount;
                    _myProduct.ProductGeneralRate = badMsg.productCommentSummary.generalCount;
                    _myProduct.ProductHotCommentTag = "";
                    if (badMsg.hotCommentTagStatistics != null && badMsg.hotCommentTagStatistics.Count > 0)
                    {
                        foreach (var item in badMsg.hotCommentTagStatistics)
                        {
                            _myProduct.ProductHotCommentTag += item.name + " ";
                        }
                    }
                    if (needAllComment)
                    {
                        getMsgs.Add(badMsg);
                        int iCount = badMsg.productCommentSummary.poorCount;
                        float iNum = (float)iCount / 10;
                        int pagenum = (int)(iCount / 10);
                        if (pagenum < iNum)
                        {
                            pagenum++;
                        }

                        if (pagenum > 1)
                        {
                            for (int i = 1; i <= pagenum; i++)
                            {
                                url = string.Format("http://club.jd.com/productpage/p-{0}-s-1-t-3-p-{1}.html", tID, i);
                                rtnMsg = HttpHelper.GetResponseGBK(url, "get", string.Empty);
                                if (!string.IsNullOrEmpty(rtnMsg))
                                {
                                    badMsg = JsonConvert.DeserializeObject<EvaluateMsg>(rtnMsg);
                                    if (badMsg != null && badMsg.comments != null && badMsg.comments.Count > 0)
                                    {
                                        getMsgs.Add(badMsg);
                                    }
                                }
                            }
                        }
                    }
                }
                if (getMsgs.Count > 0)
                {
                    List<ProductMessage> msgs = new List<ProductMessage>();
                    foreach (var eMsg in getMsgs)
                    {
                        foreach (var item in eMsg.comments)
                        {
                            ProductMessage msg = new ProductMessage()
                            {
                                PID = tID,
                                MsgType = 1,
                                MsgContent = item.content,
                                MsgUser = item.nickname,
                                MsgUserLevel = item.userLevelName,
                                MsgProvince = item.userProvince,
                                MsgDate = item.creationTime
                            };
                            msgs.Add(msg);
                        }
                    }
                    DBHelper.GetInstance().WareMessagesAdd(msgs);
                }
            }
            catch (Exception ex)
            {
                OtCom.XLogErr(ex.Message);
            }
        }