commonHelper.cs 188 KB

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