tmcHelper.cs 196 KB

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