tmcHelper.cs 180 KB

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