public JsonResult Check(string UserName, int approveID, int status, string memo) { using (TransactionScope sc = new TransactionScope()) { try { int TotalStep = db.T_ReissueConfig.ToList().Count; T_ReissueApprove approve = db.T_ReissueApprove.Find(approveID); string name = approve.ApproveName; T_Reissue model = db.T_Reissue.Find(approve.Pid); approve.ApproveName = UserName; approve.ApproveStatus = status; approve.ApproveTime = DateTime.Now; approve.Memo = memo; model.Status = status; db.SaveChanges(); if (status == 2)//不同意 { model.Step = model.Step + 1; db.SaveChanges(); } else//同意 { int type = db.T_ReissueReson.SingleOrDefault(s => s.Reson.Equals(model.ReissueReson)).Type; int LastStep = db.T_ReissueConfig.OrderByDescending(s => s.Step).FirstOrDefault(s => s.Reson == type).Step; if (LastStep > model.Step)//判断是否存在下一级 { //获得下一级审核部门 string nextapproveType = db.T_ReissueConfig.OrderBy(s => s.Step).FirstOrDefault(s => s.Reson == type && s.Step > model.Step).ApproveType; T_ReissueApprove newApprove = new T_ReissueApprove(); newApprove.ApproveStatus = -1; newApprove.ApproveName = nextapproveType; newApprove.ApproveTime = null; newApprove.Pid = approve.Pid; db.T_ReissueApprove.Add(newApprove); db.SaveChanges(); model.Status = 0; model.Step = model.Step + 1; db.SaveChanges(); } if (name.Equals("售后主管") || name.Equals("呼吸机主管"))//售后主管审核后直接加入补发货 { //T_OrderList order = db.T_OrderList.Find(model.OrderId); //List<T_Reissue> reissue = db.T_Reissue.Where(s => s.OrderCode.Equals(model.OrderCode) && s.IsDelete == 0).ToList(); ////判断是否为第一次补发 //if (reissue.Count() == 1) //{ // order.ReissueStatus = 2; //} //List<T_ReissueDetail> reiDetails = db.T_ReissueDetail.Where(s => s.ReissueId == model.ID).ToList(); //foreach (var item in reiDetails) //{ // T_OrderDetail Orderdetail = db.T_OrderDetail.FirstOrDefault(s => s.oid.Equals(order.code) && s.item_code.Equals(item.ProductCode)); // if (Orderdetail != null) // { // Orderdetail.ReissueStatus = 1; // Orderdetail.ReissueQty += item.Num; // } //} db.SaveChanges(); #region 加入快递赔付 if (model.ReissueReson.Equals("快递破损")) { GY gy = new GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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); if (jsonData.Count == 6 || jsonData["orders"].Count == 0) { cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.history.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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["orders"].Count == 0) { return(Json(new { State = "Faile", Message = "订单号不存在" })); } } JsonData jsonOrders = jsonData["orders"][0]; var deliver = jsonOrders["deliverys"][0]; //快递单号 string mail_no = isNULL(deliver["mail_no"]).ToString(); //订单金额 string amount = isNULL(jsonOrders["amount"]).ToString(); //快递名称 string express_name = isNULL(jsonOrders["express_name"]).ToString(); T_ExpressIndemnity Inde = new T_ExpressIndemnity { PostUserName = model.PostUser, Date = DateTime.Now, OrderNum = model.OrderCode, wangwang = model.VipCode, ShopName = model.StoreName, RetreatExpressNum = mail_no, State = "0", OrderMoney = Convert.ToDouble(amount), Type = "破损", Second = "0", CurrentApproveName = "快递组", IsDelete = 0, ExpressName = express_name, IndemnityMoney = 0 }; db.T_ExpressIndemnity.Add(Inde); db.SaveChanges(); List <T_ReissuePic> picList = db.T_ReissuePic.Where(s => s.ReissueId == model.ID).ToList(); foreach (var item in picList) { T_ExpressIndemnityPic expressPic = new T_ExpressIndemnityPic { EID = Inde.ID, PicURL = item.Url }; db.T_ExpressIndemnityPic.Add(expressPic); } db.SaveChanges(); } else if (model.ReissueReson.Equals("丢件")) { GY gy = new GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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); if (jsonData.Count == 6 || jsonData["orders"].Count == 0) { cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.history.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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["orders"].Count == 0) { return(Json(new { State = "Faile", Message = "订单号不存在" })); } } JsonData jsonOrders = jsonData["orders"][0]; var deliver = jsonOrders["deliverys"][0]; //快递单号 string mail_no = isNULL(deliver["mail_no"]).ToString(); //订单金额 string amount = isNULL(jsonOrders["amount"]).ToString(); //快递名称 string express_name = isNULL(jsonOrders["express_name"]).ToString(); T_ExpressIndemnity Inde = new T_ExpressIndemnity { PostUserName = model.PostUser, Date = DateTime.Now, OrderNum = model.OrderCode, wangwang = model.VipCode, ShopName = model.StoreName, RetreatExpressNum = mail_no, State = "0", OrderMoney = Convert.ToDouble(amount), Type = "丢件", Second = "0", CurrentApproveName = "快递组", IsDelete = 0, ExpressName = express_name, IndemnityMoney = 0 }; db.T_ExpressIndemnity.Add(Inde); db.SaveChanges(); } #endregion if (PostGy(model) != "True") { return(Json(new { State = "Faile", Message = "上传管易错误,请联系管理员" }, JsonRequestBehavior.AllowGet)); } } } db.SaveChanges(); List <T_ModularNotaudited> ModularNotaudited = db.T_ModularNotaudited.Where(a => a.ModularName == "补发货未审核").ToList(); if (ModularNotaudited.Count > 0) { foreach (var item in ModularNotaudited) { db.T_ModularNotaudited.Remove(item); } db.SaveChanges(); } string RetreatAppRoveSql = "select isnull(ApproveUser,ApproveName) as PendingAuditName,COUNT(*) as NotauditedNumber from T_ReissueApprove where Pid in ( select ID from T_Reissue where IsDelete=0 ) and ApproveStatus=-1 and ApproveTime is null GROUP BY ApproveName,ApproveUser "; List <Modular> RetreatAppRoveQuery = db.Database.SqlQuery <Modular>(RetreatAppRoveSql).ToList(); string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); for (int e = 0; e < RetreatAppRoveQuery.Count; e++) { string PendingAuditName = RetreatAppRoveQuery[e].PendingAuditName; T_ModularNotaudited NotauditedModel = db.T_ModularNotaudited.SingleOrDefault(a => a.ModularName == "补发货未审核" && a.PendingAuditName == PendingAuditName); if (NotauditedModel != null) { NotauditedModel.NotauditedNumber = RetreatAppRoveQuery[e].NotauditedNumber; db.Entry <T_ModularNotaudited>(NotauditedModel).State = System.Data.EntityState.Modified; } else { T_ModularNotaudited ModularNotauditedModel = new T_ModularNotaudited(); ModularNotauditedModel.ModularName = "补发货未审核"; ModularNotauditedModel.NotauditedNumber = RetreatAppRoveQuery[e].NotauditedNumber; ModularNotauditedModel.PendingAuditName = RetreatAppRoveQuery[e].PendingAuditName; ModularNotauditedModel.ToupdateDate = DateTime.Now; ModularNotauditedModel.ToupdateName = Nickname; db.T_ModularNotaudited.Add(ModularNotauditedModel); } db.SaveChanges(); } sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }
public JsonResult Check(string UserName, int approveID, int status, string memo) { using (TransactionScope sc = new TransactionScope()) { try { int TotalStep = db.T_ExchangeCenterConfig.ToList().Count; T_ExchangeCenterApprove approve = db.T_ExchangeCenterApprove.Find(approveID); string name = approve.ApproveName; T_ExchangeCenter model = db.T_ExchangeCenter.Find(approve.Pid); approve.ApproveName = UserName; approve.ApproveStatus = status; approve.ApproveTime = DateTime.Now; approve.Memo = memo; db.SaveChanges(); if (status == 2)//不同意 { model.Status = status; model.Step = model.Step + 1; db.SaveChanges(); } else//同意 { int type = db.T_ExchangeReson.SingleOrDefault(s => s.Reson.Equals(model.ExchangeReson)).Type; int LastStep = db.T_ExchangeCenterConfig.OrderByDescending(s => s.Step).FirstOrDefault(s => s.Reson == type).Step; if (LastStep > model.Step)//判断是否存在下一级 { //获得下一级审核部门 string nextapproveType = db.T_ExchangeCenterConfig.OrderBy(s => s.Step).FirstOrDefault(s => s.Reson == type && s.Step > model.Step).ApproveType; T_ExchangeCenterApprove newApprove = new T_ExchangeCenterApprove(); newApprove.ApproveStatus = -1; newApprove.ApproveName = nextapproveType; newApprove.ApproveTime = null; newApprove.Pid = approve.Pid; db.T_ExchangeCenterApprove.Add(newApprove); db.SaveChanges(); model.Status = 0; model.Step = model.Step + 1; db.SaveChanges(); } if (name.Equals("售后主管") || name.Equals("呼吸机主管"))//售后主管审核后直接加入补发货 { //T_OrderList order = db.T_OrderList.Find(model.OrderId); List <T_ExchangeDetail> exchangedetail = db.T_ExchangeDetail.Where(s => s.ExchangeCenterId == model.ID).ToList(); #region 加入快递赔付 if (model.ExchangeReson.Equals("快递破损")) { GY gy = new GY(); string cmd = ""; cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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); if (jsonData.Count == 6 || jsonData["orders"].Count == 0) { cmd = "{" + "\"appkey\":\"171736\"," + "\"method\":\"gy.erp.trade.history.get\"," + "\"page_no\":1," + "\"page_size\":10," + "\"platform_code\":\"" + model.OrderCode + "\"," + "\"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["orders"].Count == 0) { return(Json(new { State = "Faile", Message = "订单号不存在" })); } } JsonData jsonOrders = jsonData["orders"][0]; var deliver = jsonOrders["deliverys"][0]; //快递单号 string mail_no = isNULL(deliver["mail_no"]).ToString(); //订单金额 string amount = isNULL(jsonOrders["amount"]).ToString(); //快递名称 string express_name = isNULL(jsonOrders["express_name"]).ToString(); T_ExpressIndemnity Inde = new T_ExpressIndemnity { PostUserName = model.PostUser, Date = DateTime.Now, OrderNum = model.OrderCode, wangwang = model.VipCode, ShopName = model.StoreName, RetreatExpressNum = mail_no, State = "0", OrderMoney = Convert.ToDouble(amount), Type = "破损", Second = "0", CurrentApproveName = "快递组", IsDelete = 0, ExpressName = express_name, IndemnityMoney = 0 }; db.T_ExpressIndemnity.Add(Inde); db.SaveChanges(); List <T_ExchangePic> picList = db.T_ExchangePic.Where(s => s.ExchangeId == model.ID).ToList(); foreach (var item in picList) { T_ExpressIndemnityPic expressPic = new T_ExpressIndemnityPic { EID = Inde.ID, PicURL = item.Url }; db.T_ExpressIndemnityPic.Add(expressPic); } db.SaveChanges(); } #endregion //#region 新增订单数据 //string newOrderCode = ""; //string newCode = ""; //string usedOrderCode = model.OrderCode; //string userCode = order.code; //List<T_OrderList> HEmodel = db.T_OrderList.Where(a => a.platform_code.Contains(usedOrderCode)).ToList(); //List<T_OrderList> orderList = db.T_OrderList.Where(a => a.code.Contains(userCode)).ToList(); //if (HEmodel.Count > 1) //{ // string HEmodelCount = HEmodel.Count.ToString(); // newOrderCode = usedOrderCode + HEmodelCount; //} //else // newOrderCode = usedOrderCode + "1"; //if (orderList.Count > 1) //{ // string listCount = orderList.Count.ToString(); // newCode = userCode + listCount; //} //else // newCode = userCode + "1"; //model.NewOrderCode = newOrderCode; //db.SaveChanges(); //T_OrderList newOrder = new T_OrderList //{ // code = newCode, // order_type_name = "换货订单", // platform_code = newOrderCode, // createtime = DateTime.Now, // dealtime = model.SingleTime.ToString(), // cod = order.cod, // approve = order.approve, // delivery_state = order.delivery_state, // warehouse_code = model.ReturnWarhouse, // warehouse_name = db.T_Warehouses.SingleOrDefault(s => s.code.Equals(model.ReturnWarhouse)).name, // shop_code = model.StoreCode, // shop_name = model.StoreName, // express_code = model.ReturnExpressName, // express_name = db.T_Express.SingleOrDefault(s => s.Code.Equals(model.ReturnExpressName)).Name, // buyer_memo = model.BuyRemark, // seller_memo = model.SalesRemark, // vip_code = model.VipCode, // vip_name = model.VipName, // receiver_name = model.ReceivingName, // receiver_mobile = model.ReceivingTelPhone, // receiver_phone = model.ReceivingPhone, // receiver_zip = model.NeedPostalCode, // receiver_area = model.AddressMessage, // receiver_address = model.ReceivingAddress, // payCode = order.payCode, // vipIdCard = order.vipIdCard, // vipRealName = order.vipRealName, // vipEmail = order.vipEmail, // amount = 0, // payment_amount = 0, // post_fee = 0, // discount_fee = 0, // payment = 0, // qty = "1", // weight_origin = "0", // post_cost = 0, // mail_no = model.ReturnExpressCode, // platform_flag = "0", // IsGeneralize = 0, // Status_CashBack = 0, // Status_Retreat = 0, // Status_ExpressIndemnity = 0, // ExchangeStatus = 0, // ReissueStatus = 0 //}; //db.T_OrderList.Add(newOrder); //db.SaveChanges(); //foreach (var item in exchangedetail) //{ // T_OrderDetail Orderdetail = db.T_OrderDetail.FirstOrDefault(s => s.oid.Equals(order.code) && s.item_code.Equals(item.SendProductCode)); // if (Orderdetail != null)//修改原订单详情换货状态与换货数量 // { // Orderdetail.ExchangeStatus = 1; // Orderdetail.ExchangeQty += item.SendProductNum; // db.SaveChanges(); // } // T_OrderDetail t = new T_OrderDetail // { // oid = newCode, // refund = 0, // item_code = item.NeedProductCode, // item_name = item.NeedProductName, // item_simple_name = "", // sku_code = "", // sku_name = "", // qty = 0, // price = 0, // amount = 0, // discount_fee = 0, // amount_after = 0, // post_fee = 0, // platform_item_name = "", // platform_sku_name = "", // note = "", // ExchangeStatus = 0, // ExchangeQty = 0, // ReissueStatus = 0, // ReissueQty = 0, // RetreatQty = 0, // RetreatStatus = 0 // }; // db.T_OrderDetail.Add(t); // db.SaveChanges(); //} //#endregion #region 加入补发货 string remark = ""; T_Reissue re = db.T_Reissue.FirstOrDefault(s => s.OrderCode.Equals(model.OrderCode) && s.IsDelete == 0); if (re != null) { var date = Convert.ToDateTime(DateTime.Now).ToString("yyyyMMdd"); var modeldate = Convert.ToDateTime(re.CreatDate).ToString("yyyyMMdd"); if (re != null && int.Parse(date) - int.Parse(modeldate) <= 3) { remark = model.SystemRemark + "3天内补发货重复"; } } //更改订单主表补发货状态 //else //{ // order.ReissueStatus = 1; // db.SaveChanges(); //} T_Reissue reissue = new T_Reissue { OrderCode = model.OrderCode, NewOrderCode = "8" + DateTime.Now.ToString("yyyyMMddHHmmss"), VipName = model.VipName, StoreName = model.StoreName, WarhouseName = model.NeedWarhouse, ExpressName = model.NeedExpress, OrderType = "Return", SingleTime = model.SingleTime, ReceivingName = model.ReceivingName, PostalCode = model.NeedPostalCode, Phone = model.ReceivingPhone, TelPhone = model.ReceivingTelPhone, VipCode = model.VipCode, Address = model.ReceivingAddress, AddressMessage = model.AddressMessage, SalesRemark = model.SalesRemark, BuyRemark = model.BuyRemark, StoreCode = model.StoreCode, Step = 0, Status = -2, BusinessName = Com.GetReissueName(model.StoreCode, model.ExchangeReson), PostUser = model.PostUser, DraftName = Com.GetReissueName(model.StoreCode, model.ExchangeReson), CreatDate = DateTime.Now, IsDelete = 0, ReissueReson = model.ExchangeReson, SystemRemark = remark }; db.T_Reissue.Add(reissue); db.SaveChanges(); IQueryable <T_ExchangeDetail> detail = db.T_ExchangeDetail.Where(s => s.ExchangeCenterId == model.ID); foreach (var item in detail) { T_ReissueDetail items = new T_ReissueDetail { ProductCode = item.NeedProductCode, ProductName = item.NeedProductName, Num = item.NeedProductNum, ReissueId = reissue.ID }; db.T_ReissueDetail.Add(items); } db.SaveChanges(); #endregion #region 判断仓库是否收货 T_ReturnToStorage storge = db.T_ReturnToStorage.SingleOrDefault(s => s.Retreat_expressNumber.Equals(model.ReturnExpressCode)); if (storge != null) { //List<T_ExchangeCenter> exchange = db.T_ExchangeCenter.Where(s => s.OrderCode.Equals(model.OrderCode) && s.IsDelete == 0).ToList(); model.WarhouseStatus = 1; model.Status = 1; T_ExchangeCenterApprove approve1 = db.T_ExchangeCenterApprove.SingleOrDefault(s => s.ApproveName.Equals("仓库") && !s.ApproveTime.HasValue && s.Pid == model.ID); approve1.ApproveName = "仓库"; approve1.ApproveStatus = 1; approve1.ApproveTime = DateTime.Now; //判断是否第一次换货,如果是则修改订单状态为已收货 //if (exchange.Count() == 1) //{ // order.ExchangeStatus = 2; //} } #endregion } } List <T_ModularNotaudited> ModularNotaudited = db.T_ModularNotaudited.Where(a => a.ModularName == "换货未审核").ToList(); if (ModularNotaudited.Count > 0) { foreach (var item in ModularNotaudited) { db.T_ModularNotaudited.Remove(item); } db.SaveChanges(); } string RetreatAppRoveSql = " select isnull(ApproveUser,ApproveName) as PendingAuditName,COUNT(*) as NotauditedNumber from T_ExchangeCenterApprove where Pid in ( select ID from T_ExchangeCenter where IsDelete=0 ) and ApproveStatus=-1 and ApproveTime is null GROUP BY ApproveName,ApproveUser"; List <Modular> RetreatAppRoveQuery = db.Database.SqlQuery <Modular>(RetreatAppRoveSql).ToList(); string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value); for (int e = 0; e < RetreatAppRoveQuery.Count; e++) { string PendingAuditName = RetreatAppRoveQuery[e].PendingAuditName; T_ModularNotaudited NotauditedModel = db.T_ModularNotaudited.SingleOrDefault(a => a.ModularName == "换货未审核" && a.PendingAuditName == PendingAuditName); if (NotauditedModel != null) { NotauditedModel.NotauditedNumber = RetreatAppRoveQuery[e].NotauditedNumber; db.Entry <T_ModularNotaudited>(NotauditedModel).State = System.Data.EntityState.Modified; } else { T_ModularNotaudited ModularNotauditedModel = new T_ModularNotaudited(); ModularNotauditedModel.ModularName = "换货未审核"; ModularNotauditedModel.NotauditedNumber = RetreatAppRoveQuery[e].NotauditedNumber; ModularNotauditedModel.PendingAuditName = RetreatAppRoveQuery[e].PendingAuditName; ModularNotauditedModel.ToupdateDate = DateTime.Now; ModularNotauditedModel.ToupdateName = Nickname; db.T_ModularNotaudited.Add(ModularNotauditedModel); } db.SaveChanges(); } sc.Complete(); return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } }