using BizCom; using Newtonsoft.Json; using NPOI.POIFS.Properties; using NPOI.SS.Formula.Functions; using SiteCore.Handler; using SiteCore.taoObj; using SQLData; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Reflection; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Metadata.W3cXsd2001; using System.Security.Policy; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using static NHibernate.Linq.Visitors.LeftJoinDetector; using static SiteCore.taoObj.work_core_vo; namespace SiteCore.Handler { public class designHelper : BaseHandler, IHttpHandler { public void ProcessRequest(HttpContext context) { if (UrlParmsCheck("t")) { String tname = GetString("t"); MethodInfo method; Type type = this.GetType(); method = type.GetMethod(tname); con = context; if (method == null) { conError("找不到对应方法,服务器返回错误"); return; } successFlag = false; context.Response.ContentType = "application/json"; context.Response.Headers.Set("Access-Control-Allow-Origin", "*"); try { method.Invoke(this, null); } catch (Exception ex) { conError("处理接口错误,服务器返回错误"); } finally { } } } static string baseUrl = "http://api.lingtao8.com/"; //static string baseUrl = "http://47.122.40.91:8099/"; static string pUrl = baseUrl + "api/manager/"; static HttpHelper tb_http = new HttpHelper(); public static designApiResponseVo API_GetPrintData_CreateOrder(CeErpTradeCell ceErpTradeCell, string post = "") { if (ceErpTradeCell.IsSample == 2) { return new designApiResponseVo(-1, "补差价订单不需要过设计系统"); } string post_url = pUrl + "createOrder"; CeErpOrderFormData formData = null; if (!ceErpTradeCell.ctid.Contains("S_") && ceErpTradeCell.ShopId != 136 && ceErpTradeCell.ShopId != 95) { formData = CeErpOrderFormData.GetByTid(ceErpTradeCell.ctid.ToString()); if (formData == null) { return new designApiResponseVo(-1, "请填写订单的手机号或者微信号才可指派到设计系统"); } } designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell, post); if (response.code != 200) { return response; } WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); //json参数 NameValueCollection PostVars = getParams(ceErpTradeCell); if (ceErpTradeCell.CustomerUserId > 0) { string sql = "select top 1 Name,Mobile from view_ErpUser where ID = '" + ceErpTradeCell.CustomerUserId + "'"; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; PostVars.Add("customerName", dt.Rows[0]["Name"].ToString()); PostVars.Add("customerTel", dt.Rows[0]["Mobile"].ToString()); } //{"msg":"推送成功","code":200,"success":true} string result = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); response = JsonConvert.DeserializeObject(remoteInfo); result = "设计共创:失败-" + response.msg; if (response.code == 200) { result = "设计共创:成功"; CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 2); //commonHelper.updateDataTradeCellDesignInfo(ceErpTradeCell.ctid); } } catch (Exception ex) { XLog.SaveLog(0, "API_GetPrintData_CreateOrder:" + ex.Message); } return new designApiResponseVo(200, result); } public static designApiResponseVo API_GetPrintData_CreateAfterOrder(CeErpTradeCell ceErpTradeCell, string post = "") { if (ceErpTradeCell.IsSample == 2) { return new designApiResponseVo(-1, "补差价订单不需要过设计系统"); } string post_url = pUrl + "createAfterOrder"; CeErpOrderFormData formData = null; if (!ceErpTradeCell.ctid.Contains("S_") && ceErpTradeCell.ShopId != 136 && ceErpTradeCell.ShopId != 95) { formData = CeErpOrderFormData.GetByTid(ceErpTradeCell.ctid.ToString()); if (formData == null) { return new designApiResponseVo(-1, "请填写订单的手机号或者微信号才可指派到设计系统"); } } designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell, post); if (response.code != 200) { return response; } WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); //json参数 NameValueCollection PostVars = getParams(ceErpTradeCell); if (ceErpTradeCell.CustomerUserId > 0) { string sql = "select top 1 Name,Mobile from view_ErpUser where ID = '" + ceErpTradeCell.CustomerUserId + "'"; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; PostVars.Add("customerName", dt.Rows[0]["Name"].ToString()); PostVars.Add("customerTel", dt.Rows[0]["Mobile"].ToString()); } //{"msg":"推送成功","code":200,"success":true} string result = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); response = JsonConvert.DeserializeObject(remoteInfo); result = "设计共创:失败-" + response.msg; if (response.code == 200) { result = "设计共创:成功"; CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 2); //commonHelper.updateDataTradeCellDesignInfo(ceErpTradeCell.ctid); } } catch (Exception ex) { XLog.SaveLog(0, "API_GetPrintData_CreateOrder:" + ex.Message); } return new designApiResponseVo(200, result); } public static designApiResponseVo API_update_order(CeErpTradeCell ceErpTradeCell) { string post_url = pUrl + "workCore"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = getParams(ceErpTradeCell); PostVars.Add("actionName", "orderRemarks"); PostVars.Add("orderNumber", ceErpTradeCell.ctid); string result = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); designApiResponseVo response = JsonConvert.DeserializeObject(remoteInfo); result = "设计共创:失败-" + response.msg; if (response.code == 200) { result = "设计共创:成功"; CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 2); //commonHelper.updateDataTradeCellDesignInfo(ceErpTradeCell.ctid); } } catch (Exception ex) { XLog.SaveLog(0, "API_GetPrintData_CreateOrder:" + ex.Message); } return new designApiResponseVo(200, result); } public static designApiResponseVo API_update_renewOrder(CeErpTradeCell ceErpTradeCell) { string post_url = pUrl + "renewOrder"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = getParams(ceErpTradeCell); PostVars.Add("actionName", "orderRemarks"); PostVars.Add("orderNumber", ceErpTradeCell.ctid); string result = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); designApiResponseVo response = JsonConvert.DeserializeObject(remoteInfo); result = "设计共创:失败-" + response.msg; if (response.code == 200) { result = "设计共创:成功"; CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 2); //commonHelper.updateDataTradeCellDesignInfo(ceErpTradeCell.ctid); } } catch (Exception ex) { XLog.SaveLog(0, "API_update_renewOrder:" + ex.Message); } return new designApiResponseVo(200, result); } private static NameValueCollection getParams(CeErpTradeCell ceErpTradeCell) { Boolean isOldCustomerText = false; Boolean isReturn = false; Boolean isGai = false; if (ceErpTradeCell.IsOldCustomer == 1) { isOldCustomerText = true; } if (ceErpTradeCell.IsReturn > 0) { isReturn = true; } if (ceErpTradeCell.MemoOpt == 1) { isGai = true; } CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid); CeErpShop ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId); CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid); //Dictionary dataDic = ToDictionary(ro_json); //string urlData = ToUrlParams(dataDic); //string sql_pay = "INSERT INTO CE_ErpToDesignLog (ctid, ctime) VALUES ('" + ceErpTradeCell.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');"; //CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString()); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("outId", ceErpTradeCell.ID.ToString()); PostVars.Add("productId", ceErpTradeCell.ProductId.ToString()); PostVars.Add("payment", ceErpTradeCell.payment.ToString()); PostVars.Add("isUrgent", ceErpTradeCell.IsUrgency.ToString()); PostVars.Add("customerMemo", ceErpTradeCell.CustomerMemo); PostVars.Add("shopName", ceErpShop.ShopName); PostVars.Add("buyerNick", ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao"); PostVars.Add("receiverName", ceErpTrade.receiver_name); PostVars.Add("receiverMobile", ceErpTrade.receiver_mobile); PostVars.Add("receiverState", ceErpTrade.receiver_state); PostVars.Add("receiverCity", ceErpTrade.receiver_city); PostVars.Add("receiverDistrict", ceErpTrade.receiver_district); PostVars.Add("receiverAddress", ceErpTrade.receiver_address); PostVars.Add("tids", ceErpTradeCell.ctid); PostVars.Add("isOldlser", isOldCustomerText.ToString()); PostVars.Add("sellerMemo", ceErpTradeCell.seller_memo); PostVars.Add("orderRemarks", ceErpTradeCell.seller_memo); PostVars.Add("isChange", isGai.ToString()); PostVars.Add("isBack", isReturn.ToString()); PostVars.Add("tid", ceErpTradeCell.tid); PostVars.Add("isDianziOrder", ceErpTradeCell.isDianziOrder.ToString()); PostVars.Add("orderUnique", ceErpTradeCell.OrderSn); PostVars.Add("ptid", ceErpTradeCell.ptid); PostVars.Add("SplitTag", ceErpTradeCell.SplitTag); PostVars.Add("remarkSign", ceErpTradeCell.MemoOpt.ToString()); PostVars.Add("otherMemo", ceErpTradeCell.OtherMemo); PostVars.Add("parentSplitNo", ceErpTradeCell.ParentSplitNo); if (ceErpTradeCellExtend != null) { PostVars.Add("productFirName", ceErpTradeCellExtend.cate1);/// 分类1 PostVars.Add("productFirId", ceErpTradeCellExtend.cate1Id);/// 分类id PostVars.Add("productSecName", ceErpTradeCellExtend.cate2);/// 分类2 PostVars.Add("productSecId", ceErpTradeCellExtend.cate2Id);/// 分类id PostVars.Add("productThirdId", ceErpTradeCellExtend.cate3Id);/// 分类id PostVars.Add("sceneName", ceErpTradeCellExtend.scene); /// 场景 PostVars.Add("sceneId", ceErpTradeCellExtend.sceneId); /// 场景id PostVars.Add("productSizeW", ceErpTradeCellExtend.length.ToString()); /// 长 PostVars.Add("productSizeH", ceErpTradeCellExtend.height.ToString()); /// 高 PostVars.Add("productSizeL", ceErpTradeCellExtend.width.ToString()); /// 宽 PostVars.Add("productCraftName", ceErpTradeCellExtend.craft); /// 工艺 PostVars.Add("offerAmount", ceErpTradeCellExtend.offerAmount.ToString()); /// 报价金额 PostVars.Add("styleCount", ceErpTradeCellExtend.numbers.ToString()); /// 款数 PostVars.Add("materialName", ceErpTradeCellExtend.material); /// 材质 PostVars.Add("materialId", ceErpTradeCellExtend.materialId); /// 材质id PostVars.Add("stylePricing", ceErpTradeCellExtend.numberType); /// 多款类型 PostVars.Add("productSceneName", ceErpTradeCellExtend.typeScene); /// 品类场景 PostVars.Add("productSceneId", ceErpTradeCellExtend.typeSceneId); /// 品类场景id PostVars.Add("opScene", ceErpTradeCellExtend.opScene); /// 运营场景 PostVars.Add("opSceneId", ceErpTradeCellExtend.opSceneId); /// 运营场景id PostVars.Add("quantity", ceErpTradeCellExtend.quantity.ToString()); /// 数量 PostVars.Add("productUnit", ceErpTradeCellExtend.numberUnit); /// 数量单位 PostVars.Add("spuId", ceErpTradeCellExtend.spu_id); /// spuid PostVars.Add("recSize", ceErpTradeCellExtend.recSize); /// 推荐尺寸 PostVars.Add("productSizeUnit", ceErpTradeCellExtend.sizeUnit); /// 尺寸单位 PostVars.Add("orderFrom", ceErpTradeCellExtend.orderFrom.ToString()); /// 【订单来源】"10":第三方平台"15":私域电商"20":ERP"30":售前系统 PostVars.Add("orderType", ceErpTradeCellExtend.orderType.ToString()); /// 【订单类型】"10":线上单"15":线下单"20":补差单"30":售后单 PostVars.Add("discountAmount", ceErpTradeCellExtend.discountAmount.ToString());//折扣金额 PostVars.Add("differentAmount", ceErpTradeCellExtend.differentAmount.ToString());//补差金额 PostVars.Add("differentSplitNo", ceErpTradeCellExtend.differentSplitNo);//补差识别号 } return PostVars; } /** *actionName: * followRemarks 跟单备注 * orderRemarks 修改订单备注 * rebutDesign 下单部打回设计单 * afterDesign 售后设计单 * changeDesign 改稿/定稿/加急 * remarkSign 1改稿2定稿3加急 * closeDesign 关闭订单 * resetDesign 重置订单 * packageDesign 顺丰状态 * finishDesign 顺丰状态 * approveDesign 下单部通过 **/ public static void API_WorkCore(string orderNumber, string actionName, string orderRemarks = "", int remarkSign = 0, string reasonRemarks = "", string isSf = "", int demandExamine = 0) { string post_url = pUrl + "workCore"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("orderNumber", orderNumber); PostVars.Add("actionName", actionName); if (remarkSign > 0) { PostVars.Add("remarkSign", remarkSign.ToString()); } if (orderRemarks != "") { PostVars.Add("orderRemarks", orderRemarks); } if (reasonRemarks != "") { PostVars.Add("reasonRemarks", reasonRemarks); } if (isSf != "") { PostVars.Add("packageSign", isSf); } if (demandExamine != 0) { PostVars.Add("demandExamine", demandExamine.ToString()); } string remoteInfo = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); } catch (Exception ex) { XLog.SaveLog(0, "API_WorkCore:" + ex.Message); } } /** *actionName: * followRemarks 跟单备注 * orderRemarks 修改订单备注 * rebutDesign 下单部打回设计单 * afterDesign 售后设计单 * changeDesign 改稿/定稿/加急 * remarkSign 1改稿2定稿3加急 * closeDesign 关闭订单 * resetDesign 重置订单 * packageDesign 顺丰状态 * finishDesign 上传设计 * repairDesign 补差金额 * approveDesign 下单部通过 * afterOver 售后结束 **/ public static void API_WorkCore(ApiVo vo) { string post_url = pUrl + "workCore"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("orderNumber", vo.orderNumber); PostVars.Add("actionName", vo.actionName); PostVars.Add("isDesign", vo.isDesign.ToString()); PostVars.Add("isOriginal", vo.isOriginal.ToString()); if (vo.remarkSign > 0) { PostVars.Add("remarkSign", vo.remarkSign.ToString()); } if (vo.orderRemarks != "") { PostVars.Add("orderRemarks", vo.orderRemarks); } if (vo.reasonRemarks != "") { PostVars.Add("reasonRemarks", vo.reasonRemarks); } if (vo.isSf != "") { PostVars.Add("packageSign", vo.isSf); } if (vo.demandExamine != 0) { PostVars.Add("demandExamine", vo.demandExamine.ToString()); } if (vo.payment != 0) { PostVars.Add("payment", vo.payment.ToString()); } if (vo.designFree != 0) { PostVars.Add("designFree", vo.designFree.ToString()); } if (vo.responsibleId != 0) { PostVars.Add("responsibleId", vo.responsibleId.ToString()); } if (!string.IsNullOrEmpty(vo.afterFiles)) { PostVars.Add("afterFiles", vo.afterFiles); } string remoteInfo = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); if ("orderRemarks".Equals(vo.actionName)) { XLog.SaveLog(0, "API_WorkCore:" + remoteInfo + vo.actionName); } } catch (Exception ex) { XLog.SaveLog(0, "API_WorkCore:" + ex.Message); } } public static void api_approveDesign(string orderNumber) { string post_url = pUrl + "approveDesign"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("orderNumber", orderNumber); string remoteInfo = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); } catch (Exception ex) { XLog.SaveLog(0, "api_approveDesign:" + ex.Message); } } /** *actionName: * refundIng 退款申请 * refundEd 已退款 * refundCancel 取消退款 **/ public static void API_refundOrder(string orderNumber, string actionName, string remark) { string post_url = pUrl + "refundOrder"; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("orderNumber", orderNumber); PostVars.Add("actionName", actionName); PostVars.Add("orderRemarks", remark); string remoteInfo = ""; try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); } catch (Exception ex) { XLog.SaveLog(0, "API_refundOrder:" + ex.Message); } } public static string API_CheckOrderTo(string orderNumber, string spuId, int shopId) { List shopIds = new List() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 17, 18, 21, 23, 24, 27, 28, 31, 32, 56, 61, 63, 64, 66, 124, 126, 127, 128 }; string result = "无"; if (!shopIds.Contains(shopId)) { return result; } return result; string post_url = pUrl + "discernOrder"; System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // 根据需要选择合适的协议版本 WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding("utf-8"); NameValueCollection PostVars = new NameValueCollection(); PostVars.Add("orderNumber", orderNumber); PostVars.Add("spuId", spuId); try { byte[] ret = wc.UploadValues(post_url, "POST", PostVars); string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret); designApiResponseVo designApiResponseVo = JsonConvert.DeserializeObject(remoteInfo); if (designApiResponseVo.code == 200) { result = designApiResponseVo.msg; } } catch (Exception ex) { XLog.SaveLog(0, "discernOrder:" + ex.Message); } return result; } public static string API_GetPrintData_Refund(CeErpTradeCell ceErpTradeCell) { string post_url = pUrl + "refund"; //json参数 List postLst = new List(); Boolean isOldCustomerText = false; Boolean isReturn = false; Boolean isGai = false; if (ceErpTradeCell.IsOldCustomer == 1) { isOldCustomerText = true; } if (ceErpTradeCell.IsReturn > 0) { isReturn = true; } if (ceErpTradeCell.MemoOpt == 1) { isGai = true; } CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid); CeErpShop ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId); var res_obj = new { outId = ceErpTradeCell.ID, productId = ceErpTradeCell.ProductId, payment = ceErpTradeCell.payment, isUrgent = ceErpTradeCell.IsUrgency, customerMemo = ceErpTradeCell.CustomerMemo, shopName = ceErpShop.ShopName, buyerNick = ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao", receiverName = ceErpTrade.receiver_name, receiverMobile = ceErpTrade.receiver_mobile, receiverState = ceErpTrade.receiver_state, receiverCity = ceErpTrade.receiver_city, receiverDistrict = ceErpTrade.receiver_district, receiverAddress = ceErpTrade.receiver_address, tids = ceErpTradeCell.ctid, isOldUser = isOldCustomerText, sellerMemo = ceErpTradeCell.seller_memo, isChange = isGai, isBack = isReturn, tid = ceErpTradeCell.tid }; string ro_json = JsonConvert.SerializeObject(res_obj); //;*************************************************** ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; HttpItem item = new HttpItem() { URL = post_url, Method = "POST", Postdata = ro_json }; item.PostEncoding = Encoding.UTF8; HttpResult hResult = tb_http.GetHtml(item); return hResult.Html; } public static string API_GetPrintData_ModifyOrder(string tid, string seller_memo, Boolean isGai, Boolean isReturn, string returnReason = "") { string post_url = pUrl + "modify"; //json参数 List postLst = new List(); CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid); CeErpShop ceErpShop = null; if (ceErpTradeCell != null) { ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId); } var res_obj = new { outId = tid, orderText = seller_memo, isChange = isGai, isBack = isReturn, returnReason = returnReason, }; string ro_json = JsonConvert.SerializeObject(res_obj); //*************************************************** ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; HttpItem item = new HttpItem() { URL = post_url, Method = "POST", Postdata = ro_json }; item.PostEncoding = Encoding.UTF8; HttpResult hResult = tb_http.GetHtml(item); return hResult.Html; } } }