tmcHelper.cs 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509
  1. using BizCom;
  2. using Microsoft.SqlServer.Server;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NHibernate.Mapping;
  6. using SiteCore;
  7. using SiteCore.Handler;
  8. using SiteCore.taobao;
  9. using SiteCore.taoObj;
  10. using SQLData;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Data.SqlClient;
  15. using System.Linq;
  16. using System.Text;
  17. using static SiteCore.taoObj.Api_tmc_trade_info_Obj;
  18. using static SiteCore.taoObj.Api_trade_fullinfo_get_response_Obj;
  19. using static SiteCore.taoObj.Api_trade_info;
  20. using static SiteCore.taoObj.dataShopResponseVo;
  21. using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
  22. using static SiteCore.taoObj.Trade_fullinfo_get_response_Obj;
  23. using static SiteCore.taoObj.work_core_vo;
  24. //status可选值:
  25. //* TRADE_NO_CREATE_PAY(没有创建支付宝交易)
  26. //* WAIT_BUYER_PAY(等待买家付款)
  27. //* SELLER_CONSIGNED_PART(卖家部分发货)
  28. //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款)
  29. //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货)
  30. //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用)
  31. //* TRADE_FINISHED(交易成功)
  32. //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭)
  33. //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易)
  34. //* PAY_PENDING(国际信用卡支付付款确认中)
  35. //* WAIT_PRE_AUTH_CONFIRM(0元购合约中)
  36. namespace SiteCore
  37. {
  38. /// <summary>
  39. /// 同步推送处理
  40. /// </summary>
  41. public class tmcHelper
  42. {
  43. public static int RemoveEmptyEntries { get; private set; }
  44. // case "taobao_trade_TradeCreate"://创建淘宝交易消息
  45. // {
  46. // break;
  47. // }
  48. // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息
  49. // case "taobao_trade_TradeMemoModified"://交易备注修改消息
  50. // case "taobao_trade_TradeRated"://交易评价变更消息
  51. // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款
  52. // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货)
  53. // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息
  54. // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息
  55. // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息
  56. // case "taobao_trade_TradeSellerShip"://卖家发货消息
  57. // case "taobao_trade_TradeClose"://关闭交易消息
  58. // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息
  59. // case "taobao_trade_TradeModifyFee"://修改交易费用消息
  60. public static string GetUTF8String(byte[] buffer)
  61. {
  62. if (buffer == null)
  63. return null;
  64. if (buffer.Length <= 3)
  65. {
  66. return Encoding.UTF8.GetString(buffer);
  67. }
  68. byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf };
  69. if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2])
  70. {
  71. return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
  72. }
  73. return Encoding.UTF8.GetString(buffer);
  74. }
  75. /// <summary>
  76. /// 交易订单关闭
  77. /// </summary>
  78. /// <param name="content"></param>
  79. public static void erp_CloseTrade(string content)
  80. {
  81. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  82. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  83. if (status == "TRADE_CLOSED_BY_TAOBAO")
  84. {
  85. StringBuilder sql = new StringBuilder();
  86. sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]);
  87. sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭);
  88. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]);
  89. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  90. //消息通知
  91. }
  92. }
  93. //接收到--新订单生成消息
  94. public static void erp_TradeBuyerPay(string content)
  95. {
  96. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  97. string tid = dics["tid"].ToString();
  98. string sellerNick = dics["seller_nick"].ToString();
  99. string sessionkey = taobaoHelper.ShopKeyDics[sellerNick];
  100. string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test();
  101. createNewOrder(res);
  102. }
  103. //创建新订单
  104. public static void createNewOrder(string res)
  105. {
  106. Trade_fullinfo_get_response_Obj fullObj = null;
  107. if (res == "") return;
  108. try
  109. {
  110. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  111. //res = res.Replace(" ", "");
  112. fullObj = JsonConvert.DeserializeObject<Trade_fullinfo_get_response_Obj>(res);
  113. }
  114. catch (Exception ex)
  115. {
  116. }
  117. if (fullObj == null)
  118. {
  119. Console.WriteLine("Trade_fullinfo_get_response_Obj isNull");
  120. return;
  121. }
  122. Trade tObj = fullObj.trade_fullinfo_get_response.trade;
  123. Orders orderList = tObj.orders;
  124. StringBuilder sql = new StringBuilder();
  125. CeErpTrade td = CeErpTrade.Get(tObj.tid);
  126. if (td != null)
  127. {
  128. //已经存在了,就不要再继续创建了;
  129. return;
  130. }
  131. //原始单创建
  132. CeErpTrade trade = new CeErpTrade();
  133. trade.tid = tObj.tid;
  134. trade.num = tObj.num;
  135. trade.status = tObj.status;
  136. trade.type = tObj.type;
  137. trade.price = Convert.ToDouble(tObj.price);
  138. trade.discount_fee = Convert.ToDouble(tObj.discount_fee);
  139. trade.total_fee = Convert.ToDouble(tObj.total_fee);
  140. trade.created = tObj.created;
  141. if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null)
  142. {
  143. trade.pay_time = tObj.pay_time;
  144. }
  145. if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null)
  146. {
  147. trade.modified = tObj.modified;
  148. }
  149. if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null)
  150. {
  151. trade.end_time = tObj.end_time;
  152. }
  153. trade.buyer_nick = tObj.buyer_nick;
  154. trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  155. trade.seller_nick = tObj.seller_nick;
  156. trade.payment = Convert.ToDouble(tObj.payment);
  157. trade.receiver_name = tObj.receiver_name;
  158. trade.receiver_state = tObj.receiver_state;
  159. trade.receiver_city = tObj.receiver_city;
  160. trade.receiver_town = GetNoNullValue_string(tObj.receiver_town);
  161. trade.receiver_district = GetNoNullValue_string(tObj.receiver_district);
  162. trade.receiver_address = tObj.receiver_address;
  163. trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  164. trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  165. if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  166. {
  167. trade.consign_time = tObj.consign_time;
  168. }
  169. if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null)
  170. {
  171. trade.delivery_time = tObj.delivery_time;
  172. }
  173. trade.buyer_message = GetNoNullValue_string(tObj.buyer_message);
  174. trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo);
  175. trade.seller_memo = GetNoNullValue_string(tObj.seller_memo);
  176. trade.Create();
  177. //查询是否有退款记录
  178. CeErpSpecialRefund ceErpSpecialRefund = new CeErpSpecialRefund();
  179. ceErpSpecialRefund = CeErpSpecialRefund.GetByTid(trade.tid);
  180. if (ceErpSpecialRefund != null)
  181. {
  182. refundTmcHelper.Api_TmcRefundMsg(ceErpSpecialRefund.refxml);
  183. ceErpSpecialRefund.whethernotify = 1;
  184. ceErpSpecialRefund.Update();
  185. }
  186. bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注
  187. string xianhuoMemo = "(" + trade.tid + ")现货-";
  188. //order表创建
  189. foreach (Order item in orderList.order)
  190. {
  191. CeErpTradeOrder order = new CeErpTradeOrder();
  192. order.tid = trade.tid;
  193. order.oid = item.oid;
  194. order.buyer_nick = trade.buyer_nick;
  195. order.refund_status = item.refund_status;
  196. order.status = item.status;
  197. order.title = item.title;
  198. order.price = Convert.ToDouble(item.price);
  199. order.pic_path = item.pic_path;
  200. order.num = Convert.ToDouble(item.num.ToString());
  201. order.payment = Convert.ToDouble(item.payment);
  202. order.adjust_fee = Convert.ToDouble(item.adjust_fee);
  203. if (item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货") != -1)
  204. {
  205. order.sku_properties_name = item.sku_properties_name;
  206. order.sku_id = item.sku_id;
  207. isXianhuo = true;
  208. xianhuoMemo += order.sku_properties_name;
  209. }
  210. order.Create();
  211. }
  212. if (isXianhuo)
  213. {
  214. xianhuoMemo += "-";
  215. xianhuoMemo += trade.seller_nick;
  216. }
  217. //cell表创建
  218. CeErpTradeCell entity = null;
  219. entity = CeErpTradeCell.GetByCtid(tObj.tid);
  220. if (entity == null)
  221. {
  222. try
  223. {
  224. entity = new CeErpTradeCell();
  225. entity.ctid = tObj.tid;
  226. entity.tid = tObj.tid;
  227. entity.payment = Convert.ToDouble(tObj.payment);
  228. if (isXianhuo)
  229. {
  230. entity.OrderState = 5;
  231. entity.seller_memo = xianhuoMemo;
  232. }
  233. entity.Create();
  234. }
  235. catch (Exception ex)
  236. {
  237. XLog.SaveLog(0, ex.Message);
  238. }
  239. }
  240. //生成档案客户信息
  241. operateCustomer(tObj);
  242. }
  243. public static void operateCustomer(Trade Obj)
  244. {
  245. CeErpCustomer cus = null;
  246. cus = CeErpCustomer.GetByNick(Obj.buyer_nick);
  247. if (cus != null)
  248. {
  249. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  250. cus.phone = Obj.receiver_mobile;
  251. TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time);
  252. cus.buy_day = tsday.Days;
  253. cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
  254. cus.buy_count = cus.buy_count + 1;
  255. cus.lastbuy_time = Obj.pay_time;
  256. cus.Update();
  257. }
  258. else
  259. {
  260. try
  261. {
  262. cus = new CeErpCustomer();
  263. cus.buyer_nick = Obj.buyer_nick;
  264. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  265. cus.phone = Obj.receiver_mobile;
  266. cus.buy_day = 0;
  267. cus.buy_count = 1;
  268. cus.lastbuy_time = Obj.pay_time;
  269. cus.total_fee = Convert.ToDouble(Obj.payment);
  270. cus.Create();
  271. }
  272. catch (Exception ex)
  273. {
  274. XLog.SaveLog(0, ex.Message);
  275. }
  276. }
  277. }
  278. public static string GetNoNullValue_string(string value)
  279. {
  280. value = value.Replace("\n", " ");
  281. value = value.Replace("\r", " ");
  282. value = value.Replace("*", "x");
  283. if (value == null)
  284. {
  285. return "";
  286. }
  287. return value;
  288. }
  289. public static string GetNull_tostring(object value)
  290. {
  291. if (value == null)
  292. {
  293. return "";
  294. }
  295. return value.ToString();
  296. }
  297. //接收到--卖家修改备注消息
  298. public static void erp_TradeMemoModified(string content)
  299. {
  300. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  301. if (!dics.ContainsKey("seller_memo"))
  302. {
  303. return;
  304. }
  305. string tid = dics["tid"].ToString();
  306. string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO
  307. string buyer = dics["buyer_nick"].ToString();
  308. //原始表--没有这个单,不能拆分
  309. CeErpTrade mainEn = CeErpTrade.Get(tid);
  310. if (mainEn == null) return;
  311. createCellOrder(mainEn, tid, smemo, buyer);
  312. }
  313. //接收到--交易成功消息
  314. public static void erp_TradeSuccess(string content)
  315. {
  316. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  317. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  318. //if (status == "TRADE_FINISHED")
  319. //{
  320. StringBuilder sql = new StringBuilder();
  321. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]);
  322. sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成);
  323. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]);
  324. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  325. //}
  326. }
  327. //接收到--卖家发货消息
  328. public static void erp_TradeSellerShip(string content)
  329. {
  330. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  331. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  332. //if (status == "WAIT_BUYER_CONFIRM_GOODS")
  333. //{
  334. StringBuilder sql = new StringBuilder();
  335. //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState
  336. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  337. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  338. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  339. //}
  340. }
  341. //接收到买家子订单退款 并卖家确认
  342. public static void erp_TradePartlyRefund(string content)
  343. {
  344. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  345. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  346. //if (status == "TRADE_CLOSED")
  347. //{
  348. StringBuilder sql = new StringBuilder();
  349. sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]);
  350. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]);
  351. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭, 1, dics["tid"]);
  352. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  353. LogHelper.addLog(dics["tid"].ToString(), 0, "客户申请退款,已确认", (int)OrderState.交易关闭);
  354. //}
  355. }
  356. static List<string> postcodes = new List<string>()
  357. {
  358. "yujia","taolai","zhufan","dingyi","lingtao","yangguangmao","xinkeli","yuejia","maiyu","xiyinshuo"
  359. };
  360. public static void Api_TmcTradeMsg(string res)
  361. {
  362. Api_tmc_trade_info_Obj fullObj = null;
  363. if (res == "") return;
  364. try
  365. {
  366. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  367. //res = res.Replace(" ", "");
  368. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  369. }
  370. catch (Exception ex)
  371. {
  372. XLog.SaveLog(0, res + "|1|" + ex.Message);
  373. }
  374. if (fullObj == null)
  375. {
  376. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  377. XLog.SaveLog(0, "Api_tmc_trade_info_Obj isNull");
  378. return;
  379. }
  380. Content tObj = fullObj.content;
  381. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  382. //未付款,未成功的单不需要 榆家不收
  383. if (tObj.status == "DELETED" || (tObj.status == "CANCEL" && tObj.refType != "JD") || tObj.status == "UNKNOWN" || tObj.status == "UNPAID" || postcodes.IndexOf(tObj.posCode) > -1)
  384. {
  385. return;
  386. }
  387. bool isCreate = false;
  388. CeErpTrade trade = null;
  389. trade = CeErpTrade.Get(tObj.refOid);
  390. tObj.sellerMemo = tObj.sellerMemo.Replace("默拍-发小礼物", "").Replace("电子稿-发小礼物", "").Replace("客户联系不上-发小礼物", "");
  391. if (trade == null)
  392. { //新生成订单的
  393. isCreate = true;
  394. trade = new CeErpTrade();
  395. trade.tid = tObj.refOid;
  396. trade.type = tObj.refType;
  397. trade.price = Convert.ToDouble(tObj.totalPrice);
  398. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  399. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  400. trade.created = StampToDateTime(tObj.orderTime);
  401. if (tObj.payTime != null && tObj.payTime.Length > 0)
  402. {
  403. trade.pay_time = StampToDateTime(tObj.payTime);
  404. }
  405. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  406. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  407. if (trade.seller_nick == "")
  408. {
  409. trade.seller_nick = getShopNameByECode(trade.posCode);
  410. tObj.openSellerNick = trade.seller_nick;
  411. }
  412. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  413. trade.payment = Convert.ToDouble(tObj.payment);
  414. //trade.receiver_name = tObj.receiver_name;
  415. }
  416. if (trade.buyer_nick == null || trade.buyer_nick.Length == 0)
  417. {
  418. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  419. }
  420. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  421. trade.receiver_state = tObj.receiverState;
  422. trade.receiver_city = tObj.receiverCity;
  423. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  424. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  425. if (trade.type == "JD" && tObj.status == "CANCEL")
  426. trade.status = "CLOSE";
  427. else
  428. trade.status = tObj.status;
  429. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  430. //{
  431. //}
  432. trade.seller_flag = tObj.flag;
  433. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  434. {
  435. trade.modified = StampToDateTime(tObj.modifyTime);
  436. }
  437. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  438. {
  439. trade.end_time = StampToDateTime(tObj.finishTime);
  440. }
  441. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  442. {
  443. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  444. }
  445. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  446. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  447. bool isSellerMemoChange = false;
  448. //备注修改
  449. tObj.sellerMemo = GetNoNullValue_string(tObj.sellerMemo);
  450. if (trade.seller_memo != tObj.sellerMemo)
  451. {
  452. isSellerMemoChange = true;
  453. }
  454. if (trade.seller_memo.Length != tObj.sellerMemo.Length)
  455. {
  456. isSellerMemoChange = true;
  457. }
  458. trade.seller_memo = tObj.sellerMemo;
  459. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  460. {
  461. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  462. {
  463. string[] acclist = tObj.sellerMemo.Split('-');
  464. List<string> list = new List<string>(acclist);
  465. string buyer_nick = "";
  466. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  467. {
  468. if (list.Count > 3)
  469. {
  470. buyer_nick = list[3];
  471. }
  472. }
  473. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  474. {
  475. if (list.Count > 1)
  476. {
  477. buyer_nick = list[1];
  478. }
  479. }
  480. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  481. {
  482. if (list.Count > 1)
  483. {
  484. buyer_nick = list[1];
  485. }
  486. }
  487. else if (trade.seller_memo.IndexOf("寄样") != -1)
  488. {
  489. if (list.Count > 3)
  490. {
  491. buyer_nick = list[3];
  492. }
  493. }
  494. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  495. {
  496. if (list.Count > 1)
  497. {
  498. buyer_nick = list[1];
  499. }
  500. }
  501. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  502. {
  503. if (list.Count > 1)
  504. {
  505. buyer_nick = list[1];
  506. }
  507. }
  508. else
  509. {
  510. if (list.Count > 5)
  511. {
  512. buyer_nick = list[5];
  513. }
  514. }
  515. tObj.sellerMemo = string.Join("-", list);
  516. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  517. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  518. }
  519. }
  520. if (isCreate)
  521. {
  522. trade.create_time = DateTime.Now;
  523. trade.Create();
  524. }
  525. else
  526. {
  527. if (tObj.status == "CLOSE")
  528. {
  529. trade.consign_time = DateTime.Now;
  530. }
  531. trade.Update();
  532. }
  533. //dataHelper.sendErpTradeInfo(new dataSendTradeBean(tObj));
  534. try
  535. {
  536. if (tObj.status == "CLOSE" || tObj.status == "CANCEL")
  537. {
  538. StringBuilder sql = new StringBuilder();
  539. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, tObj.refOid);
  540. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  541. ApiVo apiVo = new ApiVo();
  542. apiVo.actionName = "closeDesign";
  543. apiVo.orderNumber = tObj.refOid;
  544. //designHelper.API_WorkCore(apiVo);//closeDesign
  545. LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
  546. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  547. // removeOldCustomerInfo(trade);
  548. }
  549. else if (tObj.status == "COMPLETE")
  550. {
  551. StringBuilder sql = new StringBuilder();
  552. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, tObj.refOid);
  553. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  554. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  555. }
  556. else if (tObj.status == "SHIPPED")//已发货
  557. {
  558. StringBuilder sql = new StringBuilder();
  559. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tObj.refOid);
  560. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  561. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  562. }
  563. }
  564. catch (Exception ex)
  565. {
  566. XLog.SaveLog(0, res + "shipped:" + ex.Message);
  567. throw ex;
  568. }
  569. int xianhuoProductCount = 0;
  570. bool isXianhuo = false;
  571. string xianhuoMemo = "(" + trade.tid + ")现货-";
  572. bool isNew = true;
  573. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  574. int shopId = 0;
  575. if (nShop != null)
  576. {
  577. shopId = nShop.ID;
  578. }
  579. try
  580. {
  581. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  582. {
  583. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  584. bool isCreateOrder = false;
  585. if (order == null)
  586. {
  587. order = new CeErpTradeOrder();
  588. isCreateOrder = true;
  589. order.oid = item.refOlId;
  590. order.tid = trade.tid;
  591. order.buyer_nick = trade.buyer_nick;
  592. }
  593. if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS")
  594. {
  595. CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid);
  596. if (refund == null)
  597. {
  598. refund = new CeErpTradeRefund();
  599. refund.refund_id = tObj.refOid;
  600. refund.tid = tObj.refOid;
  601. //refund.oid = item.oid;
  602. refund.created = DateTime.Now;
  603. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  604. {
  605. refund.modified = StampToDateTime(tObj.modifyTime);
  606. }
  607. refund.status = item.refundStatus;
  608. refund.order_status = tObj.status;
  609. refund.payment = tObj.payment;
  610. refund.refund_fee = tObj.payment;
  611. refund.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  612. refund.buyer_id = GetNull_tostring(tObj.openBuyerId);
  613. refund.seller_nick = trade.seller_nick;
  614. refund.total_fee = tObj.payment;
  615. refund.RefundState = 1;//1待审核2待确认
  616. refund.Create();
  617. //cell订单 添加退款标记
  618. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  619. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  620. designHelper.API_refundOrder(tObj.refOid, "refundEd", "");
  621. LogHelper.addLog(tObj.refOid, 0, "已退款", (int)OrderState.交易关闭);
  622. }
  623. else
  624. {
  625. if (refund.status != item.refundStatus)
  626. {
  627. refund.modified = DateTime.Now;
  628. refund.status = item.refundStatus;
  629. refund.order_status = tObj.status;
  630. refund.Update();
  631. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  632. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  633. LogHelper.addLog(tObj.refOid, 0, "更新退款状态", (int)OrderState.交易关闭);
  634. }
  635. }
  636. }
  637. else if (item.refundStatus == "REFUNDING" && order.refund_status != "REFUNDING")
  638. {
  639. commonHelper.UpdateRefundOrderState(tObj.refOid, 1);
  640. designHelper.API_refundOrder(tObj.refOid, "refundIng", "");
  641. LogHelper.addLog(tObj.refOid, 0, "申请退款中");
  642. }
  643. else if (item.refundStatus == "NO_REFUND" && order.refund_status != "NO_REFUND" && isCreateOrder == false)
  644. {
  645. //CeErpTradeRefund.Del(tObj.refOid);
  646. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  647. designHelper.API_refundOrder(tObj.refOid, "refundCancel", "");
  648. LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
  649. }
  650. else if (item.refundStatus == "REJECT_REFUNDED" && order.refund_status != "REJECT_REFUNDED" && isCreateOrder == false)
  651. {
  652. //CeErpTradeRefund.Del(tObj.refOid);
  653. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  654. LogHelper.addLog(tObj.refOid, 0, "拒绝退货退款");
  655. }
  656. order.refund_status = item.refundStatus;
  657. order.status = trade.status;
  658. order.title = item.title;
  659. order.price = Convert.ToDouble(item.price);
  660. if (item.picUrl != null)
  661. order.pic_path = item.picUrl;
  662. order.num = Convert.ToDouble(item.num.ToString());
  663. order.payment = Convert.ToDouble(item.price);
  664. order.total_fee = Convert.ToDouble(item.totalFee);
  665. //order.adjust_fee = Convert.ToDouble(item.price);
  666. if (item.refSkuId != null && item.refSkuId != "")
  667. {
  668. order.sku_id = item.refSkuId;
  669. }
  670. if (item.standards != null && item.standards != "")
  671. {
  672. order.sku_properties_name = item.standards;
  673. }
  674. if (item.refSpuId != null && item.refSpuId != "")
  675. {
  676. order.spu_id = item.refSpuId;
  677. }
  678. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1 || item.standards.IndexOf("兔团团") != -1 || item.standards.IndexOf("帆布") != -1 || item.standards.IndexOf("手拉旗") != -1 || item.standards.IndexOf("kt") != -1 || item.standards.IndexOf("条幅") != -1 || item.standards.IndexOf("#") != -1) && item.standards.IndexOf("定制") == -1)
  679. {
  680. isXianhuo = true;
  681. xianhuoMemo += order.sku_properties_name;
  682. xianhuoMemo += ("-数量:" + order.num + ";");
  683. xianhuoProductCount += (int)order.num;
  684. if (isCreateOrder)
  685. {
  686. string goodsSql = "select * from CE_ErpBagShopGoods";
  687. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  688. if (goodsDt.Rows.Count > 0)
  689. {
  690. foreach (DataRow gdr in goodsDt.Rows)
  691. {
  692. string bname = gdr["bname"].ToString();
  693. string bsize = gdr["bsize"].ToString();
  694. string bcount = gdr["bcount"].ToString();
  695. if (bname.Length > 0 && order.sku_properties_name.IndexOf(bname) != -1)
  696. {
  697. order.bagName = bname;
  698. order.isBagOrder = 1;
  699. }
  700. if (bsize.Length > 0 && order.sku_properties_name.IndexOf(bsize) != -1)
  701. {
  702. order.bagSize = bsize;
  703. }
  704. if (bcount.Length > 0 && order.sku_properties_name.IndexOf(bcount) != -1)
  705. {
  706. order.bagCount = bcount;
  707. int bbcount = commonHelper.getIntCountFromString(bcount);
  708. order.bagRealCount = bbcount * (int)order.num;
  709. }
  710. }
  711. }
  712. }
  713. }
  714. if (isCreateOrder)
  715. {
  716. order.Create();
  717. CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(order.spu_id);
  718. //dataHelper.sendErpTradeOrderInfo(new dataSendTradeOrderBean(item, tObj));
  719. if (ceErpTradeSpu == null)
  720. {
  721. ceErpTradeSpu = new CeErpTradeSpu();
  722. ceErpTradeSpu.spuId = order.spu_id;
  723. ceErpTradeSpu.tid = order.tid;
  724. ceErpTradeSpu.createTime = DateTime.Now;
  725. dataSendSpuBean bean = new dataSendSpuBean();
  726. bean.ShortText1728890680485 = order.title;
  727. bean.ShortText1728890649488 = order.spu_id;
  728. bean.shopId = shopId.ToString();
  729. bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  730. dataResponseVo response = dataHelper.sendSpuInfo(bean);
  731. if (response != null)
  732. {
  733. if ("0".Equals(response.errcode))
  734. {
  735. ceErpTradeSpu.isSync = true;
  736. }
  737. else
  738. {
  739. ceErpTradeSpu.message = response.errmsg;
  740. }
  741. }
  742. ceErpTradeSpu.Create();
  743. }
  744. DateTime orderTime = ceErpTradeSpu.createTime ?? DateTime.MinValue;
  745. if (DateTime.Compare(orderTime.AddDays(30), DateTime.Now) < 0)
  746. {
  747. isNew = false;
  748. }
  749. }
  750. else
  751. {
  752. order.Update();
  753. }
  754. }
  755. }
  756. catch (Exception ex)
  757. {
  758. XLog.SaveLog(0, res + "|order表:" + ex.Message);
  759. throw ex;
  760. }
  761. //if (isXianhuo)
  762. //{
  763. // xianhuoMemo += "-";
  764. // xianhuoMemo += trade.seller_nick;
  765. //}
  766. trade.IsNew = isNew;
  767. CeErpTradeCell entity = null;
  768. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  769. if (entity == null)
  770. {
  771. try
  772. {
  773. entity = new CeErpTradeCell();
  774. entity.ctid = tObj.refOid;
  775. //唯一标识
  776. entity.OrderSn = tObj.refOid;
  777. /*string orderSn = dataHelper.getSaleOrderSn();
  778. if (orderSn != "")
  779. {
  780. entity.OrderSn = orderSn;
  781. }*/
  782. entity.tid = tObj.refOid;
  783. entity.seller_memo = "";
  784. entity.payment = Convert.ToDouble(tObj.payment);
  785. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  786. if (tObj.payTime != null)
  787. {
  788. entity.pay_time = StampToDateTime(tObj.payTime);
  789. }
  790. entity.ShopId = shopId;
  791. if (isXianhuo)
  792. {
  793. entity.OrderState = 6;
  794. entity.seller_memo = xianhuoMemo;
  795. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  796. entity.IsXianHuo = 1;
  797. entity.FinishPlaceTime = entity.pay_time;
  798. entity.ProductCount = xianhuoProductCount.ToString();
  799. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  800. {
  801. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  802. if (trade.buyer_memo != "")
  803. {
  804. entity.OrderState = 2;
  805. entity.ProductId = 1;
  806. entity.IsXianHuo = 0;
  807. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  808. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  809. entity.seller_memo = xianhuoMemo;
  810. if (entity.ShopId != 0)
  811. {
  812. entity.OrderState = orderAudit(entity.ShopId);
  813. }
  814. }
  815. }
  816. else if (xianhuoMemo.IndexOf("#") != -1)
  817. {
  818. entity.SupplierId = 87;
  819. }
  820. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  821. {
  822. entity.SupplierId = 70;
  823. }
  824. else if (xianhuoMemo.IndexOf("兔团团") != -1)
  825. {
  826. entity.SupplierId = 101;
  827. }
  828. else if (xianhuoMemo.IndexOf("手拉旗") != -1)
  829. {
  830. entity.SupplierId = 108;
  831. }
  832. try
  833. {
  834. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  835. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  836. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  837. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  838. foreach (DataRow dr in goodsDt.Rows)
  839. {
  840. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  841. List<string> xianhuo = sqlMemo.Split(',').ToList();
  842. foreach (var item in xianhuo)
  843. {
  844. if (string.IsNullOrEmpty(item)) continue;
  845. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  846. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  847. if (item.IndexOf('-') > -1)
  848. {
  849. List<string> list = item.Split('-').ToList();
  850. material_map.Add(dr["id"].ToString(), list[0]);
  851. name_map.Add(dr["id"].ToString(), list[1]);
  852. }
  853. else
  854. {
  855. material_map.Add(dr["id"].ToString(), item);
  856. }
  857. material_list.Add(material_map);
  858. name_list.Add(name_map);
  859. }
  860. }
  861. List<string> materials = new List<string>();
  862. List<string> names = new List<string>();
  863. List<string> result = new List<string>();
  864. for (int i = 0; i < material_list.Count; i++)
  865. {
  866. Dictionary<string, string> map = material_list[i];
  867. foreach (var item in map)
  868. {
  869. if (xianhuoMemo.IndexOf(item.Value) > -1)
  870. {
  871. Dictionary<string, string> map2 = name_list[i];
  872. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  873. {
  874. foreach (var item1 in map2)
  875. {
  876. if (xianhuoMemo.IndexOf(item1.Value) > -1)
  877. {
  878. names.Add(item1.Key);
  879. materials.Add(item.Key);
  880. }
  881. }
  882. }
  883. else
  884. {
  885. materials.Add(item.Key);
  886. }
  887. }
  888. }
  889. }
  890. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  891. {
  892. result = names.Distinct().ToList();
  893. }
  894. else
  895. {
  896. result = materials.Distinct().ToList();
  897. }
  898. if (result.Count > 0)
  899. {
  900. Random rnd = new Random();
  901. int index = rnd.Next(result.Count);
  902. entity.SupplierId = int.Parse(result[index]);
  903. }
  904. }
  905. catch (Exception e)
  906. {
  907. XLog.SaveLog(0, res + "|现货匹配|" + e.Message);
  908. }
  909. if (isCreate)
  910. {
  911. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  912. if (oldRes > 0)
  913. {
  914. entity.IsOldCustomer = 1;
  915. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  916. }
  917. }
  918. //if (trade != null)
  919. //{
  920. // trade.seller_memo = xianhuoMemo;
  921. // trade.Update();
  922. //}
  923. }
  924. //if (xianhuoMemo.IndexOf("修改文字下单备注") != -1)
  925. //{
  926. // entity.OrderState = Convert.ToInt32(OrderState.待设计); // Convert.ToInt32(OrderState.待设计);
  927. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  928. // entity.WaitDesignTime = DateTime.Now;
  929. // entity.FinishPlaceTime = null;
  930. // entity.SupplierId = 0;
  931. // LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  932. //}
  933. entity.Create();
  934. CeErpTradeCellExtend.createInfo(entity.ctid);
  935. }
  936. catch (Exception ex)
  937. {
  938. XLog.SaveLog(0, res + "|cell创建" + ex.Message);
  939. }
  940. }
  941. if (tObj.sellerMemo == "物料")
  942. {
  943. entity.seller_memo = "(" + trade.tid + ")-物料";
  944. entity.OrderState = 6; //下单完成
  945. entity.WaitDesignTime = DateTime.Now;
  946. entity.FinishDesignTime = DateTime.Now;
  947. entity.StartDesignTime = DateTime.Now;
  948. entity.FinishPlaceTime = DateTime.Now;
  949. entity.IsSample = 1;
  950. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  951. entity.Update();
  952. }
  953. //else if (isXianhuo && trade.status== "NOT_SHIPPED")
  954. //{
  955. // entity.seller_memo = xianhuoMemo;
  956. // entity.IsXianHuo = 1;
  957. // entity.FinishPlaceTime = entity.pay_time;
  958. // entity.ProductCount = xianhuoProductCount.ToString();
  959. // if (xianhuoMemo.IndexOf("封酒贴") != -1)
  960. // {
  961. // if (trade.buyer_memo != "") //没设计之前
  962. // {
  963. // if(entity.OrderState <= 2)
  964. // {
  965. // entity.OrderState = 2; //买家有备注的要设计
  966. // }
  967. // entity.ProductId = 1;
  968. // entity.IsXianHuo = 0;
  969. // xianhuoMemo = xianhuoMemo.Replace("现货", "");
  970. // xianhuoMemo = xianhuoMemo.Replace(" ", "");
  971. // entity.seller_memo = xianhuoMemo;
  972. // }
  973. // }
  974. // else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  975. // {
  976. // entity.SupplierId = 70; //智涛
  977. // LogHelper.addLog(entity.ctid,0,"喜字贴纸现货到智涛待发货",0);
  978. // }
  979. // entity.Update();
  980. //}
  981. if (isSellerMemoChange)
  982. {
  983. try
  984. {
  985. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  986. }
  987. catch (Exception ex)
  988. {
  989. XLog.SaveLog(0, res + "|2|" + ex.Message);
  990. }
  991. }
  992. }
  993. public static void Api_TmcTradeMsg_Create(string res)
  994. {
  995. Api_tmc_trade_info_Obj fullObj = null;
  996. if (res == "") return;
  997. try
  998. {
  999. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  1000. //res = res.Replace(" ", "");
  1001. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  1002. }
  1003. catch (Exception ex)
  1004. {
  1005. XLog.SaveLog(0, res + "|1 create|" + ex.Message);
  1006. throw ex;
  1007. }
  1008. if (fullObj == null)
  1009. {
  1010. XLog.SaveLog(0, "create Api_tmc_trade_info_Obj isNull");
  1011. return;
  1012. }
  1013. Content tObj = fullObj.content;
  1014. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  1015. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  1016. {
  1017. return;
  1018. }
  1019. bool isCreate = false;
  1020. CeErpTrade trade = null;
  1021. trade = CeErpTrade.Get(tObj.refOid);
  1022. if (trade == null)
  1023. {
  1024. isCreate = true;
  1025. trade = new CeErpTrade();
  1026. trade.tid = tObj.refOid;
  1027. trade.type = tObj.refType;
  1028. trade.price = Convert.ToDouble(tObj.totalPrice);
  1029. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  1030. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  1031. trade.created = StampToDateTime(tObj.orderTime);
  1032. if (tObj.payTime != null && tObj.payTime.Length > 0)
  1033. {
  1034. trade.pay_time = StampToDateTime(tObj.payTime);
  1035. }
  1036. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  1037. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  1038. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  1039. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  1040. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  1041. if (trade.seller_nick == "")
  1042. {
  1043. trade.seller_nick = getShopNameByECode(trade.posCode);
  1044. }
  1045. trade.payment = Convert.ToDouble(tObj.payment);
  1046. //trade.receiver_name = tObj.receiver_name;
  1047. trade.receiver_state = tObj.receiverState;
  1048. trade.receiver_city = tObj.receiverCity;
  1049. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  1050. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  1051. }
  1052. trade.status = tObj.status;
  1053. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  1054. //{
  1055. //}
  1056. trade.seller_flag = tObj.flag;
  1057. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  1058. {
  1059. trade.modified = StampToDateTime(tObj.modifyTime);
  1060. }
  1061. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  1062. {
  1063. trade.end_time = StampToDateTime(tObj.finishTime);
  1064. }
  1065. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  1066. {
  1067. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  1068. }
  1069. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  1070. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  1071. bool isSellerMemoChange = false;
  1072. if (trade.seller_memo != tObj.sellerMemo)
  1073. {
  1074. isSellerMemoChange = true;
  1075. }
  1076. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  1077. if (isCreate)
  1078. {
  1079. trade.Create();
  1080. }
  1081. else
  1082. {
  1083. trade.Update();
  1084. }
  1085. int xianhuoProductCount = 0;
  1086. bool isXianhuo = false;
  1087. string xianhuoMemo = "(" + trade.tid + ")现货-";
  1088. try
  1089. {
  1090. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  1091. {
  1092. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  1093. bool isCreateOrder = false;
  1094. if (order == null)
  1095. {
  1096. order = new CeErpTradeOrder();
  1097. isCreateOrder = true;
  1098. }
  1099. order.tid = trade.tid;
  1100. order.oid = item.refOlId;
  1101. order.buyer_nick = trade.buyer_nick;
  1102. order.refund_status = item.refundStatus;
  1103. order.status = trade.status;
  1104. order.title = item.title;
  1105. order.price = Convert.ToDouble(item.price);
  1106. if (item.picUrl != null)
  1107. order.pic_path = item.picUrl;
  1108. order.num = Convert.ToDouble(item.num.ToString());
  1109. order.payment = Convert.ToDouble(item.price);
  1110. //order.adjust_fee = Convert.ToDouble(item.price);
  1111. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  1112. {
  1113. order.sku_properties_name = item.standards;
  1114. order.sku_id = item.refSkuId;
  1115. isXianhuo = true;
  1116. xianhuoMemo += order.sku_properties_name;
  1117. xianhuoMemo += ("-数量:" + order.num + "; ");
  1118. xianhuoProductCount += (int)order.num;
  1119. }
  1120. if (isCreateOrder)
  1121. {
  1122. order.Create();
  1123. }
  1124. else
  1125. {
  1126. order.Update();
  1127. }
  1128. }
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. XLog.SaveLog(0, res + "|create order表:" + ex.Message);
  1133. throw ex;
  1134. }
  1135. //if (isXianhuo)
  1136. //{
  1137. // xianhuoMemo += "-";
  1138. // xianhuoMemo += trade.seller_nick;
  1139. //}
  1140. CeErpTradeCell entity = null;
  1141. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  1142. if (entity == null)
  1143. {
  1144. try
  1145. {
  1146. entity = new CeErpTradeCell();
  1147. entity.ctid = tObj.refOid;
  1148. entity.tid = tObj.refOid;
  1149. entity.seller_memo = "";
  1150. entity.payment = Convert.ToDouble(tObj.payment);
  1151. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  1152. if (tObj.payTime != null)
  1153. {
  1154. entity.pay_time = StampToDateTime(tObj.payTime);
  1155. }
  1156. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  1157. int shopId = 0;
  1158. if (nShop != null)
  1159. {
  1160. shopId = nShop.ID;
  1161. }
  1162. entity.ShopId = shopId;
  1163. if (isXianhuo)
  1164. {
  1165. entity.FinishPlaceTime = DateTime.Now;
  1166. entity.OrderState = 6;
  1167. entity.seller_memo = xianhuoMemo;
  1168. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1169. entity.IsXianHuo = 1;
  1170. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  1171. {
  1172. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);
  1173. if (trade.buyer_memo != "")
  1174. {
  1175. entity.OrderState = 2;
  1176. entity.ProductId = 1;
  1177. entity.IsXianHuo = 0;
  1178. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  1179. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  1180. entity.seller_memo = xianhuoMemo;
  1181. if (entity.ShopId != 0)
  1182. {
  1183. entity.OrderState = orderAudit(entity.ShopId);
  1184. }
  1185. }
  1186. }
  1187. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  1188. {
  1189. entity.SupplierId = 70;
  1190. }
  1191. entity.FinishPlaceTime = entity.pay_time;
  1192. entity.ProductCount = xianhuoProductCount.ToString();
  1193. if (isCreate)
  1194. {
  1195. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1196. if (oldRes == 2)
  1197. {
  1198. entity.IsOldCustomer = 1;
  1199. entity.IsOldCustomerMore = 1;
  1200. }
  1201. else if (oldRes == 1)
  1202. {
  1203. entity.IsOldCustomer = 1;
  1204. }
  1205. }
  1206. //if (trade != null)
  1207. //{
  1208. // trade.seller_memo = xianhuoMemo;
  1209. // trade.Update();
  1210. //}
  1211. }
  1212. entity.Create();
  1213. }
  1214. catch (Exception ex)
  1215. {
  1216. XLog.SaveLog(0, res + "|create cell创建" + ex.Message);
  1217. throw ex;
  1218. }
  1219. }
  1220. if (isSellerMemoChange && trade.seller_memo.Length > 0)
  1221. {
  1222. try
  1223. {
  1224. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1225. }
  1226. catch (Exception ex)
  1227. {
  1228. XLog.SaveLog(0, res + "|2_create|" + ex.Message);
  1229. }
  1230. }
  1231. }
  1232. public static void createCellOrder(CeErpTrade father, string tid, string smemo, string buyer, bool isJump = false)
  1233. {
  1234. smemo = smemo.Replace("\r", " ");
  1235. smemo = smemo.Replace("\n", " ");
  1236. bool isNeedCellOrder = true;
  1237. //try
  1238. //{
  1239. string issql = "select * from ce_erptradecell where tid='" + tid + "';";
  1240. DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
  1241. if (ishavedt.Rows.Count > 0)
  1242. {
  1243. foreach (DataRow hdr in ishavedt.Rows)
  1244. {
  1245. if (smemo.IndexOf("封酒贴") != -1)
  1246. {
  1247. if (Convert.ToInt32(hdr["IsXianHuo"]) == 1 && Convert.ToInt32(hdr["OrderState"]) >= 4)
  1248. {
  1249. isNeedCellOrder = false;
  1250. break;
  1251. }
  1252. else if (Convert.ToInt32(hdr["IsXianHuo"]) == 0 && Convert.ToInt32(hdr["OrderState"]) > 2)
  1253. {
  1254. isNeedCellOrder = false;
  1255. break;
  1256. }
  1257. }
  1258. else if ((Convert.ToInt32(hdr["OrderState"]) > 2 && smemo.IndexOf("礼物") == -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("礼物") != -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("寄样") != -1))
  1259. {
  1260. isNeedCellOrder = false;
  1261. break;
  1262. }
  1263. }
  1264. if (isNeedCellOrder)
  1265. {
  1266. foreach (DataRow hdr in ishavedt.Rows)
  1267. {
  1268. if (hdr["ctid"].ToString().IndexOf("C") != -1)
  1269. {
  1270. string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
  1271. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. }
  1277. //}
  1278. //catch(Exception ex)
  1279. //{
  1280. // isNeedCellOrder = false;
  1281. // XLog.SaveLog(0, "推送是否需要重新生成判断出错"+ tid + ex.Message);
  1282. //}
  1283. if (isJump)
  1284. {
  1285. isNeedCellOrder = true;
  1286. LogHelper.addLog(tid, 0, "原单强制重新生成", 0);
  1287. }
  1288. //if (smemo.IndexOf("g") != -1)
  1289. //{
  1290. // smemo = smemo.Replace("g", "克");
  1291. //}
  1292. if (smemo.IndexOf("补差价") != -1)
  1293. {
  1294. CeErpTradeCell entity = null;
  1295. entity = CeErpTradeCell.GetByCtid(tid);
  1296. bool ishaveBu = true;
  1297. if (entity == null)
  1298. {
  1299. entity = new CeErpTradeCell();
  1300. entity.ctid = tid;
  1301. //唯一标识
  1302. entity.OrderSn = tid;
  1303. /*string orderSn = dataHelper.getSaleOrderSn();
  1304. if (orderSn != "")
  1305. {
  1306. entity.OrderSn = orderSn;
  1307. }*/
  1308. entity.tid = tid;
  1309. ishaveBu = false;
  1310. }
  1311. if (entity.ShopId == 0)
  1312. {
  1313. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1314. int shopId = 0;
  1315. if (nShop != null)
  1316. {
  1317. shopId = nShop.ID;
  1318. }
  1319. entity.ShopId = shopId;
  1320. }
  1321. if (father.type != "PDD")
  1322. {
  1323. if (entity.OrderState >= 5) return;
  1324. }
  1325. entity.seller_memo = smemo;
  1326. entity.payment = Convert.ToDouble(father.payment);
  1327. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1328. entity.pay_time = father.pay_time;
  1329. smemo = smemo.Replace(":", ":");
  1330. string[] listmemo = smemo.Split(':');
  1331. if (listmemo.Length > 1)
  1332. {
  1333. string maintid = listmemo[1];//System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", "");
  1334. string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'";
  1335. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1336. if (dt_bu.Rows.Count > 0)
  1337. {
  1338. entity.ptid = dt_bu.Rows[0]["tid"].ToString();
  1339. if (father.type != "PDD")
  1340. {
  1341. entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]);
  1342. }
  1343. entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]);
  1344. entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]);
  1345. entity.SupplierId = Convert.ToInt32(dt_bu.Rows[0]["SupplierId"]);
  1346. entity.seller_memo = "补差价:" + entity.ptid;
  1347. entity.payment = father.payment;
  1348. entity.IsSample = 2;
  1349. if (dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value)
  1350. {
  1351. entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]);
  1352. }
  1353. if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value)
  1354. {
  1355. entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]);
  1356. }
  1357. if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value)
  1358. {
  1359. entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]);
  1360. }
  1361. if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value)
  1362. {
  1363. entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]);
  1364. }
  1365. }
  1366. }
  1367. if (ishaveBu)
  1368. {
  1369. entity.Update();
  1370. }
  1371. else
  1372. {
  1373. father.create_time = DateTime.Now;
  1374. father.orderType = 20;
  1375. father.Update();
  1376. entity.Create();
  1377. CeErpTradeCellExtend.createInfo(entity.ctid, 20, 10);
  1378. }
  1379. ApiVo apiVo = new ApiVo();
  1380. apiVo.orderNumber = entity.ptid;
  1381. apiVo.payment = entity.payment;
  1382. apiVo.actionName = "repairDesign";
  1383. designHelper.API_WorkCore(apiVo);//repairDesign
  1384. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1385. CeErpSukuraData.createInfo(entity.ctid, 1);
  1386. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1387. isNeedCellOrder = false;
  1388. }
  1389. else if (smemo.IndexOf("拿样订单") != -1)
  1390. {
  1391. CeErpTradeCell entity = null;
  1392. entity = CeErpTradeCell.GetByCtid(tid);
  1393. if (entity == null)
  1394. {
  1395. if (entity.ShopId == 0)
  1396. {
  1397. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1398. int shopId = 0;
  1399. if (nShop != null)
  1400. {
  1401. shopId = nShop.ID;
  1402. }
  1403. entity.ShopId = shopId;
  1404. }
  1405. entity = new CeErpTradeCell();
  1406. entity.ctid = tid;
  1407. //唯一标识
  1408. entity.OrderSn = tid;
  1409. /* string orderSn = dataHelper.getSaleOrderSn();
  1410. if (orderSn != "")
  1411. {
  1412. entity.OrderSn = orderSn;
  1413. }*/
  1414. entity.tid = tid;
  1415. entity.seller_memo = smemo;
  1416. entity.payment = Convert.ToDouble(father.payment);
  1417. entity.pay_time = father.pay_time;
  1418. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1419. entity.OrderState = 6; //下单完成
  1420. entity.FinishPlaceTime = DateTime.Now;
  1421. entity.IsSample = 1;
  1422. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1423. entity.IsOldCustomer = 0;
  1424. father.create_time = DateTime.Now;
  1425. father.Update();
  1426. entity.Create();
  1427. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1428. }
  1429. else
  1430. {
  1431. entity.IsSample = 1;
  1432. entity.seller_memo = smemo;
  1433. entity.OrderState = 6;
  1434. entity.FinishPlaceTime = DateTime.Now;
  1435. entity.IsOldCustomer = 0;
  1436. entity.Update();
  1437. }
  1438. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1439. CeErpSukuraData.createInfo(entity.ctid, 1);
  1440. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1441. isNeedCellOrder = false;
  1442. }
  1443. if (isNeedCellOrder == false)
  1444. {
  1445. return;
  1446. }
  1447. if (smemo.IndexOf("*") != -1)
  1448. {
  1449. return;
  1450. }
  1451. if (smemo.IndexOf("{") != -1 && smemo.IndexOf("+") != -1)
  1452. {
  1453. createNewSplitFn(smemo, father);
  1454. return;
  1455. }
  1456. string[] memoList = null;
  1457. if (smemo.IndexOf(",") != -1)
  1458. {
  1459. smemo = smemo.Replace(',', ',');
  1460. }
  1461. if (smemo.IndexOf(",,") != -1)
  1462. {
  1463. return;
  1464. }
  1465. memoList = smemo.Split(',');
  1466. int orderIdx = 1;
  1467. int hebaoCount = 0;
  1468. bool isMulity = false;
  1469. if (memoList.Length > 1)
  1470. {
  1471. isMulity = true;
  1472. foreach (string mstr in memoList)
  1473. {
  1474. if (mstr.IndexOf("合包") != -1)
  1475. {
  1476. hebaoCount += 1;
  1477. }
  1478. }
  1479. }
  1480. if (hebaoCount == 1)
  1481. {
  1482. createHebaoCell(isMulity, 0, smemo, father);
  1483. }
  1484. else
  1485. {
  1486. decimal hePrice = Convert.ToDecimal(father.payment); //合包价格
  1487. string needHebaoItem = "";
  1488. foreach (string item in memoList)
  1489. {
  1490. if (item.IndexOf("合包") != -1)
  1491. {
  1492. needHebaoItem += item;
  1493. needHebaoItem += ",";
  1494. }
  1495. else
  1496. {
  1497. //if (item.IndexOf("电子稿") != -1)
  1498. //{
  1499. // createDianziCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1500. //}
  1501. //else
  1502. if (item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
  1503. {
  1504. createLogoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1505. }
  1506. else if (item.IndexOf("寄样") != -1)
  1507. {
  1508. createDemoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1509. }
  1510. else if (item.IndexOf("礼物") != -1)
  1511. {
  1512. createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1513. }
  1514. else
  1515. createNotHeBaoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1516. orderIdx = orderIdx + 1;
  1517. }
  1518. }
  1519. bool isHaveHebaoOrder = false;
  1520. if (needHebaoItem.Length > 0)
  1521. {
  1522. isHaveHebaoOrder = true;
  1523. needHebaoItem = needHebaoItem.Substring(0, needHebaoItem.Length - 1);
  1524. createHebaoCell(isMulity, orderIdx, needHebaoItem, father, hePrice);
  1525. orderIdx = orderIdx + 1;
  1526. }
  1527. if (orderIdx > 2)
  1528. {
  1529. try
  1530. {
  1531. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1532. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1533. LogHelper.addLog(tid, 0, "delete ctid=tid orderidx=" + orderIdx, 0);
  1534. if (System.Math.Abs(hePrice) > Convert.ToDecimal(0.01) && hePrice != Convert.ToDecimal(father.payment) && isHaveHebaoOrder == false)
  1535. {
  1536. string sql_pay = "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
  1537. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  1538. LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
  1539. }
  1540. }
  1541. catch (Exception ex)
  1542. {
  1543. XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
  1544. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1545. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1546. }
  1547. }
  1548. string orderSql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeOrder] WHERE tid = '{0}' and total_fee > 0", father.tid);
  1549. DataTable table = SqlHelper.ExecuteDataSet(orderSql).Tables[0];
  1550. string spu_id = "";
  1551. if (table != null && table.Rows.Count == 1)
  1552. {
  1553. spu_id = table.Rows[0]["spu_id"].ToString();
  1554. }
  1555. string cellSql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid = '{0}'", father.tid);
  1556. DataTable data = SqlHelper.ExecuteDataSet(cellSql).Tables[0];
  1557. if (data != null && data.Rows.Count > 0)
  1558. {
  1559. foreach (DataRow row in data.Rows)
  1560. {
  1561. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(row["ctid"].ToString());
  1562. if (ceErpTradeCellExtend == null)
  1563. {
  1564. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  1565. ceErpTradeCellExtend.ctid = row["ctid"].ToString();
  1566. }
  1567. ceErpTradeCellExtend.spu_id = spu_id;
  1568. if (ceErpTradeCellExtend.ID == 0)
  1569. {
  1570. ceErpTradeCellExtend.Create();
  1571. }
  1572. else
  1573. {
  1574. ceErpTradeCellExtend.Update();
  1575. }
  1576. }
  1577. }
  1578. //autoCell(tid);
  1579. }
  1580. }
  1581. public static void createNewSplitFn(string smemo, CeErpTrade father)
  1582. {
  1583. if (smemo.IndexOf("合包") != -1)
  1584. {
  1585. createHebaoCell(false, 0, smemo, father);
  1586. }
  1587. else
  1588. {
  1589. int firstDaKuoHaoCount = 0;
  1590. string firstoneContent = commonHelper.MidStrEx(smemo, "{", "}");
  1591. string[] oneElementList = firstoneContent.Split('+');
  1592. firstDaKuoHaoCount = oneElementList.Length;
  1593. string[] memoList = smemo.Split('-');
  1594. for (int idx = 0; idx < firstDaKuoHaoCount; idx++)
  1595. {
  1596. string newMemoStr = "";
  1597. foreach (string oneStr in memoList)
  1598. {
  1599. string oneContent = "";
  1600. if (oneStr.IndexOf("{") != -1)
  1601. {
  1602. oneContent = commonHelper.MidStrEx(oneStr, "{", "}");
  1603. string[] oneList = oneContent.Split('+');
  1604. if (oneList.Length != firstDaKuoHaoCount)
  1605. {
  1606. XLog.SaveLog(0, father.tid + ",备注大括号内的元素个数不相等");
  1607. return;
  1608. }
  1609. newMemoStr += oneList[idx];
  1610. }
  1611. else
  1612. newMemoStr += oneStr;
  1613. newMemoStr += "-";
  1614. }
  1615. newMemoStr = newMemoStr.Substring(0, newMemoStr.Length - 1);
  1616. if (idx == 0)
  1617. createNewSplitCell(true, idx + 1, newMemoStr, father, father.payment - firstDaKuoHaoCount * 0.1, firstDaKuoHaoCount);
  1618. else
  1619. createNewSplitCell(true, idx + 1, newMemoStr, father, 0.1, firstDaKuoHaoCount);
  1620. }
  1621. try
  1622. {
  1623. string sql_del = "delete from CE_ErpTradeCell where ctid='" + father.tid + "'";
  1624. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1625. LogHelper.addLog(father.tid, 0, "新拆分方法 delete ctid=tid ", 0);
  1626. }
  1627. catch (Exception ex)
  1628. {
  1629. XLog.SaveLog(0, "|新拆分删除首单错误|" + ex.Message);
  1630. }
  1631. }
  1632. }
  1633. public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1634. {
  1635. if (itemMemo.Length <= 0) return;
  1636. string ctid = "";
  1637. string splitTag = "";
  1638. if (isMulty && itemMemo.Length > 2)
  1639. {
  1640. string preStr = "C" + orderIndex + "_";
  1641. ctid = preStr + father.tid;
  1642. splitTag = "C" + orderIndex;
  1643. }
  1644. else if (itemMemo.Length > 2)
  1645. {
  1646. ctid = father.tid;
  1647. }
  1648. CeErpTradeCell entity = null;
  1649. entity = CeErpTradeCell.GetByCtid(ctid);
  1650. bool isNull = false;
  1651. if (entity == null)
  1652. {
  1653. entity = new CeErpTradeCell();
  1654. isNull = true;
  1655. }
  1656. entity.ctid = ctid;
  1657. //唯一标识
  1658. entity.OrderSn = ctid;
  1659. /*string orderSn = dataHelper.getSaleOrderSn();
  1660. if (orderSn != "")
  1661. {
  1662. entity.OrderSn = orderSn;
  1663. }*/
  1664. entity.tid = father.tid;
  1665. entity.SplitTag = splitTag;
  1666. if (entity.ShopId == 0)
  1667. {
  1668. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1669. int shopId = 0;
  1670. if (nShop != null)
  1671. {
  1672. shopId = nShop.ID;
  1673. }
  1674. entity.ShopId = shopId;
  1675. }
  1676. if (entity.IsSample == 1 || entity.IsSample == 2)
  1677. {
  1678. entity.IsSample = 0;
  1679. entity.ptid = "";
  1680. }
  1681. if (entity.isDianziOrder == 1)
  1682. {
  1683. entity.isDianziOrder = 0;
  1684. }
  1685. string[] acclist = itemMemo.Split('-');
  1686. if (acclist.Length < 4) return;
  1687. string count = acclist[0];
  1688. string product = acclist[1];
  1689. string account = acclist[3];
  1690. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1691. if (cusInfo != null)
  1692. {
  1693. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1694. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1695. {
  1696. }
  1697. else
  1698. {
  1699. entity.OrderState = 2;
  1700. if (entity.ShopId != 0)
  1701. {
  1702. entity.OrderState = orderAudit(entity.ShopId);
  1703. }
  1704. }
  1705. }
  1706. entity.ProductId = getProductIdByName("logo");
  1707. if (entity.ProductId == 0)
  1708. {
  1709. return;
  1710. }
  1711. entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
  1712. if (isMulty)
  1713. {
  1714. try
  1715. {
  1716. string strPrice = acclist[4];
  1717. if (strPrice.IndexOf("元") != -1)
  1718. {
  1719. strPrice = strPrice.Replace("元", "");
  1720. }
  1721. entity.payment = Convert.ToDouble(strPrice);
  1722. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  1723. }
  1724. catch (Exception ex)
  1725. {
  1726. }
  1727. }
  1728. else
  1729. {
  1730. entity.payment = Convert.ToDouble(father.payment);
  1731. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1732. }
  1733. string newmemo = "(" + entity.OrderSn + ")-";
  1734. string newOtherMemo = "";
  1735. for (int i = 0; i < acclist.Length; i++)
  1736. {
  1737. if (i == 3) continue;
  1738. if (i >= 4)
  1739. {
  1740. newOtherMemo += acclist[i];
  1741. }
  1742. else
  1743. newmemo += acclist[i];
  1744. if (i < acclist.Length - 2)
  1745. {
  1746. newmemo += "-";
  1747. }
  1748. }
  1749. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  1750. newmemo += ("-" + sName);
  1751. if (father.buyer_nick.IndexOf("*") < 0)
  1752. {
  1753. newmemo += ("-" + father.buyer_nick);
  1754. }
  1755. newmemo += ("-" + father.receiver_state);
  1756. if (cusInfo != null)
  1757. {
  1758. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  1759. }
  1760. if (isMulty)
  1761. {
  1762. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  1763. }
  1764. if (itemMemo.IndexOf("顺丰到付") != -1)
  1765. {
  1766. if (newmemo.IndexOf("顺丰到付") == -1)
  1767. newmemo += ("-顺丰到付");
  1768. entity.IsSF = 2;
  1769. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  1770. }
  1771. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  1772. {
  1773. if (newmemo.IndexOf("顺丰寄付") == -1)
  1774. newmemo += ("-顺丰寄付");
  1775. entity.IsSF = 1;
  1776. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  1777. }
  1778. if (itemMemo.IndexOf("加急") != -1)
  1779. {
  1780. if (newmemo.IndexOf("加急") == -1)
  1781. newmemo += ("-加急");
  1782. entity.IsUrgency = true;
  1783. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  1784. }
  1785. entity.seller_memo = newmemo;
  1786. entity.OtherMemo = newOtherMemo;
  1787. entity.pay_time = father.pay_time;
  1788. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1789. //if (oldRes>0)
  1790. //{
  1791. // entity.IsOldCustomer = 1;
  1792. // if (oldRes == 2)
  1793. // {
  1794. // entity.IsOldCustomer = 1;
  1795. // entity.IsOldCustomerMore = 1;
  1796. // }
  1797. //}
  1798. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1799. {
  1800. }
  1801. else
  1802. {
  1803. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  1804. {
  1805. entity.IsOldCustomer = 0;
  1806. }
  1807. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1808. if (oldRes > 0)
  1809. {
  1810. entity.IsOldCustomer = 1;
  1811. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1812. int curHour = DateTime.Now.Hour;
  1813. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  1814. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1815. {
  1816. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  1817. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1818. entity.DesignUserId = initSysDesignerId;
  1819. entity.WaitDesignTime = DateTime.Now;
  1820. }
  1821. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1822. {
  1823. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  1824. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1825. entity.DesignUserId = initSysDesignerId;
  1826. entity.WaitDesignTime = DateTime.Now;
  1827. }
  1828. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1829. {
  1830. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  1831. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1832. entity.DesignUserId = initSysDesignerId;
  1833. entity.WaitDesignTime = DateTime.Now;
  1834. }
  1835. else
  1836. {
  1837. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  1838. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  1839. {
  1840. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1841. entity.DesignUserId = initSysDesignerId;
  1842. entity.WaitDesignTime = DateTime.Now;
  1843. }
  1844. }
  1845. }
  1846. }
  1847. if (isNull)
  1848. {
  1849. father.create_time = DateTime.Now;
  1850. father.Update();
  1851. entity.Create();
  1852. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1853. }
  1854. else
  1855. {
  1856. entity.Update();
  1857. }
  1858. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1859. CeErpSukuraData.createInfo(entity.ctid, 1);
  1860. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "logo推送生成" + entity.seller_memo, entity.OrderState);
  1861. }
  1862. public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1863. {
  1864. if (itemMemo.Length <= 0) return;
  1865. string ctid = "";
  1866. string splitTag = "";
  1867. if (isMulity && itemMemo.Length > 2)
  1868. {
  1869. string preStr = "C" + orderIndex + "_";
  1870. ctid = preStr + father.tid;
  1871. splitTag = "C" + orderIndex;
  1872. }
  1873. else if (itemMemo.Length > 2)
  1874. {
  1875. ctid = father.tid;
  1876. }
  1877. CeErpTradeCell entity = null;
  1878. entity = CeErpTradeCell.GetByCtid(ctid);
  1879. bool isNull = false;
  1880. if (entity == null)
  1881. {
  1882. entity = new CeErpTradeCell();
  1883. isNull = true;
  1884. }
  1885. entity.ctid = ctid;
  1886. entity.tid = father.tid;
  1887. entity.SplitTag = splitTag;
  1888. if (entity.ShopId == 0)
  1889. {
  1890. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1891. int shopId = 0;
  1892. if (nShop != null)
  1893. {
  1894. shopId = nShop.ID;
  1895. }
  1896. entity.ShopId = shopId;
  1897. }
  1898. if (entity.IsSample == 1 || entity.IsSample == 2)
  1899. {
  1900. entity.IsSample = 0;
  1901. entity.ptid = "";
  1902. }
  1903. if (entity.isDianziOrder == 1)
  1904. {
  1905. entity.isDianziOrder = 0;
  1906. }
  1907. string[] acclist = itemMemo.Split('-');
  1908. if (acclist.Length < 4) return;
  1909. string count = acclist[0];
  1910. string product = acclist[1];
  1911. string account = acclist[3];
  1912. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1913. if (cusInfo != null)
  1914. {
  1915. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1916. }
  1917. if (entity.OrderState < 3 && entity.DesignUserId == 0)
  1918. {
  1919. entity.OrderState = Convert.ToInt32(OrderState.待抢单);
  1920. //entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1921. //entity.DesignUserId = 255; //电子稿给亿佳设计
  1922. //entity.WaitDesignTime = DateTime.Now;
  1923. }
  1924. entity.ProductId = getProductIdByName(product);
  1925. if (entity.ProductId == 0)
  1926. {
  1927. return;
  1928. }
  1929. entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
  1930. entity.isDianziOrder = 1;//电子稿
  1931. entity.pay_time = father.pay_time;
  1932. if (isMulity)
  1933. {
  1934. try
  1935. {
  1936. string strPrice = acclist[4];
  1937. if (strPrice.IndexOf("元") != -1)
  1938. {
  1939. strPrice = strPrice.Replace("元", "");
  1940. }
  1941. entity.payment = Convert.ToDouble(strPrice);
  1942. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  1943. }
  1944. catch (Exception ex)
  1945. {
  1946. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  1947. }
  1948. }
  1949. else
  1950. {
  1951. entity.payment = Convert.ToDouble(father.payment);
  1952. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1953. }
  1954. string newmemo = "(" + entity.tid + ")-";
  1955. string newOtherMemo = "";
  1956. for (int i = 0; i < acclist.Length; i++)
  1957. {
  1958. if (i == 3) continue;
  1959. newmemo += acclist[i];
  1960. if (i < acclist.Length - 2)
  1961. {
  1962. newmemo += "-";
  1963. }
  1964. }
  1965. string sName = getShopSNameByName(father.seller_nick);
  1966. newmemo += ("-" + sName);
  1967. if (father.buyer_nick.IndexOf("*") < 0)
  1968. {
  1969. newmemo += ("-" + father.buyer_nick);
  1970. }
  1971. newmemo += ("-" + father.receiver_state);
  1972. if (cusInfo != null)
  1973. {
  1974. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  1975. }
  1976. if (isMulity)
  1977. {
  1978. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  1979. }
  1980. entity.seller_memo = newmemo;
  1981. entity.OtherMemo = newOtherMemo;
  1982. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1983. //if (oldRes > 0)
  1984. //{
  1985. // entity.IsOldCustomer = 1;
  1986. // if (oldRes == 2)
  1987. // {
  1988. // entity.IsOldCustomer = 1;
  1989. // entity.IsOldCustomerMore = 1;
  1990. // }
  1991. //}
  1992. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1993. {
  1994. }
  1995. else
  1996. {
  1997. entity.IsOldCustomer = 0;
  1998. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1999. if (oldRes > 0)
  2000. {
  2001. entity.IsOldCustomer = 1;
  2002. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2003. dealOldCustomerEntityAuto(ref entity);
  2004. }
  2005. }
  2006. if (isNull)
  2007. {
  2008. father.create_time = DateTime.Now;
  2009. father.Update();
  2010. entity.Create();
  2011. }
  2012. else
  2013. {
  2014. entity.Update();
  2015. }
  2016. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2017. CeErpSukuraData.createInfo(entity.ctid, 1);
  2018. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "电子稿推送生成" + entity.seller_memo, entity.OrderState);
  2019. }
  2020. public static void createDemoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2021. {
  2022. if (itemMemo.Length <= 0) return;
  2023. string ctid = "";
  2024. string splitTag = "";
  2025. if (isMulty && itemMemo.Length > 2)
  2026. {
  2027. string preStr = "C" + orderIndex + "_";
  2028. ctid = preStr + father.tid;
  2029. splitTag = "C" + orderIndex;
  2030. }
  2031. else if (itemMemo.Length > 2)
  2032. {
  2033. ctid = father.tid;
  2034. }
  2035. CeErpTradeCell entity = null;
  2036. entity = CeErpTradeCell.GetByCtid(ctid);
  2037. bool isNull = false;
  2038. if (entity == null)
  2039. {
  2040. entity = new CeErpTradeCell();
  2041. isNull = true;
  2042. }
  2043. entity.ctid = ctid;
  2044. //唯一标识
  2045. entity.OrderSn = ctid;
  2046. /*string orderSn = dataHelper.getSaleOrderSn();
  2047. if (orderSn != "")
  2048. {
  2049. entity.OrderSn = orderSn;
  2050. }*/
  2051. entity.tid = father.tid;
  2052. entity.SplitTag = splitTag;
  2053. if (entity.ShopId == 0)
  2054. {
  2055. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2056. int shopId = 0;
  2057. if (nShop != null)
  2058. {
  2059. shopId = nShop.ID;
  2060. }
  2061. entity.ShopId = shopId;
  2062. }
  2063. entity.IsSample = 3;
  2064. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2065. if (entity.isDianziOrder == 1)
  2066. {
  2067. entity.isDianziOrder = 0;
  2068. }
  2069. string[] acclist = itemMemo.Split('-');
  2070. if (acclist.Length <= 3) return;
  2071. //string count = acclist[0];
  2072. string product = acclist[1];
  2073. string account = acclist[3];
  2074. DataRow cusInfo = getUserInfoByAccount(account);
  2075. if (cusInfo != null)
  2076. {
  2077. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2078. if (entity.OrderState > 6)
  2079. {
  2080. }
  2081. else
  2082. {
  2083. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2084. }
  2085. }
  2086. entity.ProductId = getProductIdByName(product);
  2087. if (entity.ProductId == 0)
  2088. {
  2089. return;
  2090. }
  2091. if (isMulty)
  2092. {
  2093. try
  2094. {
  2095. string strPrice = acclist[4];
  2096. if (strPrice.IndexOf("元") != -1)
  2097. {
  2098. strPrice = strPrice.Replace("元", "");
  2099. }
  2100. entity.payment = Convert.ToDouble(strPrice);
  2101. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2102. }
  2103. catch (Exception ex)
  2104. {
  2105. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2106. }
  2107. }
  2108. else
  2109. {
  2110. entity.payment = Convert.ToDouble(father.payment);
  2111. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2112. }
  2113. string newmemo = "(" + entity.OrderSn + ")-";
  2114. string newOtherMemo = "";
  2115. List<string> list = new List<string>();
  2116. for (int i = 0; i < acclist.Length; i++)
  2117. {
  2118. if (i == 3) continue;
  2119. if (isMulty)
  2120. {
  2121. if (i == 4) continue;
  2122. }
  2123. list.Add(acclist[i]);
  2124. }
  2125. newmemo += string.Join("-", list);
  2126. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2127. newmemo += ("-" + sName);
  2128. if (father.buyer_nick.IndexOf("*") < 0)
  2129. {
  2130. newmemo += ("-" + father.buyer_nick);
  2131. }
  2132. newmemo += ("-" + father.receiver_state);
  2133. if (cusInfo != null)
  2134. {
  2135. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2136. }
  2137. if (isMulty)
  2138. {
  2139. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2140. }
  2141. if (itemMemo.IndexOf("顺丰到付") != -1)
  2142. {
  2143. if (newmemo.IndexOf("顺丰到付") == -1)
  2144. newmemo += ("-顺丰到付");
  2145. entity.IsSF = 2;
  2146. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2147. }
  2148. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2149. {
  2150. if (newmemo.IndexOf("顺丰寄付") == -1)
  2151. newmemo += ("-顺丰寄付");
  2152. entity.IsSF = 1;
  2153. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2154. }
  2155. if (itemMemo.IndexOf("加急") != -1)
  2156. {
  2157. if (newmemo.IndexOf("加急") == -1)
  2158. newmemo += ("-加急");
  2159. entity.IsUrgency = true;
  2160. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2161. }
  2162. entity.seller_memo = newmemo;
  2163. entity.OtherMemo = newOtherMemo;
  2164. entity.pay_time = father.pay_time;
  2165. entity.FinishDesignTime = DateTime.Now;
  2166. entity.StartDesignTime = DateTime.Now;
  2167. entity.WaitDesignTime = DateTime.Now;
  2168. entity.FinishPlaceTime = DateTime.Now;
  2169. entity.IsOldCustomer = 0;
  2170. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2171. if (oldRes > 0)
  2172. {
  2173. entity.IsOldCustomer = 1;
  2174. if (oldRes == 2)
  2175. {
  2176. entity.IsOldCustomer = 1;
  2177. entity.IsOldCustomerMore = 1;
  2178. }
  2179. }
  2180. if (isNull)
  2181. {
  2182. father.create_time = DateTime.Now;
  2183. father.Update();
  2184. entity.Create();
  2185. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2186. }
  2187. else
  2188. {
  2189. entity.Update();
  2190. }
  2191. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2192. CeErpSukuraData.createInfo(entity.ctid, 1);
  2193. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "寄样推送生成" + entity.seller_memo, entity.OrderState);
  2194. }
  2195. public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2196. {
  2197. if (itemMemo.Length <= 0) return;
  2198. string ctid = "";
  2199. string splitTag = "";
  2200. if (isMulty && itemMemo.Length > 2)
  2201. {
  2202. string preStr = "C" + orderIndex + "_";
  2203. ctid = preStr + father.tid;
  2204. splitTag = "C" + orderIndex;
  2205. }
  2206. else if (itemMemo.Length > 2)
  2207. {
  2208. ctid = father.tid;
  2209. }
  2210. CeErpTradeCell entity = null;
  2211. entity = CeErpTradeCell.GetByCtid(ctid);
  2212. bool isNull = false;
  2213. if (entity == null)
  2214. {
  2215. entity = new CeErpTradeCell();
  2216. isNull = true;
  2217. }
  2218. if (entity.OrderState > 6) return;
  2219. if (entity.ShopId == 0)
  2220. {
  2221. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2222. int shopId = 0;
  2223. if (nShop != null)
  2224. {
  2225. shopId = nShop.ID;
  2226. }
  2227. entity.ShopId = shopId;
  2228. }
  2229. if (entity.IsSample == 1 || entity.IsSample == 2)
  2230. {
  2231. entity.IsSample = 0;
  2232. entity.ptid = "";
  2233. }
  2234. if (entity.isDianziOrder == 1)
  2235. {
  2236. entity.isDianziOrder = 0;
  2237. }
  2238. entity.ctid = ctid;
  2239. //唯一标识
  2240. entity.OrderSn = ctid;
  2241. /*string orderSn = dataHelper.getSaleOrderSn();
  2242. if (orderSn != "")
  2243. {
  2244. entity.OrderSn = orderSn;
  2245. }*/
  2246. entity.tid = father.tid;
  2247. entity.SplitTag = splitTag;
  2248. string[] acclist = itemMemo.Split('-');
  2249. if (acclist.Length < 2) return;
  2250. if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
  2251. {
  2252. return;
  2253. }
  2254. string product = acclist[0];
  2255. string account = acclist[1];
  2256. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2257. if (cusInfo != null)
  2258. {
  2259. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2260. }
  2261. entity.IsOldCustomer = 0;
  2262. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  2263. entity.IsXianHuo = 1;
  2264. entity.IsGift = 1;
  2265. entity.FinishPlaceTime = father.pay_time;
  2266. if (entity.OrderState < 6)
  2267. {
  2268. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2269. }
  2270. if (isMulty)
  2271. {
  2272. try
  2273. {
  2274. string strPrice = acclist[2];
  2275. if (strPrice.IndexOf("元") != -1)
  2276. {
  2277. strPrice = strPrice.Replace("元", "");
  2278. }
  2279. entity.payment = Convert.ToDouble(strPrice);
  2280. hePrice = hePrice - Convert.ToDecimal(acclist[2]);
  2281. }
  2282. catch (Exception ex)
  2283. {
  2284. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2285. }
  2286. }
  2287. else
  2288. {
  2289. entity.payment = Convert.ToDouble(father.payment);
  2290. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2291. }
  2292. string newmemo = "(" + entity.OrderSn + ")-";
  2293. string newOtherMemo = "";
  2294. for (int i = 0; i < acclist.Length; i++)
  2295. {
  2296. if (i == 1) continue;
  2297. newmemo += acclist[i];
  2298. if (i < acclist.Length - 1)
  2299. {
  2300. newmemo += "-";
  2301. }
  2302. }
  2303. string sName = getShopSNameByName(father.seller_nick);
  2304. newmemo += ("" + sName);
  2305. newmemo += ("-" + father.buyer_nick);
  2306. newmemo += ("-" + father.receiver_state);
  2307. if (cusInfo != null)
  2308. {
  2309. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2310. }
  2311. if (isMulty)
  2312. {
  2313. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2314. }
  2315. if (newmemo.IndexOf("现货") != -1)
  2316. {
  2317. newmemo = newmemo.Replace("礼物", "");
  2318. }
  2319. if (itemMemo.IndexOf("顺丰到付") != -1)
  2320. {
  2321. newmemo += ("-顺丰到付");
  2322. entity.IsSF = 2;
  2323. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2324. }
  2325. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2326. {
  2327. newmemo += ("-顺丰寄付");
  2328. entity.IsSF = 1;
  2329. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2330. }
  2331. if (itemMemo.IndexOf("加急") != -1)
  2332. {
  2333. newmemo += ("-加急");
  2334. entity.IsUrgency = true;
  2335. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2336. }
  2337. entity.seller_memo = newmemo;
  2338. entity.OtherMemo = newOtherMemo;
  2339. entity.pay_time = father.pay_time;
  2340. if (isNull)
  2341. {
  2342. father.create_time = DateTime.Now;
  2343. father.Update();
  2344. entity.Create();
  2345. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2346. }
  2347. else
  2348. {
  2349. entity.Update();
  2350. }
  2351. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2352. CeErpSukuraData.createInfo(entity.ctid, 1);
  2353. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
  2354. }
  2355. public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
  2356. {
  2357. if (itemMemo.Length <= 0) return;
  2358. string[] hebaoMemoList = itemMemo.Split(',');
  2359. string memo_index1 = hebaoMemoList[0];
  2360. string ctid = "";
  2361. string splitTag = "";
  2362. if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
  2363. {
  2364. string preStr = "C" + orderIndex + "_";
  2365. ctid = preStr + father.tid;
  2366. splitTag = "C" + orderIndex + "+" + orderIndex;
  2367. }
  2368. else if (itemMemo.Length > 2)
  2369. {
  2370. ctid = father.tid;
  2371. }
  2372. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2373. bool ishave = true;
  2374. if (entity == null)
  2375. {
  2376. entity = new CeErpTradeCell();
  2377. ishave = false;
  2378. }
  2379. if (entity.ShopId == 0)
  2380. {
  2381. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2382. int shopId = 0;
  2383. if (nShop != null)
  2384. {
  2385. shopId = nShop.ID;
  2386. }
  2387. entity.ShopId = shopId;
  2388. }
  2389. if (entity.IsSample == 1 || entity.IsSample == 2)
  2390. {
  2391. entity.IsSample = 0;
  2392. entity.ptid = "";
  2393. }
  2394. if (entity.isDianziOrder == 1)
  2395. {
  2396. entity.isDianziOrder = 0;
  2397. }
  2398. entity.ctid = ctid;
  2399. //唯一标识
  2400. entity.OrderSn = ctid;
  2401. /* string orderSn = dataHelper.getSaleOrderSn();
  2402. if (orderSn != "")
  2403. {
  2404. entity.OrderSn = orderSn;
  2405. }*/
  2406. entity.tid = father.tid;
  2407. entity.SplitTag = splitTag;
  2408. string[] acclist = memo_index1.Split('-');
  2409. bool isXianhuo = false;
  2410. if (acclist[0] == "现货")
  2411. {
  2412. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2413. System.Array.Resize(ref acclist, acclist.Length - 1);
  2414. isXianhuo = true;
  2415. }
  2416. if (acclist.Length < 6)
  2417. {
  2418. return;
  2419. }
  2420. string size = acclist[0];
  2421. string count = acclist[1];
  2422. bool isBuGanJiao = false;
  2423. string product = "";
  2424. string mt = "", ct = "";
  2425. string account = "";
  2426. memo_index1 = memo_index1.Replace("PVC", "pvc");
  2427. if ((acclist[3] == "不干胶" || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("礼物") == -1)
  2428. {
  2429. isBuGanJiao = true;
  2430. product = acclist[3];
  2431. mt = acclist[2];
  2432. }
  2433. else
  2434. {
  2435. product = acclist[2];
  2436. mt = acclist[3];
  2437. }
  2438. account = acclist[5];
  2439. ct = acclist[4];
  2440. entity.ProductId = getProductIdByName(product);
  2441. if (entity.ProductId == 0)
  2442. {
  2443. return;
  2444. }
  2445. if (isMulity && hePrice != 0)
  2446. {
  2447. entity.payment = Convert.ToDouble(hePrice);
  2448. }
  2449. else
  2450. {
  2451. entity.payment = father.payment;
  2452. }
  2453. DataRow cusInfo = getUserInfoByAccount(account);
  2454. if (cusInfo != null)
  2455. {
  2456. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2457. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2458. {
  2459. }
  2460. else
  2461. {
  2462. entity.OrderState = 2;
  2463. if (entity.ShopId != 0)
  2464. {
  2465. entity.OrderState = orderAudit(entity.ShopId);
  2466. }
  2467. if (entity.DesignUserId > 0)
  2468. {
  2469. entity.OrderState = 3;
  2470. }
  2471. }
  2472. }
  2473. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2474. {
  2475. entity.IsOldCustomer = 1;
  2476. if (itemMemo.IndexOf("改稿") != -1)
  2477. {
  2478. if (entity.payment > 0)
  2479. {
  2480. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  2481. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2482. {
  2483. }
  2484. else
  2485. {
  2486. dealOldCustomerEntityTag(ref entity, father);
  2487. }
  2488. }
  2489. }
  2490. else
  2491. {
  2492. entity.OrderState = 3;
  2493. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2494. entity.WaitDesignTime = DateTime.Now;
  2495. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2496. }
  2497. }
  2498. entity.Material = mt;
  2499. entity.ProductSize = size;
  2500. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count); ;
  2501. entity.Craft = ct;
  2502. entity.pay_time = father.pay_time;
  2503. string newmemo = "(" + entity.OrderSn + ")-";
  2504. if (isXianhuo)
  2505. {
  2506. newmemo += "现货-";
  2507. entity.IsXianHuo = 1;
  2508. }
  2509. string newOtherMemo = "";
  2510. for (int idx = 0; idx < hebaoMemoList.Length; idx++)
  2511. {
  2512. string smallitem = hebaoMemoList[idx];
  2513. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  2514. {
  2515. newmemo = "";
  2516. }
  2517. string[] smallList = smallitem.Split('-');
  2518. if (smallList.Length > 5 && idx > 0)
  2519. {
  2520. string itemsize = smallList[0];
  2521. string itemcount = smallList[1];
  2522. string itemmt = "", itemct = "";
  2523. if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
  2524. {
  2525. itemmt = acclist[2];
  2526. }
  2527. else
  2528. {
  2529. itemmt = acclist[3];
  2530. }
  2531. itemct = acclist[4];
  2532. entity.ProductSize = entity.ProductSize + "," + itemsize;
  2533. entity.ProductCount = entity.ProductCount + "," + itemcount;
  2534. entity.Material = entity.Material + "," + itemmt;
  2535. entity.Craft = entity.Craft + "," + itemct;
  2536. }
  2537. if (smallList.Length >= 7)
  2538. {
  2539. smallList[6] = smallList[6].Replace("(", "");
  2540. smallList[6] = smallList[6].Replace(")", "");
  2541. smallList[6] = smallList[6].Replace("(", "");
  2542. smallList[6] = smallList[6].Replace(")", "");
  2543. entity.MakeSupplier = smallList[6];
  2544. smallList[6] = "(" + smallList[6] + ")";
  2545. newmemo += smallList[6];
  2546. newmemo += "-";
  2547. }
  2548. if (smallitem.IndexOf("海报") != -1)
  2549. {
  2550. newmemo += smallList[2];
  2551. newmemo += smallList[0];
  2552. newmemo += "-";
  2553. newmemo += smallList[1];
  2554. newmemo += "(";
  2555. newmemo += father.tid;
  2556. newmemo += ")";
  2557. newmemo += "-";
  2558. newmemo += smallList[4];
  2559. if (smallList.Length > 7)
  2560. {
  2561. for (int i = 7; i < smallList.Length; i++)
  2562. {
  2563. newOtherMemo += smallList[i];
  2564. newOtherMemo += "-";
  2565. }
  2566. }
  2567. if (smallitem.IndexOf("5mmpvc") != -1)
  2568. {
  2569. entity.ProductId = 8; //pvc卡片
  2570. }
  2571. }
  2572. else
  2573. {
  2574. for (int i = 0; i < smallList.Length; i++)
  2575. {
  2576. if (isMulity && i == 5)
  2577. {
  2578. continue;
  2579. }
  2580. if (i >= 7)
  2581. {
  2582. newOtherMemo += smallList[i];
  2583. if (i < smallList.Length - 2 && i != 2 && i != 3)
  2584. {
  2585. newOtherMemo += "-";
  2586. }
  2587. }
  2588. else
  2589. {
  2590. if (i == 6)
  2591. {
  2592. continue;
  2593. }
  2594. else
  2595. newmemo += smallList[i];
  2596. if (i != 2 && i != 3)
  2597. {
  2598. newmemo += "-";
  2599. }
  2600. }
  2601. }
  2602. }
  2603. if (hebaoMemoList.Length > idx + 1)
  2604. {
  2605. newmemo += ",";
  2606. newOtherMemo += ",";
  2607. }
  2608. }
  2609. string sName = getShopSNameByName(father.seller_nick);
  2610. newmemo += (sName);
  2611. if (father.buyer_nick.IndexOf("*") < 0)
  2612. {
  2613. newmemo += ("-" + father.buyer_nick);
  2614. }
  2615. newmemo += ("-" + father.receiver_state);
  2616. if (cusInfo != null)
  2617. {
  2618. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2619. }
  2620. if (orderIndex > 1 && isMulity)
  2621. {
  2622. newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
  2623. }
  2624. //newmemo += "-合包";
  2625. if (itemMemo.IndexOf("顺丰到付") != -1)
  2626. {
  2627. //if(newmemo.IndexOf("顺丰到付")==-1)
  2628. // newmemo += ("-顺丰到付");
  2629. entity.IsSF = 2;
  2630. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2631. }
  2632. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2633. {
  2634. //if (newmemo.IndexOf("顺丰寄付") == -1)
  2635. // newmemo += ("-顺丰寄付");
  2636. entity.IsSF = 1;
  2637. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2638. }
  2639. if (itemMemo.IndexOf("加急") != -1)
  2640. {
  2641. //if (newmemo.IndexOf("加急") == -1)
  2642. // newmemo += ("-加急");
  2643. entity.IsUrgency = true;
  2644. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2645. }
  2646. entity.seller_memo = newmemo;
  2647. entity.OtherMemo = newOtherMemo;
  2648. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  2649. {
  2650. string odt = commonHelper.getDateFromString(newOtherMemo);
  2651. if (odt.Length > 0)
  2652. {
  2653. entity.OldCustomerTime = Convert.ToDateTime(odt);
  2654. }
  2655. }
  2656. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2657. {
  2658. }
  2659. else
  2660. {
  2661. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  2662. {
  2663. entity.IsOldCustomer = 0;
  2664. }
  2665. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2666. if (oldRes > 0)
  2667. {
  2668. entity.IsOldCustomer = 1;
  2669. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2670. dealOldCustomerEntityAuto(ref entity);
  2671. }
  2672. }
  2673. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  2674. {
  2675. entity.OrderState = 6;
  2676. entity.FinishPlaceTime = DateTime.Now;
  2677. entity.SupplierId = 98;//-领鸿
  2678. }
  2679. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  2680. {
  2681. entity.OrderState = 6;
  2682. entity.FinishPlaceTime = DateTime.Now;
  2683. entity.SupplierId = 5;//-福广
  2684. }
  2685. if (ishave)
  2686. {
  2687. entity.Update();
  2688. }
  2689. else
  2690. {
  2691. father.create_time = DateTime.Now;
  2692. father.Update();
  2693. entity.Create();
  2694. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2695. }
  2696. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2697. CeErpSukuraData.createInfo(entity.ctid, 1);
  2698. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
  2699. }
  2700. public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2701. {
  2702. if (itemMemo.Length <= 0) return;
  2703. //itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
  2704. string ctid = "";
  2705. string splitTag = "";
  2706. if (isMulity && itemMemo.Length > 2)
  2707. {
  2708. string preStr = "C" + orderIndex + "_";
  2709. ctid = preStr + father.tid;
  2710. splitTag = "C" + totalCount + "+" + orderIndex;
  2711. }
  2712. else if (itemMemo.Length > 2)
  2713. {
  2714. ctid = father.tid;
  2715. }
  2716. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2717. bool ishave = true;
  2718. if (entity == null)
  2719. {
  2720. entity = new CeErpTradeCell();
  2721. ishave = false;
  2722. }
  2723. entity.ctid = ctid;
  2724. //唯一标识
  2725. entity.OrderSn = ctid;
  2726. /* string orderSn = dataHelper.getSaleOrderSn();
  2727. if (orderSn != "")
  2728. {
  2729. entity.OrderSn = orderSn;
  2730. }*/
  2731. entity.tid = father.tid;
  2732. entity.SplitTag = splitTag;
  2733. string[] acclist = itemMemo.Split('-');
  2734. bool isXianhuo = false;
  2735. if (acclist[0] == "现货")
  2736. {
  2737. isXianhuo = true;
  2738. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2739. System.Array.Resize(ref acclist, acclist.Length - 1);
  2740. }
  2741. if (entity.ShopId == 0)
  2742. {
  2743. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2744. int shopId = 0;
  2745. if (nShop != null)
  2746. {
  2747. shopId = nShop.ID;
  2748. }
  2749. entity.ShopId = shopId;
  2750. }
  2751. if (entity.IsSample == 1 || entity.IsSample == 2)
  2752. {
  2753. entity.IsSample = 0;
  2754. entity.ptid = "";
  2755. }
  2756. if (entity.isDianziOrder == 1)
  2757. {
  2758. entity.isDianziOrder = 0;
  2759. }
  2760. if (entity.IsXianHuo == 1)
  2761. {
  2762. entity.IsXianHuo = 0;
  2763. }
  2764. if (isMulity && acclist.Length < 7)
  2765. {
  2766. return;
  2767. }
  2768. if (acclist.Length < 6)
  2769. {
  2770. return;
  2771. }
  2772. string size = acclist[0];
  2773. string count = acclist[1];
  2774. bool isBuGanJiao = false;
  2775. string product = "";
  2776. string mt = "", ct = "";
  2777. string account = "";
  2778. itemMemo = itemMemo.Replace("PVC", "pvc");
  2779. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  2780. {
  2781. isBuGanJiao = true;
  2782. product = acclist[3];
  2783. mt = acclist[2];
  2784. }
  2785. else
  2786. {
  2787. product = acclist[2];
  2788. mt = acclist[3];
  2789. }
  2790. account = acclist[5];
  2791. ct = acclist[4];
  2792. if (isMulity)
  2793. {
  2794. try
  2795. {
  2796. string strPrice = acclist[6];
  2797. if (strPrice.IndexOf("元") != -1)
  2798. {
  2799. strPrice = strPrice.Replace("元", "");
  2800. }
  2801. entity.payment = Convert.ToDouble(strPrice);
  2802. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2803. }
  2804. catch (Exception ex)
  2805. {
  2806. entity.payment = 0;
  2807. return;
  2808. }
  2809. if (acclist.Length >= 8)
  2810. {
  2811. acclist[7] = acclist[7].Replace("(", "");
  2812. acclist[7] = acclist[7].Replace(")", "");
  2813. acclist[7] = acclist[7].Replace("(", "");
  2814. acclist[7] = acclist[7].Replace(")", "");
  2815. entity.MakeSupplier = acclist[7];
  2816. acclist[7] = "(" + acclist[7] + ")";
  2817. }
  2818. }
  2819. else
  2820. {
  2821. entity.payment = father.payment;
  2822. if (acclist.Length >= 7)
  2823. {
  2824. acclist[6] = acclist[6].Replace("(", "");
  2825. acclist[6] = acclist[6].Replace(")", "");
  2826. acclist[6] = acclist[6].Replace("(", "");
  2827. acclist[6] = acclist[6].Replace(")", "");
  2828. entity.MakeSupplier = acclist[6];
  2829. acclist[6] = "(" + acclist[6] + ")";
  2830. }
  2831. }
  2832. entity.ProductId = getProductIdByName(product);
  2833. if (entity.ProductId == 0)
  2834. {
  2835. return;
  2836. }
  2837. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2838. if (cusInfo != null)
  2839. {
  2840. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2841. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2842. {
  2843. }
  2844. else
  2845. {
  2846. entity.OrderState = 2;
  2847. if (entity.ShopId != 0)
  2848. {
  2849. entity.OrderState = orderAudit(entity.ShopId);
  2850. }
  2851. if (entity.DesignUserId > 0)
  2852. {
  2853. entity.OrderState = 3;
  2854. }
  2855. }
  2856. }
  2857. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2858. {
  2859. entity.IsOldCustomer = 1;
  2860. if (itemMemo.IndexOf("改稿") != -1)
  2861. {
  2862. if (entity.payment > 0)
  2863. {
  2864. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2865. {
  2866. }
  2867. else
  2868. {
  2869. dealOldCustomerEntityTag(ref entity, father);
  2870. }
  2871. }
  2872. }
  2873. else
  2874. {
  2875. if (entity.payment != 0)
  2876. {
  2877. entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
  2878. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  2879. entity.WaitDesignTime = DateTime.Now;
  2880. entity.FinishPlaceTime = DateTime.Now;
  2881. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  2882. }
  2883. }
  2884. }
  2885. if (mt.IndexOf("铜板纸") != -1)
  2886. {
  2887. mt = mt.Replace("铜板纸", "铜版纸");
  2888. }
  2889. entity.Material = mt;
  2890. entity.ProductSize = size;
  2891. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
  2892. entity.Craft = ct;
  2893. entity.pay_time = father.pay_time;
  2894. if (itemMemo.IndexOf("电子稿") != -1)
  2895. {
  2896. entity.isDianziOrder = 1;
  2897. }
  2898. if (product == "现货手提袋")
  2899. {
  2900. entity.OrderState = 6;//下单完成
  2901. entity.FinishPlaceTime = DateTime.Now;
  2902. }
  2903. string newmemo = "(" + entity.OrderSn + ")-";
  2904. if (isXianhuo)
  2905. {
  2906. newmemo += "现货-";
  2907. entity.IsXianHuo = 1;
  2908. }
  2909. string newOtherMemo = "";
  2910. if (false)
  2911. {
  2912. newmemo = acclist[2];
  2913. newmemo += acclist[0];
  2914. newmemo += "-";
  2915. newmemo += acclist[1];
  2916. newmemo += "(";
  2917. newmemo += father.tid;
  2918. newmemo += ")";
  2919. newmemo += "-";
  2920. newmemo += acclist[4];
  2921. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2922. newmemo += ("-" + sName);
  2923. newmemo += ("-" + father.buyer_nick);
  2924. if (father.buyer_nick.IndexOf("*") < 0)
  2925. {
  2926. newmemo += ("-" + father.buyer_nick);
  2927. }
  2928. if (cusInfo != null)
  2929. {
  2930. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2931. }
  2932. if (isMulity)
  2933. {
  2934. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2935. }
  2936. if (acclist.Length > 7)
  2937. {
  2938. for (int i = 7; i < acclist.Length; i++)
  2939. {
  2940. newOtherMemo += acclist[i];
  2941. newOtherMemo += "-";
  2942. }
  2943. }
  2944. }
  2945. else
  2946. {
  2947. if (acclist.Length >= 7 && !isMulity)
  2948. {
  2949. newmemo += acclist[6];
  2950. newmemo += "-";
  2951. }
  2952. if (isMulity && acclist.Length >= 8)
  2953. {
  2954. newmemo += acclist[7];
  2955. newmemo += "-";
  2956. }
  2957. for (int i = 0; i < acclist.Length; i++)
  2958. {
  2959. if ((isMulity && i == 6) || i == 5)
  2960. {
  2961. continue;
  2962. }
  2963. if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
  2964. {
  2965. newOtherMemo += acclist[i];
  2966. newOtherMemo += "-";
  2967. }
  2968. else
  2969. {
  2970. if ((i == 6 && !isMulity) || (isMulity && i == 7))
  2971. {
  2972. continue;
  2973. }
  2974. else
  2975. newmemo += acclist[i];
  2976. if (i != 2 && i != 3)
  2977. {
  2978. newmemo += "-";
  2979. }
  2980. }
  2981. }
  2982. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2983. newmemo += (sName);
  2984. if (father.buyer_nick.IndexOf("*") < 0)
  2985. {
  2986. newmemo += ("-" + father.buyer_nick);
  2987. }
  2988. newmemo += ("-" + father.receiver_state);
  2989. if (cusInfo != null)
  2990. {
  2991. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2992. }
  2993. if (itemMemo.IndexOf("顺丰到付") != -1)
  2994. {
  2995. //if (newmemo.IndexOf("顺丰到付") == -1)
  2996. // newmemo += ("-顺丰到付");
  2997. entity.IsSF = 2;
  2998. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2999. }
  3000. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3001. {
  3002. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3003. // newmemo += ("-顺丰寄付");
  3004. entity.IsSF = 1;
  3005. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3006. }
  3007. if (itemMemo.IndexOf("加急") != -1)
  3008. {
  3009. //if (newmemo.IndexOf("加急") == -1)
  3010. // newmemo += ("-加急");
  3011. entity.IsUrgency = true;
  3012. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3013. }
  3014. }
  3015. if (isMulity)
  3016. {
  3017. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3018. }
  3019. newmemo = newmemo.Replace("\n", " ");
  3020. entity.seller_memo = newmemo;
  3021. entity.OtherMemo = newOtherMemo;
  3022. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3023. {
  3024. string odt = commonHelper.getDateFromString(newOtherMemo);
  3025. if (odt.Length > 0)
  3026. {
  3027. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3028. }
  3029. }
  3030. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3031. {
  3032. //到了设计那边,就更新memo,状态不设置
  3033. }
  3034. else
  3035. {
  3036. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  3037. {
  3038. entity.IsOldCustomer = 0;
  3039. }
  3040. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3041. if (oldRes > 0)
  3042. {
  3043. entity.IsOldCustomer = 1;
  3044. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3045. dealOldCustomerEntityAuto(ref entity);
  3046. }
  3047. }
  3048. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  3049. {
  3050. entity.OrderState = 6;
  3051. entity.FinishPlaceTime = DateTime.Now;
  3052. entity.SupplierId = 98;//-领鸿
  3053. }
  3054. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  3055. {
  3056. entity.OrderState = 6;
  3057. entity.FinishPlaceTime = DateTime.Now;
  3058. entity.SupplierId = 5;//-福广
  3059. }
  3060. if (ishave)
  3061. {
  3062. entity.Update();
  3063. }
  3064. else
  3065. {
  3066. father.create_time = DateTime.Now;
  3067. father.Update();
  3068. entity.Create();
  3069. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  3070. }
  3071. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  3072. CeErpSukuraData.createInfo(entity.ctid, 1);
  3073. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
  3074. }
  3075. public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
  3076. {
  3077. //UV跟指定店铺
  3078. int[] shopList = { 49, 67, 26, 45, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
  3079. if (entity.ProductId == 43 || shopList.Contains(entity.ShopId))
  3080. {
  3081. /**int curHour = DateTime.Now.Hour;
  3082. int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3083. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3084. {
  3085. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3086. entity.DesignUserId = initSysDesignerId;
  3087. entity.WaitDesignTime = DateTime.Now;
  3088. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3089. }
  3090. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3091. {
  3092. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3093. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3094. entity.DesignUserId = initSysDesignerId;
  3095. entity.WaitDesignTime = DateTime.Now;
  3096. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3097. }
  3098. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3099. {
  3100. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3101. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3102. entity.DesignUserId = initSysDesignerId;
  3103. entity.WaitDesignTime = DateTime.Now;
  3104. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3105. }
  3106. else
  3107. {**/
  3108. int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3109. if (designId != 0)
  3110. {
  3111. entity.DesignUserId = designId;
  3112. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3113. entity.WaitDesignTime = DateTime.Now;
  3114. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
  3115. }
  3116. }
  3117. }
  3118. public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
  3119. {
  3120. int curHour = DateTime.Now.Hour;
  3121. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3122. /**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3123. {
  3124. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3125. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3126. entity.DesignUserId = initSysDesignerId;
  3127. entity.WaitDesignTime = DateTime.Now;
  3128. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3129. }
  3130. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3131. {
  3132. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3133. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3134. entity.DesignUserId = initSysDesignerId;
  3135. entity.WaitDesignTime = DateTime.Now;
  3136. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3137. }
  3138. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3139. {
  3140. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3141. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3142. entity.DesignUserId = initSysDesignerId;
  3143. entity.WaitDesignTime = DateTime.Now;
  3144. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3145. }
  3146. else
  3147. {**/
  3148. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3149. //这个设计师有上班,有关联此店铺
  3150. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3151. {
  3152. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3153. entity.DesignUserId = initSysDesignerId;
  3154. entity.WaitDesignTime = DateTime.Now;
  3155. LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
  3156. }
  3157. //}
  3158. }
  3159. public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
  3160. {
  3161. if (itemMemo.Length <= 0) return;
  3162. string ctid = "";
  3163. string splitTag = "";
  3164. if (isMulity && itemMemo.Length > 2)
  3165. {
  3166. string preStr = "C" + orderIndex + "_";
  3167. ctid = preStr + father.tid;
  3168. splitTag = "C" + orderIndex;
  3169. }
  3170. else if (itemMemo.Length > 2)
  3171. {
  3172. ctid = father.tid;
  3173. }
  3174. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  3175. bool ishave = true;
  3176. if (entity == null)
  3177. {
  3178. entity = new CeErpTradeCell();
  3179. ishave = false;
  3180. }
  3181. entity.ctid = ctid;
  3182. entity.tid = father.tid;
  3183. entity.SplitTag = splitTag;
  3184. string[] acclist = itemMemo.Split('-');
  3185. if (entity.ShopId == 0)
  3186. {
  3187. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  3188. int shopId = 0;
  3189. if (nShop != null)
  3190. {
  3191. shopId = nShop.ID;
  3192. }
  3193. entity.ShopId = shopId;
  3194. }
  3195. if (entity.IsSample == 1 || entity.IsSample == 2)
  3196. {
  3197. entity.IsSample = 0;
  3198. }
  3199. if (entity.isDianziOrder == 1)
  3200. {
  3201. entity.isDianziOrder = 0;
  3202. }
  3203. if (acclist.Length < 6)
  3204. {
  3205. return;
  3206. }
  3207. string size = acclist[0];
  3208. string count = acclist[1];
  3209. bool isBuGanJiao = false;
  3210. string product = "";
  3211. string mt = "", ct = "";
  3212. string account = "";
  3213. itemMemo = itemMemo.Replace("PVC", "pvc");
  3214. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3215. {
  3216. isBuGanJiao = true;
  3217. product = acclist[3];
  3218. mt = acclist[2];
  3219. }
  3220. else
  3221. {
  3222. product = acclist[2];
  3223. mt = acclist[3];
  3224. }
  3225. account = acclist[5];
  3226. ct = acclist[4];
  3227. if (isMulity)
  3228. {
  3229. entity.payment = orderPrice;
  3230. if (acclist.Length >= 7)
  3231. {
  3232. acclist[6] = acclist[6].Replace("(", "");
  3233. acclist[6] = acclist[6].Replace(")", "");
  3234. acclist[6] = acclist[6].Replace("(", "");
  3235. acclist[6] = acclist[6].Replace(")", "");
  3236. entity.MakeSupplier = acclist[6];
  3237. acclist[6] = "(" + acclist[6] + ")";
  3238. }
  3239. }
  3240. entity.ProductId = getProductIdByName(product);
  3241. if (entity.ProductId == 0)
  3242. {
  3243. return;
  3244. }
  3245. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  3246. if (cusInfo != null)
  3247. {
  3248. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3249. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3250. {
  3251. }
  3252. else
  3253. {
  3254. entity.OrderState = 2;
  3255. if (entity.ShopId != 0)
  3256. {
  3257. entity.OrderState = orderAudit(entity.ShopId);
  3258. }
  3259. if (entity.DesignUserId > 0)
  3260. {
  3261. entity.OrderState = 3;
  3262. }
  3263. }
  3264. }
  3265. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  3266. {
  3267. entity.IsOldCustomer = 1;
  3268. if (itemMemo.IndexOf("改稿") != -1)
  3269. {
  3270. if (entity.payment > 0)
  3271. {
  3272. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  3273. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3274. {
  3275. }
  3276. else
  3277. {
  3278. int designId = Convert.ToInt32(webConfig.PlaceChangeId);
  3279. CeErpUser oldGaiPlace = CeErpUser.Get(designId);
  3280. if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
  3281. {
  3282. }
  3283. else
  3284. {
  3285. designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3286. }
  3287. if (designId != 0)
  3288. {
  3289. entity.DesignUserId = designId;
  3290. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3291. entity.WaitDesignTime = DateTime.Now;
  3292. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
  3293. }
  3294. }
  3295. }
  3296. }
  3297. else
  3298. {
  3299. if (entity.payment != 0)
  3300. {
  3301. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  3302. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  3303. entity.WaitDesignTime = DateTime.Now;
  3304. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  3305. }
  3306. }
  3307. }
  3308. if (mt.IndexOf("铜板纸") != -1)
  3309. {
  3310. mt = mt.Replace("铜板纸", "铜版纸");
  3311. }
  3312. entity.Material = mt;
  3313. entity.ProductSize = size;
  3314. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
  3315. entity.Craft = ct;
  3316. entity.pay_time = father.pay_time;
  3317. if (product == "现货手提袋")
  3318. {
  3319. entity.OrderState = 6;//下单完成
  3320. entity.FinishPlaceTime = DateTime.Now;
  3321. }
  3322. string newmemo = "(" + father.tid + ")-";
  3323. string newOtherMemo = "";
  3324. if (itemMemo.IndexOf("海报") != -1)
  3325. {
  3326. newmemo = acclist[2];
  3327. newmemo += acclist[0];
  3328. newmemo += "-";
  3329. newmemo += acclist[1];
  3330. newmemo += "(";
  3331. newmemo += father.tid;
  3332. newmemo += ")";
  3333. newmemo += "-";
  3334. newmemo += acclist[4];
  3335. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3336. newmemo += ("-" + sName);
  3337. if (father.buyer_nick.IndexOf("*") < 0)
  3338. {
  3339. newmemo += ("-" + father.buyer_nick);
  3340. }
  3341. newmemo += ("-" + father.receiver_state);
  3342. if (cusInfo != null)
  3343. {
  3344. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3345. }
  3346. if (isMulity)
  3347. {
  3348. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3349. }
  3350. if (acclist.Length > 7)
  3351. {
  3352. for (int i = 7; i < acclist.Length; i++)
  3353. {
  3354. newOtherMemo += acclist[i];
  3355. newOtherMemo += "-";
  3356. }
  3357. }
  3358. }
  3359. else
  3360. {
  3361. if (acclist.Length >= 7)
  3362. {
  3363. newmemo += acclist[6];
  3364. newmemo += "-";
  3365. }
  3366. for (int i = 0; i < acclist.Length; i++)
  3367. {
  3368. if (i == 5)
  3369. {
  3370. continue;
  3371. }
  3372. if (i >= 7)
  3373. {
  3374. newOtherMemo += acclist[i];
  3375. newOtherMemo += "-";
  3376. }
  3377. else
  3378. {
  3379. if (i == 6)
  3380. {
  3381. continue;
  3382. }
  3383. else
  3384. newmemo += acclist[i];
  3385. if (i != 2 && i != 3)
  3386. {
  3387. newmemo += "-";
  3388. }
  3389. }
  3390. }
  3391. string sName = getShopSNameByName(father.seller_nick);
  3392. newmemo += (sName);
  3393. if (father.buyer_nick.IndexOf("*") < 0)
  3394. {
  3395. newmemo += ("-" + father.buyer_nick);
  3396. }
  3397. newmemo += ("-" + father.receiver_state);
  3398. if (cusInfo != null)
  3399. {
  3400. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3401. }
  3402. if (itemMemo.IndexOf("顺丰到付") != -1)
  3403. {
  3404. entity.IsSF = 2;
  3405. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3406. }
  3407. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3408. {
  3409. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3410. // newmemo += ("-顺丰寄付");
  3411. entity.IsSF = 1;
  3412. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3413. }
  3414. if (itemMemo.IndexOf("加急") != -1)
  3415. {
  3416. //if (newmemo.IndexOf("加急") == -1)
  3417. // newmemo += ("-加急");
  3418. entity.IsUrgency = true;
  3419. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3420. }
  3421. }
  3422. if (isMulity)
  3423. {
  3424. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3425. }
  3426. newmemo = newmemo.Replace("\n", " ");
  3427. entity.seller_memo = newmemo;
  3428. entity.OtherMemo = newOtherMemo;
  3429. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3430. {
  3431. string odt = commonHelper.getDateFromString(newOtherMemo);
  3432. if (odt.Length > 0)
  3433. {
  3434. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3435. }
  3436. }
  3437. if (entity.IsOldCustomer == 0)
  3438. {
  3439. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3440. {
  3441. //到了设计那边,就更新memo,状态不设置
  3442. }
  3443. else
  3444. {
  3445. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3446. if (oldRes > 0)
  3447. {
  3448. entity.IsOldCustomer = 1;
  3449. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3450. int curHour = DateTime.Now.Hour;
  3451. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3452. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3453. {
  3454. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3455. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3456. entity.DesignUserId = initSysDesignerId;
  3457. entity.WaitDesignTime = DateTime.Now;
  3458. }
  3459. else
  3460. {
  3461. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3462. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3463. {
  3464. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3465. entity.DesignUserId = initSysDesignerId;
  3466. entity.WaitDesignTime = DateTime.Now;
  3467. }
  3468. }
  3469. }
  3470. }
  3471. }
  3472. if (ishave)
  3473. {
  3474. entity.Update();
  3475. }
  3476. else
  3477. {
  3478. entity.Create();
  3479. }
  3480. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
  3481. }
  3482. public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
  3483. {
  3484. DateTime nowTime = DateTime.Now;
  3485. if (nowTime.Hour >= 17)
  3486. {
  3487. return 0;
  3488. }
  3489. string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
  3490. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3491. foreach (DataRow dr in dt.Rows)
  3492. {
  3493. if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"]) != Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
  3494. {
  3495. int designId = Convert.ToInt32(dr["DesignUserId"]);
  3496. string sql_user = "select * from view_erpuser where ','+pemShop+',' like '%," + shopId + ",%' and (PostCode='Designer' or PostCode='DesignerMr') and ','+pemDesign+',' like '%," + prodcutId + ",%' and OnDuty=1 and id=" + designId;
  3497. DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
  3498. if (dt_user.Rows.Count > 0)
  3499. {
  3500. return designId;
  3501. }
  3502. else
  3503. return 0;
  3504. }
  3505. }
  3506. return 0;
  3507. }
  3508. public static int getProductIdByName(string proName)
  3509. {
  3510. string dname = proName;
  3511. if (dname == "暧心贴")
  3512. {
  3513. dname = "暖心贴";
  3514. }
  3515. string sql = "select top 1 * from ce_erpproduct where uuid='" + dname + "';";
  3516. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3517. if (dt.Rows.Count > 0)
  3518. {
  3519. return Convert.ToInt32(dt.Rows[0]["ID"]);
  3520. }
  3521. return 0;
  3522. }
  3523. public static string getShopSNameByName(string seller_nick)
  3524. {
  3525. string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3526. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3527. if (dt.Rows.Count > 0)
  3528. {
  3529. return Convert.ToString(dt.Rows[0]["SName"]);
  3530. }
  3531. return "";
  3532. }
  3533. //public static string getShopRealName(string seller_nick)
  3534. //{
  3535. // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3536. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3537. // if (dt.Rows.Count > 0)
  3538. // {
  3539. // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
  3540. // return Convert.ToString(dt.Rows[0]["ShopName"]);
  3541. // }
  3542. // return seller_nick;
  3543. //}
  3544. public static DataRow getRelationOrder(string buyer, string sampTid)
  3545. {
  3546. string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer + "' and seller_memo not like '%补差价%' and tid<>'" + sampTid + "' order by id desc";
  3547. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3548. if (dt.Rows.Count > 0)
  3549. {
  3550. DataRow need = dt.Rows[0];
  3551. if (dt.Rows.Count == 1)
  3552. {
  3553. return need;
  3554. }
  3555. int idx = 0;
  3556. foreach (DataRow dr in dt.Rows)
  3557. {
  3558. if (idx != 0)
  3559. {
  3560. int day = Convert.ToDateTime(need["pay_time"]).Day;
  3561. int nday = Convert.ToDateTime(dr["pay_time"]).Day;
  3562. if (day == nday)
  3563. {
  3564. need = dr;
  3565. }
  3566. }
  3567. idx++;
  3568. }
  3569. return need;
  3570. }
  3571. return null;
  3572. }
  3573. public static DataRow getUserInfoByAccount(string account)
  3574. {
  3575. string sql = "select * from view_erpuser where isOpen=1 and Account='" + account + "'";
  3576. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3577. if (dt != null && dt.Rows.Count > 0)
  3578. {
  3579. return dt.Rows[0];
  3580. }
  3581. return null;
  3582. }
  3583. public static string getShopNameByECode(string code)
  3584. {
  3585. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  3586. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3587. if (dt != null && dt.Rows.Count > 0)
  3588. {
  3589. return dt.Rows[0]["ShopName"].ToString();
  3590. }
  3591. return "";
  3592. }
  3593. // 时间戳转为C#格式时间
  3594. public static DateTime StampToDateTime(string timeStamp)
  3595. {
  3596. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  3597. long lTime = long.Parse(timeStamp + "0000");
  3598. TimeSpan toNow = new TimeSpan(lTime);
  3599. return dateTimeStart.Add(toNow);
  3600. }
  3601. public static void Api_Tmc_CreateNewOrder(string res)
  3602. {
  3603. Api_trade_fullinfo_get_response_Obj fullObj = null;
  3604. if (res == "") return;
  3605. try
  3606. {
  3607. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  3608. //res = res.Replace(" ", "");
  3609. fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
  3610. }
  3611. catch (Exception ex)
  3612. {
  3613. XLog.SaveLog(0, ex.Message);
  3614. }
  3615. if (fullObj == null)
  3616. {
  3617. Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
  3618. return;
  3619. }
  3620. ContentItem tObj = null;
  3621. if (fullObj.response.data.content.Count > 0)
  3622. {
  3623. tObj = fullObj.response.data.content[0];
  3624. }
  3625. if (tObj == null)
  3626. {
  3627. return;
  3628. }
  3629. //未付款,未成功的单不需要
  3630. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  3631. {
  3632. return;
  3633. }
  3634. List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
  3635. StringBuilder sql = new StringBuilder();
  3636. CeErpTrade trade = CeErpTrade.Get(tObj.refOid);
  3637. bool isCreate = false;
  3638. if (trade == null)
  3639. {
  3640. trade = new CeErpTrade();
  3641. isCreate = true;
  3642. }
  3643. //原始单创建
  3644. trade.tid = tObj.refOid;
  3645. if (tObj.posCode != null)
  3646. trade.posCode = tObj.posCode;
  3647. //trade.num = tObj.num;
  3648. trade.status = tObj.status;
  3649. trade.seller_flag = tObj.flag;
  3650. trade.type = tObj.refType;
  3651. trade.price = Convert.ToDouble(tObj.totalPrice);
  3652. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  3653. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  3654. trade.created = StampToDateTime(tObj.orderTime);
  3655. if (tObj.payTime != null)
  3656. {
  3657. trade.pay_time = StampToDateTime(tObj.payTime);
  3658. }
  3659. if (tObj.modifyTime != null)
  3660. {
  3661. trade.modified = StampToDateTime(tObj.modifyTime);
  3662. }
  3663. if (tObj.finishTime != null)
  3664. {
  3665. trade.end_time = StampToDateTime(tObj.finishTime);
  3666. }
  3667. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  3668. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  3669. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  3670. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  3671. if (trade.seller_nick == "")
  3672. {
  3673. trade.seller_nick = getShopNameByECode(trade.posCode);
  3674. }
  3675. trade.payment = Convert.ToDouble(tObj.payment);
  3676. //trade.receiver_name = tObj.receiver_name;
  3677. trade.receiver_state = tObj.receiverState;
  3678. trade.receiver_city = tObj.receiverCity;
  3679. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  3680. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  3681. //trade.receiver_address = tObj.receiver_address;
  3682. //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  3683. //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  3684. //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  3685. //{
  3686. // trade.consign_time = tObj.consign_time;
  3687. //}
  3688. if (tObj.shippingTime != null)
  3689. {
  3690. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  3691. }
  3692. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  3693. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  3694. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  3695. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  3696. {
  3697. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  3698. {
  3699. string[] acclist = tObj.sellerMemo.Split('-');
  3700. List<string> list = new List<string>(acclist);
  3701. string buyer_nick = "";
  3702. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  3703. {
  3704. if (list.Count > 3)
  3705. {
  3706. buyer_nick = list[3];
  3707. }
  3708. }
  3709. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  3710. {
  3711. if (list.Count > 1)
  3712. {
  3713. buyer_nick = list[1];
  3714. }
  3715. }
  3716. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  3717. {
  3718. if (list.Count > 1)
  3719. {
  3720. buyer_nick = list[1];
  3721. }
  3722. }
  3723. else if (trade.seller_memo.IndexOf("寄样") != -1)
  3724. {
  3725. if (list.Count > 3)
  3726. {
  3727. buyer_nick = list[3];
  3728. }
  3729. }
  3730. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  3731. {
  3732. if (list.Count > 1)
  3733. {
  3734. buyer_nick = list[1];
  3735. }
  3736. }
  3737. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  3738. {
  3739. if (list.Count > 1)
  3740. {
  3741. buyer_nick = list[1];
  3742. }
  3743. }
  3744. else
  3745. {
  3746. if (list.Count > 5)
  3747. {
  3748. buyer_nick = list[5];
  3749. }
  3750. }
  3751. tObj.sellerMemo = string.Join("-", list);
  3752. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  3753. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  3754. }
  3755. }
  3756. if (isCreate)
  3757. {
  3758. trade.Create();
  3759. }
  3760. else
  3761. {
  3762. trade.Update();
  3763. }
  3764. bool isXianhuo = false;
  3765. string xianhuoMemo = "(" + trade.tid + ")现货-";
  3766. //order表创建
  3767. foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
  3768. {
  3769. bool orderCreate = false;
  3770. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  3771. if (order == null)
  3772. {
  3773. order = new CeErpTradeOrder();
  3774. orderCreate = true;
  3775. }
  3776. order.tid = trade.tid;
  3777. order.oid = item.refOlId;
  3778. order.buyer_nick = trade.buyer_nick;
  3779. order.refund_status = item.refundStatus;
  3780. order.status = trade.status;
  3781. order.title = item.title;
  3782. order.price = Convert.ToDouble(item.price);
  3783. if (item.picUrl != null)
  3784. order.pic_path = item.picUrl;
  3785. order.num = Convert.ToDouble(item.num.ToString());
  3786. order.payment = Convert.ToDouble(item.price);
  3787. //order.adjust_fee = Convert.ToDouble(item.price);
  3788. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  3789. {
  3790. order.sku_properties_name = item.standards;
  3791. order.sku_id = item.refSkuId;
  3792. isXianhuo = true;
  3793. xianhuoMemo += order.sku_properties_name;
  3794. xianhuoMemo += ("-数量:" + order.num + "; ");
  3795. }
  3796. if (orderCreate)
  3797. {
  3798. order.Create();
  3799. }
  3800. else
  3801. {
  3802. order.Update();
  3803. }
  3804. }
  3805. //if (isXianhuo)
  3806. //{
  3807. // xianhuoMemo += "-";
  3808. // xianhuoMemo += trade.seller_nick;
  3809. //}
  3810. //cell表创建
  3811. CeErpTradeCell entity = null;
  3812. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  3813. if (entity == null)
  3814. {
  3815. try
  3816. {
  3817. entity = new CeErpTradeCell();
  3818. entity.ctid = tObj.refOid;
  3819. entity.tid = tObj.refOid;
  3820. entity.payment = Convert.ToDouble(tObj.payment);
  3821. if (tObj.payTime != null)
  3822. {
  3823. entity.pay_time = StampToDateTime(tObj.payTime);
  3824. }
  3825. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  3826. int shopId = 0;
  3827. if (nShop != null)
  3828. {
  3829. shopId = nShop.ID;
  3830. }
  3831. entity.ShopId = shopId;
  3832. if (isXianhuo)
  3833. {
  3834. entity.OrderState = 6;//现货直接下单完成
  3835. entity.seller_memo = xianhuoMemo;
  3836. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  3837. entity.IsXianHuo = 1;
  3838. entity.FinishPlaceTime = entity.pay_time;
  3839. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  3840. {
  3841. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  3842. if (trade.buyer_memo != "")
  3843. {
  3844. entity.OrderState = 2; //买家有备注的要设计
  3845. entity.ProductId = 1;
  3846. entity.IsXianHuo = 0;
  3847. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  3848. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  3849. entity.seller_memo = xianhuoMemo;
  3850. }
  3851. }
  3852. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  3853. {
  3854. entity.SupplierId = 70; //智涛
  3855. }
  3856. //if (trade != null)
  3857. //{
  3858. // trade.seller_memo = xianhuoMemo;
  3859. // trade.Update();
  3860. //}
  3861. }
  3862. entity.Create();
  3863. }
  3864. catch (Exception ex)
  3865. {
  3866. XLog.SaveLog(0, ex.Message);
  3867. }
  3868. }
  3869. if (tObj.sellerMemo.Length > 0)
  3870. {
  3871. try
  3872. {
  3873. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  3874. }
  3875. catch (Exception ex)
  3876. {
  3877. XLog.SaveLog(0, res + "|" + ex.Message);
  3878. }
  3879. }
  3880. ////生成档案客户信息
  3881. //insertCustomerInfo(tObj);
  3882. }
  3883. public static int isOldCustomerOrder(CeErpTrade father)
  3884. {
  3885. if (father.seller_nick == "") return 0;
  3886. CeErpCustomer cusone = null;
  3887. cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  3888. if (cusone != null)
  3889. {
  3890. return 1;
  3891. }
  3892. return 0;
  3893. }
  3894. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  3895. {
  3896. if (father.seller_nick == "") return 0;
  3897. CeErpCustomer cus = null;
  3898. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  3899. if (cus == null)
  3900. {
  3901. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  3902. }
  3903. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  3904. //CeErpCustomer cusone = null;
  3905. //cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  3906. if (cus != null)
  3907. {
  3908. if (cus.lastbuy_time.ToString() == "") return 0;
  3909. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  3910. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  3911. //cus.phone = Obj.receiver_mobile;
  3912. cus.buyer_id = father.buyer_id;
  3913. int returnNum = 0;
  3914. int lastpCount = cus.product_count;
  3915. if (cus.lastTid == father.tid)
  3916. {
  3917. if (pcount != cus.product_count)
  3918. {
  3919. cus.product_count = pcount;
  3920. cus.Update();
  3921. }
  3922. }
  3923. else
  3924. {
  3925. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  3926. cus.buyer_nick = father.buyer_nick;
  3927. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  3928. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  3929. cus.buy_count = cus.buy_count + 1;
  3930. cus.lastbuy_time2 = cus.lastbuy_time;
  3931. cus.lastbuy_time = father.pay_time;
  3932. cus.product_count = pcount;
  3933. cus.lastTid2 = cus.lastTid;
  3934. cus.lastTid = father.tid;
  3935. cus.Update();
  3936. }
  3937. if (cus.buy_day > 1)
  3938. {
  3939. if (pcount > lastpCount && cus.product_count != 0)
  3940. {
  3941. cus.isMore = 1;
  3942. returnNum = 2;
  3943. }
  3944. else
  3945. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  3946. }
  3947. else
  3948. {
  3949. returnNum = 0;
  3950. }
  3951. return returnNum;
  3952. }
  3953. //else if (cusone != null)
  3954. //{
  3955. // cusone.seller_nick = father.seller_nick;
  3956. // TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
  3957. // cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
  3958. // cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
  3959. // cusone.buy_count = cusone.buy_count + 1;
  3960. // cusone.lastbuy_time2 = cusone.lastbuy_time;
  3961. // cusone.lastbuy_time = father.pay_time;
  3962. // cusone.product_count = pcount;
  3963. // cusone.lastTid2 = cusone.lastTid;
  3964. // cusone.lastTid = father.tid;
  3965. // cusone.Update();
  3966. // return 1;
  3967. //}
  3968. else
  3969. {
  3970. try
  3971. {
  3972. cus = new CeErpCustomer();
  3973. cus.buyer_nick = father.buyer_nick;
  3974. cus.seller_nick = father.seller_nick;
  3975. cus.buyer_id = father.buyer_id;
  3976. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  3977. //cus.phone = Obj.receiver_mobile;
  3978. cus.buy_day = 0;
  3979. cus.buy_count = 1;
  3980. cus.lastbuy_time = father.pay_time;
  3981. cus.lastTid = father.tid;
  3982. cus.total_fee = Convert.ToDouble(father.payment);
  3983. cus.product_count = pcount;
  3984. cus.Create();
  3985. //StringBuilder sql = new StringBuilder();
  3986. //sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
  3987. //DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  3988. //if (dt.Rows.Count > 0)
  3989. //{
  3990. // return true;
  3991. //}
  3992. return 0;
  3993. }
  3994. catch (Exception ex)
  3995. {
  3996. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  3997. }
  3998. }
  3999. return 0;
  4000. }
  4001. public static void removeOldCustomerInfo(CeErpTrade trade)
  4002. {
  4003. CeErpCustomer cus = null;
  4004. cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
  4005. if (cus != null)
  4006. {
  4007. if (cus.lastTid == trade.tid)
  4008. {
  4009. if (cus.buy_count > 1)
  4010. {
  4011. cus.lastTid = cus.lastTid2;
  4012. cus.lastbuy_time = cus.lastbuy_time2;
  4013. cus.buy_count = cus.buy_count - 1;
  4014. cus.Update();
  4015. }
  4016. else
  4017. {
  4018. CeErpCustomer.Del(cus.ID);
  4019. }
  4020. }
  4021. }
  4022. }
  4023. //接收到--新订单生成消息
  4024. public static void API_Tmc_TradeBuyerPay(string content)
  4025. {
  4026. Api_tmc_trade_info_Obj fullObj = null;
  4027. if (content == "") return;
  4028. try
  4029. {
  4030. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4031. //res = res.Replace(" ", "");
  4032. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4033. }
  4034. catch (Exception ex)
  4035. {
  4036. }
  4037. if (fullObj == null)
  4038. {
  4039. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4040. return;
  4041. }
  4042. Content tObj = fullObj.content;
  4043. string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
  4044. Api_Tmc_CreateNewOrder(res);
  4045. }
  4046. //推送接收到卖家备注修改
  4047. public static void API_Tmc_TradeMemoModified(string content)
  4048. {
  4049. Api_tmc_trade_info_Obj fullObj = null;
  4050. if (content == "") return;
  4051. try
  4052. {
  4053. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4054. //res = res.Replace(" ", "");
  4055. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4056. }
  4057. catch (Exception ex)
  4058. {
  4059. }
  4060. if (fullObj == null)
  4061. {
  4062. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4063. return;
  4064. }
  4065. Content tObj = fullObj.content;
  4066. //原始表--没有这个单,不能拆分
  4067. CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
  4068. if (mainEn == null) return;
  4069. createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
  4070. }
  4071. public static int orderAudit(int shopId)
  4072. {
  4073. try
  4074. {
  4075. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  4076. if (ceErpShop == null) return 2;
  4077. if (!ceErpShop.orderAudit) return 2;
  4078. return -1;
  4079. }
  4080. catch (Exception ex)
  4081. {
  4082. return 2;
  4083. }
  4084. }
  4085. public static void autoCell(string tid)
  4086. {
  4087. if (tid.Length == 0)
  4088. {
  4089. return;
  4090. }
  4091. DateTime nowTime = DateTime.Now;
  4092. if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
  4093. {
  4094. return;
  4095. }
  4096. try
  4097. {
  4098. string sql = string.Format("select ctid,IsOldCustomer,shopid from view_ErpTradeCell where tid='{0}' and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and isrefund=0 order by IsUrgency desc,pay_time asc;", tid);
  4099. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4100. if (dt != null && dt.Rows.Count > 0)
  4101. {
  4102. bool changeBl = false;
  4103. //int c = Convert.ToInt32(result);// / 20 + 1;
  4104. foreach (DataRow dr in dt.Rows)
  4105. {
  4106. if (nowTime.Hour > 12 && nowTime.Hour < 17)
  4107. {
  4108. //这段时间白班晚班平均分配
  4109. if (changeBl)
  4110. {
  4111. changeBl = false;
  4112. }
  4113. else
  4114. {
  4115. changeBl = true;
  4116. }
  4117. }
  4118. else
  4119. changeBl = false;
  4120. string IsOldCustomer = dr["IsOldCustomer"].ToString();
  4121. string res = "";
  4122. CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
  4123. int userId = 0;
  4124. if (ceErpShop != null)
  4125. {
  4126. userId = ceErpShop.UserID;
  4127. }
  4128. SqlParameter[] sqlParameter = {
  4129. new SqlParameter("@inctid", SqlDbType.VarChar,200),
  4130. new SqlParameter("@intype", SqlDbType.Int,5),
  4131. new SqlParameter("@res", SqlDbType.VarChar, 50) };
  4132. sqlParameter[0].Value = dr["ctid"].ToString();
  4133. sqlParameter[1].Value = changeBl ? 1 : 0;
  4134. sqlParameter[2].Direction = ParameterDirection.Output;
  4135. if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
  4136. {
  4137. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
  4138. }
  4139. else
  4140. {
  4141. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
  4142. }
  4143. res = sqlParameter[2].Value.ToString();
  4144. }
  4145. }
  4146. }
  4147. catch (Exception ex)
  4148. {
  4149. XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
  4150. }
  4151. }
  4152. }
  4153. }