commonHelper.cs 162 KB

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