| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- using BizCom;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using NHibernate.Cfg.MappingSchema;
- 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.IO;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Security.Cryptography;
- using System.Text;
- using System.Web;
- using Utils;
- using static SiteCore.taoObj.Api_waybill_code_response_Obj;
- using static SiteCore.taoObj.work_core_vo;
- namespace SiteCore.Handler
- {
- public class apiCaiYingTong : 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("服务器返回错误");
- }
- }
- static string appID = "1823193185001";
- //***************************************************
- //static string signkey = "fed5be35cf5bd04b14dcfff984f861dd";
- static HttpHelper tb_http = new HttpHelper();
- static string merSecret = "D8FF9498A5A2E6A6B4CB6EF88DB1DC35";
- static string pUrl = "https://front.lingtao8.com/designRest.htm";
- //static string pUrl = "https://localhost:8999/designRest.htm";
- //static string pUrl = "http://yi.yhmwacg.cn/designRest.htm";
- public static int DateTimeToUnixTime(DateTime dateTime)
- {
- return (int)(dateTime - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
- }
- //public static string ToUrlParams(object jsonObject)
- //{
- // var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); // 遍历JSON对象的属性,并添加到查询字符串中
- // foreach (var property in jsonObject.GetType().GetProperties())
- // {
- // queryString[property.Name] = property.GetValue(jsonObject)?.ToString() ?? string.Empty;
- // }
- // return queryString.ToString();
- //}
- public static Dictionary<string, object> ToDictionary(object obj)
- {
- var type = obj.GetType();
- var properties = type.GetProperties();
- var dictionary = new Dictionary<string, object>();
- foreach (var property in properties)
- {
- var value = property.GetValue(obj);
- dictionary.Add(property.Name, value);
- }
- return dictionary;
- }
- public static string ToUrlParams(Dictionary<string, object> jsonObject)
- {
- var queryString = new System.Collections.Specialized.NameValueCollection();
- // 遍历JSON对象的属性,并添加到查询字符串中
- foreach (var property in jsonObject)
- {
- var value = property.Value;
- if (value != null)
- {
- // 如果属性值不为null,则添加到查询字符串中
- if (value is System.Collections.IEnumerable && !(value is string))
- {
- // 如果是数组或集合类型,需要进一步处理
- var index = 0;
- foreach (var item in (System.Collections.IEnumerable)value)
- {
- queryString.Add(property.Key + "[" + index + "]", item != null ? item.ToString() : string.Empty);
- index++;
- }
- }
- else
- {
- // 普通属性
- queryString.Add(property.Key, value.ToString());
- }
- }
- }
- // 获取最终的查询字符串
- return string.Join("&", queryString.AllKeys.Select(key => key + "=" + queryString[key]));
- }
- public static string createSignCode(string method, string timeStr, string design_app_id, string design_secret)
- {
- byte[] use_bytes;
- //query.Append(secret);
- //预留看一下到时候签名怎么用md5加密;***************************************************
- string encryStr = design_secret + method + timeStr + design_app_id + design_secret;
- MD5 md5 = MD5.Create();
- use_bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(encryStr));
- StringBuilder result = new StringBuilder();
- for (int i = 0; i < use_bytes.Length; i++)
- {
- result.Append(use_bytes[i].ToString("x2"));
- }
- string singResult = result.ToString();
- return singResult.Replace("-", "");
- //return bytes.ToString();
- }
- //http://47.114.150.226:88/Handler/apiDesign.ashx?t=DesignSys_AddLog post请求参数(参数放body中):string tid(淘宝订单号)string userName(操作用户)string con(日志内容)int orderState(订单状态)
- public void DesignSys_AddLog()
- {
- if (UrlPostParmsCheck("tid"))
- {
- try
- {
- //HttpContext.Current.Request.BinaryRead()
- string tid = GetPostString("tid");
- string userName = GetPostString("userName");
- int orderState = GetPostInt("orderState");
- string con = GetPostString("con");
- //returnErrorMsg(tid + "," + userName + "," + orderState + "," + con);
- //return;
- try
- {
- CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
- if (ceErpTradeCell != null)
- {
- if (userName != "")
- {
- CeErpUser ceErpUser = CeErpUser.GetByUserName(userName);
- if (ceErpUser != null)
- {
- LogHelper.addLog(tid, ceErpUser.ID, con, orderState);
- return;
- }
- else
- {
- returnErrorMsg("找不到对应用户");
- return;
- }
- }
- returnErrorMsg("找不到对应用户");
- }
- else
- {
- returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "xxxxx," + ex.Message);
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- return;
- }
- returnErrorMsg("缺少必要的参数");
- }
- public void shipments_Api()
- {
- string tid = GetString("tid");
- string comCode = GetString("comCode");
- string out_Sid = GetString("out_Sid");
- string curUseWayBillCode = out_Sid;
- string cpCode = comCode;
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
- if (entity != null)
- {
- CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
- string sql = "select top 1 * from view_erptradecell where tid='" + tid + "';";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- if (dt.Rows.Count <= 0) return;
- string posCode = dt.Rows[0]["posCode"].ToString();
- string apires = API_LogisticsOnlineSend(tid, posCode, comCode, out_Sid);
- CeErpMessageAPI ceErpMessageAPI = new CeErpMessageAPI();
- JObject jsonObject = new JObject
- {
- { "tid", tid},
- { "pCode", posCode},
- { "comCode", comCode },
- { "out_Sid", out_Sid }
- };
- ceErpMessageAPI.ctid = tid;
- ceErpMessageAPI.tid = tid;
- ceErpMessageAPI.creationtime = DateTime.Now;
- ceErpMessageAPI.content = apires;
- ceErpMessageAPI.Create();
- if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
- {
- try
- {
- entity.OutSid = curUseWayBillCode;
- entity.OrderState = 7;
- entity.IsUrgency = false;
- entity.LastBillCpCode = "";
- entity.LastBillWaybillCode = "";
- entity.FinishDeliveryTime = DateTime.Now;
- entity.IsReturn = 0;
- entity.MemoOpt = 0;
- entity.Update();
- //还要插入快递信息到 快递信息表
- CeErpExpressInfo exinfo = new CeErpExpressInfo();
- exinfo.tid = entity.ctid;
- exinfo.out_sid = entity.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();
- commonHelper.UpdateRelationOrder(entity.ctid);
- CeErpSukuraData.createInfo(entity.ctid, 4);
- commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
- }
- }
- else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
- {
- entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
- if (entity.OrderState == 6)
- {
- entity.OrderState = 7;
- }
- entity.FinishDeliveryTime = DateTime.Now;
- entity.Update();
- CeErpExpressInfo exinfo = new CeErpExpressInfo();
- exinfo.tid = entity.ctid;
- exinfo.out_sid = entity.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();
- commonHelper.UpdateRelationOrder(entity.ctid);
- //不处理
- }
- else
- {
- entity.LastBillCpCode = cpCode;
- entity.LastBillWaybillCode = curUseWayBillCode;
- entity.Update();
- string errmsg = commonHelper.KeepChinese(apires);
- //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
- XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
- }
- returnSuccessMsg(apires);
- LogHelper.addLog(entity.ctid, 0, "彩印通发货-" + comCode + "-" + out_Sid, entity.OrderState);
- return;
- }
- else
- {
- returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
- return;
- }
- return;
- }
- public void waybill_Api()
- {
- string tid = GetString("tid");
- string cpCode = GetString("cpCode");
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
- if (entity != null)
- {
- bool isUseLastWayBillCode = true;
- if ((entity.OrderState == 7 || entity.OrderState == 6))
- {
- isUseLastWayBillCode = false;
- }
- else
- {
- returnErrorMsg("订单状态错误无法获取面单");
- return;
- }
- if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
- {
- returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
- return;
- }
- string res = "";
- Api_waybill_code_response_Obj fullObj = null;
- string pData_str = "";
- string curUseWayBillCode = "";
- if (isUseLastWayBillCode == false)
- {
- res = apiHelper.API_GetWaybill(cpCode, tid);
- try
- {
- if (res.IndexOf("failure") != -1)
- {
- //int idx = res.IndexOf("sub_message");
- //int idx2 = res.IndexOf("flag");
- //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
- string errMsgNeed = commonHelper.KeepChinese(res);
- var res_objd = new
- {
- restype = 0,
- data = "获取面单失败" + errMsgNeed
- };
- string ro_jsond = JsonConvert.SerializeObject(res_objd);
- returnSuccess(ro_jsond);
- if (res.IndexOf("停发") != -1)
- {
- entity.UnusualCon = "物流停发";
- entity.Update();
- }
- //returnErrorMsg("获取面单失败,"+emsg);
- XLog.SaveLog(0, "获取面单失败" + res);
- return;
- }
- else if (res.IndexOf("errorMsg") != -1)
- {
- //int idx = res.IndexOf("errorMsg");
- //int idx2 = res.IndexOf("}]}");
- //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
- string errMsgNeed = commonHelper.KeepChinese(res);
- var res_objf = new
- {
- restype = 0,
- data = "获取面单失败2" + errMsgNeed
- };
- string ro_jsonf = JsonConvert.SerializeObject(res_objf);
- if (res.IndexOf("停发") != -1)
- {
- entity.UnusualCon = "物流停发";
- entity.Update();
- CeErpTrade trade = CeErpTrade.Get(entity.tid);
- if (trade != null)
- {
- string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
- }
- }
- returnSuccess(ro_jsonf);
- //returnErrorMsg("获取面单失败," + emsg);
- XLog.SaveLog(0, "获取面单失败2" + res);
- return;
- }
- res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "生成fullObj" + res);
- var res_objf = new
- {
- restype = 0,
- data = "生成fullObj发生错误" + ex.Message
- };
- string ro_jsonf = JsonConvert.SerializeObject(res_objf);
- returnSuccess(ro_jsonf);
- return;
- }
- if (fullObj.response.data.content.Count > 0)
- {
- ContentItem codeObj = fullObj.response.data.content[0];
- if (cpCode.IndexOf("SFFQ-") != -1)
- {
- pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
- }
- else
- pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
- curUseWayBillCode = codeObj.waybillCode;
- LogHelper.addLog(entity.ctid, 0, "彩印通获取面单成功-" + cpCode + "-" + curUseWayBillCode, entity.OrderState);
- returnSuccess(pData_str);
- return;
- }
- else
- {
- XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
- var res_objf = new
- {
- restype = 0,
- data = "生成fullObj找不到快递单号waybillCode"
- };
- string ro_jsonf = JsonConvert.SerializeObject(res_objf);
- returnSuccess(ro_jsonf);
- return;
- }
- }
- else
- {
- //使用上次打印的快递单号
- if (cpCode == "SFFQ-LY")
- {
- pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
- }
- else
- pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
- curUseWayBillCode = entity.LastBillWaybillCode;
- }
- if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
- {
- var res_obje = new
- {
- restype = 0,
- data = "获取加密打印数据失败"
- };
- string ro_jsone = JsonConvert.SerializeObject(res_obje);
- returnSuccess(ro_jsone);
- entity.LastBillCpCode = cpCode;
- entity.LastBillWaybillCode = curUseWayBillCode;
- entity.Update();
- XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
- //returnErrorMsg("获取加密打印数据失败");
- return;
- }
- }
- else
- {
- returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
- return;
- }
- return;
- }
- //http://47.114.150.226:88/Handler/apiCaiYingTong.ashx?t=afterCytSale ctid status supmemo
- public void afterCytSale()
- {
- string ctid = GetString("ctid");
- int st = GetInt("status");
- string afmemo = GetString("supmemo");
- string id = "0";
- CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(ctid, 64, 1, 0);
- CeErpTradeCell entity = null;
- if (ceErpTradeResponsible != null)
- {
- id = ceErpTradeResponsible.ID.ToString();
- entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
- if (ceErpTradeResponsible.VerifyState == 1)
- {
- returnErrorMsg("已超时自动认可");
- return;
- }
- }
- if (entity != null)
- {
- if (entity.AfterSaleState != 3 || ceErpTradeResponsible.VerifyState != 0)
- {
- returnErrorMsg("此单售后当前状态不可操作!");
- return;
- }
- entity.AfterSaleSupplierState = st;
- entity.AfterSaleSupplierMemo = afmemo;
- if (st == 1)
- {
- ceErpTradeResponsible.VerifyState = 1;
- ceErpTradeResponsible.VerifyTime = DateTime.Now;
- ceErpTradeResponsible.Update();
- bool isAll = commonHelper.tradeResponsibleAll(entity);
- if (isAll)
- {
- entity.AfterSaleState = 4;
- entity.FinishAfterSaleTime = DateTime.Now;
- if (entity.AfterSaleResSupId > 0)
- {
- entity.AfterSaleSupplierState = 1;
- }
- }
- }
- else
- {
- CeErpTradeResponsible.dateByTid(entity.ctid);
- CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
- if (ceErpTradeAfterSaleExtend != null)
- {
- }
- else
- {
- ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
- ceErpTradeAfterSaleExtend.tid = entity.ctid;
- ceErpTradeAfterSaleExtend.Create();
- }
- entity.AfterSaleState = 2;
- }
- if (entity.AfterSaleState == 4)
- {
- LogHelper.addLog(entity.tid, 0, "彩印通接口完成售后", 0, 3);
- if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
- {
- LogHelper.addDesignerBillLog(entity.tid, 0, "彩印通接口售后取消设计费", "彩印通接口", 1);
- }
- ApiVo apiVo = new ApiVo();
- apiVo.orderNumber = entity.ctid;
- apiVo.actionName = "afterOver";
- designHelper.API_WorkCore(apiVo); //afterOver
- }
- entity.Update();
- returnSuccessMsg("操作成功!");
- CeErpSukuraData.createInfo(entity.ctid, 8);
- LogHelper.addLog(entity.ctid, 0, "彩印通接口供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
- LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "彩印通接口供应商" + (st == 1 ? "认可" : "不认可"), 0, st == 1 ? 0 : 1, afmemo);
- return;
- }
- returnErrorMsg("找不到订单记录");
- }
- public static string API_LogisticsOnlineSend(string orderid, string pCode, string comCode, string out_Sid)
- {
- if (string.IsNullOrWhiteSpace(orderid) || string.IsNullOrWhiteSpace(pCode) || string.IsNullOrWhiteSpace(comCode) || string.IsNullOrWhiteSpace(out_Sid))
- {
- return "参数不完整";
- }
- List<string> postLst = new List<string>();
- var res_obj = new
- {
- refOid = orderid,
- posCode = pCode,
- packages = new[]
- {
- new{ outSid=out_Sid,companyCode=comCode}
- }
- };
- string ro_json = JsonConvert.SerializeObject(res_obj);
- string res = apiHelper.Base_Request(ro_json, "ds.omni.erp.third.order.send");
- return res;
- }
- }
- }
|