commonHelper.cs 120 KB

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