public JsonResult SingleProductAddSave(T_goodsGY model) { string name = Server.UrlDecode(Request.Cookies["Nickname"].Value); using (TransactionScope sc = new TransactionScope()) { model.create_date = DateTime.Now; model.create_Name = name; db.T_goodsGY.Add(model); try { int i = db.SaveChanges(); if (i > 0) { App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"skus\":[]" + "}"; string sign = gy.Sign(cmd); string comcode = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"sign\":\"" + sign + "\"," + "\"skus\":[]" + "}"; string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string sd = jsonData[0].ToString(); if (sd == "True") { sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet)); } } } catch (DbEntityValidationException ex) { return(Json(new { State = "Faile", Message = ex.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult ViewSingleProductsplitCheckSave(string code) { using (TransactionScope sc = new TransactionScope()) { T_goodsGY model = db.T_goodsGY.SingleOrDefault(a => a.code == code); model.isexamine = "1"; db.Entry <T_goodsGY>(model).State = System.Data.Entity.EntityState.Modified; try { int i = db.SaveChanges(); if (i > 0) { App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"skus\":[]" + "}"; string sign = gy.Sign(cmd); string comcode = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"sign\":\"" + sign + "\"," + "\"skus\":[]" + "}"; string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string sd = jsonData[0].ToString(); if (sd == "True") { sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet)); } } } catch (DbEntityValidationException ex) { return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile", Message = "审核失败" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult WDTExpressTb() { int page_no = 0; int c = 0; int s = 0; App_Code.GY gy = new App_Code.GY(); //do //{ dic.Clear(); //dic.Add("mine", "0"); dic.Add("sid", "hhs2"); dic.Add("appkey", "hhs2-ot"); dic.Add("timestamp", GetTimeStamp()); //dic.Add("page_no", page_no.ToString());//页号 var cmd = CreateParam(dic, true); string ret = gy.DoPostnew("http://121.41.177.115/openapi2/logistics.php", cmd, Encoding.UTF8); string ssx = Regex.Unescape(ret); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string iscode = jsonData["code"].ToString(); if (iscode != "0") { return(Json("", JsonRequestBehavior.AllowGet)); } JsonData jsontrades = jsonData["logistics_list"]; c = jsontrades.Count; return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取旺店通 /// </summary> /// <param name="code"></param> /// <returns></returns> public JsonResult QuyerOrderBYcode(string code) { Dictionary <string, string> dic = new Dictionary <string, string>(); if (code == "" || code == null) { return(Json("", JsonRequestBehavior.AllowGet)); } App_Code.GY gy = new App_Code.GY(); string repeat = ""; List <T_InterceptLogistics> modelList = db.T_InterceptLogistics.Where(a => a.OrderNumber.Equals(code.Trim()) && a.Del == 0).ToList(); if (modelList.Count > 0) { repeat += "物流拦截记录已存在此订单号"; } #region ////查询旺店通 //List<T_Retreat> modelList = db.T_Retreat.Where(a => a.Retreat_OrderNumber.Equals(code.Trim()) && a.Isdelete == "0").ToList(); //if (modelList.Count > 0) //{ // repeat += "退货退款记录重复,"; //} ////查是否有返现记录 //List<T_CashBack> cash = db.T_CashBack.Where(a => a.OrderNum.Equals(code.Trim()) && a.For_Delete == 0 && a.Status != 2).ToList(); //if (cash.Count > 0) //{ // repeat += "有返现记录重复,"; //} //List<T_Reissue> Reissue = db.T_Reissue.Where(a => a.OrderCode.Equals(code.Trim()) && a.IsDelete == 0 && a.Status != 2).ToList(); //if (Reissue.Count > 0) //{ // repeat += "有补发记录重复,"; //} //List<T_ExchangeCenter> ExchangeCenter = db.T_ExchangeCenter.Where(a => a.OrderCode.Equals(code.Trim()) && a.IsDelete == 0 && a.Status != 2).ToList(); //if (ExchangeCenter.Count > 0) //{ // repeat += "有换货记录重复,"; //} //List<T_Intercept> Intercept = db.T_Intercept.Where(a => a.OrderNumber.Equals(code.Trim()) && a.IsDelete == 0 && a.Status != 2).ToList(); //if (Intercept.Count > 0) //{ // repeat += "拦截模块有记录,"; //} #endregion dic.Clear(); dic.Add("src_tid", code); //dic.Add("trade_no", code); dic.Add("sid", "hhs2"); dic.Add("appkey", "hhs2-ot"); dic.Add("timestamp", GetTimeStamp()); string cmd = CreateParam(dic, true); string ret = gy.DoPostnew("http://api.wangdian.cn/openapi2/trade_query.php", cmd, Encoding.UTF8); string ssx = Regex.Unescape(ret); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string iscode = jsonData["total_count"].ToString(); if (iscode != "0") { JsonData jsontrades = jsonData["trades"]; if (jsontrades.Count != 0) { JsonData trades = jsontrades[0]; //店铺名称 string shop_name = trades["shop_name"].ToString(); //仓库编码 string warehouse_no = trades["warehouse_no"].ToString(); //原始订单编号 string src_tids = trades["src_tids"].ToString(); //下单时间 string trade_time = trades["trade_time"].ToString(); //付款时间 string pay_time = trades["pay_time"].ToString(); //旺旺号 string customer_name = trades["buyer_nick"].ToString(); //订单状态 string trade_status = trades["trade_status"].ToString(); //收件人姓名 string receiver_name = trades["receiver_name"].ToString(); //省 string receiver_province = trades["receiver_province"].ToString(); //市 string receiver_city = trades["receiver_city"].ToString(); //区 string receiver_district = trades["receiver_district"].ToString(); //详细地址 string receiver_address = trades["receiver_address"].ToString(); //电话号码 string receiver_mobile = trades["receiver_mobile"].ToString(); //邮政编码 string receiver_zip = trades["receiver_zip"].ToString(); //省市县 string receiver_area = trades["receiver_area"].ToString(); //快递公司编号 string logistics_code = trades["logistics_code"].ToString(); //快递公司名称 string logistics_name = trades["logistics_name"].ToString(); //快递单号 string logistics_no = trades["logistics_no"].ToString(); //买家留言 string buyer_message = trades["buyer_message"].ToString(); //客服备注 string cs_remark = trades["cs_remark"].ToString(); //实付金额 // string paid = trades["paid"].ToString(); //商品详情 List <T_RetreatDetails> DetailsList = new List <T_RetreatDetails>(); double paid = 0.00; for (int c = 0; c < jsontrades.Count; c++) { paid += double.Parse(jsontrades[c]["paid"].ToString()); //JsonData goods_list = jsontrades[c]["goods_list"]; //for (int i = 0; i < goods_list.Count; i++) //{ // T_RetreatDetails DetailsModel = new T_RetreatDetails(); // string ss = goods_list[i]["goods_no"] == null ? "" : goods_list[i]["goods_no"].ToString(); // DetailsModel.item_code = ss; // DetailsModel.item_name = goods_list[i]["goods_name"] == null ? "" : goods_list[i]["goods_name"].ToString(); // // double ssds=double.Parse(goods_list[i]["paid"].ToString()) / double.Parse(goods_list[i]["actual_num"].ToString()); // decimal dec = Convert.ToDecimal(Math.Round(double.Parse(goods_list[i]["share_amount"].ToString()), 2)); // DetailsModel.amount = (double)dec;//分摊邮费 // int qyt = Convert.ToInt32(Convert.ToDecimal(goods_list[i]["actual_num"].ToString())); // if (qyt != 0) // { // DetailsModel.qty = qyt; // DetailsModel.price = (double)dec / DetailsModel.qty; // } // else // { // DetailsModel.qty = 0; // DetailsModel.price = (double)dec; // } // if (qyt > 0) // { // DetailsList.Add(DetailsModel); // } //} } T_InterceptLogistics model = new T_InterceptLogistics(); model.OrderNumber = code; model.ExpressName = logistics_name; model.ExpressNumber = logistics_no; model.OrderMoney = Convert.ToDecimal(paid); //var json = new //{ // rows = (from r in DetailsList // select new T_RetreatDetails // { // item_code = r.item_code, // item_name = r.item_name, // price = r.price, // amount = r.amount, // qty = r.qty, // Simplename = r.Simplename, // }).ToArray() //}; return(Json(new { ModelList = model, Repeat = repeat }, JsonRequestBehavior.AllowGet)); } } return(Json("-1", JsonRequestBehavior.AllowGet)); }
public JsonResult ViewSingleProductPartsAddSave(T_goodsGY model) { string name = Server.UrlDecode(Request.Cookies["Nickname"].Value); using (TransactionScope sc = new TransactionScope()) { T_ProductClass ProductClassmodel = db.T_ProductClass.SingleOrDefault(a => a.ClassName == model.classify); string ClassCode = ProductClassmodel.ClassCode; T_ProductManufactor ProductManufactormodel = db.T_ProductManufactor.SingleOrDefault(a => a.ManufactorName == model.Manufactor); string ManufactorCode = ProductManufactormodel.ManufactorCode; string Specifications = model.Specifications; string code = "S" + ClassCode + ManufactorCode + Specifications; List <T_goodsGY> goodsList = db.T_goodsGY.Where(a => a.code == code).ToList(); if (goodsList.Count > 0) { return(Json(new { State = "Faile", Message = "该组合方式的配件已存在" }, JsonRequestBehavior.AllowGet)); } model.code = code; model.create_date = DateTime.Now; model.create_Name = name; db.T_goodsGY.Add(model); try { int i = db.SaveChanges(); if (i > 0) { App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"skus\":[]" + "}"; string sign = gy.Sign(cmd); string comcode = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.item.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"code\":\"" + model.code + "\"," + "\"name\":\"" + model.name + "\"," + "\"simple_name\":\"" + model.simple_name + "\"," + "\"sign\":\"" + sign + "\"," + "\"skus\":[]" + "}"; string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string sd = jsonData[0].ToString(); if (sd == "True") { sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet)); } } } catch (DbEntityValidationException ex) { return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile", Message = "保存失败" }, JsonRequestBehavior.AllowGet)); } }
//根据订单号查询查询数据 public JsonResult QueryDataByCode(string Ordercode) { if (!string.IsNullOrWhiteSpace(Ordercode)) { List <T_RespiratorOrder> orders = db.T_RespiratorOrder.Where(a => a.OrderCode == Ordercode.Trim()).ToList(); if (orders.Count > 0) { return(Json(-1)); } } if (Ordercode != "" && Ordercode != null) { App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + Ordercode + "\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" + "}"; string sign = gy.Sign(cmd); cmd = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}"); string retnum = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd); JsonData jsonDatanum = null; jsonDatanum = JsonMapper.ToObject(retnum); int successnum = int.Parse(jsonDatanum[7].ToString()); if (successnum > 0) { //赋值 JsonData orders = jsonDatanum["orders"][0]; //收货人 string receiver_name = isNULL(orders["receiver_name"]).ToString(); //收货人电话 string receiver_phone = isNULL(orders["receiver_phone"]).ToString(); //收货人手机 string receiver_mobile = isNULL(orders["receiver_mobile"]).ToString(); //收货人地址 string receiver_address = isNULL(orders["receiver_address"]).ToString(); T_RespiratorOrder model = new T_RespiratorOrder(); model.CustomerName = receiver_name; if (receiver_phone != "") { model.Customerphone = receiver_phone; } else { model.Customerphone = receiver_mobile; } model.Customeraddress = receiver_address; JsonData details = orders["details"]; List <T_RespiratorOrderDetails> detalislist = new List <T_RespiratorOrderDetails>(); for (int s = 0; s < details.Count; s++) { T_RespiratorOrderDetails detalis = new T_RespiratorOrderDetails(); JsonData detailsxiangqing = details[s]; detalis.ProductName = isNULL(detailsxiangqing["item_name"]).ToString(); detalis.Company = isNULL(detailsxiangqing["item_simple_name"]).ToString(); detalislist.Add(detalis); } return(Json(new { i = model, d = detalislist }, JsonRequestBehavior.AllowGet)); //return View(model); } else { App_Code.GY gynum = new App_Code.GY(); string cmdnum = ""; cmdnum = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.history.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + Ordercode + "\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" + "}"; string signnum = gynum.Sign(cmdnum); cmdnum = cmdnum.Replace("}", ",\"sign\":\"" + signnum + "\"}"); retnum = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmdnum); jsonDatanum = null; jsonDatanum = JsonMapper.ToObject(retnum); successnum = int.Parse(jsonDatanum[7].ToString()); if (successnum > 0) { //赋值 JsonData orders = jsonDatanum["orders"][0]; //收货人 string receiver_name = isNULL(orders["receiver_name"]).ToString(); //收货人电话 string receiver_phone = isNULL(orders["receiver_phone"]).ToString(); //收货人手机 string receiver_mobile = isNULL(orders["receiver_mobile"]).ToString(); //收货人地址 string receiver_address = isNULL(orders["receiver_address"]).ToString(); T_RespiratorOrder model = new T_RespiratorOrder(); model.CustomerName = receiver_name; if (receiver_phone != "") { model.Customerphone = receiver_phone; } else { model.Customerphone = receiver_mobile; } model.Customeraddress = receiver_address; JsonData details = orders["details"]; List <T_RespiratorOrderDetails> detalislist = new List <T_RespiratorOrderDetails>(); for (int s = 0; s < details.Count; s++) { T_RespiratorOrderDetails detalis = new T_RespiratorOrderDetails(); JsonData detailsxiangqing = details[s]; detalis.ProductName = detailsxiangqing["item_name"].ToString(); detalis.Company = detailsxiangqing["item_simple_name"].ToString(); detalis.ProductCode = detailsxiangqing["item_code"].ToString(); detalis.Number = Convert.ToInt32(detailsxiangqing["qty"].ToString()); detalislist.Add(detalis); } return(Json(new { i = model, d = detalislist }, JsonRequestBehavior.AllowGet)); } } } int i = 0; return(Json(i, JsonRequestBehavior.AllowGet)); //if (!string.IsNullOrWhiteSpace(Ordercode)) //{ // List<T_RespiratorOrder> RespiratorOrder = db.T_RespiratorOrder.Where(a => a.OrderCode == Ordercode.Trim()).ToList(); // if (RespiratorOrder.Count > 0) // { // return Json(-1);//已添加该订单 // } // else // { // T_OrderList Order = db.T_OrderList.SingleOrDefault(a => a.platform_code == Ordercode); // if (Order != null) // { // string oid=Order.code; // List<T_OrderDetail> detail = db.T_OrderDetail.Where(a => a.oid == oid).ToList(); // return Json(new { i = Order,d=detail }, JsonRequestBehavior.AllowGet); // } // else // { // return Json(0, JsonRequestBehavior.AllowGet); // } // } //} //else //{ // return Json(0, JsonRequestBehavior.AllowGet); //} }
public JsonResult QuyerRetreatDetailBYcode(string code = "") { string [] codes = code.Split(','); List <T_ElectronicInvoice> ElectronicModel = new List <T_ElectronicInvoice>(); List <T_ElectronicInvoiceDetails> DetailsList = new List <T_ElectronicInvoiceDetails>(); for (int x = 0; x < codes.Length; x++) { string codez = codes[x]; App_Code.GY gy = new App_Code.GY(); string cmd = ""; string repeat = ""; dic.Clear(); dic.Add("src_tid", codez); //dic.Add("trade_no", code); dic.Add("sid", "hhs2"); dic.Add("appkey", "hhs2-ot"); dic.Add("timestamp", GetTimeStamp()); cmd = CreateParam(dic, true); string ret = gy.DoPostnew("http://api.wangdian.cn/openapi2/trade_query.php", cmd, Encoding.UTF8); string ssx = Regex.Unescape(ret); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string iscode = jsonData["total_count"].ToString(); if (iscode != "0") { JsonData jsontrades = jsonData["trades"]; if (jsontrades.Count != 0) { JsonData trades = jsontrades[0]; //店铺名称 string shop_name = trades["shop_name"].ToString(); //仓库编码 string warehouse_no = trades["warehouse_no"].ToString(); //原始订单编号 string src_tids = trades["src_tids"].ToString(); //下单时间 string trade_time = trades["trade_time"].ToString(); //付款时间 string pay_time = trades["pay_time"].ToString(); //旺旺号 string customer_name = trades["buyer_nick"].ToString(); //收件人姓名 string receiver_name = trades["receiver_name"].ToString(); //省 string receiver_province = trades["receiver_province"].ToString(); //市 string receiver_city = trades["receiver_city"].ToString(); //区 string receiver_district = trades["receiver_district"].ToString(); //详细地址 string receiver_address = trades["receiver_address"].ToString(); //电话号码 string receiver_mobile = trades["receiver_mobile"].ToString(); //邮政编码 string receiver_zip = trades["receiver_zip"].ToString(); //省市县 string receiver_area = trades["receiver_area"].ToString(); //快递公司编号 string logistics_code = trades["logistics_code"].ToString(); //快递单号 string logistics_no = trades["logistics_no"].ToString(); //买家留言 string buyer_message = trades["buyer_message"].ToString(); //客服备注 string cs_remark = trades["cs_remark"].ToString(); //实付金额 string paid = trades["paid"].ToString(); //商品详情 JsonData goods_list = trades["goods_list"]; //查询3次。对应到具体的省市区 //查询一次.. string shop_Code = ""; T_ElectronicInvoice model = new T_ElectronicInvoice(); model.OrderNumber = codez; model.ShopName = shop_name; model.TheInvoiceAmount = decimal.Parse(paid.ToString()); ElectronicModel.Add(model); for (int i = 0; i < goods_list.Count; i++) { T_ElectronicInvoiceDetails DetailsModel = new T_ElectronicInvoiceDetails(); DetailsModel.Code = goods_list[i]["goods_no"] == null ? "" : goods_list[i]["goods_no"].ToString(); DetailsModel.Name = goods_list[i]["goods_name"] == null ? "" : goods_list[i]["goods_name"].ToString(); DetailsModel.specname = goods_list[i]["spec_name"] == null ? "" : goods_list[i]["spec_name"].ToString(); DetailsModel.UnitPrice = decimal.Parse(goods_list[i]["order_price"].ToString()); decimal qyt = decimal.Parse(goods_list[i]["actual_num"].ToString()); DetailsModel.qty = int.Parse(Math.Round(qyt).ToString()); DetailsList.Add(DetailsModel); } } } } var json = new { rows = (from r in DetailsList select new T_ElectronicInvoiceDetails { Code = r.Code, Name = r.Name, specname = r.specname, UnitPrice = r.UnitPrice, qty = r.qty, }).ToArray() }; if (ElectronicModel.Count > 0) { string ShopName = ElectronicModel[0].ShopName; decimal TheInvoiceAmount = 0.00m; for (int d = 0; d < ElectronicModel.Count; d++) { if (ShopName != ElectronicModel[d].ShopName) { return(Json("-1", JsonRequestBehavior.AllowGet)); } TheInvoiceAmount += decimal.Parse(ElectronicModel[d].TheInvoiceAmount.ToString()); } T_ElectronicInvoice model = new T_ElectronicInvoice(); model.OrderNumber = code; model.ShopName = ShopName; model.TheInvoiceAmount = TheInvoiceAmount; return(Json(new { ModelList = model, Json = json }, JsonRequestBehavior.AllowGet)); } else { return(Json("", JsonRequestBehavior.AllowGet)); } }
//[Description("新增保存")] public JsonResult StockDetailAdd(T_StockStorage Model, string jsonStr, string CurUser) { using (TransactionScope sc = new TransactionScope()) { try { string Nickname = ""; if (!string.IsNullOrWhiteSpace(CurUser)) { Nickname = CurUser; } else { Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); } Model.Type = "入库"; Model.ApplyName = Nickname; Model.ApplyDate = DateTime.Now; db.T_StockStorage.Add(Model); db.SaveChanges(); List <T_StockDetail> details = App_Code.Com.Deserialize <T_StockDetail>(jsonStr); foreach (var item in details) { item.Oid = Model.ID; db.T_StockDetail.Add(item); db.SaveChanges(); string code = item.Code; string WarehouseCode = Model.WarehouseCode; T_Stock Smodel = db.T_Stock.SingleOrDefault(a => a.Code == code && a.WarehouseName == WarehouseCode); if (Smodel != null) { Smodel.Qty += item.Qty; db.Entry <T_Stock>(Smodel).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { T_Stock StModel = new T_Stock(); StModel.Qty = item.Qty; StModel.Name = item.Name; StModel.Code = item.Code; StModel.WarehouseName = WarehouseCode; db.T_Stock.Add(StModel); db.SaveChanges(); } T_StockOutstorage StorageModel = new T_StockOutstorage(); StorageModel.Code = item.Code; StorageModel.Name = item.Name; StorageModel.WarehouseCode = WarehouseCode; StorageModel.number = Model.ID.ToString(); StorageModel.Qty = item.Qty; StorageModel.Type = "入库"; db.T_StockOutstorage.Add(StorageModel); db.SaveChanges(); } string cpcode = ""; for (int z = 0; z < details.Count; z++) { if (z == details.Count - 1) { cpcode += "{\"barcode\":\"" + details[z].Code + "\",\"qty\":" + details[z].Qty + "}"; } else { cpcode += "{\"barcode\":\"" + details[z].Code + "\",\"qty\":" + details[z].Qty + "},"; } } EBMS.App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.new.purchase.arrive.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"warehouse_code\":\"" + Model.WarehouseCode + "\"," + "\"supplier_code\":\"" + Model.SupplierName + "\"," + "\"order_type\":\"001\"," + "\"detail_list\":[" + cpcode + "]" + "}"; string sign = gy.Sign(cmd); string comcode = ""; comcode = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.new.purchase.arrive.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"sign\":\"" + sign + "\"," + "\"warehouse_code\":\"" + Model.WarehouseCode + "\"," + "\"supplier_code\":\"" + Model.SupplierName + "\"," + "\"order_type\":\"001\"," + "\"detail_list\":[" + cpcode + "]" + "}"; string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); if (jsonData.Count == 6) { return(Json(new { State = "Faile", Message = "写入管易失败,请联系管理员" }, JsonRequestBehavior.AllowGet)); } else { sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }
//查询单据编号返回详情 数据来自管易 public JsonResult getOrderDetail(string num) { try { string result = ""; if (num != null) { App_Code.GY gy = new App_Code.GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.deliverys.get\"," + "\"page\":1," + "\"page_size\":3," + "\"code\":\"" + num + "\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" + "}"; string sign = gy.Sign(cmd); cmd = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}"); string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); DateTime dateStar = DateTime.Parse("2017-02-10 16:07:50.473"); DateTime dateEnd = DateTime.Parse("2017-02-11 16:07:50.473"); if (jsonData["deliverys"].Count == 0) { cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.deliverys.history.get\"," + "\"page\":1," + "\"page_size\":3," + "\"code\":\"" + num + "\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"" + "}"; sign = gy.Sign(cmd); cmd = cmd.Replace("}", ",\"sign\":\"" + sign + "\"}"); ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", cmd); jsonData = null; jsonData = JsonMapper.ToObject(ret); if (jsonData.Count == 6 || jsonData["deliverys"].Count == 0) { result = "单据编号不存在"; return(Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet)); } } JsonData jsonOrders = jsonData["deliverys"][0]; //查询管易发货字段 可是不能修改 //int state = int.Parse((jsonOrders["delivery_state"]).ToString()); //if (state != 0) { // result = "该订单已经发货"; // return Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet); //} // 查询发货表 订单是否发货 T_Deliver deliverFlag = db.T_Deliver.FirstOrDefault(a => a.MailNo == num); if (deliverFlag != null) { return(Json(new { State = "Faile", Message = "该单据编号已经发货" }, JsonRequestBehavior.AllowGet)); } JsonData details = jsonOrders["details"]; List <AddMod> detalislist = new List <AddMod>(); for (int s = 0; s < details.Count; s++) { //返回的数据构造 AddMod detalis = new AddMod(); JsonData detailItem = details[s]; string Code = isNULL(detailItem["item_code"]).ToString(); detalis.item_code = isNULL(detailItem["item_code"]).ToString(); detalis.item_name = isNULL(detailItem["item_name"]).ToString(); detalis.qty = int.Parse(detailItem["qty"].ToString()); detalis.sku_name = isNULL(detailItem["sku_name"]).ToString(); string Tiaoma = db.T_goodsGY.SingleOrDefault(a => a.code == Code).barcode; detalis.tiaoma = Tiaoma; detalislist.Add(detalis); } string Warehouse = isNULL(jsonOrders["warehouse_name"]).ToString(); string OrderNum = isNULL(jsonOrders["platform_code"]).ToString(); result = "{\"rows\":" + JsonConvert.SerializeObject(detalislist) + ",\"Warehouse\":\"" + Warehouse + "\",\"OrderNum\":\"" + OrderNum + "\"}"; } else { result = "请输入正确的单据编号"; return(Json(new { State = "Faile", Message = result }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Success", result = result }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { State = "Faile", Message = e.Message }, JsonRequestBehavior.AllowGet)); } }
//审核 public JsonResult ManualBillingCheckCheck(T_ManualBilling model, string status, string Memo) { using (TransactionScope sc = new TransactionScope()) { int ID = model.ID; T_ManualBilling Invoicemodel = db.T_ManualBilling.SingleOrDefault(a => a.ID == ID && a.Isdelete == 0); if (Invoicemodel == null) { return(Json("数据可能被删除", JsonRequestBehavior.AllowGet)); } T_ManualBillingAppRove modelApprove = db.T_ManualBillingAppRove.FirstOrDefault(a => a.Oid == ID && a.ApproveTime == null); string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); string result = ""; modelApprove.ApproveName = Nickname; modelApprove.Memo = Memo; modelApprove.ApproveTime = DateTime.Now; modelApprove.Status = int.Parse(status); db.Entry <T_ManualBillingAppRove>(modelApprove).State = System.Data.Entity.EntityState.Modified; int i = db.SaveChanges(); if (i > 0) { if (status == "1") { T_ManualBillingAppRove newApprove = new T_ManualBillingAppRove(); int step = int.Parse(Invoicemodel.Step.ToString()); step++; IQueryable <T_ManualBillingConfig> config = db.T_ManualBillingConfig.AsQueryable(); int stepLength = config.Count();//总共步骤 if (step < stepLength) { Invoicemodel.Status = 0; T_ManualBillingConfig stepMod = db.T_ManualBillingConfig.SingleOrDefault(a => a.Step == step); string nextName = stepMod.Name; newApprove.Memo = ""; newApprove.Oid = ID; newApprove.Status = -1; newApprove.Step = step.ToString(); if (nextName != null) { newApprove.ApproveName = nextName; newApprove.ApproveDName = stepMod.Type; } else { newApprove.ApproveName = stepMod.Type; newApprove.ApproveDName = stepMod.Type; } db.T_ManualBillingAppRove.Add(newApprove); db.SaveChanges(); } else { List <T_ManualBillingDetails> DetailsList = db.T_ManualBillingDetails.Where(a => a.Oid == ID).ToList(); string shangp = ""; for (int e = 0; e < DetailsList.Count; e++) { if (e == DetailsList.Count - 1) { shangp += "{\"qty\":" + DetailsList[e].qty + ",\"note\":\"\",\"refund\":0,\"item_code\":\"" + System.Web.HttpContext.Current.Server.UrlEncode(DetailsList[e].Code) + "\"}"; } else { shangp += "{\"qty\":" + DetailsList[e].qty + ",\"note\":\"\",\"refund\":0,\"item_code\":\"" + System.Web.HttpContext.Current.Server.UrlEncode(DetailsList[e].Code) + "\"},"; } } decimal PaymentAmount = 0; if (Invoicemodel.PaymentAmount != null) { PaymentAmount = decimal.Parse(Invoicemodel.PaymentAmount.ToString()); } // string payments = "{\"pay_type_code\":wangyin,\"payment\":" + PaymentAmount + "},"; string payments = "{\"pay_type_code\":\"wangyin\",\"payment\":\"" + PaymentAmount + "\"}"; string[] address = Invoicemodel.GoodsAddress.Split('-'); string receiver_province = ""; string receiver_city = ""; string receiver_district = ""; if (address.Length >= 1) { receiver_province = address[0]; } if (address.Length >= 2) { receiver_city = address[1]; } if (address.Length >= 3) { receiver_district = address[2]; } EBMS.App_Code.GY gy = new App_Code.GY(); string ShopCode = GetShopFromString(Invoicemodel.ShopName); string datetime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"platform_code\":\"" + Invoicemodel.OrderNumber + "\"," + "\"order_type_code\":\"Sales\"," + "\"shop_code\":\"" + ShopCode + "\"," + "\"post_fee\":\"" + Invoicemodel.ExpressFee + "\"," + "\"receiver_province\":\"" + receiver_province + "\"," + "\"receiver_city\":\"" + receiver_city + "\"," + "\"receiver_district\":\"" + receiver_district + "\"," + "\"express_code\":\"" + Invoicemodel.ExpressCode + "\"," + "\"warehouse_code\":\"" + Invoicemodel.DeliverGoodsWarehouse + "\"," + "\"vip_code\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"vip_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"receiver_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"receiver_address\":\"" + Invoicemodel.GoodsReceiptAddress + "\"," + "\"receiver_mobile\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," + "\"receiver_phone\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," + "\"deal_datetime\":\"" + datetime + "\"," + "\"seller_memo\":\"" + Invoicemodel.DeliverGoodsReason + "\"," + "\"payments\":[" + payments + "]," + "\"details\":[" + shangp + "]" + "}"; string sign = gy.Sign(cmd); string comcode = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.add\"," + "\"sessionkey\":\"f5885504d9c84d1d8146200a4841f4b7\"," + "\"platform_code\":\"" + Invoicemodel.OrderNumber + "\"," + "\"order_type_code\":\"Sales\"," + "\"shop_code\":\"" + ShopCode + "\"," + "\"post_fee\":\"" + Invoicemodel.ExpressFee + "\"," + "\"receiver_province\":\"" + receiver_province + "\"," + "\"receiver_city\":\"" + receiver_city + "\"," + "\"receiver_district\":\"" + receiver_district + "\"," + "\"express_code\":\"" + Invoicemodel.ExpressCode + "\"," + "\"warehouse_code\":\"" + Invoicemodel.DeliverGoodsWarehouse + "\"," + "\"vip_code\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"vip_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"receiver_name\":\"" + Invoicemodel.GoodsReceiptName + "\"," + "\"receiver_address\":\"" + Invoicemodel.GoodsReceiptAddress + "\"," + "\"receiver_mobile\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," + "\"receiver_phone\":\"" + Invoicemodel.GoodsReceiptPhone + "\"," + "\"deal_datetime\":\"" + datetime + "\"," + "\"seller_memo\":\"" + Invoicemodel.DeliverGoodsReason + "\"," + "\"sign\":\"" + sign + "\"," + "\"payments\":[" + payments + "]," + "\"details\":[" + shangp + "]" + "}"; string ret = gy.DoPost("http://api.guanyierp.com/rest/erp_open", comcode); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string sd = jsonData[0].ToString(); if (jsonData.Count == 6) { // return Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet); result = "管理调整单失败,请核对信息"; return(Json(result, JsonRequestBehavior.AllowGet)); } Invoicemodel.Status = int.Parse(status); } Invoicemodel.Step = step; db.Entry <T_ManualBilling>(Invoicemodel).State = System.Data.Entity.EntityState.Modified; int j = db.SaveChanges(); sc.Complete(); if (j > 0) { result = "保存成功"; } else { result = "保存失败"; } } else { //不同意 Invoicemodel.Step = 0; Invoicemodel.Status = 2; db.Entry <T_ManualBilling>(Invoicemodel).State = System.Data.Entity.EntityState.Modified; int j = db.SaveChanges(); //审核流程结束 申请人编辑后插入下一条记录 sc.Complete(); if (j > 0) { result = "保存成功"; } else { result = "保存失败"; } } } else { result = "保存失败"; } return(Json(result, JsonRequestBehavior.AllowGet)); } }
//单个产品同步 public JsonResult WDTGoodsTbS(string query) { if (query == "" || query == null) { return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet)); } App_Code.GY gy = new App_Code.GY(); JsonData jsonData = null; //string ret = gy.httpGetStr("http://192.168.8.89:3980/material/GetMaterialData?code=" + query.Trim()); try { string ret = gy.httpGetStr("http://222.240.26.98:3980/material/GetMaterialData?code=" + query.Trim()); string ssx = Regex.Unescape(ret); jsonData = JsonMapper.ToObject(ret); } catch (WebException ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } //if (jsonData[0][0]==null) //{ // return Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet); //} if (jsonData != null && jsonData.Count > 0) { for (int i = 0; i < jsonData.Count; i++) { string SPEC = ""; if (jsonData[i]["SPEC"] != null) { SPEC = jsonData[i]["SPEC"].ToString(); } string NAME = jsonData[i]["NAME"].ToString(); string UNIT = jsonData[i]["UNIT"].ToString(); string BARCODE = ""; if (jsonData[i]["BARCODE"] != null) { BARCODE = jsonData[i]["BARCODE"].ToString(); } string code = jsonData[i]["CODE"].ToString();; T_WDTGoods list = db.T_WDTGoods.FirstOrDefault(s => s.goods_no == code); if (list == null) { T_WDTGoods WDTGoods = new T_WDTGoods(); WDTGoods.goods_no = code; WDTGoods.goods_name = NAME; WDTGoods.short_name = NAME; WDTGoods.goods_type = 1; WDTGoods.unit_name = UNIT; WDTGoods.spec_count = 1; WDTGoods.spec_code = code; WDTGoods.spec_no = code; WDTGoods.barcode = BARCODE; WDTGoods.spec_name = SPEC; WDTGoods.lowest_price = 0; WDTGoods.wholesale_price = 0; WDTGoods.retail_price = 0; db.T_WDTGoods.Add(WDTGoods); db.SaveChanges(); } else { list.unit_name = UNIT; list.spec_name = SPEC; db.Entry <T_WDTGoods>(list).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { State = "Faile", Message = "NC不存在" + query }, JsonRequestBehavior.AllowGet)); } }
public JsonResult ShopTb() { int page_no = 0; int c = 0; int s = 0; App_Code.GY gy = new App_Code.GY(); //List<T_WDTshop> delMod = db.T_WDTshop.AsQueryable().ToList(); //foreach (var item in delMod) //{ // db.T_WDTshop.Remove(item); //} //db.SaveChanges(); do { dic.Clear(); dic.Add("mine", "0"); dic.Add("sid", "hhs2"); dic.Add("appkey", "hhs2-ot"); dic.Add("timestamp", GetTimeStamp()); dic.Add("page_no", page_no.ToString());//页号 var cmd = CreateParam(dic, true); string ret = gy.DoPostnew("http://api.wangdian.cn/openapi2/shop.php", cmd, Encoding.UTF8); string ssx = Regex.Unescape(ret); JsonData jsonData = null; jsonData = JsonMapper.ToObject(ret); string iscode = jsonData["code"].ToString(); if (iscode != "0") { return(Json("", JsonRequestBehavior.AllowGet)); } JsonData jsontrades = jsonData["shoplist"]; c = jsontrades.Count; for (int i = 0; i < jsontrades.Count; i++) { string shopno = jsontrades[i]["shop_no"].ToString(); T_WDTshop model = db.T_WDTshop.FirstOrDefault(a => a.shop_no == shopno); if (model == null) { T_WDTshop WDTshop = new T_WDTshop(); WDTshop.platform_id = jsontrades[i]["platform_id"].ToString(); WDTshop.sub_platform_id = jsontrades[i]["sub_platform_id"].ToString(); WDTshop.shop_id = jsontrades[i]["shop_id"].ToString(); WDTshop.shop_no = jsontrades[i]["shop_no"].ToString(); WDTshop.shop_name = jsontrades[i]["shop_name"].ToString(); WDTshop.account_id = jsontrades[i]["account_id"].ToString(); WDTshop.account_nick = jsontrades[i]["account_nick"].ToString(); WDTshop.province = jsontrades[i]["province"].ToString(); WDTshop.city = jsontrades[i]["city"].ToString(); WDTshop.district = jsontrades[i]["district"].ToString(); WDTshop.address = jsontrades[i]["address"].ToString(); WDTshop.contact = jsontrades[i]["contact"].ToString(); WDTshop.zip = jsontrades[i]["zip"].ToString(); WDTshop.mobile = jsontrades[i]["mobile"].ToString(); WDTshop.telno = jsontrades[i]["telno"].ToString(); db.T_WDTshop.Add(WDTshop); s += db.SaveChanges(); } } page_no++; } while (c != 0); if (s > 0) { return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet)); }