tmcHelper.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. using BizCom;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using System.Data;
  10. //status可选值:
  11. //* TRADE_NO_CREATE_PAY(没有创建支付宝交易)
  12. //* WAIT_BUYER_PAY(等待买家付款)
  13. //* SELLER_CONSIGNED_PART(卖家部分发货)
  14. //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款)
  15. //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货)
  16. //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用)
  17. //* TRADE_FINISHED(交易成功)
  18. //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭)
  19. //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易)
  20. //* PAY_PENDING(国际信用卡支付付款确认中)
  21. //* WAIT_PRE_AUTH_CONFIRM(0元购合约中)
  22. namespace ErpServer
  23. {
  24. /// <summary>
  25. /// 同步推送处理
  26. /// </summary>
  27. public class tmcHelper
  28. {
  29. public static int RemoveEmptyEntries { get; private set; }
  30. // case "taobao_trade_TradeCreate"://创建淘宝交易消息
  31. // {
  32. // break;
  33. // }
  34. // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息
  35. // case "taobao_trade_TradeMemoModified"://交易备注修改消息
  36. // case "taobao_trade_TradeRated"://交易评价变更消息
  37. // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款
  38. // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货)
  39. // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息
  40. // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息
  41. // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息
  42. // case "taobao_trade_TradeSellerShip"://卖家发货消息
  43. // case "taobao_trade_TradeClose"://关闭交易消息
  44. // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息
  45. // case "taobao_trade_TradeModifyFee"://修改交易费用消息
  46. public static string GetUTF8String(byte[] buffer)
  47. {
  48. if (buffer == null)
  49. return null;
  50. if (buffer.Length <= 3)
  51. {
  52. return Encoding.UTF8.GetString(buffer);
  53. }
  54. byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf };
  55. if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2])
  56. {
  57. return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
  58. }
  59. return Encoding.UTF8.GetString(buffer);
  60. }
  61. /// <summary>
  62. /// 交易订单关闭
  63. /// </summary>
  64. /// <param name="content"></param>
  65. public static void erp_CloseTrade(string content)
  66. {
  67. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  68. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  69. if (status == "TRADE_CLOSED_BY_TAOBAO")
  70. {
  71. StringBuilder sql = new StringBuilder();
  72. sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]);
  73. sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭);
  74. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]);
  75. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  76. //消息通知
  77. }
  78. }
  79. //接收到--新订单生成消息
  80. public static void erp_TradeBuyerPay(string content)
  81. {
  82. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  83. string tid = dics["tid"].ToString();
  84. string sellerNick = dics["seller_nick"].ToString();
  85. string sessionkey = taobaoHelper.ShopKeyDics[sellerNick];
  86. string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test();
  87. createNewOrder(res);
  88. }
  89. //创建新订单
  90. public static void createNewOrder(string res)
  91. {
  92. Trade_fullinfo_get_response_Obj fullObj = null;
  93. if (res == "") return;
  94. try
  95. {
  96. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  97. //res = res.Replace(" ", "");
  98. fullObj = JsonConvert.DeserializeObject<Trade_fullinfo_get_response_Obj>(res);
  99. }
  100. catch (Exception ex)
  101. {
  102. }
  103. if (fullObj == null)
  104. {
  105. Console.WriteLine("Trade_fullinfo_get_response_Obj isNull");
  106. return;
  107. }
  108. Trade tObj = fullObj.trade_fullinfo_get_response.trade;
  109. Orders orderList = tObj.orders;
  110. StringBuilder sql = new StringBuilder();
  111. CeErpTrade td = CeErpTrade.Get(tObj.tid);
  112. if (td!=null)
  113. {
  114. //已经存在了,就不要再继续创建了;
  115. return;
  116. }
  117. //原始单创建
  118. CeErpTrade trade = new CeErpTrade();
  119. trade.tid = tObj.tid;
  120. trade.num = tObj.num;
  121. trade.status = tObj.status;
  122. trade.type = tObj.type;
  123. trade.price = Convert.ToDouble(tObj.price);
  124. trade.discount_fee = Convert.ToDouble(tObj.discount_fee);
  125. trade.total_fee = Convert.ToDouble(tObj.total_fee);
  126. trade.created = tObj.created;
  127. if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null)
  128. {
  129. trade.pay_time = tObj.pay_time;
  130. }
  131. if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null)
  132. {
  133. trade.modified = tObj.modified;
  134. }
  135. if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null)
  136. {
  137. trade.end_time = tObj.end_time;
  138. }
  139. trade.buyer_nick = tObj.buyer_nick;
  140. trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  141. trade.seller_nick = tObj.seller_nick;
  142. trade.payment = Convert.ToDouble(tObj.payment);
  143. trade.receiver_name = tObj.receiver_name;
  144. trade.receiver_state = tObj.receiver_state;
  145. trade.receiver_city = tObj.receiver_city;
  146. trade.receiver_town = GetNoNullValue_string(tObj.receiver_town);
  147. trade.receiver_district = GetNoNullValue_string(tObj.receiver_district);
  148. trade.receiver_address = tObj.receiver_address;
  149. trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  150. trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  151. if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  152. {
  153. trade.consign_time = tObj.consign_time;
  154. }
  155. if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null)
  156. {
  157. trade.delivery_time = tObj.delivery_time;
  158. }
  159. trade.buyer_message = GetNoNullValue_string(tObj.buyer_message);
  160. trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo);
  161. trade.seller_memo = GetNoNullValue_string(tObj.seller_memo);
  162. trade.Create();
  163. bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注
  164. string xianhuoMemo = "(" + trade.tid + ")现货-" ;
  165. //order表创建
  166. foreach (Order item in orderList.order)
  167. {
  168. CeErpTradeOrder order = new CeErpTradeOrder();
  169. order.tid = trade.tid;
  170. order.oid = item.oid;
  171. order.buyer_nick = trade.buyer_nick;
  172. order.refund_status = item.refund_status;
  173. order.status = item.status;
  174. order.title = item.title;
  175. order.price = Convert.ToDouble(item.price);
  176. order.pic_path = item.pic_path;
  177. order.num = Convert.ToDouble(item.num.ToString());
  178. order.payment = Convert.ToDouble(item.payment);
  179. order.adjust_fee = Convert.ToDouble(item.adjust_fee);
  180. if(item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货")!=-1)
  181. {
  182. order.sku_properties_name = item.sku_properties_name;
  183. order.sku_id = item.sku_id;
  184. isXianhuo = true;
  185. xianhuoMemo += order.sku_properties_name;
  186. }
  187. order.Create();
  188. }
  189. if (isXianhuo)
  190. {
  191. xianhuoMemo += "-";
  192. xianhuoMemo += trade.seller_nick;
  193. }
  194. //cell表创建
  195. CeErpTradeCell entity = null;
  196. entity = CeErpTradeCell.GetByCtid(tObj.tid);
  197. if (entity == null)
  198. {
  199. try
  200. {
  201. entity = new CeErpTradeCell();
  202. entity.ctid = tObj.tid;
  203. entity.tid = tObj.tid;
  204. entity.payment = Convert.ToDouble(tObj.payment);
  205. if (isXianhuo)
  206. {
  207. entity.OrderState = 5;
  208. entity.seller_memo = xianhuoMemo;
  209. }
  210. entity.Create();
  211. }
  212. catch(Exception ex)
  213. {
  214. XLog.SaveLog(0, ex.Message);
  215. }
  216. }
  217. operateCustomer(tObj);
  218. }
  219. public static void operateCustomer(Trade Obj)
  220. {
  221. CeErpCustomer cus = null;
  222. cus = CeErpCustomer.GetByNick(Obj.buyer_nick);
  223. if (cus != null)
  224. {
  225. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  226. cus.phone = Obj.receiver_mobile;
  227. TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time);
  228. cus.buy_day = tsday.Days ;
  229. cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
  230. cus.buy_count = cus.buy_count + 1 ;
  231. cus.lastbuy_time = Obj.pay_time;
  232. cus.Update();
  233. }
  234. else
  235. {
  236. try
  237. {
  238. cus = new CeErpCustomer();
  239. cus.buyer_nick = Obj.buyer_nick;
  240. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  241. cus.phone = Obj.receiver_mobile;
  242. cus.buy_day = 0;
  243. cus.buy_count = 1;
  244. cus.lastbuy_time = Obj.pay_time;
  245. cus.total_fee = Convert.ToDouble(Obj.payment);
  246. cus.Create();
  247. }
  248. catch(Exception ex)
  249. {
  250. XLog.SaveLog(0, ex.Message);
  251. }
  252. }
  253. }
  254. public static string GetNoNullValue_string(string value)
  255. {
  256. if (value == null)
  257. {
  258. return "";
  259. }
  260. return value;
  261. }
  262. public static void erp_TradeMemoModified(string content)
  263. {
  264. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  265. if (!dics.ContainsKey("seller_memo"))
  266. {
  267. return;
  268. }
  269. string tid = dics["tid"].ToString();
  270. string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO
  271. string buyer = dics["buyer_nick"].ToString();
  272. CeErpTrade mainEn = CeErpTrade.Get(tid);
  273. if (mainEn == null) return;
  274. createCellOrder(mainEn,tid,smemo,buyer);
  275. }
  276. public static void createCellOrder(CeErpTrade father,string tid,string smemo,string buyer,bool isJump=false)
  277. {
  278. bool isNeedCellOrder = true; //是否需要生成cell
  279. string issql = "select * from ce_erptradecell where tid='" + tid + "';";
  280. DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
  281. if (ishavedt.Rows.Count > 0)
  282. {
  283. if(Convert.ToInt32(ishavedt.Rows[0]["OrderState"])>0 && Convert.ToInt32(ishavedt.Rows[0]["DesignUserId"]) > 0)
  284. {
  285. isNeedCellOrder = false;
  286. }
  287. else if (ishavedt.Rows[0]["ctid"].ToString().IndexOf("C") != -1 && Convert.ToInt32(ishavedt.Rows[0]["OrderState"]) == 0 && Convert.ToInt32(ishavedt.Rows[0]["DesignUserId"]) == 0)
  288. {
  289. string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
  290. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  291. }
  292. }
  293. if (isJump)
  294. {
  295. isNeedCellOrder = true;
  296. }
  297. //补差价单
  298. if (smemo.IndexOf("补差价") != -1)
  299. {
  300. CeErpTradeCell entity = null;
  301. entity = CeErpTradeCell.GetByCtid(tid);
  302. bool ishaveBu = true;
  303. if (entity == null)
  304. {
  305. entity = new CeErpTradeCell();
  306. entity.ctid = tid;
  307. entity.tid = tid;
  308. ishaveBu = false;
  309. }
  310. if (entity.OrderState >= 5) return;
  311. entity.seller_memo = smemo;
  312. entity.IsSample = 2;//补差价单
  313. smemo = smemo.Replace(":", ":");
  314. string[] listmemo = smemo.Split(':');
  315. if (listmemo.Length > 1)
  316. {
  317. string maintid = System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", "");
  318. string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'";
  319. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  320. if (dt_bu.Rows.Count > 0)
  321. {
  322. entity.ptid = dt_bu.Rows[0]["tid"].ToString();
  323. entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]);
  324. entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]);
  325. entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]);
  326. if(dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value)
  327. {
  328. entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]);
  329. }
  330. if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value)
  331. {
  332. entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]);
  333. }
  334. if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value)
  335. {
  336. entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]);
  337. }
  338. if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value)
  339. {
  340. entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]);
  341. }
  342. }
  343. }
  344. if (ishaveBu)
  345. {
  346. entity.Update();
  347. }
  348. else
  349. {
  350. entity.Create();
  351. }
  352. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  353. isNeedCellOrder = false;
  354. }
  355. else if(smemo.IndexOf("拿样订单") != -1)
  356. {
  357. CeErpTradeCell entity = null;
  358. entity = CeErpTradeCell.GetByCtid(tid);
  359. if (entity == null)
  360. {
  361. entity = new CeErpTradeCell();
  362. entity.ctid = tid;
  363. entity.tid = tid;
  364. entity.seller_memo = smemo;
  365. entity.OrderState = 6; //下单完成
  366. entity.IsSample = 1;
  367. entity.Create();
  368. }
  369. else
  370. {
  371. entity.IsSample = 1;
  372. entity.seller_memo = smemo;
  373. entity.OrderState = 6;
  374. entity.Update();
  375. }
  376. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  377. isNeedCellOrder = false;
  378. }
  379. if (isNeedCellOrder == false)
  380. {
  381. return;
  382. }
  383. if (smemo.IndexOf("*") != -1)
  384. {
  385. return;
  386. }
  387. string[] memoList = null;
  388. if (smemo.IndexOf(",") != -1)
  389. {
  390. smemo = smemo.Replace(',',',');
  391. }
  392. memoList = smemo.Split(',');
  393. int orderIdx = 1;
  394. int hebaoCount = 0;
  395. bool isMulity = false;
  396. if (memoList.Length > 1)
  397. {
  398. isMulity = true;
  399. foreach(string mstr in memoList)
  400. {
  401. if (mstr.IndexOf("合包") != -1)
  402. {
  403. hebaoCount += 1;
  404. }
  405. }
  406. }
  407. if (hebaoCount == 1)
  408. {
  409. createHebaoCell(isMulity, 0, smemo, father);
  410. }
  411. else
  412. {
  413. double hePrice = father.payment;
  414. string needHebaoItem = "";
  415. foreach (string item in memoList)
  416. {
  417. if (item.IndexOf("合包") != -1)
  418. {
  419. needHebaoItem += item;
  420. needHebaoItem += ",";
  421. }
  422. else
  423. {
  424. if (item.IndexOf("电子稿") != -1)
  425. {
  426. createDianziCell(isMulity,orderIdx,item,father,ref hePrice);
  427. }
  428. else if(item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
  429. {
  430. createLogoCell(isMulity, orderIdx, item, father, ref hePrice);
  431. }
  432. else if (item.IndexOf("现货") != -1)
  433. {
  434. createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice);
  435. }
  436. else
  437. createNotHeBaoCell(isMulity, orderIdx, item, father,ref hePrice);
  438. orderIdx++;
  439. }
  440. }
  441. if (needHebaoItem.Length > 0)
  442. {
  443. createHebaoCell(isMulity, orderIdx, needHebaoItem, father,hePrice);
  444. orderIdx++;
  445. }
  446. if (orderIdx>2)
  447. {
  448. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "'";
  449. CeErpTradeRefund.ExecuteNonQuery(sql_del.ToString());
  450. }
  451. }
  452. }
  453. public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father,ref double hePrice)
  454. {
  455. if (itemMemo.Length <= 0) return;
  456. string ctid = "";
  457. if (isMulty && itemMemo.Length > 2)
  458. {
  459. string preStr = "C" + orderIndex + "_";
  460. ctid = preStr + father.tid;
  461. }
  462. else if (itemMemo.Length > 2)
  463. {
  464. ctid = father.tid;
  465. }
  466. CeErpTradeCell entity = null;
  467. entity = CeErpTradeCell.GetByCtid(ctid);
  468. bool isNull = false;
  469. if (entity == null)
  470. {
  471. entity = new CeErpTradeCell();
  472. isNull = true;
  473. }
  474. entity.ctid = ctid;
  475. entity.tid = father.tid;
  476. string[] acclist = itemMemo.Split('-');
  477. string count = acclist[0];
  478. string product = acclist[1];
  479. string account = acclist[3];
  480. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  481. if (cusInfo != null)
  482. {
  483. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  484. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  485. {
  486. }
  487. else
  488. entity.OrderState = Convert.ToInt32(OrderState.待抢单);
  489. }
  490. entity.ProductId = getProductIdByName("logo");
  491. entity.ProductCount = count;
  492. if (isMulty)
  493. {
  494. try
  495. {
  496. entity.payment = Convert.ToDouble(acclist[4]);
  497. hePrice = hePrice - Convert.ToDouble(acclist[4]);
  498. }
  499. catch (Exception ex)
  500. {
  501. XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  502. }
  503. }
  504. string newmemo = "(" + entity.tid + ")-";
  505. for (int i = 0; i < acclist.Length; i++)
  506. {
  507. if (i == 3) continue;
  508. newmemo += acclist[i];
  509. if (i < acclist.Length - 2)
  510. {
  511. newmemo += "-";
  512. }
  513. }
  514. string sName = getShopSNameByName(father.seller_nick);
  515. newmemo += ("-" + sName);
  516. newmemo += ("-" + father.buyer_nick);
  517. newmemo += ("-" + father.receiver_state);
  518. if (cusInfo != null)
  519. {
  520. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  521. }
  522. if (isMulty)
  523. {
  524. newmemo += "-[C" + orderIndex + "]";
  525. }
  526. entity.seller_memo = newmemo;
  527. if (isNull)
  528. {
  529. entity.Create();
  530. }
  531. else
  532. {
  533. entity.Update();
  534. }
  535. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  536. }
  537. public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref double hePrice)
  538. {
  539. if (itemMemo.Length <= 0) return;
  540. string ctid = "";
  541. if (isMulity && itemMemo.Length > 2)
  542. {
  543. string preStr = "C" + orderIndex + "_";
  544. ctid = preStr + father.tid;
  545. }
  546. else if (itemMemo.Length > 2)
  547. {
  548. ctid = father.tid;
  549. }
  550. CeErpTradeCell entity = null;
  551. entity = CeErpTradeCell.GetByCtid(ctid);
  552. bool isNull = false;
  553. if (entity == null)
  554. {
  555. entity = new CeErpTradeCell();
  556. isNull = true;
  557. }
  558. entity.ctid = ctid;
  559. entity.tid = father.tid;
  560. string[] acclist = itemMemo.Split('-');
  561. string count = acclist[0];
  562. string product = acclist[1];
  563. string account = acclist[3];
  564. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  565. if (cusInfo != null)
  566. {
  567. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  568. }
  569. if (entity.OrderState < 3 && entity.DesignUserId == 0)
  570. {
  571. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  572. entity.DesignUserId = 255;
  573. entity.WaitDesignTime = DateTime.Now;
  574. }
  575. entity.ProductId = getProductIdByName(product);
  576. entity.ProductCount = count;
  577. if (isMulity)
  578. {
  579. try
  580. {
  581. entity.payment = Convert.ToDouble(acclist[4]);
  582. hePrice = hePrice - Convert.ToDouble(acclist[4]);
  583. }
  584. catch (Exception ex)
  585. {
  586. XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  587. }
  588. }
  589. string newmemo = "(" + entity.tid + ")-";
  590. for (int i = 0; i < acclist.Length; i++)
  591. {
  592. if (i == 3) continue;
  593. newmemo += acclist[i];
  594. if (i < acclist.Length - 2)
  595. {
  596. newmemo += "-";
  597. }
  598. }
  599. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  600. newmemo += ("-" + sName);
  601. newmemo += ("-" + father.buyer_nick);
  602. newmemo += ("-" + father.receiver_state);
  603. if (cusInfo != null)
  604. {
  605. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  606. }
  607. if (isMulity)
  608. {
  609. newmemo += "-[C" + orderIndex + "]";
  610. }
  611. entity.seller_memo = newmemo;
  612. if (isNull)
  613. {
  614. entity.Create();
  615. }
  616. else
  617. {
  618. entity.Update();
  619. }
  620. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  621. }
  622. public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father,ref double hePrice)
  623. {
  624. if (itemMemo.Length <= 0) return;
  625. string ctid = "";
  626. if (isMulty && itemMemo.Length > 2)
  627. {
  628. string preStr = "C" + orderIndex + "_";
  629. ctid = preStr + father.tid;
  630. }
  631. else if (itemMemo.Length > 2)
  632. {
  633. ctid = father.tid;
  634. }
  635. CeErpTradeCell entity = null;
  636. entity = CeErpTradeCell.GetByCtid(ctid);
  637. bool isNull = false;
  638. if (entity == null)
  639. {
  640. entity = new CeErpTradeCell();
  641. isNull = true;
  642. }
  643. entity.ctid = ctid;
  644. entity.tid = father.tid;
  645. string[] acclist = itemMemo.Split('-');
  646. string product = acclist[0];
  647. string account = acclist[1];
  648. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  649. if (cusInfo != null)
  650. {
  651. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  652. }
  653. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  654. if (isMulty)
  655. {
  656. try
  657. {
  658. entity.payment = Convert.ToDouble(acclist[2]);
  659. hePrice = hePrice - Convert.ToDouble(acclist[2]);
  660. }
  661. catch (Exception ex)
  662. {
  663. XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  664. }
  665. }
  666. string newmemo = "(" + entity.tid + ")-";
  667. for (int i = 0; i < acclist.Length; i++)
  668. {
  669. if (i == 1) continue;
  670. newmemo += acclist[i];
  671. if (i < acclist.Length - 1)
  672. {
  673. newmemo += "-";
  674. }
  675. }
  676. string sName = getShopSNameByName(father.seller_nick);
  677. newmemo += ("-" + sName);
  678. newmemo += ("-" + father.buyer_nick);
  679. newmemo += ("-" + father.receiver_state);
  680. if (cusInfo != null)
  681. {
  682. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  683. }
  684. if (isMulty)
  685. {
  686. newmemo += "-[C" + orderIndex + "]";
  687. }
  688. entity.seller_memo = newmemo;
  689. if (isNull)
  690. {
  691. entity.Create();
  692. }
  693. else
  694. {
  695. entity.Update();
  696. }
  697. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  698. }
  699. public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father,double hePrice=0)
  700. {
  701. if (itemMemo.Length <= 0) return;
  702. string[] hebaoMemoList = itemMemo.Split(',');
  703. string memo_index1 = hebaoMemoList[0];
  704. string ctid = "";
  705. if (isMulity && orderIndex>1 && itemMemo.Length > 2)
  706. {
  707. string preStr = "C" + orderIndex + "_";
  708. ctid = preStr + father.tid;
  709. }
  710. else if (itemMemo.Length > 2)
  711. {
  712. ctid = father.tid;
  713. }
  714. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  715. bool ishave = true;
  716. if (entity == null)
  717. {
  718. entity = new CeErpTradeCell();
  719. ishave = false;
  720. }
  721. entity.ctid = ctid;
  722. entity.tid = father.tid;
  723. string[] acclist = memo_index1.Split('-');
  724. if (acclist.Length < 6)
  725. {
  726. return;
  727. }
  728. string size = acclist[0];
  729. string count = acclist[1];
  730. bool isBuGanJiao = false;
  731. string product = "";
  732. string mt = "", ct = "";
  733. string account = "";
  734. //不干胶材质和产品名对换
  735. memo_index1 = memo_index1.Replace("PVC", "pvc");
  736. if ((memo_index1.IndexOf("不干胶") != -1 || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("现货")==-1)
  737. {
  738. isBuGanJiao = true;
  739. product = acclist[3];
  740. mt = acclist[2];
  741. }
  742. else
  743. {
  744. product = acclist[2];
  745. mt = acclist[3];
  746. }
  747. account = acclist[5];
  748. ct = acclist[4];
  749. entity.ProductId = getProductIdByName(product);
  750. //找不到对应产品id的不生成
  751. if (entity.ProductId == 0)
  752. {
  753. return;
  754. }
  755. if (isMulity && hePrice != 0)
  756. {
  757. entity.payment = hePrice;
  758. }
  759. else
  760. {
  761. entity.payment = father.payment;
  762. }
  763. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  764. if (cusInfo != null)
  765. {
  766. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  767. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  768. {
  769. }
  770. else
  771. {
  772. entity.OrderState = 2;
  773. if (entity.DesignUserId > 0)
  774. {
  775. entity.OrderState = 3;
  776. }
  777. }
  778. }
  779. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  780. {
  781. if (itemMemo.IndexOf("改稿") != -1)
  782. {
  783. int designId = getOldCusByBuyer(father.buyer_nick);
  784. entity.DesignUserId = designId;
  785. if (designId != 0)
  786. {
  787. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  788. {
  789. }
  790. else
  791. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  792. entity.WaitDesignTime = DateTime.Now;
  793. LogHelper.addLog(entity.ctid, 0, "老客户改稿", entity.OrderState);
  794. }
  795. }
  796. else
  797. {
  798. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  799. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿
  800. entity.WaitDesignTime = DateTime.Now;
  801. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  802. }
  803. }
  804. entity.Material = mt;
  805. entity.ProductSize = size;
  806. entity.ProductCount = count;
  807. entity.Craft = ct;
  808. string newmemo = "(" + father.tid + ")-";
  809. for(int idx = 0; idx < hebaoMemoList.Length; idx++)
  810. {
  811. string smallitem = hebaoMemoList[idx];
  812. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  813. {
  814. newmemo = "";
  815. }
  816. smallitem = smallitem.Replace("-合包", "");
  817. smallitem = smallitem.Replace("-(合包)", "");
  818. string[] smallList = smallitem.Split('-');
  819. if (smallitem.IndexOf("海报") != -1)
  820. {
  821. newmemo += smallList[2];
  822. newmemo += smallList[0];
  823. newmemo += "-";
  824. newmemo += smallList[1];
  825. newmemo += "(";
  826. newmemo += father.tid;
  827. newmemo += ")";
  828. newmemo += "-";
  829. newmemo += smallList[4];
  830. }
  831. else
  832. {
  833. for (int i = 0; i < smallList.Length; i++)
  834. {
  835. if (isMulity && i == 5)
  836. {
  837. continue;
  838. }
  839. newmemo += smallList[i];
  840. if (i < smallList.Length - 2 && i != 2 && i != 3)
  841. {
  842. newmemo += "-";
  843. }
  844. }
  845. }
  846. if (hebaoMemoList.Length > idx + 1)
  847. {
  848. newmemo += ",";
  849. }
  850. }
  851. //string nohebaomemo = itemMemo.Replace("-合包","");
  852. //string newmemo = "(" + entity.tid + ")-" + nohebaomemo;
  853. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  854. newmemo += ("-" + sName);
  855. newmemo += ("-" + father.buyer_nick);
  856. newmemo += ("-" + father.receiver_state);
  857. if (cusInfo != null)
  858. {
  859. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  860. }
  861. if (orderIndex > 1 && isMulity)
  862. {
  863. newmemo += "-[C" + orderIndex + "]";
  864. }
  865. newmemo += "-合包";
  866. entity.seller_memo = newmemo;
  867. if (ishave)
  868. {
  869. entity.Update();
  870. }
  871. else
  872. entity.Create();
  873. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  874. }
  875. public static void createNotHeBaoCell(bool isMulity, int orderIndex,string itemMemo,CeErpTrade father,ref double hePrice)
  876. {
  877. if (itemMemo.Length <= 0) return;
  878. string ctid = "";
  879. if (isMulity && itemMemo.Length > 2) //item.length>2 避免备注加了分隔符,,且后面的是空的或者回车或者空格
  880. {
  881. string preStr = "C" + orderIndex + "_";
  882. ctid = preStr + father.tid;
  883. }
  884. else if (itemMemo.Length > 2)
  885. {
  886. ctid = father.tid;
  887. }
  888. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  889. bool ishave = true;
  890. if (entity == null)
  891. {
  892. entity = new CeErpTradeCell();
  893. ishave = false;
  894. }
  895. entity.ctid = ctid;
  896. entity.tid = father.tid;
  897. string[] acclist = itemMemo.Split('-');
  898. if (isMulity && acclist.Length < 7)
  899. {
  900. return;
  901. }
  902. if (acclist.Length < 6)
  903. {
  904. return;
  905. }
  906. string size = acclist[0];
  907. string count = acclist[1];
  908. bool isBuGanJiao = false;
  909. string product = "";
  910. string mt = "", ct = "";
  911. string account = "";
  912. //不干胶材质和产品名对换
  913. itemMemo = itemMemo.Replace("PVC", "pvc");
  914. if ((itemMemo.IndexOf("不干胶") != -1 || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("现货") == -1)
  915. {
  916. isBuGanJiao = true;
  917. product = acclist[3];
  918. mt = acclist[2];
  919. }
  920. else
  921. {
  922. product = acclist[2];
  923. mt = acclist[3];
  924. }
  925. account = acclist[5];
  926. ct = acclist[4];
  927. //如果是拆分单的话要多一个价格的拆分
  928. if (isMulity)
  929. {
  930. try
  931. {
  932. string strPrice = acclist[6];
  933. if (strPrice.IndexOf("元") != -1)
  934. {
  935. strPrice = strPrice.Replace("元", "");
  936. }
  937. entity.payment = Convert.ToDouble(strPrice);
  938. hePrice = hePrice - Convert.ToDouble(strPrice); //总价格-拆分后其他的价格=剩下需要拿去合包的价格
  939. }
  940. catch (Exception ex)
  941. {
  942. //XLog.SaveLog(0, "createNotHeBaoCell,payment=acclist[6]" + "|" + ex.Message);
  943. }
  944. }
  945. else
  946. {
  947. entity.payment = father.payment;
  948. }
  949. entity.ProductId = getProductIdByName(product);
  950. //找不到对应产品id的不生成
  951. if (entity.ProductId == 0)
  952. {
  953. return;
  954. }
  955. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  956. if (cusInfo != null)
  957. {
  958. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  959. if(entity.OrderState>2 && entity.DesignUserId > 0)
  960. {
  961. //到了设计那边,就更新memo,状态不设置
  962. }
  963. else
  964. {
  965. entity.OrderState = 2;
  966. if (entity.DesignUserId > 0) //推送过来更新的时候,如果已经指派给设计师了就待设计
  967. {
  968. entity.OrderState = 3;
  969. }
  970. }
  971. }
  972. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  973. {
  974. if (itemMemo.IndexOf("改稿") != -1)
  975. {
  976. int designId = getOldCusByBuyer(father.buyer_nick);
  977. entity.DesignUserId = designId;
  978. if (designId != 0)
  979. {
  980. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  981. {
  982. //到了设计那边,就更新memo,状态不设置
  983. }
  984. else
  985. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  986. entity.WaitDesignTime = DateTime.Now;
  987. LogHelper.addLog(entity.ctid, 0, "老客户改稿", entity.OrderState);
  988. }
  989. }
  990. else
  991. {
  992. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  993. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单不林春鸿
  994. entity.WaitDesignTime = DateTime.Now;
  995. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  996. }
  997. }
  998. entity.Material = mt;
  999. entity.ProductSize = size;
  1000. entity.ProductCount = count;
  1001. entity.Craft = ct;
  1002. string newmemo = "(" + father.tid + ")-";
  1003. if (itemMemo.IndexOf("海报") != -1)
  1004. {
  1005. newmemo = acclist[2];
  1006. newmemo += acclist[0];
  1007. newmemo += "-";
  1008. newmemo += acclist[1];
  1009. newmemo += "(";
  1010. newmemo += father.tid;
  1011. newmemo += ")";
  1012. newmemo += "-";
  1013. newmemo += acclist[4];
  1014. }
  1015. else
  1016. {
  1017. for (int i = 0; i < acclist.Length; i++)
  1018. {
  1019. if (isMulity && i == 6)
  1020. {
  1021. continue;
  1022. }
  1023. else if (i == 5)
  1024. {
  1025. continue;
  1026. }
  1027. newmemo += acclist[i];
  1028. if (i < acclist.Length - 2 && i != 2 && i != 3)
  1029. {
  1030. newmemo += "-";
  1031. }
  1032. }
  1033. }
  1034. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  1035. newmemo += ("-" + sName);
  1036. newmemo += ("-" + father.buyer_nick);
  1037. newmemo += ("-" + father.receiver_state);
  1038. if (cusInfo != null)
  1039. {
  1040. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  1041. }
  1042. if (isMulity)
  1043. {
  1044. newmemo += "-[C" + orderIndex + "]";
  1045. }
  1046. entity.seller_memo = newmemo;
  1047. if (ishave)
  1048. {
  1049. entity.Update();
  1050. }
  1051. else
  1052. entity.Create();
  1053. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "推送生成:" + entity.seller_memo, entity.OrderState);
  1054. }
  1055. public static int getOldCusByBuyer(string buyer)
  1056. {
  1057. string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
  1058. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  1059. foreach (DataRow dr in dt.Rows)
  1060. {
  1061. if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"])!= Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
  1062. {
  1063. return Convert.ToInt32(dr["DesignUserId"]);
  1064. }
  1065. }
  1066. return 0;
  1067. }
  1068. public static int getProductIdByName(string proName)
  1069. {
  1070. string dname = proName;
  1071. if(dname == "暧心贴")
  1072. {
  1073. dname = "暖心贴";
  1074. }
  1075. string sql = "select top 1 * from ce_erpproduct where PType='" + dname + "';";
  1076. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  1077. if (dt.Rows.Count > 0)
  1078. {
  1079. return Convert.ToInt32(dt.Rows[0]["ID"]);
  1080. }
  1081. return 0;
  1082. }
  1083. public static string getShopSNameByName(string seller_nick)
  1084. {
  1085. string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  1086. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  1087. if (dt.Rows.Count > 0)
  1088. {
  1089. return Convert.ToString(dt.Rows[0]["SName"]);
  1090. }
  1091. return "";
  1092. }
  1093. //public static string getShopRealName(string seller_nick)
  1094. //{
  1095. // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  1096. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1097. // if (dt.Rows.Count > 0)
  1098. // {
  1099. // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
  1100. // return Convert.ToString(dt.Rows[0]["ShopName"]);
  1101. // }
  1102. // return seller_nick;
  1103. //}
  1104. //补差价单 关联
  1105. public static DataRow getRelationOrder(string buyer,string sampTid)
  1106. {
  1107. string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer+"' and seller_memo not like '%补差价%' and tid<>'"+sampTid+"' order by id desc";
  1108. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  1109. if (dt.Rows.Count > 0)
  1110. {
  1111. DataRow need = dt.Rows[0];
  1112. if (dt.Rows.Count == 1)
  1113. {
  1114. return need;
  1115. }
  1116. int idx = 0;
  1117. foreach(DataRow dr in dt.Rows)
  1118. {
  1119. if (idx != 0)
  1120. {
  1121. int day = Convert.ToDateTime(need["pay_time"]).Day;
  1122. int nday = Convert.ToDateTime(dr["pay_time"]).Day;
  1123. if (day==nday)
  1124. {
  1125. need = dr;
  1126. }
  1127. }
  1128. idx++;
  1129. }
  1130. return need;
  1131. }
  1132. return null;
  1133. }
  1134. public static DataRow getUserInfoByAccount(string account)
  1135. {
  1136. string sql = "select * from view_erpuser where Account='"+account+"'";
  1137. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1138. if (dt != null && dt.Rows.Count > 0)
  1139. {
  1140. return dt.Rows[0];
  1141. }
  1142. return null;
  1143. }
  1144. public static void erp_TradeSuccess(string content)
  1145. {
  1146. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  1147. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  1148. //if (status == "TRADE_FINISHED")
  1149. //{
  1150. StringBuilder sql = new StringBuilder();
  1151. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]);
  1152. sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成);
  1153. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]);
  1154. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1155. //}
  1156. }
  1157. public static void erp_TradeSellerShip(string content)
  1158. {
  1159. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  1160. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  1161. //if (status == "WAIT_BUYER_CONFIRM_GOODS")
  1162. //{
  1163. StringBuilder sql = new StringBuilder();
  1164. //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState
  1165. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  1166. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  1167. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1168. //}
  1169. }
  1170. public static void erp_TradePartlyRefund(string content)
  1171. {
  1172. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  1173. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  1174. //if (status == "TRADE_CLOSED")
  1175. //{
  1176. StringBuilder sql = new StringBuilder();
  1177. sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]);
  1178. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]);
  1179. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭,1, dics["tid"]);
  1180. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1181. LogHelper.addLog(dics["tid"].ToString(),0,"客户申请退款,已确认", (int)OrderState.交易关闭) ;
  1182. //}
  1183. }
  1184. public static void Api_TmcTradeMsg(string res)
  1185. {
  1186. Api_tmc_trade_info_Obj fullObj = null;
  1187. if (res == "") return;
  1188. try
  1189. {
  1190. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  1191. //res = res.Replace(" ", "");
  1192. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  1193. }
  1194. catch (Exception ex)
  1195. {
  1196. XLog.SaveLog(0, res + "|1|"+ex.Message);
  1197. }
  1198. if (fullObj == null)
  1199. {
  1200. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  1201. return;
  1202. }
  1203. Content tObj = fullObj.content;
  1204. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  1205. if(tObj.status== "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  1206. {
  1207. return;
  1208. }
  1209. bool isCreate = false;
  1210. CeErpTrade trade = null;
  1211. trade = CeErpTrade.Get(tObj.refOid);
  1212. if (trade == null)
  1213. {
  1214. isCreate = true;
  1215. trade = new CeErpTrade();
  1216. trade.tid = tObj.refOid;
  1217. trade.type = tObj.refType;
  1218. trade.price = Convert.ToDouble(tObj.totalPrice);
  1219. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  1220. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  1221. trade.created = StampToDateTime(tObj.orderTime);
  1222. if (tObj.payTime != null && tObj.payTime.Length > 0)
  1223. {
  1224. trade.pay_time = StampToDateTime(tObj.payTime);
  1225. }
  1226. trade.buyer_nick = tObj.openBuyerNick;
  1227. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  1228. trade.seller_nick = tObj.openSellerNick;
  1229. trade.payment = Convert.ToDouble(tObj.payment);
  1230. //trade.receiver_name = tObj.receiver_name;
  1231. trade.receiver_state = tObj.receiverState;
  1232. trade.receiver_city = tObj.receiverCity;
  1233. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  1234. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  1235. }
  1236. if (tObj.posCode != null)trade.posCode = tObj.posCode;
  1237. trade.status = tObj.status;
  1238. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  1239. //{
  1240. //}
  1241. trade.seller_flag = tObj.flag;
  1242. if (tObj.modifyTime != null && tObj.modifyTime.Length>0)
  1243. {
  1244. trade.modified = StampToDateTime(tObj.modifyTime);
  1245. }
  1246. if ( tObj.finishTime!=null && tObj.finishTime.Length>0)
  1247. {
  1248. trade.end_time = StampToDateTime(tObj.finishTime);
  1249. }
  1250. if (tObj.shippingTime != null && tObj.shippingTime.Length>0)
  1251. {
  1252. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  1253. }
  1254. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  1255. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  1256. bool isSellerMemoChange = false;
  1257. if (trade.seller_memo != tObj.sellerMemo)
  1258. {
  1259. isSellerMemoChange = true;
  1260. }
  1261. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  1262. if (isCreate)
  1263. {
  1264. trade.Create();
  1265. }
  1266. else
  1267. {
  1268. trade.Update();
  1269. }
  1270. if (tObj.status == "CLOSE")
  1271. {
  1272. StringBuilder sql = new StringBuilder();
  1273. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}' where tid='{1}' and ctid not like '%S_%';", (int)OrderState.交易关闭, tObj.refOid);
  1274. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1275. LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
  1276. return;
  1277. }
  1278. else if (tObj.status == "COMPLETE")
  1279. {
  1280. StringBuilder sql = new StringBuilder();
  1281. sql.AppendFormat("update ce_ErpTradeCell set OrderState={1},IsUrgency=0 where IsPreDelivery=0 and tid='{0}' and ctid not like '%C_%' and ctid not like '%S_%';", tObj.refOid, (int)OrderState.交易完成);
  1282. sql.AppendFormat("update ce_ErpTradeCell set OrderState={1},IsUrgency=0 where IsPreDelivery=0 and tid='{0}' and ctid like '%C_%' and OrderState>5 and ctid not like '%S_%';", tObj.refOid, (int)OrderState.交易完成);
  1283. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1284. return;
  1285. }
  1286. else if (tObj.status == "SHIPPED")//已发货
  1287. {
  1288. StringBuilder sql = new StringBuilder();
  1289. sql.AppendFormat("update ce_ErpTradeCell set OrderState={1} where IsPreDelivery=0 and tid='{0}' and ctid not like '%C_%' and ctid not like '%S_%';", tObj.refOid, (int)OrderState.已发货);
  1290. sql.AppendFormat("update ce_ErpTradeCell set OrderState={1} where IsPreDelivery=0 and tid='{0}' and ctid like '%C_%' and OrderState>5 and ctid not like '%S_%';", tObj.refOid, (int)OrderState.已发货);
  1291. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1292. return;
  1293. }
  1294. bool isXianhuo = false;
  1295. string xianhuoMemo = "(" + trade.tid + ")现货-";
  1296. try
  1297. {
  1298. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  1299. {
  1300. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  1301. bool isCreateOrder = false;
  1302. if (order == null)
  1303. {
  1304. order = new CeErpTradeOrder();
  1305. isCreateOrder = true;
  1306. }
  1307. order.tid = trade.tid;
  1308. order.oid = item.refOlId;
  1309. order.buyer_nick = trade.buyer_nick;
  1310. if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS" || item.refundStatus == "REJECT_REFUNDED")
  1311. {
  1312. CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid);
  1313. if (refund == null)
  1314. {
  1315. refund = new CeErpTradeRefund();
  1316. refund.refund_id = tObj.refOid;
  1317. refund.tid = tObj.refOid;
  1318. //refund.oid = item.oid;
  1319. refund.created = StampToDateTime(tObj.orderTime);
  1320. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  1321. {
  1322. refund.modified = StampToDateTime(tObj.modifyTime);
  1323. }
  1324. refund.status = tObj.refundStatus;
  1325. refund.order_status = tObj.status;
  1326. //refund.good_status = item.good_status;
  1327. refund.payment = tObj.payment;
  1328. refund.refund_fee = tObj.payment;
  1329. //refund.refund_phase = item.refund_phase;
  1330. //refund.reason = item.reason;
  1331. //refund.describe = item.desc;
  1332. refund.buyer_nick = tObj.openBuyerNick;
  1333. refund.seller_nick = tObj.openSellerNick;
  1334. refund.total_fee = tObj.payment;
  1335. //refund.has_good_return = item.has_good_return;
  1336. refund.RefundState = 1;
  1337. refund.Create();
  1338. StringBuilder sql = new StringBuilder();
  1339. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund=1 where tid='{1}' and ctid not like '%S_%';", (int)OrderState.交易关闭, tObj.refOid);
  1340. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1341. LogHelper.addLog(tObj.refOid, 0, "已退款,交易关闭", (int)OrderState.交易关闭);
  1342. }
  1343. }
  1344. else if(item.refundStatus == "REFUNDING")
  1345. {
  1346. StringBuilder sql = new StringBuilder();
  1347. sql.AppendFormat("update CE_ErpTradeCell set IsRefund=2 where tid='{0}' and ctid not like '%S_%';", tObj.refOid);
  1348. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1349. LogHelper.addLog(tObj.refOid, 0, "申请退款中");
  1350. }
  1351. else if(item.refundStatus == "NO_REFUND" && order.refund_status!= "NO_REFUND" && isCreateOrder==false)
  1352. {
  1353. StringBuilder sql = new StringBuilder();
  1354. sql.AppendFormat("update CE_ErpTradeCell set IsRefund=0 where tid='{0}' and ctid not like '%S_%';", tObj.refOid);
  1355. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  1356. LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
  1357. }
  1358. order.refund_status = item.refundStatus;
  1359. order.status = trade.status;
  1360. order.title = item.title;
  1361. order.price = Convert.ToDouble(item.price);
  1362. if (item.picPath != null)
  1363. order.pic_path = item.picPath;
  1364. order.num = Convert.ToDouble(item.num.ToString());
  1365. order.payment = Convert.ToDouble(item.price);
  1366. //order.adjust_fee = Convert.ToDouble(item.price);
  1367. if (item.refSkuId != null && item.standards != null && item.standards.IndexOf("现货") != -1 && item.standards.IndexOf("定制") == -1)
  1368. {
  1369. order.sku_properties_name = item.standards;
  1370. order.sku_id = item.refSkuId;
  1371. isXianhuo = true;
  1372. xianhuoMemo += order.sku_properties_name;
  1373. }
  1374. if (isCreateOrder)
  1375. {
  1376. order.Create();
  1377. }
  1378. else
  1379. {
  1380. order.Update();
  1381. }
  1382. }
  1383. }
  1384. catch(Exception ex)
  1385. {
  1386. XLog.SaveLog(0, res + "|order表" + ex.Message);
  1387. }
  1388. if (isXianhuo)
  1389. {
  1390. xianhuoMemo += "-";
  1391. xianhuoMemo += trade.seller_nick;
  1392. }
  1393. if (isCreate == false) {
  1394. if (isSellerMemoChange)
  1395. {
  1396. try
  1397. {
  1398. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1399. }
  1400. catch (Exception ex)
  1401. {
  1402. XLog.SaveLog(0, res + "|2|" + ex.Message);
  1403. }
  1404. }
  1405. return;
  1406. }
  1407. //cell表创建
  1408. CeErpTradeCell entity = null;
  1409. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  1410. if (entity == null)
  1411. {
  1412. try
  1413. {
  1414. entity = new CeErpTradeCell();
  1415. entity.ctid = tObj.refOid;
  1416. entity.tid = tObj.refOid;
  1417. entity.seller_memo = "";
  1418. entity.payment = Convert.ToDouble(tObj.payment);
  1419. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  1420. if (isXianhuo)
  1421. {
  1422. entity.OrderState = 6; //下单完成
  1423. entity.seller_memo = xianhuoMemo;
  1424. entity.SupplierId = 2; //领淘本部
  1425. }
  1426. entity.Create();
  1427. }
  1428. catch (Exception ex)
  1429. {
  1430. XLog.SaveLog(0, res + "|cell创建" + ex.Message);
  1431. }
  1432. }
  1433. if (tObj.sellerMemo.Length > 0)
  1434. {
  1435. try
  1436. {
  1437. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1438. }
  1439. catch (Exception ex)
  1440. {
  1441. XLog.SaveLog(0, res + "|3|" + ex.Message);
  1442. }
  1443. }
  1444. //生成档案客户信息
  1445. insertCustomerInfo(tObj);
  1446. }
  1447. public static DateTime StampToDateTime(string timeStamp)
  1448. {
  1449. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  1450. long lTime = long.Parse(timeStamp + "0000");
  1451. TimeSpan toNow = new TimeSpan(lTime);
  1452. return dateTimeStart.Add(toNow);
  1453. }
  1454. public static void Api_Tmc_CreateNewOrder(string res)
  1455. {
  1456. Api_trade_fullinfo_get_response_Obj fullObj = null;
  1457. if (res == "") return;
  1458. try
  1459. {
  1460. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  1461. //res = res.Replace(" ", "");
  1462. fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
  1463. }
  1464. catch (Exception ex)
  1465. {
  1466. XLog.SaveLog(0, ex.Message);
  1467. }
  1468. if (fullObj == null)
  1469. {
  1470. Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
  1471. return;
  1472. }
  1473. ContentItem tObj = null;
  1474. if (fullObj.response.data.content.Count > 0) {
  1475. tObj = fullObj.response.data.content[0];
  1476. }
  1477. if (tObj == null)
  1478. {
  1479. return;
  1480. }
  1481. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  1482. {
  1483. return;
  1484. }
  1485. List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
  1486. StringBuilder sql = new StringBuilder();
  1487. CeErpTrade td = CeErpTrade.Get(tObj.refOid);
  1488. if (td != null)
  1489. {
  1490. return;
  1491. }
  1492. CeErpTrade trade = new CeErpTrade();
  1493. trade.tid = tObj.refOid;
  1494. if (tObj.posCode != null)
  1495. trade.posCode = tObj.posCode;
  1496. //trade.num = tObj.num;
  1497. trade.status = tObj.status;
  1498. trade.seller_flag = tObj.flag;
  1499. trade.type = tObj.refType;
  1500. trade.price = Convert.ToDouble(tObj.totalPrice);
  1501. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  1502. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  1503. trade.created = StampToDateTime(tObj.orderTime);
  1504. if (tObj.payTime!=null)
  1505. {
  1506. trade.pay_time = StampToDateTime(tObj.payTime);
  1507. }
  1508. if ( tObj.modifyTime != null)
  1509. {
  1510. trade.modified = StampToDateTime(tObj.modifyTime);
  1511. }
  1512. if (tObj.finishTime != null)
  1513. {
  1514. trade.end_time = StampToDateTime(tObj.finishTime);
  1515. }
  1516. trade.buyer_nick = tObj.openBuyerNick;
  1517. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  1518. trade.seller_nick = tObj.openSellerNick;
  1519. trade.payment = Convert.ToDouble(tObj.payment);
  1520. //trade.receiver_name = tObj.receiver_name;
  1521. trade.receiver_state = tObj.receiverState;
  1522. trade.receiver_city = tObj.receiverCity;
  1523. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  1524. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  1525. //trade.receiver_address = tObj.receiver_address;
  1526. //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  1527. //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  1528. //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  1529. //{
  1530. // trade.consign_time = tObj.consign_time;
  1531. //}
  1532. if ( tObj.shippingTime != null)
  1533. {
  1534. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  1535. }
  1536. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  1537. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  1538. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  1539. trade.Create();
  1540. bool isXianhuo = false;
  1541. string xianhuoMemo = "(" + trade.tid + ")现货-";
  1542. foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
  1543. {
  1544. CeErpTradeOrder order = new CeErpTradeOrder();
  1545. order.tid = trade.tid;
  1546. order.oid = item.refOlId;
  1547. order.buyer_nick = trade.buyer_nick;
  1548. order.refund_status = item.refundStatus;
  1549. order.status = trade.status;
  1550. order.title = item.title;
  1551. order.price = Convert.ToDouble(item.price);
  1552. if(item.picPath!=null)
  1553. order.pic_path = item.picPath;
  1554. order.num = Convert.ToDouble(item.num.ToString());
  1555. order.payment = Convert.ToDouble(item.price);
  1556. //order.adjust_fee = Convert.ToDouble(item.price);
  1557. if (item.refSkuId != null && item.standards != null && item.standards.IndexOf("现货") != -1 && item.standards.IndexOf("定制")==-1)
  1558. {
  1559. order.sku_properties_name = item.standards;
  1560. order.sku_id = item.refSkuId;
  1561. isXianhuo = true;
  1562. xianhuoMemo += order.sku_properties_name;
  1563. }
  1564. order.Create();
  1565. }
  1566. if (isXianhuo)
  1567. {
  1568. xianhuoMemo += "-";
  1569. xianhuoMemo += trade.seller_nick;
  1570. }
  1571. CeErpTradeCell entity = null;
  1572. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  1573. if (entity == null)
  1574. {
  1575. try
  1576. {
  1577. entity = new CeErpTradeCell();
  1578. entity.ctid = tObj.refOid;
  1579. entity.tid = tObj.refOid;
  1580. entity.payment = Convert.ToDouble(tObj.payment);
  1581. if (isXianhuo)
  1582. {
  1583. entity.OrderState = 6;//现货直接下单完成
  1584. entity.seller_memo = xianhuoMemo;
  1585. entity.SupplierId = 2; //领淘本部
  1586. }
  1587. entity.Create();
  1588. }
  1589. catch (Exception ex)
  1590. {
  1591. XLog.SaveLog(0, ex.Message);
  1592. }
  1593. }
  1594. if (tObj.sellerMemo.Length > 0)
  1595. {
  1596. try
  1597. {
  1598. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1599. }
  1600. catch (Exception ex)
  1601. {
  1602. XLog.SaveLog(0, res + "|" + ex.Message);
  1603. }
  1604. }
  1605. ////生成档案客户信息
  1606. //insertCustomerInfo(tObj);
  1607. }
  1608. public static void insertCustomerInfo(Content Obj)
  1609. {
  1610. CeErpCustomer cus = null;
  1611. cus = CeErpCustomer.GetByNick(Obj.openBuyerNick);
  1612. if (cus != null)
  1613. {
  1614. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  1615. //cus.phone = Obj.receiver_mobile;
  1616. TimeSpan tsday = StampToDateTime(Obj.payTime).Subtract((DateTime)cus.lastbuy_time);
  1617. cus.buy_day = tsday.Days;
  1618. cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
  1619. cus.buy_count = cus.buy_count + 1;
  1620. cus.lastbuy_time = StampToDateTime(Obj.payTime);
  1621. cus.Update();
  1622. }
  1623. else
  1624. {
  1625. try
  1626. {
  1627. cus = new CeErpCustomer();
  1628. cus.buyer_nick = Obj.openBuyerNick;
  1629. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  1630. //cus.phone = Obj.receiver_mobile;
  1631. cus.buy_day = 0;
  1632. cus.buy_count = 1;
  1633. cus.lastbuy_time = StampToDateTime(Obj.payTime);
  1634. cus.total_fee = Convert.ToDouble(Obj.payment);
  1635. cus.Create();
  1636. }
  1637. catch (Exception ex)
  1638. {
  1639. XLog.SaveLog(0, ex.Message);
  1640. }
  1641. }
  1642. }
  1643. //接收到--新订单生成消息
  1644. public static void API_Tmc_TradeBuyerPay(string content)
  1645. {
  1646. Api_tmc_trade_info_Obj fullObj = null;
  1647. if (content == "") return;
  1648. try
  1649. {
  1650. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  1651. //res = res.Replace(" ", "");
  1652. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  1653. }
  1654. catch (Exception ex)
  1655. {
  1656. }
  1657. if (fullObj == null)
  1658. {
  1659. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  1660. return;
  1661. }
  1662. Content tObj = fullObj.content;
  1663. string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
  1664. Api_Tmc_CreateNewOrder(res);
  1665. }
  1666. //推送接收到卖家备注修改
  1667. public static void API_Tmc_TradeMemoModified(string content)
  1668. {
  1669. Api_tmc_trade_info_Obj fullObj = null;
  1670. if (content == "") return;
  1671. try
  1672. {
  1673. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  1674. //res = res.Replace(" ", "");
  1675. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  1676. }
  1677. catch (Exception ex)
  1678. {
  1679. }
  1680. if (fullObj == null)
  1681. {
  1682. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  1683. return;
  1684. }
  1685. Content tObj = fullObj.content;
  1686. //原始表--没有这个单,不能拆分
  1687. CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
  1688. if (mainEn == null) return;
  1689. createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
  1690. }
  1691. }
  1692. }