commonHelper.cs 124 KB

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