commonHelper.cs 190 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using SiteCore.taoObj;
  4. using SQLData;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.IO;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using Match = System.Text.RegularExpressions.Match;
  13. using SiteCore.Handler;
  14. using System.Threading;
  15. using Newtonsoft.Json.Linq;
  16. using System.Net.Security;
  17. using System.Net;
  18. using System.Security.Cryptography.X509Certificates;
  19. using System.Security.Policy;
  20. using NHibernate.Engine;
  21. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  22. using NHibernate.Loader.Custom;
  23. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  24. using NPOI.OpenXmlFormats.Shared;
  25. using static SiteCore.taoObj.work_core_vo;
  26. using System.Linq;
  27. using System.Security.Cryptography;
  28. using System.Net.Http.Headers;
  29. using System.Net.Http;
  30. using NHibernate.Linq;
  31. using NPOI.SS.Formula.Functions;
  32. namespace SiteCore
  33. {
  34. public class commonHelper
  35. {
  36. //配件单
  37. public static Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  38. {
  39. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  40. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  41. {"别针",new List<string>(){ "卡片", "吊牌" } },
  42. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  43. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  44. {"旗杆",new List<string>(){ "班旗" } },
  45. {"牙签",new List<string>(){ "不干胶" } }
  46. };
  47. //其他改名
  48. public static Dictionary<int, string> suppliers = new Dictionary<int, string>()
  49. {
  50. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  51. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  52. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  53. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  54. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  55. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  56. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  57. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" },{ 129,"种子纸"},{ 125,"胶带"},{ 127,"PET透卡"}
  58. };
  59. public static Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  60. {
  61. //chy----19
  62. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  63. //GD-CYT-----64
  64. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  65. //ZHX----3
  66. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  67. //JK----97
  68. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  69. //ZT----70
  70. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  71. //GD-CYTUV---126
  72. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  73. //LHCY-----98
  74. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  75. //XD-----90
  76. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  77. //CYCY-----14
  78. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}},
  79. //THLZY----122
  80. {122, new Dictionary<string, string> {{ "烫画", "烫画" }, { "冷转印", "冷转印" }}},
  81. //DTY----138
  82. {138, new Dictionary<string, string> {{ "烫画", "烫画" }}},
  83. };
  84. public static bool placeDataIsPeijian(string seller_memo)
  85. {
  86. bool ispj = false;//是否配件单
  87. bool isfirst = true;//第一个配
  88. maps.Keys.ForEach(key =>
  89. {
  90. //备注包含配件
  91. if (seller_memo.Contains(key) && isfirst)
  92. {
  93. List<string> list = maps[key];
  94. ispj = true;
  95. isfirst = false;
  96. for (int i = 0; i < list.Count; i++)
  97. {
  98. if (seller_memo.Contains(list[i]))
  99. {
  100. ispj = false;
  101. break;
  102. }
  103. }
  104. }
  105. });
  106. return ispj;
  107. }
  108. public static string placeDataGetMapKey(string seller_memo, int supplierId)
  109. {
  110. string map_key = "";
  111. List<int> smSupplier = new List<int>() { 97, 121, 119, 80 };
  112. if (supplierMap.ContainsKey(supplierId))
  113. {
  114. foreach (var kvp in supplierMap[supplierId])
  115. {
  116. if (seller_memo.Contains(kvp.Key))
  117. {
  118. map_key = kvp.Value;
  119. break;
  120. }
  121. }
  122. }
  123. if (map_key == "")
  124. {
  125. if (smSupplier.Contains(supplierId))
  126. {
  127. map_key = "数码";
  128. }
  129. }
  130. return map_key;
  131. }
  132. public static bool placeDataIsToday(DataRow row, string type)
  133. {
  134. bool istoday = false;
  135. int supplierId = Convert.ToInt32(row["SupplierId"]);
  136. string seller_memo = row["seller_memo"].ToString();
  137. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  138. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  139. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  140. //GD-CYT-----64
  141. DateTime two = palceTimeStart.AddHours(14);
  142. DateTime three = palceTimeStart.AddHours(15);
  143. DateTime four = palceTimeStart.AddHours(16);
  144. DateTime five = palceTimeStart.AddHours(17);
  145. DateTime six = palceTimeStart.AddHours(18);
  146. string patterns = "牙签|烫金|电线胶|PVC不干胶覆哑膜|内部模切|牛皮纸不干胶";
  147. string patterns_FSMC = " 雅柔|珠光|白卡|皙贝|溪雪|萱姿";
  148. if (supplierId == 64 && "不干胶".Equals(type) && !Regex.IsMatch(seller_memo, patterns))
  149. {
  150. //下午四点前 500-1000
  151. string count = row["ProductCount"].ToString();
  152. if (count != null && count.Length > 0)
  153. {
  154. int productCount = commonHelper.getPlaceProductCount(count);
  155. if (productCount >= 500 && productCount <= 1000)
  156. {
  157. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  158. {
  159. istoday = true;
  160. }
  161. }
  162. }
  163. }
  164. //UV
  165. else if ("uv".Equals(type))
  166. {
  167. //ZT----70
  168. //ZHX----3
  169. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  170. {
  171. istoday = true;
  172. }
  173. //JK----97
  174. //HZX----105
  175. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  176. {
  177. istoday = true;
  178. }
  179. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  180. {
  181. istoday = true;
  182. }
  183. }
  184. //帆布---52|条幅---27
  185. else if ("帆布".Equals(type) || "条幅".Equals(type))
  186. {
  187. //LHCY-----98
  188. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  189. {
  190. istoday = true;
  191. }
  192. }
  193. //条幅
  194. else if ("条幅".Equals(type))
  195. {
  196. //XD-----90
  197. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  198. {
  199. istoday = true;
  200. }
  201. }
  202. //桌布
  203. else if ("桌布".Equals(type))
  204. {
  205. //XD-----90
  206. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  207. {
  208. istoday = true;
  209. }
  210. }
  211. //DL---10
  212. //AYTW---119
  213. //FS-CYT-DY ----80
  214. //JK----97
  215. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  216. {
  217. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  218. {
  219. istoday = true;
  220. }
  221. }
  222. // QC---121
  223. else if (supplierId == 121)
  224. {
  225. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  226. {
  227. istoday = true;
  228. }
  229. }
  230. else if (supplierId == 138 && "烫画".Equals(type))
  231. {
  232. if (DateTime.Compare(FinishPlaceTime, two) < 0)
  233. {
  234. istoday = true;
  235. }
  236. }
  237. else if (Regex.IsMatch(seller_memo, patterns_FSMC) && seller_memo.Contains("裁切"))
  238. {
  239. if (DateTime.Compare(FinishPlaceTime, five) < 0 && !seller_memo.Contains("顺丰"))
  240. {
  241. istoday = true;
  242. }
  243. if (DateTime.Compare(FinishPlaceTime, four) < 0 && seller_memo.Contains("顺丰"))
  244. {
  245. istoday = true;
  246. }
  247. }
  248. return istoday;
  249. }
  250. public static void autoRefreshRefundState()
  251. {
  252. StringBuilder sql = new StringBuilder();
  253. sql.AppendFormat("update CE_ErpTradeRefund set RefundState=3 where RefundState=2 and DATEDIFF(hh,modified,getdate())>=72;");
  254. //sql.AppendFormat("update ce_erptradecell with(rowlock) set AfterSaleState=4,FinishAfterSaleTime=getdate() where AfterSaleState=3 and IsArbitrate=0 and DATEDIFF(hh,AfterSalePreTime,getdate())>=168;");
  255. //sql.AppendFormat("update ce_erptradecell with(rowlock) set AfterSaleSupplierState=1,set FinishAfterSaleTime=GETDATE(),set AfterSaleState=4 where AfterSaleSupplierState=0 and AfterSaleState>1 and AfterSaleResSupId>0 and DATEDIFF(hh,HandleTime,getdate())>=72;");
  256. //sql.AppendFormat("update CE_ErpTradeResponsible set VerifyState=1 where VerifyState=0 and IsArbitrate=0 and DATEDIFF(hh,createdTime,getdate())>=168;");
  257. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  258. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  259. sql = new StringBuilder();
  260. sql.AppendFormat("SELECT r.ID, r.tid, r.VerifyState, r.UserId, r.VerifyTime, type FROM CE_ErpTradeResponsible r LEFT JOIN CE_ErpTradeCell t ON r.tid= t.ctid WHERE VerifyState > -1 AND VerifyState != 1 AND t.AfterSaleState = 3 AND DATEDIFF( hh, VerifyTime, getdate( ) ) >= 72;");
  261. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  262. foreach (DataRow dr in dt.Rows)
  263. {
  264. string state = dr["VerifyState"].ToString();
  265. string tid = dr["tid"].ToString();
  266. int userId = Convert.ToInt32(dr["UserId"]);
  267. int reasonId = Convert.ToInt32(dr["ID"]);
  268. int type = Convert.ToInt32(dr["type"]);
  269. if (type == 0)
  270. {
  271. if (state == "0")//主管审核超时
  272. {
  273. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  274. if (ceErpTradeResponsible != null)
  275. {
  276. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  277. ceErpTradeResponsible.VerifyState = 3;
  278. ceErpTradeResponsible.Update();
  279. LogHelper.AddAfterSaleLog(tid, reasonId, "主管审核超时", userId);
  280. LogHelper.addLog(tid, 0, "主管审核超时", 4, 4);
  281. }
  282. }
  283. if (state == "3")//责任人审核超时
  284. {
  285. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  286. if (ceErpTradeResponsible != null)
  287. {
  288. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  289. ceErpTradeResponsible.VerifyState = 1;
  290. ceErpTradeResponsible.Update();
  291. LogHelper.AddAfterSaleLog(tid, reasonId, "责任人审核超时", userId);
  292. LogHelper.addLog(tid, 0, "责任人审核超时", 4, 4);
  293. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  294. bool isAll = tradeResponsibleAll(entity);
  295. if (isAll)
  296. {
  297. entity.AfterSaleState = 4;
  298. entity.FinishAfterSaleTime = DateTime.Now;
  299. entity.UpdateTime = DateTime.Now;
  300. entity.AfterSaleSupplierState = 1;
  301. ApiVo apiVo = new ApiVo();
  302. apiVo.orderNumber = entity.ctid;
  303. apiVo.actionName = "afterOver";
  304. designHelper.API_WorkCore(apiVo); //afterOver
  305. entity.Update();
  306. }
  307. }
  308. }
  309. }
  310. else
  311. {
  312. DateTime date = DateTime.Parse(dr["VerifyTime"].ToString());
  313. if (type == 2)
  314. {
  315. if (DateTime.Compare(DateTime.Now, date.AddHours(96)) <= 0)
  316. {
  317. continue;
  318. }
  319. }
  320. //车间自动审核
  321. if (state == "0")
  322. {
  323. //节假日120小时
  324. /*if (DateTime.Compare(DateTime.Now, date.AddHours(120)) <= 0)
  325. {
  326. continue;
  327. }*/
  328. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  329. if (ceErpTradeResponsible != null)
  330. {
  331. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  332. ceErpTradeResponsible.VerifyState = 1;
  333. ceErpTradeResponsible.Update();
  334. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  335. bool isAll = tradeResponsibleAll(entity);
  336. if (isAll)
  337. {
  338. entity.AfterSaleState = 4;
  339. entity.FinishAfterSaleTime = DateTime.Now;
  340. entity.UpdateTime = DateTime.Now;
  341. entity.AfterSaleSupplierState = 1;
  342. entity.Update();
  343. ApiVo apiVo = new ApiVo();
  344. apiVo.orderNumber = entity.ctid;
  345. apiVo.actionName = "afterOver";
  346. designHelper.API_WorkCore(apiVo); //afterOver
  347. }
  348. CeErpSukuraData.createInfo(entity.ctid, 8);
  349. LogHelper.addLog(tid, 0, "审核超时,自动完成售后", 4, 4);
  350. }
  351. }
  352. }
  353. }
  354. }
  355. public static void tradeSaleState(CeErpTradeCell ceErpTradeCell)
  356. {
  357. string sql = "select * from ce_erptraderesponsible where tid='" + ceErpTradeCell.ctid + "' and VerifyState != -1";
  358. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  359. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ceErpTradeCell.ctid);
  360. if (ceErpTradeAfterSaleExtend == null)
  361. {
  362. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  363. ceErpTradeAfterSaleExtend.tid = ceErpTradeCell.ctid;
  364. ceErpTradeAfterSaleExtend.Create();
  365. }
  366. List<string> list = new List<string>();
  367. foreach (DataRow row in dt.Rows)
  368. {
  369. list.Add(row["VerifyState"].ToString());
  370. }
  371. ceErpTradeAfterSaleExtend.VerifyStates = String.Join(",", list);
  372. ceErpTradeAfterSaleExtend.Update();
  373. }
  374. public static bool tradeResponsibleAll(CeErpTradeCell ceErpTradeCell)
  375. {
  376. //判断是否全部处理完成
  377. string sql = "select * from ce_erptraderesponsible where tid='" + ceErpTradeCell.ctid + "' and VerifyState != -1";
  378. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  379. bool isAll = true;
  380. if (dt.Rows.Count > 0 && dt.Rows.Count == 1)
  381. {
  382. }
  383. else if (dt.Rows.Count > 1)
  384. {
  385. foreach (DataRow row in dt.Rows)
  386. {
  387. if (row["VerifyState"].ToString() != "1")
  388. {
  389. isAll = false;
  390. break;
  391. }
  392. }
  393. }
  394. return isAll;
  395. }
  396. public static string getSupplierNameById(int sid)
  397. {
  398. CeErpSupplier sup = CeErpSupplier.Get(sid);
  399. if (sup != null)
  400. {
  401. return sup.ComName;
  402. }
  403. else
  404. {
  405. return "";
  406. }
  407. }
  408. public static void aftersaleSend(string ctid, string cpCode, string curUseWayBillCode)
  409. {
  410. if (ctid.IndexOf("S_") > -1)
  411. {
  412. try
  413. {
  414. string tradeCtid = ctid.Remove(0, 2);
  415. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(tradeCtid);
  416. if (ceErpTradeAfterSaleExtend == null)
  417. {
  418. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  419. ceErpTradeAfterSaleExtend.tid = tradeCtid;
  420. ceErpTradeAfterSaleExtend.ExpressNo = cpCode + "-" + curUseWayBillCode;
  421. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  422. ceErpTradeAfterSaleExtend.Create();
  423. }
  424. else
  425. {
  426. ceErpTradeAfterSaleExtend.ExpressNo = cpCode + "-" + curUseWayBillCode;
  427. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  428. ceErpTradeAfterSaleExtend.Update();
  429. }
  430. }
  431. catch (Exception ex)
  432. {
  433. }
  434. }
  435. }
  436. public static string getUserNameById(int sid)
  437. {
  438. CeErpUser sup = CeErpUser.Get(sid);
  439. if (sup != null)
  440. {
  441. return sup.Name;
  442. }
  443. else
  444. {
  445. return "";
  446. }
  447. }
  448. public static int getSupplierIDByName(string name)
  449. {
  450. StringBuilder sql2 = new StringBuilder();
  451. sql2.AppendFormat("select top 1 * from CE_ErpSupplier where ComName='{0}';", name);
  452. DataTable dt2 = DbHelper.DbConn.ExecuteDataset(sql2.ToString()).Tables[0];
  453. if (dt2.Rows.Count > 0)
  454. {
  455. return Convert.ToInt32(dt2.Rows[0]["ID"]);
  456. }
  457. return 0;
  458. }
  459. public static int autoDistributeToSupplier(CeErpTradeCell trade)
  460. {
  461. if (trade.seller_memo.IndexOf("电子稿") != -1) return 0;
  462. int count = 0;
  463. string sc = trade.ProductCount;
  464. count = handleProductCount(sc, true);
  465. //string needSc = System.Text.RegularExpressions.Regex.Replace(sc, @"[^0-9]+", "");
  466. //if (!int.TryParse(needSc, out count))
  467. //{
  468. // XLog.SaveLog(0, "autoDistributeToSupplier:获取数量[" + trade.ProductCount + "]转换出错");
  469. //}
  470. //老客户指派之前供应商
  471. if (trade.IsOldCustomer == 1 && (trade.seller_memo.IndexOf("改稿") != -1 || trade.OtherMemo.IndexOf("老客户") != -1))
  472. {
  473. CeErpTrade ceErpTrade = CeErpTrade.Get(trade.tid);
  474. if (ceErpTrade != null)
  475. {
  476. //用昵称找之前的订单
  477. string name = ceErpTrade.buyer_nick;
  478. if (!string.IsNullOrEmpty(name))
  479. {
  480. StringBuilder CeErpTradeSql = new StringBuilder();
  481. CeErpTradeSql.AppendFormat("select top 1 * from ce_erptrade o left join CE_ErpTradeCell c on c.tid=o.tid where o.buyer_nick='{0}' and o.tid <> '{1}' and c.SupplierId <> 35 AND c.SupplierId <> 33 and c.SupplierId > 0 order by created desc;", name, trade.tid);
  482. DataSet data = DbHelper.DbConn.ExecuteDataset(CeErpTradeSql.ToString());
  483. DataTable datatable = data.Tables[0];
  484. if (datatable.Rows.Count > 0)
  485. {
  486. CeErpTradeCell oldOrder = CeErpTradeCell.GetByTid(datatable.Rows[0]["tid"].ToString());
  487. if (oldOrder != null)
  488. {
  489. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(oldOrder.SupplierId);
  490. if (ceErpSupplier != null && ceErpSupplier.IsClose == 0)
  491. {
  492. return oldOrder.SupplierId;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. if (trade.Craft.IndexOf("门挂卡") != -1)
  500. {
  501. return 7;// ljl
  502. }
  503. else if (trade.Craft.IndexOf("打印") != -1 || trade.Craft.IndexOf("专版") != -1)
  504. {
  505. return 10; //得力
  506. }
  507. else if (trade.Craft.IndexOf("打码") != -1 || trade.Craft.IndexOf("压点线") != -1)
  508. {
  509. if (count < 300)
  510. {
  511. return 10;
  512. }
  513. else
  514. return 25;
  515. }
  516. if (trade.seller_memo.Contains("金属标") && (trade.ShopId == 26 || trade.ShopId == 45))
  517. {
  518. return 9;
  519. }
  520. //if (trade.IsOldCustomer == 1)
  521. //{
  522. // StringBuilder oldsql = new StringBuilder();
  523. // oldsql.AppendFormat("select top 1 SupplierId from view_erptradecell where buyer_nick={0} and IsAutoDistribute=1 ;",trad, trade.ProductId);
  524. //}
  525. StringBuilder sql = new StringBuilder();
  526. sql.AppendFormat("select count(0) from ce_erpproduct where id={0} and IsAutoDistribute=1 ;", trade.ProductId);
  527. sql.AppendFormat("select top 1 * from ce_erptrade where tid='{0}';", trade.tid);
  528. DataSet oDs = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  529. DataTable pDt = oDs.Tables[0];
  530. DataTable rDt = oDs.Tables[1];
  531. string material = trade.Material;
  532. material = material.Replace("铜板纸", "铜版纸");
  533. string crafts = trade.Craft;
  534. string supplierCrafts = trade.MakeSupplier;
  535. if (supplierCrafts == "")
  536. {
  537. supplierCrafts = "123123";
  538. }
  539. decimal size = getOrderSizeFromString(trade.ProductSize);
  540. if (pDt != null && pDt.Rows.Count > 0)
  541. {
  542. string receiver_state = "";
  543. if (rDt != null || rDt.Rows.Count > 0)
  544. {
  545. receiver_state = rDt.Rows[0]["receiver_state"].ToString();
  546. if (trade.IsOldCustomer == 1 && !string.IsNullOrEmpty(rDt.Rows[0]["buyer_nick"].ToString()))
  547. {
  548. StringBuilder oldsql = new StringBuilder();
  549. oldsql.AppendFormat("select top 1 * from view_erptradecell where buyer_nick='{0}' and ProductId={1} and SupplierId!=0 order by ID desc;", rDt.Rows[0]["buyer_nick"].ToString(), trade.ProductId);
  550. DataTable oldDt = DbHelper.DbConn.ExecuteDataset(oldsql.ToString()).Tables[0];
  551. if (oldDt.Rows.Count > 0)
  552. {
  553. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(Convert.ToInt32(oldDt.Rows[0]["SupplierId"]));
  554. if (ceErpSupplier != null && ceErpSupplier.IsClose == 0)
  555. {
  556. return Convert.ToInt32(oldDt.Rows[0]["SupplierId"]);
  557. }
  558. }
  559. }
  560. }
  561. try
  562. {
  563. //CHARINDEX(','+'{0}'+',',','+ProductID+',')>0
  564. sql = new StringBuilder();
  565. sql.AppendFormat("select A.* from CE_ErpSupplierProduct A LEFT JOIN CE_ErpSupplier B on A.SupplierID = B.ID where B.IsClose=0 and CHARINDEX(','+'{0}'+',',','+A.ProductIds+',')>0 order by A.Bsort asc;", trade.ProductId);
  566. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  567. if (dt == null || dt.Rows.Count < 1) return 0;
  568. DataView dv = new DataView(dt);
  569. int topOneProductSupplier = Convert.ToInt32(dv[0]["SupplierID"]);
  570. if (receiver_state.Length > 0)
  571. {
  572. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1} and SizeL<={2} and SizeW>={2} and (Area like '%{3}%' or Area='*')", material, count, size, receiver_state);
  573. if (dv.Count > 0)
  574. {
  575. return Convert.ToInt32(dv[0]["SupplierID"]);
  576. }
  577. }
  578. if (count > 0)
  579. {
  580. if (size > 0)
  581. {
  582. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1} and SizeL<={2} and SizeW>={2} ", material, count, size);
  583. if (dv.Count > 0)
  584. {
  585. return Convert.ToInt32(dv[0]["SupplierID"]);
  586. }
  587. }
  588. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1}", material, count);
  589. if (dv.Count > 0)
  590. {
  591. LogHelper.addLog(trade.ctid, 0, "筛选供应商:产品 材质 工艺 数量 符合!"); return Convert.ToInt32(dv[0]["SupplierID"]);
  592. }
  593. }
  594. if (size > 0)
  595. {
  596. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1} and SizeL<={2} and SizeW>={2}", material, count, size);
  597. if (dv.Count > 0)
  598. {
  599. return Convert.ToInt32(dv[0]["SupplierID"]);
  600. }
  601. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and SizeL<={1} and SizeW>={1}", material, size);
  602. if (dv.Count > 0)
  603. {
  604. return Convert.ToInt32(dv[0]["SupplierID"]);
  605. }
  606. }
  607. dv.RowFilter = string.Format("ProductCrafts like '%{0}%'", material);
  608. if (count > 0)
  609. {
  610. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1}", material, count);
  611. if (dv.Count > 0)
  612. {
  613. return Convert.ToInt32(dv[0]["SupplierID"]);
  614. }
  615. dv.RowFilter = string.Format("MinNum<={0} and MaxNum>={0}", count);
  616. if (dv.Count > 0)
  617. {
  618. return Convert.ToInt32(dv[0]["SupplierID"]);
  619. }
  620. }
  621. if (size > 0)
  622. {
  623. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and SizeL<={1} and SizeW>={1}", material, size);
  624. if (dv.Count > 0)
  625. {
  626. return Convert.ToInt32(dv[0]["SupplierID"]);
  627. }
  628. dv.RowFilter = string.Format(" SizeL<={0} and SizeW>={0}", size);
  629. if (dv.Count > 0)
  630. {
  631. return Convert.ToInt32(dv[0]["SupplierID"]);
  632. }
  633. }
  634. dv.RowFilter = string.Format("Crafts like '%{0}%' or Crafts like '%{1}%'", crafts, supplierCrafts);
  635. if (dv.Count > 0)
  636. {
  637. return Convert.ToInt32(dv[0]["SupplierID"]);
  638. }
  639. //产品 材质符合
  640. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' ", material);
  641. if (dv.Count > 0)
  642. {
  643. return Convert.ToInt32(dv[0]["SupplierID"]);
  644. }
  645. else
  646. {
  647. return topOneProductSupplier;
  648. }
  649. }
  650. catch (Exception ex)
  651. {
  652. XLog.SaveLog(0, "commmonHelper:autoDistributeToSupplier" + ex.Message);
  653. }
  654. }
  655. return 0;
  656. }
  657. public static void setDeliveryUnusualOrder2()
  658. {
  659. StringBuilder sql = new StringBuilder();
  660. sql.AppendFormat("select ctid,IsSF,seller_memo,SupplierId,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where orderstate=6 and unusualTag=0 and FinishPlaceTime is not null AND DATEDIFF( DAY, FinishPlaceTime, GETDATE( ) ) < 20 and IsXianHuo=0 and IsSample=0 ;");
  661. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  662. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  663. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  664. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  665. foreach (DataRow datarow in timer_data.Rows)
  666. {
  667. List<CeErpSupplierProductTime> list = null;
  668. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  669. if (timer_map.ContainsKey(supplierId))
  670. {
  671. timer_map.TryGetValue(supplierId, out list);
  672. }
  673. else
  674. {
  675. list = new List<CeErpSupplierProductTime>();
  676. timer_map.Add(supplierId, list);
  677. timer_map.TryGetValue(supplierId, out list);
  678. }
  679. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  680. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  681. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  682. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  683. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  684. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  685. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  686. list.Add(ceErpSupplierProductTime);
  687. }
  688. List<string> tLst = new List<string>();
  689. if (dt != null && dt.Rows.Count > 0)
  690. {
  691. foreach (DataRow row in dt.Rows)
  692. {
  693. try
  694. {
  695. int supplierId = Convert.ToInt32(row["SupplierId"]);
  696. int productId = Convert.ToInt32(row["productId"]);
  697. if (supplierId == 0 || productId == 0)
  698. {
  699. continue;
  700. }
  701. string seller_memo = row["seller_memo"].ToString();
  702. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  703. DateTime placeTime = DateTime.Now;
  704. if (string.IsNullOrEmpty(finishPlaceTime))
  705. {
  706. continue;
  707. }
  708. placeTime = DateTime.Parse(finishPlaceTime);
  709. //订单发货时间
  710. DateTime sendtime = placeTime;
  711. string type = placeDataGetMapKey(seller_memo, supplierId);
  712. bool istoday = placeDataIsToday(row, type);
  713. //需要当天发货
  714. if (istoday)
  715. {
  716. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) < 0)
  717. {
  718. tLst.Add("'" + row["ctid"].ToString() + "'");
  719. continue;
  720. }
  721. }
  722. //没配置时间
  723. if (!timer_map.ContainsKey(supplierId))
  724. {
  725. continue;
  726. }
  727. List<CeErpSupplierProductTime> timmerList = timer_map[supplierId];
  728. if (timmerList.Count == 0)
  729. {
  730. continue;
  731. }
  732. string[] productIds = null;
  733. string txtCount = row["ProductCount"].ToString();
  734. foreach (CeErpSupplierProductTime productTime in timmerList)
  735. {
  736. string txtIds = productTime.productId;
  737. string[] crafts = { };
  738. int count = productTime.quantity;
  739. if (string.IsNullOrEmpty(txtIds))
  740. {
  741. continue;
  742. }
  743. if (count > 0)
  744. {
  745. int quantity = handleProductCount(txtCount, true);
  746. //订单数量大于写入的数量则跳过
  747. if (quantity > count)
  748. {
  749. continue;
  750. }
  751. }
  752. productIds = txtIds.Split(',');
  753. if (productIds.Contains(productId.ToString()))
  754. {
  755. string textCraft = productTime.craft;
  756. textCraft = textCraft.Replace(",", ",");//统一格式
  757. if (!string.IsNullOrEmpty(textCraft))
  758. {
  759. crafts = textCraft.Split(',');
  760. }
  761. if (crafts.Length > 0)
  762. {
  763. bool isinCraft = false;
  764. for (int i = 0; i < crafts.Length; i++)
  765. {
  766. if (seller_memo.IndexOf(crafts[i]) >= 0)
  767. {
  768. isinCraft = true;
  769. break;
  770. }
  771. }
  772. //有写工艺并且备注中没匹配中则跳过
  773. if (!isinCraft)
  774. {
  775. continue;
  776. }
  777. }
  778. DateTime deadLine = DateTime.Parse(productTime.deadLine);
  779. DateTime dayDeadLine = DateTime.Parse(productTime.dayDeadLine);
  780. int sendDay = productTime.sendDay;
  781. //下单时间小于当日发货时间则不用判断
  782. //当日发货必须发货
  783. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  784. {
  785. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  786. }
  787. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  788. {
  789. //在截稿时间之前下单的可以减去一天时间
  790. sendDay = Math.Max(1, sendDay - 1);
  791. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  792. }
  793. else
  794. {
  795. sendDay = Math.Max(1, sendDay - 1);
  796. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  797. }
  798. //判断有没有到发货日期大于0还没到发货时间
  799. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) < 0)
  800. {
  801. tLst.Add("'" + row["ctid"].ToString() + "'");
  802. //匹配到就不要继续匹配了
  803. break;
  804. }
  805. }
  806. }
  807. }
  808. catch (Exception ex)
  809. {
  810. XLog.SaveLog(0, row["ctid"].ToString() + "更新发货异常订单错误:" + ex);
  811. }
  812. }
  813. }
  814. if (tLst.Count > 0)
  815. {
  816. string needctids = string.Join(",", tLst.ToArray());
  817. StringBuilder updsql = new StringBuilder();
  818. //DateTime unusualTime = new DateTime();
  819. updsql.AppendFormat("update ce_erptradecell with(rowlock) set unusualTag=5,UnusualTime=getDate() where ctid in ({0});", needctids);
  820. DbHelper.DbConn.ExecuteNonQuery(updsql.ToString());
  821. }
  822. }
  823. public static void setDeliveryUnusualOrder()
  824. {
  825. try
  826. {
  827. StringBuilder sql = new StringBuilder();
  828. sql.AppendFormat("select * from view_ErpTradeCell where orderstate=6 and unusualTag=0 and FinishPlaceTime is not null and DATEDIFF(HH,FinishPlaceTime,GETDATE())>48 and DATEDIFF(DAY,FinishPlaceTime,GETDATE())<20 and IsXianHuo=0 and (IsSample=0 or IsSample=2);");
  829. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  830. List<string> tLst = new List<string>();
  831. if (dt.Rows.Count > 0)
  832. {
  833. foreach (DataRow dr in dt.Rows)
  834. {
  835. double hour = 0;
  836. string fptime = dr["FinishPlaceTime"].ToString();
  837. if (fptime.Length > 0)
  838. {
  839. hour = DateTime.Now.Subtract(Convert.ToDateTime(fptime)).TotalHours;
  840. }
  841. else
  842. continue;
  843. int useHour = 10000;
  844. StringBuilder sqlhour = new StringBuilder();
  845. sqlhour.AppendFormat("select top 1 * from CE_ErpProductHour where ProductID={0} and (CHARINDEX(Material,'{1}')>0 or Material='*') and (CHARINDEX(Craft,'{2}')>0 or Craft='*');", dr["ProductId"].ToString(), dr["Material"].ToString(), dr["Craft"].ToString());
  846. DataTable dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  847. if (dthour.Rows.Count > 0)
  848. {
  849. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  850. }
  851. else
  852. {
  853. sqlhour = new StringBuilder();
  854. sqlhour.AppendFormat("select top 1 * from CE_ErpProductHour where ProductID={0} and (CHARINDEX(Craft,'{1}')>0 or Craft='*');", dr["ProductId"].ToString(), dr["Craft"].ToString());
  855. dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  856. if (dthour.Rows.Count > 0)
  857. {
  858. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  859. }
  860. else
  861. {
  862. sqlhour = new StringBuilder();
  863. sqlhour.AppendFormat("select top 1 * from CE_ErpProductHour where ProductID={0};", dr["ProductId"].ToString());
  864. dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  865. if (dthour.Rows.Count > 0)
  866. {
  867. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  868. }
  869. }
  870. }
  871. if (hour > useHour)
  872. {
  873. tLst.Add("'" + dr["ctid"].ToString() + "'");
  874. }
  875. }
  876. }
  877. sql = new StringBuilder();
  878. sql.AppendFormat("select * from view_ErpTradeCell where orderstate=6 and unusualTag=0 and FinishPlaceTime is not null and DATEDIFF(HH,FinishPlaceTime,GETDATE())>3 and DATEDIFF(DAY,FinishPlaceTime,GETDATE())<20 and IsXianHuo=1 ;");
  879. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  880. if (dt.Rows.Count > 0)
  881. {
  882. foreach (DataRow dr in dt.Rows)
  883. {
  884. double hour = 0;
  885. string fptime = dr["FinishPlaceTime"].ToString();
  886. string paytime = dr["pay_time"].ToString();
  887. DateTime dtPaytime = Convert.ToDateTime(paytime);
  888. if (fptime.Length > 0)
  889. {
  890. hour = DateTime.Now.Subtract(Convert.ToDateTime(paytime)).TotalHours;
  891. }
  892. else
  893. continue;
  894. DateTime nowtime = DateTime.Now;
  895. if (hour > 18)
  896. {
  897. tLst.Add("'" + dr["ctid"].ToString() + "'");
  898. }
  899. //if (hour > 72 && Convert.ToInt32(dr["ShopId"])==34)//公司自用
  900. //{
  901. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  902. //}
  903. //else if (nowtime.Hour >= 17)
  904. //{
  905. // if((dtPaytime.Hour >= 14 && dtPaytime.Hour < 17) || (dtPaytime.Hour == 17 && dtPaytime.Minute < 40))
  906. // {
  907. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 17:40:00";
  908. // DateTime spDatetime = Convert.ToDateTime(sptime);
  909. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  910. // {
  911. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  912. // }
  913. // }
  914. //}
  915. //else if (nowtime.Hour >= 14)
  916. //{
  917. // if(dtPaytime.Hour >= 10 && dtPaytime.Hour < 14)
  918. // {
  919. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 14:00:00";
  920. // DateTime spDatetime = Convert.ToDateTime(sptime);
  921. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  922. // {
  923. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  924. // }
  925. // }
  926. //}
  927. //else if (nowtime.Hour >= 10)
  928. //{
  929. // if (dtPaytime.Hour >= 18 || dtPaytime.Hour < 10)
  930. // {
  931. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 10:00:00";
  932. // DateTime spDatetime = Convert.ToDateTime(sptime);
  933. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  934. // {
  935. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  936. // }
  937. // }
  938. //}
  939. }
  940. }
  941. if (tLst.Count > 0)
  942. {
  943. string needctids = string.Join(",", tLst.ToArray());
  944. StringBuilder updsql = new StringBuilder();
  945. //DateTime unusualTime = new DateTime();
  946. updsql.AppendFormat("update ce_erptradecell with(rowlock) set unusualTag=5,UnusualTime=getDate() where ctid in ({0});", needctids);
  947. DbHelper.DbConn.ExecuteNonQuery(updsql.ToString());
  948. }
  949. }
  950. catch (Exception ex)
  951. {
  952. XLog.SaveLog(0, "更新发货异常订单错误:" + ex.Message);
  953. }
  954. splitCell2AllPlaceOrder();
  955. }
  956. public static void splitCell2AllPlaceOrder()
  957. {
  958. //
  959. int spid = 0;
  960. try
  961. {
  962. StringBuilder sql = new StringBuilder();
  963. sql.AppendFormat("select * from CE_ErpTradeCell2 where DATEDIFF(DAY, FinishPlaceTime, GETDATE())<5 and MakeSupplier like '%,%';");
  964. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  965. List<string> idList = new List<string>();
  966. foreach (DataRow dr in dt.Rows)
  967. {
  968. string msup = dr["MakeSupplier"].ToString();
  969. string[] suplist = msup.Split(',');
  970. spid = Convert.ToInt32(dr["ID"]);
  971. foreach (string supItem in suplist)
  972. {
  973. StringBuilder newsql = new StringBuilder();
  974. newsql.AppendFormat(" insert into CE_ErpTradeCell2 ([ctid],[tid],[DesignUserId],[OrderState],[CustomerUserId],[IsUrgency],[IsRefund],[IsReturn],[IsNeedBill]," +
  975. "[SupplierId],[DeliveryAddress],[CallTimes],[NoteTimes],[OvertimeUserId],[UnusualTag],[UnusualCon],[ReturnReason],[MemoOpt],[AfterSaleTime],[AfterSaleUserId]," +
  976. "[AfterSaleReason],[PlaceUserId],[AfterSaleState],[AfterSaleMethod],[AfterSaleMemo],[AfterSaleResponsible],[AfterSalePreTime],[FinishAfterSaleTime],[DeductFee]," +
  977. "[RefundFee],[HandleTime],[IsHaveNewOrder],[ResponsibleUserId],[ptid],[IsPreDelivery],[IsSample],[seller_memo],[ProductId],[WaitDesignTime],[StartDesignTime]," +
  978. "[FinishDesignTime],[FinishPlaceTime],[FinishDeliveryTime],[DesignSelfMemo],[DesignPrice],[Material],[Craft],[ProductSize],[ProductCount],[UnusualTime],[IsAutoDispatch]," +
  979. "[IsVerifyToSupplier],[CustomerMemo],[payment],[OutSid],[AfterSalePayment],[ShopId],[SplitTag],[isAfterSaleOrder],[isDianziOrder],[LastBillCpCode],[LastBillWaybillCode]," +
  980. "[pay_time],[IsSF],[IsXianHuo],[ReturnTime],[OtherMemo],[AfterSaleBackReason],[CheckMemo],[IsOldCustomer],[IsSupplierRefund],[IsReadTag],[AfterSaleMemoType]," +
  981. "[UrgencyTime],[IsOffLineOrder],[PayProofImg],[wechatTag],[MakeSupplier]) select [ctid],[tid],[DesignUserId],[OrderState],[CustomerUserId],[IsUrgency],[IsRefund]," +
  982. "[IsReturn],[IsNeedBill],[SupplierId],[DeliveryAddress],[CallTimes],[NoteTimes],[OvertimeUserId],[UnusualTag],[UnusualCon],[ReturnReason],[MemoOpt],[AfterSaleTime]," +
  983. "[AfterSaleUserId],[AfterSaleReason],[PlaceUserId],[AfterSaleState],[AfterSaleMethod],[AfterSaleMemo],[AfterSaleResponsible],[AfterSalePreTime],[FinishAfterSaleTime]," +
  984. "[DeductFee],[RefundFee],[HandleTime],[IsHaveNewOrder],[ResponsibleUserId],[ptid],[IsPreDelivery],[IsSample],[seller_memo],[ProductId],[WaitDesignTime],[StartDesignTime]," +
  985. "[FinishDesignTime],[FinishPlaceTime],[FinishDeliveryTime],[DesignSelfMemo],[DesignPrice],[Material],[Craft],[ProductSize],[ProductCount],[UnusualTime],[IsAutoDispatch]," +
  986. "[IsVerifyToSupplier],[CustomerMemo],[payment],[OutSid],[AfterSalePayment],[ShopId],[SplitTag],[isAfterSaleOrder],[isDianziOrder],[LastBillCpCode],[LastBillWaybillCode]," +
  987. "[pay_time],[IsSF],[IsXianHuo],[ReturnTime],[OtherMemo],[AfterSaleBackReason],[CheckMemo],[IsOldCustomer],[IsSupplierRefund],[IsReadTag],[AfterSaleMemoType],[UrgencyTime]," +
  988. "[IsOffLineOrder],[PayProofImg],[wechatTag],'{1}' from CE_ErpTradeCell2 where ID={0}", Convert.ToInt32(dr["ID"]), supItem);
  989. DbHelper.DbConn.ExecuteNonQuery(newsql.ToString());
  990. }
  991. idList.Add(dr["ID"].ToString());
  992. }
  993. string idsstr = string.Join(",", idList.ToArray());
  994. sql.AppendFormat("delete from CE_ErpTradeCell2 where ID in ({0})", idsstr);
  995. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  996. }
  997. catch (Exception ex)
  998. {
  999. XLog.SaveLog(0, "拆分ce_erptradecell2表的制作车间出错:" + spid + ex.Message);
  1000. }
  1001. }
  1002. public static void DoAutoDispatch(string conn)
  1003. {
  1004. if (webConfig.Dispatch_TimeList.Contains(DateTime.Now.ToString("HH:mm")))
  1005. {
  1006. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始自动派单!"));
  1007. SqlParameter[] sqlParameter ={
  1008. new SqlParameter("@res", SqlDbType.VarChar, 50)};
  1009. sqlParameter[0].Direction = ParameterDirection.Output;
  1010. CeErpOpt.ExecuteNonQueryStore("sp_autodispatch", sqlParameter);
  1011. string res = sqlParameter[0].Value.ToString();
  1012. if (res == "派单完成") WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "结束自动派单!"));
  1013. else WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "无法成功派单"));
  1014. }
  1015. //sp_autodispatch
  1016. }
  1017. public static void DoAutoDispatch2(string conn)
  1018. {
  1019. if (webConfig.Dispatch_TimeList.Contains(DateTime.Now.ToString("HH:mm")))
  1020. {
  1021. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始自动派单!"));
  1022. SqlConnection sqlCnt = new SqlConnection(conn);
  1023. try
  1024. {
  1025. sqlCnt.Open();
  1026. string sql = "select * from view_ErpTradeCell where OrderState = 2 and ProductId <> 0";
  1027. SqlDataAdapter myDataAdapter = new SqlDataAdapter(sql, sqlCnt);
  1028. DataSet myDataSet = new DataSet();
  1029. myDataAdapter.Fill(myDataSet, "Trade");
  1030. DataTable myTable = myDataSet.Tables[0];
  1031. List<string> ids = new List<string>();
  1032. foreach (DataRow Dr in myTable.Rows)
  1033. {
  1034. if (Convert.ToInt32(Dr["OrderState"]) > 2 || Convert.ToInt32(Dr["DesignUserId"]) > 0)
  1035. {
  1036. continue;
  1037. }
  1038. ids.Add(Dr["ctid"].ToString());
  1039. CeErpShop nShop = CeErpShop.GetShopIdByName(Dr["seller_nick"].ToString());
  1040. string shopId = "0";
  1041. if (nShop != null)
  1042. {
  1043. shopId = nShop.ID.ToString();
  1044. }
  1045. string proId = Dr["ProductId"].ToString();
  1046. string Amount = Dr["payment"].ToString();
  1047. string ctid = Dr["ctid"].ToString();
  1048. string ctids = "";
  1049. if (ctid.IndexOf("C") != -1)
  1050. {
  1051. ctids = getSameTradeByTid(Dr["tid"].ToString());
  1052. if (ctids.Length <= 0)
  1053. {
  1054. continue;
  1055. }
  1056. }
  1057. else
  1058. {
  1059. ctids = "'" + ctid + "'";
  1060. }
  1061. sql = "select top 1 * from view_ErpUser " +
  1062. "where PostCode = 'Designer' and " + //设计师
  1063. "OnDuty = 1 and " + //上班状态
  1064. "DayOrderReceive < DayOrderLimit and " + //当日接单数小于可接单数量上限
  1065. "OrderAmountLimit >= " + Amount + " and " + //额度上限大于付款金额
  1066. "CHARINDEX('," + shopId + ",',','+OrgShop+ ',')>0 and " + //部门关联店铺
  1067. "CHARINDEX('," + shopId + ",',','+pemShop+ ',')>0 and " + //个人关联店铺
  1068. "CHARINDEX('," + proId + ",',','+pemDesign+ ',')>0 " + //个人关联产品
  1069. "order by DayOrderPer, PostLevel desc, Id";
  1070. SqlDataAdapter userAdapter = new SqlDataAdapter(sql, sqlCnt);
  1071. DataSet userSet = new DataSet();
  1072. userAdapter.Fill(userSet, "user");
  1073. DataTable userTable = userSet.Tables[0];
  1074. //有满足条件的设计师
  1075. if (userTable.Rows.Count > 0)
  1076. {
  1077. SqlCommand updCMD = sqlCnt.CreateCommand();
  1078. try
  1079. {
  1080. updCMD.Transaction = sqlCnt.BeginTransaction();//开启事务
  1081. //派单
  1082. updCMD.CommandText = "update CE_ErpTradeCell set OrderState = 3, IsAutoDispatch = 1, WaitDesignTime = getdate(), DesignUserId = " + userTable.Rows[0]["ID"].ToString() + " where ctid in (" + ctids + ")";
  1083. updCMD.ExecuteNonQuery();
  1084. //更新日数量上限和可接单比例
  1085. updCMD.CommandText = "update view_ErpUser set DayOrderReceive = DayOrderReceive + 1, DayOrderPer = CAST((CAST(((DayOrderReceive + 1)) as decimal(8,5)) / DayOrderLimit) as decimal(8,3)) where id = " + userTable.Rows[0]["ID"].ToString();
  1086. updCMD.ExecuteNonQuery();
  1087. //写订单日志
  1088. updCMD.CommandText = "insert into CE_ErpTradeLog(tid,OrderState,UserId,OperateTime,Con) select ctid,OrderState,0,getdate(),'自动派单' from ce_erptradecell where ctid in(" + ctids + ")";
  1089. updCMD.ExecuteNonQuery();
  1090. updCMD.Transaction.Commit();//提交事务(真正的从数据库中修改了数据)
  1091. }
  1092. catch (Exception ee)
  1093. {
  1094. updCMD.Transaction.Rollback();
  1095. }
  1096. }
  1097. }
  1098. string sql1 = "select ctid from view_ErpTradeCell where orderstate=3 and DesignUserId = 2125 and ctid in ('" + string.Join(",", ids) + "');";
  1099. /* string sql1 = "select ctid from view_ErpTradeCell where orderstate=3 and DesignUserId = 2125 ";*/
  1100. DataTable dt1 = SqlHelper.ExecuteDataSet(sql1).Tables[0];
  1101. foreach (DataRow dr1 in dt1.Rows)
  1102. {
  1103. apiDesign.API_GetPrintData_CreateOrder(CeErpTradeCell.GetByCtid(dr1["ctid"].ToString()));
  1104. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始派单" + dr1["ctid"].ToString() + "至设计系统!"));
  1105. Thread.Sleep(1000); // 添加五秒延迟
  1106. }
  1107. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "结束自动派单!"));
  1108. }
  1109. catch (Exception ed)
  1110. {
  1111. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), ed.Message));
  1112. }
  1113. finally
  1114. {
  1115. if (sqlCnt.State == ConnectionState.Open)
  1116. sqlCnt.Close();
  1117. }
  1118. }
  1119. }
  1120. public static string getSameTradeByTid(string tid)
  1121. {
  1122. StringBuilder sql = new StringBuilder();
  1123. sql.AppendFormat("select ctid from view_ErpTradeCell where tid='{0}';", tid);
  1124. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1125. if (dt.Rows.Count > 0)
  1126. {
  1127. string ctids = "";
  1128. foreach (DataRow dr in dt.Rows)
  1129. {
  1130. ctids += "'";
  1131. ctids += dr["ctid"].ToString();
  1132. ctids += "'";
  1133. ctids += ",";
  1134. }
  1135. ctids = ctids.Substring(0, ctids.Length - 1);
  1136. return ctids;
  1137. }
  1138. else
  1139. return "";
  1140. }
  1141. public static void WriteLog(string LogText)
  1142. {
  1143. string sDir = System.IO.Path.GetTempPath() + @"Log\" + DateTime.Now.ToString("yyyyMM");
  1144. if (!Directory.Exists(sDir))
  1145. Directory.CreateDirectory(sDir);
  1146. using (StreamWriter sw = new StreamWriter(sDir + @"\Log_" + DateTime.Now.ToString("dd") + ".txt", true, Encoding.UTF8))
  1147. {
  1148. sw.Write(LogText + System.Environment.NewLine);
  1149. }
  1150. }
  1151. public static void UpdateRelationOrder(string ctid)
  1152. {
  1153. if (ctid.Length <= 0) return;
  1154. CeErpTradeCell.UpdateRelationOrder(ctid);
  1155. //try
  1156. //{
  1157. // //父订单变化,更新补差价订单
  1158. // //List<string> lw = new List<string>();
  1159. // //lw.Add(string.Format("OrderState={0}", father.OrderState));
  1160. // //lw.Add(string.Format("CustomerUserId={0}", father.CustomerUserId));
  1161. // //lw.Add(string.Format("DesignUserId={0}", father.DesignUserId));
  1162. // //lw.Add(string.Format("AfterSaleState={0}", father.AfterSaleState));
  1163. // //lw.Add(string.Format("IsNeedBill={0}", father.IsNeedBill));
  1164. // ////lw.Add(string.Format("IsUrgency={0}", father.IsUrgency == true ? 1 : 0));
  1165. // //lw.Add(string.Format("IsRefund={0}", father.IsRefund));
  1166. // //lw.Add(string.Format("WaitDesignTime='{0}'", father.WaitDesignTime.ToString()));
  1167. // //lw.Add(string.Format("StartDesignTime='{0}'", father.StartDesignTime.ToString()));
  1168. // //lw.Add(string.Format("FinishDesignTime='{0}'", father.FinishDesignTime.ToString()));
  1169. // //lw.Add(string.Format("FinishPlaceTime='{0}'", father.FinishPlaceTime.ToString()));
  1170. // //lw.Add(string.Format("FinishDeliveryTime='{0}'", father.FinishDeliveryTime.ToString()));
  1171. // ////lw.Add(string.Format("IsReturn={0}", father.IsReturn));
  1172. // //string sqlstr = string.Join(" , ", lw.ToArray());
  1173. // //StringBuilder sql = new StringBuilder();
  1174. // //sql.AppendFormat("update ce_erptradecell set " + sqlstr + " where ptid='{0}'", father.tid);
  1175. // ////sql.AppendFormat("update view_erptrade set status={1} where ptid={0}", father.ctid, father.status);
  1176. // //DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1177. // //StringBuilder sql = new StringBuilder();
  1178. // //sql.Append("update ce_erptradecell set OrderState=b.OrderState,CustomerUserId=b.CustomerUserId,DesignUserId=b.DesignUserId,WaitDesignTime=b.WaitDesignTime,StartDesignTime=b.StartDesignTime,FinishDesignTime=b.FinishDesignTime,FinishPlaceTime=b.FinishPlaceTime,");
  1179. // //sql.Append("AfterSaleState=b.AfterSaleState,IsNeedBill=b.IsNeedBill,IsRefund=b.IsRefund from ce_erptradecell,ce_erptradecell as b ");
  1180. // //sql.AppendFormat("where ce_erptradecell.ptid =b.tid and ce_erptradecell.ptid='{0}'", tid);//='1827905618077154637'
  1181. // //DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1182. // //SqlParameter[] sqlParameter ={
  1183. // // new SqlParameter("@mainctids", SqlDbType.VarChar,100),
  1184. // // new SqlParameter("@res", SqlDbType.VarChar, 4000)
  1185. // //};
  1186. // //sqlParameter[0].Value = ctid;
  1187. // //sqlParameter[1].Direction = ParameterDirection.Output;
  1188. // //DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_set_bucha", sqlParameter);
  1189. //}
  1190. //catch (Exception ex)
  1191. //{
  1192. // XLog.SaveLog(0, "commmonHelper:UpdateRelationOrder" + ex.Message);
  1193. //}
  1194. }
  1195. public static void UpdateSameOrderToDesigner(CeErpTradeCell entity, int designId)
  1196. {
  1197. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1198. if (trade != null)
  1199. {
  1200. StringBuilder sql = new StringBuilder();
  1201. if (trade.type == "PDD" || trade.type == "JD")
  1202. {
  1203. sql.AppendFormat("update view_ErpTradeCell with(rowlock) set OrderState=3,WaitDesignTime=getDate(),DesignUserId={0} where buyer_nick='{1}' and tid='{4}' and seller_nick='{2}' and ABS(DATEDIFF(HH,'{3}',pay_time))<24 and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and IsRefund=0;", designId, trade.buyer_nick, trade.seller_nick, trade.pay_time, trade.tid);
  1204. }
  1205. else
  1206. sql.AppendFormat("update view_ErpTradeCell with(rowlock) set OrderState=3,WaitDesignTime=getDate(),DesignUserId={0} where buyer_nick='{1}' and seller_nick='{2}' and ABS(DATEDIFF(HH,'{3}',pay_time))<24 and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and IsRefund=0;", designId, trade.buyer_nick, trade.seller_nick, trade.pay_time);
  1207. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1208. }
  1209. }
  1210. public static void SetSameSupplierToOrder(CeErpTradeCell entity, int supId)
  1211. {
  1212. StringBuilder sql = new StringBuilder();
  1213. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set SupplierId={0} where orderstate=5 and tid='{1}';", supId, entity.tid);
  1214. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1215. }
  1216. public static string MidStrEx(string sourse, string startstr, string endstr)
  1217. {
  1218. string result = string.Empty;
  1219. int startindex, endindex;
  1220. try
  1221. {
  1222. startindex = sourse.IndexOf(startstr);
  1223. if (startindex == -1)
  1224. return result;
  1225. string tmpstr = sourse.Substring(startindex + startstr.Length);
  1226. endindex = tmpstr.IndexOf(endstr);
  1227. if (endindex == -1)
  1228. return result;
  1229. result = tmpstr.Remove(endindex);
  1230. }
  1231. catch (Exception ex)
  1232. {
  1233. Console.WriteLine("MidStrEx Err:" + ex.Message);
  1234. }
  1235. return result;
  1236. }
  1237. public static string KeepChinese(string str)
  1238. {
  1239. string chineseString = "";
  1240. for (int i = 0; i < str.Length; i++)
  1241. {
  1242. if (str[i] >= 0x4E00 && str[i] <= 0x9FA5)
  1243. {
  1244. chineseString += str[i];
  1245. }
  1246. }
  1247. return chineseString;
  1248. }
  1249. public static string GetD3ComCode(string code, string name)
  1250. {
  1251. string useStr = code;
  1252. if (code.Length == 0)
  1253. {
  1254. useStr = name;
  1255. }
  1256. string sql = "select * from CE_ErpMailInfo";
  1257. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1258. foreach (DataRow dr in dt.Rows)
  1259. {
  1260. if (dr["cpCode"].ToString().IndexOf(useStr) != -1)
  1261. {
  1262. return dr["cpCode"].ToString();
  1263. }
  1264. }
  1265. //声明存储结果的字符串
  1266. //string codeStr = "YTO-CAINIAO,HTKY-CAINIAO-GZ,YUNDA-CAINIAO-GZ,STO-CAINIAO-SC,STO-CAINIAO-JS,STO-CAINIAO-LN,ZTO-CAINIAO-GZ,ZTO-CAINIAO-FS,ZTO-CAINIAO-KF,ZTO-CAINIAO-ZZ,DISTRIBUTOR_1710055-LY,STO-CAINIAO-AH," +
  1267. // "EYB-CAINIAO-LY,EMS-CAINIAO-LY,POST-CAINIAO-LY,UC-CAINIAO-LY,DBL-CAINIAO-LY,DBKD-CAINIAO-LY,XFWL-CAINIAO-LY,AN-CAINIAO-LY,STO-CAINIAO-LY,DISTRIBUTOR_13222803-LY,BESTQJT-CAINIAO-LY,ZTO-CAINIAO-YW," +
  1268. // "SF-CAINIAO-LY,SF-DF-CAINIAO-LY,SF-CAINIAO-HNXX,SF-CAINIAO-GDFS,SF-CAINIAO-JSTZ,SF-DF-CAINIAO-HNXX,SF-DF-CAINIAO-GDFS,SF-DF-CAINIAO-JSTZ,POSTB-CAINIAO-LY,ZTO-CAINIAO-JS,POSTB-CAINIAO-FS," +
  1269. // "YUNDA-CAINIAO-JA,SF-CAINIAO-GDGZ,YUNDA-CAINIAO-GDFS,";
  1270. //string[] codeList = codeStr.Split(',');
  1271. ////将传入参数中的中文字符添加到结果字符串中
  1272. //for (int i = 0; i < codeList.Length; i++)
  1273. //{
  1274. // if (codeList[i].IndexOf(useStr) != -1)
  1275. // {
  1276. // return codeList[i];
  1277. // }
  1278. //}
  1279. //返回保留中文的处理结果
  1280. return "";
  1281. }
  1282. public static int getRefundTagByState(string st, int isPart = 0)
  1283. {
  1284. int state = 0;
  1285. if (st == "NO_REFUND" || st == "SELLER_REFUSE_BUYER" || st == "CLOSED" || st == "FAILED")
  1286. {
  1287. state = 0;
  1288. }
  1289. else if (st == "REFUNDING")
  1290. {
  1291. state = 1;
  1292. }
  1293. else if (st == "REFUNDED" || st == "SUCCESS")
  1294. {
  1295. state = 2;
  1296. }
  1297. else if (st == "PART_REFUNDED" || isPart == 1)
  1298. {
  1299. state = 3;
  1300. }
  1301. else if (st == "WAIT_BUYER_RETURN_GOODS")
  1302. {
  1303. state = 4;
  1304. }
  1305. else if (st == "REJECT_REFUNDED")
  1306. {
  1307. state = 5;
  1308. }
  1309. else if (st == "WAIT_SELLER_CONFIRM_GOODS")
  1310. {
  1311. state = 6;
  1312. }
  1313. return state;
  1314. }
  1315. public static string getRefundStringByState(string st)
  1316. {
  1317. string stateStr = "";
  1318. if (st == "NOT_SHIPPED")
  1319. {
  1320. stateStr = "待发货";
  1321. }
  1322. else if (st == "PART_SHIPPED")
  1323. {
  1324. stateStr = "部分发货";
  1325. }
  1326. else if (st == "SHIPPED")
  1327. {
  1328. stateStr = "已发货";
  1329. }
  1330. else if (st == "COMPLETE")
  1331. {
  1332. stateStr = "已完成";
  1333. }
  1334. else if (st == "CLOSE")
  1335. {
  1336. stateStr = "已关闭";
  1337. }
  1338. else if (st == "REFUNDED")
  1339. {
  1340. stateStr = "退款成功";
  1341. }
  1342. else if (st == "PART_REFUNDED")
  1343. {
  1344. stateStr = "部分退款";
  1345. }
  1346. else if (st == "WAIT_BUYER_RETURN_GOODS")
  1347. {
  1348. stateStr = "等待买家退货";
  1349. }
  1350. else if (st == "REJECT_REFUNDED")
  1351. {
  1352. stateStr = "拒绝退货";
  1353. }
  1354. else if (st == "WAIT_SELLER_CONFIRM_GOODS")
  1355. {
  1356. stateStr = "等待卖家确认收货";
  1357. }
  1358. else if (st == "SELLER_REFUSE_BUYER")
  1359. {
  1360. stateStr = "卖家拒绝退款";
  1361. }
  1362. else if (st == "SUCCESS")
  1363. {
  1364. stateStr = "退款成功";
  1365. }
  1366. else if (st == "CLOSED")
  1367. {
  1368. stateStr = "退款关闭";
  1369. }
  1370. else if (st == "FAILED")
  1371. {
  1372. stateStr = "退款失败";
  1373. }
  1374. return stateStr;
  1375. }
  1376. public static void UpdateRefundOrderState(string tid, int rstate)
  1377. {
  1378. StringBuilder sql = new StringBuilder();
  1379. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype,refundState) values('{0}',getdate(),'refund',{1}); ", tid, rstate);
  1380. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1381. }
  1382. public static void checkBillResult(int billId)
  1383. {
  1384. CeErpBill entiy = CeErpBill.Get(billId);
  1385. if (entiy != null)
  1386. {
  1387. try
  1388. {
  1389. string[] billOrderList = entiy.billOrderId.Split(',');
  1390. int iTag = 0;
  1391. entiy.fplsh = "";
  1392. entiy.fpdm = "";
  1393. entiy.fphm = "";
  1394. foreach (string billOrderId in billOrderList)
  1395. {
  1396. iTag++;
  1397. string res = taobaoHelper.get_invoicing(billId.ToString(), billOrderId);
  1398. int fcount = StrCount(res, "c_orderno");
  1399. if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  1400. {
  1401. StringBuilder sql = new StringBuilder();
  1402. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", billId.ToString());
  1403. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1404. return;
  1405. }
  1406. else if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  1407. {
  1408. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  1409. try
  1410. {
  1411. Invoicing_get_response_Obj iObj = null;
  1412. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  1413. if (iObj != null)
  1414. {
  1415. if (fcount > 1)
  1416. {
  1417. entiy.state = 4; //红冲作废
  1418. }
  1419. else
  1420. entiy.state = 2; //开票完成
  1421. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  1422. entiy.fpdm += iObj.list[0].c_fpdm;
  1423. entiy.fphm += iObj.list[0].c_fphm;
  1424. if (iTag < billOrderList.Length)
  1425. {
  1426. entiy.fplsh += ",";
  1427. entiy.fpdm += ",";
  1428. entiy.fphm += ",";
  1429. }
  1430. entiy.Update();
  1431. }
  1432. if (fcount <= 1)
  1433. {
  1434. StringBuilder sql = new StringBuilder();
  1435. sql.AppendFormat("update CE_ErpTradeCell WITH(ROWLOCK) set IsNeedBill=2 where tid='{0}';", entiy.tid);
  1436. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1437. }
  1438. }
  1439. catch (Exception ex)
  1440. {
  1441. StringBuilder sql = new StringBuilder();
  1442. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", billId.ToString());
  1443. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1444. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  1445. }
  1446. return;
  1447. }
  1448. else
  1449. {
  1450. string redError = "";
  1451. if (fcount > 1)
  1452. {
  1453. redError = "红冲失败";
  1454. }
  1455. int eidx = res.IndexOf("c_resultmsg");
  1456. string emsg = KeepChinese(res.Substring(eidx, res.Length - eidx));
  1457. //开票失败
  1458. entiy.state = 5;
  1459. entiy.failerror = entiy.failerror + (iTag + "&" + redError + emsg + "|");
  1460. entiy.Update();
  1461. return;
  1462. }
  1463. }
  1464. }
  1465. catch (Exception ex)
  1466. {
  1467. XLog.SaveLog(0, "buchajia查看开票结果错误," + ex.Message);
  1468. }
  1469. }
  1470. }
  1471. public static void insertToBuchaForDelivery(string Maintid, string posCode, string comCode, string outSid)
  1472. {
  1473. if (Maintid.Length <= 0) return;
  1474. try
  1475. {
  1476. StringBuilder sql = new StringBuilder();
  1477. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype,posCode,comCode,outSid) select tid,getdate(),'bucha_delivery','{1}','{2}','{3}' from ce_erptradecell where ptid='{0}'; ", Maintid, posCode, comCode, outSid);
  1478. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1479. //}
  1480. }
  1481. catch (Exception ex)
  1482. {
  1483. XLog.SaveLog(0, "commhelper,insertToBuchaForDelivery,insert" + ex.Message);
  1484. //}
  1485. }
  1486. }
  1487. public static void setBuChaDelivery(string tid, string posCode, string comCode, string outSid)
  1488. {
  1489. outSid = outSid.Trim();
  1490. posCode = posCode.Trim();
  1491. comCode = comCode.Trim();
  1492. CeErpTrade mainEn = CeErpTrade.Get(tid);
  1493. if (mainEn != null)
  1494. {
  1495. if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || mainEn.status == "COMPLETE" || mainEn.status == "CLOSE") //已发货的不处理直接返回面单
  1496. {
  1497. return;
  1498. //不处理
  1499. }
  1500. string apires = apiHelper.API_LogisticsDummySend(tid, posCode);
  1501. if (apires.IndexOf("发货成功") == -1)
  1502. {
  1503. XLog.SaveLog(0, "补差价单虚拟发货失败," + tid + "," + posCode + "," + apires);
  1504. string wures = apiHelper.API_LogisticsOnlineSend(tid, posCode, comCode, outSid, "");
  1505. if (wures.IndexOf("发货成功") == -1)
  1506. {
  1507. XLog.SaveLog(0, "补差价单实物发货失败," + tid + "," + posCode + "," + wures);
  1508. return;
  1509. }
  1510. else
  1511. {
  1512. LogHelper.addLog(tid, 0, "补差价发货-" + comCode + "-" + outSid);
  1513. }
  1514. return;
  1515. }
  1516. else
  1517. {
  1518. LogHelper.addLog(tid, 0, "补差价发货-" + comCode + "-" + outSid);
  1519. }
  1520. }
  1521. }
  1522. public static int StrCount(string str, string constr)
  1523. {
  1524. return System.Text.RegularExpressions.Regex.Matches(str, constr).Count;
  1525. }
  1526. public static void saveErpDesignerGather()
  1527. {
  1528. string date1 = DateTime.Now.AddDays(-1).ToString();
  1529. string date2 = DateTime.Now.AddDays(-1).ToString();
  1530. //string date1 = DateTime.Now.ToString();
  1531. //string date2 = DateTime.Now.ToString();
  1532. StringBuilder sql = new StringBuilder();
  1533. sql.AppendFormat("select ID from view_ErpUser where (PostCode = 'Designer' or PostCode = 'DesignerMr'or PostCode = 'Designerhd' or PostCode = 'wxDesigner' or PostCode='wxDesignerMr') and isOpen = 1 and ID not in(select did from CE_ErpDesignerFinishRate where DATEDIFF(day, '{0}', CTime) = 0)", date1);
  1534. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1535. foreach (DataRow dr in dt.Rows)
  1536. {
  1537. SqlParameter[] sqlParameter ={
  1538. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  1539. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  1540. new SqlParameter("@designid", SqlDbType.Int, 4)
  1541. };
  1542. sqlParameter[0].Value = date1;
  1543. sqlParameter[1].Value = date2;
  1544. sqlParameter[2].Value = Convert.ToInt32(dr["ID"]);
  1545. //CeErpTradeCell.ExecuteNonQueryStore("sp_getdesigngather", sqlParameter);
  1546. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_savedesigngather", sqlParameter);
  1547. }
  1548. new_Designer_Rate(date1);
  1549. }
  1550. public static void new_Designer_Rate(String date1)
  1551. {
  1552. /*String date1 = DateTime.Now.ToString();*/
  1553. /* if (date1 ==null) {
  1554. date1 = DateTime.Now.ToString();
  1555. }*/
  1556. DateTime currentDate = DateTime.Parse(date1);
  1557. // 获取指定日期的开始时间
  1558. DateTime startTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 0, 0, 0);//日
  1559. // 获取指定日期的结束时间(即下一天的开始时间,减去1秒)
  1560. DateTime endTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 23, 59, 59).AddSeconds(-1);//日
  1561. DateTime now = DateTime.Now; // 获取当前日期和时间
  1562. DateTime dateOnly = now.Date; // 限制日期为年月日
  1563. StringBuilder sql = new StringBuilder();
  1564. CeErpDesignerFinishRateNew.Del(startTime.ToString("yyyy-MM-dd HH:mm:ss"));
  1565. sql.AppendFormat("\t\tSELECT\r\n A.DesignUserId,\r\n B.OrgID,\r\n B.Name AS DesignerName,\r\nCOUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' and A.IsRefund ='2' THEN 1 END) AS refund, SUM(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' THEN A.payment ELSE 0 END) AS Amount,\r\n COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' and A.ctid NOT LIKE 'C%' and A.ctid NOT LIKE 'S%' THEN 1 END) AS AllOrder,\r\n COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' AND A.OrderState ='3' THEN 1 END) AS WaitDesign,\r\n COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' AND A.OrderState ='4' THEN 1 END) AS Designing,\r\n COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' AND A.OrderState >='5' THEN 1 END) AS DesignFinish,\r\n COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) = CONVERT(date, A.FinishDesignTime) AND CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' and A.ctid NOT LIKE 'C%' and A.ctid NOT LIKE 'S%' THEN 1 END) AS FinalizationRate,\r\n (SELECT COUNT(*) FROM CE_ErpTradeCell WHERE ctid LIKE 'S%' AND WaitDesignTime BETWEEN '{0}' AND '{1}' and DesignUserId =A.DesignUserId) AS afterSaleSum,\r\n\t\t(SELECT COUNT(tid) \r\n FROM CE_ErpTradeCell \r\n WHERE ctid LIKE 'C%' \r\n AND WaitDesignTime BETWEEN '{0}' AND '{1}' \r\n AND DesignUserId = A.DesignUserId) AS resolutionSum,\r\n\t\t \t(SELECT COUNT(DISTINCT tid) \r\n FROM CE_ErpTradeCell \r\n WHERE ctid LIKE 'C%' \r\n AND WaitDesignTime BETWEEN '{0}' AND '{1}' \r\n AND DesignUserId = A.DesignUserId and FinishDesignTime BETWEEN '{0}' AND '{1}') AS splitSum,\r\n\t\t \t \t(SELECT COUNT(DISTINCT tid) \r\n FROM CE_ErpTradeCell \r\n WHERE ctid LIKE 'C%' \r\n AND WaitDesignTime BETWEEN '{0}' AND '{1}' \r\n AND DesignUserId = A.DesignUserId ) AS splitSum2 ,COUNT(CASE WHEN CONVERT(date, A.WaitDesignTime) = CONVERT(date, A.FinishDesignTime) AND CONVERT(date, A.WaitDesignTime) BETWEEN '{0}' AND '{1}' and A.ctid LIKE 'C%' THEN 1 END) AS FinalizationRate2 \r\nFROM\r\n dbo.CE_ErpTradeCell AS A\r\n LEFT OUTER JOIN dbo.view_ErpUser AS B ON A.DesignUserId = B.ID\r\nWHERE\r\n b.state = '0' and a.IsSample!=2\r\nGROUP BY\r\n A.DesignUserId, B.OrgID, B.Name\r\nORDER BY\r\n Amount DESC;", startTime.ToString("yyyy-MM-dd HH:mm:ss"), endTime.ToString("yyyy-MM-dd HH:mm:ss"));
  1566. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1567. foreach (DataRow dr in dt.Rows)
  1568. {
  1569. CeErpDesignerFinishRateNew ceErpDesignerFinishRateNew = new CeErpDesignerFinishRateNew();
  1570. if (!Convert.IsDBNull(dr["DesignUserId"]))
  1571. {
  1572. ceErpDesignerFinishRateNew.did = Convert.ToInt32(dr["DesignUserId"] == null ? 0 : dr["DesignUserId"]);
  1573. }
  1574. if (!Convert.IsDBNull(dr["OrgID"]))
  1575. {
  1576. ceErpDesignerFinishRateNew.orgid = Convert.ToInt32(dr["OrgID"] == null ? 0 : dr["OrgID"]);
  1577. }
  1578. if (!Convert.IsDBNull(dr["DesignerName"]))
  1579. {
  1580. ceErpDesignerFinishRateNew.name = dr["DesignerName"].ToString() == null ? "" : dr["DesignerName"].ToString();
  1581. }
  1582. if (!Convert.IsDBNull(dr["Amount"]))
  1583. {
  1584. ceErpDesignerFinishRateNew.Amount = dr["Amount"].ToString() == null ? "" : dr["Amount"].ToString();
  1585. }
  1586. if (!Convert.IsDBNull(dr["AllOrder"]))
  1587. {
  1588. ceErpDesignerFinishRateNew.AllOrder = Convert.ToInt32(dr["AllOrder"] == null ? 0 : dr["AllOrder"]);
  1589. }
  1590. if (!Convert.IsDBNull(dr["FinalizationRate"]))
  1591. {
  1592. ceErpDesignerFinishRateNew.FinalizationRate = Convert.ToInt32(dr["FinalizationRate"] == null ? 0 : dr["FinalizationRate"]);
  1593. }
  1594. if (!Convert.IsDBNull(dr["afterSaleSum"]))
  1595. {
  1596. ceErpDesignerFinishRateNew.afterSaleSum = Convert.ToInt32(dr["afterSaleSum"] == null ? 0 : dr["afterSaleSum"]);
  1597. }
  1598. if (!Convert.IsDBNull(dr["resolutionSum"]))
  1599. {
  1600. ceErpDesignerFinishRateNew.resolutionSum = Convert.ToInt32(dr["resolutionSum"] == null ? 0 : dr["resolutionSum"]);
  1601. }
  1602. if (!Convert.IsDBNull(dr["splitSum"]))
  1603. {
  1604. ceErpDesignerFinishRateNew.splitSum = Convert.ToInt32(dr["splitSum"] == null ? 0 : dr["splitSum"]);
  1605. }
  1606. if (!Convert.IsDBNull(dr["splitSum2"]))
  1607. {
  1608. ceErpDesignerFinishRateNew.csplitum = Convert.ToInt32(dr["splitSum2"] == null ? 0 : dr["splitSum2"]);
  1609. }
  1610. if (!Convert.IsDBNull(dr["FinalizationRate2"]))
  1611. {
  1612. ceErpDesignerFinishRateNew.FinalizationRate2 = Convert.ToInt32(dr["FinalizationRate2"] == null ? 0 : dr["FinalizationRate2"]);
  1613. }
  1614. if (!Convert.IsDBNull(dr["AllOrder"]) && !Convert.IsDBNull(dr["FinalizationRate"]) && !Convert.IsDBNull(dr["splitSum2"]) && !Convert.IsDBNull(dr["splitSum"]))
  1615. {
  1616. try
  1617. {
  1618. int num1 = Convert.ToInt32(dr["FinalizationRate"]) + Convert.ToInt32(dr["splitSum"]);
  1619. int num2 = Convert.ToInt32(dr["AllOrder"]) + Convert.ToInt32(dr["splitSum2"]);
  1620. if (num2 != 0)
  1621. {
  1622. double result = (double)num1 / num2;
  1623. if (double.IsNaN(result))
  1624. {
  1625. result = 0;
  1626. }
  1627. double roundedResult = Math.Round(result, 4);
  1628. ceErpDesignerFinishRateNew.onFinalizationRate = roundedResult.ToString();
  1629. int num3 = Convert.ToInt32(dr["refund"]);
  1630. double result2 = (double)num3 / num2;
  1631. if (double.IsNaN(result2))
  1632. {
  1633. result2 = 0;
  1634. }
  1635. double roundedResult2 = Math.Round(result2, 4);
  1636. ceErpDesignerFinishRateNew.onRefund = roundedResult2.ToString();
  1637. }
  1638. else
  1639. {
  1640. ceErpDesignerFinishRateNew.onFinalizationRate = "0.0000";
  1641. ceErpDesignerFinishRateNew.onRefund = "0.0000";
  1642. }
  1643. }
  1644. catch (Exception ex)
  1645. {
  1646. ceErpDesignerFinishRateNew.onFinalizationRate = "0";
  1647. }
  1648. }
  1649. ceErpDesignerFinishRateNew.ctime = startTime;
  1650. ceErpDesignerFinishRateNew.Createtime = now;
  1651. if (!Convert.IsDBNull(dr["refund"]))
  1652. {
  1653. ceErpDesignerFinishRateNew.refund = Convert.ToInt32(dr["refund"] == null ? 0 : dr["refund"]);
  1654. }
  1655. ceErpDesignerFinishRateNew.Create();
  1656. }
  1657. }
  1658. public static DateTime FirstDayOfMonth(DateTime datetime)
  1659. {
  1660. return datetime.AddDays(1 - datetime.Day);
  1661. }
  1662. public static DateTime LastDayOfMonth(DateTime datetime)
  1663. {
  1664. return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
  1665. }
  1666. public static DateTime GetDateTimeWeekFirstDaySun(DateTime dateTime)
  1667. {
  1668. DateTime firstWeekDay = DateTime.Now;
  1669. try
  1670. {
  1671. //得到是星期几,然后从当前日期减去相应天数
  1672. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1673. int daydiff = (-1) * weeknow;
  1674. firstWeekDay = dateTime.AddDays(daydiff);
  1675. }
  1676. catch { }
  1677. return firstWeekDay;
  1678. }
  1679. public static DateTime GetDateTimeWeekFirstDayMon(DateTime dateTime)
  1680. {
  1681. DateTime firstWeekDay = DateTime.Now;
  1682. try
  1683. {
  1684. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1685. //星期一为第一天,weeknow等于0时,要向前推6天。
  1686. weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1));
  1687. int daydiff = (-1) * weeknow;
  1688. firstWeekDay = dateTime.AddDays(daydiff);
  1689. }
  1690. catch { }
  1691. return firstWeekDay;
  1692. }
  1693. public static DateTime GetDateTimeWeekLastDaySat(DateTime dateTime)
  1694. {
  1695. DateTime lastWeekDay = DateTime.Now;
  1696. try
  1697. {
  1698. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1699. int daydiff = (7 - weeknow) - 1;
  1700. lastWeekDay = dateTime.AddDays(daydiff);
  1701. }
  1702. catch { }
  1703. return lastWeekDay;
  1704. }
  1705. public static DateTime GetDateTimeWeekLastDaySun(DateTime dateTime)
  1706. {
  1707. DateTime lastWeekDay = DateTime.Now;
  1708. try
  1709. {
  1710. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1711. weeknow = (weeknow == 0 ? 7 : weeknow);
  1712. int daydiff = (7 - weeknow);
  1713. lastWeekDay = dateTime.AddDays(daydiff);
  1714. }
  1715. catch { }
  1716. return lastWeekDay;
  1717. }
  1718. public static void updateOrderStateForShipped(string ctid, int ost, string stateType)
  1719. {
  1720. try
  1721. {
  1722. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  1723. if (entity != null)
  1724. {
  1725. if (entity.isAfterSaleOrder == 1) return;
  1726. if (stateType == "updatestate_complete")
  1727. {
  1728. if (entity.IsPreDelivery == 1) return;
  1729. entity.OrderState = 8;
  1730. entity.Update();
  1731. if (entity.ProductId == 9 || entity.ProductId == 17 || entity.ProductId == 20 || entity.ProductId == 29 || entity.ProductId == 30)//卡片、手提袋价格自动核算
  1732. {
  1733. CeErpDesignerBill.updateDesignerBill(entity.ctid, entity.ProductId);
  1734. LogHelper.addDesignerBillLog(entity.ctid, 0, "自动核算设计费", "系统", 1);
  1735. }
  1736. else if (entity.ProductId == 22)
  1737. {
  1738. CeErpDesignerBill.updateBill(entity.ctid, entity.ProductId, entity.seller_memo);
  1739. LogHelper.addDesignerBillLog(entity.ctid, 0, "自动核算设计费", "系统", 1);
  1740. }
  1741. }
  1742. else if (stateType == "updatestate_shipped")
  1743. {
  1744. if (entity.IsPreDelivery == 1) return;
  1745. entity.OrderState = 7;
  1746. entity.Update();
  1747. }
  1748. else if (stateType == "updatestate_close")
  1749. {
  1750. entity.OrderState = 9;
  1751. entity.Update();
  1752. }
  1753. }
  1754. else
  1755. {
  1756. StringBuilder sql = new StringBuilder();
  1757. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{0}',{1},'{2}',getdate());", ctid, ost, stateType);
  1758. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1759. }
  1760. }
  1761. catch (Exception ex)
  1762. {
  1763. XLog.SaveLog(0, "updateOrderStateForShipped函数出错," + ctid + "," + ex.Message);
  1764. StringBuilder sql = new StringBuilder();
  1765. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{0}',{1},'{2}',getdate());", ctid, ost, stateType);
  1766. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1767. }
  1768. }
  1769. public static string changeCountFromChiness(string countStr)
  1770. {
  1771. try
  1772. {
  1773. return handleProductCount(countStr).ToString();
  1774. }
  1775. catch (Exception ex)
  1776. {
  1777. return countStr;
  1778. }
  1779. }
  1780. public static int getIntCountFromString(string fstr)
  1781. {
  1782. try
  1783. {
  1784. string str = fstr;
  1785. string r = @"[0-9]+";
  1786. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1787. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1788. int count = 0;
  1789. foreach (Match m in mc)
  1790. {
  1791. string s = m.Groups[0].Value;
  1792. int cc = Convert.ToInt32(s);
  1793. if (count == 0)
  1794. {
  1795. count = cc;
  1796. }
  1797. else
  1798. {
  1799. count = count * cc;
  1800. }
  1801. }
  1802. return count;
  1803. }
  1804. catch (Exception ex)
  1805. {
  1806. return 0;
  1807. }
  1808. }
  1809. public static int getPlaceProductCount(string count_str)
  1810. {
  1811. count_str = count_str.Trim();
  1812. string[] count_list = count_str.Split(',');
  1813. int count = 0;
  1814. foreach (string item in count_list)
  1815. {
  1816. int tem_count = getSingleIntCountFromString(item);
  1817. if (tem_count > count)
  1818. {
  1819. count = tem_count;
  1820. }
  1821. }
  1822. return count;
  1823. }
  1824. public static int getSingleIntCountFromString(string fstr)
  1825. {
  1826. try
  1827. {
  1828. string str = fstr;
  1829. string r = @"[0-9]+";
  1830. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1831. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1832. if (mc.Count <= 0) return 0;
  1833. if (mc.Count == 1)
  1834. {
  1835. string s = mc[0].Groups[0].Value;
  1836. int cc = Convert.ToInt32(s);
  1837. return cc;
  1838. }
  1839. else if (mc.Count > 1)
  1840. {
  1841. string s = mc[1].Groups[0].Value;
  1842. int cc = Convert.ToInt32(s);
  1843. return cc;
  1844. }
  1845. //foreach (Match m in mc)
  1846. //{
  1847. // string s = m.Groups[0].Value;
  1848. // int cc = Convert.ToInt32(s);
  1849. // if (count == 0)
  1850. // {
  1851. // count = cc;
  1852. // }
  1853. // else
  1854. // {
  1855. // count = count * cc;
  1856. // }
  1857. //}
  1858. return 0;
  1859. }
  1860. catch (Exception ex)
  1861. {
  1862. return 0;
  1863. }
  1864. }
  1865. public static int handleProductCount(string pCount, bool isSingle = false)
  1866. {
  1867. string cstr = pCount;
  1868. if (cstr.IndexOf("百万") != -1)
  1869. {
  1870. cstr = cstr.Replace("百万", "000000");
  1871. }
  1872. else if (cstr.IndexOf("十万") != -1)
  1873. {
  1874. cstr = cstr.Replace("十万", "00000");
  1875. }
  1876. else if (cstr.IndexOf("万") != -1)
  1877. {
  1878. cstr = cstr.Replace("万", "0000");
  1879. }
  1880. else if (cstr.IndexOf("千") != -1)
  1881. {
  1882. cstr = cstr.Replace("千", "000");
  1883. }
  1884. else if (cstr.IndexOf("百") != -1)
  1885. {
  1886. cstr = cstr.Replace("百", "00");
  1887. }
  1888. else if (cstr.IndexOf("十") != -1)
  1889. {
  1890. cstr = cstr.Replace("十", "0");
  1891. }
  1892. int rCount = 0;
  1893. if (isSingle) rCount = getSingleIntCountFromString(cstr);
  1894. else rCount = getIntCountFromString(cstr);
  1895. return rCount;
  1896. }
  1897. public static decimal getOrderSizeFromString(string size)
  1898. {
  1899. string rsize = size.Replace("mm", "");
  1900. string[] sizeList = rsize.Split('x');
  1901. if (sizeList.Length != 2) return 0;
  1902. try
  1903. {
  1904. decimal mianji = Convert.ToDecimal(sizeList[0]) * Convert.ToDecimal(sizeList[1]);
  1905. return mianji;
  1906. }
  1907. catch (Exception ex)
  1908. {
  1909. return 0;
  1910. }
  1911. return 0;
  1912. }
  1913. public static string getDateFromString(string fstr)
  1914. {
  1915. try
  1916. {
  1917. string str = fstr;
  1918. string r = @"[0-9]+";
  1919. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1920. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1921. if (mc.Count < 3) return "";
  1922. int tag = 0;
  1923. string datestr = "";
  1924. foreach (Match m in mc)
  1925. {
  1926. string s = m.Groups[0].Value;
  1927. datestr += s;
  1928. if (tag < 2) { datestr += "-"; }
  1929. else break;
  1930. tag++;
  1931. }
  1932. DateTime dd = Convert.ToDateTime(datestr);
  1933. return datestr;
  1934. }
  1935. catch (Exception ex)
  1936. {
  1937. return "";
  1938. }
  1939. }
  1940. public static void DeleteOriginalOrderIfIsSplitOrder(string tid, string splitTag)
  1941. {
  1942. if (splitTag.Length > 0)
  1943. {
  1944. CeErpTradeCell.DelByCtid(tid);
  1945. }
  1946. }
  1947. public static bool SetOrderDummyDelivery(string tid)
  1948. {
  1949. try
  1950. {
  1951. CeErpTrade trade = CeErpTrade.Get(tid);
  1952. if (trade != null)
  1953. {
  1954. string xuniapires = apiHelper.API_LogisticsDummySend(tid, trade.posCode);
  1955. if (xuniapires.IndexOf("成功") != -1)
  1956. {
  1957. LogHelper.addLog(tid, 0, "电子稿自动发货");
  1958. return true;
  1959. }
  1960. else if (xuniapires.IndexOf("失败") != -1)
  1961. {
  1962. string chiness = KeepChinese(xuniapires);
  1963. XLog.SaveLog(0, "setOrderDummyDelivery虚拟发货失败," + tid + "," + chiness);
  1964. return false;
  1965. }
  1966. }
  1967. return false;
  1968. }
  1969. catch (Exception ex)
  1970. {
  1971. XLog.SaveLog(0, "setOrderDummyDelivery虚拟发货出错," + tid + "," + ex.Message);
  1972. return false;
  1973. }
  1974. }
  1975. public static void getuserId()
  1976. {
  1977. string createtime = "2024-01-01 00:50:39.000";
  1978. string textContent = "";
  1979. int row_num = 100;
  1980. Dictionary<string, List<string>> shop_userNick = new Dictionary<string, List<string>>();
  1981. while (row_num == 100)
  1982. {
  1983. string conSql = string.Format("SELECT TOP 100 posCode, buyer_nick,pay_time FROM [dbo].[CE_ErpTrade] WHERE pay_time > '{0}' AND ( buyer_id IS NULL OR buyer_id = '' ) AND posCode != '' AND buyer_nick != '' ORDER By pay_time ASC", createtime);
  1984. DataTable table = DbHelper.DbConn.ExecuteDataset(conSql).Tables[0];
  1985. if (table != null)
  1986. {
  1987. row_num = table.Rows.Count;
  1988. foreach (DataRow row in table.Rows)
  1989. {
  1990. string posCode = row["posCode"].ToString();
  1991. string buyer_nick = row["buyer_nick"].ToString();
  1992. createtime = row["pay_time"].ToString();
  1993. List<string> userNickName = new List<string>();
  1994. if (shop_userNick.ContainsKey(posCode))
  1995. {
  1996. shop_userNick.TryGetValue(posCode, out userNickName);
  1997. }
  1998. userNickName.Add(buyer_nick);
  1999. userNickName = userNickName.Distinct().ToList();
  2000. if (userNickName.Count == 10)
  2001. {
  2002. sendApi(posCode, userNickName);
  2003. userNickName = new List<string>();
  2004. }
  2005. if (shop_userNick.ContainsKey(posCode))
  2006. {
  2007. shop_userNick[posCode] = userNickName;
  2008. }
  2009. else
  2010. {
  2011. shop_userNick.Add(posCode, userNickName);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. foreach (string key in shop_userNick.Keys)
  2017. {
  2018. List<string> nameList = shop_userNick[key];
  2019. sendApi(key, nameList);
  2020. }
  2021. }
  2022. static void sendApi(string posCode, List<string> userNickName)
  2023. {
  2024. string textContent = "";
  2025. List<api_userId_response.ContentItem> buyerIds = apiHelper.API_GetUserId(posCode, string.Join(",", userNickName));
  2026. if (buyerIds != null && buyerIds.Count > 0)
  2027. {
  2028. foreach (api_userId_response.ContentItem item in buyerIds)
  2029. {
  2030. if (item != null && !string.IsNullOrEmpty(item.buyerOpenUid))
  2031. {
  2032. textContent += string.Format("update [dbo].[CE_ErpTrade] set buyer_id='{2}' WHERE posCode='{0}' and buyer_nick='{1}';\r\n", posCode, item.buyerNick, item.buyerOpenUid);
  2033. }
  2034. }
  2035. try
  2036. {
  2037. StreamWriter fs = new StreamWriter("C:/Users/231010/Desktop/updateSql.txt", true);
  2038. fs.WriteLine(textContent);
  2039. fs.Close();
  2040. }
  2041. catch (Exception e)
  2042. {
  2043. }
  2044. }
  2045. }
  2046. public static designApiResponseVo checkOrderListDesignInfo(string tid, string ctid = "")
  2047. {
  2048. if (string.IsNullOrEmpty(tid))
  2049. {
  2050. return new designApiResponseVo(-1, "无订单信息");
  2051. }
  2052. if (!string.IsNullOrEmpty(ctid))
  2053. {
  2054. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  2055. if (ceErpTradeCellExtend != null)
  2056. {
  2057. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  2058. {
  2059. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  2060. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2061. return new designApiResponseVo(200, "");
  2062. }
  2063. if ("内部".Equals(ceErpTradeCellExtend.ToType))
  2064. {
  2065. return new designApiResponseVo(-1, "设计系统判断内部");
  2066. }
  2067. }
  2068. }
  2069. string info_sql = string.Format("SELECT ctid,ProductId,seller_memo FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}' AND OrderState < 5", tid);
  2070. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2071. string check_info = "无订单信息";
  2072. if (data.Rows.Count > 0)
  2073. {
  2074. bool need_send = false;
  2075. bool has_design = false;
  2076. foreach (DataRow row in data.Rows)
  2077. {
  2078. CeErpTradeCell cell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  2079. if (cell != null)
  2080. {
  2081. if (cell.DesignUserId == 0 || cell.DispatchSort == 2 || cell.ctid.Contains("S_"))
  2082. {
  2083. designApiResponseVo result = checkOrderDesignInfo(cell, "", data);
  2084. check_info = result.msg;
  2085. if (result.code == 200)
  2086. {
  2087. need_send = true;
  2088. has_design = false;
  2089. }
  2090. }
  2091. else
  2092. {
  2093. has_design = true;
  2094. }
  2095. }
  2096. }
  2097. if (need_send && !has_design)
  2098. {
  2099. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "' AND OrderState < 5;";
  2100. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2101. return new designApiResponseVo(200, "");
  2102. }
  2103. }
  2104. return new designApiResponseVo(-1, check_info);
  2105. }
  2106. static List<int> products = new List<int>() { 29, 2489, 2517, 2518, 2519, 2520, 2533, 2534, 2558, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599, 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2634, 2644, 2645, 2646, 2648, 2649, 2650 };
  2107. static List<int> shops = new List<int>() { 2, 77, 121, 122, 65, 87, 26, 45, 17, 21, 52, 54, 103, 107, 108, 109, 118, 63, 64, 66, 49, 67, 105, 35, 57, 29, 53, 62, 134 };
  2108. static List<int> no_design_shops = new List<int>() { 134 };
  2109. public static designApiResponseVo checkOrderDesignInfo(CeErpTradeCell ceErpTradeCell, string post = "", DataTable dt = null)
  2110. {
  2111. if (ceErpTradeCell.DispatchSort == 2)
  2112. {
  2113. return new designApiResponseVo(200, "");
  2114. }
  2115. if (ceErpTradeCell.ProductId == 0)
  2116. {
  2117. return new designApiResponseVo(-1, "订单无品类");
  2118. }
  2119. if (ceErpTradeCell.ShopId == 0)
  2120. {
  2121. return new designApiResponseVo(-1, "订单无店铺");
  2122. }
  2123. if (ceErpTradeCell.ProductId == 1797 && ceErpTradeCell.seller_memo.Contains("手绘"))
  2124. {
  2125. return new designApiResponseVo(200, "");
  2126. }
  2127. if (ceErpTradeCell.isDianziOrder == 1)
  2128. {
  2129. return new designApiResponseVo(200, "");
  2130. }
  2131. if ((post != "SysAdmin" && post != "Summarize"))
  2132. {
  2133. if (ceErpTradeCell.DesignUserId != 0 && (ceErpTradeCell.DispatchSort != 2 && !ceErpTradeCell.ctid.Contains("S_")))
  2134. {
  2135. return new designApiResponseVo(-1, "已有设计师无法指派");
  2136. }
  2137. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  2138. if (ceErpTradeCellExtend != null && "内部".Equals(ceErpTradeCellExtend.ToType))
  2139. {
  2140. return new designApiResponseVo(-1, "无法指派不是共创的订单");
  2141. }
  2142. string info_sql = string.Format("SELECT count(*) as total FROM [dbo].[Ce_ErpDesignInfo] WHERE type = 1 and tarId = 3542 and shopId = {0}", ceErpTradeCell.ShopId);
  2143. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2144. int a = Convert.ToInt32(data.Rows[0]["total"]);
  2145. bool drop = false;
  2146. if (DateTime.Now.Hour >= 17 && DateTime.Now.Hour <= 7 && products.IndexOf(ceErpTradeCell.ProductId) > -1 && (ceErpTradeCell.ShopId == 14 || ceErpTradeCell.ShopId == 56))
  2147. {
  2148. drop = false;
  2149. }
  2150. if (!drop && no_design_shops.IndexOf(ceErpTradeCell.ShopId) == -1)
  2151. {
  2152. CeErpDesignInfo ceErpDesignInfo = CeErpDesignInfo.GetByShopDesign(3542, ceErpTradeCell.ShopId, ceErpTradeCell.ProductId);
  2153. if (ceErpDesignInfo == null)
  2154. {
  2155. return new designApiResponseVo(-1, "该店铺无该技能权限");
  2156. }
  2157. }
  2158. //卡片五款
  2159. /*if (products.IndexOf(ceErpTradeCell.ProductId) > -1 && ceErpTradeCell.ShopId > 0)
  2160. {
  2161. bool num_bool = true;
  2162. bool size_bool = false;
  2163. int min_num = 2;
  2164. int num = 0;
  2165. if (shops.IndexOf(ceErpTradeCell.ShopId) == -1)//限制不是全品的店铺限制
  2166. {
  2167. *//*if (ceErpTradeCell.payment >= 500)
  2168. {
  2169. return new designApiResponseVo(-1, "订单价格超出");
  2170. }*//*
  2171. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  2172. string memo = ceErpTradeCell.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  2173. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  2174. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  2175. string size = "";
  2176. double min_width = 90;
  2177. double min_height = 90;
  2178. double width = 0;
  2179. double height = 0;
  2180. try
  2181. {
  2182. num = matches.Count;
  2183. foreach (System.Text.RegularExpressions.Match match in matches)
  2184. {
  2185. if (match.Success)
  2186. {
  2187. size = match.Groups[0].Value;
  2188. if (size.Contains("cm"))
  2189. {
  2190. size = size.Replace("cm", "");
  2191. string[] size_list = size.Split('x');
  2192. if (size_list.Length > 1)
  2193. {
  2194. width = Convert.ToDouble(size_list[0]) * 10;
  2195. height = Convert.ToDouble(size_list[1]) * 10;
  2196. }
  2197. }
  2198. else if (size.Contains("mm"))
  2199. {
  2200. size = size.Replace("mm", "");
  2201. string[] size_list = size.Split('x');
  2202. if (size_list.Length > 1)
  2203. {
  2204. width = Convert.ToDouble(size_list[0]);
  2205. height = Convert.ToDouble(size_list[1]);
  2206. }
  2207. }
  2208. if (width >= min_width && height >= min_height && height >= min_width && width >= min_height)
  2209. {
  2210. size_bool = true;
  2211. break;
  2212. }
  2213. else
  2214. {
  2215. size_bool = false;
  2216. }
  2217. }
  2218. }
  2219. }
  2220. catch (Exception ex)
  2221. {
  2222. }
  2223. num = getSellerMemoNum(ceErpTradeCell.seller_memo);
  2224. if (dt != null && dt.Rows != null && dt.Rows.Count > 1)
  2225. {
  2226. foreach (DataRow item in dt.Rows)
  2227. {
  2228. int tempNum = 0;
  2229. if (!string.IsNullOrEmpty(item["ProductId"].ToString()))
  2230. {
  2231. if (Convert.ToInt32(item["ProductId"]) == ceErpTradeCell.ProductId)
  2232. {
  2233. tempNum = getSellerMemoNum(item["seller_memo"].ToString());
  2234. tempNum = tempNum == 0 ? 1 : tempNum;
  2235. }
  2236. }
  2237. num += tempNum;
  2238. }
  2239. }
  2240. //2款不进
  2241. if (num < min_num)
  2242. {
  2243. num_bool = false;
  2244. }
  2245. if (!num_bool && !size_bool)
  2246. {
  2247. return new designApiResponseVo(-1, "尺寸小于90x90或款数小于2");
  2248. }
  2249. }
  2250. }*/
  2251. }
  2252. return new designApiResponseVo(200, "");
  2253. }
  2254. private static int getSellerMemoNum(string memo)
  2255. {
  2256. int num = 0;
  2257. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  2258. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  2259. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  2260. if (memo.Contains("刮刮"))
  2261. {
  2262. num = Math.Max(num - 1, 1);
  2263. }
  2264. pattern = @"(\d+)款";
  2265. matches = Regex.Matches(memo, pattern);
  2266. try
  2267. {
  2268. num = Math.Max(num - matches.Count, 0);
  2269. foreach (System.Text.RegularExpressions.Match match in matches)
  2270. {
  2271. if (match.Success)
  2272. {
  2273. num += Convert.ToInt32(match.Groups[1].Value);
  2274. break;
  2275. }
  2276. }
  2277. }
  2278. catch (Exception ex)
  2279. {
  2280. }
  2281. return num;
  2282. }
  2283. private static string cytUserId = "77886";
  2284. public static void sendCytAfterSale(CeErpTradeCell entity)
  2285. {
  2286. try
  2287. {
  2288. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  2289. string after = "";
  2290. if (entity != null && entity.AfterSaleReason.Contains("质量问题"))
  2291. {
  2292. after = "质量问题";
  2293. }
  2294. else if (entity != null && entity.AfterSaleReason.Contains("发货问题"))
  2295. {
  2296. after = "没收到货";
  2297. }
  2298. else
  2299. {
  2300. after = "其他问题";
  2301. }
  2302. string refund_type = "退款退货";
  2303. if (entity.supRefundType != null && entity.supRefundType == "重印" && (after == "质量问题" || after == "其他问题"))
  2304. {
  2305. refund_type = "补印";
  2306. }
  2307. JObject jsonObject12 = new JObject
  2308. {
  2309. { "Userid",cytUserId },
  2310. //{ "pwd", "lt666888" },
  2311. { "LTOrderId", entity.ctid },
  2312. { "IdCode", entity.OrderSn },
  2313. { "CytMallId", string.IsNullOrEmpty(entity.SupplierOrderSn) ? "" : entity.SupplierOrderSn},
  2314. { "RefundType", refund_type },
  2315. { "ReprintReasons", after },
  2316. { "ReasonsImgUrls", entity.AfterSaleSupplierImg },
  2317. { "ReasonRemarks", ceErpTradeAfterSaleExtend.supplierResponsible },
  2318. { "RefundAmount", entity.DeductFee }
  2319. };
  2320. /**JObject jsonObject12 = new JObject
  2321. {
  2322. { "Userid", "10095" },
  2323. { "pwd", "test123456" },
  2324. { "LTOrderId", "test123456" },
  2325. { "RefundType", "退款退货" },
  2326. { "ReprintReasons", "其他问题" },
  2327. { "ReasonRemarks", "测试" }
  2328. };**/
  2329. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/ApplyOrderRefund", jsonObject12.ToString());
  2330. JObject jsonObjects1 = JObject.Parse(response1);
  2331. string msg = (string)jsonObjects1["msg"];
  2332. if (msg.Length > 200)
  2333. {
  2334. msg = msg.Substring(0, 200);
  2335. }
  2336. LogHelper.addLog(entity.ctid, 0, "CYT售后单推送:" + msg);
  2337. }
  2338. catch (Exception ex)
  2339. {
  2340. XLog.SaveLog(0, "CYT售后单推送:" + ex);
  2341. }
  2342. }
  2343. public static void sendCytExpress(CeErpExpressInfo exinfo)
  2344. {
  2345. if (exinfo == null)
  2346. {
  2347. return;
  2348. }
  2349. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(exinfo.tid);
  2350. if (ceErpTradeCell == null)
  2351. {
  2352. return;
  2353. }
  2354. string msg = "";
  2355. try
  2356. {
  2357. JObject jsonObject12 = new JObject
  2358. {
  2359. { "Userid",cytUserId },
  2360. //{ "pwd", "lt666888" },
  2361. { "LTOrderId", ceErpTradeCell.OrderSn },
  2362. { "OrderId", ceErpTradeCell.ctid },
  2363. { "CourierNumber", exinfo.out_sid },
  2364. { "ExpressCompanyName", exinfo.company_name }
  2365. };
  2366. string response1 = HttpPost("http://www.kiy.cn/webapi/Himall.NewShop.UpdOrderExpress", jsonObject12.ToString());
  2367. JObject jsonObjects1 = JObject.Parse(response1);
  2368. msg = (string)jsonObjects1["msg"];
  2369. LogHelper.addLog(exinfo.tid, 0, "CYT打单推送:" + msg);
  2370. }
  2371. catch (Exception ex)
  2372. {
  2373. LogHelper.addLog(exinfo.tid, 0, "CYT打单推送:" + ceErpTradeCell.OrderSn + "," + ceErpTradeCell.ctid + "," + exinfo.out_sid + "," + exinfo.company_name);
  2374. XLog.SaveLog(0, "CYT打单推送失败," + msg + "->" + ex);
  2375. }
  2376. }
  2377. public static void getCytPrice(CeErpTradeCell entity)
  2378. {
  2379. try
  2380. {
  2381. if (entity.seller_memo.IndexOf("种子纸") > -1)
  2382. {
  2383. return;
  2384. }
  2385. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  2386. double price = 0;
  2387. if (cp == null)
  2388. {
  2389. JObject jsonObject12 = new JObject
  2390. {
  2391. { "UserId", cytUserId },
  2392. { "Pwd", "lt666888" },
  2393. { "Filename", entity.seller_memo }
  2394. };
  2395. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  2396. JObject jsonObjects1 = JObject.Parse(response1);
  2397. string ms1g = (string)jsonObjects1["msg"];
  2398. if (ms1g == "报价成功")
  2399. {
  2400. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  2401. string data = (string)jsonObject1["price"];
  2402. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  2403. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2404. price = Convert.ToDouble(data);
  2405. }
  2406. else
  2407. {
  2408. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + response1 + "');";
  2409. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2410. return;
  2411. }
  2412. }
  2413. String[] beizhu = entity.seller_memo.Split('-');
  2414. String chanp = "";
  2415. if (beizhu.Length > 1)
  2416. {
  2417. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  2418. }
  2419. else
  2420. {
  2421. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  2422. }
  2423. JObject jsonObject = new JObject
  2424. {
  2425. { "UserId", cytUserId },
  2426. { "Pwd", "lt666888" },
  2427. { "Filename", chanp }
  2428. };
  2429. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  2430. JObject jsonObjects = JObject.Parse(response);
  2431. string msg = (string)jsonObjects["msg"];
  2432. if (msg == "报价成功")
  2433. {
  2434. JObject jsonObject1 = (JObject)jsonObjects["data"];
  2435. string data = (string)jsonObject1["price"];
  2436. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  2437. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2438. price = Convert.ToDouble(data);
  2439. }
  2440. else
  2441. {
  2442. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + response + "');";
  2443. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2444. return;
  2445. }
  2446. if (price > 0)
  2447. {
  2448. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2449. if (ceErpTradeCellExtend == null)
  2450. {
  2451. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2452. ceErpTradeCellExtend.ctid = entity.ctid;
  2453. ceErpTradeCellExtend.payment_cyt = price;
  2454. ceErpTradeCellExtend.Create();
  2455. }
  2456. else
  2457. {
  2458. ceErpTradeCellExtend.payment_cyt = price;
  2459. ceErpTradeCellExtend.Update();
  2460. }
  2461. }
  2462. }
  2463. catch (Exception ex)
  2464. {
  2465. }
  2466. return;
  2467. }
  2468. /// <summary>
  2469. /// 更新设计信息
  2470. /// </summary>
  2471. /// <param name="ceErpTradeCell"></param>
  2472. public static void updateDataTradeCellDesignInfo(string ctid)
  2473. {
  2474. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2475. if (ceErpTradeCell == null)
  2476. {
  2477. return;
  2478. }
  2479. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", ceErpTradeCell.tid);
  2480. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2481. foreach (DataRow row in data.Rows)
  2482. {
  2483. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  2484. if (ceErpTradeCell == null)
  2485. {
  2486. continue;
  2487. }
  2488. Dictionary<string, string> map = new Dictionary<string, string>();
  2489. if (ceErpTradeCell.DesignUserId > 0)
  2490. {
  2491. string design_sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", ceErpTradeCell.DesignUserId);
  2492. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(design_sql).Tables[0];
  2493. if (design_dt != null && design_dt.Rows.Count > 0)
  2494. {
  2495. map.Add("ShortText1717743889973", design_dt.Rows[0]["Name"].ToString());
  2496. map.Add("ShortText1717743889516", design_dt.Rows[0]["OrgName"].ToString());
  2497. if (!string.IsNullOrEmpty(design_dt.Rows[0]["OrgID"].ToString()))
  2498. {
  2499. int orgId = Convert.ToInt32(design_dt.Rows[0]["OrgID"]);
  2500. if (orgId > 0)
  2501. {
  2502. string mDesign_sql = string.Format("SELECT Name FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd')", design_dt.Rows[0]["OrgID"]);
  2503. DataTable mDesign_dt = DbHelper.DbConn.ExecuteDataset(mDesign_sql).Tables[0];
  2504. if (mDesign_dt != null && mDesign_dt.Rows.Count > 0)
  2505. {
  2506. map.Add("ShortText1717743890850", mDesign_dt.Rows[0]["Name"].ToString());
  2507. }
  2508. }
  2509. }
  2510. }
  2511. map.Add("Date1717743893776", ceErpTradeCell.WaitDesignTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2512. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2513. }
  2514. dataHelper.updateErpTradeCell(map, ctid);
  2515. }
  2516. }
  2517. /// <summary>
  2518. /// 下单更新
  2519. /// </summary>
  2520. /// <param name="ceErpTradeCell"></param>
  2521. public static void updateDataTradeCellPlaceInfo(string ctid)
  2522. {
  2523. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2524. if (ceErpTradeCell == null)
  2525. {
  2526. return;
  2527. }
  2528. Dictionary<string, string> map = new Dictionary<string, string>();
  2529. if (ceErpTradeCell.OrderState >= 6 && ceErpTradeCell.SupplierId > 0)
  2530. {
  2531. map.Add("Date1717743895362", ceErpTradeCell.FinishDesignTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2532. map.Add("Date1717744246168", ceErpTradeCell.FinishPlaceTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2533. string supplierId = dataHelper.getSupplerDataInfo(ceErpTradeCell.SupplierId.ToString());
  2534. map.Add("RelevanceForm1718100412422", supplierId);
  2535. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  2536. if (ceErpTradeCellExtend != null)
  2537. {
  2538. map.Add("Number1718099884613", ceErpTradeCellExtend.payment_cyt.ToString());
  2539. }
  2540. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2541. }
  2542. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2543. }
  2544. /// <summary>
  2545. /// 发货更新
  2546. /// </summary>
  2547. /// <param name="ceErpTradeCell"></param>
  2548. public static void updateDataTradeCellDeliveInfo(string ctid)
  2549. {
  2550. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2551. if (ceErpTradeCell == null)
  2552. {
  2553. return;
  2554. }
  2555. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", ceErpTradeCell.tid);
  2556. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2557. foreach (DataRow row in data.Rows)
  2558. {
  2559. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  2560. if (ceErpTradeCell == null)
  2561. {
  2562. continue;
  2563. }
  2564. Dictionary<string, string> map = new Dictionary<string, string>();
  2565. if (ceErpTradeCell.OrderState >= 7 && ceErpTradeCell.SupplierId > 0)
  2566. {
  2567. map.Add("Date1717744254301", ceErpTradeCell.FinishDeliveryTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2568. map.Add("ShortText1717744255441", ceErpTradeCell.OutSid);
  2569. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2570. }
  2571. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2572. }
  2573. }
  2574. /// <summary>
  2575. /// 打回
  2576. /// </summary>
  2577. /// <param name="ceErpTradeCell"></param>
  2578. public static void updateDataTradeCellBackInfo(string ctid)
  2579. {
  2580. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2581. if (ceErpTradeCell == null)
  2582. {
  2583. return;
  2584. }
  2585. Dictionary<string, string> map = new Dictionary<string, string>();
  2586. map.Add("Date1717745436357", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2587. map.Add("ShortText1717745435559", "是");
  2588. map.Add("ShortText1717745481283", ceErpTradeCell.ReturnReason);
  2589. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2590. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2591. }
  2592. /// <summary>
  2593. /// 查货
  2594. /// </summary>
  2595. /// <param name="ceErpTradeCell"></param>
  2596. public static void updateDataTradeCellCheckGoodInfo(string ctid)
  2597. {
  2598. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2599. if (ceErpTradeCell == null)
  2600. {
  2601. return;
  2602. }
  2603. Dictionary<string, string> map = new Dictionary<string, string>();
  2604. map.Add("Date1717745495718", ceErpTradeCell.CheckOrderTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2605. map.Add("ShortText1717745492918", "是");
  2606. map.Add("ShortText1717745497837", ceErpTradeCell.CheckMemo);
  2607. map.Add("ShortText1717745499141", ceErpTradeCell.UnusualCon);
  2608. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2609. }
  2610. /// <summary>
  2611. /// 加急
  2612. /// </summary>
  2613. /// <param name="ceErpTradeCell"></param>
  2614. public static void updateDataTradeCellUrgentInfo(string ctid)
  2615. {
  2616. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2617. if (ceErpTradeCell == null)
  2618. {
  2619. return;
  2620. }
  2621. Dictionary<string, string> map = new Dictionary<string, string>();
  2622. map.Add("Date1717745535736", ceErpTradeCell.UrgencyTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2623. map.Add("ShortText1717745533062", "是");
  2624. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2625. }
  2626. /// <summary>
  2627. /// 售后
  2628. /// </summary>
  2629. /// <param name="ceErpTradeCell"></param>
  2630. public static void updateDataTradeCellAfterSaleInfo(string ctid)
  2631. {
  2632. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2633. if (ceErpTradeCell == null)
  2634. {
  2635. return;
  2636. }
  2637. Dictionary<string, string> map = new Dictionary<string, string>();
  2638. map.Add("ShortText1717745540758", "是");
  2639. map.Add("Date1717745544245", ceErpTradeCell.AfterSaleTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2640. if (ceErpTradeCell.AfterSaleResSupId > 0)
  2641. {
  2642. CeErpUser user = CeErpUser.Get(ceErpTradeCell.AfterSaleResSupId);
  2643. if (user != null)
  2644. {
  2645. map.Add("ShortText1717745541664", user.Name);
  2646. }
  2647. }
  2648. map.Add("Date1717745545841", ceErpTradeCell.FinishAfterSaleTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2649. if (!string.IsNullOrEmpty(ceErpTradeCell.AfterSaleReason))
  2650. {
  2651. string[] list = ceErpTradeCell.AfterSaleReason.Split('|');
  2652. for (int i = 0; i < list.Length; i++)
  2653. {
  2654. if (i == 0)
  2655. {
  2656. map.Add("ShortText1717745548220", list[i]);
  2657. }
  2658. if (i == 1)
  2659. {
  2660. map.Add("ShortText1717745549835", list[i]);
  2661. }
  2662. if (i == 2)
  2663. {
  2664. map.Add("ShortText1717745550687", list[i]);
  2665. }
  2666. }
  2667. }
  2668. if (!string.IsNullOrEmpty(ceErpTradeCell.ResponsibleUserId))
  2669. {
  2670. string[] list = ceErpTradeCell.ResponsibleUserId.Split(',');
  2671. for (int i = 0; i < list.Length; i++)
  2672. {
  2673. string[] user = list[i].Split('_');
  2674. if (user.Length > 0)
  2675. {
  2676. if (user[1] == "g")
  2677. {
  2678. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(user[0]);
  2679. if (i == 0)
  2680. {
  2681. map.Add("ShortText1717745553842", list[i]);
  2682. map.Add("ShortText1717745554626", "");
  2683. }
  2684. if (i == 1)
  2685. {
  2686. map.Add("ShortText1717811042513", list[i]);
  2687. map.Add("ShortText1717811049407", "");
  2688. }
  2689. }
  2690. else if (user[1] == "w")
  2691. {
  2692. if (i == 0)
  2693. {
  2694. map.Add("ShortText1717745553842", "物流问题");
  2695. map.Add("ShortText1717745554626", "");
  2696. }
  2697. if (i == 1)
  2698. {
  2699. map.Add("ShortText1717811042513", "物流问题");
  2700. map.Add("ShortText1717811049407", "");
  2701. }
  2702. }
  2703. else
  2704. {
  2705. string customer_sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", ceErpTradeCell.CustomerUserId);
  2706. DataTable customer_dt = DbHelper.DbConn.ExecuteDataset(customer_sql).Tables[0];
  2707. if (customer_dt.Rows.Count > 0)
  2708. {
  2709. if (i == 0)
  2710. {
  2711. map.Add("ShortText1717745553842", customer_dt.Rows[0]["Name"].ToString());
  2712. map.Add("ShortText1717745554626", customer_dt.Rows[0]["OrgName"].ToString());
  2713. }
  2714. if (i == 1)
  2715. {
  2716. map.Add("ShortText1717811042513", customer_dt.Rows[0]["Name"].ToString());
  2717. map.Add("ShortText1717811049407", customer_dt.Rows[0]["OrgName"].ToString());
  2718. }
  2719. }
  2720. }
  2721. }
  2722. }
  2723. }
  2724. map.Add("number1717745810151", ceErpTradeCell.RefundFee.ToString());
  2725. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ceErpTradeCell.ctid);
  2726. if (ceErpTradeAfterSaleExtend != null && !string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.RefundFees))
  2727. {
  2728. string[] list = ceErpTradeAfterSaleExtend.RefundFees.Split(',');
  2729. for (int i = 0; i < list.Length; i++)
  2730. {
  2731. if (i == 0)
  2732. {
  2733. map.Add("Number1717745564936", list[i]);
  2734. }
  2735. if (i == 1)
  2736. {
  2737. map.Add("Number1717745565580", list[i]);
  2738. }
  2739. }
  2740. }
  2741. map.Add("ShortText1717745580986", ceErpTradeCell.AfterSaleSupplierState == 1 ? "认可" : "不认可");
  2742. map.Add("ShortText1717745582613", ceErpTradeCell.AfterSaleSupplierMemo);
  2743. map.Add("ShortText1717745583256", ceErpTradeCell.AfterSaleMethod);
  2744. map.Add("ShortText1717745583810", ceErpTradeCell.AfterSaleMemo);
  2745. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2746. }
  2747. /// <summary>
  2748. /// 退款
  2749. /// </summary>
  2750. /// <param name="content"></param>
  2751. public static void updateDataTradeCellRefundInfo(Api_tmc_refund_info_Obj.Content content)
  2752. {
  2753. Dictionary<string, string> map = new Dictionary<string, string>();
  2754. map.Add("Date1717745588048", StampToDateTime(content.createTime).ToString("yyyy-MM-dd HH:mm:ss"));
  2755. map.Add("ShortText1717745585444", "是");
  2756. map.Add("Number1717743148189", content.refundFee);
  2757. map.Add("ShortText1717745591810", content.reason);
  2758. map.Add("ShortText1717745592639", content.desc);
  2759. string tid = content.refOid;
  2760. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", tid);
  2761. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2762. foreach (DataRow row in data.Rows)
  2763. {
  2764. dataHelper.updateErpTradeCell(map, row["ctid"].ToString());
  2765. }
  2766. }
  2767. /// <summary>
  2768. /// 返现
  2769. /// </summary>
  2770. /// <param name="entity"></param>
  2771. /// <param name="cash"></param>
  2772. public static void updateDataTradeCellCashInfo(CeErpTradeCell entity, CeErpReturnCash cash)
  2773. {
  2774. Dictionary<string, string> map = new Dictionary<string, string>();
  2775. map.Add("ShortText1717745601056", "是");
  2776. map.Add("ShortText1717745602313", cash.rtype);
  2777. map.Add("Number1717745604245", cash.payment.ToString());
  2778. map.Add("ShortText1717745607208", cash.con);
  2779. dataHelper.updateErpTradeCell(map, entity.ctid);
  2780. }
  2781. /// <summary>
  2782. /// 推购
  2783. /// </summary>
  2784. /// <param name="entity"></param>
  2785. public static void updateDataTradeCellStayInfo(CeErpTradeCell entity)
  2786. {
  2787. Dictionary<string, string> map = new Dictionary<string, string>();
  2788. map.Add("ShortText1717745608381", "是");
  2789. dataHelper.updateErpTradeCell(map, entity.ctid);
  2790. }
  2791. public static DateTime StampToDateTime(string timeStamp)
  2792. {
  2793. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2794. long lTime = long.Parse(timeStamp + "0000");
  2795. TimeSpan toNow = new TimeSpan(lTime);
  2796. return dateTimeStart.Add(toNow);
  2797. }
  2798. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  2799. {
  2800. return true; //总是接受
  2801. }
  2802. public static string HttpPost(string url, string param = null)
  2803. {
  2804. HttpWebRequest request;
  2805. //如果是发送HTTPS请求
  2806. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  2807. {
  2808. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  2809. request = WebRequest.Create(url) as HttpWebRequest;
  2810. request.ProtocolVersion = HttpVersion.Version10;
  2811. }
  2812. else
  2813. {
  2814. request = WebRequest.Create(url) as HttpWebRequest;
  2815. }
  2816. request.Method = "POST";
  2817. request.ContentType = "application/json";
  2818. request.Accept = "*/*";
  2819. request.Timeout = 60000;
  2820. request.AllowAutoRedirect = false;
  2821. StreamWriter requestStream = null;
  2822. WebResponse response = null;
  2823. string responseStr = null;
  2824. try
  2825. {
  2826. requestStream = new StreamWriter(request.GetRequestStream());
  2827. requestStream.Write(param);
  2828. requestStream.Close();
  2829. response = request.GetResponse();
  2830. if (response != null)
  2831. {
  2832. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  2833. responseStr = reader.ReadToEnd();
  2834. reader.Close();
  2835. }
  2836. }
  2837. catch (Exception ex)
  2838. {
  2839. return ex.Message;
  2840. }
  2841. finally
  2842. {
  2843. request = null;
  2844. requestStream = null;
  2845. response = null;
  2846. }
  2847. return responseStr;
  2848. }
  2849. public static List<int> spu_products = new List<int>() { 4, 13, 19, 24, 28, 32, 40, 51, 57, 1971, 2319, 2377, 2521, 2524, 2533, 2538, 2542, 2554, 2556, 2557, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2568, 2569, 2570, 2571, 2572, 2619, 2625, 2636, 2637, 2638, 2645, 2646 };
  2850. public static List<int> spu_shopIds = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 27, 28, 31, 32, 56, 61 };
  2851. public static List<string> receiver_state = new List<string> { "内蒙古", "西藏", "甘肃", "青海", "宁夏", "新疆" };
  2852. public static bool isFarAddress(string state)
  2853. {
  2854. for (int i = 0; receiver_state.Count > i; i++)
  2855. {
  2856. if (state.Contains(receiver_state[i]))
  2857. {
  2858. return true;
  2859. }
  2860. }
  2861. return false;
  2862. }
  2863. public static void setSpuData(CeErpTrade father)
  2864. {
  2865. if (string.IsNullOrEmpty(father.seller_memo))
  2866. {
  2867. return;
  2868. }
  2869. string orderSql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeOrder] WHERE tid = '{0}' and total_fee > 0", father.tid);
  2870. DataTable table = SqlHelper.ExecuteDataSet(orderSql).Tables[0];
  2871. string spu_id = "";
  2872. if (table != null && table.Rows.Count == 1)
  2873. {
  2874. spu_id = table.Rows[0]["spu_id"].ToString();
  2875. }
  2876. string cellSql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid = '{0}'", father.tid);
  2877. DataTable data = SqlHelper.ExecuteDataSet(cellSql).Tables[0];
  2878. if (data != null && data.Rows.Count > 0)
  2879. {
  2880. foreach (DataRow row in data.Rows)
  2881. {
  2882. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(row["ctid"].ToString());
  2883. if (ceErpTradeCellExtend == null)
  2884. {
  2885. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2886. ceErpTradeCellExtend.ctid = row["ctid"].ToString();
  2887. }
  2888. ceErpTradeCellExtend.spu_id = spu_id;
  2889. if (!string.IsNullOrEmpty(spu_id))
  2890. {
  2891. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ceErpTradeCellExtend.ctid);
  2892. ceErpTradeCellExtend = sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  2893. }
  2894. if (ceErpTradeCellExtend.ID == 0)
  2895. {
  2896. ceErpTradeCellExtend.Create();
  2897. }
  2898. else
  2899. {
  2900. ceErpTradeCellExtend.Update();
  2901. }
  2902. }
  2903. }
  2904. List<string> list = new List<string>() { "kevin_boz", "奥丽芙旗舰店", "鼎怡旗舰店", "格图旗舰店", "宫契旗舰店", "海角七旗舰店", "航和旗舰店", "岚恬旗舰店", "琳19890725", "领淘文具旗舰店", "麦郁旗舰店", "米笛儿旗舰店", "颂盼旗舰店", "涛莱旗舰店", "腾科吉旗舰店", "万慕办公旗舰店", "喜印说旗舰店", "欣克利旗舰店", "阳光猫旗舰店", "翊喜旗舰店", "尹灵旗舰店", "悦加旗舰店", "竹范旗舰店", "卓胜旗舰店" };
  2905. if (string.IsNullOrEmpty(spu_id) && list.IndexOf(father.seller_nick) > -1)
  2906. {
  2907. string sql_pay = "update CE_ErpTradeCell with(rowlock) set orderstate=-1 where tid='" + father.tid + "';";
  2908. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2909. }
  2910. }
  2911. public static CeErpTradeCellExtend sendSpuData(CeErpTradeCell ceErpTradeCell, CeErpTradeCellExtend ceErpTradeCellExtend)
  2912. {
  2913. if (ceErpTradeCellExtend == null)
  2914. {
  2915. return null;
  2916. }
  2917. //string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  2918. string result = "无";
  2919. ceErpTradeCellExtend.ToType = result;
  2920. int dispatchSort = 0;
  2921. if ("无".Equals(result) && spu_shopIds.Contains(ceErpTradeCell.ShopId))
  2922. {
  2923. ceErpTradeCellExtend.ToType = "内部";
  2924. dispatchSort = 0;
  2925. }
  2926. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && spu_shopIds.Contains(ceErpTradeCell.ShopId) && !spu_products.Contains(ceErpTradeCell.ProductId))
  2927. {
  2928. ceErpTradeCellExtend.ToType = "内部";
  2929. dispatchSort = 0;
  2930. }
  2931. if (ceErpTradeCell.payment >= 500 && spu_shopIds.Contains(ceErpTradeCell.ShopId) && !spu_products.Contains(ceErpTradeCell.ProductId))
  2932. {
  2933. ceErpTradeCellExtend.ToType = "内部";
  2934. dispatchSort = 0;
  2935. }
  2936. if (spu_products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  2937. {
  2938. ceErpTradeCellExtend.ToType = "外协";
  2939. dispatchSort = 2;
  2940. }
  2941. string sql_pay = string.Format("update CE_ErpTradeCell with(rowlock) set DispatchSort={0} where ctid='{1}';", dispatchSort, ceErpTradeCell.ctid);
  2942. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2943. if (ceErpTradeCellExtend.ID > 0)
  2944. {
  2945. ceErpTradeCellExtend.Update();
  2946. }
  2947. return ceErpTradeCellExtend;
  2948. }
  2949. public static DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  2950. {
  2951. StringBuilder sql = new StringBuilder();
  2952. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount,OrderSn from view_ErpTradeCell where SupplierId={0} and orderstate=6 and IsSample = 0 AND ShopId = {1}", entity.SupplierId, entity.ShopId);
  2953. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  2954. {
  2955. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  2956. }
  2957. else
  2958. {
  2959. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  2960. }
  2961. DataTable dt = null;
  2962. try
  2963. {
  2964. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2965. StringBuilder timerSql = new StringBuilder();
  2966. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  2967. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  2968. //没有设置时间则不判断
  2969. dt.Columns.Add(new DataColumn("default", typeof(int)));
  2970. if (timerTable == null || timerTable.Rows.Count == 0)
  2971. {
  2972. return dt;
  2973. }
  2974. foreach (DataRow dr in dt.Rows)
  2975. {
  2976. dr["default"] = 0;
  2977. //当前订单
  2978. if (entity.ctid.Equals(dr["ctid"]))
  2979. {
  2980. continue;
  2981. }
  2982. //已经标记过发货
  2983. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  2984. if (ceErpDeliverMark != null)
  2985. {
  2986. dr["default"] = 1;
  2987. continue;
  2988. }
  2989. string[] productIds = null;
  2990. string productId = dr["productId"].ToString();
  2991. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  2992. string sellmer_mome = dr["seller_memo"].ToString();
  2993. string txtCount = dr["ProductCount"].ToString();
  2994. DateTime placeTime = DateTime.Now;
  2995. //没有品类
  2996. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  2997. {
  2998. continue;
  2999. }
  3000. if (string.IsNullOrEmpty(finishPlaceTime))
  3001. {
  3002. continue;
  3003. }
  3004. placeTime = DateTime.Parse(finishPlaceTime);
  3005. foreach (DataRow row in timerTable.Rows)
  3006. {
  3007. string txtIds = row["productId"].ToString();
  3008. string[] crafts = { };
  3009. int count = Convert.ToUInt16(row["quantity"]);
  3010. if (string.IsNullOrEmpty(txtIds))
  3011. {
  3012. continue;
  3013. }
  3014. if (count > 0)
  3015. {
  3016. int quantity = commonHelper.handleProductCount(txtCount, true);
  3017. //订单数量大于写入的数量则跳过
  3018. if (quantity > count)
  3019. {
  3020. continue;
  3021. }
  3022. }
  3023. productIds = txtIds.Split(',');
  3024. if (productIds.Contains(productId))
  3025. {
  3026. string textCraft = row["craft"].ToString();
  3027. textCraft = textCraft.Replace(",", ",");//统一格式
  3028. if (!string.IsNullOrEmpty(textCraft))
  3029. {
  3030. crafts = textCraft.Split(',');
  3031. }
  3032. if (crafts.Length > 0)
  3033. {
  3034. bool isinCraft = false;
  3035. for (int i = 0; i < crafts.Length; i++)
  3036. {
  3037. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  3038. {
  3039. isinCraft = true;
  3040. break;
  3041. }
  3042. }
  3043. //有写工艺并且备注中没匹配中则跳过
  3044. if (!isinCraft)
  3045. {
  3046. continue;
  3047. }
  3048. }
  3049. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  3050. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  3051. int sendDay = Convert.ToInt16(row["sendDay"]);
  3052. //下单时间小于当日发货时间则不用判断
  3053. //当日发货必须发货
  3054. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  3055. {
  3056. dr["default"] = 1;
  3057. break;
  3058. }
  3059. //在截稿时间之前下单的可以减去一天时间
  3060. /*if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  3061. {
  3062. sendDay = Math.Max(1, sendDay - 1);
  3063. }
  3064. DateTime sendtime = placeTime.AddDays(sendDay);
  3065. //判断有没有到发货日期
  3066. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  3067. {
  3068. break;
  3069. }*/
  3070. }
  3071. }
  3072. }
  3073. }
  3074. catch (Exception ex)
  3075. {
  3076. }
  3077. return dt;
  3078. }
  3079. public static double calculationPrice(CeErpTradeCell ceErpTradeCell)
  3080. {
  3081. double price = 0;
  3082. return 200;
  3083. List<string> list = new List<string>();
  3084. //查补差订单
  3085. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select tid from CE_ErpTradeCell where ptid = '{0}' and IsSample =2", ceErpTradeCell.tid)).Tables[0];
  3086. list.Add("'" + ceErpTradeCell.tid + "'");
  3087. if (dt != null && dt.Rows.Count > 0)
  3088. {
  3089. foreach (DataRow dr in dt.Rows)
  3090. {
  3091. list.Add("'" + dr["tid"].ToString() + "'");
  3092. }
  3093. }
  3094. DataTable tradeTables = DbHelper.DbConn.ExecuteDataset(string.Format("select payment from CE_ErpTrade where tid in ({0})", string.Join(",", list))).Tables[0];
  3095. if (tradeTables != null && tradeTables.Rows.Count > 0)
  3096. {
  3097. foreach (DataRow dr in tradeTables.Rows)
  3098. {
  3099. price += Convert.ToDouble(dr["payment"]);
  3100. }
  3101. }
  3102. return price;
  3103. }
  3104. public static bool loginGetOrder(int userId)
  3105. {
  3106. DataTable dt = null;
  3107. try
  3108. {
  3109. dt = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where ID = {0}", userId)).Tables[0];
  3110. }
  3111. catch (Exception e)
  3112. {
  3113. }
  3114. if (dt == null || dt.Rows.Count == 0)
  3115. {
  3116. return false;
  3117. }
  3118. DataRow dr = dt.Rows[0];
  3119. int isOpen = Convert.ToInt32(dr["isOpen"]);
  3120. int dayOrderReceive = Convert.ToInt32(dr["DayOrderReceive"]);//已经派了多少
  3121. int dayOrderLimit = Convert.ToInt32(dr["DayOrderLimit"]);//总的能派多少
  3122. int orderAmountLimit = Convert.ToInt32(dr["OrderAmountLimit"]);//能派的金额多少
  3123. int oldOrder = Convert.ToInt32(dr["OldOrder"]);//能派的金额多少
  3124. string orgShop = dr["OrgShop"].ToString();
  3125. string pemShop = dr["pemShop"].ToString();
  3126. string pemDesign = dr["pemDesign"].ToString();
  3127. if (isOpen == 0)
  3128. {
  3129. return false;
  3130. }
  3131. if (string.IsNullOrEmpty(orgShop) || string.IsNullOrEmpty(pemShop) || string.IsNullOrEmpty(pemDesign))
  3132. {
  3133. return false;
  3134. }
  3135. string normolSql = string.Format("and payment <={0} and shopid in ({1}) and shopid in ({2}) and ProductId in ({3})", orderAmountLimit, orgShop, pemShop, pemDesign);
  3136. string orderSql = string.Format("select tid,ctid,IsOldCustomer,shopid,payment,ProductId from view_ErpTradeCell where orderstate=2 and productid<>0 and designuserid=0 and payment>0 and isrefund=0 and isDianziOrder = 0 {0} order by IsUrgency DESC, YEAR ( pay_time ), MONTH ( pay_time ), DAY ( pay_time ), payment DESC;", normolSql);
  3137. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(orderSql).Tables[0];
  3138. if (dataTable == null || dataTable.Rows.Count == 0)
  3139. {
  3140. return true;
  3141. }
  3142. designApiResponseVo result = null;
  3143. List<string> list = new List<string>();
  3144. foreach (DataRow row in dataTable.Rows)
  3145. {
  3146. if (dayOrderReceive >= dayOrderLimit)
  3147. {
  3148. break;
  3149. }
  3150. string IsOldCustomer = dr["IsOldCustomer"].ToString();
  3151. int ProductId = Convert.ToInt32(dr["ProductId"]);
  3152. CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
  3153. int shopUserId = 0;
  3154. if (ceErpShop != null)
  3155. {
  3156. shopUserId = ceErpShop.UserID;
  3157. }
  3158. bool isIn = false;
  3159. if ((IsOldCustomer == "1" && shopUserId == 241) || (shopUserId == 241 && Convert.ToDouble(dr["payment"]) >= 500))
  3160. {
  3161. if (oldOrder == 1)
  3162. {
  3163. //手绘 logo 画册 海报 宣传单
  3164. if ((IsOldCustomer == "1" && (ProductId == 28 || ProductId == 57 || ProductId == 40 || ProductId == 4 || ProductId == 13)))
  3165. {
  3166. result = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3167. if (result != null && result.code == 200)
  3168. {
  3169. continue;
  3170. }
  3171. }
  3172. isIn = true;
  3173. }
  3174. }
  3175. else
  3176. {
  3177. if (oldOrder == 0)
  3178. {
  3179. if (shopUserId != 82)
  3180. {
  3181. result = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3182. if (result != null && result.code == 200)
  3183. {
  3184. continue;
  3185. }
  3186. }
  3187. isIn = true;
  3188. }
  3189. }
  3190. if (isIn)
  3191. {
  3192. int rowCount = DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where tid={0} and OrderState=2 and DesignUserId=0 ;", dr["tid"].ToString(), (int)OrderState.下单完成, userId, "3测试自动派单" + userId));
  3193. //int rowCount = DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=3,IsAutoDispatch=1,WaitDesignTime=getdate(),UpdateTime=getdate(),DesignUserId={0},DispatchSort=0 where tid={1} and OrderState=2 and DesignUserId=0", userId, dr["tid"].ToString()));
  3194. dayOrderReceive += rowCount;
  3195. }
  3196. }
  3197. return true;
  3198. }
  3199. public static bool setFromDataInfo(string tid, string content, int userId)
  3200. {
  3201. CeErpTradeCell tradeCell = CeErpTradeCell.GetByCtid(tid);
  3202. if (tradeCell == null)
  3203. {
  3204. return false;
  3205. }
  3206. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", tradeCell.tid);
  3207. if (tradeCell.ctid.Contains("S_"))
  3208. {
  3209. info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE ctid ='{0}'", tradeCell.ctid);
  3210. }
  3211. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  3212. CeErpOrderFormData formData = null;
  3213. if (data.Rows.Count > 0)
  3214. {
  3215. List<CeErpTradeCell> cell_list = new List<CeErpTradeCell>();
  3216. foreach (DataRow row in data.Rows)
  3217. {
  3218. string ctid = row["ctid"].ToString();
  3219. CeErpTradeCell cell = CeErpTradeCell.GetByCtid(ctid);
  3220. cell_list.Add(cell);
  3221. formData = CeErpOrderFormData.GetByTid(ctid);
  3222. if (formData == null)
  3223. {
  3224. formData = new CeErpOrderFormData();
  3225. }
  3226. formData.tid = ctid;
  3227. formData.content = content;
  3228. if (formData.ID > 0)
  3229. {
  3230. formData.Update();
  3231. }
  3232. else
  3233. {
  3234. formData.userId = userId;
  3235. formData.Create();
  3236. }
  3237. }
  3238. if (tradeCell.OrderState >= 5)
  3239. {
  3240. LogHelper.addLog(tradeCell.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:订单状态不正确!", tradeCell.OrderState);
  3241. return false;
  3242. }
  3243. //能进来并且没有设计师
  3244. foreach (CeErpTradeCell entity in cell_list)
  3245. {
  3246. try
  3247. {
  3248. if (entity != null && entity.seller_memo.Length > 0)
  3249. {
  3250. if (entity.OrderState >= 5)
  3251. {
  3252. LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:订单状态不正确!", entity.OrderState);
  3253. continue;
  3254. }
  3255. //判断能不能推送
  3256. designApiResponseVo result = checkOrderListDesignInfo(entity.tid, entity.ctid);
  3257. if (result != null && result.code == 200)
  3258. {
  3259. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, "SysAdmin");
  3260. if (response.code == 200)
  3261. {
  3262. if (response.msg == "设计共创:成功")
  3263. {
  3264. if (entity.ctid.IndexOf("S_") == -1)
  3265. {
  3266. int suid = autoDistributeToSupplier(entity); //自动分配供应商
  3267. entity.SupplierId = suid;
  3268. string suname = getSupplierNameById(entity.SupplierId);
  3269. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3270. }
  3271. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3272. entity.DesignUserId = 3542;
  3273. entity.WaitDesignTime = DateTime.Now;
  3274. entity.DispatchSort = 2;
  3275. entity.UpdateTime = DateTime.Now;
  3276. entity.Update();
  3277. }
  3278. }
  3279. LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:" + response.msg, Convert.ToInt32(OrderState.待设计));
  3280. }
  3281. else
  3282. {
  3283. LogHelper.addLog(entity.ctid, formData.userId > 0 ? formData.userId : 3542, "外链派单:" + result.msg, Convert.ToInt32(OrderState.待设计));
  3284. }
  3285. }
  3286. }
  3287. catch (Exception ex)
  3288. {
  3289. XLog.SaveLog(0, "外链派单:" + ex.Message);
  3290. }
  3291. }
  3292. }
  3293. return true;
  3294. }
  3295. public static void checkIsVipOld(CeErpTrade ceErpTrade)
  3296. {
  3297. if (ceErpTrade == null || string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  3298. {
  3299. return;
  3300. }
  3301. int VipCustomer = 2;
  3302. string last_tid = "";
  3303. string sql = "";
  3304. if (ceErpTrade.payment > 20)
  3305. {
  3306. sql = string.Format("SELECT top 1 tid FROM [dbo].[view_ErpTradeCell] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and IsSample = 0 and payment >= 20 order by pay_time desc;", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  3307. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  3308. {
  3309. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  3310. }
  3311. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3312. if (dataTable != null && dataTable.Rows.Count > 0)
  3313. {
  3314. last_tid = dataTable.Rows[0]["tid"].ToString();
  3315. if (!string.IsNullOrEmpty(last_tid))
  3316. {
  3317. VipCustomer = 1;
  3318. }
  3319. }
  3320. }
  3321. if (VipCustomer == 1)
  3322. {
  3323. LogHelper.addLog(ceErpTrade.tid, 0, "老客户订单号:" + last_tid, Convert.ToInt32(OrderState.待设计));
  3324. }
  3325. DbHelper.DbConn.ExecuteNonQuery(string.Format("UPDATE [dbo].[CE_ErpTradeCell] set VipCustomer = {1} WHERE tid='{0}';", ceErpTrade.tid, VipCustomer));
  3326. return;
  3327. }
  3328. public static bool interceptionSizeUnit(string size, CeErpProduct ceErpProduct)
  3329. {
  3330. size = size.Replace(",", ",");
  3331. size = size.Replace("C", "c");
  3332. size = size.Replace("M", "m");
  3333. List<string> list = ExtractUnitsOnly(size);
  3334. if (list.Count == 0)
  3335. {
  3336. return true;
  3337. }
  3338. if (ceErpProduct == null)
  3339. {
  3340. return true;
  3341. }
  3342. //未设置的不处理
  3343. if (string.IsNullOrEmpty(ceErpProduct.SizeUnit))
  3344. {
  3345. return true;
  3346. }
  3347. //提取到的单位数量不符合
  3348. if (size.Contains(",") && size.Split(',').Length != list.Count)
  3349. {
  3350. return false;
  3351. }
  3352. if (size.Contains("+") && size.Split('+').Length != list.Count)
  3353. {
  3354. return false;
  3355. }
  3356. list = list.Distinct().ToList();
  3357. //不能同时存在两个尺寸单位
  3358. if (list.Count != 1)
  3359. {
  3360. return false;
  3361. }
  3362. if (!list[0].Equals(ceErpProduct.SizeUnit))
  3363. {
  3364. return false;
  3365. }
  3366. return true;
  3367. }
  3368. static List<string> ExtractUnitsOnly(string text)
  3369. {
  3370. List<string> units = new List<string>();
  3371. string pattern = @"(cm|mm|m)";
  3372. foreach (Match match in Regex.Matches(text, pattern))
  3373. {
  3374. units.Add(match.Value);
  3375. }
  3376. return units;
  3377. }
  3378. public static string getProductCount(string txt)
  3379. {
  3380. txt = txt.Replace(",", ",");
  3381. string[] txtList = txt.Split(',');
  3382. int total = 0;
  3383. for (int i = 0; i < txtList.Length; i++)
  3384. {
  3385. string kuanPattern = @"(\d+)(?=款)";
  3386. Match kuanMatch = Regex.Match(txtList[i], kuanPattern);
  3387. string kuanNum = kuanMatch.Success ? kuanMatch.Groups[1].Value : "1";
  3388. // 提取"个"或"张"前面的数字
  3389. string unitPattern = @"(\d+)(?=个|张|本|套|件|卷|劵|条|箱 )";
  3390. Match unitMatch = Regex.Match(txtList[i], unitPattern);
  3391. string unitNum = unitMatch.Success ? unitMatch.Groups[1].Value : "1";
  3392. int kuan = 1;
  3393. int unit = 1;
  3394. if (!int.TryParse(kuanNum, out kuan))
  3395. {
  3396. return txt;
  3397. }
  3398. if (!int.TryParse(unitNum, out unit))
  3399. {
  3400. return txt;
  3401. }
  3402. total += kuan * unit;
  3403. }
  3404. return (total).ToString();
  3405. }
  3406. public static string convertQNMemo(string itemMemo, ref CeErpTradeCell entity)
  3407. {
  3408. if (string.IsNullOrEmpty(itemMemo))
  3409. {
  3410. return "";
  3411. }
  3412. CeErpTrade father = CeErpTrade.Get(entity.tid);
  3413. //删除备注中的旺旺
  3414. if (father.type == "TMALL" || father.type == "TB")
  3415. {
  3416. string[] memoList = itemMemo.Split('-');
  3417. List<string> list = new List<string>(memoList);
  3418. string buyer_nick = "";
  3419. if ((itemMemo.IndexOf("logo") != -1 || itemMemo.IndexOf("LOGO") != -1))
  3420. {
  3421. if (list.Count > 3)
  3422. {
  3423. buyer_nick = list[3];
  3424. }
  3425. }
  3426. else if (itemMemo.IndexOf("补差") != -1 && list.Count < 6)
  3427. {
  3428. if (list.Count > 1)
  3429. {
  3430. buyer_nick = list[1];
  3431. }
  3432. }
  3433. else if (itemMemo.IndexOf("默拍单") != -1 && list.Count < 6)
  3434. {
  3435. if (list.Count > 1)
  3436. {
  3437. buyer_nick = list[1];
  3438. }
  3439. }
  3440. else if (itemMemo.IndexOf("寄样") != -1)
  3441. {
  3442. if (list.Count > 3)
  3443. {
  3444. buyer_nick = list[3];
  3445. }
  3446. }
  3447. else if (itemMemo.IndexOf("拿样订单") != -1)
  3448. {
  3449. if (list.Count > 1)
  3450. {
  3451. buyer_nick = list[1];
  3452. }
  3453. }
  3454. else if (itemMemo.IndexOf("礼物") != -1 && list.Count < 6)
  3455. {
  3456. if (list.Count > 1)
  3457. {
  3458. buyer_nick = list[1];
  3459. }
  3460. }
  3461. else
  3462. {
  3463. if (list.Count > 5)
  3464. {
  3465. buyer_nick = list[5];
  3466. }
  3467. }
  3468. itemMemo = string.Join("-", list);
  3469. itemMemo = itemMemo.Replace("-" + buyer_nick, string.Empty);
  3470. }
  3471. itemMemo = itemMemo.Replace("\r", " ");
  3472. itemMemo = itemMemo.Replace("\n", " ");
  3473. string newmemo = "";
  3474. if (itemMemo.Contains("logo") || itemMemo.Contains("LOGO"))
  3475. {
  3476. string[] acclist = itemMemo.Split('-');
  3477. if (acclist.Length < 4) return null;
  3478. string count = acclist[0];
  3479. string product = acclist[1];
  3480. string account = acclist[3];
  3481. DataRow cusInfo = tmcHelper.getUserInfoByAccount(account); //客服id
  3482. entity.ProductId = tmcHelper.getProductIdByName("logo");
  3483. entity.ProductCount = commonHelper.getProductCount(count);// commonHelper.changeCountFromChiness(count); ;
  3484. newmemo = "(" + entity.OrderSn + ")-";
  3485. string newOtherMemo = "";
  3486. for (int i = 0; i < acclist.Length; i++)
  3487. {
  3488. if (i == 3) continue;
  3489. if (i >= 4)
  3490. {
  3491. newOtherMemo += acclist[i];
  3492. }
  3493. else
  3494. newmemo += acclist[i];
  3495. if (i < acclist.Length - 2)
  3496. {
  3497. newmemo += "-";
  3498. }
  3499. }
  3500. string sName = tmcHelper.getShopSNameByName(father.seller_nick);//获取店铺简称
  3501. newmemo += ("-" + sName);
  3502. if (father.buyer_nick.IndexOf("*") < 0)
  3503. {
  3504. newmemo += ("-" + father.buyer_nick);
  3505. }
  3506. newmemo += ("-" + father.receiver_state);
  3507. if (cusInfo != null)
  3508. {
  3509. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3510. }
  3511. entity.seller_memo = newmemo;
  3512. entity.OtherMemo = newOtherMemo;
  3513. }
  3514. else if (itemMemo.Contains("合包"))
  3515. {
  3516. itemMemo = itemMemo.Replace(",", ",");
  3517. string[] hebaoMemoList = itemMemo.Split(',');
  3518. string newOtherMemo = "";
  3519. bool isMulity = true;
  3520. if (string.IsNullOrEmpty(entity.SplitTag))
  3521. {
  3522. isMulity = false;
  3523. }
  3524. string memo_index1 = hebaoMemoList[0];
  3525. string[] acclist = memo_index1.Split('-');
  3526. string account = acclist[5];
  3527. newmemo = "(" + entity.OrderSn + ")-";
  3528. for (int idx = 0; idx < hebaoMemoList.Length; idx++)
  3529. {
  3530. string smallitem = hebaoMemoList[idx];
  3531. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  3532. {
  3533. newmemo = "";
  3534. }
  3535. string[] smallList = smallitem.Split('-');
  3536. if (smallList.Length > 5 && idx > 0)
  3537. {
  3538. string itemsize = smallList[0];
  3539. string itemcount = smallList[1];
  3540. string itemmt = "", itemct = "";
  3541. if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
  3542. {
  3543. itemmt = acclist[2];
  3544. }
  3545. else
  3546. {
  3547. itemmt = acclist[3];
  3548. }
  3549. itemct = acclist[4];
  3550. entity.ProductSize = entity.ProductSize + "," + itemsize;
  3551. entity.ProductCount = entity.ProductCount + "," + itemcount;
  3552. entity.Material = entity.Material + "," + itemmt;
  3553. entity.Craft = entity.Craft + "," + itemct;
  3554. }
  3555. if (smallList.Length >= 7)
  3556. {
  3557. smallList[6] = smallList[6].Replace("(", "");
  3558. smallList[6] = smallList[6].Replace(")", "");
  3559. smallList[6] = smallList[6].Replace("(", "");
  3560. smallList[6] = smallList[6].Replace(")", "");
  3561. entity.MakeSupplier = smallList[6];
  3562. smallList[6] = "(" + smallList[6] + ")";
  3563. newmemo += smallList[6];
  3564. newmemo += "-";
  3565. }
  3566. if (false)
  3567. {
  3568. newmemo += smallList[2];
  3569. newmemo += smallList[0];
  3570. newmemo += "-";
  3571. newmemo += smallList[1];
  3572. newmemo += "(";
  3573. newmemo += entity.OrderSn;
  3574. newmemo += ")";
  3575. newmemo += "-";
  3576. newmemo += smallList[4];
  3577. if (smallList.Length > 7)
  3578. {
  3579. for (int i = 7; i < smallList.Length; i++)
  3580. {
  3581. newOtherMemo += smallList[i];
  3582. newOtherMemo += "-";
  3583. }
  3584. }
  3585. if (smallitem.IndexOf("5mmpvc") != -1)
  3586. {
  3587. entity.ProductId = 8; //pvc卡片
  3588. }
  3589. }
  3590. else
  3591. {
  3592. for (int i = 0; i < smallList.Length; i++)
  3593. {
  3594. if (isMulity && i == 5)
  3595. {
  3596. continue;
  3597. }
  3598. if (i >= 7)
  3599. {
  3600. newOtherMemo += smallList[i];
  3601. if (i < smallList.Length - 2 && i != 2 && i != 3)
  3602. {
  3603. newOtherMemo += "-";
  3604. }
  3605. }
  3606. else
  3607. {
  3608. if (i == 5 || i == 6)
  3609. {
  3610. continue;
  3611. }
  3612. else
  3613. newmemo += smallList[i];
  3614. if (i != 2 && i != 3)
  3615. {
  3616. newmemo += "-";
  3617. }
  3618. }
  3619. }
  3620. }
  3621. if (hebaoMemoList.Length > idx + 1)
  3622. {
  3623. newmemo += ",";
  3624. newOtherMemo += ",";
  3625. }
  3626. }
  3627. entity.ProductCount = commonHelper.getProductCount(entity.ProductCount);
  3628. string sName = tmcHelper.getShopSNameByName(father.seller_nick);
  3629. newmemo += (sName);
  3630. if (father.buyer_nick.IndexOf("*") < 0)
  3631. {
  3632. newmemo += ("-" + father.buyer_nick);
  3633. }
  3634. newmemo += ("-" + father.receiver_state);
  3635. DataRow cusInfo = tmcHelper.getUserInfoByAccount(account); //客服id
  3636. if (cusInfo != null)
  3637. {
  3638. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3639. }
  3640. if (cusInfo != null)
  3641. {
  3642. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3643. }
  3644. entity.seller_memo = newmemo;
  3645. entity.OtherMemo = newOtherMemo;
  3646. }
  3647. else
  3648. {
  3649. string[] acclist = itemMemo.Split('-');
  3650. bool isXianhuo = false;
  3651. if (acclist[0] == "现货")
  3652. {
  3653. isXianhuo = true;
  3654. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  3655. System.Array.Resize(ref acclist, acclist.Length - 1);
  3656. }
  3657. if (acclist.Length < 6)
  3658. {
  3659. return "";
  3660. }
  3661. string size = acclist[0];
  3662. string count = acclist[1];
  3663. bool isBuGanJiao = false;
  3664. string product = "";
  3665. string mt = "", ct = "";
  3666. string account = "";
  3667. itemMemo = itemMemo.Replace("PVC", "pvc");
  3668. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3669. {
  3670. isBuGanJiao = true;
  3671. product = acclist[3];
  3672. mt = acclist[2];
  3673. }
  3674. else
  3675. {
  3676. product = acclist[2];
  3677. mt = acclist[3];
  3678. }
  3679. account = acclist[5];
  3680. ct = acclist[4];
  3681. if (acclist.Length >= 7)
  3682. {
  3683. acclist[6] = acclist[6].Replace("(", "");
  3684. acclist[6] = acclist[6].Replace(")", "");
  3685. acclist[6] = acclist[6].Replace("(", "");
  3686. acclist[6] = acclist[6].Replace(")", "");
  3687. entity.MakeSupplier = acclist[6];
  3688. acclist[6] = "(" + acclist[6] + ")";
  3689. }
  3690. entity.ProductId = tmcHelper.getProductIdByName(product);
  3691. if (entity.ProductId == 0)
  3692. {
  3693. return "";
  3694. }
  3695. DataRow cusInfo = tmcHelper.getUserInfoByAccount(account); //客服id
  3696. if (cusInfo != null)
  3697. {
  3698. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3699. }
  3700. if (mt.IndexOf("铜板纸") != -1)
  3701. {
  3702. mt = mt.Replace("铜板纸", "铜版纸");
  3703. }
  3704. entity.Material = mt;
  3705. entity.ProductSize = size;
  3706. entity.ProductCount = getProductCount(count); ;//commonHelper.changeCountFromChiness(count);
  3707. entity.Craft = ct;
  3708. newmemo = "(" + entity.OrderSn + ")-";
  3709. if (isXianhuo)
  3710. {
  3711. newmemo += "现货-";
  3712. }
  3713. string newOtherMemo = "";
  3714. bool isMulity = true;
  3715. if (string.IsNullOrEmpty(entity.SplitTag))
  3716. {
  3717. isMulity = false;
  3718. }
  3719. if (acclist.Length >= 7 && !isMulity)
  3720. {
  3721. newmemo += acclist[6];
  3722. newmemo += "-";
  3723. }
  3724. if (isMulity && acclist.Length >= 8)
  3725. {
  3726. newmemo += acclist[7];
  3727. newmemo += "-";
  3728. }
  3729. for (int i = 0; i < acclist.Length; i++)
  3730. {
  3731. if ((isMulity && i == 6) || i == 5)
  3732. {
  3733. continue;
  3734. }
  3735. if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
  3736. {
  3737. newOtherMemo += acclist[i];
  3738. newOtherMemo += "-";
  3739. }
  3740. else
  3741. {
  3742. if ((i == 6 && !isMulity) || (isMulity && i == 7))
  3743. {
  3744. continue;
  3745. }
  3746. else
  3747. newmemo += acclist[i];
  3748. if (i != 2 && i != 3)
  3749. {
  3750. newmemo += "-";
  3751. }
  3752. }
  3753. }
  3754. string sName = tmcHelper.getShopSNameByName(father.seller_nick);//获取店铺简称
  3755. newmemo += (sName);
  3756. if (father.buyer_nick.IndexOf("*") < 0)
  3757. {
  3758. newmemo += ("-" + father.buyer_nick);
  3759. }
  3760. newmemo += ("-" + father.receiver_state);
  3761. if (cusInfo != null)
  3762. {
  3763. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3764. }
  3765. if (!string.IsNullOrEmpty(entity.SplitTag))
  3766. {
  3767. newmemo += "-[" + entity.SplitTag + "]";
  3768. }
  3769. newmemo = newmemo.Replace("\n", " ");
  3770. entity.seller_memo = newmemo;
  3771. entity.OtherMemo = newOtherMemo;
  3772. }
  3773. return newmemo;
  3774. }
  3775. public static bool isMultiSize(string memo)
  3776. {
  3777. bool result = false;
  3778. if (memo.Contains("合包"))
  3779. {
  3780. return result;
  3781. }
  3782. string[] memolist = memo.Split('-');
  3783. if (memolist.Length < 3)
  3784. {
  3785. return result;
  3786. }
  3787. string size_text = memolist[1];
  3788. if (size_text.Contains(")") || size_text.Contains(")"))
  3789. {
  3790. size_text = memolist[2];
  3791. }
  3792. if (size_text.Contains(",") || size_text.Contains(",") || size_text.Contains("+"))
  3793. {
  3794. result = true;
  3795. }
  3796. if (!result)
  3797. {
  3798. int a = size_text.Split(new string[] { "mm" }, StringSplitOptions.None).Length - 1;
  3799. a += size_text.Split(new string[] { "cm" }, StringSplitOptions.None).Length - 1;
  3800. if (size_text.Count(c => c == 'x') > 1 && a > 1)
  3801. {
  3802. result = true;
  3803. }
  3804. }
  3805. return result;
  3806. }
  3807. public static void sendOrderInfo(string tid, string order_status, string buyer_id, string buyer_nick, int type = 0)
  3808. {
  3809. Thread thread = new Thread(new ThreadStart(() =>
  3810. {
  3811. string url = "https://wx.lingtao8.com/api/v1/msg/new_order";
  3812. HttpClient client = new HttpClient();
  3813. string param = JsonConvert.SerializeObject(new
  3814. {
  3815. order_type = type,
  3816. order_id = tid,
  3817. buyer_nick = buyer_nick,
  3818. buyer_id = buyer_id,
  3819. order_status = order_status,
  3820. });
  3821. var request = new HttpRequestMessage
  3822. {
  3823. Method = HttpMethod.Post,
  3824. RequestUri = new Uri(url),
  3825. Content = new StringContent(param)
  3826. {
  3827. Headers =
  3828. {
  3829. ContentType = new MediaTypeHeaderValue("application/json")
  3830. }
  3831. }
  3832. };
  3833. try
  3834. {
  3835. var response = client.SendAsync(request).Result;
  3836. response.EnsureSuccessStatusCode();
  3837. }
  3838. catch (Exception e)
  3839. {
  3840. }
  3841. }));
  3842. thread.Start();
  3843. }
  3844. public static void sendOrderInfoToNewPlant(string data)
  3845. {
  3846. Thread thread = new Thread(new ThreadStart(() =>
  3847. {
  3848. string url = "http://api.industry.lingtao8.com/admin-api/erp/open/diansan/notice/order";
  3849. HttpClient client = new HttpClient();
  3850. var request = new HttpRequestMessage
  3851. {
  3852. Method = HttpMethod.Post,
  3853. RequestUri = new Uri(url),
  3854. Content = new StringContent(data)
  3855. {
  3856. Headers =
  3857. {
  3858. ContentType = new MediaTypeHeaderValue("application/json")
  3859. }
  3860. }
  3861. };
  3862. try
  3863. {
  3864. var response = client.SendAsync(request).Result;
  3865. response.EnsureSuccessStatusCode();
  3866. }
  3867. catch (Exception e)
  3868. {
  3869. XLog.SaveLog(0, "sendOrderInfoToNewPlant:" + e);
  3870. }
  3871. }));
  3872. thread.Start();
  3873. }
  3874. public static void sendOrderInfoToNewAIPlant(string data)
  3875. {
  3876. Thread thread = new Thread(new ThreadStart(() =>
  3877. {
  3878. string url = "http://121.43.175.84/admin-api/erp/open/diansan/notice/order";
  3879. HttpClient client = new HttpClient();
  3880. var request = new HttpRequestMessage
  3881. {
  3882. Method = HttpMethod.Post,
  3883. RequestUri = new Uri(url),
  3884. Content = new StringContent(data)
  3885. {
  3886. Headers =
  3887. {
  3888. ContentType = new MediaTypeHeaderValue("application/json")
  3889. }
  3890. }
  3891. };
  3892. try
  3893. {
  3894. var response = client.SendAsync(request).Result;
  3895. response.EnsureSuccessStatusCode();
  3896. }
  3897. catch (Exception e)
  3898. {
  3899. XLog.SaveLog(0, "sendOrderInfoToNewPlant:" + e);
  3900. }
  3901. }));
  3902. thread.Start();
  3903. }
  3904. public static string generateDateTimeRandomNos()
  3905. {
  3906. Random random = new Random();
  3907. const int maxAttempts = 10;
  3908. for (int i = 0; i < maxAttempts; i++)
  3909. {
  3910. string orderSn = DateTimeNow("yyMMddHHmmssfff") + RandomNumbers(random, 3);
  3911. return orderSn;
  3912. }
  3913. return "";
  3914. }
  3915. /// <summary>
  3916. /// 获取当前日期时间的指定格式字符串
  3917. /// </summary>
  3918. private static string DateTimeNow(string format)
  3919. {
  3920. return DateTime.Now.ToString(format);
  3921. }
  3922. /// <summary>
  3923. /// 生成指定长度的随机数字字符串
  3924. /// </summary>
  3925. private static string RandomNumbers(Random random, int length)
  3926. {
  3927. if (length <= 0) return string.Empty;
  3928. var rng = RandomNumberGenerator.Create();
  3929. while (true)
  3930. {
  3931. byte[] randomBytes = new byte[2]; // 2字节=16位,足够0-900范围
  3932. int value;
  3933. do
  3934. {
  3935. rng.GetBytes(randomBytes);
  3936. value = randomBytes[0] * 256 + randomBytes[1];
  3937. } while (value >= 900 * (65536 / 900)); // 拒绝采样,避免偏差
  3938. value = value % 900 + 100;
  3939. if (value > 100 && value < 1000)
  3940. {
  3941. return value.ToString();
  3942. }
  3943. }
  3944. }
  3945. }
  3946. }