public static LogicHotTao Instance(int userid) { if (_instance == null) { _instance = new LogicHotTao(); } if (dal == null && userid > 0) { dal = new HotTaoDAL(userid); } return(_instance); }
/// <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)); }
/// <summary> /// 下载商品图片 /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="goodsImageUrl">The goods image URL.</param> private void downloadGoodsImage(string fileName, string goodsImageUrl, string goodsid, int userid) { new System.Threading.Thread(() => { try { string _goodsid = goodsid; byte[] data = BaseRequestService.GetNetWorkImageData(goodsImageUrl); if (data == null) { System.Threading.Thread.Sleep(1000); data = BaseRequestService.GetNetWorkImageData(goodsImageUrl); } if (data != null) { MemoryStream ms = new MemoryStream(data); Bitmap img = new Bitmap(ms); img.Save(fileName, ImageFormat.Jpeg); ms.Dispose(); ms = null; img.Dispose(); img = null; } else { LogicHotTao.Instance(userid).DeleteGoodsByGoodsid(goodsid); } } catch (Exception ex) { } }) { IsBackground = true }.Start(); }