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. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  251. string posCode = mainEn.posCode;
  252. string apires = API_LogisticsOnlineSend(tid, posCode, comCode, out_Sid);
  253. CeErpMessageAPI ceErpMessageAPI = new CeErpMessageAPI();
  254. JObject jsonObject = new JObject
  255. {
  256. { "tid", tid},
  257. { "pCode", posCode},
  258. { "comCode", comCode },
  259. { "out_Sid", out_Sid }
  260. };
  261. ceErpMessageAPI.ctid = tid;
  262. ceErpMessageAPI.tid = tid;
  263. ceErpMessageAPI.creationtime = DateTime.Now;
  264. ceErpMessageAPI.content = apires;
  265. ceErpMessageAPI.Create();
  266. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  267. {
  268. try
  269. {
  270. entity.OutSid = curUseWayBillCode;
  271. entity.OrderState = 7;
  272. entity.IsUrgency = false;
  273. entity.LastBillCpCode = "";
  274. entity.LastBillWaybillCode = "";
  275. entity.FinishDeliveryTime = DateTime.Now;
  276. entity.IsReturn = 0;
  277. entity.MemoOpt = 0;
  278. entity.Update();
  279. //还要插入快递信息到 快递信息表
  280. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  281. exinfo.tid = entity.ctid;
  282. exinfo.out_sid = entity.OutSid;
  283. exinfo.company_code = cpCode;
  284. exinfo.company_name = cpCode;
  285. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  286. exinfo.deliveryType = "发货成功";
  287. exinfo.print_time = DateTime.Now;
  288. exinfo.printUser = "彩印通接口";
  289. exinfo.Create();
  290. commonHelper.UpdateRelationOrder(entity.ctid);
  291. CeErpSukuraData.createInfo(entity.ctid, 4);
  292. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  293. }
  294. catch (Exception ex)
  295. {
  296. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  297. }
  298. }
  299. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  300. {
  301. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  302. if (entity.OrderState == 6)
  303. {
  304. entity.OrderState = 7;
  305. }
  306. entity.FinishDeliveryTime = DateTime.Now;
  307. entity.Update();
  308. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  309. exinfo.tid = entity.ctid;
  310. exinfo.out_sid = entity.OutSid;
  311. exinfo.company_code = cpCode;
  312. exinfo.company_name = cpCode;
  313. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  314. exinfo.deliveryType = "发货成功";
  315. exinfo.print_time = DateTime.Now;
  316. exinfo.printUser = "彩印通接口";
  317. exinfo.Create();
  318. commonHelper.UpdateRelationOrder(entity.ctid);
  319. //不处理
  320. }
  321. else
  322. {
  323. entity.LastBillCpCode = cpCode;
  324. entity.LastBillWaybillCode = curUseWayBillCode;
  325. entity.Update();
  326. string errmsg = commonHelper.KeepChinese(apires);
  327. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  328. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  329. }
  330. returnSuccessMsg(apires);
  331. LogHelper.addLog(entity.ctid, 0, "彩印通发货-" + comCode + "-" + out_Sid, entity.OrderState);
  332. return;
  333. }
  334. else
  335. {
  336. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  337. return;
  338. }
  339. return;
  340. }
  341. public void waybill_Api()
  342. {
  343. string tid = GetString("tid");
  344. string cpCode = GetString("cpCode");
  345. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  346. if (entity == null)
  347. {
  348. entity = CeErpTradeCell.GetByCode(tid);
  349. }
  350. if (entity != null)
  351. {
  352. try
  353. {
  354. string[] cpCodeList = cpCode.Split(',');
  355. if (cpCodeList.Length > 1)
  356. {
  357. string newCpCode = "";
  358. //拼多多
  359. if (entity.tid.Contains("-"))
  360. {
  361. if (cpCodeList[0].Contains("PDD") || cpCodeList[0].Contains("pdd"))
  362. {
  363. newCpCode = cpCodeList[0];
  364. }
  365. if (cpCodeList[1].Contains("PDD") || cpCodeList[1].Contains("pdd"))
  366. {
  367. newCpCode = cpCodeList[1];
  368. }
  369. }
  370. else
  371. {
  372. if (!cpCodeList[0].Contains("PDD") && !cpCodeList[0].Contains("pdd"))
  373. {
  374. newCpCode = cpCodeList[0];
  375. }
  376. if (!cpCodeList[1].Contains("PDD") && !cpCodeList[1].Contains("pdd"))
  377. {
  378. newCpCode = cpCodeList[1];
  379. }
  380. }
  381. if (string.IsNullOrEmpty(newCpCode))
  382. {
  383. returnErrorMsg("快递编码错误");
  384. return;
  385. }
  386. cpCode = newCpCode;
  387. }
  388. }
  389. catch (Exception e)
  390. {
  391. XLog.SaveLog(0, "解析快递编码错误" + e);
  392. returnErrorMsg("解析快递编码错误");
  393. return;
  394. }
  395. bool isUseLastWayBillCode = true;
  396. if ((entity.OrderState == 7 || entity.OrderState == 6))
  397. {
  398. isUseLastWayBillCode = false;
  399. }
  400. else
  401. {
  402. returnErrorMsg("订单状态错误无法获取面单");
  403. return;
  404. }
  405. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  406. {
  407. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  408. return;
  409. }
  410. string res = "";
  411. Api_waybill_code_response_Obj fullObj = null;
  412. string pData_str = "";
  413. string curUseWayBillCode = "";
  414. if (isUseLastWayBillCode == false)
  415. {
  416. res = apiHelper.API_GetWaybill(cpCode, tid);
  417. try
  418. {
  419. if (res.IndexOf("failure") != -1)
  420. {
  421. //int idx = res.IndexOf("sub_message");
  422. //int idx2 = res.IndexOf("flag");
  423. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  424. string errMsgNeed = commonHelper.KeepChinese(res);
  425. var res_objd = new
  426. {
  427. restype = 0,
  428. data = "获取面单失败" + errMsgNeed
  429. };
  430. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  431. returnSuccess(ro_jsond);
  432. if (res.IndexOf("停发") != -1)
  433. {
  434. entity.UnusualCon = "物流停发";
  435. entity.Update();
  436. }
  437. //returnErrorMsg("获取面单失败,"+emsg);
  438. XLog.SaveLog(0, "获取面单失败" + res);
  439. return;
  440. }
  441. else if (res.IndexOf("errorMsg") != -1)
  442. {
  443. //int idx = res.IndexOf("errorMsg");
  444. //int idx2 = res.IndexOf("}]}");
  445. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  446. string errMsgNeed = commonHelper.KeepChinese(res);
  447. var res_objf = new
  448. {
  449. restype = 0,
  450. data = "获取面单失败2" + errMsgNeed
  451. };
  452. if (res.IndexOf("停发") != -1)
  453. {
  454. entity.UnusualCon = "物流停发";
  455. entity.Update();
  456. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  457. if (trade != null)
  458. {
  459. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  460. }
  461. }
  462. returnSuccess(res);
  463. //returnErrorMsg("获取面单失败," + emsg);
  464. XLog.SaveLog(0, "获取面单失败2" + res);
  465. return;
  466. }
  467. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  468. //res = res.Replace(" ", "");
  469. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  470. }
  471. catch (Exception ex)
  472. {
  473. XLog.SaveLog(0, "生成fullObj" + res);
  474. var res_objf = new
  475. {
  476. restype = 0,
  477. data = "生成fullObj发生错误" + ex.Message
  478. };
  479. returnSuccess(res);
  480. return;
  481. }
  482. if (fullObj.response.data.content.Count > 0)
  483. {
  484. ContentItem codeObj = fullObj.response.data.content[0];
  485. if (cpCode.IndexOf("SFFQ-") != -1)
  486. {
  487. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  488. }
  489. else
  490. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  491. curUseWayBillCode = codeObj.waybillCode;
  492. LogHelper.addLog(entity.ctid, 0, "彩印通获取面单成功-" + cpCode + "-" + curUseWayBillCode, entity.OrderState);
  493. returnSuccess(pData_str);
  494. return;
  495. }
  496. else
  497. {
  498. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  499. var res_objf = new
  500. {
  501. restype = 0,
  502. data = "生成fullObj找不到快递单号waybillCode"
  503. };
  504. returnSuccess(res);
  505. return;
  506. }
  507. }
  508. else
  509. {
  510. //使用上次打印的快递单号
  511. if (cpCode == "SFFQ-LY")
  512. {
  513. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  514. }
  515. else
  516. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  517. curUseWayBillCode = entity.LastBillWaybillCode;
  518. }
  519. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  520. {
  521. var res_obje = new
  522. {
  523. restype = 0,
  524. data = "获取加密打印数据失败"
  525. };
  526. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  527. returnSuccess(ro_jsone);
  528. entity.LastBillCpCode = cpCode;
  529. entity.LastBillWaybillCode = curUseWayBillCode;
  530. entity.Update();
  531. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  532. //returnErrorMsg("获取加密打印数据失败");
  533. return;
  534. }
  535. }
  536. else
  537. {
  538. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  539. return;
  540. }
  541. return;
  542. }
  543. //http://47.114.150.226:88/Handler/apiCaiYingTong.ashx?t=afterCytSale ctid status supmemo
  544. public void afterCytSale()
  545. {
  546. string ctid = GetString("ctid");
  547. int st = GetInt("status");
  548. string afmemo = GetString("supmemo");
  549. string id = "0";
  550. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  551. if (entity == null)
  552. {
  553. entity = CeErpTradeCell.GetByCode(ctid);
  554. if (entity == null)
  555. {
  556. returnErrorMsg("找不到订单记录");
  557. return;
  558. }
  559. }
  560. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 64, 1, 0);
  561. if (ceErpTradeResponsible == null)
  562. {
  563. ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 80, 1, 0);
  564. }
  565. if (ceErpTradeResponsible == null)
  566. {
  567. ceErpTradeResponsible = CeErpTradeResponsible.GetByUserId(entity.ctid, 126, 1, 0);
  568. }
  569. if (ceErpTradeResponsible != null)
  570. {
  571. id = ceErpTradeResponsible.ID.ToString();
  572. if (ceErpTradeResponsible.VerifyState == 1)
  573. {
  574. returnErrorMsg("已超时自动认可");
  575. return;
  576. }
  577. }
  578. if (entity != null && ceErpTradeResponsible != null)
  579. {
  580. if (entity.AfterSaleState != 3 || ceErpTradeResponsible.VerifyState != 0)
  581. {
  582. returnErrorMsg("此单售后当前状态不可操作!");
  583. return;
  584. }
  585. entity.AfterSaleSupplierState = st;
  586. entity.AfterSaleSupplierMemo = afmemo;
  587. if (st == 1)
  588. {
  589. ceErpTradeResponsible.VerifyState = 1;
  590. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  591. ceErpTradeResponsible.Update();
  592. bool isAll = commonHelper.tradeResponsibleAll(entity);
  593. if (isAll)
  594. {
  595. entity.AfterSaleState = 4;
  596. entity.AfterSaleSupplierState = 1;
  597. }
  598. }
  599. else
  600. {
  601. CeErpTradeResponsible.dateByTid(entity.ctid);
  602. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('彩印通接口供应商不认可')", ceErpTradeResponsible.tid);
  603. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  604. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  605. if (num <= 1)
  606. {
  607. entity.AfterSaleState = 1;
  608. }
  609. else
  610. {
  611. entity.AfterSaleState = 5;
  612. }
  613. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  614. if (ceErpTradeAfterSaleExtend != null)
  615. {
  616. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  617. ceErpTradeAfterSaleExtend.Update();
  618. }
  619. else
  620. {
  621. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  622. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  623. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  624. ceErpTradeAfterSaleExtend.Create();
  625. }
  626. }
  627. if (entity.AfterSaleState == 4)
  628. {
  629. LogHelper.addLog(entity.tid, 0, "彩印通接口完成售后", 0, 3);
  630. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  631. {
  632. LogHelper.addDesignerBillLog(entity.tid, 0, "彩印通接口售后取消设计费", "彩印通接口", 1);
  633. }
  634. ApiVo apiVo = new ApiVo();
  635. apiVo.orderNumber = entity.ctid;
  636. apiVo.actionName = "afterOver";
  637. designHelper.API_WorkCore(apiVo); //afterOver
  638. }
  639. entity.Update();
  640. returnSuccessMsg("操作成功!");
  641. CeErpSukuraData.createInfo(entity.ctid, 8);
  642. LogHelper.addLog(entity.ctid, 0, "彩印通接口供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  643. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "彩印通接口供应商" + (st == 1 ? "认可" : "不认可"), 0, st == 1 ? 0 : 1, afmemo);
  644. return;
  645. }
  646. returnErrorMsg("找不到订单记录");
  647. }
  648. //http://47.114.150.226:88/Handler/apiCaiYingTong.ashx?t=getMergeOrders orderSn
  649. public void getMergeOrders()
  650. {
  651. string orderSn = GetString("orderSn");
  652. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(orderSn);
  653. if (ceErpTradeCell == null)
  654. {
  655. ceErpTradeCell = CeErpTradeCell.GetByCtid(orderSn);
  656. }
  657. if (ceErpTradeCell == null)
  658. {
  659. returnErrorMsg("查无订单!");
  660. return;
  661. }
  662. if (ceErpTradeCell.SupplierId != 64 && ceErpTradeCell.SupplierId != 80 && ceErpTradeCell.SupplierId != 126)
  663. {
  664. returnErrorMsg("查无订单!");
  665. return;
  666. }
  667. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  668. DataTable dt = commonHelper.getSameOrderList(ceErpTradeCell, ceErpTrade);
  669. if (dt != null && dt.Rows.Count > 1)
  670. {
  671. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  672. return;
  673. }
  674. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  675. return;
  676. }
  677. public static string API_LogisticsOnlineSend(string orderid, string pCode, string comCode, string out_Sid)
  678. {
  679. if (string.IsNullOrWhiteSpace(orderid) || string.IsNullOrWhiteSpace(pCode) || string.IsNullOrWhiteSpace(comCode) || string.IsNullOrWhiteSpace(out_Sid))
  680. {
  681. return "参数不完整";
  682. }
  683. List<string> postLst = new List<string>();
  684. var res_obj = new
  685. {
  686. refOid = orderid,
  687. posCode = pCode,
  688. packages = new[]
  689. {
  690. new{ outSid=out_Sid,companyCode=comCode}
  691. }
  692. };
  693. string ro_json = JsonConvert.SerializeObject(res_obj);
  694. string res = apiHelper.Base_Request(ro_json, "ds.omni.erp.third.order.send");
  695. return res;
  696. }
  697. }
  698. }