tmcHelper.cs 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643
  1. using BizCom;
  2. using Microsoft.SqlServer.Server;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NHibernate.Mapping;
  6. using SiteCore;
  7. using SiteCore.Handler;
  8. using SiteCore.taobao;
  9. using SiteCore.taoObj;
  10. using SQLData;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Data.SqlClient;
  15. using System.Linq;
  16. using System.Text;
  17. using static SiteCore.taoObj.Api_tmc_trade_info_Obj;
  18. using static SiteCore.taoObj.Api_trade_fullinfo_get_response_Obj;
  19. using static SiteCore.taoObj.Api_trade_info;
  20. using static SiteCore.taoObj.dataShopResponseVo;
  21. using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
  22. using static SiteCore.taoObj.Trade_fullinfo_get_response_Obj;
  23. using static SiteCore.taoObj.work_core_vo;
  24. //status可选值:
  25. //* TRADE_NO_CREATE_PAY(没有创建支付宝交易)
  26. //* WAIT_BUYER_PAY(等待买家付款)
  27. //* SELLER_CONSIGNED_PART(卖家部分发货)
  28. //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款)
  29. //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货)
  30. //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用)
  31. //* TRADE_FINISHED(交易成功)
  32. //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭)
  33. //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易)
  34. //* PAY_PENDING(国际信用卡支付付款确认中)
  35. //* WAIT_PRE_AUTH_CONFIRM(0元购合约中)
  36. namespace SiteCore
  37. {
  38. /// <summary>
  39. /// 同步推送处理
  40. /// </summary>
  41. public class tmcHelper
  42. {
  43. public static int RemoveEmptyEntries { get; private set; }
  44. // case "taobao_trade_TradeCreate"://创建淘宝交易消息
  45. // {
  46. // break;
  47. // }
  48. // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息
  49. // case "taobao_trade_TradeMemoModified"://交易备注修改消息
  50. // case "taobao_trade_TradeRated"://交易评价变更消息
  51. // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款
  52. // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货)
  53. // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息
  54. // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息
  55. // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息
  56. // case "taobao_trade_TradeSellerShip"://卖家发货消息
  57. // case "taobao_trade_TradeClose"://关闭交易消息
  58. // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息
  59. // case "taobao_trade_TradeModifyFee"://修改交易费用消息
  60. public static string GetUTF8String(byte[] buffer)
  61. {
  62. if (buffer == null)
  63. return null;
  64. if (buffer.Length <= 3)
  65. {
  66. return Encoding.UTF8.GetString(buffer);
  67. }
  68. byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf };
  69. if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2])
  70. {
  71. return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
  72. }
  73. return Encoding.UTF8.GetString(buffer);
  74. }
  75. /// <summary>
  76. /// 交易订单关闭
  77. /// </summary>
  78. /// <param name="content"></param>
  79. public static void erp_CloseTrade(string content)
  80. {
  81. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  82. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  83. if (status == "TRADE_CLOSED_BY_TAOBAO")
  84. {
  85. StringBuilder sql = new StringBuilder();
  86. sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]);
  87. sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭);
  88. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]);
  89. CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
  90. //消息通知
  91. }
  92. }
  93. //接收到--新订单生成消息
  94. public static void erp_TradeBuyerPay(string content)
  95. {
  96. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  97. string tid = dics["tid"].ToString();
  98. string sellerNick = dics["seller_nick"].ToString();
  99. string sessionkey = taobaoHelper.ShopKeyDics[sellerNick];
  100. string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test();
  101. createNewOrder(res);
  102. }
  103. //创建新订单
  104. public static void createNewOrder(string res)
  105. {
  106. Trade_fullinfo_get_response_Obj fullObj = null;
  107. if (res == "") return;
  108. try
  109. {
  110. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  111. //res = res.Replace(" ", "");
  112. fullObj = JsonConvert.DeserializeObject<Trade_fullinfo_get_response_Obj>(res);
  113. }
  114. catch (Exception ex)
  115. {
  116. }
  117. if (fullObj == null)
  118. {
  119. Console.WriteLine("Trade_fullinfo_get_response_Obj isNull");
  120. return;
  121. }
  122. Trade tObj = fullObj.trade_fullinfo_get_response.trade;
  123. Orders orderList = tObj.orders;
  124. StringBuilder sql = new StringBuilder();
  125. CeErpTrade td = CeErpTrade.Get(tObj.tid);
  126. if (td != null)
  127. {
  128. //已经存在了,就不要再继续创建了;
  129. return;
  130. }
  131. //原始单创建
  132. CeErpTrade trade = new CeErpTrade();
  133. trade.tid = tObj.tid;
  134. trade.num = tObj.num;
  135. trade.status = tObj.status;
  136. trade.type = tObj.type;
  137. trade.price = Convert.ToDouble(tObj.price);
  138. trade.discount_fee = Convert.ToDouble(tObj.discount_fee);
  139. trade.total_fee = Convert.ToDouble(tObj.total_fee);
  140. trade.created = tObj.created;
  141. if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null)
  142. {
  143. trade.pay_time = tObj.pay_time;
  144. }
  145. if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null)
  146. {
  147. trade.modified = tObj.modified;
  148. }
  149. if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null)
  150. {
  151. trade.end_time = tObj.end_time;
  152. }
  153. trade.buyer_nick = tObj.buyer_nick;
  154. trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  155. trade.seller_nick = tObj.seller_nick;
  156. trade.payment = Convert.ToDouble(tObj.payment);
  157. trade.receiver_name = tObj.receiver_name;
  158. trade.receiver_state = tObj.receiver_state;
  159. trade.receiver_city = tObj.receiver_city;
  160. trade.receiver_town = GetNoNullValue_string(tObj.receiver_town);
  161. trade.receiver_district = GetNoNullValue_string(tObj.receiver_district);
  162. trade.receiver_address = tObj.receiver_address;
  163. trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  164. trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  165. if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  166. {
  167. trade.consign_time = tObj.consign_time;
  168. }
  169. if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null)
  170. {
  171. trade.delivery_time = tObj.delivery_time;
  172. }
  173. trade.buyer_message = GetNoNullValue_string(tObj.buyer_message);
  174. trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo);
  175. trade.seller_memo = GetNoNullValue_string(tObj.seller_memo);
  176. trade.Create();
  177. //查询是否有退款记录
  178. CeErpSpecialRefund ceErpSpecialRefund = new CeErpSpecialRefund();
  179. ceErpSpecialRefund = CeErpSpecialRefund.GetByTid(trade.tid);
  180. if (ceErpSpecialRefund != null)
  181. {
  182. refundTmcHelper.Api_TmcRefundMsg(ceErpSpecialRefund.refxml);
  183. ceErpSpecialRefund.whethernotify = 1;
  184. ceErpSpecialRefund.Update();
  185. }
  186. bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注
  187. string xianhuoMemo = "(" + trade.tid + ")现货-";
  188. //order表创建
  189. foreach (Order item in orderList.order)
  190. {
  191. CeErpTradeOrder order = new CeErpTradeOrder();
  192. order.tid = trade.tid;
  193. order.oid = item.oid;
  194. order.buyer_nick = trade.buyer_nick;
  195. order.refund_status = item.refund_status;
  196. order.status = item.status;
  197. order.title = item.title;
  198. order.price = Convert.ToDouble(item.price);
  199. order.pic_path = item.pic_path;
  200. order.num = Convert.ToDouble(item.num.ToString());
  201. order.payment = Convert.ToDouble(item.payment);
  202. order.adjust_fee = Convert.ToDouble(item.adjust_fee);
  203. if (item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货") != -1)
  204. {
  205. order.sku_properties_name = item.sku_properties_name;
  206. order.sku_id = item.sku_id;
  207. isXianhuo = true;
  208. xianhuoMemo += order.sku_properties_name;
  209. }
  210. order.Create();
  211. }
  212. if (isXianhuo)
  213. {
  214. xianhuoMemo += "-";
  215. xianhuoMemo += trade.seller_nick;
  216. }
  217. //cell表创建
  218. CeErpTradeCell entity = null;
  219. entity = CeErpTradeCell.GetByCtid(tObj.tid);
  220. if (entity == null)
  221. {
  222. try
  223. {
  224. entity = new CeErpTradeCell();
  225. entity.ctid = tObj.tid;
  226. entity.tid = tObj.tid;
  227. entity.payment = Convert.ToDouble(tObj.payment);
  228. if (isXianhuo)
  229. {
  230. entity.OrderState = 5;
  231. entity.seller_memo = xianhuoMemo;
  232. }
  233. entity.Create();
  234. }
  235. catch (Exception ex)
  236. {
  237. XLog.SaveLog(0, ex.Message);
  238. }
  239. }
  240. //生成档案客户信息
  241. operateCustomer(tObj);
  242. }
  243. public static void operateCustomer(Trade Obj)
  244. {
  245. CeErpCustomer cus = null;
  246. cus = CeErpCustomer.GetByNick(Obj.buyer_nick);
  247. if (cus != null)
  248. {
  249. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  250. cus.phone = Obj.receiver_mobile;
  251. TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time);
  252. cus.buy_day = tsday.Days;
  253. cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
  254. cus.buy_count = cus.buy_count + 1;
  255. cus.lastbuy_time = Obj.pay_time;
  256. cus.Update();
  257. }
  258. else
  259. {
  260. try
  261. {
  262. cus = new CeErpCustomer();
  263. cus.buyer_nick = Obj.buyer_nick;
  264. cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  265. cus.phone = Obj.receiver_mobile;
  266. cus.buy_day = 0;
  267. cus.buy_count = 1;
  268. cus.lastbuy_time = Obj.pay_time;
  269. cus.total_fee = Convert.ToDouble(Obj.payment);
  270. cus.Create();
  271. }
  272. catch (Exception ex)
  273. {
  274. XLog.SaveLog(0, ex.Message);
  275. }
  276. }
  277. }
  278. public static string GetNoNullValue_string(string value)
  279. {
  280. value = value.Replace("\n", " ");
  281. value = value.Replace("\r", " ");
  282. value = value.Replace("*", "x");
  283. if (value == null)
  284. {
  285. return "";
  286. }
  287. return value;
  288. }
  289. public static string GetNull_tostring(object value)
  290. {
  291. if (value == null)
  292. {
  293. return "";
  294. }
  295. return value.ToString();
  296. }
  297. //接收到--卖家修改备注消息
  298. public static void erp_TradeMemoModified(string content)
  299. {
  300. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  301. if (!dics.ContainsKey("seller_memo"))
  302. {
  303. return;
  304. }
  305. string tid = dics["tid"].ToString();
  306. string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO
  307. string buyer = dics["buyer_nick"].ToString();
  308. //原始表--没有这个单,不能拆分
  309. CeErpTrade mainEn = CeErpTrade.Get(tid);
  310. if (mainEn == null) return;
  311. createCellOrder(mainEn, tid, smemo, buyer);
  312. }
  313. //接收到--交易成功消息
  314. public static void erp_TradeSuccess(string content)
  315. {
  316. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  317. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  318. //if (status == "TRADE_FINISHED")
  319. //{
  320. StringBuilder sql = new StringBuilder();
  321. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]);
  322. sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成);
  323. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]);
  324. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  325. //}
  326. }
  327. //接收到--卖家发货消息
  328. public static void erp_TradeSellerShip(string content)
  329. {
  330. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  331. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  332. //if (status == "WAIT_BUYER_CONFIRM_GOODS")
  333. //{
  334. StringBuilder sql = new StringBuilder();
  335. //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState
  336. sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  337. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
  338. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  339. //}
  340. }
  341. //接收到买家子订单退款 并卖家确认
  342. public static void erp_TradePartlyRefund(string content)
  343. {
  344. Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
  345. string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
  346. //if (status == "TRADE_CLOSED")
  347. //{
  348. StringBuilder sql = new StringBuilder();
  349. sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]);
  350. sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]);
  351. sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭, 1, dics["tid"]);
  352. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  353. LogHelper.addLog(dics["tid"].ToString(), 0, "客户申请退款,已确认", (int)OrderState.交易关闭);
  354. //}
  355. }
  356. public static void Api_TmcTradeMsg(string res)
  357. {
  358. Api_tmc_trade_info_Obj fullObj = null;
  359. if (res == "") return;
  360. try
  361. {
  362. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  363. //res = res.Replace(" ", "");
  364. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  365. }
  366. catch (Exception ex)
  367. {
  368. XLog.SaveLog(0, res + "|1|" + ex.Message);
  369. }
  370. if (fullObj == null)
  371. {
  372. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  373. XLog.SaveLog(0, "Api_tmc_trade_info_Obj isNull");
  374. return;
  375. }
  376. Content tObj = fullObj.content;
  377. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  378. //未付款,未成功的单不需要 榆家不收
  379. if (tObj.status == "DELETED" || (tObj.status == "CANCEL" && tObj.refType != "JD") || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  380. {
  381. return;
  382. }
  383. bool isCreate = false;
  384. CeErpTrade trade = null;
  385. trade = CeErpTrade.Get(tObj.refOid);
  386. tObj.sellerMemo = tObj.sellerMemo.Replace("默拍-发小礼物", "").Replace("电子稿-发小礼物", "").Replace("客户联系不上-发小礼物", "");
  387. if (trade == null)
  388. { //新生成订单的
  389. isCreate = true;
  390. trade = new CeErpTrade();
  391. trade.tid = tObj.refOid;
  392. trade.type = tObj.refType;
  393. trade.price = Convert.ToDouble(tObj.totalPrice);
  394. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  395. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  396. trade.created = StampToDateTime(tObj.orderTime);
  397. if (tObj.payTime != null && tObj.payTime.Length > 0)
  398. {
  399. trade.pay_time = StampToDateTime(tObj.payTime);
  400. }
  401. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  402. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  403. if (trade.seller_nick == "")
  404. {
  405. trade.seller_nick = getShopNameByECode(trade.posCode);
  406. tObj.openSellerNick = trade.seller_nick;
  407. }
  408. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  409. trade.payment = Convert.ToDouble(tObj.payment);
  410. //trade.receiver_name = tObj.receiver_name;
  411. }
  412. if (trade.buyer_nick == null || trade.buyer_nick.Length == 0)
  413. {
  414. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  415. }
  416. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  417. trade.receiver_state = tObj.receiverState;
  418. trade.receiver_city = tObj.receiverCity;
  419. trade.receiverId = tObj.receiverId;
  420. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  421. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  422. if (trade.type == "JD" && tObj.status == "CANCEL")
  423. trade.status = "CLOSE";
  424. else
  425. trade.status = tObj.status;
  426. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  427. //{
  428. //}
  429. trade.seller_flag = tObj.flag;
  430. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  431. {
  432. trade.modified = StampToDateTime(tObj.modifyTime);
  433. }
  434. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  435. {
  436. trade.end_time = StampToDateTime(tObj.finishTime);
  437. }
  438. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  439. {
  440. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  441. }
  442. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  443. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  444. bool isSellerMemoChange = false;
  445. //备注修改
  446. tObj.sellerMemo = GetNoNullValue_string(tObj.sellerMemo);
  447. if (trade.seller_memo != tObj.sellerMemo)
  448. {
  449. isSellerMemoChange = true;
  450. }
  451. if (trade.seller_memo.Length != tObj.sellerMemo.Length)
  452. {
  453. isSellerMemoChange = true;
  454. }
  455. trade.seller_memo = tObj.sellerMemo;
  456. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  457. {
  458. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  459. {
  460. string[] acclist = tObj.sellerMemo.Split('-');
  461. List<string> list = new List<string>(acclist);
  462. string buyer_nick = "";
  463. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  464. {
  465. if (list.Count > 3)
  466. {
  467. buyer_nick = list[3];
  468. }
  469. }
  470. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  471. {
  472. if (list.Count > 1)
  473. {
  474. buyer_nick = list[1];
  475. }
  476. }
  477. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  478. {
  479. if (list.Count > 1)
  480. {
  481. buyer_nick = list[1];
  482. }
  483. }
  484. else if (trade.seller_memo.IndexOf("寄样") != -1)
  485. {
  486. if (list.Count > 3)
  487. {
  488. buyer_nick = list[3];
  489. }
  490. }
  491. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  492. {
  493. if (list.Count > 1)
  494. {
  495. buyer_nick = list[1];
  496. }
  497. }
  498. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  499. {
  500. if (list.Count > 1)
  501. {
  502. buyer_nick = list[1];
  503. }
  504. }
  505. else
  506. {
  507. if (list.Count > 5)
  508. {
  509. buyer_nick = list[5];
  510. }
  511. }
  512. tObj.sellerMemo = string.Join("-", list);
  513. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  514. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  515. }
  516. }
  517. if (isCreate)
  518. {
  519. trade.create_time = DateTime.Now;
  520. trade.Create();
  521. }
  522. else
  523. {
  524. if (tObj.status == "CLOSE")
  525. {
  526. trade.consign_time = DateTime.Now;
  527. }
  528. trade.Update();
  529. }
  530. //dataHelper.sendErpTradeInfo(new dataSendTradeBean(tObj));
  531. try
  532. {
  533. if (tObj.status == "CLOSE" || tObj.status == "CANCEL")
  534. {
  535. StringBuilder sql = new StringBuilder();
  536. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, tObj.refOid);
  537. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  538. ApiVo apiVo = new ApiVo();
  539. apiVo.actionName = "closeDesign";
  540. apiVo.orderNumber = tObj.refOid;
  541. //designHelper.API_WorkCore(apiVo);//closeDesign
  542. LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
  543. // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
  544. // removeOldCustomerInfo(trade);
  545. }
  546. else if (tObj.status == "COMPLETE")
  547. {
  548. StringBuilder sql = new StringBuilder();
  549. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, tObj.refOid);
  550. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  551. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
  552. }
  553. else if (tObj.status == "SHIPPED")//已发货
  554. {
  555. StringBuilder sql = new StringBuilder();
  556. sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tObj.refOid);
  557. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  558. //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
  559. }
  560. }
  561. catch (Exception ex)
  562. {
  563. XLog.SaveLog(0, res + "shipped:" + ex.Message);
  564. throw ex;
  565. }
  566. int xianhuoProductCount = 0;
  567. bool isXianhuo = false;
  568. string xianhuoMemo = "(" + trade.tid + ")现货-";
  569. bool isNew = true;
  570. CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
  571. int shopId = 0;
  572. if (nShop != null)
  573. {
  574. shopId = nShop.ID;
  575. }
  576. try
  577. {
  578. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  579. {
  580. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  581. bool isCreateOrder = false;
  582. if (order == null)
  583. {
  584. order = new CeErpTradeOrder();
  585. isCreateOrder = true;
  586. order.oid = item.refOlId;
  587. order.tid = trade.tid;
  588. order.buyer_nick = trade.buyer_nick;
  589. }
  590. if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS")
  591. {
  592. CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid);
  593. if (refund == null)
  594. {
  595. refund = new CeErpTradeRefund();
  596. refund.refund_id = tObj.refOid;
  597. refund.tid = tObj.refOid;
  598. //refund.oid = item.oid;
  599. refund.created = DateTime.Now;
  600. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  601. {
  602. refund.modified = StampToDateTime(tObj.modifyTime);
  603. }
  604. refund.status = item.refundStatus;
  605. refund.order_status = tObj.status;
  606. refund.payment = tObj.payment;
  607. refund.refund_fee = tObj.payment;
  608. refund.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  609. refund.buyer_id = GetNull_tostring(tObj.openBuyerId);
  610. refund.seller_nick = trade.seller_nick;
  611. refund.total_fee = tObj.payment;
  612. refund.RefundState = 1;//1待审核2待确认
  613. refund.Create();
  614. //cell订单 添加退款标记
  615. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  616. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  617. designHelper.API_refundOrder(tObj.refOid, "refundEd", "");
  618. LogHelper.addLog(tObj.refOid, 0, "已退款", (int)OrderState.交易关闭);
  619. }
  620. else
  621. {
  622. if (refund.status != item.refundStatus)
  623. {
  624. refund.modified = DateTime.Now;
  625. refund.status = item.refundStatus;
  626. refund.order_status = tObj.status;
  627. refund.Update();
  628. int rstate = commonHelper.getRefundTagByState(item.refundStatus);
  629. commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
  630. LogHelper.addLog(tObj.refOid, 0, "更新退款状态", (int)OrderState.交易关闭);
  631. }
  632. }
  633. }
  634. else if (item.refundStatus == "REFUNDING" && order.refund_status != "REFUNDING")
  635. {
  636. commonHelper.UpdateRefundOrderState(tObj.refOid, 1);
  637. designHelper.API_refundOrder(tObj.refOid, "refundIng", "");
  638. LogHelper.addLog(tObj.refOid, 0, "申请退款中");
  639. }
  640. else if (item.refundStatus == "NO_REFUND" && order.refund_status != "NO_REFUND" && isCreateOrder == false)
  641. {
  642. //CeErpTradeRefund.Del(tObj.refOid);
  643. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  644. designHelper.API_refundOrder(tObj.refOid, "refundCancel", "");
  645. LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
  646. }
  647. else if (item.refundStatus == "REJECT_REFUNDED" && order.refund_status != "REJECT_REFUNDED" && isCreateOrder == false)
  648. {
  649. //CeErpTradeRefund.Del(tObj.refOid);
  650. commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
  651. LogHelper.addLog(tObj.refOid, 0, "拒绝退货退款");
  652. }
  653. order.refund_status = item.refundStatus;
  654. order.status = trade.status;
  655. order.title = item.title;
  656. order.price = Convert.ToDouble(item.price);
  657. if (item.picUrl != null)
  658. order.pic_path = item.picUrl;
  659. order.num = Convert.ToDouble(item.num.ToString());
  660. order.payment = Convert.ToDouble(item.price);
  661. order.total_fee = Convert.ToDouble(item.totalFee);
  662. //order.adjust_fee = Convert.ToDouble(item.price);
  663. if (item.refSkuId != null && item.refSkuId != "")
  664. {
  665. order.sku_id = item.refSkuId;
  666. }
  667. if (item.standards != null && item.standards != "")
  668. {
  669. order.sku_properties_name = item.standards;
  670. }
  671. if (item.refSpuId != null && item.refSpuId != "")
  672. {
  673. order.spu_id = item.refSpuId;
  674. }
  675. List<string> standards_list = new List<string>() { "现货", "封酒贴", "兔团团", "帆布", "手拉旗", "kt", "条幅", "臂贴" };
  676. bool isInList = false;
  677. foreach (string text in standards_list)
  678. {
  679. if (item.standards.IndexOf(text) > -1)
  680. {
  681. isInList = true;
  682. }
  683. }
  684. if (item.refSkuId != null && item.standards != null && (isInList || item.standards.IndexOf("#") != -1) && item.standards.IndexOf("定制") == -1)
  685. {
  686. isXianhuo = true;
  687. xianhuoMemo += order.sku_properties_name;
  688. xianhuoMemo += ("-数量:" + order.num + ";");
  689. xianhuoProductCount += (int)order.num;
  690. if (isCreateOrder)
  691. {
  692. string goodsSql = "select * from CE_ErpBagShopGoods";
  693. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  694. if (goodsDt.Rows.Count > 0)
  695. {
  696. foreach (DataRow gdr in goodsDt.Rows)
  697. {
  698. string bname = gdr["bname"].ToString();
  699. string bsize = gdr["bsize"].ToString();
  700. string bcount = gdr["bcount"].ToString();
  701. if (bname.Length > 0 && order.sku_properties_name.IndexOf(bname) != -1)
  702. {
  703. order.bagName = bname;
  704. order.isBagOrder = 1;
  705. }
  706. if (bsize.Length > 0 && order.sku_properties_name.IndexOf(bsize) != -1)
  707. {
  708. order.bagSize = bsize;
  709. }
  710. if (bcount.Length > 0 && order.sku_properties_name.IndexOf(bcount) != -1)
  711. {
  712. order.bagCount = bcount;
  713. int bbcount = commonHelper.getIntCountFromString(bcount);
  714. order.bagRealCount = bbcount * (int)order.num;
  715. }
  716. }
  717. }
  718. }
  719. }
  720. if (isCreateOrder)
  721. {
  722. order.Create();
  723. CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(order.spu_id);
  724. //dataHelper.sendErpTradeOrderInfo(new dataSendTradeOrderBean(item, tObj));
  725. if (ceErpTradeSpu == null)
  726. {
  727. ceErpTradeSpu = new CeErpTradeSpu();
  728. ceErpTradeSpu.spuId = order.spu_id;
  729. ceErpTradeSpu.tid = order.tid;
  730. ceErpTradeSpu.shopId = shopId;
  731. ceErpTradeSpu.createTime = DateTime.Now;
  732. dataSendSpuBean bean = new dataSendSpuBean();
  733. bean.ShortText1728890680485 = order.title;
  734. bean.ShortText1728890649488 = order.spu_id;
  735. bean.shopId = shopId.ToString();
  736. bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  737. dataResponseVo response = dataHelper.sendSpuInfo(bean);
  738. if (response != null)
  739. {
  740. if ("0".Equals(response.errcode))
  741. {
  742. ceErpTradeSpu.isSync = true;
  743. }
  744. else
  745. {
  746. ceErpTradeSpu.message = response.errmsg;
  747. }
  748. }
  749. ceErpTradeSpu.Create();
  750. }
  751. DateTime orderTime = ceErpTradeSpu.createTime ?? DateTime.MinValue;
  752. if (DateTime.Compare(orderTime.AddDays(30), DateTime.Now) < 0)
  753. {
  754. isNew = false;
  755. }
  756. }
  757. else
  758. {
  759. order.Update();
  760. }
  761. }
  762. }
  763. catch (Exception ex)
  764. {
  765. XLog.SaveLog(0, res + "|order表:" + ex.Message);
  766. throw ex;
  767. }
  768. //if (isXianhuo)
  769. //{
  770. // xianhuoMemo += "-";
  771. // xianhuoMemo += trade.seller_nick;
  772. //}
  773. if (!trade.IsNew)
  774. {
  775. trade.IsNew = isNew;
  776. }
  777. CeErpTradeCell entity = null;
  778. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  779. if (entity == null)
  780. {
  781. try
  782. {
  783. entity = new CeErpTradeCell();
  784. entity.ctid = tObj.refOid;
  785. //唯一标识
  786. entity.OrderSn = tObj.refOid;
  787. string orderSn = dataHelper.getSaleOrderSn();
  788. if (orderSn != "")
  789. {
  790. entity.OrderSn = orderSn;
  791. }
  792. entity.tid = tObj.refOid;
  793. entity.seller_memo = "";
  794. entity.payment = Convert.ToDouble(tObj.payment);
  795. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  796. if (tObj.payTime != null)
  797. {
  798. entity.pay_time = StampToDateTime(tObj.payTime);
  799. }
  800. entity.UpdateTime = DateTime.Now;
  801. entity.ShopId = shopId;
  802. if (isXianhuo)
  803. {
  804. entity.OrderState = 6;
  805. entity.seller_memo = xianhuoMemo;
  806. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  807. entity.IsXianHuo = 1;
  808. entity.FinishPlaceTime = entity.pay_time;
  809. entity.ProductCount = xianhuoProductCount.ToString();
  810. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  811. {
  812. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  813. if (trade.buyer_memo != "")
  814. {
  815. entity.OrderState = 2;
  816. entity.ProductId = 1;
  817. entity.IsXianHuo = 0;
  818. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  819. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  820. entity.seller_memo = xianhuoMemo;
  821. if (entity.ShopId != 0)
  822. {
  823. entity.OrderState = orderAudit(entity.ShopId);
  824. }
  825. }
  826. }
  827. else if (xianhuoMemo.IndexOf("#") != -1)
  828. {
  829. entity.SupplierId = 87;
  830. }
  831. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  832. {
  833. entity.SupplierId = 70;
  834. }
  835. else if (xianhuoMemo.IndexOf("兔团团") != -1)
  836. {
  837. entity.SupplierId = 101;
  838. }
  839. else if (xianhuoMemo.IndexOf("手拉旗") != -1)
  840. {
  841. entity.SupplierId = 108;
  842. }
  843. else if (xianhuoMemo.IndexOf("臂贴") != -1)
  844. {
  845. entity.OrderState = 2;
  846. entity.ProductId = 2690;
  847. entity.IsXianHuo = 0;
  848. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  849. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  850. entity.seller_memo = xianhuoMemo;
  851. }
  852. try
  853. {
  854. string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
  855. DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
  856. List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
  857. List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
  858. foreach (DataRow dr in goodsDt.Rows)
  859. {
  860. string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
  861. List<string> xianhuo = sqlMemo.Split(',').ToList();
  862. foreach (var item in xianhuo)
  863. {
  864. if (string.IsNullOrEmpty(item)) continue;
  865. Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
  866. Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
  867. if (item.IndexOf('-') > -1)
  868. {
  869. List<string> list = item.Split('-').ToList();
  870. material_map.Add(dr["id"].ToString(), list[0]);
  871. name_map.Add(dr["id"].ToString(), list[1]);
  872. }
  873. else
  874. {
  875. material_map.Add(dr["id"].ToString(), item);
  876. }
  877. material_list.Add(material_map);
  878. name_list.Add(name_map);
  879. }
  880. }
  881. List<string> materials = new List<string>();
  882. List<string> names = new List<string>();
  883. List<string> result = new List<string>();
  884. for (int i = 0; i < material_list.Count; i++)
  885. {
  886. Dictionary<string, string> map = material_list[i];
  887. foreach (var item in map)
  888. {
  889. if (xianhuoMemo.IndexOf(item.Value) > -1)
  890. {
  891. Dictionary<string, string> map2 = name_list[i];
  892. if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
  893. {
  894. foreach (var item1 in map2)
  895. {
  896. if (xianhuoMemo.IndexOf(item1.Value) > -1)
  897. {
  898. names.Add(item1.Key);
  899. materials.Add(item.Key);
  900. }
  901. }
  902. }
  903. else
  904. {
  905. materials.Add(item.Key);
  906. }
  907. }
  908. }
  909. }
  910. if (names.Count > 0)//特殊名称有只先在特殊名称里选择
  911. {
  912. result = names.Distinct().ToList();
  913. }
  914. else
  915. {
  916. result = materials.Distinct().ToList();
  917. }
  918. if (result.Count > 0)
  919. {
  920. Random rnd = new Random();
  921. int index = rnd.Next(result.Count);
  922. entity.SupplierId = int.Parse(result[index]);
  923. }
  924. }
  925. catch (Exception e)
  926. {
  927. XLog.SaveLog(0, res + "|现货匹配|" + e.Message);
  928. }
  929. if (isCreate)
  930. {
  931. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  932. if (oldRes > 0)
  933. {
  934. entity.IsOldCustomer = 1;
  935. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  936. }
  937. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  938. }
  939. //if (trade != null)
  940. //{
  941. // trade.seller_memo = xianhuoMemo;
  942. // trade.Update();
  943. //}
  944. }
  945. //if (xianhuoMemo.IndexOf("修改文字下单备注") != -1)
  946. //{
  947. // entity.OrderState = Convert.ToInt32(OrderState.待设计); // Convert.ToInt32(OrderState.待设计);
  948. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  949. // entity.WaitDesignTime = DateTime.Now;
  950. // entity.FinishPlaceTime = null;
  951. // entity.SupplierId = 0;
  952. // LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  953. //}
  954. entity.Create();
  955. CeErpTradeCellExtend.createInfo(entity.ctid);
  956. commonHelper.setSpuData(trade);
  957. }
  958. catch (Exception ex)
  959. {
  960. XLog.SaveLog(0, res + "|cell创建" + ex.Message);
  961. }
  962. }
  963. else
  964. {
  965. if (entity.OrderState == 0 && string.IsNullOrEmpty(entity.seller_memo))
  966. {
  967. isSellerMemoChange = true;
  968. }
  969. }
  970. CeErpTradeCell.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set UpdateTime = getdate() where tid = '{0}'", tObj.refOid));
  971. if (tObj.sellerMemo == "物料")
  972. {
  973. entity.seller_memo = "(" + trade.tid + ")-物料";
  974. entity.OrderState = 6; //下单完成
  975. entity.WaitDesignTime = DateTime.Now;
  976. entity.FinishDesignTime = DateTime.Now;
  977. entity.StartDesignTime = DateTime.Now;
  978. entity.FinishPlaceTime = DateTime.Now;
  979. entity.IsSample = 1;
  980. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  981. entity.Update();
  982. }
  983. //else if (isXianhuo && trade.status== "NOT_SHIPPED")
  984. //{
  985. // entity.seller_memo = xianhuoMemo;
  986. // entity.IsXianHuo = 1;
  987. // entity.FinishPlaceTime = entity.pay_time;
  988. // entity.ProductCount = xianhuoProductCount.ToString();
  989. // if (xianhuoMemo.IndexOf("封酒贴") != -1)
  990. // {
  991. // if (trade.buyer_memo != "") //没设计之前
  992. // {
  993. // if(entity.OrderState <= 2)
  994. // {
  995. // entity.OrderState = 2; //买家有备注的要设计
  996. // }
  997. // entity.ProductId = 1;
  998. // entity.IsXianHuo = 0;
  999. // xianhuoMemo = xianhuoMemo.Replace("现货", "");
  1000. // xianhuoMemo = xianhuoMemo.Replace(" ", "");
  1001. // entity.seller_memo = xianhuoMemo;
  1002. // }
  1003. // }
  1004. // else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  1005. // {
  1006. // entity.SupplierId = 70; //智涛
  1007. // LogHelper.addLog(entity.ctid,0,"喜字贴纸现货到智涛待发货",0);
  1008. // }
  1009. // entity.Update();
  1010. //}
  1011. if (isSellerMemoChange)
  1012. {
  1013. try
  1014. {
  1015. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1016. if (entity.VipCustomer != 1 && entity.VipCustomer != 2)
  1017. {
  1018. commonHelper.checkIsVipOld(trade);
  1019. }
  1020. }
  1021. catch (Exception ex)
  1022. {
  1023. XLog.SaveLog(0, res + "|2|" + ex);
  1024. }
  1025. }
  1026. }
  1027. public static void Api_TmcTradeMsg_Create(string res)
  1028. {
  1029. Api_tmc_trade_info_Obj fullObj = null;
  1030. if (res == "") return;
  1031. try
  1032. {
  1033. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  1034. //res = res.Replace(" ", "");
  1035. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
  1036. }
  1037. catch (Exception ex)
  1038. {
  1039. XLog.SaveLog(0, res + "|1 create|" + ex.Message);
  1040. throw ex;
  1041. }
  1042. if (fullObj == null)
  1043. {
  1044. XLog.SaveLog(0, "create Api_tmc_trade_info_Obj isNull");
  1045. return;
  1046. }
  1047. Content tObj = fullObj.content;
  1048. List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
  1049. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  1050. {
  1051. return;
  1052. }
  1053. bool isCreate = false;
  1054. CeErpTrade trade = null;
  1055. trade = CeErpTrade.Get(tObj.refOid);
  1056. if (trade == null)
  1057. {
  1058. isCreate = true;
  1059. trade = new CeErpTrade();
  1060. trade.tid = tObj.refOid;
  1061. trade.type = tObj.refType;
  1062. trade.price = Convert.ToDouble(tObj.totalPrice);
  1063. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  1064. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  1065. trade.created = StampToDateTime(tObj.orderTime);
  1066. if (tObj.payTime != null && tObj.payTime.Length > 0)
  1067. {
  1068. trade.pay_time = StampToDateTime(tObj.payTime);
  1069. }
  1070. if (tObj.posCode != null) trade.posCode = tObj.posCode;
  1071. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  1072. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  1073. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  1074. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  1075. if (trade.seller_nick == "")
  1076. {
  1077. trade.seller_nick = getShopNameByECode(trade.posCode);
  1078. }
  1079. trade.payment = Convert.ToDouble(tObj.payment);
  1080. //trade.receiver_name = tObj.receiver_name;
  1081. trade.receiver_state = tObj.receiverState;
  1082. trade.receiver_city = tObj.receiverCity;
  1083. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  1084. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  1085. }
  1086. trade.status = tObj.status;
  1087. //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
  1088. //{
  1089. //}
  1090. trade.seller_flag = tObj.flag;
  1091. if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
  1092. {
  1093. trade.modified = StampToDateTime(tObj.modifyTime);
  1094. }
  1095. if (tObj.finishTime != null && tObj.finishTime.Length > 0)
  1096. {
  1097. trade.end_time = StampToDateTime(tObj.finishTime);
  1098. }
  1099. if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
  1100. {
  1101. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  1102. }
  1103. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  1104. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  1105. bool isSellerMemoChange = false;
  1106. if (trade.seller_memo != tObj.sellerMemo)
  1107. {
  1108. isSellerMemoChange = true;
  1109. }
  1110. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  1111. if (isCreate)
  1112. {
  1113. trade.Create();
  1114. }
  1115. else
  1116. {
  1117. trade.Update();
  1118. }
  1119. int xianhuoProductCount = 0;
  1120. bool isXianhuo = false;
  1121. string xianhuoMemo = "(" + trade.tid + ")现货-";
  1122. try
  1123. {
  1124. foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
  1125. {
  1126. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  1127. bool isCreateOrder = false;
  1128. if (order == null)
  1129. {
  1130. order = new CeErpTradeOrder();
  1131. isCreateOrder = true;
  1132. }
  1133. order.tid = trade.tid;
  1134. order.oid = item.refOlId;
  1135. order.buyer_nick = trade.buyer_nick;
  1136. order.refund_status = item.refundStatus;
  1137. order.status = trade.status;
  1138. order.title = item.title;
  1139. order.price = Convert.ToDouble(item.price);
  1140. if (item.picUrl != null)
  1141. order.pic_path = item.picUrl;
  1142. order.num = Convert.ToDouble(item.num.ToString());
  1143. order.payment = Convert.ToDouble(item.price);
  1144. //order.adjust_fee = Convert.ToDouble(item.price);
  1145. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  1146. {
  1147. order.sku_properties_name = item.standards;
  1148. order.sku_id = item.refSkuId;
  1149. isXianhuo = true;
  1150. xianhuoMemo += order.sku_properties_name;
  1151. xianhuoMemo += ("-数量:" + order.num + "; ");
  1152. xianhuoProductCount += (int)order.num;
  1153. }
  1154. if (isCreateOrder)
  1155. {
  1156. order.Create();
  1157. }
  1158. else
  1159. {
  1160. order.Update();
  1161. }
  1162. }
  1163. }
  1164. catch (Exception ex)
  1165. {
  1166. XLog.SaveLog(0, res + "|create order表:" + ex.Message);
  1167. throw ex;
  1168. }
  1169. //if (isXianhuo)
  1170. //{
  1171. // xianhuoMemo += "-";
  1172. // xianhuoMemo += trade.seller_nick;
  1173. //}
  1174. CeErpTradeCell entity = null;
  1175. entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
  1176. if (entity == null)
  1177. {
  1178. try
  1179. {
  1180. entity = new CeErpTradeCell();
  1181. entity.ctid = tObj.refOid;
  1182. entity.tid = tObj.refOid;
  1183. entity.seller_memo = "";
  1184. entity.payment = Convert.ToDouble(tObj.payment);
  1185. entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
  1186. if (tObj.payTime != null)
  1187. {
  1188. entity.pay_time = StampToDateTime(tObj.payTime);
  1189. }
  1190. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  1191. int shopId = 0;
  1192. if (nShop != null)
  1193. {
  1194. shopId = nShop.ID;
  1195. }
  1196. entity.ShopId = shopId;
  1197. if (isXianhuo)
  1198. {
  1199. entity.FinishPlaceTime = DateTime.Now;
  1200. entity.OrderState = 6;
  1201. entity.seller_memo = xianhuoMemo;
  1202. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1203. entity.IsXianHuo = 1;
  1204. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  1205. {
  1206. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);
  1207. if (trade.buyer_memo != "")
  1208. {
  1209. entity.OrderState = 2;
  1210. entity.ProductId = 1;
  1211. entity.IsXianHuo = 0;
  1212. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  1213. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  1214. entity.seller_memo = xianhuoMemo;
  1215. if (entity.ShopId != 0)
  1216. {
  1217. entity.OrderState = orderAudit(entity.ShopId);
  1218. }
  1219. }
  1220. }
  1221. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  1222. {
  1223. entity.SupplierId = 70;
  1224. }
  1225. entity.FinishPlaceTime = entity.pay_time;
  1226. entity.ProductCount = xianhuoProductCount.ToString();
  1227. if (isCreate)
  1228. {
  1229. int oldRes = isOldAndInsertCustomerInfo(trade, entity);
  1230. if (oldRes == 2)
  1231. {
  1232. entity.IsOldCustomer = 1;
  1233. entity.IsOldCustomerMore = 1;
  1234. }
  1235. else if (oldRes == 1)
  1236. {
  1237. entity.IsOldCustomer = 1;
  1238. }
  1239. }
  1240. //if (trade != null)
  1241. //{
  1242. // trade.seller_memo = xianhuoMemo;
  1243. // trade.Update();
  1244. //}
  1245. }
  1246. entity.Create();
  1247. }
  1248. catch (Exception ex)
  1249. {
  1250. XLog.SaveLog(0, res + "|create cell创建" + ex.Message);
  1251. throw ex;
  1252. }
  1253. }
  1254. if (isSellerMemoChange && trade.seller_memo.Length > 0)
  1255. {
  1256. try
  1257. {
  1258. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  1259. }
  1260. catch (Exception ex)
  1261. {
  1262. XLog.SaveLog(0, res + "|2_create|" + ex.Message);
  1263. }
  1264. }
  1265. }
  1266. public static void createCellOrder(CeErpTrade father, string tid, string smemo, string buyer, bool isJump = false)
  1267. {
  1268. smemo = smemo.Replace("\r", " ");
  1269. smemo = smemo.Replace("\n", " ");
  1270. bool isNeedCellOrder = true;
  1271. //try
  1272. //{
  1273. string issql = "select * from ce_erptradecell where tid='" + tid + "';";
  1274. DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
  1275. if (ishavedt.Rows.Count > 0)
  1276. {
  1277. foreach (DataRow hdr in ishavedt.Rows)
  1278. {
  1279. if (smemo.IndexOf("封酒贴") != -1)
  1280. {
  1281. if (Convert.ToInt32(hdr["IsXianHuo"]) == 1 && Convert.ToInt32(hdr["OrderState"]) >= 4)
  1282. {
  1283. isNeedCellOrder = false;
  1284. break;
  1285. }
  1286. else if (Convert.ToInt32(hdr["IsXianHuo"]) == 0 && Convert.ToInt32(hdr["OrderState"]) > 2)
  1287. {
  1288. isNeedCellOrder = false;
  1289. break;
  1290. }
  1291. }
  1292. else if ((Convert.ToInt32(hdr["OrderState"]) > 2 && smemo.IndexOf("礼物") == -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("礼物") != -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("寄样") != -1))
  1293. {
  1294. isNeedCellOrder = false;
  1295. break;
  1296. }
  1297. }
  1298. if (isNeedCellOrder)
  1299. {
  1300. foreach (DataRow hdr in ishavedt.Rows)
  1301. {
  1302. if (hdr["ctid"].ToString().IndexOf("C") != -1)
  1303. {
  1304. string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
  1305. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1306. break;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. //}
  1312. //catch(Exception ex)
  1313. //{
  1314. // isNeedCellOrder = false;
  1315. // XLog.SaveLog(0, "推送是否需要重新生成判断出错"+ tid + ex.Message);
  1316. //}
  1317. if (isJump)
  1318. {
  1319. isNeedCellOrder = true;
  1320. LogHelper.addLog(tid, 0, "原单强制重新生成", 0);
  1321. }
  1322. //if (smemo.IndexOf("g") != -1)
  1323. //{
  1324. // smemo = smemo.Replace("g", "克");
  1325. //}
  1326. if (smemo.IndexOf("补差价") != -1)
  1327. {
  1328. CeErpTradeCell entity = null;
  1329. entity = CeErpTradeCell.GetByCtid(tid);
  1330. bool ishaveBu = true;
  1331. if (entity == null)
  1332. {
  1333. entity = new CeErpTradeCell();
  1334. entity.ctid = tid;
  1335. //唯一标识
  1336. entity.OrderSn = tid;
  1337. string orderSn = dataHelper.getSaleOrderSn();
  1338. if (orderSn != "")
  1339. {
  1340. entity.OrderSn = orderSn;
  1341. }
  1342. entity.tid = tid;
  1343. ishaveBu = false;
  1344. }
  1345. entity.UpdateTime = DateTime.Now;
  1346. if (entity.ShopId == 0)
  1347. {
  1348. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1349. int shopId = 0;
  1350. if (nShop != null)
  1351. {
  1352. shopId = nShop.ID;
  1353. }
  1354. entity.ShopId = shopId;
  1355. }
  1356. if (father.type != "PDD")
  1357. {
  1358. if (entity.OrderState >= 5) return;
  1359. }
  1360. entity.seller_memo = smemo;
  1361. entity.payment = Convert.ToDouble(father.payment);
  1362. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1363. entity.pay_time = father.pay_time;
  1364. smemo = smemo.Replace(":", ":");
  1365. string[] listmemo = smemo.Split(':');
  1366. if (listmemo.Length > 1)
  1367. {
  1368. string maintid = listmemo[1];//System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", "");
  1369. string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'";
  1370. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  1371. if (dt_bu.Rows.Count > 0)
  1372. {
  1373. entity.ptid = dt_bu.Rows[0]["tid"].ToString();
  1374. if (father.type != "PDD")
  1375. {
  1376. entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]);
  1377. }
  1378. entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]);
  1379. entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]);
  1380. entity.SupplierId = Convert.ToInt32(dt_bu.Rows[0]["SupplierId"]);
  1381. entity.seller_memo = "补差价:" + entity.ptid;
  1382. entity.payment = father.payment;
  1383. entity.IsSample = 2;
  1384. if (dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value)
  1385. {
  1386. entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]);
  1387. }
  1388. if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value)
  1389. {
  1390. entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]);
  1391. }
  1392. if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value)
  1393. {
  1394. entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]);
  1395. }
  1396. if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value)
  1397. {
  1398. entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]);
  1399. }
  1400. }
  1401. }
  1402. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1403. {
  1404. entity.OrderState = -1;
  1405. entity.DesignUserId = 0;
  1406. entity.WaitDesignTime = null;
  1407. }
  1408. if (ishaveBu)
  1409. {
  1410. entity.Update();
  1411. }
  1412. else
  1413. {
  1414. father.create_time = DateTime.Now;
  1415. father.orderType = 20;
  1416. father.Update();
  1417. entity.Create();
  1418. CeErpTradeCellExtend.createInfo(entity.ctid, 20, 10);
  1419. }
  1420. ApiVo apiVo = new ApiVo();
  1421. apiVo.orderNumber = entity.ptid;
  1422. apiVo.payment = entity.payment;
  1423. apiVo.actionName = "repairDesign";
  1424. designHelper.API_WorkCore(apiVo);//repairDesign
  1425. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1426. CeErpSukuraData.createInfo(entity.ctid, 1);
  1427. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1428. isNeedCellOrder = false;
  1429. commonHelper.setSpuData(father);
  1430. }
  1431. else if (smemo.IndexOf("拿样订单") != -1)
  1432. {
  1433. CeErpTradeCell entity = null;
  1434. entity = CeErpTradeCell.GetByCtid(tid);
  1435. if (entity == null)
  1436. {
  1437. if (entity.ShopId == 0)
  1438. {
  1439. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1440. int shopId = 0;
  1441. if (nShop != null)
  1442. {
  1443. shopId = nShop.ID;
  1444. }
  1445. entity.ShopId = shopId;
  1446. }
  1447. entity = new CeErpTradeCell();
  1448. entity.ctid = tid;
  1449. //唯一标识
  1450. entity.OrderSn = tid;
  1451. string orderSn = dataHelper.getSaleOrderSn();
  1452. if (orderSn != "")
  1453. {
  1454. entity.OrderSn = orderSn;
  1455. }
  1456. entity.UpdateTime = DateTime.Now;
  1457. entity.tid = tid;
  1458. entity.seller_memo = smemo;
  1459. entity.payment = Convert.ToDouble(father.payment);
  1460. entity.pay_time = father.pay_time;
  1461. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1462. entity.OrderState = 6; //下单完成
  1463. entity.FinishPlaceTime = DateTime.Now;
  1464. entity.IsSample = 1;
  1465. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  1466. entity.IsOldCustomer = 0;
  1467. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1468. {
  1469. entity.OrderState = -1;
  1470. entity.DesignUserId = 0;
  1471. entity.WaitDesignTime = null;
  1472. }
  1473. father.create_time = DateTime.Now;
  1474. father.Update();
  1475. entity.Create();
  1476. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1477. }
  1478. else
  1479. {
  1480. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1481. {
  1482. entity.OrderState = -1;
  1483. entity.DesignUserId = 0;
  1484. entity.WaitDesignTime = null;
  1485. }
  1486. entity.IsSample = 1;
  1487. entity.UpdateTime = DateTime.Now;
  1488. entity.seller_memo = smemo;
  1489. entity.OrderState = 6;
  1490. entity.FinishPlaceTime = DateTime.Now;
  1491. entity.IsOldCustomer = 0;
  1492. entity.Update();
  1493. }
  1494. LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
  1495. CeErpSukuraData.createInfo(entity.ctid, 1);
  1496. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1497. isNeedCellOrder = false;
  1498. commonHelper.setSpuData(father);
  1499. }
  1500. if (isNeedCellOrder == false)
  1501. {
  1502. return;
  1503. }
  1504. if (smemo.IndexOf("*") != -1)
  1505. {
  1506. return;
  1507. }
  1508. if (smemo.IndexOf("{") != -1 && smemo.IndexOf("+") != -1)
  1509. {
  1510. createNewSplitFn(smemo, father);
  1511. return;
  1512. }
  1513. string[] memoList = null;
  1514. if (smemo.IndexOf(",") != -1)
  1515. {
  1516. smemo = smemo.Replace(',', ',');
  1517. }
  1518. if (smemo.IndexOf(",,") != -1)
  1519. {
  1520. return;
  1521. }
  1522. memoList = smemo.Split(',');
  1523. int orderIdx = 1;
  1524. int hebaoCount = 0;
  1525. bool isMulity = false;
  1526. if (memoList.Length > 1)
  1527. {
  1528. isMulity = true;
  1529. foreach (string mstr in memoList)
  1530. {
  1531. if (mstr.IndexOf("合包") != -1)
  1532. {
  1533. hebaoCount += 1;
  1534. }
  1535. }
  1536. }
  1537. if (hebaoCount == 1)
  1538. {
  1539. createHebaoCell(isMulity, 0, smemo, father);
  1540. }
  1541. else
  1542. {
  1543. decimal hePrice = Convert.ToDecimal(father.payment); //合包价格
  1544. string needHebaoItem = "";
  1545. foreach (string item in memoList)
  1546. {
  1547. if (item.IndexOf("合包") != -1)
  1548. {
  1549. needHebaoItem += item;
  1550. needHebaoItem += ",";
  1551. }
  1552. else
  1553. {
  1554. //if (item.IndexOf("电子稿") != -1)
  1555. //{
  1556. // createDianziCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1557. //}
  1558. //else
  1559. if (item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
  1560. {
  1561. createLogoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1562. }
  1563. else if (item.IndexOf("寄样") != -1)
  1564. {
  1565. createDemoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1566. }
  1567. else if (item.IndexOf("礼物") != -1)
  1568. {
  1569. createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1570. }
  1571. else
  1572. createNotHeBaoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
  1573. orderIdx = orderIdx + 1;
  1574. }
  1575. }
  1576. bool isHaveHebaoOrder = false;
  1577. if (needHebaoItem.Length > 0)
  1578. {
  1579. isHaveHebaoOrder = true;
  1580. needHebaoItem = needHebaoItem.Substring(0, needHebaoItem.Length - 1);
  1581. createHebaoCell(isMulity, orderIdx, needHebaoItem, father, hePrice);
  1582. orderIdx = orderIdx + 1;
  1583. }
  1584. if (orderIdx > 2)
  1585. {
  1586. try
  1587. {
  1588. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1589. LogHelper.addLog(tid, 0, "delete ctid=tid orderidx=" + orderIdx, 0);
  1590. if (System.Math.Abs(hePrice) > Convert.ToDecimal(0.01) && hePrice != Convert.ToDecimal(father.payment) && isHaveHebaoOrder == false)
  1591. {
  1592. sql_del += "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
  1593. LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
  1594. }
  1595. CeErpTradeCell.ExecuteNonQuery(sql_del);
  1596. }
  1597. catch (Exception ex)
  1598. {
  1599. XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
  1600. string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
  1601. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1602. }
  1603. }
  1604. commonHelper.setSpuData(father);
  1605. //autoCell(tid);
  1606. }
  1607. }
  1608. public static void createNewSplitFn(string smemo, CeErpTrade father)
  1609. {
  1610. if (smemo.IndexOf("合包") != -1)
  1611. {
  1612. createHebaoCell(false, 0, smemo, father);
  1613. }
  1614. else
  1615. {
  1616. int firstDaKuoHaoCount = 0;
  1617. string firstoneContent = commonHelper.MidStrEx(smemo, "{", "}");
  1618. string[] oneElementList = firstoneContent.Split('+');
  1619. firstDaKuoHaoCount = oneElementList.Length;
  1620. string[] memoList = smemo.Split('-');
  1621. for (int idx = 0; idx < firstDaKuoHaoCount; idx++)
  1622. {
  1623. string newMemoStr = "";
  1624. foreach (string oneStr in memoList)
  1625. {
  1626. string oneContent = "";
  1627. if (oneStr.IndexOf("{") != -1)
  1628. {
  1629. oneContent = commonHelper.MidStrEx(oneStr, "{", "}");
  1630. string[] oneList = oneContent.Split('+');
  1631. if (oneList.Length != firstDaKuoHaoCount)
  1632. {
  1633. XLog.SaveLog(0, father.tid + ",备注大括号内的元素个数不相等");
  1634. return;
  1635. }
  1636. newMemoStr += oneList[idx];
  1637. }
  1638. else
  1639. newMemoStr += oneStr;
  1640. newMemoStr += "-";
  1641. }
  1642. newMemoStr = newMemoStr.Substring(0, newMemoStr.Length - 1);
  1643. if (idx == 0)
  1644. createNewSplitCell(true, idx + 1, newMemoStr, father, father.payment - firstDaKuoHaoCount * 0.1, firstDaKuoHaoCount);
  1645. else
  1646. createNewSplitCell(true, idx + 1, newMemoStr, father, 0.1, firstDaKuoHaoCount);
  1647. }
  1648. try
  1649. {
  1650. string sql_del = "delete from CE_ErpTradeCell where ctid='" + father.tid + "'";
  1651. CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
  1652. LogHelper.addLog(father.tid, 0, "新拆分方法 delete ctid=tid ", 0);
  1653. }
  1654. catch (Exception ex)
  1655. {
  1656. XLog.SaveLog(0, "|新拆分删除首单错误|" + ex.Message);
  1657. }
  1658. }
  1659. }
  1660. public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1661. {
  1662. if (itemMemo.Length <= 0) return;
  1663. string ctid = "";
  1664. string splitTag = "";
  1665. if (isMulty && itemMemo.Length > 2)
  1666. {
  1667. string preStr = "C" + orderIndex + "_";
  1668. ctid = preStr + father.tid;
  1669. splitTag = "C" + orderIndex;
  1670. }
  1671. else if (itemMemo.Length > 2)
  1672. {
  1673. ctid = father.tid;
  1674. }
  1675. CeErpTradeCell entity = null;
  1676. entity = CeErpTradeCell.GetByCtid(ctid);
  1677. bool isNull = false;
  1678. if (entity == null)
  1679. {
  1680. entity = new CeErpTradeCell();
  1681. isNull = true;
  1682. entity.ctid = ctid;
  1683. //唯一标识
  1684. entity.OrderSn = ctid;
  1685. string orderSn = dataHelper.getSaleOrderSn();
  1686. if (orderSn != "")
  1687. {
  1688. entity.OrderSn = orderSn;
  1689. }
  1690. }
  1691. entity.UpdateTime = DateTime.Now;
  1692. entity.tid = father.tid;
  1693. entity.SplitTag = splitTag;
  1694. if (entity.ShopId == 0)
  1695. {
  1696. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1697. int shopId = 0;
  1698. if (nShop != null)
  1699. {
  1700. shopId = nShop.ID;
  1701. }
  1702. entity.ShopId = shopId;
  1703. }
  1704. if (entity.IsSample == 1 || entity.IsSample == 2)
  1705. {
  1706. entity.IsSample = 0;
  1707. entity.ptid = "";
  1708. }
  1709. if (entity.isDianziOrder == 1)
  1710. {
  1711. entity.isDianziOrder = 0;
  1712. }
  1713. string[] acclist = itemMemo.Split('-');
  1714. if (acclist.Length < 4) return;
  1715. string count = acclist[0];
  1716. string product = acclist[1];
  1717. string account = acclist[3];
  1718. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1719. if (cusInfo != null)
  1720. {
  1721. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1722. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1723. {
  1724. }
  1725. else
  1726. {
  1727. entity.OrderState = 2;
  1728. if (entity.ShopId != 0)
  1729. {
  1730. entity.OrderState = orderAudit(entity.ShopId);
  1731. }
  1732. }
  1733. }
  1734. entity.ProductId = getProductIdByName("logo");
  1735. if (entity.ProductId == 0)
  1736. {
  1737. return;
  1738. }
  1739. entity.ProductCount = commonHelper.getProductCount(count);// commonHelper.changeCountFromChiness(count); ;
  1740. if (isMulty)
  1741. {
  1742. try
  1743. {
  1744. string strPrice = acclist[4];
  1745. if (strPrice.IndexOf("元") != -1)
  1746. {
  1747. strPrice = strPrice.Replace("元", "");
  1748. }
  1749. entity.payment = Convert.ToDouble(strPrice);
  1750. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  1751. }
  1752. catch (Exception ex)
  1753. {
  1754. }
  1755. }
  1756. else
  1757. {
  1758. entity.payment = Convert.ToDouble(father.payment);
  1759. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1760. }
  1761. string newmemo = "(" + entity.OrderSn + ")-";
  1762. string newOtherMemo = "";
  1763. for (int i = 0; i < acclist.Length; i++)
  1764. {
  1765. if (i == 3) continue;
  1766. if (i >= 4)
  1767. {
  1768. newOtherMemo += acclist[i];
  1769. }
  1770. else
  1771. newmemo += acclist[i];
  1772. if (i < acclist.Length - 2)
  1773. {
  1774. newmemo += "-";
  1775. }
  1776. }
  1777. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  1778. newmemo += ("-" + sName);
  1779. if (father.buyer_nick.IndexOf("*") < 0)
  1780. {
  1781. newmemo += ("-" + father.buyer_nick);
  1782. }
  1783. newmemo += ("-" + father.receiver_state);
  1784. if (cusInfo != null)
  1785. {
  1786. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  1787. }
  1788. if (isMulty)
  1789. {
  1790. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  1791. }
  1792. if (itemMemo.IndexOf("顺丰到付") != -1)
  1793. {
  1794. if (newmemo.IndexOf("顺丰到付") == -1)
  1795. newmemo += ("-顺丰到付");
  1796. entity.IsSF = 2;
  1797. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  1798. }
  1799. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  1800. {
  1801. if (newmemo.IndexOf("顺丰寄付") == -1)
  1802. newmemo += ("-顺丰寄付");
  1803. entity.IsSF = 1;
  1804. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  1805. }
  1806. if (itemMemo.IndexOf("加急") != -1)
  1807. {
  1808. if (newmemo.IndexOf("加急") == -1)
  1809. newmemo += ("-加急");
  1810. entity.IsUrgency = true;
  1811. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  1812. }
  1813. entity.seller_memo = newmemo;
  1814. entity.OtherMemo = newOtherMemo;
  1815. entity.pay_time = father.pay_time;
  1816. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1817. //if (oldRes>0)
  1818. //{
  1819. // entity.IsOldCustomer = 1;
  1820. // if (oldRes == 2)
  1821. // {
  1822. // entity.IsOldCustomer = 1;
  1823. // entity.IsOldCustomerMore = 1;
  1824. // }
  1825. //}
  1826. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  1827. {
  1828. }
  1829. else
  1830. {
  1831. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  1832. {
  1833. entity.IsOldCustomer = 0;
  1834. }
  1835. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  1836. if (oldRes > 0)
  1837. {
  1838. entity.IsOldCustomer = 1;
  1839. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  1840. int curHour = DateTime.Now.Hour;
  1841. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  1842. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1843. {
  1844. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  1845. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1846. entity.DesignUserId = initSysDesignerId;
  1847. entity.WaitDesignTime = DateTime.Now;
  1848. }
  1849. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1850. {
  1851. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  1852. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1853. entity.DesignUserId = initSysDesignerId;
  1854. entity.WaitDesignTime = DateTime.Now;
  1855. }
  1856. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  1857. {
  1858. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  1859. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1860. entity.DesignUserId = initSysDesignerId;
  1861. entity.WaitDesignTime = DateTime.Now;
  1862. }
  1863. else
  1864. {
  1865. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  1866. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  1867. {
  1868. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1869. entity.DesignUserId = initSysDesignerId;
  1870. entity.WaitDesignTime = DateTime.Now;
  1871. }
  1872. }
  1873. }
  1874. }
  1875. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  1876. {
  1877. entity.OrderState = -1;
  1878. entity.DesignUserId = 0;
  1879. entity.WaitDesignTime = null;
  1880. }
  1881. if (entity.ProductId > 0)
  1882. {
  1883. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  1884. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1885. {
  1886. entity.NewProduct = 1;
  1887. }
  1888. }
  1889. if (isNull)
  1890. {
  1891. father.create_time = DateTime.Now;
  1892. father.Update();
  1893. entity.Create();
  1894. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  1895. }
  1896. else
  1897. {
  1898. entity.Update();
  1899. }
  1900. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  1901. CeErpSukuraData.createInfo(entity.ctid, 1);
  1902. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "logo推送生成" + entity.seller_memo, entity.OrderState);
  1903. }
  1904. public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  1905. {
  1906. if (itemMemo.Length <= 0) return;
  1907. string ctid = "";
  1908. string splitTag = "";
  1909. if (isMulity && itemMemo.Length > 2)
  1910. {
  1911. string preStr = "C" + orderIndex + "_";
  1912. ctid = preStr + father.tid;
  1913. splitTag = "C" + orderIndex;
  1914. }
  1915. else if (itemMemo.Length > 2)
  1916. {
  1917. ctid = father.tid;
  1918. }
  1919. CeErpTradeCell entity = null;
  1920. entity = CeErpTradeCell.GetByCtid(ctid);
  1921. bool isNull = false;
  1922. if (entity == null)
  1923. {
  1924. entity = new CeErpTradeCell();
  1925. isNull = true;
  1926. }
  1927. entity.ctid = ctid;
  1928. entity.tid = father.tid;
  1929. entity.SplitTag = splitTag;
  1930. if (entity.ShopId == 0)
  1931. {
  1932. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  1933. int shopId = 0;
  1934. if (nShop != null)
  1935. {
  1936. shopId = nShop.ID;
  1937. }
  1938. entity.ShopId = shopId;
  1939. }
  1940. if (entity.IsSample == 1 || entity.IsSample == 2)
  1941. {
  1942. entity.IsSample = 0;
  1943. entity.ptid = "";
  1944. }
  1945. if (entity.isDianziOrder == 1)
  1946. {
  1947. entity.isDianziOrder = 0;
  1948. }
  1949. string[] acclist = itemMemo.Split('-');
  1950. if (acclist.Length < 4) return;
  1951. string count = acclist[0];
  1952. string product = acclist[1];
  1953. string account = acclist[3];
  1954. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  1955. if (cusInfo != null)
  1956. {
  1957. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  1958. }
  1959. if (entity.OrderState < 3 && entity.DesignUserId == 0)
  1960. {
  1961. entity.OrderState = Convert.ToInt32(OrderState.待抢单);
  1962. //entity.OrderState = Convert.ToInt32(OrderState.待设计);
  1963. //entity.DesignUserId = 255; //电子稿给亿佳设计
  1964. //entity.WaitDesignTime = DateTime.Now;
  1965. }
  1966. entity.ProductId = getProductIdByName(product);
  1967. if (entity.ProductId == 0)
  1968. {
  1969. return;
  1970. }
  1971. entity.ProductCount = commonHelper.getProductCount(count); ;// commonHelper.changeCountFromChiness(count); ;
  1972. entity.isDianziOrder = 1;//电子稿
  1973. entity.pay_time = father.pay_time;
  1974. if (isMulity)
  1975. {
  1976. try
  1977. {
  1978. string strPrice = acclist[4];
  1979. if (strPrice.IndexOf("元") != -1)
  1980. {
  1981. strPrice = strPrice.Replace("元", "");
  1982. }
  1983. entity.payment = Convert.ToDouble(strPrice);
  1984. hePrice = hePrice - Convert.ToDecimal(acclist[4]);
  1985. }
  1986. catch (Exception ex)
  1987. {
  1988. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  1989. }
  1990. }
  1991. else
  1992. {
  1993. entity.payment = Convert.ToDouble(father.payment);
  1994. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  1995. }
  1996. string newmemo = "(" + entity.tid + ")-";
  1997. string newOtherMemo = "";
  1998. for (int i = 0; i < acclist.Length; i++)
  1999. {
  2000. if (i == 3) continue;
  2001. newmemo += acclist[i];
  2002. if (i < acclist.Length - 2)
  2003. {
  2004. newmemo += "-";
  2005. }
  2006. }
  2007. string sName = getShopSNameByName(father.seller_nick);
  2008. newmemo += ("-" + sName);
  2009. if (father.buyer_nick.IndexOf("*") < 0)
  2010. {
  2011. newmemo += ("-" + father.buyer_nick);
  2012. }
  2013. newmemo += ("-" + father.receiver_state);
  2014. if (cusInfo != null)
  2015. {
  2016. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2017. }
  2018. if (isMulity)
  2019. {
  2020. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2021. }
  2022. entity.seller_memo = newmemo;
  2023. entity.OtherMemo = newOtherMemo;
  2024. //int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2025. //if (oldRes > 0)
  2026. //{
  2027. // entity.IsOldCustomer = 1;
  2028. // if (oldRes == 2)
  2029. // {
  2030. // entity.IsOldCustomer = 1;
  2031. // entity.IsOldCustomerMore = 1;
  2032. // }
  2033. //}
  2034. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2035. {
  2036. }
  2037. else
  2038. {
  2039. entity.IsOldCustomer = 0;
  2040. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2041. if (oldRes > 0)
  2042. {
  2043. entity.IsOldCustomer = 1;
  2044. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2045. dealOldCustomerEntityAuto(ref entity);
  2046. }
  2047. }
  2048. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2049. {
  2050. entity.OrderState = -1;
  2051. entity.DesignUserId = 0;
  2052. entity.WaitDesignTime = null;
  2053. }
  2054. if (entity.ProductId > 0)
  2055. {
  2056. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2057. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2058. {
  2059. entity.NewProduct = 1;
  2060. }
  2061. }
  2062. if (isNull)
  2063. {
  2064. father.create_time = DateTime.Now;
  2065. father.Update();
  2066. entity.Create();
  2067. }
  2068. else
  2069. {
  2070. entity.Update();
  2071. }
  2072. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2073. CeErpSukuraData.createInfo(entity.ctid, 1);
  2074. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "电子稿推送生成" + entity.seller_memo, entity.OrderState);
  2075. }
  2076. public static void createDemoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2077. {
  2078. if (itemMemo.Length <= 0) return;
  2079. string ctid = "";
  2080. string splitTag = "";
  2081. if (isMulty && itemMemo.Length > 2)
  2082. {
  2083. string preStr = "C" + orderIndex + "_";
  2084. ctid = preStr + father.tid;
  2085. splitTag = "C" + orderIndex;
  2086. }
  2087. else if (itemMemo.Length > 2)
  2088. {
  2089. ctid = father.tid;
  2090. }
  2091. CeErpTradeCell entity = null;
  2092. entity = CeErpTradeCell.GetByCtid(ctid);
  2093. bool isNull = false;
  2094. if (entity == null)
  2095. {
  2096. entity = new CeErpTradeCell();
  2097. isNull = true;
  2098. entity.ctid = ctid;
  2099. //唯一标识
  2100. entity.OrderSn = ctid;
  2101. string orderSn = dataHelper.getSaleOrderSn();
  2102. if (orderSn != "")
  2103. {
  2104. entity.OrderSn = orderSn;
  2105. }
  2106. }
  2107. entity.UpdateTime = DateTime.Now;
  2108. entity.tid = father.tid;
  2109. entity.SplitTag = splitTag;
  2110. if (entity.ShopId == 0)
  2111. {
  2112. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2113. int shopId = 0;
  2114. if (nShop != null)
  2115. {
  2116. shopId = nShop.ID;
  2117. }
  2118. entity.ShopId = shopId;
  2119. }
  2120. entity.IsSample = 3;
  2121. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2122. if (entity.isDianziOrder == 1)
  2123. {
  2124. entity.isDianziOrder = 0;
  2125. }
  2126. string[] acclist = itemMemo.Split('-');
  2127. if (acclist.Length <= 3) return;
  2128. //string count = acclist[0];
  2129. string product = acclist[1];
  2130. string account = acclist[3];
  2131. DataRow cusInfo = getUserInfoByAccount(account);
  2132. if (cusInfo != null)
  2133. {
  2134. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2135. if (entity.OrderState > 6)
  2136. {
  2137. }
  2138. else
  2139. {
  2140. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2141. }
  2142. }
  2143. entity.ProductId = getProductIdByName(product);
  2144. if (entity.ProductId == 0)
  2145. {
  2146. return;
  2147. }
  2148. if (isMulty)
  2149. {
  2150. try
  2151. {
  2152. string strPrice = acclist[4];
  2153. if (strPrice.IndexOf("元") != -1)
  2154. {
  2155. strPrice = strPrice.Replace("元", "");
  2156. }
  2157. entity.payment = Convert.ToDouble(strPrice);
  2158. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2159. }
  2160. catch (Exception ex)
  2161. {
  2162. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2163. }
  2164. }
  2165. else
  2166. {
  2167. entity.payment = Convert.ToDouble(father.payment);
  2168. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2169. }
  2170. string newmemo = "(" + entity.OrderSn + ")-";
  2171. string newOtherMemo = "";
  2172. List<string> list = new List<string>();
  2173. for (int i = 0; i < acclist.Length; i++)
  2174. {
  2175. if (i == 3) continue;
  2176. if (isMulty)
  2177. {
  2178. if (i == 4) continue;
  2179. }
  2180. list.Add(acclist[i]);
  2181. }
  2182. newmemo += string.Join("-", list);
  2183. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  2184. newmemo += ("-" + sName);
  2185. if (father.buyer_nick.IndexOf("*") < 0)
  2186. {
  2187. newmemo += ("-" + father.buyer_nick);
  2188. }
  2189. newmemo += ("-" + father.receiver_state);
  2190. if (cusInfo != null)
  2191. {
  2192. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2193. }
  2194. if (isMulty)
  2195. {
  2196. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2197. }
  2198. if (itemMemo.IndexOf("顺丰到付") != -1)
  2199. {
  2200. if (newmemo.IndexOf("顺丰到付") == -1)
  2201. newmemo += ("-顺丰到付");
  2202. entity.IsSF = 2;
  2203. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2204. }
  2205. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2206. {
  2207. if (newmemo.IndexOf("顺丰寄付") == -1)
  2208. newmemo += ("-顺丰寄付");
  2209. entity.IsSF = 1;
  2210. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2211. }
  2212. if (itemMemo.IndexOf("加急") != -1)
  2213. {
  2214. if (newmemo.IndexOf("加急") == -1)
  2215. newmemo += ("-加急");
  2216. entity.IsUrgency = true;
  2217. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2218. }
  2219. entity.seller_memo = newmemo;
  2220. entity.OtherMemo = newOtherMemo;
  2221. entity.pay_time = father.pay_time;
  2222. entity.FinishDesignTime = DateTime.Now;
  2223. entity.StartDesignTime = DateTime.Now;
  2224. entity.WaitDesignTime = DateTime.Now;
  2225. entity.FinishPlaceTime = DateTime.Now;
  2226. entity.IsOldCustomer = 0;
  2227. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2228. if (oldRes > 0)
  2229. {
  2230. entity.IsOldCustomer = 1;
  2231. if (oldRes == 2)
  2232. {
  2233. entity.IsOldCustomer = 1;
  2234. entity.IsOldCustomerMore = 1;
  2235. }
  2236. }
  2237. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2238. {
  2239. entity.OrderState = -1;
  2240. entity.DesignUserId = 0;
  2241. entity.WaitDesignTime = null;
  2242. }
  2243. if (entity.ProductId > 0)
  2244. {
  2245. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2246. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2247. {
  2248. entity.NewProduct = 1;
  2249. }
  2250. }
  2251. if (isNull)
  2252. {
  2253. father.create_time = DateTime.Now;
  2254. father.Update();
  2255. entity.Create();
  2256. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2257. }
  2258. else
  2259. {
  2260. entity.Update();
  2261. }
  2262. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2263. CeErpSukuraData.createInfo(entity.ctid, 1);
  2264. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "寄样推送生成" + entity.seller_memo, entity.OrderState);
  2265. }
  2266. public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2267. {
  2268. if (itemMemo.Length <= 0) return;
  2269. string ctid = "";
  2270. string splitTag = "";
  2271. if (isMulty && itemMemo.Length > 2)
  2272. {
  2273. string preStr = "C" + orderIndex + "_";
  2274. ctid = preStr + father.tid;
  2275. splitTag = "C" + orderIndex;
  2276. }
  2277. else if (itemMemo.Length > 2)
  2278. {
  2279. ctid = father.tid;
  2280. }
  2281. CeErpTradeCell entity = null;
  2282. entity = CeErpTradeCell.GetByCtid(ctid);
  2283. bool isNull = false;
  2284. if (entity == null)
  2285. {
  2286. entity = new CeErpTradeCell();
  2287. isNull = true;
  2288. }
  2289. if (entity.OrderState > 6) return;
  2290. if (entity.ShopId == 0)
  2291. {
  2292. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2293. int shopId = 0;
  2294. if (nShop != null)
  2295. {
  2296. shopId = nShop.ID;
  2297. }
  2298. entity.ShopId = shopId;
  2299. }
  2300. if (entity.IsSample == 1 || entity.IsSample == 2)
  2301. {
  2302. entity.IsSample = 0;
  2303. entity.ptid = "";
  2304. }
  2305. if (entity.isDianziOrder == 1)
  2306. {
  2307. entity.isDianziOrder = 0;
  2308. }
  2309. entity.ctid = ctid;
  2310. if (string.IsNullOrEmpty(entity.OrderSn))
  2311. {
  2312. //唯一标识
  2313. string orderSn = dataHelper.getSaleOrderSn();
  2314. if (orderSn != "")
  2315. {
  2316. entity.OrderSn = orderSn;
  2317. }
  2318. }
  2319. entity.UpdateTime = DateTime.Now;
  2320. entity.tid = father.tid;
  2321. entity.SplitTag = splitTag;
  2322. string[] acclist = itemMemo.Split('-');
  2323. if (acclist.Length < 2) return;
  2324. if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
  2325. {
  2326. return;
  2327. }
  2328. string product = acclist[0];
  2329. string account = acclist[1];
  2330. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2331. if (cusInfo != null)
  2332. {
  2333. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2334. }
  2335. entity.IsOldCustomer = 0;
  2336. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  2337. entity.IsXianHuo = 1;
  2338. entity.IsGift = 1;
  2339. entity.FinishPlaceTime = father.pay_time;
  2340. if (entity.OrderState < 6)
  2341. {
  2342. entity.OrderState = Convert.ToInt32(OrderState.下单完成);
  2343. }
  2344. if (isMulty)
  2345. {
  2346. try
  2347. {
  2348. string strPrice = acclist[2];
  2349. if (strPrice.IndexOf("元") != -1)
  2350. {
  2351. strPrice = strPrice.Replace("元", "");
  2352. }
  2353. entity.payment = Convert.ToDouble(strPrice);
  2354. hePrice = hePrice - Convert.ToDecimal(acclist[2]);
  2355. }
  2356. catch (Exception ex)
  2357. {
  2358. //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
  2359. }
  2360. }
  2361. else
  2362. {
  2363. entity.payment = Convert.ToDouble(father.payment);
  2364. entity.AfterSalePayment = Convert.ToDouble(father.payment);
  2365. }
  2366. string newmemo = "(" + entity.OrderSn + ")-";
  2367. string newOtherMemo = "";
  2368. for (int i = 0; i < acclist.Length; i++)
  2369. {
  2370. if (i == 1) continue;
  2371. newmemo += acclist[i];
  2372. if (i < acclist.Length - 1)
  2373. {
  2374. newmemo += "-";
  2375. }
  2376. }
  2377. string sName = getShopSNameByName(father.seller_nick);
  2378. newmemo += ("" + sName);
  2379. newmemo += ("-" + father.buyer_nick);
  2380. newmemo += ("-" + father.receiver_state);
  2381. if (cusInfo != null)
  2382. {
  2383. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2384. }
  2385. if (isMulty)
  2386. {
  2387. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  2388. }
  2389. if (newmemo.IndexOf("现货") != -1)
  2390. {
  2391. newmemo = newmemo.Replace("礼物", "");
  2392. }
  2393. if (itemMemo.IndexOf("顺丰到付") != -1)
  2394. {
  2395. newmemo += ("-顺丰到付");
  2396. entity.IsSF = 2;
  2397. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2398. }
  2399. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2400. {
  2401. newmemo += ("-顺丰寄付");
  2402. entity.IsSF = 1;
  2403. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2404. }
  2405. if (itemMemo.IndexOf("加急") != -1)
  2406. {
  2407. newmemo += ("-加急");
  2408. entity.IsUrgency = true;
  2409. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2410. }
  2411. entity.seller_memo = newmemo;
  2412. entity.OtherMemo = newOtherMemo;
  2413. entity.pay_time = father.pay_time;
  2414. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2415. {
  2416. entity.OrderState = -1;
  2417. entity.DesignUserId = 0;
  2418. entity.WaitDesignTime = null;
  2419. }
  2420. if (entity.ProductId > 0)
  2421. {
  2422. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2423. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2424. {
  2425. entity.NewProduct = 1;
  2426. }
  2427. }
  2428. if (isNull)
  2429. {
  2430. father.create_time = DateTime.Now;
  2431. father.Update();
  2432. entity.Create();
  2433. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2434. }
  2435. else
  2436. {
  2437. entity.Update();
  2438. }
  2439. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2440. CeErpSukuraData.createInfo(entity.ctid, 1);
  2441. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
  2442. }
  2443. public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
  2444. {
  2445. if (itemMemo.Length <= 0) return;
  2446. string[] hebaoMemoList = itemMemo.Split(',');
  2447. string memo_index1 = hebaoMemoList[0];
  2448. string ctid = "";
  2449. string splitTag = "";
  2450. if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
  2451. {
  2452. string preStr = "C" + orderIndex + "_";
  2453. ctid = preStr + father.tid;
  2454. splitTag = "C" + orderIndex + "+" + orderIndex;
  2455. }
  2456. else if (itemMemo.Length > 2)
  2457. {
  2458. ctid = father.tid;
  2459. }
  2460. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2461. bool ishave = true;
  2462. if (entity == null)
  2463. {
  2464. entity = new CeErpTradeCell();
  2465. ishave = false;
  2466. }
  2467. if (entity.ShopId == 0)
  2468. {
  2469. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2470. int shopId = 0;
  2471. if (nShop != null)
  2472. {
  2473. shopId = nShop.ID;
  2474. }
  2475. entity.ShopId = shopId;
  2476. }
  2477. if (entity.IsSample == 1 || entity.IsSample == 2)
  2478. {
  2479. entity.IsSample = 0;
  2480. entity.ptid = "";
  2481. }
  2482. if (entity.isDianziOrder == 1)
  2483. {
  2484. entity.isDianziOrder = 0;
  2485. }
  2486. entity.ctid = ctid;
  2487. if (string.IsNullOrEmpty(entity.OrderSn))
  2488. {
  2489. //唯一标识
  2490. string orderSn = dataHelper.getSaleOrderSn();
  2491. if (orderSn != "")
  2492. {
  2493. entity.OrderSn = orderSn;
  2494. }
  2495. }
  2496. entity.UpdateTime = DateTime.Now;
  2497. entity.tid = father.tid;
  2498. entity.SplitTag = splitTag;
  2499. string[] acclist = memo_index1.Split('-');
  2500. bool isXianhuo = false;
  2501. if (acclist[0] == "现货")
  2502. {
  2503. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2504. System.Array.Resize(ref acclist, acclist.Length - 1);
  2505. isXianhuo = true;
  2506. }
  2507. if (acclist.Length < 6)
  2508. {
  2509. return;
  2510. }
  2511. string size = acclist[0];
  2512. string count = acclist[1];
  2513. bool isBuGanJiao = false;
  2514. string product = "";
  2515. string mt = "", ct = "";
  2516. string account = "";
  2517. memo_index1 = memo_index1.Replace("PVC", "pvc");
  2518. if ((acclist[3] == "不干胶" || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("礼物") == -1)
  2519. {
  2520. isBuGanJiao = true;
  2521. product = acclist[3];
  2522. mt = acclist[2];
  2523. }
  2524. else
  2525. {
  2526. product = acclist[2];
  2527. mt = acclist[3];
  2528. }
  2529. account = acclist[5];
  2530. ct = acclist[4];
  2531. entity.ProductId = getProductIdByName(product);
  2532. if (entity.ProductId == 0)
  2533. {
  2534. return;
  2535. }
  2536. if (isMulity && hePrice != 0)
  2537. {
  2538. entity.payment = Convert.ToDouble(hePrice);
  2539. }
  2540. else
  2541. {
  2542. entity.payment = father.payment;
  2543. }
  2544. DataRow cusInfo = getUserInfoByAccount(account);
  2545. if (cusInfo != null)
  2546. {
  2547. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2548. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2549. {
  2550. }
  2551. else
  2552. {
  2553. entity.OrderState = 2;
  2554. if (entity.ShopId != 0)
  2555. {
  2556. entity.OrderState = orderAudit(entity.ShopId);
  2557. }
  2558. if (entity.DesignUserId > 0)
  2559. {
  2560. entity.OrderState = 3;
  2561. }
  2562. }
  2563. }
  2564. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2565. {
  2566. entity.IsOldCustomer = 1;
  2567. if (itemMemo.IndexOf("改稿") != -1)
  2568. {
  2569. if (entity.payment > 0)
  2570. {
  2571. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  2572. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2573. {
  2574. }
  2575. else
  2576. {
  2577. dealOldCustomerEntityTag(ref entity, father);
  2578. }
  2579. }
  2580. }
  2581. else
  2582. {
  2583. entity.OrderState = 3;
  2584. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
  2585. entity.WaitDesignTime = DateTime.Now;
  2586. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
  2587. }
  2588. }
  2589. entity.Material = mt;
  2590. entity.ProductSize = size;
  2591. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count); ;
  2592. entity.Craft = ct;
  2593. entity.pay_time = father.pay_time;
  2594. string newmemo = "(" + entity.OrderSn + ")-";
  2595. if (isXianhuo)
  2596. {
  2597. newmemo += "现货-";
  2598. entity.IsXianHuo = 1;
  2599. }
  2600. string newOtherMemo = "";
  2601. for (int idx = 0; idx < hebaoMemoList.Length; idx++)
  2602. {
  2603. string smallitem = hebaoMemoList[idx];
  2604. if (idx == 0 && smallitem.IndexOf("海报") != -1)
  2605. {
  2606. newmemo = "";
  2607. }
  2608. string[] smallList = smallitem.Split('-');
  2609. if (smallList.Length > 5 && idx > 0)
  2610. {
  2611. string itemsize = smallList[0];
  2612. string itemcount = smallList[1];
  2613. string itemmt = "", itemct = "";
  2614. if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
  2615. {
  2616. itemmt = acclist[2];
  2617. }
  2618. else
  2619. {
  2620. itemmt = acclist[3];
  2621. }
  2622. itemct = acclist[4];
  2623. entity.ProductSize = entity.ProductSize + "," + itemsize;
  2624. entity.ProductCount = entity.ProductCount + "," + itemcount;
  2625. entity.Material = entity.Material + "," + itemmt;
  2626. entity.Craft = entity.Craft + "," + itemct;
  2627. }
  2628. if (smallList.Length >= 7)
  2629. {
  2630. smallList[6] = smallList[6].Replace("(", "");
  2631. smallList[6] = smallList[6].Replace(")", "");
  2632. smallList[6] = smallList[6].Replace("(", "");
  2633. smallList[6] = smallList[6].Replace(")", "");
  2634. entity.MakeSupplier = smallList[6];
  2635. smallList[6] = "(" + smallList[6] + ")";
  2636. newmemo += smallList[6];
  2637. newmemo += "-";
  2638. }
  2639. if (smallitem.IndexOf("海报") != -1)
  2640. {
  2641. newmemo += smallList[2];
  2642. newmemo += smallList[0];
  2643. newmemo += "-";
  2644. newmemo += smallList[1];
  2645. newmemo += "(";
  2646. newmemo += entity.OrderSn;
  2647. newmemo += ")";
  2648. newmemo += "-";
  2649. newmemo += smallList[4];
  2650. if (smallList.Length > 7)
  2651. {
  2652. for (int i = 7; i < smallList.Length; i++)
  2653. {
  2654. newOtherMemo += smallList[i];
  2655. newOtherMemo += "-";
  2656. }
  2657. }
  2658. if (smallitem.IndexOf("5mmpvc") != -1)
  2659. {
  2660. entity.ProductId = 8; //pvc卡片
  2661. }
  2662. }
  2663. else
  2664. {
  2665. for (int i = 0; i < smallList.Length; i++)
  2666. {
  2667. if (isMulity && i == 5)
  2668. {
  2669. continue;
  2670. }
  2671. if (i >= 7)
  2672. {
  2673. newOtherMemo += smallList[i];
  2674. if (i < smallList.Length - 2 && i != 2 && i != 3)
  2675. {
  2676. newOtherMemo += "-";
  2677. }
  2678. }
  2679. else
  2680. {
  2681. if (i == 6)
  2682. {
  2683. continue;
  2684. }
  2685. else
  2686. newmemo += smallList[i];
  2687. if (i != 2 && i != 3)
  2688. {
  2689. newmemo += "-";
  2690. }
  2691. }
  2692. }
  2693. }
  2694. if (hebaoMemoList.Length > idx + 1)
  2695. {
  2696. newmemo += ",";
  2697. newOtherMemo += ",";
  2698. }
  2699. }
  2700. entity.ProductCount = commonHelper.getProductCount(entity.ProductCount);
  2701. string sName = getShopSNameByName(father.seller_nick);
  2702. newmemo += (sName);
  2703. if (father.buyer_nick.IndexOf("*") < 0)
  2704. {
  2705. newmemo += ("-" + father.buyer_nick);
  2706. }
  2707. newmemo += ("-" + father.receiver_state);
  2708. if (cusInfo != null)
  2709. {
  2710. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  2711. }
  2712. if (orderIndex > 1 && isMulity)
  2713. {
  2714. newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
  2715. }
  2716. //newmemo += "-合包";
  2717. if (itemMemo.IndexOf("顺丰到付") != -1)
  2718. {
  2719. //if(newmemo.IndexOf("顺丰到付")==-1)
  2720. // newmemo += ("-顺丰到付");
  2721. entity.IsSF = 2;
  2722. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  2723. }
  2724. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  2725. {
  2726. //if (newmemo.IndexOf("顺丰寄付") == -1)
  2727. // newmemo += ("-顺丰寄付");
  2728. entity.IsSF = 1;
  2729. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  2730. }
  2731. if (itemMemo.IndexOf("加急") != -1)
  2732. {
  2733. //if (newmemo.IndexOf("加急") == -1)
  2734. // newmemo += ("-加急");
  2735. entity.IsUrgency = true;
  2736. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  2737. }
  2738. entity.seller_memo = newmemo;
  2739. entity.OtherMemo = newOtherMemo;
  2740. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  2741. {
  2742. string odt = commonHelper.getDateFromString(newOtherMemo);
  2743. if (odt.Length > 0)
  2744. {
  2745. entity.OldCustomerTime = Convert.ToDateTime(odt);
  2746. }
  2747. }
  2748. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2749. {
  2750. }
  2751. else
  2752. {
  2753. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  2754. {
  2755. entity.IsOldCustomer = 0;
  2756. }
  2757. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  2758. if (oldRes > 0)
  2759. {
  2760. entity.IsOldCustomer = 1;
  2761. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  2762. dealOldCustomerEntityAuto(ref entity);
  2763. }
  2764. }
  2765. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  2766. {
  2767. entity.OrderState = 6;
  2768. entity.FinishPlaceTime = DateTime.Now;
  2769. entity.SupplierId = 98;//-领鸿
  2770. }
  2771. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  2772. {
  2773. entity.OrderState = 6;
  2774. entity.FinishPlaceTime = DateTime.Now;
  2775. entity.SupplierId = 5;//-福广
  2776. }
  2777. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  2778. {
  2779. entity.OrderState = -1;
  2780. entity.DesignUserId = 0;
  2781. entity.WaitDesignTime = null;
  2782. }
  2783. if (entity.ProductId > 0)
  2784. {
  2785. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  2786. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  2787. {
  2788. entity.NewProduct = 1;
  2789. }
  2790. }
  2791. if (ishave)
  2792. {
  2793. entity.Update();
  2794. }
  2795. else
  2796. {
  2797. father.create_time = DateTime.Now;
  2798. father.Update();
  2799. entity.Create();
  2800. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  2801. }
  2802. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  2803. CeErpSukuraData.createInfo(entity.ctid, 1);
  2804. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
  2805. }
  2806. public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
  2807. {
  2808. if (itemMemo.Length <= 0) return;
  2809. //itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
  2810. string ctid = "";
  2811. string splitTag = "";
  2812. if (isMulity && itemMemo.Length > 2)
  2813. {
  2814. string preStr = "C" + orderIndex + "_";
  2815. ctid = preStr + father.tid;
  2816. splitTag = "C" + totalCount + "+" + orderIndex;
  2817. }
  2818. else if (itemMemo.Length > 2)
  2819. {
  2820. ctid = father.tid;
  2821. }
  2822. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  2823. bool ishave = true;
  2824. if (entity == null)
  2825. {
  2826. entity = new CeErpTradeCell();
  2827. ishave = false;
  2828. }
  2829. entity.ctid = ctid;
  2830. if (string.IsNullOrEmpty(entity.OrderSn))
  2831. {
  2832. //唯一标识
  2833. string orderSn = dataHelper.getSaleOrderSn();
  2834. if (orderSn != "")
  2835. {
  2836. entity.OrderSn = orderSn;
  2837. }
  2838. }
  2839. entity.UpdateTime = DateTime.Now;
  2840. entity.tid = father.tid;
  2841. entity.SplitTag = splitTag;
  2842. string[] acclist = itemMemo.Split('-');
  2843. bool isXianhuo = false;
  2844. if (acclist[0] == "现货")
  2845. {
  2846. isXianhuo = true;
  2847. System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
  2848. System.Array.Resize(ref acclist, acclist.Length - 1);
  2849. }
  2850. if (entity.ShopId == 0)
  2851. {
  2852. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  2853. int shopId = 0;
  2854. if (nShop != null)
  2855. {
  2856. shopId = nShop.ID;
  2857. }
  2858. entity.ShopId = shopId;
  2859. }
  2860. if (entity.IsSample == 1 || entity.IsSample == 2)
  2861. {
  2862. entity.IsSample = 0;
  2863. entity.ptid = "";
  2864. }
  2865. if (entity.isDianziOrder == 1)
  2866. {
  2867. entity.isDianziOrder = 0;
  2868. }
  2869. if (entity.IsXianHuo == 1)
  2870. {
  2871. entity.IsXianHuo = 0;
  2872. }
  2873. if (isMulity && acclist.Length < 7)
  2874. {
  2875. return;
  2876. }
  2877. if (acclist.Length < 6)
  2878. {
  2879. return;
  2880. }
  2881. string size = acclist[0];
  2882. string count = acclist[1];
  2883. bool isBuGanJiao = false;
  2884. string product = "";
  2885. string mt = "", ct = "";
  2886. string account = "";
  2887. itemMemo = itemMemo.Replace("PVC", "pvc");
  2888. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  2889. {
  2890. isBuGanJiao = true;
  2891. product = acclist[3];
  2892. mt = acclist[2];
  2893. }
  2894. else
  2895. {
  2896. product = acclist[2];
  2897. mt = acclist[3];
  2898. }
  2899. account = acclist[5];
  2900. ct = acclist[4];
  2901. if (isMulity)
  2902. {
  2903. try
  2904. {
  2905. string strPrice = acclist[6];
  2906. if (strPrice.IndexOf("元") != -1)
  2907. {
  2908. strPrice = strPrice.Replace("元", "");
  2909. }
  2910. entity.payment = Convert.ToDouble(strPrice);
  2911. hePrice = hePrice - Convert.ToDecimal(strPrice);
  2912. }
  2913. catch (Exception ex)
  2914. {
  2915. entity.payment = 0;
  2916. return;
  2917. }
  2918. if (acclist.Length >= 8)
  2919. {
  2920. acclist[7] = acclist[7].Replace("(", "");
  2921. acclist[7] = acclist[7].Replace(")", "");
  2922. acclist[7] = acclist[7].Replace("(", "");
  2923. acclist[7] = acclist[7].Replace(")", "");
  2924. entity.MakeSupplier = acclist[7];
  2925. acclist[7] = "(" + acclist[7] + ")";
  2926. }
  2927. }
  2928. else
  2929. {
  2930. entity.payment = father.payment;
  2931. if (acclist.Length >= 7)
  2932. {
  2933. acclist[6] = acclist[6].Replace("(", "");
  2934. acclist[6] = acclist[6].Replace(")", "");
  2935. acclist[6] = acclist[6].Replace("(", "");
  2936. acclist[6] = acclist[6].Replace(")", "");
  2937. entity.MakeSupplier = acclist[6];
  2938. acclist[6] = "(" + acclist[6] + ")";
  2939. }
  2940. }
  2941. entity.ProductId = getProductIdByName(product);
  2942. if (entity.ProductId == 0)
  2943. {
  2944. return;
  2945. }
  2946. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  2947. if (cusInfo != null)
  2948. {
  2949. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  2950. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2951. {
  2952. }
  2953. else
  2954. {
  2955. entity.OrderState = 2;
  2956. if (entity.ShopId != 0)
  2957. {
  2958. entity.OrderState = orderAudit(entity.ShopId);
  2959. }
  2960. if (entity.DesignUserId > 0)
  2961. {
  2962. entity.OrderState = 3;
  2963. }
  2964. }
  2965. }
  2966. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  2967. {
  2968. entity.IsOldCustomer = 1;
  2969. if (itemMemo.IndexOf("改稿") != -1)
  2970. {
  2971. if (entity.payment > 0)
  2972. {
  2973. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  2974. {
  2975. }
  2976. else
  2977. {
  2978. dealOldCustomerEntityTag(ref entity, father);
  2979. }
  2980. }
  2981. }
  2982. else
  2983. {
  2984. if (entity.payment != 0)
  2985. {
  2986. entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
  2987. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  2988. entity.WaitDesignTime = DateTime.Now;
  2989. entity.FinishPlaceTime = DateTime.Now;
  2990. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  2991. }
  2992. }
  2993. }
  2994. if (mt.IndexOf("铜板纸") != -1)
  2995. {
  2996. mt = mt.Replace("铜板纸", "铜版纸");
  2997. }
  2998. entity.Material = mt;
  2999. entity.ProductSize = size;
  3000. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count);
  3001. entity.Craft = ct;
  3002. entity.pay_time = father.pay_time;
  3003. if (itemMemo.IndexOf("电子稿") != -1)
  3004. {
  3005. entity.isDianziOrder = 1;
  3006. }
  3007. if (product == "现货手提袋")
  3008. {
  3009. entity.OrderState = 6;//下单完成
  3010. entity.FinishPlaceTime = DateTime.Now;
  3011. }
  3012. string newmemo = "(" + entity.OrderSn + ")-";
  3013. if (isXianhuo)
  3014. {
  3015. newmemo += "现货-";
  3016. entity.IsXianHuo = 1;
  3017. }
  3018. string newOtherMemo = "";
  3019. if (false)
  3020. {
  3021. newmemo = acclist[2];
  3022. newmemo += acclist[0];
  3023. newmemo += "-";
  3024. newmemo += acclist[1];
  3025. newmemo += "(";
  3026. newmemo += father.tid;
  3027. newmemo += ")";
  3028. newmemo += "-";
  3029. newmemo += acclist[4];
  3030. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3031. newmemo += ("-" + sName);
  3032. newmemo += ("-" + father.buyer_nick);
  3033. if (father.buyer_nick.IndexOf("*") < 0)
  3034. {
  3035. newmemo += ("-" + father.buyer_nick);
  3036. }
  3037. if (cusInfo != null)
  3038. {
  3039. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3040. }
  3041. if (isMulity)
  3042. {
  3043. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3044. }
  3045. if (acclist.Length > 7)
  3046. {
  3047. for (int i = 7; i < acclist.Length; i++)
  3048. {
  3049. newOtherMemo += acclist[i];
  3050. newOtherMemo += "-";
  3051. }
  3052. }
  3053. }
  3054. else
  3055. {
  3056. if (acclist.Length >= 7 && !isMulity)
  3057. {
  3058. newmemo += acclist[6];
  3059. newmemo += "-";
  3060. }
  3061. if (isMulity && acclist.Length >= 8)
  3062. {
  3063. newmemo += acclist[7];
  3064. newmemo += "-";
  3065. }
  3066. for (int i = 0; i < acclist.Length; i++)
  3067. {
  3068. if ((isMulity && i == 6) || i == 5)
  3069. {
  3070. continue;
  3071. }
  3072. if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
  3073. {
  3074. newOtherMemo += acclist[i];
  3075. newOtherMemo += "-";
  3076. }
  3077. else
  3078. {
  3079. if ((i == 6 && !isMulity) || (isMulity && i == 7))
  3080. {
  3081. continue;
  3082. }
  3083. else
  3084. newmemo += acclist[i];
  3085. if (i != 2 && i != 3)
  3086. {
  3087. newmemo += "-";
  3088. }
  3089. }
  3090. }
  3091. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3092. newmemo += (sName);
  3093. if (father.buyer_nick.IndexOf("*") < 0)
  3094. {
  3095. newmemo += ("-" + father.buyer_nick);
  3096. }
  3097. newmemo += ("-" + father.receiver_state);
  3098. if (cusInfo != null)
  3099. {
  3100. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3101. }
  3102. if (itemMemo.IndexOf("顺丰到付") != -1)
  3103. {
  3104. //if (newmemo.IndexOf("顺丰到付") == -1)
  3105. // newmemo += ("-顺丰到付");
  3106. entity.IsSF = 2;
  3107. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3108. }
  3109. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3110. {
  3111. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3112. // newmemo += ("-顺丰寄付");
  3113. entity.IsSF = 1;
  3114. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3115. }
  3116. if (itemMemo.IndexOf("加急") != -1)
  3117. {
  3118. //if (newmemo.IndexOf("加急") == -1)
  3119. // newmemo += ("-加急");
  3120. entity.IsUrgency = true;
  3121. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3122. }
  3123. }
  3124. if (isMulity)
  3125. {
  3126. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3127. }
  3128. newmemo = newmemo.Replace("\n", " ");
  3129. entity.seller_memo = newmemo;
  3130. entity.OtherMemo = newOtherMemo;
  3131. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3132. {
  3133. string odt = commonHelper.getDateFromString(newOtherMemo);
  3134. if (odt.Length > 0)
  3135. {
  3136. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3137. }
  3138. }
  3139. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3140. {
  3141. //到了设计那边,就更新memo,状态不设置
  3142. }
  3143. else
  3144. {
  3145. if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
  3146. {
  3147. entity.IsOldCustomer = 0;
  3148. }
  3149. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3150. if (oldRes > 0)
  3151. {
  3152. entity.IsOldCustomer = 1;
  3153. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3154. dealOldCustomerEntityAuto(ref entity);
  3155. }
  3156. }
  3157. if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
  3158. {
  3159. entity.OrderState = 6;
  3160. entity.FinishPlaceTime = DateTime.Now;
  3161. entity.SupplierId = 98;//-领鸿
  3162. }
  3163. if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
  3164. {
  3165. entity.OrderState = 6;
  3166. entity.FinishPlaceTime = DateTime.Now;
  3167. entity.SupplierId = 5;//-福广
  3168. }
  3169. if (entity.seller_memo.Contains("法式蛋糕"))
  3170. {
  3171. entity.OrderState = 6;
  3172. entity.FinishPlaceTime = DateTime.Now;
  3173. entity.SupplierId = 35;//-福广
  3174. }
  3175. //台湾省要审核
  3176. if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
  3177. {
  3178. entity.OrderState = -1;
  3179. entity.DesignUserId = 0;
  3180. entity.WaitDesignTime = null;
  3181. }
  3182. if (entity.ProductId > 0)
  3183. {
  3184. CeErpProduct ceErpProduct = CeErpProduct.GetById(entity.ProductId);
  3185. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  3186. {
  3187. entity.NewProduct = 1;
  3188. }
  3189. }
  3190. if (ishave)
  3191. {
  3192. entity.Update();
  3193. }
  3194. else
  3195. {
  3196. father.create_time = DateTime.Now;
  3197. father.Update();
  3198. entity.Create();
  3199. CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
  3200. }
  3201. //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
  3202. CeErpSukuraData.createInfo(entity.ctid, 1);
  3203. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
  3204. }
  3205. public static List<int> shop_list = new List<int>() { 5, 6, 8, 10, 11, 12, 14, 15, 16, 18, 24, 26, 28, 31, 32, 45, 56, 61, 126, 128 };
  3206. public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
  3207. {
  3208. //UV跟指定店铺
  3209. int[] shopList = { 49, 67, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
  3210. if ((entity.ProductId == 43 && !shop_list.Contains(entity.ShopId)) || shopList.Contains(entity.ShopId))
  3211. {
  3212. /**int curHour = DateTime.Now.Hour;
  3213. int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3214. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3215. {
  3216. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3217. entity.DesignUserId = initSysDesignerId;
  3218. entity.WaitDesignTime = DateTime.Now;
  3219. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3220. }
  3221. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3222. {
  3223. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3224. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3225. entity.DesignUserId = initSysDesignerId;
  3226. entity.WaitDesignTime = DateTime.Now;
  3227. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3228. }
  3229. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3230. {
  3231. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3232. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3233. entity.DesignUserId = initSysDesignerId;
  3234. entity.WaitDesignTime = DateTime.Now;
  3235. LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3236. }
  3237. else
  3238. {**/
  3239. int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3240. if (designId != 0)
  3241. {
  3242. entity.DesignUserId = designId;
  3243. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3244. entity.WaitDesignTime = DateTime.Now;
  3245. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
  3246. }
  3247. }
  3248. }
  3249. public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
  3250. {
  3251. int curHour = DateTime.Now.Hour;
  3252. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3253. /**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3254. {
  3255. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3256. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3257. entity.DesignUserId = initSysDesignerId;
  3258. entity.WaitDesignTime = DateTime.Now;
  3259. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3260. }
  3261. else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3262. {
  3263. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
  3264. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3265. entity.DesignUserId = initSysDesignerId;
  3266. entity.WaitDesignTime = DateTime.Now;
  3267. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3268. }
  3269. else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3270. {
  3271. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
  3272. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3273. entity.DesignUserId = initSysDesignerId;
  3274. entity.WaitDesignTime = DateTime.Now;
  3275. LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
  3276. }
  3277. else
  3278. {**/
  3279. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3280. //这个设计师有上班,有关联此店铺
  3281. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3282. {
  3283. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3284. entity.DesignUserId = initSysDesignerId;
  3285. entity.WaitDesignTime = DateTime.Now;
  3286. LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
  3287. }
  3288. //}
  3289. }
  3290. public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
  3291. {
  3292. if (itemMemo.Length <= 0) return;
  3293. string ctid = "";
  3294. string splitTag = "";
  3295. if (isMulity && itemMemo.Length > 2)
  3296. {
  3297. string preStr = "C" + orderIndex + "_";
  3298. ctid = preStr + father.tid;
  3299. splitTag = "C" + orderIndex;
  3300. }
  3301. else if (itemMemo.Length > 2)
  3302. {
  3303. ctid = father.tid;
  3304. }
  3305. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  3306. bool ishave = true;
  3307. if (entity == null)
  3308. {
  3309. entity = new CeErpTradeCell();
  3310. ishave = false;
  3311. }
  3312. entity.ctid = ctid;
  3313. entity.tid = father.tid;
  3314. entity.SplitTag = splitTag;
  3315. string[] acclist = itemMemo.Split('-');
  3316. if (entity.ShopId == 0)
  3317. {
  3318. CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
  3319. int shopId = 0;
  3320. if (nShop != null)
  3321. {
  3322. shopId = nShop.ID;
  3323. }
  3324. entity.ShopId = shopId;
  3325. }
  3326. if (entity.IsSample == 1 || entity.IsSample == 2)
  3327. {
  3328. entity.IsSample = 0;
  3329. }
  3330. if (entity.isDianziOrder == 1)
  3331. {
  3332. entity.isDianziOrder = 0;
  3333. }
  3334. if (acclist.Length < 6)
  3335. {
  3336. return;
  3337. }
  3338. string size = acclist[0];
  3339. string count = acclist[1];
  3340. bool isBuGanJiao = false;
  3341. string product = "";
  3342. string mt = "", ct = "";
  3343. string account = "";
  3344. itemMemo = itemMemo.Replace("PVC", "pvc");
  3345. if ((acclist[3] == "不干胶" || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
  3346. {
  3347. isBuGanJiao = true;
  3348. product = acclist[3];
  3349. mt = acclist[2];
  3350. }
  3351. else
  3352. {
  3353. product = acclist[2];
  3354. mt = acclist[3];
  3355. }
  3356. account = acclist[5];
  3357. ct = acclist[4];
  3358. if (isMulity)
  3359. {
  3360. entity.payment = orderPrice;
  3361. if (acclist.Length >= 7)
  3362. {
  3363. acclist[6] = acclist[6].Replace("(", "");
  3364. acclist[6] = acclist[6].Replace(")", "");
  3365. acclist[6] = acclist[6].Replace("(", "");
  3366. acclist[6] = acclist[6].Replace(")", "");
  3367. entity.MakeSupplier = acclist[6];
  3368. acclist[6] = "(" + acclist[6] + ")";
  3369. }
  3370. }
  3371. entity.ProductId = getProductIdByName(product);
  3372. if (entity.ProductId == 0)
  3373. {
  3374. return;
  3375. }
  3376. DataRow cusInfo = getUserInfoByAccount(account); //客服id
  3377. if (cusInfo != null)
  3378. {
  3379. entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
  3380. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3381. {
  3382. }
  3383. else
  3384. {
  3385. entity.OrderState = 2;
  3386. if (entity.ShopId != 0)
  3387. {
  3388. entity.OrderState = orderAudit(entity.ShopId);
  3389. }
  3390. if (entity.DesignUserId > 0)
  3391. {
  3392. entity.OrderState = 3;
  3393. }
  3394. }
  3395. }
  3396. if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
  3397. {
  3398. entity.IsOldCustomer = 1;
  3399. if (itemMemo.IndexOf("改稿") != -1)
  3400. {
  3401. if (entity.payment > 0)
  3402. {
  3403. //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
  3404. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3405. {
  3406. }
  3407. else
  3408. {
  3409. int designId = Convert.ToInt32(webConfig.PlaceChangeId);
  3410. CeErpUser oldGaiPlace = CeErpUser.Get(designId);
  3411. if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
  3412. {
  3413. }
  3414. else
  3415. {
  3416. designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
  3417. }
  3418. if (designId != 0)
  3419. {
  3420. entity.DesignUserId = designId;
  3421. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3422. entity.WaitDesignTime = DateTime.Now;
  3423. LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
  3424. }
  3425. }
  3426. }
  3427. }
  3428. else
  3429. {
  3430. if (entity.payment != 0)
  3431. {
  3432. entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
  3433. entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
  3434. entity.WaitDesignTime = DateTime.Now;
  3435. LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
  3436. }
  3437. }
  3438. }
  3439. if (mt.IndexOf("铜板纸") != -1)
  3440. {
  3441. mt = mt.Replace("铜板纸", "铜版纸");
  3442. }
  3443. entity.Material = mt;
  3444. entity.ProductSize = size;
  3445. entity.ProductCount = commonHelper.getProductCount(count); ;//commonHelper.changeCountFromChiness(count);
  3446. entity.Craft = ct;
  3447. entity.pay_time = father.pay_time;
  3448. if (product == "现货手提袋")
  3449. {
  3450. entity.OrderState = 6;//下单完成
  3451. entity.FinishPlaceTime = DateTime.Now;
  3452. }
  3453. string newmemo = "(" + father.tid + ")-";
  3454. string newOtherMemo = "";
  3455. if (itemMemo.IndexOf("海报") != -1)
  3456. {
  3457. newmemo = acclist[2];
  3458. newmemo += acclist[0];
  3459. newmemo += "-";
  3460. newmemo += acclist[1];
  3461. newmemo += "(";
  3462. newmemo += father.tid;
  3463. newmemo += ")";
  3464. newmemo += "-";
  3465. newmemo += acclist[4];
  3466. string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
  3467. newmemo += ("-" + sName);
  3468. if (father.buyer_nick.IndexOf("*") < 0)
  3469. {
  3470. newmemo += ("-" + father.buyer_nick);
  3471. }
  3472. newmemo += ("-" + father.receiver_state);
  3473. if (cusInfo != null)
  3474. {
  3475. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3476. }
  3477. if (isMulity)
  3478. {
  3479. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3480. }
  3481. if (acclist.Length > 7)
  3482. {
  3483. for (int i = 7; i < acclist.Length; i++)
  3484. {
  3485. newOtherMemo += acclist[i];
  3486. newOtherMemo += "-";
  3487. }
  3488. }
  3489. }
  3490. else
  3491. {
  3492. if (acclist.Length >= 7)
  3493. {
  3494. newmemo += acclist[6];
  3495. newmemo += "-";
  3496. }
  3497. for (int i = 0; i < acclist.Length; i++)
  3498. {
  3499. if (i == 5)
  3500. {
  3501. continue;
  3502. }
  3503. if (i >= 7)
  3504. {
  3505. newOtherMemo += acclist[i];
  3506. newOtherMemo += "-";
  3507. }
  3508. else
  3509. {
  3510. if (i == 6)
  3511. {
  3512. continue;
  3513. }
  3514. else
  3515. newmemo += acclist[i];
  3516. if (i != 2 && i != 3)
  3517. {
  3518. newmemo += "-";
  3519. }
  3520. }
  3521. }
  3522. string sName = getShopSNameByName(father.seller_nick);
  3523. newmemo += (sName);
  3524. if (father.buyer_nick.IndexOf("*") < 0)
  3525. {
  3526. newmemo += ("-" + father.buyer_nick);
  3527. }
  3528. newmemo += ("-" + father.receiver_state);
  3529. if (cusInfo != null)
  3530. {
  3531. newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
  3532. }
  3533. if (itemMemo.IndexOf("顺丰到付") != -1)
  3534. {
  3535. entity.IsSF = 2;
  3536. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
  3537. }
  3538. else if (itemMemo.IndexOf("顺丰寄付") != -1)
  3539. {
  3540. //if (newmemo.IndexOf("顺丰寄付") == -1)
  3541. // newmemo += ("-顺丰寄付");
  3542. entity.IsSF = 1;
  3543. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
  3544. }
  3545. if (itemMemo.IndexOf("加急") != -1)
  3546. {
  3547. //if (newmemo.IndexOf("加急") == -1)
  3548. // newmemo += ("-加急");
  3549. entity.IsUrgency = true;
  3550. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
  3551. }
  3552. }
  3553. if (isMulity)
  3554. {
  3555. newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
  3556. }
  3557. newmemo = newmemo.Replace("\n", " ");
  3558. entity.seller_memo = newmemo;
  3559. entity.OtherMemo = newOtherMemo;
  3560. if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
  3561. {
  3562. string odt = commonHelper.getDateFromString(newOtherMemo);
  3563. if (odt.Length > 0)
  3564. {
  3565. entity.OldCustomerTime = Convert.ToDateTime(odt);
  3566. }
  3567. }
  3568. if (entity.IsOldCustomer == 0)
  3569. {
  3570. if (entity.OrderState > 2 && entity.DesignUserId > 0)
  3571. {
  3572. //到了设计那边,就更新memo,状态不设置
  3573. }
  3574. else
  3575. {
  3576. int oldRes = isOldAndInsertCustomerInfo(father, entity);
  3577. if (oldRes > 0)
  3578. {
  3579. entity.IsOldCustomer = 1;
  3580. if (oldRes == 2) entity.IsOldCustomerMore = 1;
  3581. int curHour = DateTime.Now.Hour;
  3582. int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
  3583. if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
  3584. {
  3585. initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
  3586. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3587. entity.DesignUserId = initSysDesignerId;
  3588. entity.WaitDesignTime = DateTime.Now;
  3589. }
  3590. else
  3591. {
  3592. CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
  3593. if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
  3594. {
  3595. entity.OrderState = Convert.ToInt32(OrderState.待设计);
  3596. entity.DesignUserId = initSysDesignerId;
  3597. entity.WaitDesignTime = DateTime.Now;
  3598. }
  3599. }
  3600. }
  3601. }
  3602. }
  3603. if (ishave)
  3604. {
  3605. entity.Update();
  3606. }
  3607. else
  3608. {
  3609. entity.Create();
  3610. }
  3611. LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
  3612. }
  3613. public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
  3614. {
  3615. DateTime nowTime = DateTime.Now;
  3616. if (nowTime.Hour >= 17)
  3617. {
  3618. return 0;
  3619. }
  3620. string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
  3621. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3622. foreach (DataRow dr in dt.Rows)
  3623. {
  3624. if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"]) != Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
  3625. {
  3626. int designId = Convert.ToInt32(dr["DesignUserId"]);
  3627. string sql_user = "select * from view_erpuser where ','+pemShop+',' like '%," + shopId + ",%' and (PostCode='Designer' or PostCode='DesignerMr') and ','+pemDesign+',' like '%," + prodcutId + ",%' and OnDuty=1 and id=" + designId;
  3628. DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
  3629. if (dt_user.Rows.Count > 0)
  3630. {
  3631. return designId;
  3632. }
  3633. else
  3634. return 0;
  3635. }
  3636. }
  3637. return 0;
  3638. }
  3639. public static int getProductIdByName(string proName)
  3640. {
  3641. string dname = proName;
  3642. if (dname == "暧心贴")
  3643. {
  3644. dname = "暖心贴";
  3645. }
  3646. string sql = "select top 1 * from ce_erpproduct where uuid='" + dname + "';";
  3647. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3648. if (dt.Rows.Count > 0)
  3649. {
  3650. return Convert.ToInt32(dt.Rows[0]["ID"]);
  3651. }
  3652. return 0;
  3653. }
  3654. public static string getShopSNameByName(string seller_nick)
  3655. {
  3656. string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3657. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3658. if (dt.Rows.Count > 0)
  3659. {
  3660. return Convert.ToString(dt.Rows[0]["SName"]);
  3661. }
  3662. return "";
  3663. }
  3664. //public static string getShopRealName(string seller_nick)
  3665. //{
  3666. // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
  3667. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3668. // if (dt.Rows.Count > 0)
  3669. // {
  3670. // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
  3671. // return Convert.ToString(dt.Rows[0]["ShopName"]);
  3672. // }
  3673. // return seller_nick;
  3674. //}
  3675. public static DataRow getRelationOrder(string buyer, string sampTid)
  3676. {
  3677. string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer + "' and seller_memo not like '%补差价%' and tid<>'" + sampTid + "' order by id desc";
  3678. DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
  3679. if (dt.Rows.Count > 0)
  3680. {
  3681. DataRow need = dt.Rows[0];
  3682. if (dt.Rows.Count == 1)
  3683. {
  3684. return need;
  3685. }
  3686. int idx = 0;
  3687. foreach (DataRow dr in dt.Rows)
  3688. {
  3689. if (idx != 0)
  3690. {
  3691. int day = Convert.ToDateTime(need["pay_time"]).Day;
  3692. int nday = Convert.ToDateTime(dr["pay_time"]).Day;
  3693. if (day == nday)
  3694. {
  3695. need = dr;
  3696. }
  3697. }
  3698. idx++;
  3699. }
  3700. return need;
  3701. }
  3702. return null;
  3703. }
  3704. public static DataRow getUserInfoByAccount(string account)
  3705. {
  3706. string sql = "select * from view_erpuser where isOpen=1 and Account='" + account + "'";
  3707. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3708. if (dt != null && dt.Rows.Count > 0)
  3709. {
  3710. return dt.Rows[0];
  3711. }
  3712. return null;
  3713. }
  3714. public static string getShopNameByECode(string code)
  3715. {
  3716. string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
  3717. DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  3718. if (dt != null && dt.Rows.Count > 0)
  3719. {
  3720. return dt.Rows[0]["ShopName"].ToString();
  3721. }
  3722. return "";
  3723. }
  3724. // 时间戳转为C#格式时间
  3725. public static DateTime StampToDateTime(string timeStamp)
  3726. {
  3727. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  3728. long lTime = long.Parse(timeStamp + "0000");
  3729. TimeSpan toNow = new TimeSpan(lTime);
  3730. return dateTimeStart.Add(toNow);
  3731. }
  3732. public static void Api_Tmc_CreateNewOrder(string res)
  3733. {
  3734. Api_trade_fullinfo_get_response_Obj fullObj = null;
  3735. if (res == "") return;
  3736. try
  3737. {
  3738. res = GetUTF8String(Encoding.UTF8.GetBytes(res));
  3739. //res = res.Replace(" ", "");
  3740. fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
  3741. }
  3742. catch (Exception ex)
  3743. {
  3744. XLog.SaveLog(0, ex.Message);
  3745. }
  3746. if (fullObj == null)
  3747. {
  3748. Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
  3749. return;
  3750. }
  3751. ContentItem tObj = null;
  3752. if (fullObj.response.data.content.Count > 0)
  3753. {
  3754. tObj = fullObj.response.data.content[0];
  3755. }
  3756. if (tObj == null)
  3757. {
  3758. return;
  3759. }
  3760. //未付款,未成功的单不需要
  3761. if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
  3762. {
  3763. return;
  3764. }
  3765. List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
  3766. StringBuilder sql = new StringBuilder();
  3767. CeErpTrade trade = CeErpTrade.Get(tObj.refOid);
  3768. bool isCreate = false;
  3769. if (trade == null)
  3770. {
  3771. trade = new CeErpTrade();
  3772. isCreate = true;
  3773. }
  3774. //原始单创建
  3775. trade.tid = tObj.refOid;
  3776. if (tObj.posCode != null)
  3777. trade.posCode = tObj.posCode;
  3778. //trade.num = tObj.num;
  3779. trade.status = tObj.status;
  3780. trade.seller_flag = tObj.flag;
  3781. trade.type = tObj.refType;
  3782. trade.price = Convert.ToDouble(tObj.totalPrice);
  3783. trade.discount_fee = Convert.ToDouble(tObj.discountFee);
  3784. trade.total_fee = Convert.ToDouble(tObj.totalFee);
  3785. trade.created = StampToDateTime(tObj.orderTime);
  3786. if (tObj.payTime != null)
  3787. {
  3788. trade.pay_time = StampToDateTime(tObj.payTime);
  3789. }
  3790. if (tObj.modifyTime != null)
  3791. {
  3792. trade.modified = StampToDateTime(tObj.modifyTime);
  3793. }
  3794. if (tObj.finishTime != null)
  3795. {
  3796. trade.end_time = StampToDateTime(tObj.finishTime);
  3797. }
  3798. trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
  3799. trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
  3800. //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
  3801. trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
  3802. if (trade.seller_nick == "")
  3803. {
  3804. trade.seller_nick = getShopNameByECode(trade.posCode);
  3805. }
  3806. trade.payment = Convert.ToDouble(tObj.payment);
  3807. //trade.receiver_name = tObj.receiver_name;
  3808. trade.receiver_state = tObj.receiverState;
  3809. trade.receiver_city = tObj.receiverCity;
  3810. trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
  3811. trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
  3812. //trade.receiver_address = tObj.receiver_address;
  3813. //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
  3814. //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
  3815. //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
  3816. //{
  3817. // trade.consign_time = tObj.consign_time;
  3818. //}
  3819. if (tObj.shippingTime != null)
  3820. {
  3821. trade.delivery_time = StampToDateTime(tObj.shippingTime);
  3822. }
  3823. //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
  3824. trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
  3825. trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
  3826. if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
  3827. {
  3828. if (tObj.refType == "TMALL" || tObj.refType == "TB")
  3829. {
  3830. string[] acclist = tObj.sellerMemo.Split('-');
  3831. List<string> list = new List<string>(acclist);
  3832. string buyer_nick = "";
  3833. if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
  3834. {
  3835. if (list.Count > 3)
  3836. {
  3837. buyer_nick = list[3];
  3838. }
  3839. }
  3840. else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
  3841. {
  3842. if (list.Count > 1)
  3843. {
  3844. buyer_nick = list[1];
  3845. }
  3846. }
  3847. else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
  3848. {
  3849. if (list.Count > 1)
  3850. {
  3851. buyer_nick = list[1];
  3852. }
  3853. }
  3854. else if (trade.seller_memo.IndexOf("寄样") != -1)
  3855. {
  3856. if (list.Count > 3)
  3857. {
  3858. buyer_nick = list[3];
  3859. }
  3860. }
  3861. else if (trade.seller_memo.IndexOf("拿样订单") != -1)
  3862. {
  3863. if (list.Count > 1)
  3864. {
  3865. buyer_nick = list[1];
  3866. }
  3867. }
  3868. else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
  3869. {
  3870. if (list.Count > 1)
  3871. {
  3872. buyer_nick = list[1];
  3873. }
  3874. }
  3875. else
  3876. {
  3877. if (list.Count > 5)
  3878. {
  3879. buyer_nick = list[5];
  3880. }
  3881. }
  3882. tObj.sellerMemo = string.Join("-", list);
  3883. tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
  3884. trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
  3885. }
  3886. }
  3887. if (isCreate)
  3888. {
  3889. trade.Create();
  3890. }
  3891. else
  3892. {
  3893. trade.Update();
  3894. }
  3895. bool isXianhuo = false;
  3896. string xianhuoMemo = "(" + trade.tid + ")现货-";
  3897. //order表创建
  3898. foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
  3899. {
  3900. bool orderCreate = false;
  3901. CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
  3902. if (order == null)
  3903. {
  3904. order = new CeErpTradeOrder();
  3905. orderCreate = true;
  3906. }
  3907. order.tid = trade.tid;
  3908. order.oid = item.refOlId;
  3909. order.buyer_nick = trade.buyer_nick;
  3910. order.refund_status = item.refundStatus;
  3911. order.status = trade.status;
  3912. order.title = item.title;
  3913. order.price = Convert.ToDouble(item.price);
  3914. if (item.picUrl != null)
  3915. order.pic_path = item.picUrl;
  3916. order.num = Convert.ToDouble(item.num.ToString());
  3917. order.payment = Convert.ToDouble(item.price);
  3918. if (item.refSpuId != null && item.refSpuId != "")
  3919. {
  3920. order.spu_id = item.refSpuId;
  3921. }
  3922. //order.adjust_fee = Convert.ToDouble(item.price);
  3923. if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
  3924. {
  3925. order.sku_properties_name = item.standards;
  3926. order.sku_id = item.refSkuId;
  3927. isXianhuo = true;
  3928. xianhuoMemo += order.sku_properties_name;
  3929. xianhuoMemo += ("-数量:" + order.num + "; ");
  3930. }
  3931. if (orderCreate)
  3932. {
  3933. order.Create();
  3934. }
  3935. else
  3936. {
  3937. order.Update();
  3938. }
  3939. }
  3940. //if (isXianhuo)
  3941. //{
  3942. // xianhuoMemo += "-";
  3943. // xianhuoMemo += trade.seller_nick;
  3944. //}
  3945. //cell表创建
  3946. CeErpTradeCell entity = null;
  3947. entity = CeErpTradeCell.GetByCtid(tObj.refOid);
  3948. if (entity == null)
  3949. {
  3950. try
  3951. {
  3952. entity = new CeErpTradeCell();
  3953. entity.ctid = tObj.refOid;
  3954. entity.tid = tObj.refOid;
  3955. entity.payment = Convert.ToDouble(tObj.payment);
  3956. if (tObj.payTime != null)
  3957. {
  3958. entity.pay_time = StampToDateTime(tObj.payTime);
  3959. }
  3960. CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
  3961. int shopId = 0;
  3962. if (nShop != null)
  3963. {
  3964. shopId = nShop.ID;
  3965. }
  3966. entity.ShopId = shopId;
  3967. if (isXianhuo)
  3968. {
  3969. entity.OrderState = 6;//现货直接下单完成
  3970. entity.seller_memo = xianhuoMemo;
  3971. entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
  3972. entity.IsXianHuo = 1;
  3973. entity.FinishPlaceTime = entity.pay_time;
  3974. if (xianhuoMemo.IndexOf("封酒贴") != -1)
  3975. {
  3976. entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
  3977. if (trade.buyer_memo != "")
  3978. {
  3979. entity.OrderState = 2; //买家有备注的要设计
  3980. entity.ProductId = 1;
  3981. entity.IsXianHuo = 0;
  3982. xianhuoMemo = xianhuoMemo.Replace("现货", "");
  3983. xianhuoMemo = xianhuoMemo.Replace(" ", "");
  3984. entity.seller_memo = xianhuoMemo;
  3985. }
  3986. }
  3987. else if (xianhuoMemo.IndexOf("喜字贴") != -1)
  3988. {
  3989. entity.SupplierId = 70; //智涛
  3990. }
  3991. //if (trade != null)
  3992. //{
  3993. // trade.seller_memo = xianhuoMemo;
  3994. // trade.Update();
  3995. //}
  3996. }
  3997. entity.Create();
  3998. commonHelper.setSpuData(trade);
  3999. }
  4000. catch (Exception ex)
  4001. {
  4002. XLog.SaveLog(0, ex.Message);
  4003. }
  4004. }
  4005. if (tObj.sellerMemo.Length > 0)
  4006. {
  4007. try
  4008. {
  4009. createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
  4010. }
  4011. catch (Exception ex)
  4012. {
  4013. XLog.SaveLog(0, res + "|" + ex.Message);
  4014. }
  4015. }
  4016. ////生成档案客户信息
  4017. //insertCustomerInfo(tObj);
  4018. }
  4019. public static int isOldCustomerOrder(CeErpTrade father)
  4020. {
  4021. if (father.seller_nick == "") return 0;
  4022. CeErpCustomer cusone = null;
  4023. cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  4024. if (cusone != null)
  4025. {
  4026. return 1;
  4027. }
  4028. return 0;
  4029. }
  4030. public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
  4031. {
  4032. if (father.seller_nick == "") return 0;
  4033. CeErpCustomer cus = null;
  4034. cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
  4035. if (cus == null)
  4036. {
  4037. cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
  4038. }
  4039. int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
  4040. //CeErpCustomer cusone = null;
  4041. //cusone = CeErpCustomer.GetByNick(father.buyer_nick);
  4042. if (cus != null)
  4043. {
  4044. if (cus.lastbuy_time.ToString() == "") return 0;
  4045. if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
  4046. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  4047. //cus.phone = Obj.receiver_mobile;
  4048. cus.buyer_id = father.buyer_id;
  4049. int returnNum = 0;
  4050. int lastpCount = cus.product_count;
  4051. if (cus.lastTid == father.tid)
  4052. {
  4053. if (pcount != cus.product_count)
  4054. {
  4055. cus.product_count = pcount;
  4056. cus.Update();
  4057. }
  4058. }
  4059. else
  4060. {
  4061. TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
  4062. cus.buyer_nick = father.buyer_nick;
  4063. cus.buy_day = Convert.ToInt32(tsday.TotalDays);
  4064. cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
  4065. cus.buy_count = cus.buy_count + 1;
  4066. cus.lastbuy_time2 = cus.lastbuy_time;
  4067. cus.lastbuy_time = father.pay_time;
  4068. cus.product_count = pcount;
  4069. cus.lastTid2 = cus.lastTid;
  4070. cus.lastTid = father.tid;
  4071. cus.Update();
  4072. }
  4073. if (cus.buy_day > 1)
  4074. {
  4075. if (pcount > lastpCount && cus.product_count != 0)
  4076. {
  4077. cus.isMore = 1;
  4078. returnNum = 2;
  4079. }
  4080. else
  4081. returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
  4082. }
  4083. else
  4084. {
  4085. returnNum = 0;
  4086. }
  4087. return returnNum;
  4088. }
  4089. //else if (cusone != null)
  4090. //{
  4091. // cusone.seller_nick = father.seller_nick;
  4092. // TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
  4093. // cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
  4094. // cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
  4095. // cusone.buy_count = cusone.buy_count + 1;
  4096. // cusone.lastbuy_time2 = cusone.lastbuy_time;
  4097. // cusone.lastbuy_time = father.pay_time;
  4098. // cusone.product_count = pcount;
  4099. // cusone.lastTid2 = cusone.lastTid;
  4100. // cusone.lastTid = father.tid;
  4101. // cusone.Update();
  4102. // return 1;
  4103. //}
  4104. else
  4105. {
  4106. try
  4107. {
  4108. cus = new CeErpCustomer();
  4109. cus.buyer_nick = father.buyer_nick;
  4110. cus.seller_nick = father.seller_nick;
  4111. cus.buyer_id = father.buyer_id;
  4112. //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
  4113. //cus.phone = Obj.receiver_mobile;
  4114. cus.buy_day = 0;
  4115. cus.buy_count = 1;
  4116. cus.lastbuy_time = father.pay_time;
  4117. cus.lastTid = father.tid;
  4118. cus.total_fee = Convert.ToDouble(father.payment);
  4119. cus.product_count = pcount;
  4120. cus.Create();
  4121. //StringBuilder sql = new StringBuilder();
  4122. //sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
  4123. //DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
  4124. //if (dt.Rows.Count > 0)
  4125. //{
  4126. // return true;
  4127. //}
  4128. return 0;
  4129. }
  4130. catch (Exception ex)
  4131. {
  4132. XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
  4133. }
  4134. }
  4135. return 0;
  4136. }
  4137. public static void removeOldCustomerInfo(CeErpTrade trade)
  4138. {
  4139. CeErpCustomer cus = null;
  4140. cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
  4141. if (cus != null)
  4142. {
  4143. if (cus.lastTid == trade.tid)
  4144. {
  4145. if (cus.buy_count > 1)
  4146. {
  4147. cus.lastTid = cus.lastTid2;
  4148. cus.lastbuy_time = cus.lastbuy_time2;
  4149. cus.buy_count = cus.buy_count - 1;
  4150. cus.Update();
  4151. }
  4152. else
  4153. {
  4154. CeErpCustomer.Del(cus.ID);
  4155. }
  4156. }
  4157. }
  4158. }
  4159. //接收到--新订单生成消息
  4160. public static void API_Tmc_TradeBuyerPay(string content)
  4161. {
  4162. Api_tmc_trade_info_Obj fullObj = null;
  4163. if (content == "") return;
  4164. try
  4165. {
  4166. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4167. //res = res.Replace(" ", "");
  4168. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4169. }
  4170. catch (Exception ex)
  4171. {
  4172. }
  4173. if (fullObj == null)
  4174. {
  4175. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4176. return;
  4177. }
  4178. Content tObj = fullObj.content;
  4179. string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
  4180. Api_Tmc_CreateNewOrder(res);
  4181. }
  4182. //推送接收到卖家备注修改
  4183. public static void API_Tmc_TradeMemoModified(string content)
  4184. {
  4185. Api_tmc_trade_info_Obj fullObj = null;
  4186. if (content == "") return;
  4187. try
  4188. {
  4189. content = GetUTF8String(Encoding.UTF8.GetBytes(content));
  4190. //res = res.Replace(" ", "");
  4191. fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
  4192. }
  4193. catch (Exception ex)
  4194. {
  4195. }
  4196. if (fullObj == null)
  4197. {
  4198. Console.WriteLine("Api_tmc_trade_info_Obj isNull");
  4199. return;
  4200. }
  4201. Content tObj = fullObj.content;
  4202. //原始表--没有这个单,不能拆分
  4203. CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
  4204. if (mainEn == null) return;
  4205. createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
  4206. }
  4207. public static int orderAudit(int shopId)
  4208. {
  4209. try
  4210. {
  4211. CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
  4212. if (ceErpShop == null) return 2;
  4213. if (!ceErpShop.orderAudit) return 2;
  4214. return -1;
  4215. }
  4216. catch (Exception ex)
  4217. {
  4218. return 2;
  4219. }
  4220. }
  4221. public static void autoCell(string tid)
  4222. {
  4223. if (tid.Length == 0)
  4224. {
  4225. return;
  4226. }
  4227. DateTime nowTime = DateTime.Now;
  4228. if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
  4229. {
  4230. return;
  4231. }
  4232. try
  4233. {
  4234. string sql = string.Format("select ctid,IsOldCustomer,shopid from view_ErpTradeCell where tid='{0}' and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and isrefund=0 order by IsUrgency desc,pay_time asc;", tid);
  4235. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4236. if (dt != null && dt.Rows.Count > 0)
  4237. {
  4238. bool changeBl = false;
  4239. //int c = Convert.ToInt32(result);// / 20 + 1;
  4240. foreach (DataRow dr in dt.Rows)
  4241. {
  4242. if (nowTime.Hour > 12 && nowTime.Hour < 17)
  4243. {
  4244. //这段时间白班晚班平均分配
  4245. if (changeBl)
  4246. {
  4247. changeBl = false;
  4248. }
  4249. else
  4250. {
  4251. changeBl = true;
  4252. }
  4253. }
  4254. else
  4255. changeBl = false;
  4256. string IsOldCustomer = dr["IsOldCustomer"].ToString();
  4257. string res = "";
  4258. CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
  4259. int userId = 0;
  4260. if (ceErpShop != null)
  4261. {
  4262. userId = ceErpShop.UserID;
  4263. }
  4264. SqlParameter[] sqlParameter = {
  4265. new SqlParameter("@inctid", SqlDbType.VarChar,200),
  4266. new SqlParameter("@intype", SqlDbType.Int,5),
  4267. new SqlParameter("@res", SqlDbType.VarChar, 50) };
  4268. sqlParameter[0].Value = dr["ctid"].ToString();
  4269. sqlParameter[1].Value = changeBl ? 1 : 0;
  4270. sqlParameter[2].Direction = ParameterDirection.Output;
  4271. if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
  4272. {
  4273. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
  4274. }
  4275. else
  4276. {
  4277. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
  4278. }
  4279. res = sqlParameter[2].Value.ToString();
  4280. }
  4281. }
  4282. }
  4283. catch (Exception ex)
  4284. {
  4285. XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
  4286. }
  4287. }
  4288. }
  4289. }