apiCaiYingTong.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Cfg.MappingSchema;
  5. using NPOI.OpenXmlFormats.Shared;
  6. using NPOI.SS.Formula.Functions;
  7. using SiteCore.taoObj;
  8. using SQLData;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Reflection;
  16. using System.Reflection.Emit;
  17. using System.Security.Cryptography;
  18. using System.Text;
  19. using System.Web;
  20. using Utils;
  21. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  22. using static SiteCore.taoObj.work_core_vo;
  23. namespace SiteCore.Handler
  24. {
  25. public class apiCaiYingTong : BaseHandler, IHttpHandler
  26. {
  27. public void ProcessRequest(HttpContext context)
  28. {
  29. if (UrlParmsCheck("t"))
  30. {
  31. String tname = GetString("t");
  32. MethodInfo method;
  33. Type type = this.GetType();
  34. method = type.GetMethod(tname);
  35. con = context;
  36. if (method == null)
  37. {
  38. conError("找不到对应方法,服务器返回错误");
  39. return;
  40. }
  41. successFlag = false;
  42. context.Response.ContentType = "application/json";
  43. context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
  44. try
  45. {
  46. method.Invoke(this, null);
  47. }
  48. catch (Exception ex)
  49. {
  50. XLog.SaveLog(0, "彩印通接口错:" + ex);
  51. conError("处理接口错误,服务器返回错误");
  52. }
  53. finally
  54. {
  55. //AfterInvoke(methodName);
  56. }
  57. //if (!successFlag) returnErrorMsg("服务器返回错误");
  58. }
  59. }
  60. static string appID = "1823193185001";
  61. //***************************************************
  62. //static string signkey = "fed5be35cf5bd04b14dcfff984f861dd";
  63. static HttpHelper tb_http = new HttpHelper();
  64. static string merSecret = "D8FF9498A5A2E6A6B4CB6EF88DB1DC35";
  65. static string pUrl = "https://front.lingtao8.com/designRest.htm";
  66. //static string pUrl = "https://localhost:8999/designRest.htm";
  67. //static string pUrl = "http://yi.yhmwacg.cn/designRest.htm";
  68. public static int DateTimeToUnixTime(DateTime dateTime)
  69. {
  70. return (int)(dateTime - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
  71. }
  72. //public static string ToUrlParams(object jsonObject)
  73. //{
  74. // var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); // 遍历JSON对象的属性,并添加到查询字符串中
  75. // foreach (var property in jsonObject.GetType().GetProperties())
  76. // {
  77. // queryString[property.Name] = property.GetValue(jsonObject)?.ToString() ?? string.Empty;
  78. // }
  79. // return queryString.ToString();
  80. //}
  81. public static Dictionary<string, object> ToDictionary(object obj)
  82. {
  83. var type = obj.GetType();
  84. var properties = type.GetProperties();
  85. var dictionary = new Dictionary<string, object>();
  86. foreach (var property in properties)
  87. {
  88. var value = property.GetValue(obj);
  89. dictionary.Add(property.Name, value);
  90. }
  91. return dictionary;
  92. }
  93. public static string ToUrlParams(Dictionary<string, object> jsonObject)
  94. {
  95. var queryString = new System.Collections.Specialized.NameValueCollection();
  96. // 遍历JSON对象的属性,并添加到查询字符串中
  97. foreach (var property in jsonObject)
  98. {
  99. var value = property.Value;
  100. if (value != null)
  101. {
  102. // 如果属性值不为null,则添加到查询字符串中
  103. if (value is System.Collections.IEnumerable && !(value is string))
  104. {
  105. // 如果是数组或集合类型,需要进一步处理
  106. var index = 0;
  107. foreach (var item in (System.Collections.IEnumerable)value)
  108. {
  109. queryString.Add(property.Key + "[" + index + "]", item != null ? item.ToString() : string.Empty);
  110. index++;
  111. }
  112. }
  113. else
  114. {
  115. // 普通属性
  116. queryString.Add(property.Key, value.ToString());
  117. }
  118. }
  119. }
  120. // 获取最终的查询字符串
  121. return string.Join("&", queryString.AllKeys.Select(key => key + "=" + queryString[key]));
  122. }
  123. public static string createSignCode(string method, string timeStr, string design_app_id, string design_secret)
  124. {
  125. byte[] use_bytes;
  126. //query.Append(secret);
  127. //预留看一下到时候签名怎么用md5加密;***************************************************
  128. string encryStr = design_secret + method + timeStr + design_app_id + design_secret;
  129. MD5 md5 = MD5.Create();
  130. use_bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(encryStr));
  131. StringBuilder result = new StringBuilder();
  132. for (int i = 0; i < use_bytes.Length; i++)
  133. {
  134. result.Append(use_bytes[i].ToString("x2"));
  135. }
  136. string singResult = result.ToString();
  137. return singResult.Replace("-", "");
  138. //return bytes.ToString();
  139. }
  140. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=DesignSys_AddLog post请求参数(参数放body中):string tid(淘宝订单号)string userName(操作用户)string con(日志内容)int orderState(订单状态)
  141. public void DesignSys_AddLog()
  142. {
  143. if (UrlPostParmsCheck("tid"))
  144. {
  145. try
  146. {
  147. //HttpContext.Current.Request.BinaryRead()
  148. string tid = GetPostString("tid");
  149. string userName = GetPostString("userName");
  150. int orderState = GetPostInt("orderState");
  151. string con = GetPostString("con");
  152. //returnErrorMsg(tid + "," + userName + "," + orderState + "," + con);
  153. //return;
  154. try
  155. {
  156. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  157. if (ceErpTradeCell != null)
  158. {
  159. if (userName != "")
  160. {
  161. CeErpUser ceErpUser = CeErpUser.GetByUserName(userName);
  162. if (ceErpUser != null)
  163. {
  164. LogHelper.addLog(tid, ceErpUser.ID, con, orderState);
  165. return;
  166. }
  167. else
  168. {
  169. returnErrorMsg("找不到对应用户");
  170. return;
  171. }
  172. }
  173. returnErrorMsg("找不到对应用户");
  174. }
  175. else
  176. {
  177. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  178. }
  179. }
  180. catch (Exception ex)
  181. {
  182. XLog.SaveLog(0, "xxxxx," + ex.Message);
  183. }
  184. }
  185. catch (Exception ex)
  186. {
  187. XLog.SaveLog(0, ex.Message);
  188. }
  189. return;
  190. }
  191. returnErrorMsg("缺少必要的参数");
  192. }
  193. public void shipments_Api()
  194. {
  195. string tid = GetString("tid");
  196. string comCode = GetString("comCode");
  197. string out_Sid = GetString("out_Sid");
  198. string curUseWayBillCode = out_Sid;
  199. string cpCode = comCode;
  200. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  201. if (entity == null)
  202. {
  203. entity = CeErpTradeCell.GetByCode(tid);
  204. }
  205. if (entity != null)
  206. {
  207. try
  208. {
  209. string[] cpCodeList = cpCode.Split(',');
  210. if (cpCodeList.Length > 1)
  211. {
  212. string newCpCode = "";
  213. //拼多多
  214. if (entity.tid.Contains("-"))
  215. {
  216. if (cpCodeList[0].Contains("PDD") || cpCodeList[0].Contains("pdd"))
  217. {
  218. newCpCode = cpCodeList[0];
  219. }
  220. if (cpCodeList[1].Contains("PDD") || cpCodeList[1].Contains("pdd"))
  221. {
  222. newCpCode = cpCodeList[1];
  223. }
  224. }
  225. else
  226. {
  227. if (!cpCodeList[0].Contains("PDD") && !cpCodeList[0].Contains("pdd"))
  228. {
  229. newCpCode = cpCodeList[0];
  230. }
  231. if (!cpCodeList[1].Contains("PDD") && !cpCodeList[1].Contains("pdd"))
  232. {
  233. newCpCode = cpCodeList[1];
  234. }
  235. }
  236. if (string.IsNullOrEmpty(newCpCode))
  237. {
  238. returnErrorMsg("快递编码错误");
  239. return;
  240. }
  241. cpCode = newCpCode;
  242. }
  243. }
  244. catch (Exception e)
  245. {
  246. XLog.SaveLog(0, "解析快递编码错误" + e);
  247. returnErrorMsg("解析快递编码错误");
  248. return;
  249. }
  250. comCode = cpCode;
  251. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  252. string posCode = mainEn.posCode;
  253. string apires = API_LogisticsOnlineSend(entity.tid, posCode, comCode, out_Sid);
  254. CeErpMessageAPI ceErpMessageAPI = new CeErpMessageAPI();
  255. JObject jsonObject = new JObject
  256. {
  257. { "tid", tid},
  258. { "pCode", posCode},
  259. { "comCode", comCode },
  260. { "out_Sid", out_Sid }
  261. };
  262. ceErpMessageAPI.ctid = entity.ctid;
  263. ceErpMessageAPI.tid = entity.tid;
  264. ceErpMessageAPI.creationtime = DateTime.Now;
  265. ceErpMessageAPI.content = apires;
  266. ceErpMessageAPI.Create();
  267. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  268. {
  269. try
  270. {
  271. entity.OutSid = curUseWayBillCode;
  272. entity.OrderState = 7;
  273. entity.IsUrgency = false;
  274. entity.LastBillCpCode = "";
  275. entity.LastBillWaybillCode = "";
  276. entity.FinishDeliveryTime = DateTime.Now;
  277. entity.IsReturn = 0;
  278. entity.MemoOpt = 0;
  279. entity.Update();
  280. //还要插入快递信息到 快递信息表
  281. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  282. exinfo.tid = entity.ctid;
  283. exinfo.out_sid = entity.OutSid;
  284. exinfo.company_code = cpCode;
  285. exinfo.company_name = cpCode;
  286. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  287. exinfo.deliveryType = "发货成功";
  288. exinfo.print_time = DateTime.Now;
  289. exinfo.printUser = "彩印通接口";
  290. exinfo.Create();
  291. commonHelper.UpdateRelationOrder(entity.ctid);
  292. CeErpSukuraData.createInfo(entity.ctid, 4);
  293. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  294. }
  295. catch (Exception ex)
  296. {
  297. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  298. }
  299. }
  300. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  301. {
  302. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  303. if (entity.OrderState == 6)
  304. {
  305. entity.OrderState = 7;
  306. }
  307. entity.FinishDeliveryTime = DateTime.Now;
  308. entity.Update();
  309. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  310. exinfo.tid = entity.ctid;
  311. exinfo.out_sid = entity.OutSid;
  312. exinfo.company_code = cpCode;
  313. exinfo.company_name = cpCode;
  314. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  315. exinfo.deliveryType = "发货成功";
  316. exinfo.print_time = DateTime.Now;
  317. exinfo.printUser = "彩印通接口";
  318. exinfo.Create();
  319. commonHelper.UpdateRelationOrder(entity.ctid);
  320. //不处理
  321. }
  322. else
  323. {
  324. entity.LastBillCpCode = cpCode;
  325. entity.LastBillWaybillCode = curUseWayBillCode;
  326. entity.Update();
  327. string errmsg = commonHelper.KeepChinese(apires);
  328. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  329. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  330. }
  331. returnSuccessMsg(apires);
  332. LogHelper.addLog(entity.ctid, 0, "彩印通发货-" + comCode + "-" + out_Sid, entity.OrderState);
  333. return;
  334. }
  335. else
  336. {
  337. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  338. return;
  339. }
  340. return;
  341. }
  342. public void waybill_Api()
  343. {
  344. string tid = GetString("tid");
  345. string cpCode = GetString("cpCode");
  346. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  347. if (entity == null)
  348. {
  349. entity = CeErpTradeCell.GetByCode(tid);
  350. }
  351. if (entity != null)
  352. {
  353. try
  354. {
  355. string[] cpCodeList = cpCode.Split(',');
  356. if (cpCodeList.Length > 1)
  357. {
  358. string newCpCode = "";
  359. //拼多多
  360. if (entity.tid.Contains("-"))
  361. {
  362. if (cpCodeList[0].Contains("PDD") || cpCodeList[0].Contains("pdd"))
  363. {
  364. newCpCode = cpCodeList[0];
  365. }
  366. if (cpCodeList[1].Contains("PDD") || cpCodeList[1].Contains("pdd"))
  367. {
  368. newCpCode = cpCodeList[1];
  369. }
  370. }
  371. else
  372. {
  373. if (!cpCodeList[0].Contains("PDD") && !cpCodeList[0].Contains("pdd"))
  374. {
  375. newCpCode = cpCodeList[0];
  376. }
  377. if (!cpCodeList[1].Contains("PDD") && !cpCodeList[1].Contains("pdd"))
  378. {
  379. newCpCode = cpCodeList[1];
  380. }
  381. }
  382. if (string.IsNullOrEmpty(newCpCode))
  383. {
  384. returnErrorMsg("快递编码错误");
  385. return;
  386. }
  387. cpCode = newCpCode;
  388. }
  389. }
  390. catch (Exception e)
  391. {
  392. XLog.SaveLog(0, "解析快递编码错误" + e);
  393. returnErrorMsg("解析快递编码错误");
  394. return;
  395. }
  396. bool isUseLastWayBillCode = true;
  397. if ((entity.OrderState == 7 || entity.OrderState == 6))
  398. {
  399. isUseLastWayBillCode = false;
  400. }
  401. else
  402. {
  403. returnErrorMsg("订单状态错误无法获取面单");
  404. return;
  405. }
  406. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  407. {
  408. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  409. return;
  410. }
  411. string res = "";
  412. Api_waybill_code_response_Obj fullObj = null;
  413. string pData_str = "";
  414. string curUseWayBillCode = "";
  415. if (isUseLastWayBillCode == false)
  416. {
  417. res = apiHelper.API_GetWaybill(cpCode, entity.ctid);
  418. try
  419. {
  420. if (res.IndexOf("failure") != -1)
  421. {
  422. //int idx = res.IndexOf("sub_message");
  423. //int idx2 = res.IndexOf("flag");
  424. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  425. string errMsgNeed = commonHelper.KeepChinese(res);
  426. var res_objd = new
  427. {
  428. restype = 0,
  429. data = "获取面单失败" + errMsgNeed
  430. };
  431. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  432. returnSuccess(ro_jsond);
  433. if (res.IndexOf("停发") != -1)
  434. {
  435. entity.UnusualCon = "物流停发";
  436. entity.Update();
  437. }
  438. //returnErrorMsg("获取面单失败,"+emsg);
  439. XLog.SaveLog(0, "获取面单失败" + res);
  440. return;
  441. }
  442. else if (res.IndexOf("errorMsg") != -1)
  443. {
  444. //int idx = res.IndexOf("errorMsg");
  445. //int idx2 = res.IndexOf("}]}");
  446. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  447. string errMsgNeed = commonHelper.KeepChinese(res);
  448. var res_objf = new
  449. {
  450. restype = 0,
  451. data = "获取面单失败2" + errMsgNeed
  452. };
  453. if (res.IndexOf("停发") != -1)
  454. {
  455. entity.UnusualCon = "物流停发";
  456. entity.Update();
  457. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  458. if (trade != null)
  459. {
  460. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  461. }
  462. }
  463. returnSuccess(res);
  464. //returnErrorMsg("获取面单失败," + emsg);
  465. XLog.SaveLog(0, "获取面单失败2" + res);
  466. return;
  467. }
  468. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  469. //res = res.Replace(" ", "");
  470. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  471. }
  472. catch (Exception ex)
  473. {
  474. XLog.SaveLog(0, "生成fullObj" + res);
  475. var res_objf = new
  476. {
  477. restype = 0,
  478. data = "生成fullObj发生错误" + ex.Message
  479. };
  480. returnSuccess(res);
  481. return;
  482. }
  483. if (fullObj != null && fullObj.response.data.content.Count > 0)
  484. {
  485. ContentItem codeObj = fullObj.response.data.content[0];
  486. if (cpCode.IndexOf("SFFQ-") != -1)
  487. {
  488. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  489. }
  490. else
  491. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  492. curUseWayBillCode = codeObj.waybillCode;
  493. LogHelper.addLog(entity.ctid, 0, "彩印通获取面单成功-" + cpCode + "-" + curUseWayBillCode, entity.OrderState);
  494. returnSuccess(pData_str);
  495. return;
  496. }
  497. else
  498. {
  499. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  500. var res_objf = new
  501. {
  502. restype = 0,
  503. data = "生成fullObj找不到快递单号waybillCode"
  504. };
  505. returnSuccess(res);
  506. return;
  507. }
  508. }
  509. else
  510. {
  511. //使用上次打印的快递单号
  512. if (cpCode == "SFFQ-LY")
  513. {
  514. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  515. }
  516. else
  517. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  518. curUseWayBillCode = entity.LastBillWaybillCode;
  519. }
  520. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  521. {
  522. var res_obje = new
  523. {
  524. restype = 0,
  525. data = "获取加密打印数据失败"
  526. };
  527. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  528. returnSuccess(ro_jsone);
  529. entity.LastBillCpCode = cpCode;
  530. entity.LastBillWaybillCode = curUseWayBillCode;
  531. entity.Update();
  532. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  533. //returnErrorMsg("获取加密打印数据失败");
  534. return;
  535. }
  536. }
  537. else
  538. {
  539. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  540. return;
  541. }
  542. return;
  543. }
  544. //http://47.114.150.226:88/Handler/apiCaiYingTong.ashx?t=afterCytSale ctid status supmemo
  545. public void afterCytSale()
  546. {
  547. string ctid = GetString("ctid");
  548. int st = GetInt("status");
  549. string afmemo = GetString("supmemo");
  550. string id = "0";
  551. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  552. if (entity == null)
  553. {
  554. entity = CeErpTradeCell.GetByCode(ctid);
  555. if (entity == null)
  556. {
  557. returnErrorMsg("找不到订单记录");
  558. return;
  559. }
  560. }
  561. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 64, 1, 0);
  562. if (ceErpTradeResponsible == null)
  563. {
  564. ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 80, 1, 0);
  565. }
  566. if (ceErpTradeResponsible == null)
  567. {
  568. ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 126, 1, 0);
  569. }
  570. if (ceErpTradeResponsible != null)
  571. {
  572. id = ceErpTradeResponsible.ID.ToString();
  573. if (ceErpTradeResponsible.VerifyState == 1)
  574. {
  575. returnErrorMsg("已超时自动认可");
  576. return;
  577. }
  578. }
  579. if (entity != null && ceErpTradeResponsible != null)
  580. {
  581. if (entity.AfterSaleState != 3 || ceErpTradeResponsible.VerifyState != 0)
  582. {
  583. returnErrorMsg("此单售后当前状态不可操作!");
  584. return;
  585. }
  586. entity.AfterSaleSupplierState = st;
  587. entity.AfterSaleSupplierMemo = afmemo;
  588. if (st == 1)
  589. {
  590. ceErpTradeResponsible.VerifyState = 1;
  591. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  592. ceErpTradeResponsible.Update();
  593. bool isAll = commonHelper.tradeResponsibleAll(entity);
  594. if (isAll)
  595. {
  596. entity.AfterSaleState = 4;
  597. entity.AfterSaleSupplierState = 1;
  598. }
  599. }
  600. else
  601. {
  602. CeErpTradeResponsible.dateByTid(entity.ctid);
  603. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('彩印通接口供应商不认可')", ceErpTradeResponsible.tid);
  604. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  605. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  606. if (num <= 1)
  607. {
  608. entity.AfterSaleState = 1;
  609. }
  610. else
  611. {
  612. entity.AfterSaleState = 5;
  613. }
  614. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  615. if (ceErpTradeAfterSaleExtend != null)
  616. {
  617. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  618. ceErpTradeAfterSaleExtend.Update();
  619. }
  620. else
  621. {
  622. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  623. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  624. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  625. ceErpTradeAfterSaleExtend.Create();
  626. }
  627. }
  628. if (entity.AfterSaleState == 4)
  629. {
  630. LogHelper.addLog(entity.tid, 0, "彩印通接口完成售后", 0, 3);
  631. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  632. {
  633. LogHelper.addDesignerBillLog(entity.tid, 0, "彩印通接口售后取消设计费", "彩印通接口", 1);
  634. }
  635. ApiVo apiVo = new ApiVo();
  636. apiVo.orderNumber = entity.ctid;
  637. apiVo.actionName = "afterOver";
  638. designHelper.API_WorkCore(apiVo); //afterOver
  639. }
  640. entity.Update();
  641. returnSuccessMsg("操作成功!");
  642. CeErpSukuraData.createInfo(entity.ctid, 8);
  643. LogHelper.addLog(entity.ctid, 0, "彩印通接口供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  644. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "彩印通接口供应商" + (st == 1 ? "认可" : "不认可"), 0, st == 1 ? 0 : 1, afmemo);
  645. return;
  646. }
  647. returnErrorMsg("找不到订单记录");
  648. }
  649. //http://47.114.150.226:88/Handler/apiCaiYingTong.ashx?t=getMergeOrders orderSn
  650. public void getMergeOrders()
  651. {
  652. string orderSn = GetString("orderSn");
  653. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(orderSn);
  654. if (ceErpTradeCell == null)
  655. {
  656. ceErpTradeCell = CeErpTradeCell.GetByCtid(orderSn);
  657. }
  658. if (ceErpTradeCell == null)
  659. {
  660. returnErrorMsg("查无订单!");
  661. return;
  662. }
  663. if (ceErpTradeCell.SupplierId != 64 && ceErpTradeCell.SupplierId != 80 && ceErpTradeCell.SupplierId != 126)
  664. {
  665. returnErrorMsg("查无订单!");
  666. return;
  667. }
  668. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  669. DataTable dt = commonHelper.getSameOrderList(ceErpTradeCell, ceErpTrade);
  670. if (dt != null && dt.Rows.Count > 1)
  671. {
  672. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  673. return;
  674. }
  675. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  676. return;
  677. }
  678. public static string API_LogisticsOnlineSend(string orderid, string pCode, string comCode, string out_Sid)
  679. {
  680. if (string.IsNullOrWhiteSpace(orderid) || string.IsNullOrWhiteSpace(pCode) || string.IsNullOrWhiteSpace(comCode) || string.IsNullOrWhiteSpace(out_Sid))
  681. {
  682. return "参数不完整";
  683. }
  684. List<string> postLst = new List<string>();
  685. var res_obj = new
  686. {
  687. refOid = orderid,
  688. posCode = pCode,
  689. packages = new[]
  690. {
  691. new{ outSid=out_Sid,companyCode=comCode}
  692. }
  693. };
  694. string ro_json = JsonConvert.SerializeObject(res_obj);
  695. string res = apiHelper.Base_Request(ro_json, "ds.omni.erp.third.order.send");
  696. return res;
  697. }
  698. }
  699. }