apiDesign.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using SiteCore.taobao;
  4. using SQLData;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Reflection;
  11. using System.Security.Cryptography;
  12. using System.Text;
  13. using System.Web;
  14. using Utils;
  15. using static SiteCore.taoObj.work_core_vo;
  16. namespace SiteCore.Handler
  17. {
  18. public class apiDesign : BaseHandler, IHttpHandler
  19. {
  20. public void ProcessRequest(HttpContext context)
  21. {
  22. if (UrlParmsCheck("t"))
  23. {
  24. String tname = GetString("t");
  25. MethodInfo method;
  26. Type type = this.GetType();
  27. method = type.GetMethod(tname);
  28. con = context;
  29. if (method == null)
  30. {
  31. conError("找不到对应方法,服务器返回错误");
  32. return;
  33. }
  34. successFlag = false;
  35. context.Response.ContentType = "application/json";
  36. context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
  37. try
  38. {
  39. method.Invoke(this, null);
  40. }
  41. catch (Exception ex)
  42. {
  43. conError("处理接口错误,服务器返回错误");
  44. }
  45. finally
  46. {
  47. //AfterInvoke(methodName);
  48. }
  49. //if (!successFlag) returnErrorMsg("服务器返回错误");
  50. }
  51. }
  52. static string appID = "1823193185001";
  53. //***************************************************
  54. //static string signkey = "fed5be35cf5bd04b14dcfff984f861dd";
  55. static HttpHelper tb_http = new HttpHelper();
  56. static string merSecret = "D8FF9498A5A2E6A6B4CB6EF88DB1DC35";
  57. static string pUrl = "https://front.lingtao8.com/designRest.htm";
  58. //static string pUrl = "http://localhost:8999/designRest.htm";
  59. //static string pUrl = "http://yi.yhmwacg.cn/designRest.htm";
  60. public static int DateTimeToUnixTime(DateTime dateTime)
  61. {
  62. return (int)(dateTime - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1))).TotalSeconds;
  63. }
  64. //public static string ToUrlParams(object jsonObject)
  65. //{
  66. // var queryString = System.Web.HttpUtility.ParseQueryString(string.Empty); // 遍历JSON对象的属性,并添加到查询字符串中
  67. // foreach (var property in jsonObject.GetType().GetProperties())
  68. // {
  69. // queryString[property.Name] = property.GetValue(jsonObject)?.ToString() ?? string.Empty;
  70. // }
  71. // return queryString.ToString();
  72. //}
  73. public static Dictionary<string, object> ToDictionary(object obj)
  74. {
  75. var type = obj.GetType();
  76. var properties = type.GetProperties();
  77. var dictionary = new Dictionary<string, object>();
  78. foreach (var property in properties)
  79. {
  80. var value = property.GetValue(obj);
  81. dictionary.Add(property.Name, value);
  82. }
  83. return dictionary;
  84. }
  85. public static string ToUrlParams(Dictionary<string, object> jsonObject)
  86. {
  87. var queryString = new System.Collections.Specialized.NameValueCollection();
  88. // 遍历JSON对象的属性,并添加到查询字符串中
  89. foreach (var property in jsonObject)
  90. {
  91. var value = property.Value;
  92. if (value != null)
  93. {
  94. // 如果属性值不为null,则添加到查询字符串中
  95. if (value is System.Collections.IEnumerable && !(value is string))
  96. {
  97. // 如果是数组或集合类型,需要进一步处理
  98. var index = 0;
  99. foreach (var item in (System.Collections.IEnumerable)value)
  100. {
  101. queryString.Add(property.Key + "[" + index + "]", item != null ? item.ToString() : string.Empty);
  102. index++;
  103. }
  104. }
  105. else
  106. {
  107. // 普通属性
  108. queryString.Add(property.Key, value.ToString());
  109. }
  110. }
  111. }
  112. // 获取最终的查询字符串
  113. return string.Join("&", queryString.AllKeys.Select(key => key + "=" + queryString[key]));
  114. }
  115. public static string createSignCode(string method, string timeStr, string design_app_id, string design_secret)
  116. {
  117. byte[] use_bytes;
  118. //query.Append(secret);
  119. //预留看一下到时候签名怎么用md5加密;***************************************************
  120. string encryStr = design_secret + method + timeStr + design_app_id + design_secret;
  121. MD5 md5 = MD5.Create();
  122. use_bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(encryStr));
  123. StringBuilder result = new StringBuilder();
  124. for (int i = 0; i < use_bytes.Length; i++)
  125. {
  126. result.Append(use_bytes[i].ToString("x2"));
  127. }
  128. string singResult = result.ToString();
  129. return singResult.Replace("-", "");
  130. //return bytes.ToString();
  131. }
  132. public static string API_GetPrintData_CreateOrder(CeErpTradeCell ceErpTradeCell)
  133. {
  134. if (ceErpTradeCell.IsSample == 2)
  135. {
  136. return "补差价订单不需要过设计系统";
  137. }
  138. CeErpOrderFormData formData = null;
  139. formData = CeErpOrderFormData.GetByTid(ceErpTradeCell.ctid.ToString());
  140. if (formData == null)
  141. {
  142. /* CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
  143. ceErpMessageTip.tid = ceErpTradeCell.ctid;
  144. ceErpMessageTip.type = 2;
  145. ceErpMessageTip.userId = ceErpTradeCell.CustomerUserId;
  146. ceErpMessageTip.isVisit = false;
  147. ceErpMessageTip.content = "订单:" + ceErpTradeCell.ctid + "备注手机号或者微信号未填写!无法指派到设计系统!!请立马备注!!";
  148. ceErpMessageTip.Create();*/
  149. //return "请填写订单的手机号或者微信号才可指派到设计系统";
  150. }
  151. //json参数
  152. List<string> postLst = new List<string>();
  153. Boolean isOldCustomerText = false;
  154. Boolean isReturn = false;
  155. Boolean isGai = false;
  156. if (ceErpTradeCell.IsOldCustomer == 1)
  157. {
  158. isOldCustomerText = true;
  159. }
  160. if (ceErpTradeCell.IsReturn > 0)
  161. {
  162. isReturn = true;
  163. }
  164. if (ceErpTradeCell.MemoOpt == 1)
  165. {
  166. isGai = true;
  167. }
  168. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  169. CeErpShop ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId);
  170. string design_app_id = ceErpShop.design_app_id;
  171. string design_secret = ceErpShop.design_secret;
  172. if (design_app_id == null || design_app_id == "")
  173. {
  174. design_app_id = appID;
  175. }
  176. if (design_secret == null || design_secret == "")
  177. {
  178. design_secret = merSecret;
  179. }
  180. string method = "design.order.create";
  181. string timeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  182. string sign = createSignCode(method, timeStr, design_app_id, design_secret);
  183. var res_obj = new
  184. {
  185. sign = sign,
  186. method = method,
  187. merchantId = design_app_id,
  188. appKey = design_app_id,
  189. outId = ceErpTradeCell.ID,
  190. designType = ceErpTradeCell.ProductId,
  191. draftType = 2,
  192. designPage = 1,
  193. afterNames = "null",
  194. printSpecial = "null",
  195. designWidth = 0,
  196. designHeight = 0,
  197. printKs = 1,
  198. printMs = 1,
  199. printWidth = 0,
  200. printHeight = 0,
  201. amount = ceErpTradeCell.payment,
  202. isUrgent = ceErpTradeCell.IsUrgency,
  203. userContact = ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao",
  204. userMobile = "null",
  205. userQq = "null",
  206. userWx = "null",
  207. userText = "null",
  208. userNotice = "null",
  209. servicesMessage = ceErpTradeCell.CustomerMemo,
  210. shopNick = ceErpShop.ShopName,
  211. buyerNick = ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao",
  212. apiFiles = new Array[1],
  213. receiverName = ceErpTrade.receiver_name,
  214. receiverMobile = ceErpTrade.receiver_mobile,
  215. receiverState = ceErpTrade.receiver_state,
  216. receiverCity = ceErpTrade.receiver_city,
  217. receiverDistrict = ceErpTrade.receiver_district,
  218. receiverAddress = ceErpTrade.receiver_address,
  219. expressCode = "null",
  220. creater = "null",
  221. orderSrc = "0",
  222. tids = ceErpTradeCell.ctid,
  223. isOnlyDesign = "false",
  224. isOldUser = isOldCustomerText,
  225. orderText = ceErpTradeCell.seller_memo,
  226. isChange = isGai,
  227. isBack = isReturn,
  228. tid = ceErpTradeCell.tid
  229. };
  230. string ro_json = JsonConvert.SerializeObject(res_obj);
  231. ro_json = ro_json.Replace("{", "");
  232. ro_json = ro_json.Replace("}", "");
  233. ro_json = ro_json.Replace("\"", "");
  234. ro_json = ro_json.Replace(",", "&");
  235. ro_json = ro_json.Replace(":", "=");
  236. ro_json = ro_json.Replace("+", "%2B");
  237. ro_json += "&timestamp=" + timeStr;
  238. //;***************************************************
  239. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  240. //Dictionary<string, object> dataDic = ToDictionary(ro_json);
  241. //string urlData = ToUrlParams(dataDic);
  242. string sql_pay = "INSERT INTO CE_ErpToDesignLog (ctid, ctime) VALUES ('" + ceErpTradeCell.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');";
  243. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  244. HttpItem item = new HttpItem()
  245. {
  246. URL = pUrl,
  247. Method = "POST",
  248. ContentType = "application/x-www-form-urlencoded",
  249. Postdata = ro_json
  250. };
  251. item.PostEncoding = Encoding.UTF8;
  252. HttpResult hResult = tb_http.GetHtml(item);
  253. return hResult.Html;
  254. //string res = Base_Request_CreateOrder(ro_json, "design.order.create");
  255. //return res;
  256. }
  257. public static string API_GetPrintData_Refund(CeErpTradeCell ceErpTradeCell)
  258. {
  259. if (ceErpTradeCell == null)
  260. {
  261. return "";
  262. }
  263. //json参数
  264. List<string> postLst = new List<string>();
  265. Boolean isOldCustomerText = false;
  266. Boolean isReturn = false;
  267. Boolean isGai = false;
  268. if (ceErpTradeCell.IsOldCustomer == 1)
  269. {
  270. isOldCustomerText = true;
  271. }
  272. if (ceErpTradeCell.IsReturn > 0)
  273. {
  274. isReturn = true;
  275. }
  276. if (ceErpTradeCell.MemoOpt == 1)
  277. {
  278. isGai = true;
  279. }
  280. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  281. CeErpShop ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId);
  282. string design_app_id = "";
  283. string design_secret = "";
  284. if (design_app_id == null || design_app_id == "")
  285. {
  286. design_app_id = appID;
  287. }
  288. if (design_secret == null || design_secret == "")
  289. {
  290. design_secret = merSecret;
  291. }
  292. string method = "design.order.refund";
  293. string timeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  294. string sign = createSignCode(method, timeStr, design_app_id, design_secret);
  295. var res_obj = new
  296. {
  297. sign = sign,
  298. method = method,
  299. merchantId = design_app_id,
  300. appKey = design_app_id,
  301. outId = ceErpTradeCell.ID,
  302. designType = ceErpTradeCell.ProductId,
  303. draftType = 2,
  304. designPage = 1,
  305. afterNames = "null",
  306. printSpecial = "null",
  307. designWidth = 0,
  308. designHeight = 0,
  309. printKs = 1,
  310. printMs = 1,
  311. printWidth = 0,
  312. printHeight = 0,
  313. amount = ceErpTradeCell.payment,
  314. isUrgent = ceErpTradeCell.IsUrgency,
  315. userContact = ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao",
  316. userMobile = "null",
  317. userQq = "null",
  318. userWx = "null",
  319. userText = "null",
  320. userNotice = "null",
  321. servicesMessage = ceErpTradeCell.CustomerMemo,
  322. shopNick = "",
  323. buyerNick = ceErpTrade.buyer_nick != "" ? ceErpTrade.buyer_nick : "lingtao",
  324. apiFiles = new Array[1],
  325. receiverName = ceErpTrade.receiver_name,
  326. receiverMobile = ceErpTrade.receiver_mobile,
  327. receiverState = ceErpTrade.receiver_state,
  328. receiverCity = ceErpTrade.receiver_city,
  329. receiverDistrict = ceErpTrade.receiver_district,
  330. receiverAddress = ceErpTrade.receiver_address,
  331. expressCode = "null",
  332. creater = "null",
  333. orderSrc = "0",
  334. tids = ceErpTradeCell.tid,
  335. isOnlyDesign = "false",
  336. isOldUser = isOldCustomerText,
  337. orderText = ceErpTradeCell.seller_memo,
  338. isChange = isGai,
  339. isBack = isReturn
  340. };
  341. string ro_json = JsonConvert.SerializeObject(res_obj);
  342. ro_json = ro_json.Replace("{", "");
  343. ro_json = ro_json.Replace("}", "");
  344. ro_json = ro_json.Replace("\"", "");
  345. ro_json = ro_json.Replace(",", "&");
  346. ro_json = ro_json.Replace(":", "=");
  347. ro_json += "&timestamp=" + timeStr;
  348. //;***************************************************
  349. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  350. //Dictionary<string, object> dataDic = ToDictionary(ro_json);
  351. //string urlData = ToUrlParams(dataDic);
  352. HttpItem item = new HttpItem()
  353. {
  354. URL = pUrl,
  355. Method = "POST",
  356. ContentType = "application/x-www-form-urlencoded",
  357. Postdata = ro_json
  358. };
  359. item.PostEncoding = Encoding.UTF8;
  360. HttpResult hResult = tb_http.GetHtml(item);
  361. return hResult.Html;
  362. //string res = Base_Request_CreateOrder(ro_json, "design.order.create");
  363. //return res;
  364. }
  365. //public static string Base_Request_CreateOrder(string jsonParams, string methodStr)
  366. //{
  367. // int sc = DateTimeToUnixTime(DateTime.Now);
  368. // Dictionary<string, string> postParamList = new Dictionary<string, string>();
  369. // postParamList.Add("sign", "fed5be35cf5bd04b14dcfff984f861dd");
  370. // postParamList.Add("method", methodStr);
  371. // postParamList.Add("merchantId", appid);
  372. // postParamList.Add("appKey", appid);
  373. // //json参数
  374. // List<string> postLst = new List<string>();
  375. // string ro_json = jsonParams;
  376. // //post参数
  377. // postLst.Add("method=" + methodStr);
  378. // postLst.Add("appKey=" + appid);
  379. // postLst.Add("timestamp=" + sc);
  380. // postLst.Add("sign=" + sign);
  381. // postLst.Add("merchantId=" + appid);
  382. // string pUrl = "http://127.0.0.1:8999/designRest.htm" + "?" + string.Join("&", postLst.ToArray());
  383. // HttpItem item = new HttpItem()
  384. // {
  385. // URL = pUrl,
  386. // Method = "POST",
  387. // ContentType = "application/x-www-form-urlencoded",
  388. // Postdata = ro_json
  389. // };
  390. // item.PostEncoding = Encoding.UTF8;
  391. // HttpResult hResult = tb_http.GetHtml(item);
  392. // return hResult.Html;
  393. //}
  394. public static string API_GetPrintData_ModifyOrder(string tid, string seller_memo, Boolean isGai, Boolean isReturn, string returnReason = "")
  395. {
  396. //json参数
  397. List<string> postLst = new List<string>();
  398. string method = "design.order.update.info";
  399. string timeStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  400. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  401. CeErpShop ceErpShop = null;
  402. if (ceErpTradeCell != null)
  403. {
  404. ceErpShop = CeErpShop.Get(ceErpTradeCell.ShopId);
  405. }
  406. string design_app_id = null;
  407. string design_secret = null;
  408. if (ceErpShop != null)
  409. {
  410. design_app_id = ceErpShop.design_app_id;
  411. design_secret = ceErpShop.design_secret;
  412. }
  413. if (design_app_id == null || design_app_id == "")
  414. {
  415. design_app_id = appID;
  416. }
  417. if (design_secret == null || design_secret == "")
  418. {
  419. design_secret = merSecret;
  420. }
  421. string sign = createSignCode(method, timeStr, design_app_id, design_secret);
  422. var res_obj = new
  423. {
  424. method = method,
  425. sign = sign,
  426. merchantId = design_app_id,
  427. appKey = design_app_id,
  428. outId = tid,
  429. orderText = seller_memo,
  430. isChange = isGai,
  431. isBack = isReturn,
  432. returnReason = returnReason,
  433. };
  434. string ro_json = JsonConvert.SerializeObject(res_obj);
  435. ro_json = ro_json.Replace("{", "");
  436. ro_json = ro_json.Replace("}", "");
  437. ro_json = ro_json.Replace("\"", "");
  438. ro_json = ro_json.Replace(",", "&");
  439. ro_json = ro_json.Replace(":", "=");
  440. ro_json = ro_json.Replace("+", "%2B");
  441. ro_json += "&timestamp=" + timeStr;
  442. //***************************************************
  443. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
  444. HttpItem item = new HttpItem()
  445. {
  446. URL = pUrl,
  447. Method = "POST",
  448. Accept = "*/*",
  449. ContentType = "application/x-www-form-urlencoded",
  450. Postdata = ro_json
  451. };
  452. item.PostEncoding = Encoding.UTF8;
  453. HttpResult hResult = tb_http.GetHtml(item);
  454. return hResult.Html;
  455. //string res = Base_Request_ModifyOrder(ro_json, "design.order.update.info");
  456. //return res;
  457. }
  458. //public static string Base_Request_ModifyOrder(string jsonParams, string methodStr)
  459. //{
  460. // int sc = DateTimeToUnixTime(DateTime.Now);
  461. // Dictionary<string, string> postParamList = new Dictionary<string, string>();
  462. // //json参数
  463. // List<string> postLst = new List<string>();
  464. // string ro_json = jsonParams;
  465. // //post参数
  466. // postLst.Add("method=" + methodStr);
  467. // postLst.Add("appKey=" + appid);
  468. // postLst.Add("timestamp=" + sc);
  469. // postLst.Add("sign=" + sign);
  470. // postLst.Add("merchantId=" + appid);
  471. // string pUrl = "http://127.0.0.1:8999/designRest.htm" + "?" + string.Join("&", postLst.ToArray());
  472. // HttpItem item = new HttpItem()
  473. // {
  474. // URL = pUrl,
  475. // Method = "POST",
  476. // ContentType = "application/x-www-form-urlencoded",
  477. // Postdata = ro_json
  478. // };
  479. // item.PostEncoding = Encoding.UTF8;
  480. // HttpResult hResult = tb_http.GetHtml(item);
  481. // return hResult.Html;
  482. //}
  483. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=DesignSys_AddLog post请求参数(参数放body中):string tid(淘宝订单号)string userName(操作用户)string con(日志内容)int orderState(订单状态)
  484. public void DesignSys_AddLog()
  485. {
  486. if (UrlPostParmsCheck("tid"))
  487. {
  488. try
  489. {
  490. //HttpContext.Current.Request.BinaryRead()
  491. string tid = GetPostString("tid");
  492. int userId = GetPostInt("userId");
  493. int orderState = GetPostInt("orderState");
  494. string con = GetPostString("con");
  495. if (userId == 0)
  496. {
  497. userId = 2125;
  498. }
  499. try
  500. {
  501. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  502. if (ceErpTradeCell != null)
  503. {
  504. LogHelper.addLog(tid, userId, con, orderState);
  505. return;
  506. }
  507. else
  508. {
  509. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  510. }
  511. }
  512. catch (Exception ex)
  513. {
  514. XLog.SaveLog(0, "xxxxx," + ex.Message);
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. XLog.SaveLog(0, ex.Message);
  520. }
  521. return;
  522. }
  523. returnErrorMsg("缺少必要的参数");
  524. }
  525. public void DesignSys_AddStateLog()
  526. {
  527. if (UrlPostParmsCheck("tid"))
  528. {
  529. try
  530. {
  531. //HttpContext.Current.Request.BinaryRead()
  532. string tid = GetPostString("tid");
  533. int userId = GetPostInt("userId");
  534. int orderState = GetPostInt("orderState");
  535. string con = GetPostString("con");
  536. if (userId == 0)
  537. {
  538. userId = 2125;
  539. }
  540. try
  541. {
  542. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  543. if (ceErpTradeCell != null)
  544. {
  545. ceErpTradeCell.OrderState = orderState;
  546. ceErpTradeCell.UpdateTime = DateTime.Now;
  547. LogHelper.addLog(tid, userId, con, orderState);
  548. return;
  549. }
  550. else
  551. {
  552. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  553. }
  554. }
  555. catch (Exception ex)
  556. {
  557. XLog.SaveLog(0, "xxxxx," + ex.Message);
  558. }
  559. }
  560. catch (Exception ex)
  561. {
  562. XLog.SaveLog(0, ex.Message);
  563. }
  564. return;
  565. }
  566. returnErrorMsg("缺少必要的参数");
  567. }
  568. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=DesignSys_OrderStateChange post请求参数(参数放body中):string tid(淘宝订单号)string userName(用户姓名)int orderState(订单状态)
  569. public void DesignSys_OrderStateChange()
  570. {
  571. if (UrlPostParmsCheck("tid"))
  572. {
  573. string tid = GetPostString("tid");
  574. string userName = GetPostString("userName");
  575. int orderState = GetPostInt("orderState");
  576. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  577. if (ceErpTradeCell != null)
  578. {
  579. if (ceErpTradeCell.OrderState >= 5)
  580. {
  581. return;
  582. }
  583. if (userName != "")
  584. {
  585. CeErpUser ceErpUser = CeErpUser.GetByUserName(userName);
  586. if (ceErpUser != null)
  587. {
  588. }
  589. else
  590. {
  591. ceErpUser = CeErpUser.GetByUserName("外协设计-" + userName);
  592. if (ceErpUser == null)
  593. {
  594. returnErrorMsg("找不到对应用户");
  595. return;
  596. }
  597. }
  598. List<string> sqlList = new List<string>();
  599. sqlList.Add(" DesignUserId=" + ceErpUser.ID);
  600. sqlList.Add(" OrderState=" + orderState);
  601. if (orderState == 4)
  602. {
  603. sqlList.Add(" WaitDesignTime= GETDATE()");
  604. sqlList.Add(" StartDesignTime= GETDATE()");
  605. }
  606. sqlList.Add(" UpdateTime= GETDATE()");
  607. CeErpTradeCell.ExecuteNonQuery(string.Format("UPDATE CE_ErpTradeCell set {0} WHERE ctid = '{1}'", string.Join(",", sqlList), ceErpTradeCell.ctid));
  608. LogHelper.addLog(ceErpTradeCell.ctid, 3542, "接口请求:" + orderState, ceErpTradeCell.OrderState);
  609. commonHelper.UpdateRelationOrder(tid);
  610. return;
  611. }
  612. returnErrorMsg("找不到对应用户");
  613. }
  614. else
  615. {
  616. returnErrorMsg("找不到对应订单记录,核对淘宝订单号");
  617. return;
  618. }
  619. return;
  620. }
  621. returnErrorMsg("缺少必要的参数");
  622. }
  623. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=create_erp_account post请求参数(参数放body中):string name(用户姓名)string pwd(密码)
  624. public void create_erp_account()
  625. {
  626. if (UrlPostParmsCheck("name,pwd"))
  627. {
  628. string name = GetPostString("name");
  629. if (CeErpUser.Exists(" Account=?", name))
  630. {
  631. returnErrorMsg("该账户名已经存在,请更换!");
  632. return;
  633. }
  634. string pwd = SecurityHelper.EncryptSymmetric(GetPostString("pwd"));
  635. CeErpUser user = new CeErpUser();
  636. user.Account = name;
  637. user.Name = name;
  638. user.isOpen = false;
  639. user.CreateTime = DateTime.Now;
  640. user.PassWord = pwd;
  641. user.Create();
  642. returnSuccessMsg("保存成功!");
  643. }
  644. }
  645. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=change_order_price post请求参数(参数放body中):ctid content
  646. public void change_order_price()
  647. {
  648. if (UrlPostParmsCheck("ctid"))
  649. {
  650. string ctid = GetPostString("ctid");
  651. string content = GetPostString("content");
  652. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  653. if (ce == null)
  654. {
  655. returnErrorMsg("找不到订单!");
  656. return;
  657. }
  658. CeErpMessageTip ct = new CeErpMessageTip();
  659. string sql_pay = string.Format("select top 1 * from CE_ErpMessageTip where tid = '{0}' and type = 2", ctid);
  660. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql_pay).Tables[0];
  661. ct.tid = ctid;
  662. ct.sectionId = 0;
  663. ct.userId = ce.CustomerUserId;
  664. ct.type = 2;
  665. ct.isVisit = false;
  666. ct.content = content;
  667. if (dth.Rows.Count > 0)
  668. {
  669. ct.ID = Convert.ToInt32(dth.Rows[0]["ID"]);
  670. ct.Update();
  671. }
  672. else
  673. {
  674. ct.Create();
  675. }
  676. LogHelper.addLog(ce.ctid, 3542, "接口请求修改:" + content, ce.OrderState);
  677. returnSuccessMsg("保存成功!");
  678. }
  679. }
  680. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=change_order_price post请求参数(参数放body中):ctid content
  681. public void return_order()
  682. {
  683. if (UrlPostParmsCheck("ctid"))
  684. {
  685. string ctid = GetPostString("ctid");
  686. string content = GetPostString("content");
  687. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  688. if (entity == null)
  689. {
  690. returnErrorMsg("找不到订单!");
  691. return;
  692. }
  693. entity.OrderState = 0;
  694. entity.ReturnUserType = 1;
  695. entity.IsReadTag = 1;
  696. entity.IsVerifyToSupplier = false;
  697. entity.UnusualTag = 0;
  698. entity.UnusualTime = null;
  699. entity.UnusualCon = "";
  700. entity.IsReturn = 2;
  701. entity.ReturnTime = DateTime.Now;
  702. entity.ReturnReason = content;
  703. entity.UpdateTime = DateTime.Now;
  704. entity.Update();
  705. LogHelper.addLog(entity.ctid, 3542, "接口打回:" + content, entity.OrderState);
  706. returnSuccessMsg("保存成功!");
  707. return;
  708. }
  709. returnErrorMsg("参数错误!");
  710. }
  711. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=handleAfterSale post请求参数(参数放body中):responsibleId-售后单id status-处理结果1同意2不同意 supmemo-理由
  712. public void handleAfterSale()
  713. {
  714. string responsibleId = GetString("responsibleId");
  715. int st = GetInt("status");
  716. string afmemo = GetString("supmemo");
  717. string id = "0";
  718. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.Get(responsibleId);
  719. CeErpTradeCell entity = null;
  720. if (ceErpTradeResponsible != null)
  721. {
  722. id = ceErpTradeResponsible.ID.ToString();
  723. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  724. if (ceErpTradeResponsible.VerifyState == 1)
  725. {
  726. returnErrorMsg("已超时自动认可");
  727. return;
  728. }
  729. }
  730. if (entity != null)
  731. {
  732. if (entity.AfterSaleState != 3 || ceErpTradeResponsible.VerifyState != 0)
  733. {
  734. returnErrorMsg("此单售后当前状态不可操作!");
  735. return;
  736. }
  737. entity.AfterSaleSupplierState = st;
  738. entity.AfterSaleSupplierMemo = afmemo;
  739. if (st == 1)
  740. {
  741. ceErpTradeResponsible.VerifyState = 1;
  742. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  743. ceErpTradeResponsible.Update();
  744. bool isAll = commonHelper.tradeResponsibleAll(entity);
  745. if (isAll)
  746. {
  747. entity.AfterSaleState = 4;
  748. entity.FinishAfterSaleTime = DateTime.Now;
  749. if (entity.AfterSaleResSupId > 0)
  750. {
  751. entity.AfterSaleSupplierState = 1;
  752. }
  753. }
  754. }
  755. else
  756. {
  757. CeErpTradeResponsible.dateByTid(entity.ctid);
  758. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  759. if (ceErpTradeAfterSaleExtend != null)
  760. {
  761. }
  762. else
  763. {
  764. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  765. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  766. ceErpTradeAfterSaleExtend.Create();
  767. }
  768. entity.AfterSaleState = 2;
  769. }
  770. if (entity.AfterSaleState == 4)
  771. {
  772. LogHelper.addLog(entity.tid, 0, "设计共创接口完成售后", 0, 3);
  773. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  774. {
  775. LogHelper.addDesignerBillLog(entity.tid, 0, "设计共创接口售后取消设计费", "设计共创接口", 1);
  776. }
  777. ApiVo apiVo = new ApiVo();
  778. apiVo.orderNumber = entity.ctid;
  779. apiVo.actionName = "afterOver";
  780. designHelper.API_WorkCore(apiVo); //afterOver
  781. }
  782. entity.UpdateTime = DateTime.Now;
  783. entity.Update();
  784. returnSuccessMsg("操作成功!");
  785. CeErpSukuraData.createInfo(entity.ctid, 8);
  786. LogHelper.addLog(entity.ctid, 0, "设计共创接口" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  787. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "设计共创" + (st == 1 ? "认可" : "不认可"), 0, st == 1 ? 0 : 1, afmemo);
  788. return;
  789. }
  790. returnErrorMsg("找不到订单记录");
  791. }
  792. //http://47.114.150.226:88/Handler/apiDesign.ashx?t=getOrderLogs post请求参数(参数放body中):responsibleId-售后单id status-处理结果1同意2不同意 supmemo-理由
  793. public void getOrderLogs()
  794. {
  795. string ctid = GetPostString("ctid");
  796. if (string.IsNullOrEmpty(ctid))
  797. {
  798. returnErrorMsg("找不到订单记录");
  799. return;
  800. }
  801. StringBuilder sql = new StringBuilder();
  802. sql.AppendFormat("select * from view_erptradelog where tid='{0}' order by id;", ctid);
  803. DataTable ds = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  804. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(ds)) + "}");
  805. return;
  806. }
  807. }
  808. }