commonHelper.cs 118 KB

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