tmcHelper.cs 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512
  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"
  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. }
  1659. entity.ctid = ctid;
  1660. //唯一标识
  1661. entity.OrderSn = ctid;
  1662. /*string orderSn = dataHelper.getSaleOrderSn();
  1663. if (orderSn != "")
  1664. {
  1665. entity.OrderSn = orderSn;
  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. }
  2046. entity.ctid = ctid;
  2047. //唯一标识
  2048. entity.OrderSn = ctid;
  2049. /*string orderSn = dataHelper.getSaleOrderSn();
  2050. if (orderSn != "")
  2051. {
  2052. entity.OrderSn = orderSn;
  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. //唯一标识
  2243. entity.OrderSn = ctid;
  2244. /*string orderSn = dataHelper.getSaleOrderSn();
  2245. if (orderSn != "")
  2246. {
  2247. entity.OrderSn = orderSn;
  2248. }*/
  2249. entity.tid = father.tid;
  2250. entity.SplitTag = splitTag;
  2251. string[] acclist = itemMemo.Split('-');
  2252. if (acclist.Length < 2) return;
  2253. if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
  2254. {
  2255. return;
  2256. }
  2257. string product = acclist[0];
  2258. string account = acclist[1];
  2259. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2260. if (cusInfo != null)
  2261. {
  2262. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2263. }
  2264. entity.IsOldCustomer = 0;
  2265. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  2266. entity.IsXianHuo = 1;
  2267. entity.IsGift = 1;
  2268. entity.FinishPlaceTime = father.pay_time;
  2269. if (entity.OrderState < 6)
  2270. {
  2271. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2272. }
  2273. if (isMulty)
  2274. {
  2275. try
  2276. {
  2277. string strPrice = acclist[2];
  2278. if (strPrice.IndexOf("元") != -1)
  2279. {
  2280. strPrice = strPrice.Replace("元", "");
  2281. }
  2282. entity.payment = Convert.ToDouble(strPrice);
  2283. hePrice = hePrice - Convert.ToDecimal(acclist[2]);
  2284. }
  2285. catch (Exception ex)
  2286. {
  2287. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2288. }
  2289. }
  2290. else
  2291. {
  2292. entity.payment = Convert.ToDouble(father.payment);
  2293. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2294. }
  2295. string newmemo = "(" + entity.OrderSn + ")-";
  2296. string newOtherMemo = "";
  2297. for (int i = 0; i < acclist.Length; i++)
  2298. {
  2299. if (i == 1) continue;
  2300. newmemo += acclist[i];
  2301. if (i < acclist.Length - 1)
  2302. {
  2303. newmemo += "-";
  2304. }
  2305. }
  2306. string sName = getShopSNameByName(father.seller_nick);
  2307. newmemo += ("" + sName);
  2308. newmemo += ("-" + father.buyer_nick);
  2309. newmemo += ("-" + father.receiver_state);
  2310. if (cusInfo != null)
  2311. {
  2312. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2313. }
  2314. if (isMulty)
  2315. {
  2316. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2317. }
  2318. if (newmemo.IndexOf("现货") != -1)
  2319. {
  2320. newmemo = newmemo.Replace("礼物", "");
  2321. }
  2322. if (itemMemo.IndexOf("顺丰到付") != -1)
  2323. {
  2324. newmemo += ("-顺丰到付");
  2325. entity.IsSF = 2;
  2326. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2327. }
  2328. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2329. {
  2330. newmemo += ("-顺丰寄付");
  2331. entity.IsSF = 1;
  2332. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2333. }
  2334. if (itemMemo.IndexOf("加急") != -1)
  2335. {
  2336. newmemo += ("-加急");
  2337. entity.IsUrgency = true;
  2338. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2339. }
  2340. entity.seller_memo = newmemo;
  2341. entity.OtherMemo = newOtherMemo;
  2342. entity.pay_time = father.pay_time;
  2343. if (isNull)
  2344. {
  2345. father.create_time = DateTime.Now;
  2346. father.Update();
  2347. entity.Create();
  2348. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2349. }
  2350. else
  2351. {
  2352. entity.Update();
  2353. }
  2354. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2355. CeErpSukuraData.createInfo(entity.ctid, 1);
  2356. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
  2357. }
  2358. public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
  2359. {
  2360. if (itemMemo.Length <= 0) return;
  2361. string[] hebaoMemoList = itemMemo.Split(',');
  2362. string memo_index1 = hebaoMemoList[0];
  2363. string ctid = "";
  2364. string splitTag = "";
  2365. if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
  2366. {
  2367. string preStr = "C" + orderIndex + "_";
  2368. ctid = preStr + father.tid;
  2369. splitTag = "C" + orderIndex + "+" + orderIndex;
  2370. }
  2371. else if (itemMemo.Length > 2)
  2372. {
  2373. ctid = father.tid;
  2374. }
  2375. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2376. bool ishave = true;
  2377. if (entity == null)
  2378. {
  2379. entity = new CeErpTradeCell();
  2380. ishave = false;
  2381. }
  2382. if (entity.ShopId == 0)
  2383. {
  2384. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2385. int shopId = 0;
  2386. if (nShop != null)
  2387. {
  2388. shopId = nShop.ID;
  2389. }
  2390. entity.ShopId = shopId;
  2391. }
  2392. if (entity.IsSample == 1 || entity.IsSample == 2)
  2393. {
  2394. entity.IsSample = 0;
  2395. entity.ptid = "";
  2396. }
  2397. if (entity.isDianziOrder == 1)
  2398. {
  2399. entity.isDianziOrder = 0;
  2400. }
  2401. entity.ctid = ctid;
  2402. //唯一标识
  2403. entity.OrderSn = ctid;
  2404. /* string orderSn = dataHelper.getSaleOrderSn();
  2405. if (orderSn != "")
  2406. {
  2407. entity.OrderSn = orderSn;
  2408. }*/
  2409. entity.tid = father.tid;
  2410. entity.SplitTag = splitTag;
  2411. string[] acclist = memo_index1.Split('-');
  2412. bool isXianhuo = false;
  2413. if (acclist[0] == "现货")
  2414. {
  2415. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2416. System.Array.Resize(ref acclist, acclist.Length - 1);
  2417. isXianhuo = true;
  2418. }
  2419. if (acclist.Length < 6)
  2420. {
  2421. return;
  2422. }
  2423. string size = acclist[0];
  2424. string count = acclist[1];
  2425. bool isBuGanJiao = false;
  2426. string product = "";
  2427. string mt = "", ct = "";
  2428. string account = "";
  2429. memo_index1 = memo_index1.Replace("PVC", "pvc");
  2430. if ((acclist[3] == "不干胶" || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("礼物") == -1)
  2431. {
  2432. isBuGanJiao = true;
  2433. product = acclist[3];
  2434. mt = acclist[2];
  2435. }
  2436. else
  2437. {
  2438. product = acclist[2];
  2439. mt = acclist[3];
  2440. }
  2441. account = acclist[5];
  2442. ct = acclist[4];
  2443. entity.ProductId = getProductIdByName(product);
  2444. if (entity.ProductId == 0)
  2445. {
  2446. return;
  2447. }
  2448. if (isMulity && hePrice != 0)
  2449. {
  2450. entity.payment = Convert.ToDouble(hePrice);
  2451. }
  2452. else
  2453. {
  2454. entity.payment = father.payment;
  2455. }
  2456. DataRow cusInfo = getUserInfoByAccount(account);
  2457. if (cusInfo != null)
  2458. {
  2459. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2460. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2461. {
  2462. }
  2463. else
  2464. {
  2465. entity.OrderState = 2;
  2466. if (entity.ShopId != 0)
  2467. {
  2468. entity.OrderState = orderAudit(entity.ShopId);
  2469. }
  2470. if (entity.DesignUserId > 0)
  2471. {
  2472. entity.OrderState = 3;
  2473. }
  2474. }
  2475. }
  2476. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2477. {
  2478. entity.IsOldCustomer = 1;
  2479. if (itemMemo.IndexOf("改稿") != -1)
  2480. {
  2481. if (entity.payment > 0)
  2482. {
  2483. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  2484. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2485. {
  2486. }
  2487. else
  2488. {
  2489. dealOldCustomerEntityTag(ref entity, father);
  2490. }
  2491. }
  2492. }
  2493. else
  2494. {
  2495. entity.OrderState = 3;
  2496. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2497. entity.WaitDesignTime = DateTime.Now;
  2498. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2499. }
  2500. }
  2501. entity.Material = mt;
  2502. entity.ProductSize = size;
  2503. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count); ;
  2504. entity.Craft = ct;
  2505. entity.pay_time = father.pay_time;
  2506. string newmemo = "(" + entity.OrderSn + ")-";
  2507. if (isXianhuo)
  2508. {
  2509. newmemo += "现货-";
  2510. entity.IsXianHuo = 1;
  2511. }
  2512. string newOtherMemo = "";
  2513. for (int idx = 0; idx < hebaoMemoList.Length; idx++)
  2514. {
  2515. string smallitem = hebaoMemoList[idx];
  2516. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  2517. {
  2518. newmemo = "";
  2519. }
  2520. string[] smallList = smallitem.Split('-');
  2521. if (smallList.Length > 5 && idx > 0)
  2522. {
  2523. string itemsize = smallList[0];
  2524. string itemcount = smallList[1];
  2525. string itemmt = "", itemct = "";
  2526. if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
  2527. {
  2528. itemmt = acclist[2];
  2529. }
  2530. else
  2531. {
  2532. itemmt = acclist[3];
  2533. }
  2534. itemct = acclist[4];
  2535. entity.ProductSize = entity.ProductSize + "," + itemsize;
  2536. entity.ProductCount = entity.ProductCount + "," + itemcount;
  2537. entity.Material = entity.Material + "," + itemmt;
  2538. entity.Craft = entity.Craft + "," + itemct;
  2539. }
  2540. if (smallList.Length >= 7)
  2541. {
  2542. smallList[6] = smallList[6].Replace("(", "");
  2543. smallList[6] = smallList[6].Replace(")", "");
  2544. smallList[6] = smallList[6].Replace("(", "");
  2545. smallList[6] = smallList[6].Replace(")", "");
  2546. entity.MakeSupplier = smallList[6];
  2547. smallList[6] = "(" + smallList[6] + ")";
  2548. newmemo += smallList[6];
  2549. newmemo += "-";
  2550. }
  2551. if (smallitem.IndexOf("海报") != -1)
  2552. {
  2553. newmemo += smallList[2];
  2554. newmemo += smallList[0];
  2555. newmemo += "-";
  2556. newmemo += smallList[1];
  2557. newmemo += "(";
  2558. newmemo += father.tid;
  2559. newmemo += ")";
  2560. newmemo += "-";
  2561. newmemo += smallList[4];
  2562. if (smallList.Length > 7)
  2563. {
  2564. for (int i = 7; i < smallList.Length; i++)
  2565. {
  2566. newOtherMemo += smallList[i];
  2567. newOtherMemo += "-";
  2568. }
  2569. }
  2570. if (smallitem.IndexOf("5mmpvc") != -1)
  2571. {
  2572. entity.ProductId = 8; //pvc卡片
  2573. }
  2574. }
  2575. else
  2576. {
  2577. for (int i = 0; i < smallList.Length; i++)
  2578. {
  2579. if (isMulity && i == 5)
  2580. {
  2581. continue;
  2582. }
  2583. if (i >= 7)
  2584. {
  2585. newOtherMemo += smallList[i];
  2586. if (i < smallList.Length - 2 && i != 2 && i != 3)
  2587. {
  2588. newOtherMemo += "-";
  2589. }
  2590. }
  2591. else
  2592. {
  2593. if (i == 6)
  2594. {
  2595. continue;
  2596. }
  2597. else
  2598. newmemo += smallList[i];
  2599. if (i != 2 && i != 3)
  2600. {
  2601. newmemo += "-";
  2602. }
  2603. }
  2604. }
  2605. }
  2606. if (hebaoMemoList.Length > idx + 1)
  2607. {
  2608. newmemo += ",";
  2609. newOtherMemo += ",";
  2610. }
  2611. }
  2612. string sName = getShopSNameByName(father.seller_nick);
  2613. newmemo += (sName);
  2614. if (father.buyer_nick.IndexOf("*") < 0)
  2615. {
  2616. newmemo += ("-" + father.buyer_nick);
  2617. }
  2618. newmemo += ("-" + father.receiver_state);
  2619. if (cusInfo != null)
  2620. {
  2621. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2622. }
  2623. if (orderIndex > 1 && isMulity)
  2624. {
  2625. newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
  2626. }
  2627. //newmemo += "-合包";
  2628. if (itemMemo.IndexOf("顺丰到付") != -1)
  2629. {
  2630. //if(newmemo.IndexOf("顺丰到付")==-1)
  2631. // newmemo += ("-顺丰到付");
  2632. entity.IsSF = 2;
  2633. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2634. }
  2635. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2636. {
  2637. //if (newmemo.IndexOf("顺丰寄付") == -1)
  2638. // newmemo += ("-顺丰寄付");
  2639. entity.IsSF = 1;
  2640. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2641. }
  2642. if (itemMemo.IndexOf("加急") != -1)
  2643. {
  2644. //if (newmemo.IndexOf("加急") == -1)
  2645. // newmemo += ("-加急");
  2646. entity.IsUrgency = true;
  2647. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2648. }
  2649. entity.seller_memo = newmemo;
  2650. entity.OtherMemo = newOtherMemo;
  2651. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  2652. {
  2653. string odt = commonHelper.getDateFromString(newOtherMemo);
  2654. if (odt.Length > 0)
  2655. {
  2656. entity.OldCustomerTime = Convert.ToDateTime(odt);
  2657. }
  2658. }
  2659. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2660. {
  2661. }
  2662. else
  2663. {
  2664. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  2665. {
  2666. entity.IsOldCustomer = 0;
  2667. }
  2668. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2669. if (oldRes > 0)
  2670. {
  2671. entity.IsOldCustomer = 1;
  2672. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2673. dealOldCustomerEntityAuto(ref entity);
  2674. }
  2675. }
  2676. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  2677. {
  2678. entity.OrderState = 6;
  2679. entity.FinishPlaceTime = DateTime.Now;
  2680. entity.SupplierId = 98;//-领鸿
  2681. }
  2682. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  2683. {
  2684. entity.OrderState = 6;
  2685. entity.FinishPlaceTime = DateTime.Now;
  2686. entity.SupplierId = 5;//-福广
  2687. }
  2688. if (ishave)
  2689. {
  2690. entity.Update();
  2691. }
  2692. else
  2693. {
  2694. father.create_time = DateTime.Now;
  2695. father.Update();
  2696. entity.Create();
  2697. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2698. }
  2699. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2700. CeErpSukuraData.createInfo(entity.ctid, 1);
  2701. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
  2702. }
  2703. public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2704. {
  2705. if (itemMemo.Length <= 0) return;
  2706. //itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
  2707. string ctid = "";
  2708. string splitTag = "";
  2709. if (isMulity && itemMemo.Length > 2)
  2710. {
  2711. string preStr = "C" + orderIndex + "_";
  2712. ctid = preStr + father.tid;
  2713. splitTag = "C" + totalCount + "+" + orderIndex;
  2714. }
  2715. else if (itemMemo.Length > 2)
  2716. {
  2717. ctid = father.tid;
  2718. }
  2719. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2720. bool ishave = true;
  2721. if (entity == null)
  2722. {
  2723. entity = new CeErpTradeCell();
  2724. ishave = false;
  2725. }
  2726. entity.ctid = ctid;
  2727. //唯一标识
  2728. entity.OrderSn = ctid;
  2729. /* string orderSn = dataHelper.getSaleOrderSn();
  2730. if (orderSn != "")
  2731. {
  2732. entity.OrderSn = orderSn;
  2733. }*/
  2734. entity.tid = father.tid;
  2735. entity.SplitTag = splitTag;
  2736. string[] acclist = itemMemo.Split('-');
  2737. bool isXianhuo = false;
  2738. if (acclist[0] == "现货")
  2739. {
  2740. isXianhuo = true;
  2741. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2742. System.Array.Resize(ref acclist, acclist.Length - 1);
  2743. }
  2744. if (entity.ShopId == 0)
  2745. {
  2746. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2747. int shopId = 0;
  2748. if (nShop != null)
  2749. {
  2750. shopId = nShop.ID;
  2751. }
  2752. entity.ShopId = shopId;
  2753. }
  2754. if (entity.IsSample == 1 || entity.IsSample == 2)
  2755. {
  2756. entity.IsSample = 0;
  2757. entity.ptid = "";
  2758. }
  2759. if (entity.isDianziOrder == 1)
  2760. {
  2761. entity.isDianziOrder = 0;
  2762. }
  2763. if (entity.IsXianHuo == 1)
  2764. {
  2765. entity.IsXianHuo = 0;
  2766. }
  2767. if (isMulity && acclist.Length < 7)
  2768. {
  2769. return;
  2770. }
  2771. if (acclist.Length < 6)
  2772. {
  2773. return;
  2774. }
  2775. string size = acclist[0];
  2776. string count = acclist[1];
  2777. bool isBuGanJiao = false;
  2778. string product = "";
  2779. string mt = "", ct = "";
  2780. string account = "";
  2781. itemMemo = itemMemo.Replace("PVC", "pvc");
  2782. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  2783. {
  2784. isBuGanJiao = true;
  2785. product = acclist[3];
  2786. mt = acclist[2];
  2787. }
  2788. else
  2789. {
  2790. product = acclist[2];
  2791. mt = acclist[3];
  2792. }
  2793. account = acclist[5];
  2794. ct = acclist[4];
  2795. if (isMulity)
  2796. {
  2797. try
  2798. {
  2799. string strPrice = acclist[6];
  2800. if (strPrice.IndexOf("元") != -1)
  2801. {
  2802. strPrice = strPrice.Replace("元", "");
  2803. }
  2804. entity.payment = Convert.ToDouble(strPrice);
  2805. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2806. }
  2807. catch (Exception ex)
  2808. {
  2809. entity.payment = 0;
  2810. return;
  2811. }
  2812. if (acclist.Length >= 8)
  2813. {
  2814. acclist[7] = acclist[7].Replace("(", "");
  2815. acclist[7] = acclist[7].Replace(")", "");
  2816. acclist[7] = acclist[7].Replace("(", "");
  2817. acclist[7] = acclist[7].Replace(")", "");
  2818. entity.MakeSupplier = acclist[7];
  2819. acclist[7] = "(" + acclist[7] + ")";
  2820. }
  2821. }
  2822. else
  2823. {
  2824. entity.payment = father.payment;
  2825. if (acclist.Length >= 7)
  2826. {
  2827. acclist[6] = acclist[6].Replace("(", "");
  2828. acclist[6] = acclist[6].Replace(")", "");
  2829. acclist[6] = acclist[6].Replace("(", "");
  2830. acclist[6] = acclist[6].Replace(")", "");
  2831. entity.MakeSupplier = acclist[6];
  2832. acclist[6] = "(" + acclist[6] + ")";
  2833. }
  2834. }
  2835. entity.ProductId = getProductIdByName(product);
  2836. if (entity.ProductId == 0)
  2837. {
  2838. return;
  2839. }
  2840. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2841. if (cusInfo != null)
  2842. {
  2843. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2844. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2845. {
  2846. }
  2847. else
  2848. {
  2849. entity.OrderState = 2;
  2850. if (entity.ShopId != 0)
  2851. {
  2852. entity.OrderState = orderAudit(entity.ShopId);
  2853. }
  2854. if (entity.DesignUserId > 0)
  2855. {
  2856. entity.OrderState = 3;
  2857. }
  2858. }
  2859. }
  2860. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2861. {
  2862. entity.IsOldCustomer = 1;
  2863. if (itemMemo.IndexOf("改稿") != -1)
  2864. {
  2865. if (entity.payment > 0)
  2866. {
  2867. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2868. {
  2869. }
  2870. else
  2871. {
  2872. dealOldCustomerEntityTag(ref entity, father);
  2873. }
  2874. }
  2875. }
  2876. else
  2877. {
  2878. if (entity.payment != 0)
  2879. {
  2880. entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
  2881. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  2882. entity.WaitDesignTime = DateTime.Now;
  2883. entity.FinishPlaceTime = DateTime.Now;
  2884. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  2885. }
  2886. }
  2887. }
  2888. if (mt.IndexOf("铜板纸") != -1)
  2889. {
  2890. mt = mt.Replace("铜板纸", "铜版纸");
  2891. }
  2892. entity.Material = mt;
  2893. entity.ProductSize = size;
  2894. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
  2895. entity.Craft = ct;
  2896. entity.pay_time = father.pay_time;
  2897. if (itemMemo.IndexOf("电子稿") != -1)
  2898. {
  2899. entity.isDianziOrder = 1;
  2900. }
  2901. if (product == "现货手提袋")
  2902. {
  2903. entity.OrderState = 6;//下单完成
  2904. entity.FinishPlaceTime = DateTime.Now;
  2905. }
  2906. string newmemo = "(" + entity.OrderSn + ")-";
  2907. if (isXianhuo)
  2908. {
  2909. newmemo += "现货-";
  2910. entity.IsXianHuo = 1;
  2911. }
  2912. string newOtherMemo = "";
  2913. if (false)
  2914. {
  2915. newmemo = acclist[2];
  2916. newmemo += acclist[0];
  2917. newmemo += "-";
  2918. newmemo += acclist[1];
  2919. newmemo += "(";
  2920. newmemo += father.tid;
  2921. newmemo += ")";
  2922. newmemo += "-";
  2923. newmemo += acclist[4];
  2924. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2925. newmemo += ("-" + sName);
  2926. newmemo += ("-" + father.buyer_nick);
  2927. if (father.buyer_nick.IndexOf("*") < 0)
  2928. {
  2929. newmemo += ("-" + father.buyer_nick);
  2930. }
  2931. if (cusInfo != null)
  2932. {
  2933. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2934. }
  2935. if (isMulity)
  2936. {
  2937. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2938. }
  2939. if (acclist.Length > 7)
  2940. {
  2941. for (int i = 7; i < acclist.Length; i++)
  2942. {
  2943. newOtherMemo += acclist[i];
  2944. newOtherMemo += "-";
  2945. }
  2946. }
  2947. }
  2948. else
  2949. {
  2950. if (acclist.Length >= 7 && !isMulity)
  2951. {
  2952. newmemo += acclist[6];
  2953. newmemo += "-";
  2954. }
  2955. if (isMulity && acclist.Length >= 8)
  2956. {
  2957. newmemo += acclist[7];
  2958. newmemo += "-";
  2959. }
  2960. for (int i = 0; i < acclist.Length; i++)
  2961. {
  2962. if ((isMulity && i == 6) || i == 5)
  2963. {
  2964. continue;
  2965. }
  2966. if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
  2967. {
  2968. newOtherMemo += acclist[i];
  2969. newOtherMemo += "-";
  2970. }
  2971. else
  2972. {
  2973. if ((i == 6 && !isMulity) || (isMulity && i == 7))
  2974. {
  2975. continue;
  2976. }
  2977. else
  2978. newmemo += acclist[i];
  2979. if (i != 2 && i != 3)
  2980. {
  2981. newmemo += "-";
  2982. }
  2983. }
  2984. }
  2985. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2986. newmemo += (sName);
  2987. if (father.buyer_nick.IndexOf("*") < 0)
  2988. {
  2989. newmemo += ("-" + father.buyer_nick);
  2990. }
  2991. newmemo += ("-" + father.receiver_state);
  2992. if (cusInfo != null)
  2993. {
  2994. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2995. }
  2996. if (itemMemo.IndexOf("顺丰到付") != -1)
  2997. {
  2998. //if (newmemo.IndexOf("顺丰到付") == -1)
  2999. // newmemo += ("-顺丰到付");
  3000. entity.IsSF = 2;
  3001. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3002. }
  3003. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3004. {
  3005. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3006. // newmemo += ("-顺丰寄付");
  3007. entity.IsSF = 1;
  3008. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3009. }
  3010. if (itemMemo.IndexOf("加急") != -1)
  3011. {
  3012. //if (newmemo.IndexOf("加急") == -1)
  3013. // newmemo += ("-加急");
  3014. entity.IsUrgency = true;
  3015. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3016. }
  3017. }
  3018. if (isMulity)
  3019. {
  3020. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3021. }
  3022. newmemo = newmemo.Replace("\n", " ");
  3023. entity.seller_memo = newmemo;
  3024. entity.OtherMemo = newOtherMemo;
  3025. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3026. {
  3027. string odt = commonHelper.getDateFromString(newOtherMemo);
  3028. if (odt.Length > 0)
  3029. {
  3030. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3031. }
  3032. }
  3033. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3034. {
  3035. //到了设计那边,就更新memo,状态不设置
  3036. }
  3037. else
  3038. {
  3039. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  3040. {
  3041. entity.IsOldCustomer = 0;
  3042. }
  3043. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3044. if (oldRes > 0)
  3045. {
  3046. entity.IsOldCustomer = 1;
  3047. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3048. dealOldCustomerEntityAuto(ref entity);
  3049. }
  3050. }
  3051. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  3052. {
  3053. entity.OrderState = 6;
  3054. entity.FinishPlaceTime = DateTime.Now;
  3055. entity.SupplierId = 98;//-领鸿
  3056. }
  3057. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  3058. {
  3059. entity.OrderState = 6;
  3060. entity.FinishPlaceTime = DateTime.Now;
  3061. entity.SupplierId = 5;//-福广
  3062. }
  3063. if (ishave)
  3064. {
  3065. entity.Update();
  3066. }
  3067. else
  3068. {
  3069. father.create_time = DateTime.Now;
  3070. father.Update();
  3071. entity.Create();
  3072. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  3073. }
  3074. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  3075. CeErpSukuraData.createInfo(entity.ctid, 1);
  3076. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
  3077. }
  3078. public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
  3079. {
  3080. //UV跟指定店铺
  3081. int[] shopList = { 49, 67, 26, 45, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
  3082. if (entity.ProductId == 43 || shopList.Contains(entity.ShopId))
  3083. {
  3084. /**int curHour = DateTime.Now.Hour;
  3085. int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3086. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3087. {
  3088. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3089. entity.DesignUserId = initSysDesignerId;
  3090. entity.WaitDesignTime = DateTime.Now;
  3091. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3092. }
  3093. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3094. {
  3095. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3096. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3097. entity.DesignUserId = initSysDesignerId;
  3098. entity.WaitDesignTime = DateTime.Now;
  3099. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3100. }
  3101. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3102. {
  3103. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3104. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3105. entity.DesignUserId = initSysDesignerId;
  3106. entity.WaitDesignTime = DateTime.Now;
  3107. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3108. }
  3109. else
  3110. {**/
  3111. int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3112. if (designId != 0)
  3113. {
  3114. entity.DesignUserId = designId;
  3115. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3116. entity.WaitDesignTime = DateTime.Now;
  3117. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
  3118. }
  3119. }
  3120. }
  3121. public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
  3122. {
  3123. int curHour = DateTime.Now.Hour;
  3124. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3125. /**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3126. {
  3127. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3128. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3129. entity.DesignUserId = initSysDesignerId;
  3130. entity.WaitDesignTime = DateTime.Now;
  3131. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3132. }
  3133. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3134. {
  3135. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3136. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3137. entity.DesignUserId = initSysDesignerId;
  3138. entity.WaitDesignTime = DateTime.Now;
  3139. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3140. }
  3141. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3142. {
  3143. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3144. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3145. entity.DesignUserId = initSysDesignerId;
  3146. entity.WaitDesignTime = DateTime.Now;
  3147. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3148. }
  3149. else
  3150. {**/
  3151. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3152. //这个设计师有上班,有关联此店铺
  3153. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3154. {
  3155. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3156. entity.DesignUserId = initSysDesignerId;
  3157. entity.WaitDesignTime = DateTime.Now;
  3158. LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
  3159. }
  3160. //}
  3161. }
  3162. public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
  3163. {
  3164. if (itemMemo.Length <= 0) return;
  3165. string ctid = "";
  3166. string splitTag = "";
  3167. if (isMulity && itemMemo.Length > 2)
  3168. {
  3169. string preStr = "C" + orderIndex + "_";
  3170. ctid = preStr + father.tid;
  3171. splitTag = "C" + orderIndex;
  3172. }
  3173. else if (itemMemo.Length > 2)
  3174. {
  3175. ctid = father.tid;
  3176. }
  3177. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  3178. bool ishave = true;
  3179. if (entity == null)
  3180. {
  3181. entity = new CeErpTradeCell();
  3182. ishave = false;
  3183. }
  3184. entity.ctid = ctid;
  3185. entity.tid = father.tid;
  3186. entity.SplitTag = splitTag;
  3187. string[] acclist = itemMemo.Split('-');
  3188. if (entity.ShopId == 0)
  3189. {
  3190. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  3191. int shopId = 0;
  3192. if (nShop != null)
  3193. {
  3194. shopId = nShop.ID;
  3195. }
  3196. entity.ShopId = shopId;
  3197. }
  3198. if (entity.IsSample == 1 || entity.IsSample == 2)
  3199. {
  3200. entity.IsSample = 0;
  3201. }
  3202. if (entity.isDianziOrder == 1)
  3203. {
  3204. entity.isDianziOrder = 0;
  3205. }
  3206. if (acclist.Length < 6)
  3207. {
  3208. return;
  3209. }
  3210. string size = acclist[0];
  3211. string count = acclist[1];
  3212. bool isBuGanJiao = false;
  3213. string product = "";
  3214. string mt = "", ct = "";
  3215. string account = "";
  3216. itemMemo = itemMemo.Replace("PVC", "pvc");
  3217. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3218. {
  3219. isBuGanJiao = true;
  3220. product = acclist[3];
  3221. mt = acclist[2];
  3222. }
  3223. else
  3224. {
  3225. product = acclist[2];
  3226. mt = acclist[3];
  3227. }
  3228. account = acclist[5];
  3229. ct = acclist[4];
  3230. if (isMulity)
  3231. {
  3232. entity.payment = orderPrice;
  3233. if (acclist.Length >= 7)
  3234. {
  3235. acclist[6] = acclist[6].Replace("(", "");
  3236. acclist[6] = acclist[6].Replace(")", "");
  3237. acclist[6] = acclist[6].Replace("(", "");
  3238. acclist[6] = acclist[6].Replace(")", "");
  3239. entity.MakeSupplier = acclist[6];
  3240. acclist[6] = "(" + acclist[6] + ")";
  3241. }
  3242. }
  3243. entity.ProductId = getProductIdByName(product);
  3244. if (entity.ProductId == 0)
  3245. {
  3246. return;
  3247. }
  3248. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  3249. if (cusInfo != null)
  3250. {
  3251. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3252. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3253. {
  3254. }
  3255. else
  3256. {
  3257. entity.OrderState = 2;
  3258. if (entity.ShopId != 0)
  3259. {
  3260. entity.OrderState = orderAudit(entity.ShopId);
  3261. }
  3262. if (entity.DesignUserId > 0)
  3263. {
  3264. entity.OrderState = 3;
  3265. }
  3266. }
  3267. }
  3268. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  3269. {
  3270. entity.IsOldCustomer = 1;
  3271. if (itemMemo.IndexOf("改稿") != -1)
  3272. {
  3273. if (entity.payment > 0)
  3274. {
  3275. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  3276. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3277. {
  3278. }
  3279. else
  3280. {
  3281. int designId = Convert.ToInt32(webConfig.PlaceChangeId);
  3282. CeErpUser oldGaiPlace = CeErpUser.Get(designId);
  3283. if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
  3284. {
  3285. }
  3286. else
  3287. {
  3288. designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3289. }
  3290. if (designId != 0)
  3291. {
  3292. entity.DesignUserId = designId;
  3293. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3294. entity.WaitDesignTime = DateTime.Now;
  3295. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
  3296. }
  3297. }
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if (entity.payment != 0)
  3303. {
  3304. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  3305. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  3306. entity.WaitDesignTime = DateTime.Now;
  3307. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  3308. }
  3309. }
  3310. }
  3311. if (mt.IndexOf("铜板纸") != -1)
  3312. {
  3313. mt = mt.Replace("铜板纸", "铜版纸");
  3314. }
  3315. entity.Material = mt;
  3316. entity.ProductSize = size;
  3317. entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
  3318. entity.Craft = ct;
  3319. entity.pay_time = father.pay_time;
  3320. if (product == "现货手提袋")
  3321. {
  3322. entity.OrderState = 6;//下单完成
  3323. entity.FinishPlaceTime = DateTime.Now;
  3324. }
  3325. string newmemo = "(" + father.tid + ")-";
  3326. string newOtherMemo = "";
  3327. if (itemMemo.IndexOf("海报") != -1)
  3328. {
  3329. newmemo = acclist[2];
  3330. newmemo += acclist[0];
  3331. newmemo += "-";
  3332. newmemo += acclist[1];
  3333. newmemo += "(";
  3334. newmemo += father.tid;
  3335. newmemo += ")";
  3336. newmemo += "-";
  3337. newmemo += acclist[4];
  3338. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3339. newmemo += ("-" + sName);
  3340. if (father.buyer_nick.IndexOf("*") < 0)
  3341. {
  3342. newmemo += ("-" + father.buyer_nick);
  3343. }
  3344. newmemo += ("-" + father.receiver_state);
  3345. if (cusInfo != null)
  3346. {
  3347. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3348. }
  3349. if (isMulity)
  3350. {
  3351. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3352. }
  3353. if (acclist.Length > 7)
  3354. {
  3355. for (int i = 7; i < acclist.Length; i++)
  3356. {
  3357. newOtherMemo += acclist[i];
  3358. newOtherMemo += "-";
  3359. }
  3360. }
  3361. }
  3362. else
  3363. {
  3364. if (acclist.Length >= 7)
  3365. {
  3366. newmemo += acclist[6];
  3367. newmemo += "-";
  3368. }
  3369. for (int i = 0; i < acclist.Length; i++)
  3370. {
  3371. if (i == 5)
  3372. {
  3373. continue;
  3374. }
  3375. if (i >= 7)
  3376. {
  3377. newOtherMemo += acclist[i];
  3378. newOtherMemo += "-";
  3379. }
  3380. else
  3381. {
  3382. if (i == 6)
  3383. {
  3384. continue;
  3385. }
  3386. else
  3387. newmemo += acclist[i];
  3388. if (i != 2 && i != 3)
  3389. {
  3390. newmemo += "-";
  3391. }
  3392. }
  3393. }
  3394. string sName = getShopSNameByName(father.seller_nick);
  3395. newmemo += (sName);
  3396. if (father.buyer_nick.IndexOf("*") < 0)
  3397. {
  3398. newmemo += ("-" + father.buyer_nick);
  3399. }
  3400. newmemo += ("-" + father.receiver_state);
  3401. if (cusInfo != null)
  3402. {
  3403. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3404. }
  3405. if (itemMemo.IndexOf("顺丰到付") != -1)
  3406. {
  3407. entity.IsSF = 2;
  3408. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3409. }
  3410. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3411. {
  3412. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3413. // newmemo += ("-顺丰寄付");
  3414. entity.IsSF = 1;
  3415. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3416. }
  3417. if (itemMemo.IndexOf("加急") != -1)
  3418. {
  3419. //if (newmemo.IndexOf("加急") == -1)
  3420. // newmemo += ("-加急");
  3421. entity.IsUrgency = true;
  3422. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3423. }
  3424. }
  3425. if (isMulity)
  3426. {
  3427. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3428. }
  3429. newmemo = newmemo.Replace("\n", " ");
  3430. entity.seller_memo = newmemo;
  3431. entity.OtherMemo = newOtherMemo;
  3432. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3433. {
  3434. string odt = commonHelper.getDateFromString(newOtherMemo);
  3435. if (odt.Length > 0)
  3436. {
  3437. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3438. }
  3439. }
  3440. if (entity.IsOldCustomer == 0)
  3441. {
  3442. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3443. {
  3444. //到了设计那边,就更新memo,状态不设置
  3445. }
  3446. else
  3447. {
  3448. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3449. if (oldRes > 0)
  3450. {
  3451. entity.IsOldCustomer = 1;
  3452. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3453. int curHour = DateTime.Now.Hour;
  3454. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3455. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3456. {
  3457. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3458. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3459. entity.DesignUserId = initSysDesignerId;
  3460. entity.WaitDesignTime = DateTime.Now;
  3461. }
  3462. else
  3463. {
  3464. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3465. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3466. {
  3467. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3468. entity.DesignUserId = initSysDesignerId;
  3469. entity.WaitDesignTime = DateTime.Now;
  3470. }
  3471. }
  3472. }
  3473. }
  3474. }
  3475. if (ishave)
  3476. {
  3477. entity.Update();
  3478. }
  3479. else
  3480. {
  3481. entity.Create();
  3482. }
  3483. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
  3484. }
  3485. public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
  3486. {
  3487. DateTime nowTime = DateTime.Now;
  3488. if (nowTime.Hour >= 17)
  3489. {
  3490. return 0;
  3491. }
  3492. string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
  3493. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3494. foreach (DataRow dr in dt.Rows)
  3495. {
  3496. if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"]) != Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
  3497. {
  3498. int designId = Convert.ToInt32(dr["DesignUserId"]);
  3499. 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;
  3500. DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
  3501. if (dt_user.Rows.Count > 0)
  3502. {
  3503. return designId;
  3504. }
  3505. else
  3506. return 0;
  3507. }
  3508. }
  3509. return 0;
  3510. }
  3511. public static int getProductIdByName(string proName)
  3512. {
  3513. string dname = proName;
  3514. if (dname == "暧心贴")
  3515. {
  3516. dname = "暖心贴";
  3517. }
  3518. string sql = "select top 1 * from ce_erpproduct where uuid='" + dname + "';";
  3519. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3520. if (dt.Rows.Count > 0)
  3521. {
  3522. return Convert.ToInt32(dt.Rows[0]["ID"]);
  3523. }
  3524. return 0;
  3525. }
  3526. public static string getShopSNameByName(string seller_nick)
  3527. {
  3528. string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3529. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3530. if (dt.Rows.Count > 0)
  3531. {
  3532. return Convert.ToString(dt.Rows[0]["SName"]);
  3533. }
  3534. return "";
  3535. }
  3536. //public static string getShopRealName(string seller_nick)
  3537. //{
  3538. // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3539. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3540. // if (dt.Rows.Count > 0)
  3541. // {
  3542. // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
  3543. // return Convert.ToString(dt.Rows[0]["ShopName"]);
  3544. // }
  3545. // return seller_nick;
  3546. //}
  3547. public static DataRow getRelationOrder(string buyer, string sampTid)
  3548. {
  3549. string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer + "' and seller_memo not like '%补差价%' and tid<>'" + sampTid + "' order by id desc";
  3550. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3551. if (dt.Rows.Count > 0)
  3552. {
  3553. DataRow need = dt.Rows[0];
  3554. if (dt.Rows.Count == 1)
  3555. {
  3556. return need;
  3557. }
  3558. int idx = 0;
  3559. foreach (DataRow dr in dt.Rows)
  3560. {
  3561. if (idx != 0)
  3562. {
  3563. int day = Convert.ToDateTime(need["pay_time"]).Day;
  3564. int nday = Convert.ToDateTime(dr["pay_time"]).Day;
  3565. if (day == nday)
  3566. {
  3567. need = dr;
  3568. }
  3569. }
  3570. idx++;
  3571. }
  3572. return need;
  3573. }
  3574. return null;
  3575. }
  3576. public static DataRow getUserInfoByAccount(string account)
  3577. {
  3578. string sql = "select * from view_erpuser where isOpen=1 and Account='" + account + "'";
  3579. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3580. if (dt != null && dt.Rows.Count > 0)
  3581. {
  3582. return dt.Rows[0];
  3583. }
  3584. return null;
  3585. }
  3586. public static string getShopNameByECode(string code)
  3587. {
  3588. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  3589. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3590. if (dt != null && dt.Rows.Count > 0)
  3591. {
  3592. return dt.Rows[0]["ShopName"].ToString();
  3593. }
  3594. return "";
  3595. }
  3596. // 时间戳转为C#格式时间
  3597. public static DateTime StampToDateTime(string timeStamp)
  3598. {
  3599. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  3600. long lTime = long.Parse(timeStamp + "0000");
  3601. TimeSpan toNow = new TimeSpan(lTime);
  3602. return dateTimeStart.Add(toNow);
  3603. }
  3604. public static void Api_Tmc_CreateNewOrder(string res)
  3605. {
  3606. Api_trade_fullinfo_get_response_Obj fullObj = null;
  3607. if (res == "") return;
  3608. try
  3609. {
  3610. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  3611. //res = res.Replace(" ", "");
  3612. fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
  3613. }
  3614. catch (Exception ex)
  3615. {
  3616. XLog.SaveLog(0, ex.Message);
  3617. }
  3618. if (fullObj == null)
  3619. {
  3620. Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
  3621. return;
  3622. }
  3623. ContentItem tObj = null;
  3624. if (fullObj.response.data.content.Count > 0)
  3625. {
  3626. tObj = fullObj.response.data.content[0];
  3627. }
  3628. if (tObj == null)
  3629. {
  3630. return;
  3631. }
  3632. //未付款,未成功的单不需要
  3633. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  3634. {
  3635. return;
  3636. }
  3637. List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
  3638. StringBuilder sql = new StringBuilder();
  3639. CeErpTrade trade = CeErpTrade.Get(tObj.refOid);
  3640. bool isCreate = false;
  3641. if (trade == null)
  3642. {
  3643. trade = new CeErpTrade();
  3644. isCreate = true;
  3645. }
  3646. //原始单创建
  3647. trade.tid = tObj.refOid;
  3648. if (tObj.posCode != null)
  3649. trade.posCode = tObj.posCode;
  3650. //trade.num = tObj.num;
  3651. trade.status = tObj.status;
  3652. trade.seller_flag = tObj.flag;
  3653. trade.type = tObj.refType;
  3654. trade.price = Convert.ToDouble(tObj.totalPrice);
  3655. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  3656. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  3657. trade.created = StampToDateTime(tObj.orderTime);
  3658. if (tObj.payTime != null)
  3659. {
  3660. trade.pay_time = StampToDateTime(tObj.payTime);
  3661. }
  3662. if (tObj.modifyTime != null)
  3663. {
  3664. trade.modified = StampToDateTime(tObj.modifyTime);
  3665. }
  3666. if (tObj.finishTime != null)
  3667. {
  3668. trade.end_time = StampToDateTime(tObj.finishTime);
  3669. }
  3670. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  3671. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  3672. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  3673. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  3674. if (trade.seller_nick == "")
  3675. {
  3676. trade.seller_nick = getShopNameByECode(trade.posCode);
  3677. }
  3678. trade.payment = Convert.ToDouble(tObj.payment);
  3679. //trade.receiver_name = tObj.receiver_name;
  3680. trade.receiver_state = tObj.receiverState;
  3681. trade.receiver_city = tObj.receiverCity;
  3682. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  3683. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  3684. //trade.receiver_address = tObj.receiver_address;
  3685. //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  3686. //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  3687. //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  3688. //{
  3689. // trade.consign_time = tObj.consign_time;
  3690. //}
  3691. if (tObj.shippingTime != null)
  3692. {
  3693. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  3694. }
  3695. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  3696. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  3697. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  3698. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  3699. {
  3700. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  3701. {
  3702. string[] acclist = tObj.sellerMemo.Split('-');
  3703. List<string> list = new List<string>(acclist);
  3704. string buyer_nick = "";
  3705. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  3706. {
  3707. if (list.Count > 3)
  3708. {
  3709. buyer_nick = list[3];
  3710. }
  3711. }
  3712. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  3713. {
  3714. if (list.Count > 1)
  3715. {
  3716. buyer_nick = list[1];
  3717. }
  3718. }
  3719. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  3720. {
  3721. if (list.Count > 1)
  3722. {
  3723. buyer_nick = list[1];
  3724. }
  3725. }
  3726. else if (trade.seller_memo.IndexOf("寄样") != -1)
  3727. {
  3728. if (list.Count > 3)
  3729. {
  3730. buyer_nick = list[3];
  3731. }
  3732. }
  3733. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  3734. {
  3735. if (list.Count > 1)
  3736. {
  3737. buyer_nick = list[1];
  3738. }
  3739. }
  3740. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  3741. {
  3742. if (list.Count > 1)
  3743. {
  3744. buyer_nick = list[1];
  3745. }
  3746. }
  3747. else
  3748. {
  3749. if (list.Count > 5)
  3750. {
  3751. buyer_nick = list[5];
  3752. }
  3753. }
  3754. tObj.sellerMemo = string.Join("-", list);
  3755. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  3756. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  3757. }
  3758. }
  3759. if (isCreate)
  3760. {
  3761. trade.Create();
  3762. }
  3763. else
  3764. {
  3765. trade.Update();
  3766. }
  3767. bool isXianhuo = false;
  3768. string xianhuoMemo = "(" + trade.tid + ")现货-";
  3769. //order表创建
  3770. foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
  3771. {
  3772. bool orderCreate = false;
  3773. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  3774. if (order == null)
  3775. {
  3776. order = new CeErpTradeOrder();
  3777. orderCreate = true;
  3778. }
  3779. order.tid = trade.tid;
  3780. order.oid = item.refOlId;
  3781. order.buyer_nick = trade.buyer_nick;
  3782. order.refund_status = item.refundStatus;
  3783. order.status = trade.status;
  3784. order.title = item.title;
  3785. order.price = Convert.ToDouble(item.price);
  3786. if (item.picUrl != null)
  3787. order.pic_path = item.picUrl;
  3788. order.num = Convert.ToDouble(item.num.ToString());
  3789. order.payment = Convert.ToDouble(item.price);
  3790. //order.adjust_fee = Convert.ToDouble(item.price);
  3791. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  3792. {
  3793. order.sku_properties_name = item.standards;
  3794. order.sku_id = item.refSkuId;
  3795. isXianhuo = true;
  3796. xianhuoMemo += order.sku_properties_name;
  3797. xianhuoMemo += ("-数量:" + order.num + "; ");
  3798. }
  3799. if (orderCreate)
  3800. {
  3801. order.Create();
  3802. }
  3803. else
  3804. {
  3805. order.Update();
  3806. }
  3807. }
  3808. //if (isXianhuo)
  3809. //{
  3810. // xianhuoMemo += "-";
  3811. // xianhuoMemo += trade.seller_nick;
  3812. //}
  3813. //cell表创建
  3814. CeErpTradeCell entity = null;
  3815. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  3816. if (entity == null)
  3817. {
  3818. try
  3819. {
  3820. entity = new CeErpTradeCell();
  3821. entity.ctid = tObj.refOid;
  3822. entity.tid = tObj.refOid;
  3823. entity.payment = Convert.ToDouble(tObj.payment);
  3824. if (tObj.payTime != null)
  3825. {
  3826. entity.pay_time = StampToDateTime(tObj.payTime);
  3827. }
  3828. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  3829. int shopId = 0;
  3830. if (nShop != null)
  3831. {
  3832. shopId = nShop.ID;
  3833. }
  3834. entity.ShopId = shopId;
  3835. if (isXianhuo)
  3836. {
  3837. entity.OrderState = 6;//现货直接下单完成
  3838. entity.seller_memo = xianhuoMemo;
  3839. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  3840. entity.IsXianHuo = 1;
  3841. entity.FinishPlaceTime = entity.pay_time;
  3842. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  3843. {
  3844. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  3845. if (trade.buyer_memo != "")
  3846. {
  3847. entity.OrderState = 2; //买家有备注的要设计
  3848. entity.ProductId = 1;
  3849. entity.IsXianHuo = 0;
  3850. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  3851. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  3852. entity.seller_memo = xianhuoMemo;
  3853. }
  3854. }
  3855. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  3856. {
  3857. entity.SupplierId = 70; //智涛
  3858. }
  3859. //if (trade != null)
  3860. //{
  3861. // trade.seller_memo = xianhuoMemo;
  3862. // trade.Update();
  3863. //}
  3864. }
  3865. entity.Create();
  3866. }
  3867. catch (Exception ex)
  3868. {
  3869. XLog.SaveLog(0, ex.Message);
  3870. }
  3871. }
  3872. if (tObj.sellerMemo.Length > 0)
  3873. {
  3874. try
  3875. {
  3876. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  3877. }
  3878. catch (Exception ex)
  3879. {
  3880. XLog.SaveLog(0, res + "|" + ex.Message);
  3881. }
  3882. }
  3883. ////生成档案客户信息
  3884. //insertCustomerInfo(tObj);
  3885. }
  3886. public static int isOldCustomerOrder(CeErpTrade father)
  3887. {
  3888. if (father.seller_nick == "") return 0;
  3889. CeErpCustomer cusone = null;
  3890. cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  3891. if (cusone != null)
  3892. {
  3893. return 1;
  3894. }
  3895. return 0;
  3896. }
  3897. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  3898. {
  3899. if (father.seller_nick == "") return 0;
  3900. CeErpCustomer cus = null;
  3901. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  3902. if (cus == null)
  3903. {
  3904. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  3905. }
  3906. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  3907. //CeErpCustomer cusone = null;
  3908. //cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  3909. if (cus != null)
  3910. {
  3911. if (cus.lastbuy_time.ToString() == "") return 0;
  3912. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  3913. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  3914. //cus.phone = Obj.receiver_mobile;
  3915. cus.buyer_id = father.buyer_id;
  3916. int returnNum = 0;
  3917. int lastpCount = cus.product_count;
  3918. if (cus.lastTid == father.tid)
  3919. {
  3920. if (pcount != cus.product_count)
  3921. {
  3922. cus.product_count = pcount;
  3923. cus.Update();
  3924. }
  3925. }
  3926. else
  3927. {
  3928. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  3929. cus.buyer_nick = father.buyer_nick;
  3930. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  3931. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  3932. cus.buy_count = cus.buy_count + 1;
  3933. cus.lastbuy_time2 = cus.lastbuy_time;
  3934. cus.lastbuy_time = father.pay_time;
  3935. cus.product_count = pcount;
  3936. cus.lastTid2 = cus.lastTid;
  3937. cus.lastTid = father.tid;
  3938. cus.Update();
  3939. }
  3940. if (cus.buy_day > 1)
  3941. {
  3942. if (pcount > lastpCount && cus.product_count != 0)
  3943. {
  3944. cus.isMore = 1;
  3945. returnNum = 2;
  3946. }
  3947. else
  3948. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  3949. }
  3950. else
  3951. {
  3952. returnNum = 0;
  3953. }
  3954. return returnNum;
  3955. }
  3956. //else if (cusone != null)
  3957. //{
  3958. // cusone.seller_nick = father.seller_nick;
  3959. // TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
  3960. // cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
  3961. // cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
  3962. // cusone.buy_count = cusone.buy_count + 1;
  3963. // cusone.lastbuy_time2 = cusone.lastbuy_time;
  3964. // cusone.lastbuy_time = father.pay_time;
  3965. // cusone.product_count = pcount;
  3966. // cusone.lastTid2 = cusone.lastTid;
  3967. // cusone.lastTid = father.tid;
  3968. // cusone.Update();
  3969. // return 1;
  3970. //}
  3971. else
  3972. {
  3973. try
  3974. {
  3975. cus = new CeErpCustomer();
  3976. cus.buyer_nick = father.buyer_nick;
  3977. cus.seller_nick = father.seller_nick;
  3978. cus.buyer_id = father.buyer_id;
  3979. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  3980. //cus.phone = Obj.receiver_mobile;
  3981. cus.buy_day = 0;
  3982. cus.buy_count = 1;
  3983. cus.lastbuy_time = father.pay_time;
  3984. cus.lastTid = father.tid;
  3985. cus.total_fee = Convert.ToDouble(father.payment);
  3986. cus.product_count = pcount;
  3987. cus.Create();
  3988. //StringBuilder sql = new StringBuilder();
  3989. //sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
  3990. //DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  3991. //if (dt.Rows.Count > 0)
  3992. //{
  3993. // return true;
  3994. //}
  3995. return 0;
  3996. }
  3997. catch (Exception ex)
  3998. {
  3999. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  4000. }
  4001. }
  4002. return 0;
  4003. }
  4004. public static void removeOldCustomerInfo(CeErpTrade trade)
  4005. {
  4006. CeErpCustomer cus = null;
  4007. cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
  4008. if (cus != null)
  4009. {
  4010. if (cus.lastTid == trade.tid)
  4011. {
  4012. if (cus.buy_count > 1)
  4013. {
  4014. cus.lastTid = cus.lastTid2;
  4015. cus.lastbuy_time = cus.lastbuy_time2;
  4016. cus.buy_count = cus.buy_count - 1;
  4017. cus.Update();
  4018. }
  4019. else
  4020. {
  4021. CeErpCustomer.Del(cus.ID);
  4022. }
  4023. }
  4024. }
  4025. }
  4026. //接收到--新订单生成消息
  4027. public static void API_Tmc_TradeBuyerPay(string content)
  4028. {
  4029. Api_tmc_trade_info_Obj fullObj = null;
  4030. if (content == "") return;
  4031. try
  4032. {
  4033. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4034. //res = res.Replace(" ", "");
  4035. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4036. }
  4037. catch (Exception ex)
  4038. {
  4039. }
  4040. if (fullObj == null)
  4041. {
  4042. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4043. return;
  4044. }
  4045. Content tObj = fullObj.content;
  4046. string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
  4047. Api_Tmc_CreateNewOrder(res);
  4048. }
  4049. //推送接收到卖家备注修改
  4050. public static void API_Tmc_TradeMemoModified(string content)
  4051. {
  4052. Api_tmc_trade_info_Obj fullObj = null;
  4053. if (content == "") return;
  4054. try
  4055. {
  4056. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4057. //res = res.Replace(" ", "");
  4058. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4059. }
  4060. catch (Exception ex)
  4061. {
  4062. }
  4063. if (fullObj == null)
  4064. {
  4065. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4066. return;
  4067. }
  4068. Content tObj = fullObj.content;
  4069. //原始表--没有这个单,不能拆分
  4070. CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
  4071. if (mainEn == null) return;
  4072. createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
  4073. }
  4074. public static int orderAudit(int shopId)
  4075. {
  4076. try
  4077. {
  4078. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  4079. if (ceErpShop == null) return 2;
  4080. if (!ceErpShop.orderAudit) return 2;
  4081. return -1;
  4082. }
  4083. catch (Exception ex)
  4084. {
  4085. return 2;
  4086. }
  4087. }
  4088. public static void autoCell(string tid)
  4089. {
  4090. if (tid.Length == 0)
  4091. {
  4092. return;
  4093. }
  4094. DateTime nowTime = DateTime.Now;
  4095. if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
  4096. {
  4097. return;
  4098. }
  4099. try
  4100. {
  4101. 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);
  4102. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4103. if (dt != null && dt.Rows.Count > 0)
  4104. {
  4105. bool changeBl = false;
  4106. //int c = Convert.ToInt32(result);// / 20 + 1;
  4107. foreach (DataRow dr in dt.Rows)
  4108. {
  4109. if (nowTime.Hour > 12 && nowTime.Hour < 17)
  4110. {
  4111. //这段时间白班晚班平均分配
  4112. if (changeBl)
  4113. {
  4114. changeBl = false;
  4115. }
  4116. else
  4117. {
  4118. changeBl = true;
  4119. }
  4120. }
  4121. else
  4122. changeBl = false;
  4123. string IsOldCustomer = dr["IsOldCustomer"].ToString();
  4124. string res = "";
  4125. CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
  4126. int userId = 0;
  4127. if (ceErpShop != null)
  4128. {
  4129. userId = ceErpShop.UserID;
  4130. }
  4131. SqlParameter[] sqlParameter = {
  4132. new SqlParameter("@inctid", SqlDbType.VarChar,200),
  4133. new SqlParameter("@intype", SqlDbType.Int,5),
  4134. new SqlParameter("@res", SqlDbType.VarChar, 50) };
  4135. sqlParameter[0].Value = dr["ctid"].ToString();
  4136. sqlParameter[1].Value = changeBl ? 1 : 0;
  4137. sqlParameter[2].Direction = ParameterDirection.Output;
  4138. if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
  4139. {
  4140. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
  4141. }
  4142. else
  4143. {
  4144. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
  4145. }
  4146. res = sqlParameter[2].Value.ToString();
  4147. }
  4148. }
  4149. }
  4150. catch (Exception ex)
  4151. {
  4152. XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
  4153. }
  4154. }
  4155. }
  4156. }