Beispiel #1
0
        /// <summary>
        /// 采集商品
        /// </summary>
        private void GetGoodsInfo()
        {
            CurrentGoods = null;
            List <Dictionary <string, string> > list = new List <Dictionary <string, string> >();
            Dictionary <string, string>         data = new Dictionary <string, string>();

            data["url"]  = txtGoodsUrl.Text.Trim();
            data["url2"] = txtCouponUrl.Text.Trim();
            list.Add(data);
            string jsonUrls = JsonConvert.SerializeObject(list);

            new System.Threading.Thread(() =>
            {
                //根据地址,获取商品优惠信息
                List <GoodsSelectedModel> goodsData = LogicGoods.Instance.getGoodsByLink(MyUserInfo.LoginToken, jsonUrls);
                try
                {
                    if (goodsData != null && goodsData.Count() > 0)
                    {
                        CurrentGoods = goodsData[0];
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            })
            {
                IsBackground = true
            }.Start();
        }
        public GoodsSelectedModel GetGoodsInfo(string goodsId)
        {
            ITopClient            client = new DefaultTopClient(url, appkey, appsecret);
            TbkItemInfoGetRequest req    = new TbkItemInfoGetRequest();

            req.Fields   = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            req.Platform = 1L;
            req.NumIids  = goodsId;
            TbkItemInfoGetResponse rsp = client.Execute(req);

            if (!rsp.IsError)
            {
                List <NTbkItem> data = rsp.Results;
                if (data != null && data.Count() > 0)
                {
                    NTbkItem           item  = data[0];
                    GoodsSelectedModel model = new GoodsSelectedModel()
                    {
                        goodsId          = item.NumIid.ToString(),
                        goodsName        = item.Title,
                        goodsPrice       = Convert.ToDecimal(item.ZkFinalPrice),
                        goodsDetailUrl   = item.ItemUrl,
                        goodsImageUrl    = item.PictUrl,
                        goodsSalesAmount = Convert.ToInt32(item.Volume),
                    };
                    return(model);
                }
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// 商品入库
        /// </summary>
        /// <param name="item"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public int SaveGoods(GoodsSelectedModel item, int userid, out bool isUpdate)
        {
            isUpdate = false;
            if (item.couponPrice <= 0 || item.goodsPrice - item.couponPrice <= 0)
            {
                return(0);
            }
            GoodsModel goods = new GoodsModel()
            {
                userid           = userid,
                goodsId          = item.goodsId.Replace("=", ""),
                goodsName        = item.goodsName,
                goodsIntro       = item.goodsIntro,
                goodsMainImgUrl  = item.goodsImageUrl,
                goodsDetailUrl   = item.goodsDetailUrl,
                goodsSupplier    = string.IsNullOrEmpty(item.goodsPlatform) ? "淘宝" : item.goodsPlatform,
                goodsComsRate    = item.goodsComsRate,
                goodsPrice       = item.goodsPrice,
                goodsSalesAmount = item.goodsSalesAmount,
                endTime          = Convert.ToDateTime(item.endTime),
                couponUrl        = item.couponUrl,
                couponId         = item.couponId.Replace("activityId=", "").Replace("activity_id=", "").Replace("activity_Id=", ""),
                couponPrice      = item.couponPrice
            };

            if (string.IsNullOrEmpty(goods.couponId))
            {
                System.Text.RegularExpressions.Regex regs = new System.Text.RegularExpressions.Regex("&activityId=[^&]*", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                string couponUrl = item.couponUrl.Replace("activity_id=", "activityId=").Replace("activity_Id=", "activityId=");
                System.Text.RegularExpressions.Match m = regs.Match(couponUrl);
                if (m.Success)
                {
                    goods.couponId = m.Value.Replace("&activityId=", "");
                }
            }

            string fileName = Environment.CurrentDirectory + "\\temp\\img\\" + userid;

            if (!Directory.Exists(fileName))
            {
                Directory.CreateDirectory(fileName);
            }
            fileName += "\\" + EncryptHelper.MD5(goods.goodsId) + ".jpg";
            //判断文件是否存在
            if (!File.Exists(fileName))
            {
                downloadGoodsImage(fileName, goods.goodsMainImgUrl, goods.goodsId, userid);
            }
            goods.goodslocatImgPath = fileName;
            return(LogicHotTao.Instance(userid).AddUserGoods(goods, out isUpdate));
        }