using BizCom; using Microsoft.SqlServer.Server; using Newtonsoft.Json; using NPOI.OpenXmlFormats.Shared; using NPOI.SS.Formula.Functions; using SiteCore.taoObj; using SQLData; using System; using System.Collections.Generic; using System.Data; using System.Reflection; using System.Text; using System.Web; namespace SiteCore.Handler { public class noti : 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 { //AfterInvoke(methodName); } //if (!successFlag) returnErrorMsg("服务器返回错误"); } } public void sendNotify() { if (UrlPostParmsCheck("title,oid")) { string title = GetPostString("title"); string openid = GetPostString("oid"); WxPush.sendMonitorMsg(title, openid); conSuccess("已发送"); return; } conError("没有发送成功!"); } public void LT_ERP_delivery_push() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid"); string outsid = GetPostString("outsid"); string cpCode = GetPostString("cpcode"); tbtid = tbtid.Trim(); CeErpTrade mainEn = CeErpTrade.Get(tbtid); if (mainEn != null || tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid); //cpcode是 YTO-CAINIAO //string comCode = cpCode.Split('-')[0].ToString(); string apires = ""; if (tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { apires = "发货成功"; } else { string dcomcode = commonHelper.GetD3ComCode(cpCode, cpCode); apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outsid); } //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode); //打单后发货 if (apires.IndexOf("发货成功") != -1) { try { //还要插入快递信息到 快递信息表 CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "裕恒"; exinfo.Create(); if (mainEn != null) { commonHelper.UpdateRelationOrder(mainEn.tid); commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, outsid); } LogHelper.addLog(tbtid, 0, "裕恒接口-发货成功-" + cpCode + "-" + outsid); StringBuilder sql = new StringBuilder(); sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tbtid); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); returnSuccessMsg("记录及同步成功"); return; } catch (Exception ex) { XLog.SaveLog(0, "裕恒接口发货成功后更新数据失败," + ex.Message); } } else { string errmsg = commonHelper.KeepChinese(apires); //returnErrorMsg("同步淘宝发货失败!" + errmsg); XLog.SaveLog(0, "裕恒接口-打单后发货失败," + tbtid + "," + outsid + "," + apires); try { CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "裕恒"; exinfo.Create(); returnSuccessMsg("记录成功!"); } catch (Exception ex) { XLog.SaveLog(0, "裕恒接口记录快递号,失败," + ex.Message); } return; } //else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED") //已发货的不处理直接返回面单 //{ // entity.OutSid = (entity.OutSid + "," + curUseWayBillCode); // if (entity.OrderState == 6) // { // entity.OrderState = 7; // } // btnType = "已发货"; // entity.Update(); // commonHelper.UpdateRelationOrder(entity.ctid); // //不处理 //} //else //{ // entity.LastBillCpCode = cpCode; // entity.LastBillWaybillCode = curUseWayBillCode; // entity.Update(); // string errmsg = commonHelper.KeepChinese(apires); // var res_objz = new // { // restype = 0, // data = "打单后发货失败" // }; // string ro_jsonz = JsonConvert.SerializeObject(res_objz); // returnSuccess(ro_jsonz); // //returnErrorMsg("同步淘宝发货失败!"+ errmsg); // XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires); // return; //} return; } returnErrorMsg("找不到对应订单记录,核对淘宝订单号"); return; } returnErrorMsg("缺少必要的参数"); } public void LT_ERP_order_err_report() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid"); string errdis = GetPostString("errdis"); tbtid = tbtid.Trim(); CeErpTradeCell entity = null; if (tbtid != "") entity = CeErpTradeCell.GetByCtid(tbtid); if (entity != null) { entity.IsVerifyToSupplier = false; entity.IsReturn = 1; entity.ReturnTime = DateTime.Now; entity.ReturnReason = errdis; if (entity.OrderState == 6) { entity.OrderState = 5; } entity.Update(); LogHelper.addLog(entity.ctid, 0, "裕恒接口-供应商退回下单", entity.OrderState); returnSuccessMsg("操作成功!"); return; } else { StringBuilder sql = new StringBuilder(); sql.AppendFormat("select * from CE_ErpTradeCell where tid='{0}' and orderstate=6 and SupplierId=8", tbtid); DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0]; if (dt.Rows.Count > 1) { returnErrorMsg("匹配不到对应的淘宝单号,请直接发给领淘"); return; } else { StringBuilder sqlbac = new StringBuilder(); sqlbac.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsVerifyToSupplier=0,IsReturn=1,ReturnTime=getdate(),ReturnReason={1},OrderState=5 where ctid='{0}' and orderstate=6 and SupplierId=8;", dt.Rows[0]["ctid"].ToString(), errdis); DbHelper.DbConn.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(dt.Rows[0]["ctid"].ToString(), 0, "裕恒接口-供应商退回下单", 0); returnSuccessMsg("操作成功"); return; } } } returnErrorMsg("缺少必要的参数"); } //印艺发货 public void LT_ERP_YY_DELIVERY_PUSH() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid"); string outsid = GetPostString("outsid"); string cpCode = GetPostString("cpcode"); tbtid = tbtid.Trim(); CeErpTrade mainEn = CeErpTrade.Get(tbtid); if (mainEn != null || tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid); //cpcode是 YTO-CAINIAO //string comCode = cpCode.Split('-')[0].ToString(); string apires = ""; if (tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { apires = "发货成功"; } else { string dcomcode = commonHelper.GetD3ComCode(cpCode, cpCode); apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outsid); } //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode); //打单后发货 if (apires.IndexOf("发货成功") != -1) { try { //还要插入快递信息到 快递信息表 CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "印艺"; exinfo.Create(); if (mainEn != null) { commonHelper.UpdateRelationOrder(mainEn.tid); commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, outsid); } LogHelper.addLog(tbtid, 0, "印艺接口-发货成功-" + cpCode + "-" + outsid); StringBuilder sql = new StringBuilder(); sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tbtid); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); returnSuccessMsg("记录及同步成功"); return; } catch (Exception ex) { XLog.SaveLog(0, "印艺接口发货成功后更新数据失败," + ex.Message); } } else { string errmsg = commonHelper.KeepChinese(apires); //returnErrorMsg("同步淘宝发货失败!" + errmsg); XLog.SaveLog(0, "印艺接口-打单后发货失败," + tbtid + "," + outsid + "," + apires); try { CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "印艺"; exinfo.Create(); returnSuccessMsg("记录成功!"); } catch (Exception ex) { XLog.SaveLog(0, "印艺接口记录快递号,失败," + ex.Message); } return; } return; } returnErrorMsg("找不到对应订单记录,核对淘宝订单号"); return; } returnErrorMsg("缺少必要的参数"); } //智韬发货 public void LT_ERP_ZT_DELIVERY_PUSH() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid"); string outsid = GetPostString("outsid"); string cpCode = GetPostString("cpcode"); tbtid = tbtid.Trim(); CeErpTrade mainEn = CeErpTrade.Get(tbtid); if (mainEn != null || tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid); //cpcode是 YTO-CAINIAO //string comCode = cpCode.Split('-')[0].ToString(); string apires = ""; if (tbtid.IndexOf("N") != -1 || tbtid.IndexOf("S") != -1) { apires = "发货成功"; } else { string dcomcode = commonHelper.GetD3ComCode(cpCode, cpCode); apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outsid); } //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode); //打单后发货 if (apires.IndexOf("发货成功") != -1) { try { //还要插入快递信息到 快递信息表 CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "智韬"; exinfo.Create(); if (mainEn != null) { commonHelper.UpdateRelationOrder(mainEn.tid); commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, outsid); } LogHelper.addLog(tbtid, 0, "智韬接口-发货成功-" + cpCode + "-" + outsid); StringBuilder sql = new StringBuilder(); sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tbtid); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); returnSuccessMsg("记录及同步成功"); return; } catch (Exception ex) { XLog.SaveLog(0, "智韬接口发货成功后更新数据失败," + ex.Message); } } else { string errmsg = commonHelper.KeepChinese(apires); //returnErrorMsg("同步淘宝发货失败!" + errmsg); XLog.SaveLog(0, "智韬接口-打单后发货失败," + tbtid + "," + outsid + "," + apires); try { CeErpExpressInfo exinfo = new CeErpExpressInfo(); exinfo.tid = tbtid; exinfo.out_sid = outsid; exinfo.company_code = cpCode; exinfo.company_name = cpCode; //exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId); exinfo.deliveryType = "发货成功"; exinfo.print_time = DateTime.Now; exinfo.printUser = "智韬"; exinfo.Create(); returnSuccessMsg("记录成功!"); } catch (Exception ex) { XLog.SaveLog(0, "智韬接口记录快递号,失败," + ex.Message); } return; } return; } returnErrorMsg("找不到对应订单记录,核对淘宝订单号"); return; } returnErrorMsg("缺少必要的参数"); } //chy补差价单发货接口 public void LT_ERP_CHY_DELIVERY_PUSH() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid").Trim(); string outsid = GetPostString("outsid").Trim(); string cpCode = GetPostString("cpcode").Trim(); CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tbtid); if (entity != null && entity.isAfterSaleOrder == 1) { entity.OrderState = 7; entity.Update(); LogHelper.addLog(tbtid, 0, "chy发货售后单-" + cpCode + "-" + outsid); return; } string sql = "select top 1 * from view_erptradecell where ptid='" + tbtid + "';"; DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0]; if (dt.Rows.Count <= 0) return; string tid = dt.Rows[0]["tid"].ToString(); string posCode = dt.Rows[0]["posCode"].ToString(); string status = dt.Rows[0]["status"].ToString(); string comCode = cpCode; string sqlstr = "select * from CE_ErpMailInfo"; DataTable dtstr = DbHelper.DbConn.ExecuteDataset(sqlstr.ToString()).Tables[0]; foreach (DataRow dr in dtstr.Rows) { if (dr["cpCode"].ToString().IndexOf(cpCode) != -1) { comCode = dr["cpCode"].ToString(); } } if (status == "SHIPPED" || status == "PART_SHIPPED" || status == "COMPLETE" || status == "CLOSE") //已发货的不处理直接返回面单 { return; //不处理 } string apires = apiHelper.API_LogisticsDummySend(tid, posCode); if (apires.IndexOf("发货成功") == -1) { //XLog.SaveLog(0, "补差价单虚拟发货失败," + tid + "," + posCode + "," + apires); string wures = apiHelper.API_LogisticsOnlineSend(tid, posCode, comCode, outsid); if (wures.IndexOf("发货成功") == -1) { XLog.SaveLog(0, "chy补差价单实物发货失败," + tid + "," + posCode + "," + wures); return; } else { LogHelper.addLog(tid, 0, "chy补差价发货-" + comCode + "-" + outsid); } return; } else { LogHelper.addLog(tbtid, 0, "chy补差价发货-" + comCode + "-" + outsid); } } } //印艺快递停发 public void LT_ERP_YY_STOP_DELIVERY() { if (UrlPostParmsCheck("tbtid")) { string tbtid = GetPostString("tbtid"); tbtid = tbtid.Trim(); CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tbtid); if (entity != null) { if (entity.IsRefund <= 0 && entity.OrderState == 6) { entity.IsVerifyToSupplier = false; entity.UnusualTag = 5; entity.UnusualCon = "快递停发"; entity.Update(); LogHelper.addLog(entity.ctid, 0, "印艺接口-快递停发", entity.OrderState); returnSuccessMsg("操作成功!"); return; } else { returnSuccessMsg("订单非下单完成状态或已退款!"); return; } } else { returnErrorMsg("匹配不到对应的淘宝单号,请直接发给领淘"); return; } } returnErrorMsg("缺少必要的参数"); } public void get_product_form_data() { string tid = GetPostString("tid"); if (tid != null && tid != "0") { tid = tid.Trim(); CeErpTradeCell tradeCell = CeErpTradeCell.GetByCtid(tid); CeErpProduct entity = null; if (tradeCell != null) { entity = CeErpProduct.Get(tradeCell.ProductId); } CeErpOrderFormData formData = CeErpOrderFormData.GetByTid(tid); StringBuilder str = new StringBuilder(); str.Append("{"); str.Append("\"success\":true,"); str.AppendFormat("\"tradeCell\":{0},", JsonConvert.SerializeObject(tradeCell)); str.AppendFormat("\"product\":{0},", JsonConvert.SerializeObject(entity)); str.AppendFormat("\"CeErpOrderFormData\":{0},", JsonConvert.SerializeObject(formData)); str.AppendFormat("\"code\":200,"); str.AppendFormat("\"msg\":\"成功\""); str.Append("}"); con.Response.Write(str.ToString()); } } public void save_product_form_data() { string tid = GetPostString("tid"); if (tid != null && tid != "0") { tid = tid.Trim(); CeErpTradeCell tradeCell = CeErpTradeCell.GetByCtid(tid); if (tradeCell == null) { returnErrorMsg("单号查无订单"); return; } string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", tradeCell.tid); if (tradeCell.ctid.Contains("S_")) { info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE ctid ='{0}'", tradeCell.ctid); } DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0]; string content = GetPostString("content"); int eid = GetPostInt("id"); CeErpOrderFormData formData = null; if (data.Rows.Count > 0) { List cell_list = new List(); foreach (DataRow row in data.Rows) { string ctid = row["ctid"].ToString(); CeErpTradeCell cell = CeErpTradeCell.GetByCtid(ctid); cell_list.Add(cell); formData = CeErpOrderFormData.GetByTid(ctid); if (formData == null) { formData = new CeErpOrderFormData(); } formData.tid = ctid; formData.content = content; if (formData.ID > 0) { formData.Update(); } else { formData.userId = GetPostInt("userId"); formData.Create(); } } if (tradeCell.OrderState >= 5) { LogHelper.addLog(tradeCell.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:订单状态不正确!", tradeCell.OrderState); returnSuccessMsg("保存成功!"); return; } //能进来并且没有设计师 foreach (CeErpTradeCell entity in cell_list) { try { if (entity != null && entity.seller_memo.Length > 0) { if (entity.OrderState >= 5) { LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:订单状态不正确!", entity.OrderState); continue; } //判断能不能推送 designApiResponseVo result = commonHelper.checkOrderListDesignInfo(entity.tid, entity.ctid); if (result != null && result.code == 200) { designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, "SysAdmin"); if (response.code == 200) { if (response.msg == "设计共创:成功") { if (entity.ctid.IndexOf("S_") == -1) { int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商 entity.SupplierId = suid; string suname = commonHelper.getSupplierNameById(entity.SupplierId); LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState); } entity.OrderState = Convert.ToInt32(OrderState.待设计); entity.DesignUserId = 3542; entity.WaitDesignTime = DateTime.Now; entity.DispatchSort = 2; entity.UpdateTime = DateTime.Now; entity.Update(); } } LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:" + response.msg, Convert.ToInt32(OrderState.待设计)); } else { LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:" + result.msg, Convert.ToInt32(OrderState.待设计)); } } } catch (Exception ex) { XLog.SaveLog(0, "外链派单:" + ex.Message); } } } returnSuccessMsg("保存成功!"); } } //http://47.114.150.226:88/Handler/noti.ashx?t=LT_ERP_CHY_DELIVERY_PUSH post请求参数(参数放body中): tbtid(淘宝订单号) outsid(快递单号) cpcode(快递公司编码,如:圆通的是 YTO) } }