tmcHelper.cs 187 KB

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