tmcHelper.cs 184 KB

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