commonHelper.cs 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790
  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. namespace SiteCore
  32. {
  33. public class commonHelper
  34. {
  35. public static void autoRefreshRefundState()
  36. {
  37. StringBuilder sql = new StringBuilder();
  38. sql.AppendFormat("update CE_ErpTradeRefund set RefundState=3 where RefundState=2 and DATEDIFF(hh,modified,getdate())>=72;");
  39. //sql.AppendFormat("update ce_erptradecell with(rowlock) set AfterSaleState=4,FinishAfterSaleTime=getdate() where AfterSaleState=3 and IsArbitrate=0 and DATEDIFF(hh,AfterSalePreTime,getdate())>=168;");
  40. //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;");
  41. //sql.AppendFormat("update CE_ErpTradeResponsible set VerifyState=1 where VerifyState=0 and IsArbitrate=0 and DATEDIFF(hh,createdTime,getdate())>=168;");
  42. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  43. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  44. sql = new StringBuilder();
  45. 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;");
  46. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  47. foreach (DataRow dr in dt.Rows)
  48. {
  49. string state = dr["VerifyState"].ToString();
  50. string tid = dr["tid"].ToString();
  51. int userId = Convert.ToInt32(dr["UserId"]);
  52. int reasonId = Convert.ToInt32(dr["ID"]);
  53. int type = Convert.ToInt32(dr["type"]);
  54. if (type == 0)
  55. {
  56. if (state == "0")//主管审核超时
  57. {
  58. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  59. if (ceErpTradeResponsible != null)
  60. {
  61. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  62. ceErpTradeResponsible.VerifyState = 3;
  63. ceErpTradeResponsible.Update();
  64. LogHelper.AddAfterSaleLog(tid, reasonId, "主管审核超时", userId);
  65. LogHelper.addLog(tid, 0, "主管审核超时", 4, 4);
  66. }
  67. }
  68. if (state == "3")//责任人审核超时
  69. {
  70. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  71. if (ceErpTradeResponsible != null)
  72. {
  73. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  74. ceErpTradeResponsible.VerifyState = 1;
  75. ceErpTradeResponsible.Update();
  76. LogHelper.AddAfterSaleLog(tid, reasonId, "责任人审核超时", userId);
  77. LogHelper.addLog(tid, 0, "责任人审核超时", 4, 4);
  78. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  79. bool isAll = tradeResponsibleAll(entity);
  80. if (isAll)
  81. {
  82. entity.AfterSaleState = 4;
  83. entity.FinishAfterSaleTime = DateTime.Now;
  84. entity.UpdateTime = DateTime.Now;
  85. entity.AfterSaleSupplierState = 1;
  86. ApiVo apiVo = new ApiVo();
  87. apiVo.orderNumber = entity.ctid;
  88. apiVo.actionName = "afterOver";
  89. designHelper.API_WorkCore(apiVo); //afterOver
  90. entity.Update();
  91. }
  92. }
  93. }
  94. }
  95. else
  96. {
  97. DateTime date = DateTime.Parse(dr["VerifyTime"].ToString());
  98. if (type == 2)
  99. {
  100. if (DateTime.Compare(DateTime.Now, date.AddHours(96)) <= 0)
  101. {
  102. continue;
  103. }
  104. }
  105. //车间自动审核
  106. if (state == "0")
  107. {
  108. //节假日120小时
  109. if (DateTime.Compare(DateTime.Now, date.AddHours(120)) <= 0)
  110. {
  111. continue;
  112. }
  113. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(dr["ID"].ToString());
  114. if (ceErpTradeResponsible != null)
  115. {
  116. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  117. ceErpTradeResponsible.VerifyState = 1;
  118. ceErpTradeResponsible.Update();
  119. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  120. bool isAll = tradeResponsibleAll(entity);
  121. if (isAll)
  122. {
  123. entity.AfterSaleState = 4;
  124. entity.FinishAfterSaleTime = DateTime.Now;
  125. entity.UpdateTime = DateTime.Now;
  126. entity.AfterSaleSupplierState = 1;
  127. entity.Update();
  128. ApiVo apiVo = new ApiVo();
  129. apiVo.orderNumber = entity.ctid;
  130. apiVo.actionName = "afterOver";
  131. designHelper.API_WorkCore(apiVo); //afterOver
  132. }
  133. CeErpSukuraData.createInfo(entity.ctid, 8);
  134. LogHelper.addLog(tid, 0, "审核超时,自动完成售后", 4, 4);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. public static void tradeSaleState(CeErpTradeCell ceErpTradeCell)
  141. {
  142. string sql = "select * from ce_erptraderesponsible where tid='" + ceErpTradeCell.ctid + "' and VerifyState != -1";
  143. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  144. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ceErpTradeCell.ctid);
  145. if (ceErpTradeAfterSaleExtend == null)
  146. {
  147. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  148. ceErpTradeAfterSaleExtend.tid = ceErpTradeCell.ctid;
  149. ceErpTradeAfterSaleExtend.Create();
  150. }
  151. List<string> list = new List<string>();
  152. foreach (DataRow row in dt.Rows)
  153. {
  154. list.Add(row["VerifyState"].ToString());
  155. }
  156. ceErpTradeAfterSaleExtend.VerifyStates = String.Join(",", list);
  157. ceErpTradeAfterSaleExtend.Update();
  158. }
  159. public static bool tradeResponsibleAll(CeErpTradeCell ceErpTradeCell)
  160. {
  161. //判断是否全部处理完成
  162. string sql = "select * from ce_erptraderesponsible where tid='" + ceErpTradeCell.ctid + "' and VerifyState != -1";
  163. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  164. bool isAll = true;
  165. if (dt.Rows.Count > 0 && dt.Rows.Count == 1)
  166. {
  167. }
  168. else if (dt.Rows.Count > 1)
  169. {
  170. foreach (DataRow row in dt.Rows)
  171. {
  172. if (row["VerifyState"].ToString() != "1")
  173. {
  174. isAll = false;
  175. break;
  176. }
  177. }
  178. }
  179. return isAll;
  180. }
  181. public static string getSupplierNameById(int sid)
  182. {
  183. CeErpSupplier sup = CeErpSupplier.Get(sid);
  184. if (sup != null)
  185. {
  186. return sup.ComName;
  187. }
  188. else
  189. {
  190. return "";
  191. }
  192. }
  193. public static void aftersaleSend(string ctid, string cpCode, string curUseWayBillCode)
  194. {
  195. if (ctid.IndexOf("S_") > -1)
  196. {
  197. try
  198. {
  199. string tradeCtid = ctid.Remove(0, 2);
  200. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(tradeCtid);
  201. if (ceErpTradeAfterSaleExtend == null)
  202. {
  203. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  204. ceErpTradeAfterSaleExtend.tid = tradeCtid;
  205. ceErpTradeAfterSaleExtend.ExpressNo = cpCode + "-" + curUseWayBillCode;
  206. ceErpTradeAfterSaleExtend.Create();
  207. }
  208. else
  209. {
  210. ceErpTradeAfterSaleExtend.ExpressNo = cpCode + "-" + curUseWayBillCode;
  211. ceErpTradeAfterSaleExtend.Update();
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. }
  217. }
  218. }
  219. public static string getUserNameById(int sid)
  220. {
  221. CeErpUser sup = CeErpUser.Get(sid);
  222. if (sup != null)
  223. {
  224. return sup.Name;
  225. }
  226. else
  227. {
  228. return "";
  229. }
  230. }
  231. public static int getSupplierIDByName(string name)
  232. {
  233. StringBuilder sql2 = new StringBuilder();
  234. sql2.AppendFormat("select top 1 * from CE_ErpSupplier where ComName='{0}';", name);
  235. DataTable dt2 = DbHelper.DbConn.ExecuteDataset(sql2.ToString()).Tables[0];
  236. if (dt2.Rows.Count > 0)
  237. {
  238. return Convert.ToInt32(dt2.Rows[0]["ID"]);
  239. }
  240. return 0;
  241. }
  242. public static int autoDistributeToSupplier(CeErpTradeCell trade)
  243. {
  244. if (trade.seller_memo.IndexOf("电子稿") != -1) return 0;
  245. int count = 0;
  246. string sc = trade.ProductCount;
  247. count = handleProductCount(sc, true);
  248. //string needSc = System.Text.RegularExpressions.Regex.Replace(sc, @"[^0-9]+", "");
  249. //if (!int.TryParse(needSc, out count))
  250. //{
  251. // XLog.SaveLog(0, "autoDistributeToSupplier:获取数量[" + trade.ProductCount + "]转换出错");
  252. //}
  253. //老客户指派之前供应商
  254. if (trade.IsOldCustomer == 1 && (trade.seller_memo.IndexOf("改稿") != -1 || trade.OtherMemo.IndexOf("老客户") != -1))
  255. {
  256. CeErpTrade ceErpTrade = CeErpTrade.Get(trade.tid);
  257. if (ceErpTrade != null)
  258. {
  259. //用昵称找之前的订单
  260. string name = ceErpTrade.buyer_nick;
  261. StringBuilder CeErpTradeSql = new StringBuilder();
  262. 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 order by created desc;", name, trade.tid);
  263. DataSet data = DbHelper.DbConn.ExecuteDataset(CeErpTradeSql.ToString());
  264. DataTable datatable = data.Tables[0];
  265. if (datatable.Rows.Count > 0)
  266. {
  267. CeErpTradeCell oldOrder = CeErpTradeCell.GetByTid(datatable.Rows[0]["tid"].ToString());
  268. if (oldOrder != null)
  269. {
  270. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(oldOrder.SupplierId);
  271. if (ceErpSupplier != null && ceErpSupplier.IsClose == 0)
  272. {
  273. return oldOrder.SupplierId;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. if (trade.Craft.IndexOf("门挂卡") != -1)
  280. {
  281. return 7;// ljl
  282. }
  283. else if (trade.Craft.IndexOf("打印") != -1 || trade.Craft.IndexOf("专版") != -1)
  284. {
  285. return 10; //得力
  286. }
  287. else if (trade.Craft.IndexOf("打码") != -1 || trade.Craft.IndexOf("压点线") != -1)
  288. {
  289. if (count < 300)
  290. {
  291. return 10;
  292. }
  293. else
  294. return 25;
  295. }
  296. if (trade.seller_memo.Contains("金属标") && (trade.ShopId == 26 || trade.ShopId == 45))
  297. {
  298. return 9;
  299. }
  300. //if (trade.IsOldCustomer == 1)
  301. //{
  302. // StringBuilder oldsql = new StringBuilder();
  303. // oldsql.AppendFormat("select top 1 SupplierId from view_erptradecell where buyer_nick={0} and IsAutoDistribute=1 ;",trad, trade.ProductId);
  304. //}
  305. StringBuilder sql = new StringBuilder();
  306. sql.AppendFormat("select count(0) from ce_erpproduct where id={0} and IsAutoDistribute=1 ;", trade.ProductId);
  307. sql.AppendFormat("select top 1 * from ce_erptrade where tid='{0}';", trade.tid);
  308. DataSet oDs = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  309. DataTable pDt = oDs.Tables[0];
  310. DataTable rDt = oDs.Tables[1];
  311. string material = trade.Material;
  312. material = material.Replace("铜板纸", "铜版纸");
  313. string crafts = trade.Craft;
  314. string supplierCrafts = trade.MakeSupplier;
  315. if (supplierCrafts == "")
  316. {
  317. supplierCrafts = "123123";
  318. }
  319. decimal size = getOrderSizeFromString(trade.ProductSize);
  320. if (pDt != null && pDt.Rows.Count > 0)
  321. {
  322. string receiver_state = "";
  323. if (rDt != null || rDt.Rows.Count > 0)
  324. {
  325. receiver_state = rDt.Rows[0]["receiver_state"].ToString();
  326. if (trade.IsOldCustomer == 1)
  327. {
  328. StringBuilder oldsql = new StringBuilder();
  329. 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);
  330. DataTable oldDt = DbHelper.DbConn.ExecuteDataset(oldsql.ToString()).Tables[0];
  331. if (oldDt.Rows.Count > 0)
  332. {
  333. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(Convert.ToInt32(oldDt.Rows[0]["SupplierId"]));
  334. if (ceErpSupplier != null && ceErpSupplier.IsClose == 0)
  335. {
  336. return Convert.ToInt32(oldDt.Rows[0]["SupplierId"]);
  337. }
  338. }
  339. }
  340. }
  341. try
  342. {
  343. //CHARINDEX(','+'{0}'+',',','+ProductID+',')>0
  344. sql = new StringBuilder();
  345. 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);
  346. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  347. if (dt == null || dt.Rows.Count < 1) return 0;
  348. DataView dv = new DataView(dt);
  349. int topOneProductSupplier = Convert.ToInt32(dv[0]["SupplierID"]);
  350. if (receiver_state.Length > 0)
  351. {
  352. 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);
  353. if (dv.Count > 0)
  354. {
  355. return Convert.ToInt32(dv[0]["SupplierID"]);
  356. }
  357. }
  358. if (count > 0)
  359. {
  360. if (size > 0)
  361. {
  362. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1} and SizeL<={2} and SizeW>={2} ", material, count, size);
  363. if (dv.Count > 0)
  364. {
  365. return Convert.ToInt32(dv[0]["SupplierID"]);
  366. }
  367. }
  368. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1}", material, count);
  369. if (dv.Count > 0)
  370. {
  371. LogHelper.addLog(trade.ctid, 0, "筛选供应商:产品 材质 工艺 数量 符合!"); return Convert.ToInt32(dv[0]["SupplierID"]);
  372. }
  373. }
  374. if (size > 0)
  375. {
  376. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1} and SizeL<={2} and SizeW>={2}", material, count, size);
  377. if (dv.Count > 0)
  378. {
  379. return Convert.ToInt32(dv[0]["SupplierID"]);
  380. }
  381. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and SizeL<={1} and SizeW>={1}", material, size);
  382. if (dv.Count > 0)
  383. {
  384. return Convert.ToInt32(dv[0]["SupplierID"]);
  385. }
  386. }
  387. dv.RowFilter = string.Format("ProductCrafts like '%{0}%'", material);
  388. if (count > 0)
  389. {
  390. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and MinNum<={1} and MaxNum>={1}", material, count);
  391. if (dv.Count > 0)
  392. {
  393. return Convert.ToInt32(dv[0]["SupplierID"]);
  394. }
  395. dv.RowFilter = string.Format("MinNum<={0} and MaxNum>={0}", count);
  396. if (dv.Count > 0)
  397. {
  398. return Convert.ToInt32(dv[0]["SupplierID"]);
  399. }
  400. }
  401. if (size > 0)
  402. {
  403. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' and SizeL<={1} and SizeW>={1}", material, size);
  404. if (dv.Count > 0)
  405. {
  406. return Convert.ToInt32(dv[0]["SupplierID"]);
  407. }
  408. dv.RowFilter = string.Format(" SizeL<={0} and SizeW>={0}", size);
  409. if (dv.Count > 0)
  410. {
  411. return Convert.ToInt32(dv[0]["SupplierID"]);
  412. }
  413. }
  414. dv.RowFilter = string.Format("Crafts like '%{0}%' or Crafts like '%{1}%'", crafts, supplierCrafts);
  415. if (dv.Count > 0)
  416. {
  417. return Convert.ToInt32(dv[0]["SupplierID"]);
  418. }
  419. //产品 材质符合
  420. dv.RowFilter = string.Format("ProductCrafts like '%{0}%' ", material);
  421. if (dv.Count > 0)
  422. {
  423. return Convert.ToInt32(dv[0]["SupplierID"]);
  424. }
  425. else
  426. {
  427. return topOneProductSupplier;
  428. }
  429. }
  430. catch (Exception ex)
  431. {
  432. XLog.SaveLog(0, "commmonHelper:autoDistributeToSupplier" + ex.Message);
  433. }
  434. }
  435. return 0;
  436. }
  437. public static void setDeliveryUnusualOrder()
  438. {
  439. try
  440. {
  441. StringBuilder sql = new StringBuilder();
  442. 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);");
  443. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  444. List<string> tLst = new List<string>();
  445. if (dt.Rows.Count > 0)
  446. {
  447. foreach (DataRow dr in dt.Rows)
  448. {
  449. double hour = 0;
  450. string fptime = dr["FinishPlaceTime"].ToString();
  451. if (fptime.Length > 0)
  452. {
  453. hour = DateTime.Now.Subtract(Convert.ToDateTime(fptime)).TotalHours;
  454. }
  455. else
  456. continue;
  457. int useHour = 10000;
  458. StringBuilder sqlhour = new StringBuilder();
  459. 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());
  460. DataTable dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  461. if (dthour.Rows.Count > 0)
  462. {
  463. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  464. }
  465. else
  466. {
  467. sqlhour = new StringBuilder();
  468. sqlhour.AppendFormat("select top 1 * from CE_ErpProductHour where ProductID={0} and (CHARINDEX(Craft,'{1}')>0 or Craft='*');", dr["ProductId"].ToString(), dr["Craft"].ToString());
  469. dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  470. if (dthour.Rows.Count > 0)
  471. {
  472. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  473. }
  474. else
  475. {
  476. sqlhour = new StringBuilder();
  477. sqlhour.AppendFormat("select top 1 * from CE_ErpProductHour where ProductID={0};", dr["ProductId"].ToString());
  478. dthour = DbHelper.DbConn.ExecuteDataset(sqlhour.ToString()).Tables[0];
  479. if (dthour.Rows.Count > 0)
  480. {
  481. useHour = Convert.ToInt32(dthour.Rows[0]["fhTime"]);
  482. }
  483. }
  484. }
  485. if (hour > useHour)
  486. {
  487. tLst.Add("'" + dr["ctid"].ToString() + "'");
  488. }
  489. }
  490. }
  491. sql = new StringBuilder();
  492. 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 ;");
  493. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  494. if (dt.Rows.Count > 0)
  495. {
  496. foreach (DataRow dr in dt.Rows)
  497. {
  498. double hour = 0;
  499. string fptime = dr["FinishPlaceTime"].ToString();
  500. string paytime = dr["pay_time"].ToString();
  501. DateTime dtPaytime = Convert.ToDateTime(paytime);
  502. if (fptime.Length > 0)
  503. {
  504. hour = DateTime.Now.Subtract(Convert.ToDateTime(paytime)).TotalHours;
  505. }
  506. else
  507. continue;
  508. DateTime nowtime = DateTime.Now;
  509. if (hour > 18)
  510. {
  511. tLst.Add("'" + dr["ctid"].ToString() + "'");
  512. }
  513. //if (hour > 72 && Convert.ToInt32(dr["ShopId"])==34)//公司自用
  514. //{
  515. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  516. //}
  517. //else if (nowtime.Hour >= 17)
  518. //{
  519. // if((dtPaytime.Hour >= 14 && dtPaytime.Hour < 17) || (dtPaytime.Hour == 17 && dtPaytime.Minute < 40))
  520. // {
  521. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 17:40:00";
  522. // DateTime spDatetime = Convert.ToDateTime(sptime);
  523. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  524. // {
  525. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  526. // }
  527. // }
  528. //}
  529. //else if (nowtime.Hour >= 14)
  530. //{
  531. // if(dtPaytime.Hour >= 10 && dtPaytime.Hour < 14)
  532. // {
  533. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 14:00:00";
  534. // DateTime spDatetime = Convert.ToDateTime(sptime);
  535. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  536. // {
  537. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  538. // }
  539. // }
  540. //}
  541. //else if (nowtime.Hour >= 10)
  542. //{
  543. // if (dtPaytime.Hour >= 18 || dtPaytime.Hour < 10)
  544. // {
  545. // string sptime = nowtime.Year + "/" + nowtime.Month + "/" + nowtime.Day + " 10:00:00";
  546. // DateTime spDatetime = Convert.ToDateTime(sptime);
  547. // if (spDatetime.Subtract(Convert.ToDateTime(paytime)).TotalMinutes > 0)
  548. // {
  549. // tLst.Add("'" + dr["ctid"].ToString() + "'");
  550. // }
  551. // }
  552. //}
  553. }
  554. }
  555. if (tLst.Count > 0)
  556. {
  557. string needctids = string.Join(",", tLst.ToArray());
  558. StringBuilder updsql = new StringBuilder();
  559. //DateTime unusualTime = new DateTime();
  560. updsql.AppendFormat("update ce_erptradecell with(rowlock) set unusualTag=5,UnusualTime=getDate() where ctid in ({0});", needctids);
  561. DbHelper.DbConn.ExecuteNonQuery(updsql.ToString());
  562. }
  563. }
  564. catch (Exception ex)
  565. {
  566. XLog.SaveLog(0, "更新发货异常订单错误:" + ex.Message);
  567. }
  568. splitCell2AllPlaceOrder();
  569. }
  570. public static void splitCell2AllPlaceOrder()
  571. {
  572. //
  573. int spid = 0;
  574. try
  575. {
  576. StringBuilder sql = new StringBuilder();
  577. sql.AppendFormat("select * from CE_ErpTradeCell2 where DATEDIFF(DAY, FinishPlaceTime, GETDATE())<5 and MakeSupplier like '%,%';");
  578. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  579. List<string> idList = new List<string>();
  580. foreach (DataRow dr in dt.Rows)
  581. {
  582. string msup = dr["MakeSupplier"].ToString();
  583. string[] suplist = msup.Split(',');
  584. spid = Convert.ToInt32(dr["ID"]);
  585. foreach (string supItem in suplist)
  586. {
  587. StringBuilder newsql = new StringBuilder();
  588. newsql.AppendFormat(" insert into CE_ErpTradeCell2 ([ctid],[tid],[DesignUserId],[OrderState],[CustomerUserId],[IsUrgency],[IsRefund],[IsReturn],[IsNeedBill]," +
  589. "[SupplierId],[DeliveryAddress],[CallTimes],[NoteTimes],[OvertimeUserId],[UnusualTag],[UnusualCon],[ReturnReason],[MemoOpt],[AfterSaleTime],[AfterSaleUserId]," +
  590. "[AfterSaleReason],[PlaceUserId],[AfterSaleState],[AfterSaleMethod],[AfterSaleMemo],[AfterSaleResponsible],[AfterSalePreTime],[FinishAfterSaleTime],[DeductFee]," +
  591. "[RefundFee],[HandleTime],[IsHaveNewOrder],[ResponsibleUserId],[ptid],[IsPreDelivery],[IsSample],[seller_memo],[ProductId],[WaitDesignTime],[StartDesignTime]," +
  592. "[FinishDesignTime],[FinishPlaceTime],[FinishDeliveryTime],[DesignSelfMemo],[DesignPrice],[Material],[Craft],[ProductSize],[ProductCount],[UnusualTime],[IsAutoDispatch]," +
  593. "[IsVerifyToSupplier],[CustomerMemo],[payment],[OutSid],[AfterSalePayment],[ShopId],[SplitTag],[isAfterSaleOrder],[isDianziOrder],[LastBillCpCode],[LastBillWaybillCode]," +
  594. "[pay_time],[IsSF],[IsXianHuo],[ReturnTime],[OtherMemo],[AfterSaleBackReason],[CheckMemo],[IsOldCustomer],[IsSupplierRefund],[IsReadTag],[AfterSaleMemoType]," +
  595. "[UrgencyTime],[IsOffLineOrder],[PayProofImg],[wechatTag],[MakeSupplier]) select [ctid],[tid],[DesignUserId],[OrderState],[CustomerUserId],[IsUrgency],[IsRefund]," +
  596. "[IsReturn],[IsNeedBill],[SupplierId],[DeliveryAddress],[CallTimes],[NoteTimes],[OvertimeUserId],[UnusualTag],[UnusualCon],[ReturnReason],[MemoOpt],[AfterSaleTime]," +
  597. "[AfterSaleUserId],[AfterSaleReason],[PlaceUserId],[AfterSaleState],[AfterSaleMethod],[AfterSaleMemo],[AfterSaleResponsible],[AfterSalePreTime],[FinishAfterSaleTime]," +
  598. "[DeductFee],[RefundFee],[HandleTime],[IsHaveNewOrder],[ResponsibleUserId],[ptid],[IsPreDelivery],[IsSample],[seller_memo],[ProductId],[WaitDesignTime],[StartDesignTime]," +
  599. "[FinishDesignTime],[FinishPlaceTime],[FinishDeliveryTime],[DesignSelfMemo],[DesignPrice],[Material],[Craft],[ProductSize],[ProductCount],[UnusualTime],[IsAutoDispatch]," +
  600. "[IsVerifyToSupplier],[CustomerMemo],[payment],[OutSid],[AfterSalePayment],[ShopId],[SplitTag],[isAfterSaleOrder],[isDianziOrder],[LastBillCpCode],[LastBillWaybillCode]," +
  601. "[pay_time],[IsSF],[IsXianHuo],[ReturnTime],[OtherMemo],[AfterSaleBackReason],[CheckMemo],[IsOldCustomer],[IsSupplierRefund],[IsReadTag],[AfterSaleMemoType],[UrgencyTime]," +
  602. "[IsOffLineOrder],[PayProofImg],[wechatTag],'{1}' from CE_ErpTradeCell2 where ID={0}", Convert.ToInt32(dr["ID"]), supItem);
  603. DbHelper.DbConn.ExecuteNonQuery(newsql.ToString());
  604. }
  605. idList.Add(dr["ID"].ToString());
  606. }
  607. string idsstr = string.Join(",", idList.ToArray());
  608. sql.AppendFormat("delete from CE_ErpTradeCell2 where ID in ({0})", idsstr);
  609. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  610. }
  611. catch (Exception ex)
  612. {
  613. XLog.SaveLog(0, "拆分ce_erptradecell2表的制作车间出错:" + spid + ex.Message);
  614. }
  615. }
  616. public static void DoAutoDispatch(string conn)
  617. {
  618. if (webConfig.Dispatch_TimeList.Contains(DateTime.Now.ToString("HH:mm")))
  619. {
  620. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始自动派单!"));
  621. SqlParameter[] sqlParameter ={
  622. new SqlParameter("@res", SqlDbType.VarChar, 50)};
  623. sqlParameter[0].Direction = ParameterDirection.Output;
  624. CeErpOpt.ExecuteNonQueryStore("sp_autodispatch", sqlParameter);
  625. string res = sqlParameter[0].Value.ToString();
  626. if (res == "派单完成") WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "结束自动派单!"));
  627. else WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "无法成功派单"));
  628. }
  629. //sp_autodispatch
  630. }
  631. public static void DoAutoDispatch2(string conn)
  632. {
  633. if (webConfig.Dispatch_TimeList.Contains(DateTime.Now.ToString("HH:mm")))
  634. {
  635. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始自动派单!"));
  636. SqlConnection sqlCnt = new SqlConnection(conn);
  637. try
  638. {
  639. sqlCnt.Open();
  640. string sql = "select * from view_ErpTradeCell where OrderState = 2 and ProductId <> 0";
  641. SqlDataAdapter myDataAdapter = new SqlDataAdapter(sql, sqlCnt);
  642. DataSet myDataSet = new DataSet();
  643. myDataAdapter.Fill(myDataSet, "Trade");
  644. DataTable myTable = myDataSet.Tables[0];
  645. List<string> ids = new List<string>();
  646. foreach (DataRow Dr in myTable.Rows)
  647. {
  648. if (Convert.ToInt32(Dr["OrderState"]) > 2 || Convert.ToInt32(Dr["DesignUserId"]) > 0)
  649. {
  650. continue;
  651. }
  652. ids.Add(Dr["ctid"].ToString());
  653. CeErpShop nShop = CeErpShop.GetShopIdByName(Dr["seller_nick"].ToString());
  654. string shopId = "0";
  655. if (nShop != null)
  656. {
  657. shopId = nShop.ID.ToString();
  658. }
  659. string proId = Dr["ProductId"].ToString();
  660. string Amount = Dr["payment"].ToString();
  661. string ctid = Dr["ctid"].ToString();
  662. string ctids = "";
  663. if (ctid.IndexOf("C") != -1)
  664. {
  665. ctids = getSameTradeByTid(Dr["tid"].ToString());
  666. if (ctids.Length <= 0)
  667. {
  668. continue;
  669. }
  670. }
  671. else
  672. {
  673. ctids = "'" + ctid + "'";
  674. }
  675. sql = "select top 1 * from view_ErpUser " +
  676. "where PostCode = 'Designer' and " + //设计师
  677. "OnDuty = 1 and " + //上班状态
  678. "DayOrderReceive < DayOrderLimit and " + //当日接单数小于可接单数量上限
  679. "OrderAmountLimit >= " + Amount + " and " + //额度上限大于付款金额
  680. "CHARINDEX('," + shopId + ",',','+OrgShop+ ',')>0 and " + //部门关联店铺
  681. "CHARINDEX('," + shopId + ",',','+pemShop+ ',')>0 and " + //个人关联店铺
  682. "CHARINDEX('," + proId + ",',','+pemDesign+ ',')>0 " + //个人关联产品
  683. "order by DayOrderPer, PostLevel desc, Id";
  684. SqlDataAdapter userAdapter = new SqlDataAdapter(sql, sqlCnt);
  685. DataSet userSet = new DataSet();
  686. userAdapter.Fill(userSet, "user");
  687. DataTable userTable = userSet.Tables[0];
  688. //有满足条件的设计师
  689. if (userTable.Rows.Count > 0)
  690. {
  691. SqlCommand updCMD = sqlCnt.CreateCommand();
  692. try
  693. {
  694. updCMD.Transaction = sqlCnt.BeginTransaction();//开启事务
  695. //派单
  696. updCMD.CommandText = "update CE_ErpTradeCell set OrderState = 3, IsAutoDispatch = 1, WaitDesignTime = getdate(), DesignUserId = " + userTable.Rows[0]["ID"].ToString() + " where ctid in (" + ctids + ")";
  697. updCMD.ExecuteNonQuery();
  698. //更新日数量上限和可接单比例
  699. 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();
  700. updCMD.ExecuteNonQuery();
  701. //写订单日志
  702. updCMD.CommandText = "insert into CE_ErpTradeLog(tid,OrderState,UserId,OperateTime,Con) select ctid,OrderState,0,getdate(),'自动派单' from ce_erptradecell where ctid in(" + ctids + ")";
  703. updCMD.ExecuteNonQuery();
  704. updCMD.Transaction.Commit();//提交事务(真正的从数据库中修改了数据)
  705. }
  706. catch (Exception ee)
  707. {
  708. updCMD.Transaction.Rollback();
  709. }
  710. }
  711. }
  712. string sql1 = "select ctid from view_ErpTradeCell where orderstate=3 and DesignUserId = 2125 and ctid in ('" + string.Join(",", ids) + "');";
  713. /* string sql1 = "select ctid from view_ErpTradeCell where orderstate=3 and DesignUserId = 2125 ";*/
  714. DataTable dt1 = SqlHelper.ExecuteDataSet(sql1).Tables[0];
  715. foreach (DataRow dr1 in dt1.Rows)
  716. {
  717. apiDesign.API_GetPrintData_CreateOrder(CeErpTradeCell.GetByCtid(dr1["ctid"].ToString()));
  718. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "开始派单" + dr1["ctid"].ToString() + "至设计系统!"));
  719. Thread.Sleep(1000); // 添加五秒延迟
  720. }
  721. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), "结束自动派单!"));
  722. }
  723. catch (Exception ed)
  724. {
  725. WriteLog(string.Format("派单 | {0} | {1}", DateTime.Now.ToString(), ed.Message));
  726. }
  727. finally
  728. {
  729. if (sqlCnt.State == ConnectionState.Open)
  730. sqlCnt.Close();
  731. }
  732. }
  733. }
  734. public static string getSameTradeByTid(string tid)
  735. {
  736. StringBuilder sql = new StringBuilder();
  737. sql.AppendFormat("select ctid from view_ErpTradeCell where tid='{0}';", tid);
  738. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  739. if (dt.Rows.Count > 0)
  740. {
  741. string ctids = "";
  742. foreach (DataRow dr in dt.Rows)
  743. {
  744. ctids += "'";
  745. ctids += dr["ctid"].ToString();
  746. ctids += "'";
  747. ctids += ",";
  748. }
  749. ctids = ctids.Substring(0, ctids.Length - 1);
  750. return ctids;
  751. }
  752. else
  753. return "";
  754. }
  755. public static void WriteLog(string LogText)
  756. {
  757. string sDir = System.IO.Path.GetTempPath() + @"Log\" + DateTime.Now.ToString("yyyyMM");
  758. if (!Directory.Exists(sDir))
  759. Directory.CreateDirectory(sDir);
  760. using (StreamWriter sw = new StreamWriter(sDir + @"\Log_" + DateTime.Now.ToString("dd") + ".txt", true, Encoding.UTF8))
  761. {
  762. sw.Write(LogText + System.Environment.NewLine);
  763. }
  764. }
  765. public static void UpdateRelationOrder(string ctid)
  766. {
  767. if (ctid.Length <= 0) return;
  768. CeErpTradeCell.UpdateRelationOrder(ctid);
  769. //try
  770. //{
  771. // //父订单变化,更新补差价订单
  772. // //List<string> lw = new List<string>();
  773. // //lw.Add(string.Format("OrderState={0}", father.OrderState));
  774. // //lw.Add(string.Format("CustomerUserId={0}", father.CustomerUserId));
  775. // //lw.Add(string.Format("DesignUserId={0}", father.DesignUserId));
  776. // //lw.Add(string.Format("AfterSaleState={0}", father.AfterSaleState));
  777. // //lw.Add(string.Format("IsNeedBill={0}", father.IsNeedBill));
  778. // ////lw.Add(string.Format("IsUrgency={0}", father.IsUrgency == true ? 1 : 0));
  779. // //lw.Add(string.Format("IsRefund={0}", father.IsRefund));
  780. // //lw.Add(string.Format("WaitDesignTime='{0}'", father.WaitDesignTime.ToString()));
  781. // //lw.Add(string.Format("StartDesignTime='{0}'", father.StartDesignTime.ToString()));
  782. // //lw.Add(string.Format("FinishDesignTime='{0}'", father.FinishDesignTime.ToString()));
  783. // //lw.Add(string.Format("FinishPlaceTime='{0}'", father.FinishPlaceTime.ToString()));
  784. // //lw.Add(string.Format("FinishDeliveryTime='{0}'", father.FinishDeliveryTime.ToString()));
  785. // ////lw.Add(string.Format("IsReturn={0}", father.IsReturn));
  786. // //string sqlstr = string.Join(" , ", lw.ToArray());
  787. // //StringBuilder sql = new StringBuilder();
  788. // //sql.AppendFormat("update ce_erptradecell set " + sqlstr + " where ptid='{0}'", father.tid);
  789. // ////sql.AppendFormat("update view_erptrade set status={1} where ptid={0}", father.ctid, father.status);
  790. // //DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  791. // //StringBuilder sql = new StringBuilder();
  792. // //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,");
  793. // //sql.Append("AfterSaleState=b.AfterSaleState,IsNeedBill=b.IsNeedBill,IsRefund=b.IsRefund from ce_erptradecell,ce_erptradecell as b ");
  794. // //sql.AppendFormat("where ce_erptradecell.ptid =b.tid and ce_erptradecell.ptid='{0}'", tid);//='1827905618077154637'
  795. // //DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  796. // //SqlParameter[] sqlParameter ={
  797. // // new SqlParameter("@mainctids", SqlDbType.VarChar,100),
  798. // // new SqlParameter("@res", SqlDbType.VarChar, 4000)
  799. // //};
  800. // //sqlParameter[0].Value = ctid;
  801. // //sqlParameter[1].Direction = ParameterDirection.Output;
  802. // //DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_set_bucha", sqlParameter);
  803. //}
  804. //catch (Exception ex)
  805. //{
  806. // XLog.SaveLog(0, "commmonHelper:UpdateRelationOrder" + ex.Message);
  807. //}
  808. }
  809. public static void UpdateSameOrderToDesigner(CeErpTradeCell entity, int designId)
  810. {
  811. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  812. if (trade != null)
  813. {
  814. StringBuilder sql = new StringBuilder();
  815. if (trade.type == "PDD" || trade.type == "JD")
  816. {
  817. 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);
  818. }
  819. else
  820. 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);
  821. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  822. }
  823. }
  824. public static void SetSameSupplierToOrder(CeErpTradeCell entity, int supId)
  825. {
  826. StringBuilder sql = new StringBuilder();
  827. sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set SupplierId={0} where orderstate=5 and tid='{1}';", supId, entity.tid);
  828. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  829. }
  830. public static string MidStrEx(string sourse, string startstr, string endstr)
  831. {
  832. string result = string.Empty;
  833. int startindex, endindex;
  834. try
  835. {
  836. startindex = sourse.IndexOf(startstr);
  837. if (startindex == -1)
  838. return result;
  839. string tmpstr = sourse.Substring(startindex + startstr.Length);
  840. endindex = tmpstr.IndexOf(endstr);
  841. if (endindex == -1)
  842. return result;
  843. result = tmpstr.Remove(endindex);
  844. }
  845. catch (Exception ex)
  846. {
  847. Console.WriteLine("MidStrEx Err:" + ex.Message);
  848. }
  849. return result;
  850. }
  851. public static string KeepChinese(string str)
  852. {
  853. string chineseString = "";
  854. for (int i = 0; i < str.Length; i++)
  855. {
  856. if (str[i] >= 0x4E00 && str[i] <= 0x9FA5)
  857. {
  858. chineseString += str[i];
  859. }
  860. }
  861. return chineseString;
  862. }
  863. public static string GetD3ComCode(string code, string name)
  864. {
  865. string useStr = code;
  866. if (code.Length == 0)
  867. {
  868. useStr = name;
  869. }
  870. string sql = "select * from CE_ErpMailInfo";
  871. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  872. foreach (DataRow dr in dt.Rows)
  873. {
  874. if (dr["cpCode"].ToString().IndexOf(useStr) != -1)
  875. {
  876. return dr["cpCode"].ToString();
  877. }
  878. }
  879. //声明存储结果的字符串
  880. //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," +
  881. // "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," +
  882. // "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," +
  883. // "YUNDA-CAINIAO-JA,SF-CAINIAO-GDGZ,YUNDA-CAINIAO-GDFS,";
  884. //string[] codeList = codeStr.Split(',');
  885. ////将传入参数中的中文字符添加到结果字符串中
  886. //for (int i = 0; i < codeList.Length; i++)
  887. //{
  888. // if (codeList[i].IndexOf(useStr) != -1)
  889. // {
  890. // return codeList[i];
  891. // }
  892. //}
  893. //返回保留中文的处理结果
  894. return "";
  895. }
  896. public static int getRefundTagByState(string st, int isPart = 0)
  897. {
  898. int state = 0;
  899. if (st == "NO_REFUND" || st == "SELLER_REFUSE_BUYER" || st == "CLOSED" || st == "FAILED")
  900. {
  901. state = 0;
  902. }
  903. else if (st == "REFUNDING")
  904. {
  905. state = 1;
  906. }
  907. else if (st == "REFUNDED" || st == "SUCCESS")
  908. {
  909. state = 2;
  910. }
  911. else if (st == "PART_REFUNDED" || isPart == 1)
  912. {
  913. state = 3;
  914. }
  915. else if (st == "WAIT_BUYER_RETURN_GOODS")
  916. {
  917. state = 4;
  918. }
  919. else if (st == "REJECT_REFUNDED")
  920. {
  921. state = 5;
  922. }
  923. else if (st == "WAIT_SELLER_CONFIRM_GOODS")
  924. {
  925. state = 6;
  926. }
  927. return state;
  928. }
  929. public static string getRefundStringByState(string st)
  930. {
  931. string stateStr = "";
  932. if (st == "NOT_SHIPPED")
  933. {
  934. stateStr = "待发货";
  935. }
  936. else if (st == "PART_SHIPPED")
  937. {
  938. stateStr = "部分发货";
  939. }
  940. else if (st == "SHIPPED")
  941. {
  942. stateStr = "已发货";
  943. }
  944. else if (st == "COMPLETE")
  945. {
  946. stateStr = "已完成";
  947. }
  948. else if (st == "CLOSE")
  949. {
  950. stateStr = "已关闭";
  951. }
  952. else if (st == "REFUNDED")
  953. {
  954. stateStr = "退款成功";
  955. }
  956. else if (st == "PART_REFUNDED")
  957. {
  958. stateStr = "部分退款";
  959. }
  960. else if (st == "WAIT_BUYER_RETURN_GOODS")
  961. {
  962. stateStr = "等待买家退货";
  963. }
  964. else if (st == "REJECT_REFUNDED")
  965. {
  966. stateStr = "拒绝退货";
  967. }
  968. else if (st == "WAIT_SELLER_CONFIRM_GOODS")
  969. {
  970. stateStr = "等待卖家确认收货";
  971. }
  972. else if (st == "SELLER_REFUSE_BUYER")
  973. {
  974. stateStr = "卖家拒绝退款";
  975. }
  976. else if (st == "SUCCESS")
  977. {
  978. stateStr = "退款成功";
  979. }
  980. else if (st == "CLOSED")
  981. {
  982. stateStr = "退款关闭";
  983. }
  984. else if (st == "FAILED")
  985. {
  986. stateStr = "退款失败";
  987. }
  988. return stateStr;
  989. }
  990. public static void UpdateRefundOrderState(string tid, int rstate)
  991. {
  992. StringBuilder sql = new StringBuilder();
  993. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype,refundState) values('{0}',getdate(),'refund',{1}); ", tid, rstate);
  994. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  995. }
  996. public static void checkBillResult(int billId)
  997. {
  998. CeErpBill entiy = CeErpBill.Get(billId);
  999. if (entiy != null)
  1000. {
  1001. try
  1002. {
  1003. string[] billOrderList = entiy.billOrderId.Split(',');
  1004. int iTag = 0;
  1005. entiy.fplsh = "";
  1006. entiy.fpdm = "";
  1007. entiy.fphm = "";
  1008. foreach (string billOrderId in billOrderList)
  1009. {
  1010. iTag++;
  1011. string res = taobaoHelper.get_invoicing(billId.ToString(), billOrderId);
  1012. int fcount = StrCount(res, "c_orderno");
  1013. if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  1014. {
  1015. StringBuilder sql = new StringBuilder();
  1016. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", billId.ToString());
  1017. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1018. return;
  1019. }
  1020. else if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  1021. {
  1022. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  1023. try
  1024. {
  1025. Invoicing_get_response_Obj iObj = null;
  1026. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  1027. if (iObj != null)
  1028. {
  1029. if (fcount > 1)
  1030. {
  1031. entiy.state = 4; //红冲作废
  1032. }
  1033. else
  1034. entiy.state = 2; //开票完成
  1035. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  1036. entiy.fpdm += iObj.list[0].c_fpdm;
  1037. entiy.fphm += iObj.list[0].c_fphm;
  1038. if (iTag < billOrderList.Length)
  1039. {
  1040. entiy.fplsh += ",";
  1041. entiy.fpdm += ",";
  1042. entiy.fphm += ",";
  1043. }
  1044. entiy.Update();
  1045. }
  1046. if (fcount <= 1)
  1047. {
  1048. StringBuilder sql = new StringBuilder();
  1049. sql.AppendFormat("update CE_ErpTradeCell WITH(ROWLOCK) set IsNeedBill=2 where tid='{0}';", entiy.tid);
  1050. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1051. }
  1052. }
  1053. catch (Exception ex)
  1054. {
  1055. StringBuilder sql = new StringBuilder();
  1056. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", billId.ToString());
  1057. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1058. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  1059. }
  1060. return;
  1061. }
  1062. else
  1063. {
  1064. string redError = "";
  1065. if (fcount > 1)
  1066. {
  1067. redError = "红冲失败";
  1068. }
  1069. int eidx = res.IndexOf("c_resultmsg");
  1070. string emsg = KeepChinese(res.Substring(eidx, res.Length - eidx));
  1071. //开票失败
  1072. entiy.state = 5;
  1073. entiy.failerror = entiy.failerror + (iTag + "&" + redError + emsg + "|");
  1074. entiy.Update();
  1075. return;
  1076. }
  1077. }
  1078. }
  1079. catch (Exception ex)
  1080. {
  1081. XLog.SaveLog(0, "buchajia查看开票结果错误," + ex.Message);
  1082. }
  1083. }
  1084. }
  1085. public static void insertToBuchaForDelivery(string Maintid, string posCode, string comCode, string outSid)
  1086. {
  1087. if (Maintid.Length <= 0) return;
  1088. try
  1089. {
  1090. StringBuilder sql = new StringBuilder();
  1091. 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);
  1092. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  1093. //}
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. XLog.SaveLog(0, "commhelper,insertToBuchaForDelivery,insert" + ex.Message);
  1098. //}
  1099. }
  1100. }
  1101. public static void setBuChaDelivery(string tid, string posCode, string comCode, string outSid)
  1102. {
  1103. outSid = outSid.Trim();
  1104. posCode = posCode.Trim();
  1105. comCode = comCode.Trim();
  1106. CeErpTrade mainEn = CeErpTrade.Get(tid);
  1107. if (mainEn != null)
  1108. {
  1109. if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || mainEn.status == "COMPLETE" || mainEn.status == "CLOSE") //已发货的不处理直接返回面单
  1110. {
  1111. return;
  1112. //不处理
  1113. }
  1114. string apires = apiHelper.API_LogisticsDummySend(tid, posCode);
  1115. if (apires.IndexOf("发货成功") == -1)
  1116. {
  1117. XLog.SaveLog(0, "补差价单虚拟发货失败," + tid + "," + posCode + "," + apires);
  1118. string wures = apiHelper.API_LogisticsOnlineSend(tid, posCode, comCode, outSid);
  1119. if (wures.IndexOf("发货成功") == -1)
  1120. {
  1121. XLog.SaveLog(0, "补差价单实物发货失败," + tid + "," + posCode + "," + wures);
  1122. return;
  1123. }
  1124. else
  1125. {
  1126. LogHelper.addLog(tid, 0, "补差价发货-" + comCode + "-" + outSid);
  1127. }
  1128. return;
  1129. }
  1130. else
  1131. {
  1132. LogHelper.addLog(tid, 0, "补差价发货-" + comCode + "-" + outSid);
  1133. }
  1134. }
  1135. }
  1136. public static int StrCount(string str, string constr)
  1137. {
  1138. return System.Text.RegularExpressions.Regex.Matches(str, constr).Count;
  1139. }
  1140. public static void saveErpDesignerGather()
  1141. {
  1142. string date1 = DateTime.Now.AddDays(-1).ToString();
  1143. string date2 = DateTime.Now.AddDays(-1).ToString();
  1144. //string date1 = DateTime.Now.ToString();
  1145. //string date2 = DateTime.Now.ToString();
  1146. StringBuilder sql = new StringBuilder();
  1147. 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);
  1148. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1149. foreach (DataRow dr in dt.Rows)
  1150. {
  1151. SqlParameter[] sqlParameter ={
  1152. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  1153. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  1154. new SqlParameter("@designid", SqlDbType.Int, 4)
  1155. };
  1156. sqlParameter[0].Value = date1;
  1157. sqlParameter[1].Value = date2;
  1158. sqlParameter[2].Value = Convert.ToInt32(dr["ID"]);
  1159. //CeErpTradeCell.ExecuteNonQueryStore("sp_getdesigngather", sqlParameter);
  1160. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_savedesigngather", sqlParameter);
  1161. }
  1162. new_Designer_Rate(date1);
  1163. }
  1164. public static void new_Designer_Rate(String date1)
  1165. {
  1166. /*String date1 = DateTime.Now.ToString();*/
  1167. /* if (date1 ==null) {
  1168. date1 = DateTime.Now.ToString();
  1169. }*/
  1170. DateTime currentDate = DateTime.Parse(date1);
  1171. // 获取指定日期的开始时间
  1172. DateTime startTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 0, 0, 0);//日
  1173. // 获取指定日期的结束时间(即下一天的开始时间,减去1秒)
  1174. DateTime endTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 23, 59, 59).AddSeconds(-1);//日
  1175. DateTime now = DateTime.Now; // 获取当前日期和时间
  1176. DateTime dateOnly = now.Date; // 限制日期为年月日
  1177. StringBuilder sql = new StringBuilder();
  1178. CeErpDesignerFinishRateNew.Del(startTime.ToString("yyyy-MM-dd HH:mm:ss"));
  1179. 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"));
  1180. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1181. foreach (DataRow dr in dt.Rows)
  1182. {
  1183. CeErpDesignerFinishRateNew ceErpDesignerFinishRateNew = new CeErpDesignerFinishRateNew();
  1184. if (!Convert.IsDBNull(dr["DesignUserId"]))
  1185. {
  1186. ceErpDesignerFinishRateNew.did = Convert.ToInt32(dr["DesignUserId"] == null ? 0 : dr["DesignUserId"]);
  1187. }
  1188. if (!Convert.IsDBNull(dr["OrgID"]))
  1189. {
  1190. ceErpDesignerFinishRateNew.orgid = Convert.ToInt32(dr["OrgID"] == null ? 0 : dr["OrgID"]);
  1191. }
  1192. if (!Convert.IsDBNull(dr["DesignerName"]))
  1193. {
  1194. ceErpDesignerFinishRateNew.name = dr["DesignerName"].ToString() == null ? "" : dr["DesignerName"].ToString();
  1195. }
  1196. if (!Convert.IsDBNull(dr["Amount"]))
  1197. {
  1198. ceErpDesignerFinishRateNew.Amount = dr["Amount"].ToString() == null ? "" : dr["Amount"].ToString();
  1199. }
  1200. if (!Convert.IsDBNull(dr["AllOrder"]))
  1201. {
  1202. ceErpDesignerFinishRateNew.AllOrder = Convert.ToInt32(dr["AllOrder"] == null ? 0 : dr["AllOrder"]);
  1203. }
  1204. if (!Convert.IsDBNull(dr["FinalizationRate"]))
  1205. {
  1206. ceErpDesignerFinishRateNew.FinalizationRate = Convert.ToInt32(dr["FinalizationRate"] == null ? 0 : dr["FinalizationRate"]);
  1207. }
  1208. if (!Convert.IsDBNull(dr["afterSaleSum"]))
  1209. {
  1210. ceErpDesignerFinishRateNew.afterSaleSum = Convert.ToInt32(dr["afterSaleSum"] == null ? 0 : dr["afterSaleSum"]);
  1211. }
  1212. if (!Convert.IsDBNull(dr["resolutionSum"]))
  1213. {
  1214. ceErpDesignerFinishRateNew.resolutionSum = Convert.ToInt32(dr["resolutionSum"] == null ? 0 : dr["resolutionSum"]);
  1215. }
  1216. if (!Convert.IsDBNull(dr["splitSum"]))
  1217. {
  1218. ceErpDesignerFinishRateNew.splitSum = Convert.ToInt32(dr["splitSum"] == null ? 0 : dr["splitSum"]);
  1219. }
  1220. if (!Convert.IsDBNull(dr["splitSum2"]))
  1221. {
  1222. ceErpDesignerFinishRateNew.csplitum = Convert.ToInt32(dr["splitSum2"] == null ? 0 : dr["splitSum2"]);
  1223. }
  1224. if (!Convert.IsDBNull(dr["FinalizationRate2"]))
  1225. {
  1226. ceErpDesignerFinishRateNew.FinalizationRate2 = Convert.ToInt32(dr["FinalizationRate2"] == null ? 0 : dr["FinalizationRate2"]);
  1227. }
  1228. if (!Convert.IsDBNull(dr["AllOrder"]) && !Convert.IsDBNull(dr["FinalizationRate"]) && !Convert.IsDBNull(dr["splitSum2"]) && !Convert.IsDBNull(dr["splitSum"]))
  1229. {
  1230. try
  1231. {
  1232. int num1 = Convert.ToInt32(dr["FinalizationRate"]) + Convert.ToInt32(dr["splitSum"]);
  1233. int num2 = Convert.ToInt32(dr["AllOrder"]) + Convert.ToInt32(dr["splitSum2"]);
  1234. if (num2 != 0)
  1235. {
  1236. double result = (double)num1 / num2;
  1237. if (double.IsNaN(result))
  1238. {
  1239. result = 0;
  1240. }
  1241. double roundedResult = Math.Round(result, 4);
  1242. ceErpDesignerFinishRateNew.onFinalizationRate = roundedResult.ToString();
  1243. int num3 = Convert.ToInt32(dr["refund"]);
  1244. double result2 = (double)num3 / num2;
  1245. if (double.IsNaN(result2))
  1246. {
  1247. result2 = 0;
  1248. }
  1249. double roundedResult2 = Math.Round(result2, 4);
  1250. ceErpDesignerFinishRateNew.onRefund = roundedResult2.ToString();
  1251. }
  1252. else
  1253. {
  1254. ceErpDesignerFinishRateNew.onFinalizationRate = "0.0000";
  1255. ceErpDesignerFinishRateNew.onRefund = "0.0000";
  1256. }
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. ceErpDesignerFinishRateNew.onFinalizationRate = "0";
  1261. }
  1262. }
  1263. ceErpDesignerFinishRateNew.ctime = startTime;
  1264. ceErpDesignerFinishRateNew.Createtime = now;
  1265. if (!Convert.IsDBNull(dr["refund"]))
  1266. {
  1267. ceErpDesignerFinishRateNew.refund = Convert.ToInt32(dr["refund"] == null ? 0 : dr["refund"]);
  1268. }
  1269. ceErpDesignerFinishRateNew.Create();
  1270. }
  1271. }
  1272. public static DateTime FirstDayOfMonth(DateTime datetime)
  1273. {
  1274. return datetime.AddDays(1 - datetime.Day);
  1275. }
  1276. public static DateTime LastDayOfMonth(DateTime datetime)
  1277. {
  1278. return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
  1279. }
  1280. public static DateTime GetDateTimeWeekFirstDaySun(DateTime dateTime)
  1281. {
  1282. DateTime firstWeekDay = DateTime.Now;
  1283. try
  1284. {
  1285. //得到是星期几,然后从当前日期减去相应天数
  1286. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1287. int daydiff = (-1) * weeknow;
  1288. firstWeekDay = dateTime.AddDays(daydiff);
  1289. }
  1290. catch { }
  1291. return firstWeekDay;
  1292. }
  1293. public static DateTime GetDateTimeWeekFirstDayMon(DateTime dateTime)
  1294. {
  1295. DateTime firstWeekDay = DateTime.Now;
  1296. try
  1297. {
  1298. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1299. //星期一为第一天,weeknow等于0时,要向前推6天。
  1300. weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1));
  1301. int daydiff = (-1) * weeknow;
  1302. firstWeekDay = dateTime.AddDays(daydiff);
  1303. }
  1304. catch { }
  1305. return firstWeekDay;
  1306. }
  1307. public static DateTime GetDateTimeWeekLastDaySat(DateTime dateTime)
  1308. {
  1309. DateTime lastWeekDay = DateTime.Now;
  1310. try
  1311. {
  1312. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1313. int daydiff = (7 - weeknow) - 1;
  1314. lastWeekDay = dateTime.AddDays(daydiff);
  1315. }
  1316. catch { }
  1317. return lastWeekDay;
  1318. }
  1319. public static DateTime GetDateTimeWeekLastDaySun(DateTime dateTime)
  1320. {
  1321. DateTime lastWeekDay = DateTime.Now;
  1322. try
  1323. {
  1324. int weeknow = Convert.ToInt32(dateTime.DayOfWeek);
  1325. weeknow = (weeknow == 0 ? 7 : weeknow);
  1326. int daydiff = (7 - weeknow);
  1327. lastWeekDay = dateTime.AddDays(daydiff);
  1328. }
  1329. catch { }
  1330. return lastWeekDay;
  1331. }
  1332. public static void updateOrderStateForShipped(string ctid, int ost, string stateType)
  1333. {
  1334. try
  1335. {
  1336. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  1337. if (entity != null)
  1338. {
  1339. if (entity.isAfterSaleOrder == 1) return;
  1340. if (stateType == "updatestate_complete")
  1341. {
  1342. if (entity.IsPreDelivery == 1) return;
  1343. entity.OrderState = 8;
  1344. entity.Update();
  1345. if (entity.ProductId == 9 || entity.ProductId == 17 || entity.ProductId == 20 || entity.ProductId == 29 || entity.ProductId == 30)//卡片、手提袋价格自动核算
  1346. {
  1347. CeErpDesignerBill.updateDesignerBill(entity.ctid, entity.ProductId);
  1348. LogHelper.addDesignerBillLog(entity.ctid, 0, "自动核算设计费", "系统", 1);
  1349. }
  1350. else if (entity.ProductId == 22)
  1351. {
  1352. CeErpDesignerBill.updateBill(entity.ctid, entity.ProductId, entity.seller_memo);
  1353. LogHelper.addDesignerBillLog(entity.ctid, 0, "自动核算设计费", "系统", 1);
  1354. }
  1355. }
  1356. else if (stateType == "updatestate_shipped")
  1357. {
  1358. if (entity.IsPreDelivery == 1) return;
  1359. entity.OrderState = 7;
  1360. entity.Update();
  1361. }
  1362. else if (stateType == "updatestate_close")
  1363. {
  1364. entity.OrderState = 9;
  1365. entity.Update();
  1366. }
  1367. }
  1368. else
  1369. {
  1370. StringBuilder sql = new StringBuilder();
  1371. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{0}',{1},'{2}',getdate());", ctid, ost, stateType);
  1372. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1373. }
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. XLog.SaveLog(0, "updateOrderStateForShipped函数出错," + ctid + "," + ex.Message);
  1378. StringBuilder sql = new StringBuilder();
  1379. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{0}',{1},'{2}',getdate());", ctid, ost, stateType);
  1380. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  1381. }
  1382. }
  1383. public static string changeCountFromChiness(string countStr)
  1384. {
  1385. try
  1386. {
  1387. return handleProductCount(countStr).ToString();
  1388. }
  1389. catch (Exception ex)
  1390. {
  1391. return countStr;
  1392. }
  1393. }
  1394. public static int getIntCountFromString(string fstr)
  1395. {
  1396. try
  1397. {
  1398. string str = fstr;
  1399. string r = @"[0-9]+";
  1400. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1401. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1402. int count = 0;
  1403. foreach (Match m in mc)
  1404. {
  1405. string s = m.Groups[0].Value;
  1406. int cc = Convert.ToInt32(s);
  1407. if (count == 0)
  1408. {
  1409. count = cc;
  1410. }
  1411. else
  1412. {
  1413. count = count * cc;
  1414. }
  1415. }
  1416. return count;
  1417. }
  1418. catch (Exception ex)
  1419. {
  1420. return 0;
  1421. }
  1422. }
  1423. public static int getPlaceProductCount(string count_str)
  1424. {
  1425. count_str = count_str.Trim();
  1426. string[] count_list = count_str.Split(',');
  1427. int count = 0;
  1428. foreach (string item in count_list)
  1429. {
  1430. int tem_count = getSingleIntCountFromString(item);
  1431. if (tem_count > count)
  1432. {
  1433. count = tem_count;
  1434. }
  1435. }
  1436. return count;
  1437. }
  1438. public static int getSingleIntCountFromString(string fstr)
  1439. {
  1440. try
  1441. {
  1442. string str = fstr;
  1443. string r = @"[0-9]+";
  1444. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1445. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1446. if (mc.Count <= 0) return 0;
  1447. if (mc.Count == 1)
  1448. {
  1449. string s = mc[0].Groups[0].Value;
  1450. int cc = Convert.ToInt32(s);
  1451. return cc;
  1452. }
  1453. else if (mc.Count > 1)
  1454. {
  1455. string s = mc[1].Groups[0].Value;
  1456. int cc = Convert.ToInt32(s);
  1457. return cc;
  1458. }
  1459. //foreach (Match m in mc)
  1460. //{
  1461. // string s = m.Groups[0].Value;
  1462. // int cc = Convert.ToInt32(s);
  1463. // if (count == 0)
  1464. // {
  1465. // count = cc;
  1466. // }
  1467. // else
  1468. // {
  1469. // count = count * cc;
  1470. // }
  1471. //}
  1472. return 0;
  1473. }
  1474. catch (Exception ex)
  1475. {
  1476. return 0;
  1477. }
  1478. }
  1479. public static int handleProductCount(string pCount, bool isSingle = false)
  1480. {
  1481. string cstr = pCount;
  1482. if (cstr.IndexOf("百万") != -1)
  1483. {
  1484. cstr = cstr.Replace("百万", "000000");
  1485. }
  1486. else if (cstr.IndexOf("十万") != -1)
  1487. {
  1488. cstr = cstr.Replace("十万", "00000");
  1489. }
  1490. else if (cstr.IndexOf("万") != -1)
  1491. {
  1492. cstr = cstr.Replace("万", "0000");
  1493. }
  1494. else if (cstr.IndexOf("千") != -1)
  1495. {
  1496. cstr = cstr.Replace("千", "000");
  1497. }
  1498. else if (cstr.IndexOf("百") != -1)
  1499. {
  1500. cstr = cstr.Replace("百", "00");
  1501. }
  1502. else if (cstr.IndexOf("十") != -1)
  1503. {
  1504. cstr = cstr.Replace("十", "0");
  1505. }
  1506. int rCount = 0;
  1507. if (isSingle) rCount = getSingleIntCountFromString(cstr);
  1508. else rCount = getIntCountFromString(cstr);
  1509. return rCount;
  1510. }
  1511. public static decimal getOrderSizeFromString(string size)
  1512. {
  1513. string rsize = size.Replace("mm", "");
  1514. string[] sizeList = rsize.Split('x');
  1515. if (sizeList.Length != 2) return 0;
  1516. try
  1517. {
  1518. decimal mianji = Convert.ToDecimal(sizeList[0]) * Convert.ToDecimal(sizeList[1]);
  1519. return mianji;
  1520. }
  1521. catch (Exception ex)
  1522. {
  1523. return 0;
  1524. }
  1525. return 0;
  1526. }
  1527. public static string getDateFromString(string fstr)
  1528. {
  1529. try
  1530. {
  1531. string str = fstr;
  1532. string r = @"[0-9]+";
  1533. Regex reg = new Regex(r, RegexOptions.IgnoreCase | RegexOptions.Singleline, TimeSpan.FromSeconds(2));//2秒后超时
  1534. MatchCollection mc = reg.Matches(str);//设定要查找的字符串
  1535. if (mc.Count < 3) return "";
  1536. int tag = 0;
  1537. string datestr = "";
  1538. foreach (Match m in mc)
  1539. {
  1540. string s = m.Groups[0].Value;
  1541. datestr += s;
  1542. if (tag < 2) { datestr += "-"; }
  1543. else break;
  1544. tag++;
  1545. }
  1546. DateTime dd = Convert.ToDateTime(datestr);
  1547. return datestr;
  1548. }
  1549. catch (Exception ex)
  1550. {
  1551. return "";
  1552. }
  1553. }
  1554. public static void DeleteOriginalOrderIfIsSplitOrder(string tid, string splitTag)
  1555. {
  1556. if (splitTag.Length > 0)
  1557. {
  1558. CeErpTradeCell.DelByCtid(tid);
  1559. }
  1560. }
  1561. public static bool SetOrderDummyDelivery(string tid)
  1562. {
  1563. try
  1564. {
  1565. CeErpTrade trade = CeErpTrade.Get(tid);
  1566. if (trade != null)
  1567. {
  1568. string xuniapires = apiHelper.API_LogisticsDummySend(tid, trade.posCode);
  1569. if (xuniapires.IndexOf("成功") != -1)
  1570. {
  1571. LogHelper.addLog(tid, 0, "电子稿自动发货");
  1572. return true;
  1573. }
  1574. else if (xuniapires.IndexOf("失败") != -1)
  1575. {
  1576. string chiness = KeepChinese(xuniapires);
  1577. XLog.SaveLog(0, "setOrderDummyDelivery虚拟发货失败," + tid + "," + chiness);
  1578. return false;
  1579. }
  1580. }
  1581. return false;
  1582. }
  1583. catch (Exception ex)
  1584. {
  1585. XLog.SaveLog(0, "setOrderDummyDelivery虚拟发货出错," + tid + "," + ex.Message);
  1586. return false;
  1587. }
  1588. }
  1589. public static void getuserId()
  1590. {
  1591. string createtime = "2024-01-01 00:50:39.000";
  1592. string textContent = "";
  1593. int row_num = 100;
  1594. Dictionary<string, List<string>> shop_userNick = new Dictionary<string, List<string>>();
  1595. while (row_num == 100)
  1596. {
  1597. 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);
  1598. DataTable table = DbHelper.DbConn.ExecuteDataset(conSql).Tables[0];
  1599. if (table != null)
  1600. {
  1601. row_num = table.Rows.Count;
  1602. foreach (DataRow row in table.Rows)
  1603. {
  1604. string posCode = row["posCode"].ToString();
  1605. string buyer_nick = row["buyer_nick"].ToString();
  1606. createtime = row["pay_time"].ToString();
  1607. List<string> userNickName = new List<string>();
  1608. if (shop_userNick.ContainsKey(posCode))
  1609. {
  1610. shop_userNick.TryGetValue(posCode, out userNickName);
  1611. }
  1612. userNickName.Add(buyer_nick);
  1613. userNickName = userNickName.Distinct().ToList();
  1614. if (userNickName.Count == 10)
  1615. {
  1616. sendApi(posCode, userNickName);
  1617. userNickName = new List<string>();
  1618. }
  1619. if (shop_userNick.ContainsKey(posCode))
  1620. {
  1621. shop_userNick[posCode] = userNickName;
  1622. }
  1623. else
  1624. {
  1625. shop_userNick.Add(posCode, userNickName);
  1626. }
  1627. }
  1628. }
  1629. }
  1630. foreach (string key in shop_userNick.Keys)
  1631. {
  1632. List<string> nameList = shop_userNick[key];
  1633. sendApi(key, nameList);
  1634. }
  1635. }
  1636. static void sendApi(string posCode, List<string> userNickName)
  1637. {
  1638. string textContent = "";
  1639. List<api_userId_response.ContentItem> buyerIds = apiHelper.API_GetUserId(posCode, string.Join(",", userNickName));
  1640. if (buyerIds != null && buyerIds.Count > 0)
  1641. {
  1642. foreach (api_userId_response.ContentItem item in buyerIds)
  1643. {
  1644. if (item != null && !string.IsNullOrEmpty(item.buyerOpenUid))
  1645. {
  1646. 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);
  1647. }
  1648. }
  1649. try
  1650. {
  1651. StreamWriter fs = new StreamWriter("C:/Users/231010/Desktop/updateSql.txt", true);
  1652. fs.WriteLine(textContent);
  1653. fs.Close();
  1654. }
  1655. catch (Exception e)
  1656. {
  1657. }
  1658. }
  1659. }
  1660. public static designApiResponseVo checkOrderListDesignInfo(string tid, string ctid = "")
  1661. {
  1662. if (string.IsNullOrEmpty(tid))
  1663. {
  1664. return new designApiResponseVo(-1, "无订单信息");
  1665. }
  1666. if (!string.IsNullOrEmpty(ctid))
  1667. {
  1668. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1669. if (ceErpTradeCellExtend != null)
  1670. {
  1671. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  1672. {
  1673. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  1674. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  1675. return new designApiResponseVo(200, "");
  1676. }
  1677. if ("内部".Equals(ceErpTradeCellExtend.ToType))
  1678. {
  1679. return new designApiResponseVo(-1, "设计系统判断内部");
  1680. }
  1681. }
  1682. }
  1683. string info_sql = string.Format("SELECT ctid,ProductId,seller_memo FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}' AND OrderState < 5", tid);
  1684. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  1685. string check_info = "无订单信息";
  1686. if (data.Rows.Count > 0)
  1687. {
  1688. bool need_send = false;
  1689. bool has_design = false;
  1690. foreach (DataRow row in data.Rows)
  1691. {
  1692. CeErpTradeCell cell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  1693. if (cell != null)
  1694. {
  1695. if (cell.DesignUserId == 0 || cell.DispatchSort == 2 || cell.ctid.Contains("S_"))
  1696. {
  1697. designApiResponseVo result = checkOrderDesignInfo(cell, "", data);
  1698. check_info = result.msg;
  1699. if (result.code == 200)
  1700. {
  1701. need_send = true;
  1702. has_design = false;
  1703. }
  1704. }
  1705. else
  1706. {
  1707. has_design = true;
  1708. }
  1709. }
  1710. }
  1711. if (need_send && !has_design)
  1712. {
  1713. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where tid='" + tid + "' AND OrderState < 5;";
  1714. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  1715. return new designApiResponseVo(200, "");
  1716. }
  1717. }
  1718. return new designApiResponseVo(-1, check_info);
  1719. }
  1720. 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 };
  1721. 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 };
  1722. static List<int> no_design_shops = new List<int>() { 134, 63, 64, 66 };
  1723. public static designApiResponseVo checkOrderDesignInfo(CeErpTradeCell ceErpTradeCell, string post = "", DataTable dt = null)
  1724. {
  1725. if (ceErpTradeCell.DispatchSort == 2)
  1726. {
  1727. return new designApiResponseVo(200, "");
  1728. }
  1729. if (ceErpTradeCell.ProductId == 0)
  1730. {
  1731. return new designApiResponseVo(-1, "订单无品类");
  1732. }
  1733. if (ceErpTradeCell.ProductId == 1797 && ceErpTradeCell.seller_memo.Contains("手绘"))
  1734. {
  1735. return new designApiResponseVo(200, "");
  1736. }
  1737. if (ceErpTradeCell.isDianziOrder == 1)
  1738. {
  1739. return new designApiResponseVo(200, "");
  1740. }
  1741. if ((post != "SysAdmin" && post != "Summarize"))
  1742. {
  1743. if (ceErpTradeCell.DesignUserId != 0 && (ceErpTradeCell.DispatchSort != 2 && !ceErpTradeCell.ctid.Contains("S_")))
  1744. {
  1745. return new designApiResponseVo(-1, "已有设计师无法指派");
  1746. }
  1747. string info_sql = string.Format("SELECT count(*) as total FROM [dbo].[Ce_ErpDesignInfo] WHERE type = 1 and tarId = 3542 and shopId = {0}", ceErpTradeCell.ShopId);
  1748. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  1749. int a = Convert.ToInt32(data.Rows[0]["total"]);
  1750. bool drop = false;
  1751. if (DateTime.Now.Hour >= 17 && DateTime.Now.Hour <= 7 && products.IndexOf(ceErpTradeCell.ProductId) > -1 && (ceErpTradeCell.ShopId == 14 || ceErpTradeCell.ShopId == 56))
  1752. {
  1753. drop = false;
  1754. }
  1755. if (!drop && no_design_shops.IndexOf(ceErpTradeCell.ShopId) == -1)
  1756. {
  1757. CeErpDesignInfo ceErpDesignInfo = CeErpDesignInfo.GetByShopDesign(3542, ceErpTradeCell.ShopId, ceErpTradeCell.ProductId);
  1758. if (ceErpDesignInfo == null)
  1759. {
  1760. return new designApiResponseVo(-1, "该店铺无该技能权限");
  1761. }
  1762. }
  1763. //卡片五款
  1764. if (products.IndexOf(ceErpTradeCell.ProductId) > -1 && ceErpTradeCell.ShopId > 0)
  1765. {
  1766. bool num_bool = true;
  1767. bool size_bool = false;
  1768. int min_num = 2;
  1769. int num = 0;
  1770. if (shops.IndexOf(ceErpTradeCell.ShopId) == -1)//限制不是全品的店铺限制
  1771. {
  1772. /*if (ceErpTradeCell.payment >= 500)
  1773. {
  1774. return new designApiResponseVo(-1, "订单价格超出");
  1775. }*/
  1776. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  1777. string memo = ceErpTradeCell.seller_memo.Replace("MM", "mm").Replace("CM", "cm");
  1778. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  1779. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  1780. string size = "";
  1781. double min_width = 90;
  1782. double min_height = 90;
  1783. double width = 0;
  1784. double height = 0;
  1785. try
  1786. {
  1787. num = matches.Count;
  1788. foreach (System.Text.RegularExpressions.Match match in matches)
  1789. {
  1790. if (match.Success)
  1791. {
  1792. size = match.Groups[0].Value;
  1793. if (size.Contains("cm"))
  1794. {
  1795. size = size.Replace("cm", "");
  1796. string[] size_list = size.Split('x');
  1797. if (size_list.Length > 1)
  1798. {
  1799. width = Convert.ToDouble(size_list[0]) * 10;
  1800. height = Convert.ToDouble(size_list[1]) * 10;
  1801. }
  1802. }
  1803. else if (size.Contains("mm"))
  1804. {
  1805. size = size.Replace("mm", "");
  1806. string[] size_list = size.Split('x');
  1807. if (size_list.Length > 1)
  1808. {
  1809. width = Convert.ToDouble(size_list[0]);
  1810. height = Convert.ToDouble(size_list[1]);
  1811. }
  1812. }
  1813. if (width >= min_width && height >= min_height && height >= min_width && width >= min_height)
  1814. {
  1815. size_bool = true;
  1816. break;
  1817. }
  1818. else
  1819. {
  1820. size_bool = false;
  1821. }
  1822. }
  1823. }
  1824. }
  1825. catch (Exception ex)
  1826. {
  1827. }
  1828. num = getSellerMemoNum(ceErpTradeCell.seller_memo);
  1829. if (dt != null && dt.Rows != null && dt.Rows.Count > 1)
  1830. {
  1831. foreach (DataRow item in dt.Rows)
  1832. {
  1833. int tempNum = 0;
  1834. if (!string.IsNullOrEmpty(item["ProductId"].ToString()))
  1835. {
  1836. if (Convert.ToInt32(item["ProductId"]) == ceErpTradeCell.ProductId)
  1837. {
  1838. tempNum = getSellerMemoNum(item["seller_memo"].ToString());
  1839. tempNum = tempNum == 0 ? 1 : tempNum;
  1840. }
  1841. }
  1842. num += tempNum;
  1843. }
  1844. }
  1845. //2款不进
  1846. if (num < min_num)
  1847. {
  1848. num_bool = false;
  1849. }
  1850. if (!num_bool && !size_bool)
  1851. {
  1852. return new designApiResponseVo(-1, "尺寸小于90x90或款数小于2");
  1853. }
  1854. }
  1855. }
  1856. }
  1857. return new designApiResponseVo(200, "");
  1858. }
  1859. private static int getSellerMemoNum(string memo)
  1860. {
  1861. int num = 0;
  1862. string pattern = @"\b(\d{1,5}[x\*]\d{1,5}(mm|cm))\b";
  1863. Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline, TimeSpan.FromSeconds(2));//2秒后超时
  1864. MatchCollection matches = reg.Matches(memo);//设定要查找的字符串
  1865. if (memo.Contains("刮刮"))
  1866. {
  1867. num = Math.Max(num - 1, 1);
  1868. }
  1869. pattern = @"(\d+)款";
  1870. matches = Regex.Matches(memo, pattern);
  1871. try
  1872. {
  1873. num = Math.Max(num - matches.Count, 0);
  1874. foreach (System.Text.RegularExpressions.Match match in matches)
  1875. {
  1876. if (match.Success)
  1877. {
  1878. num += Convert.ToInt32(match.Groups[1].Value);
  1879. break;
  1880. }
  1881. }
  1882. }
  1883. catch (Exception ex)
  1884. {
  1885. }
  1886. return num;
  1887. }
  1888. private static string cytUserId = "77886";
  1889. public static void sendCytAfterSale(CeErpTradeCell entity)
  1890. {
  1891. try
  1892. {
  1893. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  1894. string after = "";
  1895. if (entity != null && entity.AfterSaleReason.Contains("质量问题"))
  1896. {
  1897. after = "质量问题";
  1898. }
  1899. else if (entity != null && entity.AfterSaleReason.Contains("发货问题"))
  1900. {
  1901. after = "没收到货";
  1902. }
  1903. else
  1904. {
  1905. after = "其他问题";
  1906. }
  1907. string refund_type = "退款退货";
  1908. if (entity.supRefundType != null && entity.supRefundType == "重印" && (after == "质量问题" || after == "其他问题"))
  1909. {
  1910. refund_type = "补印";
  1911. }
  1912. JObject jsonObject12 = new JObject
  1913. {
  1914. { "Userid",cytUserId },
  1915. //{ "pwd", "lt666888" },
  1916. { "LTOrderId", entity.ctid },
  1917. { "IdCode", entity.OrderSn },
  1918. { "RefundType", refund_type },
  1919. { "ReprintReasons", after },
  1920. { "ReasonsImgUrls", entity.AfterSaleSupplierImg },
  1921. { "ReasonRemarks", ceErpTradeAfterSaleExtend.supplierResponsible }
  1922. };
  1923. /**JObject jsonObject12 = new JObject
  1924. {
  1925. { "Userid", "10095" },
  1926. { "pwd", "test123456" },
  1927. { "LTOrderId", "test123456" },
  1928. { "RefundType", "退款退货" },
  1929. { "ReprintReasons", "其他问题" },
  1930. { "ReasonRemarks", "测试" }
  1931. };**/
  1932. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/ApplyOrderRefund", jsonObject12.ToString());
  1933. JObject jsonObjects1 = JObject.Parse(response1);
  1934. string msg = (string)jsonObjects1["msg"];
  1935. LogHelper.addLog(entity.ctid, 0, "CYT售后单推送:" + msg);
  1936. }
  1937. catch (Exception ex)
  1938. {
  1939. LogHelper.addLog(entity.ctid, 0, "CYT售后单推送:" + ex.ToString());
  1940. }
  1941. }
  1942. public static void sendCytExpress(CeErpExpressInfo exinfo)
  1943. {
  1944. try
  1945. {
  1946. if (exinfo == null)
  1947. {
  1948. return;
  1949. }
  1950. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(exinfo.tid);
  1951. if (ceErpTradeCell == null)
  1952. {
  1953. return;
  1954. }
  1955. JObject jsonObject12 = new JObject
  1956. {
  1957. { "Userid",cytUserId },
  1958. //{ "pwd", "lt666888" },
  1959. { "LTOrderId", ceErpTradeCell.OrderSn },
  1960. { "CourierNumber", exinfo.out_sid },
  1961. { "ExpressCompanyName", exinfo.company_name }
  1962. };
  1963. string response1 = HttpPost("http://www.kiy.cn/webapi/Himall.NewShop.UpdOrderExpress", jsonObject12.ToString());
  1964. JObject jsonObjects1 = JObject.Parse(response1);
  1965. string msg = (string)jsonObjects1["msg"];
  1966. LogHelper.addLog(exinfo.tid, 0, "CYT售后单推送:" + msg);
  1967. }
  1968. catch (Exception ex)
  1969. {
  1970. LogHelper.addLog(exinfo.tid, 0, "CYT售后单推送:" + ex.ToString());
  1971. }
  1972. }
  1973. public static void getCytPrice(CeErpTradeCell entity)
  1974. {
  1975. try
  1976. {
  1977. if (entity.seller_memo.IndexOf("种子纸") > -1)
  1978. {
  1979. return;
  1980. }
  1981. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  1982. double price = 0;
  1983. if (cp == null)
  1984. {
  1985. JObject jsonObject12 = new JObject
  1986. {
  1987. { "UserId", cytUserId },
  1988. { "Pwd", "lt666888" },
  1989. { "Filename", entity.seller_memo }
  1990. };
  1991. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  1992. JObject jsonObjects1 = JObject.Parse(response1);
  1993. string ms1g = (string)jsonObjects1["msg"];
  1994. if (ms1g == "报价成功")
  1995. {
  1996. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  1997. string data = (string)jsonObject1["price"];
  1998. 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 + "');";
  1999. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2000. price = Convert.ToDouble(data);
  2001. }
  2002. else
  2003. {
  2004. 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 + "');";
  2005. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2006. return;
  2007. }
  2008. }
  2009. String[] beizhu = entity.seller_memo.Split('-');
  2010. String chanp = "";
  2011. if (beizhu.Length > 1)
  2012. {
  2013. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  2014. }
  2015. else
  2016. {
  2017. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  2018. }
  2019. JObject jsonObject = new JObject
  2020. {
  2021. { "UserId", cytUserId },
  2022. { "Pwd", "lt666888" },
  2023. { "Filename", chanp }
  2024. };
  2025. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  2026. JObject jsonObjects = JObject.Parse(response);
  2027. string msg = (string)jsonObjects["msg"];
  2028. if (msg == "报价成功")
  2029. {
  2030. JObject jsonObject1 = (JObject)jsonObjects["data"];
  2031. string data = (string)jsonObject1["price"];
  2032. 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 + "');";
  2033. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2034. price = Convert.ToDouble(data);
  2035. }
  2036. else
  2037. {
  2038. 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 + "');";
  2039. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2040. return;
  2041. }
  2042. if (price > 0)
  2043. {
  2044. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2045. if (ceErpTradeCellExtend == null)
  2046. {
  2047. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2048. ceErpTradeCellExtend.ctid = entity.ctid;
  2049. ceErpTradeCellExtend.payment_cyt = price;
  2050. ceErpTradeCellExtend.Create();
  2051. }
  2052. else
  2053. {
  2054. ceErpTradeCellExtend.payment_cyt = price;
  2055. ceErpTradeCellExtend.Update();
  2056. }
  2057. }
  2058. }
  2059. catch (Exception ex)
  2060. {
  2061. }
  2062. return;
  2063. }
  2064. /// <summary>
  2065. /// 更新设计信息
  2066. /// </summary>
  2067. /// <param name="ceErpTradeCell"></param>
  2068. public static void updateDataTradeCellDesignInfo(string ctid)
  2069. {
  2070. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2071. if (ceErpTradeCell == null)
  2072. {
  2073. return;
  2074. }
  2075. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", ceErpTradeCell.tid);
  2076. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2077. foreach (DataRow row in data.Rows)
  2078. {
  2079. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  2080. if (ceErpTradeCell == null)
  2081. {
  2082. continue;
  2083. }
  2084. Dictionary<string, string> map = new Dictionary<string, string>();
  2085. if (ceErpTradeCell.DesignUserId > 0)
  2086. {
  2087. string design_sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", ceErpTradeCell.DesignUserId);
  2088. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(design_sql).Tables[0];
  2089. if (design_dt != null && design_dt.Rows.Count > 0)
  2090. {
  2091. map.Add("ShortText1717743889973", design_dt.Rows[0]["Name"].ToString());
  2092. map.Add("ShortText1717743889516", design_dt.Rows[0]["OrgName"].ToString());
  2093. if (!string.IsNullOrEmpty(design_dt.Rows[0]["OrgID"].ToString()))
  2094. {
  2095. int orgId = Convert.ToInt32(design_dt.Rows[0]["OrgID"]);
  2096. if (orgId > 0)
  2097. {
  2098. 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"]);
  2099. DataTable mDesign_dt = DbHelper.DbConn.ExecuteDataset(mDesign_sql).Tables[0];
  2100. if (mDesign_dt != null && mDesign_dt.Rows.Count > 0)
  2101. {
  2102. map.Add("ShortText1717743890850", mDesign_dt.Rows[0]["Name"].ToString());
  2103. }
  2104. }
  2105. }
  2106. }
  2107. map.Add("Date1717743893776", ceErpTradeCell.WaitDesignTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2108. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2109. }
  2110. dataHelper.updateErpTradeCell(map, ctid);
  2111. }
  2112. }
  2113. /// <summary>
  2114. /// 下单更新
  2115. /// </summary>
  2116. /// <param name="ceErpTradeCell"></param>
  2117. public static void updateDataTradeCellPlaceInfo(string ctid)
  2118. {
  2119. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2120. if (ceErpTradeCell == null)
  2121. {
  2122. return;
  2123. }
  2124. Dictionary<string, string> map = new Dictionary<string, string>();
  2125. if (ceErpTradeCell.OrderState >= 6 && ceErpTradeCell.SupplierId > 0)
  2126. {
  2127. map.Add("Date1717743895362", ceErpTradeCell.FinishDesignTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2128. map.Add("Date1717744246168", ceErpTradeCell.FinishPlaceTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2129. string supplierId = dataHelper.getSupplerDataInfo(ceErpTradeCell.SupplierId.ToString());
  2130. map.Add("RelevanceForm1718100412422", supplierId);
  2131. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  2132. if (ceErpTradeCellExtend != null)
  2133. {
  2134. map.Add("Number1718099884613", ceErpTradeCellExtend.payment_cyt.ToString());
  2135. }
  2136. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2137. }
  2138. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2139. }
  2140. /// <summary>
  2141. /// 发货更新
  2142. /// </summary>
  2143. /// <param name="ceErpTradeCell"></param>
  2144. public static void updateDataTradeCellDeliveInfo(string ctid)
  2145. {
  2146. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2147. if (ceErpTradeCell == null)
  2148. {
  2149. return;
  2150. }
  2151. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", ceErpTradeCell.tid);
  2152. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2153. foreach (DataRow row in data.Rows)
  2154. {
  2155. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  2156. if (ceErpTradeCell == null)
  2157. {
  2158. continue;
  2159. }
  2160. Dictionary<string, string> map = new Dictionary<string, string>();
  2161. if (ceErpTradeCell.OrderState >= 7 && ceErpTradeCell.SupplierId > 0)
  2162. {
  2163. map.Add("Date1717744254301", ceErpTradeCell.FinishDeliveryTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2164. map.Add("ShortText1717744255441", ceErpTradeCell.OutSid);
  2165. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2166. }
  2167. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2168. }
  2169. }
  2170. /// <summary>
  2171. /// 打回
  2172. /// </summary>
  2173. /// <param name="ceErpTradeCell"></param>
  2174. public static void updateDataTradeCellBackInfo(string ctid)
  2175. {
  2176. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2177. if (ceErpTradeCell == null)
  2178. {
  2179. return;
  2180. }
  2181. Dictionary<string, string> map = new Dictionary<string, string>();
  2182. map.Add("Date1717745436357", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  2183. map.Add("ShortText1717745435559", "是");
  2184. map.Add("ShortText1717745481283", ceErpTradeCell.ReturnReason);
  2185. map.Add("ShortText1717743882604", ((OrderState)ceErpTradeCell.OrderState).ToString());
  2186. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2187. }
  2188. /// <summary>
  2189. /// 查货
  2190. /// </summary>
  2191. /// <param name="ceErpTradeCell"></param>
  2192. public static void updateDataTradeCellCheckGoodInfo(string ctid)
  2193. {
  2194. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2195. if (ceErpTradeCell == null)
  2196. {
  2197. return;
  2198. }
  2199. Dictionary<string, string> map = new Dictionary<string, string>();
  2200. map.Add("Date1717745495718", ceErpTradeCell.CheckOrderTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2201. map.Add("ShortText1717745492918", "是");
  2202. map.Add("ShortText1717745497837", ceErpTradeCell.CheckMemo);
  2203. map.Add("ShortText1717745499141", ceErpTradeCell.UnusualCon);
  2204. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2205. }
  2206. /// <summary>
  2207. /// 加急
  2208. /// </summary>
  2209. /// <param name="ceErpTradeCell"></param>
  2210. public static void updateDataTradeCellUrgentInfo(string ctid)
  2211. {
  2212. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2213. if (ceErpTradeCell == null)
  2214. {
  2215. return;
  2216. }
  2217. Dictionary<string, string> map = new Dictionary<string, string>();
  2218. map.Add("Date1717745535736", ceErpTradeCell.UrgencyTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2219. map.Add("ShortText1717745533062", "是");
  2220. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2221. }
  2222. /// <summary>
  2223. /// 售后
  2224. /// </summary>
  2225. /// <param name="ceErpTradeCell"></param>
  2226. public static void updateDataTradeCellAfterSaleInfo(string ctid)
  2227. {
  2228. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  2229. if (ceErpTradeCell == null)
  2230. {
  2231. return;
  2232. }
  2233. Dictionary<string, string> map = new Dictionary<string, string>();
  2234. map.Add("ShortText1717745540758", "是");
  2235. map.Add("Date1717745544245", ceErpTradeCell.AfterSaleTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2236. if (ceErpTradeCell.AfterSaleResSupId > 0)
  2237. {
  2238. CeErpUser user = CeErpUser.Get(ceErpTradeCell.AfterSaleResSupId);
  2239. if (user != null)
  2240. {
  2241. map.Add("ShortText1717745541664", user.Name);
  2242. }
  2243. }
  2244. map.Add("Date1717745545841", ceErpTradeCell.FinishAfterSaleTime?.ToString("yyyy-MM-dd HH:mm:ss"));
  2245. if (!string.IsNullOrEmpty(ceErpTradeCell.AfterSaleReason))
  2246. {
  2247. string[] list = ceErpTradeCell.AfterSaleReason.Split('|');
  2248. for (int i = 0; i < list.Length; i++)
  2249. {
  2250. if (i == 0)
  2251. {
  2252. map.Add("ShortText1717745548220", list[i]);
  2253. }
  2254. if (i == 1)
  2255. {
  2256. map.Add("ShortText1717745549835", list[i]);
  2257. }
  2258. if (i == 2)
  2259. {
  2260. map.Add("ShortText1717745550687", list[i]);
  2261. }
  2262. }
  2263. }
  2264. if (!string.IsNullOrEmpty(ceErpTradeCell.ResponsibleUserId))
  2265. {
  2266. string[] list = ceErpTradeCell.ResponsibleUserId.Split(',');
  2267. for (int i = 0; i < list.Length; i++)
  2268. {
  2269. string[] user = list[i].Split('_');
  2270. if (user.Length > 0)
  2271. {
  2272. if (user[1] == "g")
  2273. {
  2274. CeErpSupplier ceErpSupplier = CeErpSupplier.Get(user[0]);
  2275. if (i == 0)
  2276. {
  2277. map.Add("ShortText1717745553842", list[i]);
  2278. map.Add("ShortText1717745554626", "");
  2279. }
  2280. if (i == 1)
  2281. {
  2282. map.Add("ShortText1717811042513", list[i]);
  2283. map.Add("ShortText1717811049407", "");
  2284. }
  2285. }
  2286. else if (user[1] == "w")
  2287. {
  2288. if (i == 0)
  2289. {
  2290. map.Add("ShortText1717745553842", "物流问题");
  2291. map.Add("ShortText1717745554626", "");
  2292. }
  2293. if (i == 1)
  2294. {
  2295. map.Add("ShortText1717811042513", "物流问题");
  2296. map.Add("ShortText1717811049407", "");
  2297. }
  2298. }
  2299. else
  2300. {
  2301. string customer_sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", ceErpTradeCell.CustomerUserId);
  2302. DataTable customer_dt = DbHelper.DbConn.ExecuteDataset(customer_sql).Tables[0];
  2303. if (customer_dt.Rows.Count > 0)
  2304. {
  2305. if (i == 0)
  2306. {
  2307. map.Add("ShortText1717745553842", customer_dt.Rows[0]["Name"].ToString());
  2308. map.Add("ShortText1717745554626", customer_dt.Rows[0]["OrgName"].ToString());
  2309. }
  2310. if (i == 1)
  2311. {
  2312. map.Add("ShortText1717811042513", customer_dt.Rows[0]["Name"].ToString());
  2313. map.Add("ShortText1717811049407", customer_dt.Rows[0]["OrgName"].ToString());
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. map.Add("number1717745810151", ceErpTradeCell.RefundFee.ToString());
  2321. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ceErpTradeCell.ctid);
  2322. if (ceErpTradeAfterSaleExtend != null && !string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.RefundFees))
  2323. {
  2324. string[] list = ceErpTradeAfterSaleExtend.RefundFees.Split(',');
  2325. for (int i = 0; i < list.Length; i++)
  2326. {
  2327. if (i == 0)
  2328. {
  2329. map.Add("Number1717745564936", list[i]);
  2330. }
  2331. if (i == 1)
  2332. {
  2333. map.Add("Number1717745565580", list[i]);
  2334. }
  2335. }
  2336. }
  2337. map.Add("ShortText1717745580986", ceErpTradeCell.AfterSaleSupplierState == 1 ? "认可" : "不认可");
  2338. map.Add("ShortText1717745582613", ceErpTradeCell.AfterSaleSupplierMemo);
  2339. map.Add("ShortText1717745583256", ceErpTradeCell.AfterSaleMethod);
  2340. map.Add("ShortText1717745583810", ceErpTradeCell.AfterSaleMemo);
  2341. dataHelper.updateErpTradeCell(map, ceErpTradeCell.ctid);
  2342. }
  2343. /// <summary>
  2344. /// 退款
  2345. /// </summary>
  2346. /// <param name="content"></param>
  2347. public static void updateDataTradeCellRefundInfo(Api_tmc_refund_info_Obj.Content content)
  2348. {
  2349. Dictionary<string, string> map = new Dictionary<string, string>();
  2350. map.Add("Date1717745588048", StampToDateTime(content.createTime).ToString("yyyy-MM-dd HH:mm:ss"));
  2351. map.Add("ShortText1717745585444", "是");
  2352. map.Add("Number1717743148189", content.refundFee);
  2353. map.Add("ShortText1717745591810", content.reason);
  2354. map.Add("ShortText1717745592639", content.desc);
  2355. string tid = content.refOid;
  2356. string info_sql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid ='{0}'", tid);
  2357. DataTable data = DbHelper.DbConn.ExecuteDataset(info_sql).Tables[0];
  2358. foreach (DataRow row in data.Rows)
  2359. {
  2360. dataHelper.updateErpTradeCell(map, row["ctid"].ToString());
  2361. }
  2362. }
  2363. /// <summary>
  2364. /// 返现
  2365. /// </summary>
  2366. /// <param name="entity"></param>
  2367. /// <param name="cash"></param>
  2368. public static void updateDataTradeCellCashInfo(CeErpTradeCell entity, CeErpReturnCash cash)
  2369. {
  2370. Dictionary<string, string> map = new Dictionary<string, string>();
  2371. map.Add("ShortText1717745601056", "是");
  2372. map.Add("ShortText1717745602313", cash.rtype);
  2373. map.Add("Number1717745604245", cash.payment.ToString());
  2374. map.Add("ShortText1717745607208", cash.con);
  2375. dataHelper.updateErpTradeCell(map, entity.ctid);
  2376. }
  2377. /// <summary>
  2378. /// 推购
  2379. /// </summary>
  2380. /// <param name="entity"></param>
  2381. public static void updateDataTradeCellStayInfo(CeErpTradeCell entity)
  2382. {
  2383. Dictionary<string, string> map = new Dictionary<string, string>();
  2384. map.Add("ShortText1717745608381", "是");
  2385. dataHelper.updateErpTradeCell(map, entity.ctid);
  2386. }
  2387. public static DateTime StampToDateTime(string timeStamp)
  2388. {
  2389. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  2390. long lTime = long.Parse(timeStamp + "0000");
  2391. TimeSpan toNow = new TimeSpan(lTime);
  2392. return dateTimeStart.Add(toNow);
  2393. }
  2394. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  2395. {
  2396. return true; //总是接受
  2397. }
  2398. public static string HttpPost(string url, string param = null)
  2399. {
  2400. HttpWebRequest request;
  2401. //如果是发送HTTPS请求
  2402. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  2403. {
  2404. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  2405. request = WebRequest.Create(url) as HttpWebRequest;
  2406. request.ProtocolVersion = HttpVersion.Version10;
  2407. }
  2408. else
  2409. {
  2410. request = WebRequest.Create(url) as HttpWebRequest;
  2411. }
  2412. request.Method = "POST";
  2413. request.ContentType = "application/json";
  2414. request.Accept = "*/*";
  2415. request.Timeout = 60000;
  2416. request.AllowAutoRedirect = false;
  2417. StreamWriter requestStream = null;
  2418. WebResponse response = null;
  2419. string responseStr = null;
  2420. try
  2421. {
  2422. requestStream = new StreamWriter(request.GetRequestStream());
  2423. requestStream.Write(param);
  2424. requestStream.Close();
  2425. response = request.GetResponse();
  2426. if (response != null)
  2427. {
  2428. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  2429. responseStr = reader.ReadToEnd();
  2430. reader.Close();
  2431. }
  2432. }
  2433. catch (Exception ex)
  2434. {
  2435. return ex.Message;
  2436. }
  2437. finally
  2438. {
  2439. request = null;
  2440. requestStream = null;
  2441. response = null;
  2442. }
  2443. return responseStr;
  2444. }
  2445. public static void setSpuData(CeErpTrade father)
  2446. {
  2447. string orderSql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeOrder] WHERE tid = '{0}' and total_fee > 0", father.tid);
  2448. DataTable table = SqlHelper.ExecuteDataSet(orderSql).Tables[0];
  2449. string spu_id = "";
  2450. if (table != null && table.Rows.Count == 1)
  2451. {
  2452. spu_id = table.Rows[0]["spu_id"].ToString();
  2453. }
  2454. string cellSql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid = '{0}'", father.tid);
  2455. DataTable data = SqlHelper.ExecuteDataSet(cellSql).Tables[0];
  2456. if (data != null && data.Rows.Count > 0)
  2457. {
  2458. foreach (DataRow row in data.Rows)
  2459. {
  2460. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(row["ctid"].ToString());
  2461. if (ceErpTradeCellExtend == null)
  2462. {
  2463. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2464. ceErpTradeCellExtend.ctid = row["ctid"].ToString();
  2465. }
  2466. ceErpTradeCellExtend.spu_id = spu_id;
  2467. if (!string.IsNullOrEmpty(spu_id))
  2468. {
  2469. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ceErpTradeCellExtend.ctid);
  2470. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  2471. ceErpTradeCellExtend.ToType = result;
  2472. List<int> 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, 2634, 2636, 2637, 2638, 2645, 2646 };
  2473. List<int> shopIds = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 27, 28, 31, 32, 56, 61 };
  2474. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  2475. {
  2476. ceErpTradeCellExtend.ToType = "外协";
  2477. }
  2478. if ((ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿")) && shopIds.Contains(ceErpTradeCell.ShopId))
  2479. {
  2480. ceErpTradeCellExtend.ToType = "内部";
  2481. }
  2482. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  2483. {
  2484. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ceErpTradeCellExtend.ctid + "';";
  2485. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2486. }
  2487. }
  2488. if (ceErpTradeCellExtend.ID == 0)
  2489. {
  2490. ceErpTradeCellExtend.Create();
  2491. }
  2492. else
  2493. {
  2494. ceErpTradeCellExtend.Update();
  2495. }
  2496. }
  2497. }
  2498. List<string> list = new List<string>() { "kevin_boz", "奥丽芙旗舰店", "鼎怡旗舰店", "格图旗舰店", "宫契旗舰店", "海角七旗舰店", "航和旗舰店", "岚恬旗舰店", "琳19890725", "领淘文具旗舰店", "麦郁旗舰店", "米笛儿旗舰店", "颂盼旗舰店", "涛莱旗舰店", "腾科吉旗舰店", "万慕办公旗舰店", "喜印说旗舰店", "欣克利旗舰店", "阳光猫旗舰店", "翊喜旗舰店", "尹灵旗舰店", "悦加旗舰店", "竹范旗舰店", "卓胜旗舰店" };
  2499. if (string.IsNullOrEmpty(spu_id) && list.IndexOf(father.seller_nick) > -1)
  2500. {
  2501. string sql_pay = "update CE_ErpTradeCell with(rowlock) set orderstate=-1 where tid='" + father.tid + "';";
  2502. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  2503. }
  2504. }
  2505. public static double calculationPrice(CeErpTradeCell ceErpTradeCell)
  2506. {
  2507. double price = 0;
  2508. return 200;
  2509. List<string> list = new List<string>();
  2510. //查补差订单
  2511. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select tid from CE_ErpTradeCell where ptid = '{0}' and IsSample =2", ceErpTradeCell.tid)).Tables[0];
  2512. list.Add("'" + ceErpTradeCell.tid + "'");
  2513. if (dt != null && dt.Rows.Count > 0)
  2514. {
  2515. foreach (DataRow dr in dt.Rows)
  2516. {
  2517. list.Add("'" + dr["tid"].ToString() + "'");
  2518. }
  2519. }
  2520. DataTable tradeTables = DbHelper.DbConn.ExecuteDataset(string.Format("select payment from CE_ErpTrade where tid in ({0})", string.Join(",", list))).Tables[0];
  2521. if (tradeTables != null && tradeTables.Rows.Count > 0)
  2522. {
  2523. foreach (DataRow dr in tradeTables.Rows)
  2524. {
  2525. price += Convert.ToDouble(dr["payment"]);
  2526. }
  2527. }
  2528. return price;
  2529. }
  2530. }
  2531. }