tmcHelper.cs 179 KB

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