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