/// <summary> /// 图片详情接口 /// </summary> /// <returns></returns> public void GetItem(HttpContext context) { int pid = GetInt("pid"); SourceMaterial sm = SourceMaterialHelper.GetItem(pid); if (sm == null) { ReturnErrorMsg("图片墙不存在id:" + pid); return; } var url = Utility.GetSizePicUrl(sm.Url, 500, 0, context); var data = new { pid = sm.Id, title = sm.Title, img = url, description = sm.Description, views = sm.Views, commentnum = sm.Commentnum, height = Utility.GetImgHeight(url, context) }; sm.Views += 1; SourceMaterialHelper.Update(sm); JsonTransfer jt = new JsonTransfer(); jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
/// <summary> /// 图片列表接口 /// </summary> /// <returns></returns> public void GetList(HttpContext context) { int pageIndex = GetInt("start"); int pageSize = GetInt("limit"); int sellerId = GetInt("sellerid"); PagResults <SourceMaterial> results = SourceMaterialHelper.GetPaging(pageIndex * pageSize, pageSize, sellerId); var data = new List <object>(); foreach (var r in results.Results) { var imgurl = Utility.GetSizePicUrl(r.Url, 200, 0, context); var d = new { pid = r.Id, img = imgurl, height = Utility.GetImgHeight(imgurl, context), title = r.Title }; r.Views += 1; SourceMaterialHelper.Update(r); data.Add(d); } JsonTransfer jt = new JsonTransfer(); jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
public void Delete() { //int sid = GetInt("sid"); IList <int> ids = Utility.GetListint(GetString("ids")); foreach (var id in ids) { SourceMaterialHelper.Delete(id); } }
/// <summary> /// 图片评论 /// </summary> /// <returns></returns> public void ImgComment() { int userId = GetInt("uid"); int imgId = GetInt("pid"); string msg = GetString("message"); var user = AccountHelper.GetUser(userId); SourceMaterial sm = SourceMaterialHelper.GetItem(imgId); Comment c = new Comment(); c.SellerId = sm.SellerId; c.TypeId = sm.Id; c.UserId = userId; c.Content = msg; c.Type = CommentType.Img; //冗余两个字段 c.Img = sm.Url; c.Title = sm.Title; try { CommentHelper.Create(c); sm.Commentnum += 1; SourceMaterialHelper.Update(sm); } catch { ReturnErrorMsg("fail"); throw; } ExtcreditLog log = new ExtcreditLog(); if (!ExtcreditLogHelper.JudgeExtcreditGet(ExtcreditSourceType.CommentImg, imgId, userId)) { //积分获得 log.UserId = userId; log.SellerId = user.SellerId; log.SourceId = imgId; var setting = SystemHelper.GetMerchantExtend(user.SellerId); log.Extcredit = setting != null ? setting.CommentIntegral : 0; log.Type = ExtcreditSourceType.CommentImg; log.CreateTime = DateTime.Now; ExtcreditLogHelper.AddExtcreditLog(log); user.Integral += log.Extcredit; AccountHelper.SaveAccount(user); } //ReturnCorrectMsg("评论成功"); JsonTransfer jt = new JsonTransfer(); jt.Add("data", new IntegralData(log.Extcredit)); jt.AddSuccessParam(); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
private void Update() { var id = GetInt("id"); var sm = SourceMaterialHelper.GetItem(id); sm.Title = GetString("title"); sm.Url = GetString("thumbnail"); var text = GetString("text"); //sm.Summary = text.Length > 20 ? text.Substring(0, 20) : text; sm.Description = GetString("content"); SourceMaterialHelper.Update(sm); }
/// <summary> /// 图片评论列表 /// </summary> /// <returns></returns> public void ImgCommentList(HttpContext context) { int pid = GetInt("pid"); int index = GetInt("start"); int size = GetInt("limit"); if (pid == 0) { ReturnErrorMsg("请传入正确的pid"); return; } SourceMaterial sm = SourceMaterialHelper.GetItem(pid); var cms = CommentHelper.GetPagings(sm.SellerId, CommentType.Img, pid, index * size, size, "order by CreateTime desc"); var data = new CommentsForApis(); data.Commentnum = cms.TotalCount; JsonTransfer jt = new JsonTransfer(); if (cms.Results.Count < 1) { jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); return; } var users = AccountHelper.GetUserList(cms.Results.Select(c => c.UserId).ToList()); foreach (var cm in cms.Results) { var user = users.FirstOrDefault(u => u.Id == cm.UserId); if (user == null) { throw new ArgumentNullException(string.Format("userId:{0}", cm.UserId)); } var result = new ComentsForApi { Avatar = Utility.GetSizePicUrl(user.Avatar, 100, 100, context), UserName = user.UserName, Sex = (int)user.Sex, Dateline = cm.CreateTime.GetUnixTime(), Message = cm.Content }; data.Comments.Add(result); } jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
/// <summary> /// 图片列表接口 /// </summary> /// <returns></returns> public void GetList() { int pageIndex = GetInt("start"); int pageSize = GetInt("limit"); int sellerId = GetInt("sellerid"); PagResults <SourceMaterial> data = SourceMaterialHelper.GetPaging(pageIndex * pageSize, pageSize, sellerId); JsonTransfer jt = new JsonTransfer(); jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
private void Add() { var sm = new SourceMaterial(); sm.SellerId = GetInt("sellerid"); sm.Title = GetString("title"); sm.Url = GetString("thumbnail"); var text = GetString("text"); //sm.Summary = text.Length > 20 ? text.Substring(0, 20) : text; sm.Description = GetString("content"); sm.CreateTime = DateTime.Now; sm.ImageType = UploadType.Img; SourceMaterialHelper.Create(sm); }
/// <summary> /// 图片详情接口 /// </summary> /// <returns></returns> public void GetItem() { int pid = GetInt("pid"); SourceMaterial data = SourceMaterialHelper.GetItem(pid); if (data == null) { ReturnErrorMsg("图片墙不存在pid:" + pid); return; } JsonTransfer jt = new JsonTransfer(); jt.AddSuccessParam(); jt.Add("data", data); Response.Write(DesEncrypt(jt).ToLower()); Response.End(); }
public override void ProcessRequest(HttpContext context) { RoleType = RoleType.ThirdUser; //需商家管理权限 UploadType imgType = (UploadType)Convert.ToInt32(context.Request.QueryString["type"]); var qsellerId = context.Request.QueryString["sellerid"]; var sellerId = 0; if (!string.IsNullOrEmpty(qsellerId)) { sellerId = Convert.ToInt32(qsellerId); } base.ProcessRequest(HttpContext.Current); //String aspxUrl = context.Request.Path.Substring(0, context.Request.Path.LastIndexOf("/") + 1); var userFileName = CurrentUser.Id.ToString(); var isManager = 0; if (CurrentUser.RoleType < RoleType.Merchant) { userFileName = sellerId.ToString(); if (sellerId == 0 || sellerId == CurrentUser.Id) { userFileName = "admin"; isManager = 1; } } // isManager = 1; //if (isManager == 1) //{ // //管理员上传的图片 统一到一个目录 // userFileName = "admin"; //} //文件保存目录路径 String savePath = "../../File/" + userFileName + "/";// "../attached/"; UploadType type = (UploadType)Convert.ToInt32(context.Request.QueryString["type"]); //文件保存目录URL String saveUrl = Utility._domainurl + "/File/" + userFileName + "/";; // "../attached/"; //定义允许上传的文件扩展名 Hashtable extTable = new Hashtable(); if (type == UploadType.MerchantLoginAd) { extTable.Add("image", "png"); } else { extTable.Add("image", "gif,jpg,jpeg,png,bmp"); extTable.Add("flash", "swf,flv"); extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2,apk,ipa"); } //最大文件大小 int maxSize = 1073741824; HttpPostedFile imgFile = context.Request.Files["imgFile"]; if (imgFile == null) { showError("请选择文件。"); } String dirPath = context.Server.MapPath(savePath); if (!Directory.Exists(dirPath)) { //showError("上传目录不存在。"); Directory.CreateDirectory(dirPath); } String dirName = context.Request.QueryString["dir"]; //if (String.IsNullOrEmpty(dirName)) //{ // dirName = "image"; //} if (!extTable.ContainsKey(dirName)) { showError("目录名不正确。"); } String fileName = imgFile.FileName; String fileExt = Path.GetExtension(fileName).ToLower(); if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize) { showError("上传文件大小超过限制。"); } if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1) { showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。"); } var typeName = GetTypeName(context); //创建文件夹 dirPath += dirName + typeName + "/"; saveUrl += dirName + typeName + "/"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } //管理员素材库统一到一个文件夹即可 登录页大图IOS那边需要固定地址图片http://XXX/{sellerid}/XXX/1280x800.jpg if (isManager == 0 && type != UploadType.MerchantLoginAd) { String ymd = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo); dirPath += ymd + "/"; saveUrl += ymd + "/"; } if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } //String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; //String filePath = dirPath + newFileName; var originalFileName = DateTime.Now.ToUnixTime().ToString() + Utility.GetRandom(1, 1000); fileName = originalFileName + fileExt; //fileName = fileName.Replace(',', '.');//防止图片名称中存在,分隔符 String filePath = dirPath + fileName; var index = 2; while (File.Exists(filePath)) { fileName = originalFileName + string.Format("({0})", index) + fileExt; filePath = dirPath + fileName; index++; } imgFile.SaveAs(filePath); if ((int)((int)imgType / 100) == 1) { //图片处理 生成不同尺寸图片 var list = ImgSizeCfgHelper.GetImgSizeCfgList(imgType); foreach (var imgSizeCfg in list) { Utility.MakeThumNail(filePath, imgSizeCfg.Width, imgSizeCfg.Height); } } //String fileUrl = saveUrl + newFileName; String fileUrl = saveUrl + fileName; var addId = 0; //添加商户图片 if (imgType == UploadType.Img) { //TODO:暂时这么添加 图片名称及图片描述 这个后面再根据需求定怎么赋初值 后面应该加上图片类型!(上传) var sm = new SourceMaterial(); sm.SellerId = sellerId == 0 ? CurrentUser.Id : sellerId;//管理员在商户管理页面上传的图片归商户管理 sm.Title = Path.GetFileNameWithoutExtension(fileName); sm.Url = fileUrl; sm.Description = Path.GetFileNameWithoutExtension(fileName); sm.CreateTime = DateTime.Now; sm.ImageType = UploadType.Img; addId = SourceMaterialHelper.Create(sm); } Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = fileUrl; hash["id"] = addId; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonMapper.ToJson(hash)); context.Response.End(); }