tmcHelper.cs 181 KB

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