tmcHelper.cs 178 KB

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