commonHelper.cs 190 KB

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