public JsonResult PicUpload()
        {
            var r = new List <ViewDataUploadFilesResult>();

            if (Request.Files.Count > 0)
            {
                try
                {
                    DateTime now      = DateTime.Now;
                    string   vpath    = "/Site/Goods/" + now.ToString("yyyyMMdd") + "/";
                    string   realpath = Server.MapPath(vpath);
                    if (!Directory.Exists(realpath))
                    {
                        Directory.CreateDirectory(realpath);
                    }
                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        var    file    = Request.Files[i];
                        string fileext = Path.GetExtension(file.FileName);
                        if (string.IsNullOrEmpty(fileext) || !fileext.StartsWith("."))
                        {
                            fileext = ".png";
                        }
                        string fname = Guid.NewGuid().ToString() + fileext.ToLower();
                        //if (System.IO.File.Exists(realpath + fname))
                        //{
                        //    fname = now.Ticks.ToString() + "_" + fname;
                        //}
                        file.SaveAs(realpath + fname);

                        var pic = new St_pic();
                        pic.AddTime = now;
                        pic.PicType = 5;
                        pic.PicUrl  = vpath + fname;
                        int pid = DBService.AddEntity <St_pic>(pic, true);

                        r.Add(new ViewDataUploadFilesResult()
                        {
                            ppid = pid,
                            name = fname,
                            size = file.ContentLength,
                            type = file.ContentType,
                            url  = vpath + fname
                        });
                    }
                }
                catch
                {
                }
            }

            return(Json(r));
        }
        public ActionResult PublishItem(PublishItem model)
        {
            WebResult result = new WebResult
            {
                Code    = AppConst.MSG_ERR,
                Message = string.Empty
            };

            bool IsVip = false;//当前用户

            if (model.uid > 0)
            {
                var memb = MemberService.GetMemberFromUser(model.uid);
                if (memb != null && memb.Id > 0 && memb.Level != "" && memb.Level != "普通会员" && memb.VipOverDate.HasValue && memb.VipOverDate.Value > DateTime.Now)
                {
                    IsVip = true;
                }
            }
            //判断是否出售且用户为vip
            if (model.GoodsType == 0 && !IsVip)
            {
                result.Message = "非VIP用户不能发布出售信息!";
                return(Content(JsonConvert.SerializeObject(result)));
            }

            if (model.MainPicName.Equals(string.Empty))
            {
                //result.Message = "主图不能为空!";
                //return Content(JsonConvert.SerializeObject(result));
                model.MainPicName = "/Images/stock.jpg";
            }

            //Save Item
            var item = new St_good();

            item.AddTime = DateTime.Now;
            int uid = model.uid;

            if (uid > 0)
            {
                item.AddUser = uid;
                var member = MemberService.GetMemberFromUser(uid);
                if (member != null && member.Id > 0)
                {
                    item.MemberId = member.Id;
                }
            }
            item.Details = model.Details;
            if (!model.MainPicName.Equals(string.Empty))
            {
                try
                {
                    //DateTime now = DateTime.Now;
                    //string vpath = "/Site/Goods/" + now.ToString("yyyyMMdd") + "/";
                    //string realpath = Server.MapPath(vpath);
                    //if (!Directory.Exists(realpath))
                    //Directory.CreateDirectory(realpath);
                    //string filename = model.MainPic.FileName;
                    //if (System.IO.File.Exists(realpath + filename))
                    //{
                    //filename = now.Ticks.ToString() + "_" + filename;
                    //}
                    //model.MainPic.SaveAs(realpath + filename);
                    item.MainPic = model.MainPicName;
                }
                catch
                {
                }
            }
            item.CatId = model.CatId;
            if (model.CatId > 0)
            {
                var ccat = DBService.GetEntity <St_cat>(model.CatId);
                if (ccat != null && ccat.Id > 0)
                {
                    item.CatPath = ccat.Path;
                }
            }
            item.ModifyTime       = DateTime.Now;
            item.Name             = model.Name;
            item.Price            = model.Price;
            item.PriceDetail      = model.PriceDetail;
            item.Qty              = model.Qty;
            item.QtyDetail        = model.QtyDetail;
            item.Status           = 0;
            item.ViewCount        = 0;
            item.ContactViewCount = 0;
            item.GoodsType        = model.GoodsType;
            item.RealName         = model.RealName;
            item.QQ     = model.QQ;
            item.Mobile = model.Mobile;
            item.Tel    = model.Tel;
            item.Wechat = model.Wechat;
            item.Addr   = model.Addr;
            int gid = DBService.AddEntity <St_good>(item, true);

            if (gid > 0 && !string.IsNullOrEmpty(model.OPics))
            {
                var aids   = model.OPics.Split(',');
                var picids = new List <int>();
                int tempid = 0;
                foreach (var aid in aids)
                {
                    var pic = new St_pic();
                    pic.AddTime = DateTime.Now;
                    pic.PicType = 5;
                    pic.PicUrl  = aid;
                    int pid = DBService.AddEntity <St_pic>(pic, true);
                    //if (!string.IsNullOrEmpty(pid) && int.TryParse(pid, out tempid))
                    if (pid > 0)
                    {
                        picids.Add(pid);
                    }
                }
                if (picids.Count > 0)
                {
                    StockService.UpdateStockPics(gid, picids);
                }
            }

            //return RedirectToAction("Stocks", "Manage");
            //ViewBag.PCats = StockService.GetStockCats();
            //return View(model);
            result.Code = AppConst.MSG_SUCCESS;
            return(Content(JsonConvert.SerializeObject(result)));
        }