commonHelper.cs 163 KB

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