/// <summary> /// 新增商品 /// lz /// 2016-09-26 /// </summary> //[HttpPost] public ActionResult Add() { var sr = RequestResult(res => { #region 获取参数 Hashtable param = base.GetParameters(); ParamVessel p = new ParamVessel(); p.Add("id_shop", string.Empty, HandleType.ReturnMsg); //门店id * p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //主用户id * p.Add("id_user", string.Empty, HandleType.ReturnMsg); //用户id * p.Add("barcode", string.Empty, HandleType.ReturnMsg); //条码 * p.Add("bm", string.Empty, HandleType.ReturnMsg); //编码 * p.Add("mc", string.Empty, HandleType.ReturnMsg); //名称 * p.Add("dj_jh", 0m, HandleType.DefaultValue); //进货价 p.Add("dj_ls", 0m, HandleType.DefaultValue); //零售价 p.Add("dj_hy", 0m, HandleType.DefaultValue); //会员价 p.Add("dj_ps", 0m, HandleType.DefaultValue); //配送价 p.Add("dw", string.Empty, HandleType.ReturnMsg); //单位 * p.Add("sl_kc_min", 0m, HandleType.DefaultValue); //最底库存量 * p.Add("sl_kc_max", 0m, HandleType.DefaultValue); //最高库存量 * p.Add("flag_czfs", string.Empty, HandleType.ReturnMsg); //计价方式 * p.Add("id_spfl", string.Empty, HandleType.ReturnMsg); //分类ID * p.Add("yxq", 0, HandleType.DefaultValue); //保质期 天 p.Add("cd", string.Empty, HandleType.DefaultValue); //产地 p.Add("pic_path", string.Empty, HandleType.DefaultValue); //图片路径 p.Add("id_gys", string.Empty, HandleType.DefaultValue); //默认供应商 p.Add("bz", string.Empty, HandleType.DefaultValue); //备注 p.Add("dj_pf", 0m, HandleType.DefaultValue); //批发价 目前此字段没用 p.Add("je_qc", 0m, HandleType.DefaultValue); //期初金额 p.Add("sl_qc", 0m, HandleType.DefaultValue); //期初数量 p.Add("dbzList", string.Empty, HandleType.DefaultValue); //多包装 p.Add("sign", string.Empty, HandleType.ReturnMsg); //sign #endregion #region 验证参数 try { param = param.Trim(p); } catch (Exception ex) { res.State = ServiceState.Fail; res.Message = ServiceFailCode.A0001; return(res); } #endregion #region 读取ticket //读取ticket Hashtable ht = new Hashtable(); ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString()); var ticketBr = base.GetTicketInfo(param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString()); if (!ticketBr.Success) { res.State = ServiceState.Fail; res.Message = ServiceFailCode.S0001; return(res); } var ticketModel = (Tb_Ticket)ticketBr.Data; if (ticketModel == null) { res.State = ServiceState.Fail; res.Message = ServiceFailCode.A0003; return(res); } var ticket = ticketModel.ticket; #endregion #region 验证签名 IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "id_user", "barcode", "bm", "mc", "dj_jh", "dj_ls", "dj_hy", "dj_ps", "dw", "sl_kc_min", "sl_kc_max", "flag_czfs", "id_spfl", "yxq", "cd", "pic_path", "id_gys", "bz", "je_qc", "sl_qc", "dbzList" }); var validSign = SignUtils.SignRequest(dic, ticket); //验证签名 if (param["sign"].ToString() != validSign) { res.State = ServiceState.Fail; res.Message = ServiceFailCode.A0002; return(res); } #endregion #region 验证参数是否符合 #region 多包装 //多包装 var dbzList = new List <Tb_Shopsp_DBZ>(); try { dbzList = JSON.Deserialize <List <Tb_Shopsp_DBZ> >(param["dbzList"].ToString()) ?? new List <Tb_Shopsp_DBZ>(); foreach (var item in dbzList) { item.id = Guid.NewGuid().ToString(); item.info_type = "add"; } } catch (Exception ex) { res.State = ServiceState.Fail; res.Message = "操作失败 多包装不符合要求!"; return(res); } #endregion #region 期初 //期初 var qcModel = new Td_Sp_Qc() { sl_qc = decimal.Parse(param["sl_qc"].ToString()), je_qc = decimal.Parse(param["je_qc"].ToString()) }; #endregion #region 验证数据 //控制层验证数据 var brCheck = this.CheckParam(param, qcModel, dbzList); if (!brCheck.Success) { res.State = ServiceState.Fail; res.Message = string.Join(";", brCheck.Message); return(res); } #endregion #region 数据处理 #region 图片 // 图片 if (param["pic_path"] != null && !string.IsNullOrEmpty(param["pic_path"].ToString())) { CheckImgPath(); string[] url_img = param["pic_path"].ToString().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string guid = Guid.NewGuid().ToString(); string extension = Path.GetExtension(url_img[url_img.Length - 1]); string fileName = guid + extension; ImgExtension.MakeThumbnail(param["pic_path"].ToString(), "/UpLoad/Goods/thumb/_480x480_" + fileName, 480, 480, ImgCreateWay.Cut, false); string newPath = string.Format("/UpLoad/Goods/thumb/_480x480_{0}", fileName); ; ; //480x480 param.Remove("pic_path"); param.Add("pic_path", newPath); } #endregion #region 多包装 if (param.ContainsKey("dbzList")) { param.Remove("dbzList"); } param.Add("dbzList", dbzList); #endregion #region 期初 if (param.ContainsKey("sp_qc")) { param.Remove("sp_qc"); } param.Add("sp_qc", qcModel); #endregion #region 用户管理门店 var brShopShop = this.GetUserShopShop(param["id_masteruser"].ToString(), param["id_shop"].ToString(), param["id_user"].ToString()); if (!brShopShop.Success) { res.State = ServiceState.Fail; res.Message = string.Join(";", brShopShop.Message); return(res); } var shopShopList = (List <Tb_User_ShopWithShopMc>)brShopShop.Data; param.Add("shop_shop", shopShopList); #endregion #region 获取小数点位数 var DigitHashtable = BusinessFactory.Account.GetParm(param["id_masteruser"].ToString()); if (!param.ContainsKey("DigitHashtable")) { param.Add("DigitHashtable", DigitHashtable); } #endregion #endregion #endregion #region 保存至本地图片 if (param.ContainsKey("pic_path") && !string.IsNullOrEmpty(param["pic_path"].ToString())) { var pic_path = BusinessFactory.Tb_Shopsp.GetBarcodePic(new Tb_Shopsp_Service() { BarCode = param["barcode"].ToString(), Picture = param["pic_path"].ToString() }); param["pic_path"] = pic_path; } #endregion #region 新增 var br = BusinessFactory.Tb_Shopsp.Add(param); #endregion #region 返回 res.State = br.Success ? ServiceState.Done : ServiceState.Fail; res.Message = br.Message.FirstOrDefault(); if (br.Success) { res.Data = br.Data; } return(res); #endregion }); return(JsonString(sr)); }
public override BaseResult Update(dynamic entity) { BaseResult br = new BaseResult(); Hashtable param = new Hashtable(); Tb_User_Query model = (Tb_User_Query)entity; //if (!model.email.IsEmpty() && model.email != model.email_old) //{ // param.Clear(); // param.Add("not_id", model.id); // param.Add("email", model.email); // if (DAL.GetCount(typeof(Tb_User), param) > 0) // { // br.Success = true; // br.Message.Add("此邮箱已被占用"); // br.Level = ErrorLevel.Warning; // br.Data = "email"; // return br; // } //} DateTime dbDateTime = DAL.GetDbDateTime(); param.Clear(); param.Add("id", model.id); param.Add("new_companyname", model.companyname); //param.Add("new_id_hy", model.id_hy); param.Add("new_id_province", model.id_province); param.Add("new_id_city", model.id_city); param.Add("new_id_county", model.id_county); param.Add("new_address", model.address); param.Add("new_zipcode", model.zipcode); param.Add("new_tel", model.tel); param.Add("new_fax", model.fax); //param.Add("new_location", model.location); //param.Add("new_pic_erwei", model.pic_erwei); //param.Add("new_name", model.name); //param.Add("new_job", model.job); //param.Add("new_phone", model.phone); //param.Add("new_qq", model.qq); //param.Add("new_email", model.email); param.Add("new_id_edit", model.id_edit); param.Add("new_rq_edit", dbDateTime); DAL.UpdatePart(typeof(Tb_User), param); //图片上传 if (model.picUrl != null && model.picUrl.Count > 0) { Tb_User_Pic pic; int xh = 0; //获取图册结果集 param.Clear(); param.Add("id_master", model.id_master); IList <Tb_User_Pic> lst = DAL.QueryList <Tb_User_Pic>(typeof(Tb_User_Pic), param) ?? new List <Tb_User_Pic>(); if (lst.Count > 0) { xh = Convert.ToInt32(lst[lst.Count - 1].xh); //取最大的序号 } foreach (var url in model.picUrl) { //只添加新上传的图片 if (url.Contains("Temp")) { pic = new Tb_User_Pic(); string[] url_img = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string guid = Guid.NewGuid().ToString(); string extension = Path.GetExtension(url_img[url_img.Length - 1]); //取图片后缀名 string fileName = guid + extension; //文件名 // 复制原图到 Master 文件夹下 FileExtension.Copy(System.Web.HttpContext.Current.Server.MapPath(url), System.Web.HttpContext.Current.Server.MapPath("/UpLoad/User/Master/" + fileName)); //生成缩略图至UpLoad/Master下 ImgExtension.MakeThumbnail(url, "/UpLoad/User/Master/_480x480_" + fileName, 480, 480, ImgCreateWay.Cut, false); pic.photo = string.Format("/UpLoad/User/Master/{0}", fileName); pic.photo_min = string.Format("/UpLoad/User/Master/_480x480_{0}", fileName); //pic.id_create = model.id; pic.id_master = model.id_master; xh++; pic.xh = Convert.ToByte(xh); DAL.Add(pic); } } } br.Success = true; br.Message.Add(String.Format("更新公司信息。信息:流水号:{0},公司名称:{1}", model.id, model.companyname)); return(br); }
public ActionResult UploadPic(string obj) { BaseResult br = new BaseResult(); Hashtable param = JSON.Deserialize <Hashtable>(obj); ParamVessel p = new ParamVessel(); p.Add("id_master", (long)0, HandleType.ReturnMsg); param = param.Trim(p); try { HttpPostedFileBase postedFile = Request.Files.Count > 0 ? Request.Files[0] : null; if (postedFile == null || postedFile.ContentLength <= 0) { br.Success = false; br.Level = ErrorLevel.Error; br.Message.Add("<h5>上传失败</h5>"); br.Message.Add(""); br.Message.Add("未发现上传的文件!"); return(Json(br)); } if (!CyVerify.IsImage(postedFile.InputStream)) { br.Success = false; br.Message.Add("<h5>上传失败</h5>"); br.Message.Add(""); br.Message.Add("上传的文件格式不正确,必须图片文件!"); br.Level = ErrorLevel.Warning; return(Json(br)); } Tb_User_Pic pic = new Tb_User_Pic(); string guid = Guid.NewGuid().ToString(); string extension = Path.GetExtension(postedFile.FileName); string fileName = guid + extension; //文件名 string url = "/UpLoad/User/Master/" + fileName; //存入数据库中的图片路径 string fileFullName = ApplicationInfo.UserMasterPath + "\\" + fileName; if (!Directory.Exists(ApplicationInfo.UserMasterPath)) { Directory.CreateDirectory(ApplicationInfo.UserMasterPath); } //上传原图 postedFile.SaveAs(fileFullName); //生成缩略图至UpLoad/Master下 string minUrl = "/UpLoad/User/Master/_480x480_" + fileName; ImgExtension.MakeThumbnail(url, minUrl, 480, 480, ImgCreateWay.Cut, false); pic.id_master = long.Parse(param["id_master"].ToString()); pic.id_create = GetLoginInfo <long>("id_user"); pic.photo = url; pic.photo_min = minUrl; br = BusinessFactory.UserPic.Add(pic); br.Data = url; br.Success = true; } catch (CySoftException cex) { br = cex.Result; } catch (Exception) { br.Success = false; br.Level = ErrorLevel.Error; br.Message.Add("<h5>上传失败</h5>"); br.Message.Add(""); br.Message.Add("请重试或与管理员联系!"); } return(Json(br)); }
public ActionResult Edit(Tb_Shop model) { var oldParam = new Hashtable(); BaseResult br = new BaseResult(); br.Success = true; var jumpUrl = ""; try { #region 获取数据 Hashtable param = base.GetParameters(); ParamVessel p = new ParamVessel(); p.Add("id", string.Empty, HandleType.ReturnMsg); //ID p.Add("yzm", string.Empty, HandleType.DefaultValue); //验证码 p.Add("bm", string.Empty, HandleType.ReturnMsg); //编码 p.Add("mc", string.Empty, HandleType.ReturnMsg); //名称 p.Add("email", string.Empty, HandleType.DefaultValue); //电子邮箱 p.Add("phone", string.Empty, HandleType.DefaultValue); //移动电话 p.Add("tel", string.Empty, HandleType.DefaultValue); //联系电话 p.Add("fax", string.Empty, HandleType.DefaultValue); p.Add("lxr", string.Empty, HandleType.DefaultValue); p.Add("zipcode", string.Empty, HandleType.DefaultValue); p.Add("address", string.Empty, HandleType.DefaultValue); p.Add("bz", string.Empty, HandleType.DefaultValue); p.Add("pic_path", string.Empty, HandleType.DefaultValue);//门店图片 p.Add("flag_state", string.Empty, HandleType.Remove); p.Add("qq", string.Empty, HandleType.DefaultValue); p.Add("flag_type", string.Empty, HandleType.ReturnMsg); //门店类型 p.Add("kh_id", string.Empty, HandleType.DefaultValue); //kh_id p.Add("id_shop_ps", string.Empty, HandleType.DefaultValue); //id_shop_ps //配送中心 param = param.Trim(p); param.Add("id_masteruser", id_user_master); param.Add("id_user", id_user); param.Add("id_cyuser", id_cyuser); param.Add("rq_create_master_shop", rq_create_master_shop.ToString()); param.Add("version", version); oldParam = (Hashtable)param.Clone(); #endregion #region 图片 // 图片 if (param["pic_path"] != null && !string.IsNullOrEmpty(param["pic_path"].ToString())) { if (!param["pic_path"].ToString().Contains("/UpLoad/Shops/thumb/")) { CheckImgPath(); string[] url_img = param["pic_path"].ToString().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string guid = Guid.NewGuid().ToString(); string extension = Path.GetExtension(url_img[url_img.Length - 1]); string fileName = guid + extension; ImgExtension.MakeThumbnail(param["pic_path"].ToString(), "/UpLoad/Shops/thumb/_480x480_" + fileName, 819, 306, ImgCreateWay.Cut, false); string newPath = string.Format("/UpLoad/Shops/thumb/_480x480_{0}", fileName);//480x480 param.Remove("pic_path"); param.Add("pic_path", newPath); } } #endregion if (param.ContainsKey("flag_state") && param["flag_state"].ToString() == ((byte)Enums.TbShopFlagState.Opened).ToString()) { if (PublicSign.flagCheckService == "1") { #region 根据版本获取 服务编码 var bm = BusinessFactory.Account.GetServiceBM(version); if (string.IsNullOrEmpty(bm)) { return(base.JsonString(new { status = "error", message = "操作失败 获取服务编码异常 请检查版本是否正常!" })); } #endregion #region 获取购买服务的地址 Hashtable ht = new Hashtable(); ht.Add("id_cyuser", id_cyuser); ht.Add("id", bm); ht.Add("phone", phone_master); ht.Add("service", "Detail"); ht.Add("id_masteruser", id_user_master); string buyUrl = BusinessFactory.Tb_Shop.GetBuyServiceUrl(ht); if (string.IsNullOrEmpty(buyUrl)) { buyUrl = PublicSign.cyBuyServiceUrl; } buyUrl = HttpUtility.UrlEncode(buyUrl, Encoding.UTF8); jumpUrl = buyUrl = HttpUtility.UrlEncode(buyUrl, Encoding.UTF8); #endregion } } else if (param.ContainsKey("flag_state") && param["flag_state"].ToString() == ((byte)Enums.TbShopFlagState.Closed).ToString()) { if (id_shop_master == param["id"].ToString()) { return(base.JsonString(new { status = "error", message = "操作失败 主门店不允许停用!" })); } } br = BusinessFactory.Tb_Shop.Save(param); WriteDBLog("编辑门店", oldParam, br); if (br.Success) { return(base.JsonString(new { status = "success", message = "执行成功,正在载入页面..." })); } else { return(base.JsonString(new { status = "error", message = string.Join(";", br.Message) })); } } catch (CySoftException ex) { br.Success = false; br.Data = ""; br.Message.Clear(); br.Message.Add(ex.Message); WriteDBLog("编辑门店", oldParam, br); return(base.JsonString(new { status = "error", message = string.Join(";", br.Message), level = 3, url = jumpUrl })); } catch (Exception ex) { br.Success = false; br.Data = ""; br.Message.Add("数据不符合要求!"); br.Level = ErrorLevel.Warning; WriteDBLog("编辑门店", oldParam, br); return(base.JsonString(new { status = "error", message = string.Join(";", br.Message) })); } }