| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572 |
- using BizCom;
- using Microsoft.SqlServer.Server;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using NHibernate.Mapping;
- using SiteCore;
- using SiteCore.Handler;
- using SiteCore.taobao;
- using SiteCore.taoObj;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using static SiteCore.taoObj.Api_tmc_trade_info_Obj;
- using static SiteCore.taoObj.Api_trade_fullinfo_get_response_Obj;
- using static SiteCore.taoObj.Api_trade_info;
- using static SiteCore.taoObj.dataShopResponseVo;
- using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
- using static SiteCore.taoObj.Trade_fullinfo_get_response_Obj;
- using static SiteCore.taoObj.work_core_vo;
- //status可选值:
- //* TRADE_NO_CREATE_PAY(没有创建支付宝交易)
- //* WAIT_BUYER_PAY(等待买家付款)
- //* SELLER_CONSIGNED_PART(卖家部分发货)
- //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款)
- //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货)
- //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用)
- //* TRADE_FINISHED(交易成功)
- //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭)
- //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易)
- //* PAY_PENDING(国际信用卡支付付款确认中)
- //* WAIT_PRE_AUTH_CONFIRM(0元购合约中)
- namespace SiteCore
- {
- /// <summary>
- /// 同步推送处理
- /// </summary>
- public class tmcHelper
- {
- public static int RemoveEmptyEntries { get; private set; }
- // case "taobao_trade_TradeCreate"://创建淘宝交易消息
- // {
- // break;
- // }
- // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息
- // case "taobao_trade_TradeMemoModified"://交易备注修改消息
- // case "taobao_trade_TradeRated"://交易评价变更消息
- // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款
- // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货)
- // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息
- // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息
- // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息
- // case "taobao_trade_TradeSellerShip"://卖家发货消息
- // case "taobao_trade_TradeClose"://关闭交易消息
- // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息
- // case "taobao_trade_TradeModifyFee"://修改交易费用消息
- public static string GetUTF8String(byte[] buffer)
- {
- if (buffer == null)
- return null;
- if (buffer.Length <= 3)
- {
- return Encoding.UTF8.GetString(buffer);
- }
- byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf };
- if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2])
- {
- return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3);
- }
- return Encoding.UTF8.GetString(buffer);
- }
- /// <summary>
- /// 交易订单关闭
- /// </summary>
- /// <param name="content"></param>
- public static void erp_CloseTrade(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
- if (status == "TRADE_CLOSED_BY_TAOBAO")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]);
- sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭);
- sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]);
- CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
- //消息通知
- }
- }
- //接收到--新订单生成消息
- public static void erp_TradeBuyerPay(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- string tid = dics["tid"].ToString();
- string sellerNick = dics["seller_nick"].ToString();
- string sessionkey = taobaoHelper.ShopKeyDics[sellerNick];
- string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test();
- createNewOrder(res);
- }
- //创建新订单
- public static void createNewOrder(string res)
- {
- Trade_fullinfo_get_response_Obj fullObj = null;
- if (res == "") return;
- try
- {
- res = GetUTF8String(Encoding.UTF8.GetBytes(res));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Trade_fullinfo_get_response_Obj>(res);
- }
- catch (Exception ex)
- {
- }
- if (fullObj == null)
- {
- Console.WriteLine("Trade_fullinfo_get_response_Obj isNull");
- return;
- }
- Trade tObj = fullObj.trade_fullinfo_get_response.trade;
- Orders orderList = tObj.orders;
- StringBuilder sql = new StringBuilder();
- CeErpTrade td = CeErpTrade.Get(tObj.tid);
- if (td != null)
- {
- //已经存在了,就不要再继续创建了;
- return;
- }
- //原始单创建
- CeErpTrade trade = new CeErpTrade();
- trade.tid = tObj.tid;
- trade.num = tObj.num;
- trade.status = tObj.status;
- trade.type = tObj.type;
- trade.price = Convert.ToDouble(tObj.price);
- trade.discount_fee = Convert.ToDouble(tObj.discount_fee);
- trade.total_fee = Convert.ToDouble(tObj.total_fee);
- trade.created = tObj.created;
- if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null)
- {
- trade.pay_time = tObj.pay_time;
- }
- if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null)
- {
- trade.modified = tObj.modified;
- }
- if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null)
- {
- trade.end_time = tObj.end_time;
- }
- trade.buyer_nick = tObj.buyer_nick;
- trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
- trade.seller_nick = tObj.seller_nick;
- trade.payment = Convert.ToDouble(tObj.payment);
- trade.receiver_name = tObj.receiver_name;
- trade.receiver_state = tObj.receiver_state;
- trade.receiver_city = tObj.receiver_city;
- trade.receiver_town = GetNoNullValue_string(tObj.receiver_town);
- trade.receiver_district = GetNoNullValue_string(tObj.receiver_district);
- trade.receiver_address = tObj.receiver_address;
- trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
- trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
- if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
- {
- trade.consign_time = tObj.consign_time;
- }
- if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null)
- {
- trade.delivery_time = tObj.delivery_time;
- }
- trade.buyer_message = GetNoNullValue_string(tObj.buyer_message);
- trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo);
- trade.seller_memo = GetNoNullValue_string(tObj.seller_memo);
- trade.Create();
- //查询是否有退款记录
- CeErpSpecialRefund ceErpSpecialRefund = new CeErpSpecialRefund();
- ceErpSpecialRefund = CeErpSpecialRefund.GetByTid(trade.tid);
- if (ceErpSpecialRefund != null)
- {
- refundTmcHelper.Api_TmcRefundMsg(ceErpSpecialRefund.refxml);
- ceErpSpecialRefund.whethernotify = 1;
- ceErpSpecialRefund.Update();
- }
- bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注
- string xianhuoMemo = "(" + trade.tid + ")现货-";
- //order表创建
- foreach (Order item in orderList.order)
- {
- CeErpTradeOrder order = new CeErpTradeOrder();
- order.tid = trade.tid;
- order.oid = item.oid;
- order.buyer_nick = trade.buyer_nick;
- order.refund_status = item.refund_status;
- order.status = item.status;
- order.title = item.title;
- order.price = Convert.ToDouble(item.price);
- order.pic_path = item.pic_path;
- order.num = Convert.ToDouble(item.num.ToString());
- order.payment = Convert.ToDouble(item.payment);
- order.adjust_fee = Convert.ToDouble(item.adjust_fee);
- if (item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货") != -1)
- {
- order.sku_properties_name = item.sku_properties_name;
- order.sku_id = item.sku_id;
- isXianhuo = true;
- xianhuoMemo += order.sku_properties_name;
- }
- order.Create();
- }
- if (isXianhuo)
- {
- xianhuoMemo += "-";
- xianhuoMemo += trade.seller_nick;
- }
- //cell表创建
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(tObj.tid);
- if (entity == null)
- {
- try
- {
- entity = new CeErpTradeCell();
- entity.ctid = tObj.tid;
- entity.tid = tObj.tid;
- entity.payment = Convert.ToDouble(tObj.payment);
- if (isXianhuo)
- {
- entity.OrderState = 5;
- entity.seller_memo = xianhuoMemo;
- }
- entity.Create();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- }
- //生成档案客户信息
- operateCustomer(tObj);
- }
- public static void operateCustomer(Trade Obj)
- {
- CeErpCustomer cus = null;
- cus = CeErpCustomer.GetByNick(Obj.buyer_nick);
- if (cus != null)
- {
- cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
- cus.phone = Obj.receiver_mobile;
- TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time);
- cus.buy_day = tsday.Days;
- cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment);
- cus.buy_count = cus.buy_count + 1;
- cus.lastbuy_time = Obj.pay_time;
- cus.Update();
- }
- else
- {
- try
- {
- cus = new CeErpCustomer();
- cus.buyer_nick = Obj.buyer_nick;
- cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
- cus.phone = Obj.receiver_mobile;
- cus.buy_day = 0;
- cus.buy_count = 1;
- cus.lastbuy_time = Obj.pay_time;
- cus.total_fee = Convert.ToDouble(Obj.payment);
- cus.Create();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- }
- }
- public static string GetNoNullValue_string(string value)
- {
- value = value.Replace("\n", " ");
- value = value.Replace("\r", " ");
- value = value.Replace("*", "x");
- if (value == null)
- {
- return "";
- }
- return value;
- }
- public static string GetNull_tostring(object value)
- {
- if (value == null)
- {
- return "";
- }
- return value.ToString();
- }
- //接收到--卖家修改备注消息
- public static void erp_TradeMemoModified(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- if (!dics.ContainsKey("seller_memo"))
- {
- return;
- }
- string tid = dics["tid"].ToString();
- string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO
- string buyer = dics["buyer_nick"].ToString();
- //原始表--没有这个单,不能拆分
- CeErpTrade mainEn = CeErpTrade.Get(tid);
- if (mainEn == null) return;
- createCellOrder(mainEn, tid, smemo, buyer);
- }
- //接收到--交易成功消息
- public static void erp_TradeSuccess(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
- //if (status == "TRADE_FINISHED")
- //{
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]);
- sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成);
- sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //}
- }
- //接收到--卖家发货消息
- public static void erp_TradeSellerShip(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
- //if (status == "WAIT_BUYER_CONFIRM_GOODS")
- //{
- StringBuilder sql = new StringBuilder();
- //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState
- sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
- sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //}
- }
- //接收到买家子订单退款 并卖家确认
- public static void erp_TradePartlyRefund(string content)
- {
- Dictionary<string, object> dics = Utils.Serialization.JSON.ToDictionary(content);
- string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO
- //if (status == "TRADE_CLOSED")
- //{
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]);
- sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]);
- sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭, 1, dics["tid"]);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- LogHelper.addLog(dics["tid"].ToString(), 0, "客户申请退款,已确认", (int)OrderState.交易关闭);
- //}
- }
- public static void Api_TmcTradeMsg(string res)
- {
- Api_tmc_trade_info_Obj fullObj = null;
- if (res == "") return;
- try
- {
- res = GetUTF8String(Encoding.UTF8.GetBytes(res));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|1|" + ex.Message);
- }
- if (fullObj == null)
- {
- Console.WriteLine("Api_tmc_trade_info_Obj isNull");
- XLog.SaveLog(0, "Api_tmc_trade_info_Obj isNull");
- return;
- }
- Content tObj = fullObj.content;
- List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
- //未付款,未成功的单不需要 榆家不收
- if (tObj.status == "DELETED" || (tObj.status == "CANCEL" && tObj.refType != "JD") || tObj.status == "UNKNOWN" || tObj.status == "UNPAID" )
- {
- return;
- }
- bool isCreate = false;
- CeErpTrade trade = null;
- trade = CeErpTrade.Get(tObj.refOid);
- tObj.sellerMemo = tObj.sellerMemo.Replace("默拍-发小礼物", "").Replace("电子稿-发小礼物", "").Replace("客户联系不上-发小礼物", "");
- if (trade == null)
- { //新生成订单的
- isCreate = true;
- trade = new CeErpTrade();
- trade.tid = tObj.refOid;
- trade.type = tObj.refType;
- trade.price = Convert.ToDouble(tObj.totalPrice);
- trade.discount_fee = Convert.ToDouble(tObj.discountFee);
- trade.total_fee = Convert.ToDouble(tObj.totalFee);
- trade.created = StampToDateTime(tObj.orderTime);
- if (tObj.payTime != null && tObj.payTime.Length > 0)
- {
- trade.pay_time = StampToDateTime(tObj.payTime);
- }
- if (tObj.posCode != null) trade.posCode = tObj.posCode;
- trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
- if (trade.seller_nick == "")
- {
- trade.seller_nick = getShopNameByECode(trade.posCode);
- tObj.openSellerNick = trade.seller_nick;
- }
- //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
- trade.payment = Convert.ToDouble(tObj.payment);
- //trade.receiver_name = tObj.receiver_name;
- }
- if (trade.buyer_nick == null || trade.buyer_nick.Length == 0)
- {
- trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
- }
- trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
- trade.receiver_state = tObj.receiverState;
- trade.receiver_city = tObj.receiverCity;
- trade.receiverId = tObj.receiverId;
- trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
- trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
- if (trade.type == "JD" && tObj.status == "CANCEL")
- trade.status = "CLOSE";
- else
- trade.status = tObj.status;
- //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
- //{
- //}
- trade.seller_flag = tObj.flag;
- if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
- {
- trade.modified = StampToDateTime(tObj.modifyTime);
- }
- if (tObj.finishTime != null && tObj.finishTime.Length > 0)
- {
- trade.end_time = StampToDateTime(tObj.finishTime);
- }
- if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
- {
- trade.delivery_time = StampToDateTime(tObj.shippingTime);
- }
- //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
- trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
- bool isSellerMemoChange = false;
- //备注修改
- tObj.sellerMemo = GetNoNullValue_string(tObj.sellerMemo);
- if (trade.seller_memo != tObj.sellerMemo)
- {
- isSellerMemoChange = true;
- }
- if (trade.seller_memo.Length != tObj.sellerMemo.Length)
- {
- isSellerMemoChange = true;
- }
- trade.seller_memo = tObj.sellerMemo;
- if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
- {
- if (tObj.refType == "TMALL" || tObj.refType == "TB")
- {
- string[] acclist = tObj.sellerMemo.Split('-');
- List<string> list = new List<string>(acclist);
- string buyer_nick = "";
- if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
- {
- if (list.Count > 3)
- {
- buyer_nick = list[3];
- }
- }
- else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("寄样") != -1)
- {
- if (list.Count > 3)
- {
- buyer_nick = list[3];
- }
- }
- else if (trade.seller_memo.IndexOf("拿样订单") != -1)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else
- {
- if (list.Count > 5)
- {
- buyer_nick = list[5];
- }
- }
- tObj.sellerMemo = string.Join("-", list);
- tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
- trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
- }
- }
- if (isCreate)
- {
- trade.create_time = DateTime.Now;
- trade.Create();
- }
- else
- {
- if (tObj.status == "CLOSE")
- {
- trade.consign_time = DateTime.Now;
- }
- trade.Update();
- }
- //dataHelper.sendErpTradeInfo(new dataSendTradeBean(tObj));
- try
- {
- if (tObj.status == "CLOSE" || tObj.status == "CANCEL")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, tObj.refOid);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- ApiVo apiVo = new ApiVo();
- apiVo.actionName = "closeDesign";
- apiVo.orderNumber = tObj.refOid;
- //designHelper.API_WorkCore(apiVo);//closeDesign
- LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
- // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
- // removeOldCustomerInfo(trade);
- }
- else if (tObj.status == "COMPLETE")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, tObj.refOid);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
- }
- else if (tObj.status == "SHIPPED")//已发货
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tObj.refOid);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "shipped:" + ex.Message);
- throw ex;
- }
- int xianhuoProductCount = 0;
- bool isXianhuo = false;
- string xianhuoMemo = "(" + trade.tid + ")现货-";
- bool isNew = true;
- CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- try
- {
- foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
- {
- CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
- bool isCreateOrder = false;
- if (order == null)
- {
- order = new CeErpTradeOrder();
- isCreateOrder = true;
- order.oid = item.refOlId;
- order.tid = trade.tid;
- order.buyer_nick = trade.buyer_nick;
- }
- if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS")
- {
- CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid);
- if (refund == null)
- {
- refund = new CeErpTradeRefund();
- refund.refund_id = tObj.refOid;
- refund.tid = tObj.refOid;
- //refund.oid = item.oid;
- refund.created = DateTime.Now;
- if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
- {
- refund.modified = StampToDateTime(tObj.modifyTime);
- }
- refund.status = item.refundStatus;
- refund.order_status = tObj.status;
- refund.payment = tObj.payment;
- refund.refund_fee = tObj.payment;
- refund.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
- refund.buyer_id = GetNull_tostring(tObj.openBuyerId);
- refund.seller_nick = trade.seller_nick;
- refund.total_fee = tObj.payment;
- refund.RefundState = 1;//1待审核2待确认
- refund.Create();
- //cell订单 添加退款标记
- int rstate = commonHelper.getRefundTagByState(item.refundStatus);
- commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
- designHelper.API_refundOrder(tObj.refOid, "refundEd", "");
- LogHelper.addLog(tObj.refOid, 0, "已退款", (int)OrderState.交易关闭);
- }
- else
- {
- if (refund.status != item.refundStatus)
- {
- refund.modified = DateTime.Now;
- refund.status = item.refundStatus;
- refund.order_status = tObj.status;
- refund.Update();
- int rstate = commonHelper.getRefundTagByState(item.refundStatus);
- commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
- LogHelper.addLog(tObj.refOid, 0, "更新退款状态", (int)OrderState.交易关闭);
- }
- }
- }
- else if (item.refundStatus == "REFUNDING" && order.refund_status != "REFUNDING")
- {
- commonHelper.UpdateRefundOrderState(tObj.refOid, 1);
- designHelper.API_refundOrder(tObj.refOid, "refundIng", "");
- LogHelper.addLog(tObj.refOid, 0, "申请退款中");
- }
- else if (item.refundStatus == "NO_REFUND" && order.refund_status != "NO_REFUND" && isCreateOrder == false)
- {
- //CeErpTradeRefund.Del(tObj.refOid);
- commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
- designHelper.API_refundOrder(tObj.refOid, "refundCancel", "");
- LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
- }
- else if (item.refundStatus == "REJECT_REFUNDED" && order.refund_status != "REJECT_REFUNDED" && isCreateOrder == false)
- {
- //CeErpTradeRefund.Del(tObj.refOid);
- commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
- LogHelper.addLog(tObj.refOid, 0, "拒绝退货退款");
- }
- order.refund_status = item.refundStatus;
- order.status = trade.status;
- order.title = item.title;
- order.price = Convert.ToDouble(item.price);
- if (item.picUrl != null)
- order.pic_path = item.picUrl;
- order.num = Convert.ToDouble(item.num.ToString());
- order.payment = Convert.ToDouble(item.price);
- order.total_fee = Convert.ToDouble(item.totalFee);
- //order.adjust_fee = Convert.ToDouble(item.price);
- if (item.refSkuId != null && item.refSkuId != "")
- {
- order.sku_id = item.refSkuId;
- }
- if (item.standards != null && item.standards != "")
- {
- order.sku_properties_name = item.standards;
- }
- if (item.refSpuId != null && item.refSpuId != "")
- {
- order.spu_id = item.refSpuId;
- }
- 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)
- {
- isXianhuo = true;
- xianhuoMemo += order.sku_properties_name;
- xianhuoMemo += ("-数量:" + order.num + ";");
- xianhuoProductCount += (int)order.num;
- if (isCreateOrder)
- {
- string goodsSql = "select * from CE_ErpBagShopGoods";
- DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
- if (goodsDt.Rows.Count > 0)
- {
- foreach (DataRow gdr in goodsDt.Rows)
- {
- string bname = gdr["bname"].ToString();
- string bsize = gdr["bsize"].ToString();
- string bcount = gdr["bcount"].ToString();
- if (bname.Length > 0 && order.sku_properties_name.IndexOf(bname) != -1)
- {
- order.bagName = bname;
- order.isBagOrder = 1;
- }
- if (bsize.Length > 0 && order.sku_properties_name.IndexOf(bsize) != -1)
- {
- order.bagSize = bsize;
- }
- if (bcount.Length > 0 && order.sku_properties_name.IndexOf(bcount) != -1)
- {
- order.bagCount = bcount;
- int bbcount = commonHelper.getIntCountFromString(bcount);
- order.bagRealCount = bbcount * (int)order.num;
- }
- }
- }
- }
- }
- if (isCreateOrder)
- {
- order.Create();
- CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(order.spu_id);
- //dataHelper.sendErpTradeOrderInfo(new dataSendTradeOrderBean(item, tObj));
- if (ceErpTradeSpu == null)
- {
- ceErpTradeSpu = new CeErpTradeSpu();
- ceErpTradeSpu.spuId = order.spu_id;
- ceErpTradeSpu.tid = order.tid;
- ceErpTradeSpu.shopId = shopId;
- ceErpTradeSpu.createTime = DateTime.Now;
- dataSendSpuBean bean = new dataSendSpuBean();
- bean.ShortText1728890680485 = order.title;
- bean.ShortText1728890649488 = order.spu_id;
- bean.shopId = shopId.ToString();
- bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- dataResponseVo response = dataHelper.sendSpuInfo(bean);
- if (response != null)
- {
- if ("0".Equals(response.errcode))
- {
- ceErpTradeSpu.isSync = true;
- }
- else
- {
- ceErpTradeSpu.message = response.errmsg;
- }
- }
- ceErpTradeSpu.Create();
- }
- DateTime orderTime = ceErpTradeSpu.createTime ?? DateTime.MinValue;
- if (DateTime.Compare(orderTime.AddDays(30), DateTime.Now) < 0)
- {
- isNew = false;
- }
- }
- else
- {
- order.Update();
- }
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|order表:" + ex.Message);
- throw ex;
- }
- //if (isXianhuo)
- //{
- // xianhuoMemo += "-";
- // xianhuoMemo += trade.seller_nick;
- //}
- if (!trade.IsNew)
- {
- trade.IsNew = isNew;
- }
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
- if (entity == null)
- {
- try
- {
- entity = new CeErpTradeCell();
- entity.ctid = tObj.refOid;
- //唯一标识
- entity.OrderSn = tObj.refOid;
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- entity.tid = tObj.refOid;
- entity.seller_memo = "";
- entity.payment = Convert.ToDouble(tObj.payment);
- entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
- if (tObj.payTime != null)
- {
- entity.pay_time = StampToDateTime(tObj.payTime);
- }
- entity.UpdateTime = DateTime.Now;
- entity.ShopId = shopId;
- if (isXianhuo)
- {
- entity.OrderState = 6;
- entity.seller_memo = xianhuoMemo;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- entity.IsXianHuo = 1;
- entity.FinishPlaceTime = entity.pay_time;
- entity.ProductCount = xianhuoProductCount.ToString();
- if (xianhuoMemo.IndexOf("封酒贴") != -1)
- {
- entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
- if (trade.buyer_memo != "")
- {
- entity.OrderState = 2;
- entity.ProductId = 1;
- entity.IsXianHuo = 0;
- xianhuoMemo = xianhuoMemo.Replace("现货", "");
- xianhuoMemo = xianhuoMemo.Replace(" ", "");
- entity.seller_memo = xianhuoMemo;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- }
- }
- else if (xianhuoMemo.IndexOf("#") != -1)
- {
- entity.SupplierId = 87;
- }
- else if (xianhuoMemo.IndexOf("喜字贴") != -1)
- {
- entity.SupplierId = 70;
- }
- else if (xianhuoMemo.IndexOf("兔团团") != -1)
- {
- entity.SupplierId = 101;
- }
- else if (xianhuoMemo.IndexOf("手拉旗") != -1)
- {
- entity.SupplierId = 108;
- }
- try
- {
- string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
- DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
- List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
- List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
- foreach (DataRow dr in goodsDt.Rows)
- {
- string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
- List<string> xianhuo = sqlMemo.Split(',').ToList();
- foreach (var item in xianhuo)
- {
- if (string.IsNullOrEmpty(item)) continue;
- Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
- Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
- if (item.IndexOf('-') > -1)
- {
- List<string> list = item.Split('-').ToList();
- material_map.Add(dr["id"].ToString(), list[0]);
- name_map.Add(dr["id"].ToString(), list[1]);
- }
- else
- {
- material_map.Add(dr["id"].ToString(), item);
- }
- material_list.Add(material_map);
- name_list.Add(name_map);
- }
- }
- List<string> materials = new List<string>();
- List<string> names = new List<string>();
- List<string> result = new List<string>();
- for (int i = 0; i < material_list.Count; i++)
- {
- Dictionary<string, string> map = material_list[i];
- foreach (var item in map)
- {
- if (xianhuoMemo.IndexOf(item.Value) > -1)
- {
- Dictionary<string, string> map2 = name_list[i];
- if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
- {
- foreach (var item1 in map2)
- {
- if (xianhuoMemo.IndexOf(item1.Value) > -1)
- {
- names.Add(item1.Key);
- materials.Add(item.Key);
- }
- }
- }
- else
- {
- materials.Add(item.Key);
- }
- }
- }
- }
- if (names.Count > 0)//特殊名称有只先在特殊名称里选择
- {
- result = names.Distinct().ToList();
- }
- else
- {
- result = materials.Distinct().ToList();
- }
- if (result.Count > 0)
- {
- Random rnd = new Random();
- int index = rnd.Next(result.Count);
- entity.SupplierId = int.Parse(result[index]);
- }
- }
- catch (Exception e)
- {
- XLog.SaveLog(0, res + "|现货匹配|" + e.Message);
- }
- if (isCreate)
- {
- int oldRes = isOldAndInsertCustomerInfo(trade, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- }
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- //if (trade != null)
- //{
- // trade.seller_memo = xianhuoMemo;
- // trade.Update();
- //}
- }
- //if (xianhuoMemo.IndexOf("修改文字下单备注") != -1)
- //{
- // entity.OrderState = Convert.ToInt32(OrderState.待设计); // Convert.ToInt32(OrderState.待设计);
- // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
- // entity.WaitDesignTime = DateTime.Now;
- // entity.FinishPlaceTime = null;
- // entity.SupplierId = 0;
- // LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
- //}
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid);
- commonHelper.setSpuData(trade);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|cell创建" + ex.Message);
- }
- }
- else
- {
- if (entity.OrderState == 0 && string.IsNullOrEmpty(entity.seller_memo))
- {
- isSellerMemoChange = true;
- }
- }
- CeErpTradeCell.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set UpdateTime = getdate() where tid = '{0}'", tObj.refOid));
- if (tObj.sellerMemo == "物料")
- {
- entity.seller_memo = "(" + trade.tid + ")-物料";
- entity.OrderState = 6; //下单完成
- entity.WaitDesignTime = DateTime.Now;
- entity.FinishDesignTime = DateTime.Now;
- entity.StartDesignTime = DateTime.Now;
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsSample = 1;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- entity.Update();
- }
- //else if (isXianhuo && trade.status== "NOT_SHIPPED")
- //{
- // entity.seller_memo = xianhuoMemo;
- // entity.IsXianHuo = 1;
- // entity.FinishPlaceTime = entity.pay_time;
- // entity.ProductCount = xianhuoProductCount.ToString();
- // if (xianhuoMemo.IndexOf("封酒贴") != -1)
- // {
- // if (trade.buyer_memo != "") //没设计之前
- // {
- // if(entity.OrderState <= 2)
- // {
- // entity.OrderState = 2; //买家有备注的要设计
- // }
- // entity.ProductId = 1;
- // entity.IsXianHuo = 0;
- // xianhuoMemo = xianhuoMemo.Replace("现货", "");
- // xianhuoMemo = xianhuoMemo.Replace(" ", "");
- // entity.seller_memo = xianhuoMemo;
- // }
- // }
- // else if (xianhuoMemo.IndexOf("喜字贴") != -1)
- // {
- // entity.SupplierId = 70; //智涛
- // LogHelper.addLog(entity.ctid,0,"喜字贴纸现货到智涛待发货",0);
- // }
- // entity.Update();
- //}
- if (isSellerMemoChange)
- {
- try
- {
- createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
- if (entity.VipCustomer != 1 && entity.VipCustomer != 2)
- {
- commonHelper.checkIsVipOld(trade);
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|2|" + ex);
- }
- }
- }
- public static void Api_TmcTradeMsg_Create(string res)
- {
- Api_tmc_trade_info_Obj fullObj = null;
- if (res == "") return;
- try
- {
- res = GetUTF8String(Encoding.UTF8.GetBytes(res));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(res);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|1 create|" + ex.Message);
- throw ex;
- }
- if (fullObj == null)
- {
- XLog.SaveLog(0, "create Api_tmc_trade_info_Obj isNull");
- return;
- }
- Content tObj = fullObj.content;
- List<Api_tmc_trade_info_Obj.LinesItem> orderList = tObj.lines;
- if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
- {
- return;
- }
- bool isCreate = false;
- CeErpTrade trade = null;
- trade = CeErpTrade.Get(tObj.refOid);
- if (trade == null)
- {
- isCreate = true;
- trade = new CeErpTrade();
- trade.tid = tObj.refOid;
- trade.type = tObj.refType;
- trade.price = Convert.ToDouble(tObj.totalPrice);
- trade.discount_fee = Convert.ToDouble(tObj.discountFee);
- trade.total_fee = Convert.ToDouble(tObj.totalFee);
- trade.created = StampToDateTime(tObj.orderTime);
- if (tObj.payTime != null && tObj.payTime.Length > 0)
- {
- trade.pay_time = StampToDateTime(tObj.payTime);
- }
- if (tObj.posCode != null) trade.posCode = tObj.posCode;
- trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
- trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
- //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
- trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
- if (trade.seller_nick == "")
- {
- trade.seller_nick = getShopNameByECode(trade.posCode);
- }
- trade.payment = Convert.ToDouble(tObj.payment);
- //trade.receiver_name = tObj.receiver_name;
- trade.receiver_state = tObj.receiverState;
- trade.receiver_city = tObj.receiverCity;
- trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
- trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
- }
- trade.status = tObj.status;
- //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED")
- //{
- //}
- trade.seller_flag = tObj.flag;
- if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
- {
- trade.modified = StampToDateTime(tObj.modifyTime);
- }
- if (tObj.finishTime != null && tObj.finishTime.Length > 0)
- {
- trade.end_time = StampToDateTime(tObj.finishTime);
- }
- if (tObj.shippingTime != null && tObj.shippingTime.Length > 0)
- {
- trade.delivery_time = StampToDateTime(tObj.shippingTime);
- }
- //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
- trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
- bool isSellerMemoChange = false;
- if (trade.seller_memo != tObj.sellerMemo)
- {
- isSellerMemoChange = true;
- }
- trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
- if (isCreate)
- {
- trade.Create();
- }
- else
- {
- trade.Update();
- }
- int xianhuoProductCount = 0;
- bool isXianhuo = false;
- string xianhuoMemo = "(" + trade.tid + ")现货-";
- try
- {
- foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList)
- {
- CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
- bool isCreateOrder = false;
- if (order == null)
- {
- order = new CeErpTradeOrder();
- isCreateOrder = true;
- }
- order.tid = trade.tid;
- order.oid = item.refOlId;
- order.buyer_nick = trade.buyer_nick;
- order.refund_status = item.refundStatus;
- order.status = trade.status;
- order.title = item.title;
- order.price = Convert.ToDouble(item.price);
- if (item.picUrl != null)
- order.pic_path = item.picUrl;
- order.num = Convert.ToDouble(item.num.ToString());
- order.payment = Convert.ToDouble(item.price);
- //order.adjust_fee = Convert.ToDouble(item.price);
- if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
- {
- order.sku_properties_name = item.standards;
- order.sku_id = item.refSkuId;
- isXianhuo = true;
- xianhuoMemo += order.sku_properties_name;
- xianhuoMemo += ("-数量:" + order.num + "; ");
- xianhuoProductCount += (int)order.num;
- }
- if (isCreateOrder)
- {
- order.Create();
- }
- else
- {
- order.Update();
- }
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|create order表:" + ex.Message);
- throw ex;
- }
- //if (isXianhuo)
- //{
- // xianhuoMemo += "-";
- // xianhuoMemo += trade.seller_nick;
- //}
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
- if (entity == null)
- {
- try
- {
- entity = new CeErpTradeCell();
- entity.ctid = tObj.refOid;
- entity.tid = tObj.refOid;
- entity.seller_memo = "";
- entity.payment = Convert.ToDouble(tObj.payment);
- entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
- if (tObj.payTime != null)
- {
- entity.pay_time = StampToDateTime(tObj.payTime);
- }
- CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- if (isXianhuo)
- {
- entity.FinishPlaceTime = DateTime.Now;
- entity.OrderState = 6;
- entity.seller_memo = xianhuoMemo;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- entity.IsXianHuo = 1;
- if (xianhuoMemo.IndexOf("封酒贴") != -1)
- {
- entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);
- if (trade.buyer_memo != "")
- {
- entity.OrderState = 2;
- entity.ProductId = 1;
- entity.IsXianHuo = 0;
- xianhuoMemo = xianhuoMemo.Replace("现货", "");
- xianhuoMemo = xianhuoMemo.Replace(" ", "");
- entity.seller_memo = xianhuoMemo;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- }
- }
- else if (xianhuoMemo.IndexOf("喜字贴") != -1)
- {
- entity.SupplierId = 70;
- }
- entity.FinishPlaceTime = entity.pay_time;
- entity.ProductCount = xianhuoProductCount.ToString();
- if (isCreate)
- {
- int oldRes = isOldAndInsertCustomerInfo(trade, entity);
- if (oldRes == 2)
- {
- entity.IsOldCustomer = 1;
- entity.IsOldCustomerMore = 1;
- }
- else if (oldRes == 1)
- {
- entity.IsOldCustomer = 1;
- }
- }
- //if (trade != null)
- //{
- // trade.seller_memo = xianhuoMemo;
- // trade.Update();
- //}
- }
- entity.Create();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|create cell创建" + ex.Message);
- throw ex;
- }
- }
- if (isSellerMemoChange && trade.seller_memo.Length > 0)
- {
- try
- {
- createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|2_create|" + ex.Message);
- }
- }
- }
- public static void createCellOrder(CeErpTrade father, string tid, string smemo, string buyer, bool isJump = false)
- {
- smemo = smemo.Replace("\r", " ");
- smemo = smemo.Replace("\n", " ");
- bool isNeedCellOrder = true;
- //try
- //{
- string issql = "select * from ce_erptradecell where tid='" + tid + "';";
- DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
- if (ishavedt.Rows.Count > 0)
- {
- foreach (DataRow hdr in ishavedt.Rows)
- {
- if (smemo.IndexOf("封酒贴") != -1)
- {
- if (Convert.ToInt32(hdr["IsXianHuo"]) == 1 && Convert.ToInt32(hdr["OrderState"]) >= 4)
- {
- isNeedCellOrder = false;
- break;
- }
- else if (Convert.ToInt32(hdr["IsXianHuo"]) == 0 && Convert.ToInt32(hdr["OrderState"]) > 2)
- {
- isNeedCellOrder = false;
- break;
- }
- }
- 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))
- {
- isNeedCellOrder = false;
- break;
- }
- }
- if (isNeedCellOrder)
- {
- foreach (DataRow hdr in ishavedt.Rows)
- {
- if (hdr["ctid"].ToString().IndexOf("C") != -1)
- {
- string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
- CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
- break;
- }
- }
- }
- }
- //}
- //catch(Exception ex)
- //{
- // isNeedCellOrder = false;
- // XLog.SaveLog(0, "推送是否需要重新生成判断出错"+ tid + ex.Message);
- //}
- if (isJump)
- {
- isNeedCellOrder = true;
- LogHelper.addLog(tid, 0, "原单强制重新生成", 0);
- }
- //if (smemo.IndexOf("g") != -1)
- //{
- // smemo = smemo.Replace("g", "克");
- //}
- if (smemo.IndexOf("补差价") != -1)
- {
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(tid);
- bool ishaveBu = true;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- entity.ctid = tid;
- //唯一标识
- entity.OrderSn = tid;
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- entity.tid = tid;
- ishaveBu = false;
- }
- entity.UpdateTime = DateTime.Now;
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (father.type != "PDD")
- {
- if (entity.OrderState >= 5) return;
- }
- entity.seller_memo = smemo;
- entity.payment = Convert.ToDouble(father.payment);
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- entity.pay_time = father.pay_time;
- smemo = smemo.Replace(":", ":");
- string[] listmemo = smemo.Split(':');
- if (listmemo.Length > 1)
- {
- string maintid = listmemo[1];//System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", "");
- string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'";
- DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
- if (dt_bu.Rows.Count > 0)
- {
- entity.ptid = dt_bu.Rows[0]["tid"].ToString();
- if (father.type != "PDD")
- {
- entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]);
- }
- entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]);
- entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]);
- entity.SupplierId = Convert.ToInt32(dt_bu.Rows[0]["SupplierId"]);
- entity.seller_memo = "补差价:" + entity.ptid;
- entity.payment = father.payment;
- entity.IsSample = 2;
- if (dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value)
- {
- entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]);
- }
- if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value)
- {
- entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]);
- }
- if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value)
- {
- entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]);
- }
- if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value)
- {
- entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]);
- }
- }
- }
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (ishaveBu)
- {
- entity.Update();
- }
- else
- {
- father.create_time = DateTime.Now;
- father.orderType = 20;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 20, 10);
- }
- ApiVo apiVo = new ApiVo();
- apiVo.orderNumber = entity.ptid;
- apiVo.payment = entity.payment;
- apiVo.actionName = "repairDesign";
- designHelper.API_WorkCore(apiVo);//repairDesign
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
- CeErpSukuraData.createInfo(entity.ctid, 1);
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- isNeedCellOrder = false;
- commonHelper.setSpuData(father);
- }
- else if (smemo.IndexOf("拿样订单") != -1)
- {
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(tid);
- if (entity == null)
- {
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- entity = new CeErpTradeCell();
- entity.ctid = tid;
- //唯一标识
- entity.OrderSn = tid;
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = tid;
- entity.seller_memo = smemo;
- entity.payment = Convert.ToDouble(father.payment);
- entity.pay_time = father.pay_time;
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- entity.OrderState = 6; //下单完成
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsSample = 1;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- entity.IsOldCustomer = 0;
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- else
- {
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- entity.IsSample = 1;
- entity.UpdateTime = DateTime.Now;
- entity.seller_memo = smemo;
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsOldCustomer = 0;
- entity.Update();
- }
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
- CeErpSukuraData.createInfo(entity.ctid, 1);
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- isNeedCellOrder = false;
- commonHelper.setSpuData(father);
- }
- if (isNeedCellOrder == false)
- {
- return;
- }
- if (smemo.IndexOf("*") != -1)
- {
- return;
- }
- if (smemo.IndexOf("{") != -1 && smemo.IndexOf("+") != -1)
- {
- createNewSplitFn(smemo, father);
- return;
- }
- string[] memoList = null;
- if (smemo.IndexOf(",") != -1)
- {
- smemo = smemo.Replace(',', ',');
- }
- if (smemo.IndexOf(",,") != -1)
- {
- return;
- }
- memoList = smemo.Split(',');
- int orderIdx = 1;
- int hebaoCount = 0;
- bool isMulity = false;
- if (memoList.Length > 1)
- {
- isMulity = true;
- foreach (string mstr in memoList)
- {
- if (mstr.IndexOf("合包") != -1)
- {
- hebaoCount += 1;
- }
- }
- }
- if (hebaoCount == 1)
- {
- createHebaoCell(isMulity, 0, smemo, father);
- }
- else
- {
- decimal hePrice = Convert.ToDecimal(father.payment); //合包价格
- string needHebaoItem = "";
- foreach (string item in memoList)
- {
- if (item.IndexOf("合包") != -1)
- {
- needHebaoItem += item;
- needHebaoItem += ",";
- }
- else
- {
- //if (item.IndexOf("电子稿") != -1)
- //{
- // createDianziCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
- //}
- //else
- if (item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
- {
- createLogoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
- }
- else if (item.IndexOf("寄样") != -1)
- {
- createDemoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
- }
- else if (item.IndexOf("礼物") != -1)
- {
- createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
- }
- else
- createNotHeBaoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
- orderIdx = orderIdx + 1;
- }
- }
- bool isHaveHebaoOrder = false;
- if (needHebaoItem.Length > 0)
- {
- isHaveHebaoOrder = true;
- needHebaoItem = needHebaoItem.Substring(0, needHebaoItem.Length - 1);
- createHebaoCell(isMulity, orderIdx, needHebaoItem, father, hePrice);
- orderIdx = orderIdx + 1;
- }
- if (orderIdx > 2)
- {
- try
- {
- string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
- LogHelper.addLog(tid, 0, "delete ctid=tid orderidx=" + orderIdx, 0);
- if (System.Math.Abs(hePrice) > Convert.ToDecimal(0.01) && hePrice != Convert.ToDecimal(father.payment) && isHaveHebaoOrder == false)
- {
- sql_del += "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
- LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
- }
- CeErpTradeCell.ExecuteNonQuery(sql_del);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
- string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
- CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
- }
- }
- commonHelper.setSpuData(father);
- //autoCell(tid);
- }
- }
- public static void createNewSplitFn(string smemo, CeErpTrade father)
- {
- if (smemo.IndexOf("合包") != -1)
- {
- createHebaoCell(false, 0, smemo, father);
- }
- else
- {
- int firstDaKuoHaoCount = 0;
- string firstoneContent = commonHelper.MidStrEx(smemo, "{", "}");
- string[] oneElementList = firstoneContent.Split('+');
- firstDaKuoHaoCount = oneElementList.Length;
- string[] memoList = smemo.Split('-');
- for (int idx = 0; idx < firstDaKuoHaoCount; idx++)
- {
- string newMemoStr = "";
- foreach (string oneStr in memoList)
- {
- string oneContent = "";
- if (oneStr.IndexOf("{") != -1)
- {
- oneContent = commonHelper.MidStrEx(oneStr, "{", "}");
- string[] oneList = oneContent.Split('+');
- if (oneList.Length != firstDaKuoHaoCount)
- {
- XLog.SaveLog(0, father.tid + ",备注大括号内的元素个数不相等");
- return;
- }
- newMemoStr += oneList[idx];
- }
- else
- newMemoStr += oneStr;
- newMemoStr += "-";
- }
- newMemoStr = newMemoStr.Substring(0, newMemoStr.Length - 1);
- if (idx == 0)
- createNewSplitCell(true, idx + 1, newMemoStr, father, father.payment - firstDaKuoHaoCount * 0.1, firstDaKuoHaoCount);
- else
- createNewSplitCell(true, idx + 1, newMemoStr, father, 0.1, firstDaKuoHaoCount);
- }
- try
- {
- string sql_del = "delete from CE_ErpTradeCell where ctid='" + father.tid + "'";
- CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
- LogHelper.addLog(father.tid, 0, "新拆分方法 delete ctid=tid ", 0);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "|新拆分删除首单错误|" + ex.Message);
- }
- }
- }
- public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- string ctid = "";
- string splitTag = "";
- if (isMulty && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(ctid);
- bool isNull = false;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- isNull = true;
- entity.ctid = ctid;
- //唯一标识
- entity.OrderSn = ctid;
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- entity.ptid = "";
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- string[] acclist = itemMemo.Split('-');
- if (acclist.Length < 4) return;
- string count = acclist[0];
- string product = acclist[1];
- string account = acclist[3];
- DataRow cusInfo = getUserInfoByAccount(account); //客服id
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- entity.OrderState = 2;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- }
- }
- entity.ProductId = getProductIdByName("logo");
- if (entity.ProductId == 0)
- {
- return;
- }
- entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
- if (isMulty)
- {
- try
- {
- string strPrice = acclist[4];
- if (strPrice.IndexOf("元") != -1)
- {
- strPrice = strPrice.Replace("元", "");
- }
- entity.payment = Convert.ToDouble(strPrice);
- hePrice = hePrice - Convert.ToDecimal(acclist[4]);
- }
- catch (Exception ex)
- {
- }
- }
- else
- {
- entity.payment = Convert.ToDouble(father.payment);
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- }
- string newmemo = "(" + entity.OrderSn + ")-";
- string newOtherMemo = "";
- for (int i = 0; i < acclist.Length; i++)
- {
- if (i == 3) continue;
- if (i >= 4)
- {
- newOtherMemo += acclist[i];
- }
- else
- newmemo += acclist[i];
- if (i < acclist.Length - 2)
- {
- newmemo += "-";
- }
- }
- string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
- newmemo += ("-" + sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulty)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- if (newmemo.IndexOf("顺丰到付") == -1)
- newmemo += ("-顺丰到付");
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- if (newmemo.IndexOf("顺丰寄付") == -1)
- newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- if (newmemo.IndexOf("加急") == -1)
- newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- entity.pay_time = father.pay_time;
- //int oldRes = isOldAndInsertCustomerInfo(father, entity);
- //if (oldRes>0)
- //{
- // entity.IsOldCustomer = 1;
- // if (oldRes == 2)
- // {
- // entity.IsOldCustomer = 1;
- // entity.IsOldCustomerMore = 1;
- // }
- //}
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
- {
- entity.IsOldCustomer = 0;
- }
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- int curHour = DateTime.Now.Hour;
- int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
- if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- else
- {
- CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
- if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
- {
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- }
- }
- }
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (isNull)
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- else
- {
- entity.Update();
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "logo推送生成" + entity.seller_memo, entity.OrderState);
- }
- public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- string ctid = "";
- string splitTag = "";
- if (isMulity && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(ctid);
- bool isNull = false;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- isNull = true;
- }
- entity.ctid = ctid;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- entity.ptid = "";
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- string[] acclist = itemMemo.Split('-');
- if (acclist.Length < 4) return;
- string count = acclist[0];
- string product = acclist[1];
- string account = acclist[3];
- DataRow cusInfo = getUserInfoByAccount(account); //客服id
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- }
- if (entity.OrderState < 3 && entity.DesignUserId == 0)
- {
- entity.OrderState = Convert.ToInt32(OrderState.待抢单);
- //entity.OrderState = Convert.ToInt32(OrderState.待设计);
- //entity.DesignUserId = 255; //电子稿给亿佳设计
- //entity.WaitDesignTime = DateTime.Now;
- }
- entity.ProductId = getProductIdByName(product);
- if (entity.ProductId == 0)
- {
- return;
- }
- entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
- entity.isDianziOrder = 1;//电子稿
- entity.pay_time = father.pay_time;
- if (isMulity)
- {
- try
- {
- string strPrice = acclist[4];
- if (strPrice.IndexOf("元") != -1)
- {
- strPrice = strPrice.Replace("元", "");
- }
- entity.payment = Convert.ToDouble(strPrice);
- hePrice = hePrice - Convert.ToDecimal(acclist[4]);
- }
- catch (Exception ex)
- {
- //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
- }
- }
- else
- {
- entity.payment = Convert.ToDouble(father.payment);
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- }
- string newmemo = "(" + entity.tid + ")-";
- string newOtherMemo = "";
- for (int i = 0; i < acclist.Length; i++)
- {
- if (i == 3) continue;
- newmemo += acclist[i];
- if (i < acclist.Length - 2)
- {
- newmemo += "-";
- }
- }
- string sName = getShopSNameByName(father.seller_nick);
- newmemo += ("-" + sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulity)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- //int oldRes = isOldAndInsertCustomerInfo(father, entity);
- //if (oldRes > 0)
- //{
- // entity.IsOldCustomer = 1;
- // if (oldRes == 2)
- // {
- // entity.IsOldCustomer = 1;
- // entity.IsOldCustomerMore = 1;
- // }
- //}
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- entity.IsOldCustomer = 0;
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- dealOldCustomerEntityAuto(ref entity);
- }
- }
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (isNull)
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- }
- else
- {
- entity.Update();
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "电子稿推送生成" + entity.seller_memo, entity.OrderState);
- }
- public static void createDemoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- string ctid = "";
- string splitTag = "";
- if (isMulty && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(ctid);
- bool isNull = false;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- isNull = true;
- entity.ctid = ctid;
- //唯一标识
- entity.OrderSn = ctid;
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- entity.IsSample = 3;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- string[] acclist = itemMemo.Split('-');
- if (acclist.Length <= 3) return;
- //string count = acclist[0];
- string product = acclist[1];
- string account = acclist[3];
- DataRow cusInfo = getUserInfoByAccount(account);
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- if (entity.OrderState > 6)
- {
- }
- else
- {
- entity.OrderState = Convert.ToInt32(OrderState.下单完成);
- }
- }
- entity.ProductId = getProductIdByName(product);
- if (entity.ProductId == 0)
- {
- return;
- }
- if (isMulty)
- {
- try
- {
- string strPrice = acclist[4];
- if (strPrice.IndexOf("元") != -1)
- {
- strPrice = strPrice.Replace("元", "");
- }
- entity.payment = Convert.ToDouble(strPrice);
- hePrice = hePrice - Convert.ToDecimal(strPrice);
- }
- catch (Exception ex)
- {
- //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
- }
- }
- else
- {
- entity.payment = Convert.ToDouble(father.payment);
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- }
- string newmemo = "(" + entity.OrderSn + ")-";
- string newOtherMemo = "";
- List<string> list = new List<string>();
- for (int i = 0; i < acclist.Length; i++)
- {
- if (i == 3) continue;
- if (isMulty)
- {
- if (i == 4) continue;
- }
- list.Add(acclist[i]);
- }
- newmemo += string.Join("-", list);
- string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
- newmemo += ("-" + sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulty)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- if (newmemo.IndexOf("顺丰到付") == -1)
- newmemo += ("-顺丰到付");
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- if (newmemo.IndexOf("顺丰寄付") == -1)
- newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- if (newmemo.IndexOf("加急") == -1)
- newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- entity.pay_time = father.pay_time;
- entity.FinishDesignTime = DateTime.Now;
- entity.StartDesignTime = DateTime.Now;
- entity.WaitDesignTime = DateTime.Now;
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsOldCustomer = 0;
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2)
- {
- entity.IsOldCustomer = 1;
- entity.IsOldCustomerMore = 1;
- }
- }
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (isNull)
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- else
- {
- entity.Update();
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "寄样推送生成" + entity.seller_memo, entity.OrderState);
- }
- public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- string ctid = "";
- string splitTag = "";
- if (isMulty && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(ctid);
- bool isNull = false;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- isNull = true;
- }
- if (entity.OrderState > 6) return;
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- entity.ptid = "";
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- entity.ctid = ctid;
- if (string.IsNullOrEmpty(entity.OrderSn))
- {
- //唯一标识
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- string[] acclist = itemMemo.Split('-');
- if (acclist.Length < 2) return;
- if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
- {
- return;
- }
- string product = acclist[0];
- string account = acclist[1];
- DataRow cusInfo = getUserInfoByAccount(account); //客服id
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- }
- entity.IsOldCustomer = 0;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
- entity.IsXianHuo = 1;
- entity.IsGift = 1;
- entity.FinishPlaceTime = father.pay_time;
- if (entity.OrderState < 6)
- {
- entity.OrderState = Convert.ToInt32(OrderState.下单完成);
- }
- if (isMulty)
- {
- try
- {
- string strPrice = acclist[2];
- if (strPrice.IndexOf("元") != -1)
- {
- strPrice = strPrice.Replace("元", "");
- }
- entity.payment = Convert.ToDouble(strPrice);
- hePrice = hePrice - Convert.ToDecimal(acclist[2]);
- }
- catch (Exception ex)
- {
- //XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
- }
- }
- else
- {
- entity.payment = Convert.ToDouble(father.payment);
- entity.AfterSalePayment = Convert.ToDouble(father.payment);
- }
- string newmemo = "(" + entity.OrderSn + ")-";
- string newOtherMemo = "";
- for (int i = 0; i < acclist.Length; i++)
- {
- if (i == 1) continue;
- newmemo += acclist[i];
- if (i < acclist.Length - 1)
- {
- newmemo += "-";
- }
- }
- string sName = getShopSNameByName(father.seller_nick);
- newmemo += ("" + sName);
- newmemo += ("-" + father.buyer_nick);
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulty)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- if (newmemo.IndexOf("现货") != -1)
- {
- newmemo = newmemo.Replace("礼物", "");
- }
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- newmemo += ("-顺丰到付");
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- entity.pay_time = father.pay_time;
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (isNull)
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- else
- {
- entity.Update();
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
- }
- public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
- {
- if (itemMemo.Length <= 0) return;
- string[] hebaoMemoList = itemMemo.Split(',');
- string memo_index1 = hebaoMemoList[0];
- string ctid = "";
- string splitTag = "";
- if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex + "+" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
- bool ishave = true;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- ishave = false;
- }
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- entity.ptid = "";
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- entity.ctid = ctid;
- if (string.IsNullOrEmpty(entity.OrderSn))
- {
- //唯一标识
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- string[] acclist = memo_index1.Split('-');
- bool isXianhuo = false;
- if (acclist[0] == "现货")
- {
- System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
- System.Array.Resize(ref acclist, acclist.Length - 1);
- isXianhuo = true;
- }
- if (acclist.Length < 6)
- {
- return;
- }
- string size = acclist[0];
- string count = acclist[1];
- bool isBuGanJiao = false;
- string product = "";
- string mt = "", ct = "";
- string account = "";
- memo_index1 = memo_index1.Replace("PVC", "pvc");
- if ((acclist[3] == "不干胶" || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("礼物") == -1)
- {
- isBuGanJiao = true;
- product = acclist[3];
- mt = acclist[2];
- }
- else
- {
- product = acclist[2];
- mt = acclist[3];
- }
- account = acclist[5];
- ct = acclist[4];
- entity.ProductId = getProductIdByName(product);
- if (entity.ProductId == 0)
- {
- return;
- }
- if (isMulity && hePrice != 0)
- {
- entity.payment = Convert.ToDouble(hePrice);
- }
- else
- {
- entity.payment = father.payment;
- }
- DataRow cusInfo = getUserInfoByAccount(account);
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- entity.OrderState = 2;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- if (entity.DesignUserId > 0)
- {
- entity.OrderState = 3;
- }
- }
- }
- if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
- {
- entity.IsOldCustomer = 1;
- if (itemMemo.IndexOf("改稿") != -1)
- {
- if (entity.payment > 0)
- {
- //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- dealOldCustomerEntityTag(ref entity, father);
- }
- }
- }
- else
- {
- entity.OrderState = 3;
- entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
- }
- }
- entity.Material = mt;
- entity.ProductSize = size;
- entity.ProductCount = count;//commonHelper.changeCountFromChiness(count); ;
- entity.Craft = ct;
- entity.pay_time = father.pay_time;
- string newmemo = "(" + entity.OrderSn + ")-";
- if (isXianhuo)
- {
- newmemo += "现货-";
- entity.IsXianHuo = 1;
- }
- string newOtherMemo = "";
- for (int idx = 0; idx < hebaoMemoList.Length; idx++)
- {
- string smallitem = hebaoMemoList[idx];
- if (idx == 0 && smallitem.IndexOf("海报") != -1)
- {
- newmemo = "";
- }
- string[] smallList = smallitem.Split('-');
- if (smallList.Length > 5 && idx > 0)
- {
- string itemsize = smallList[0];
- string itemcount = smallList[1];
- string itemmt = "", itemct = "";
- if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
- {
- itemmt = acclist[2];
- }
- else
- {
- itemmt = acclist[3];
- }
- itemct = acclist[4];
- entity.ProductSize = entity.ProductSize + "," + itemsize;
- entity.ProductCount = entity.ProductCount + "," + itemcount;
- entity.Material = entity.Material + "," + itemmt;
- entity.Craft = entity.Craft + "," + itemct;
- }
- if (smallList.Length >= 7)
- {
- smallList[6] = smallList[6].Replace("(", "");
- smallList[6] = smallList[6].Replace(")", "");
- smallList[6] = smallList[6].Replace("(", "");
- smallList[6] = smallList[6].Replace(")", "");
- entity.MakeSupplier = smallList[6];
- smallList[6] = "(" + smallList[6] + ")";
- newmemo += smallList[6];
- newmemo += "-";
- }
- if (smallitem.IndexOf("海报") != -1)
- {
- newmemo += smallList[2];
- newmemo += smallList[0];
- newmemo += "-";
- newmemo += smallList[1];
- newmemo += "(";
- newmemo += entity.OrderSn;
- newmemo += ")";
- newmemo += "-";
- newmemo += smallList[4];
- if (smallList.Length > 7)
- {
- for (int i = 7; i < smallList.Length; i++)
- {
- newOtherMemo += smallList[i];
- newOtherMemo += "-";
- }
- }
- if (smallitem.IndexOf("5mmpvc") != -1)
- {
- entity.ProductId = 8; //pvc卡片
- }
- }
- else
- {
- for (int i = 0; i < smallList.Length; i++)
- {
- if (isMulity && i == 5)
- {
- continue;
- }
- if (i >= 7)
- {
- newOtherMemo += smallList[i];
- if (i < smallList.Length - 2 && i != 2 && i != 3)
- {
- newOtherMemo += "-";
- }
- }
- else
- {
- if (i == 6)
- {
- continue;
- }
- else
- newmemo += smallList[i];
- if (i != 2 && i != 3)
- {
- newmemo += "-";
- }
- }
- }
- }
- if (hebaoMemoList.Length > idx + 1)
- {
- newmemo += ",";
- newOtherMemo += ",";
- }
- }
- string sName = getShopSNameByName(father.seller_nick);
- newmemo += (sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (orderIndex > 1 && isMulity)
- {
- newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
- }
- //newmemo += "-合包";
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- //if(newmemo.IndexOf("顺丰到付")==-1)
- // newmemo += ("-顺丰到付");
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- //if (newmemo.IndexOf("顺丰寄付") == -1)
- // newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- //if (newmemo.IndexOf("加急") == -1)
- // newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
- {
- string odt = commonHelper.getDateFromString(newOtherMemo);
- if (odt.Length > 0)
- {
- entity.OldCustomerTime = Convert.ToDateTime(odt);
- }
- }
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
- {
- entity.IsOldCustomer = 0;
- }
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- dealOldCustomerEntityAuto(ref entity);
- }
- }
- if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
- {
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.SupplierId = 98;//-领鸿
- }
- if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
- {
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.SupplierId = 5;//-福广
- }
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (ishave)
- {
- entity.Update();
- }
- else
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
- }
- public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- //itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
- string ctid = "";
- string splitTag = "";
- if (isMulity && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + totalCount + "+" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
- bool ishave = true;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- ishave = false;
- }
- entity.ctid = ctid;
- if (string.IsNullOrEmpty(entity.OrderSn))
- {
- //唯一标识
- string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }
- }
- entity.UpdateTime = DateTime.Now;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- string[] acclist = itemMemo.Split('-');
- bool isXianhuo = false;
- if (acclist[0] == "现货")
- {
- isXianhuo = true;
- System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
- System.Array.Resize(ref acclist, acclist.Length - 1);
- }
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- entity.ptid = "";
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- if (entity.IsXianHuo == 1)
- {
- entity.IsXianHuo = 0;
- }
- if (isMulity && acclist.Length < 7)
- {
- return;
- }
- if (acclist.Length < 6)
- {
- return;
- }
- string size = acclist[0];
- string count = acclist[1];
- bool isBuGanJiao = false;
- string product = "";
- string mt = "", ct = "";
- string account = "";
- itemMemo = itemMemo.Replace("PVC", "pvc");
- if ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
- {
- isBuGanJiao = true;
- product = acclist[3];
- mt = acclist[2];
- }
- else
- {
- product = acclist[2];
- mt = acclist[3];
- }
- account = acclist[5];
- ct = acclist[4];
- if (isMulity)
- {
- try
- {
- string strPrice = acclist[6];
- if (strPrice.IndexOf("元") != -1)
- {
- strPrice = strPrice.Replace("元", "");
- }
- entity.payment = Convert.ToDouble(strPrice);
- hePrice = hePrice - Convert.ToDecimal(strPrice);
- }
- catch (Exception ex)
- {
- entity.payment = 0;
- return;
- }
- if (acclist.Length >= 8)
- {
- acclist[7] = acclist[7].Replace("(", "");
- acclist[7] = acclist[7].Replace(")", "");
- acclist[7] = acclist[7].Replace("(", "");
- acclist[7] = acclist[7].Replace(")", "");
- entity.MakeSupplier = acclist[7];
- acclist[7] = "(" + acclist[7] + ")";
- }
- }
- else
- {
- entity.payment = father.payment;
- if (acclist.Length >= 7)
- {
- acclist[6] = acclist[6].Replace("(", "");
- acclist[6] = acclist[6].Replace(")", "");
- acclist[6] = acclist[6].Replace("(", "");
- acclist[6] = acclist[6].Replace(")", "");
- entity.MakeSupplier = acclist[6];
- acclist[6] = "(" + acclist[6] + ")";
- }
- }
- entity.ProductId = getProductIdByName(product);
- if (entity.ProductId == 0)
- {
- return;
- }
- DataRow cusInfo = getUserInfoByAccount(account); //客服id
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- entity.OrderState = 2;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- if (entity.DesignUserId > 0)
- {
- entity.OrderState = 3;
- }
- }
- }
- if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
- {
- entity.IsOldCustomer = 1;
- if (itemMemo.IndexOf("改稿") != -1)
- {
- if (entity.payment > 0)
- {
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- dealOldCustomerEntityTag(ref entity, father);
- }
- }
- }
- else
- {
- if (entity.payment != 0)
- {
- entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
- entity.WaitDesignTime = DateTime.Now;
- entity.FinishPlaceTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
- }
- }
- }
- if (mt.IndexOf("铜板纸") != -1)
- {
- mt = mt.Replace("铜板纸", "铜版纸");
- }
- entity.Material = mt;
- entity.ProductSize = size;
- entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
- entity.Craft = ct;
- entity.pay_time = father.pay_time;
- if (itemMemo.IndexOf("电子稿") != -1)
- {
- entity.isDianziOrder = 1;
- }
- if (product == "现货手提袋")
- {
- entity.OrderState = 6;//下单完成
- entity.FinishPlaceTime = DateTime.Now;
- }
- string newmemo = "(" + entity.OrderSn + ")-";
- if (isXianhuo)
- {
- newmemo += "现货-";
- entity.IsXianHuo = 1;
- }
- string newOtherMemo = "";
- if (false)
- {
- newmemo = acclist[2];
- newmemo += acclist[0];
- newmemo += "-";
- newmemo += acclist[1];
- newmemo += "(";
- newmemo += father.tid;
- newmemo += ")";
- newmemo += "-";
- newmemo += acclist[4];
- string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
- newmemo += ("-" + sName);
- newmemo += ("-" + father.buyer_nick);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulity)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- if (acclist.Length > 7)
- {
- for (int i = 7; i < acclist.Length; i++)
- {
- newOtherMemo += acclist[i];
- newOtherMemo += "-";
- }
- }
- }
- else
- {
- if (acclist.Length >= 7 && !isMulity)
- {
- newmemo += acclist[6];
- newmemo += "-";
- }
- if (isMulity && acclist.Length >= 8)
- {
- newmemo += acclist[7];
- newmemo += "-";
- }
- for (int i = 0; i < acclist.Length; i++)
- {
- if ((isMulity && i == 6) || i == 5)
- {
- continue;
- }
- if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
- {
- newOtherMemo += acclist[i];
- newOtherMemo += "-";
- }
- else
- {
- if ((i == 6 && !isMulity) || (isMulity && i == 7))
- {
- continue;
- }
- else
- newmemo += acclist[i];
- if (i != 2 && i != 3)
- {
- newmemo += "-";
- }
- }
- }
- string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
- newmemo += (sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- //if (newmemo.IndexOf("顺丰到付") == -1)
- // newmemo += ("-顺丰到付");
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- //if (newmemo.IndexOf("顺丰寄付") == -1)
- // newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- //if (newmemo.IndexOf("加急") == -1)
- // newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- }
- if (isMulity)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- newmemo = newmemo.Replace("\n", " ");
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
- {
- string odt = commonHelper.getDateFromString(newOtherMemo);
- if (odt.Length > 0)
- {
- entity.OldCustomerTime = Convert.ToDateTime(odt);
- }
- }
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- //到了设计那边,就更新memo,状态不设置
- }
- else
- {
- if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
- {
- entity.IsOldCustomer = 0;
- }
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- dealOldCustomerEntityAuto(ref entity);
- }
- }
- if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
- {
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.SupplierId = 98;//-领鸿
- }
- if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
- {
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.SupplierId = 5;//-福广
- }
- //台湾省要审核
- if ((father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip)) || entity.seller_memo.IndexOf("不要切单个") > -1 || commonHelper.isFarAddress(father.receiver_state))
- {
- entity.OrderState = -1;
- entity.DesignUserId = 0;
- entity.WaitDesignTime = null;
- }
- if (ishave)
- {
- entity.Update();
- }
- else
- {
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- //dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
- CeErpSukuraData.createInfo(entity.ctid, 1);
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
- }
- public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
- {
- //UV跟指定店铺
- int[] shopList = { 49, 67, 26, 45, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
- if (entity.ProductId == 43 || shopList.Contains(entity.ShopId))
- {
- /**int curHour = DateTime.Now.Hour;
- int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
- if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else
- {**/
- int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
- if (designId != 0)
- {
- entity.DesignUserId = designId;
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
- }
- }
- }
- public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
- {
- int curHour = DateTime.Now.Hour;
- int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
- /**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
- }
- else
- {**/
- CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
- //这个设计师有上班,有关联此店铺
- if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
- {
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
- }
- //}
- }
- public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
- {
- if (itemMemo.Length <= 0) return;
- string ctid = "";
- string splitTag = "";
- if (isMulity && itemMemo.Length > 2)
- {
- string preStr = "C" + orderIndex + "_";
- ctid = preStr + father.tid;
- splitTag = "C" + orderIndex;
- }
- else if (itemMemo.Length > 2)
- {
- ctid = father.tid;
- }
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
- bool ishave = true;
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- ishave = false;
- }
- entity.ctid = ctid;
- entity.tid = father.tid;
- entity.SplitTag = splitTag;
- string[] acclist = itemMemo.Split('-');
- if (entity.ShopId == 0)
- {
- CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- }
- if (entity.IsSample == 1 || entity.IsSample == 2)
- {
- entity.IsSample = 0;
- }
- if (entity.isDianziOrder == 1)
- {
- entity.isDianziOrder = 0;
- }
- if (acclist.Length < 6)
- {
- return;
- }
- string size = acclist[0];
- string count = acclist[1];
- bool isBuGanJiao = false;
- string product = "";
- string mt = "", ct = "";
- string account = "";
- itemMemo = itemMemo.Replace("PVC", "pvc");
- if ((acclist[3] == "不干胶" || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("礼物") == -1)
- {
- isBuGanJiao = true;
- product = acclist[3];
- mt = acclist[2];
- }
- else
- {
- product = acclist[2];
- mt = acclist[3];
- }
- account = acclist[5];
- ct = acclist[4];
- if (isMulity)
- {
- entity.payment = orderPrice;
- if (acclist.Length >= 7)
- {
- acclist[6] = acclist[6].Replace("(", "");
- acclist[6] = acclist[6].Replace(")", "");
- acclist[6] = acclist[6].Replace("(", "");
- acclist[6] = acclist[6].Replace(")", "");
- entity.MakeSupplier = acclist[6];
- acclist[6] = "(" + acclist[6] + ")";
- }
- }
- entity.ProductId = getProductIdByName(product);
- if (entity.ProductId == 0)
- {
- return;
- }
- DataRow cusInfo = getUserInfoByAccount(account); //客服id
- if (cusInfo != null)
- {
- entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- entity.OrderState = 2;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- if (entity.DesignUserId > 0)
- {
- entity.OrderState = 3;
- }
- }
- }
- if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
- {
- entity.IsOldCustomer = 1;
- if (itemMemo.IndexOf("改稿") != -1)
- {
- if (entity.payment > 0)
- {
- //designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- }
- else
- {
- int designId = Convert.ToInt32(webConfig.PlaceChangeId);
- CeErpUser oldGaiPlace = CeErpUser.Get(designId);
- if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
- {
- }
- else
- {
- designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
- }
- if (designId != 0)
- {
- entity.DesignUserId = designId;
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
- }
- }
- }
- }
- else
- {
- if (entity.payment != 0)
- {
- entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
- }
- }
- }
- if (mt.IndexOf("铜板纸") != -1)
- {
- mt = mt.Replace("铜板纸", "铜版纸");
- }
- entity.Material = mt;
- entity.ProductSize = size;
- entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
- entity.Craft = ct;
- entity.pay_time = father.pay_time;
- if (product == "现货手提袋")
- {
- entity.OrderState = 6;//下单完成
- entity.FinishPlaceTime = DateTime.Now;
- }
- string newmemo = "(" + father.tid + ")-";
- string newOtherMemo = "";
- if (itemMemo.IndexOf("海报") != -1)
- {
- newmemo = acclist[2];
- newmemo += acclist[0];
- newmemo += "-";
- newmemo += acclist[1];
- newmemo += "(";
- newmemo += father.tid;
- newmemo += ")";
- newmemo += "-";
- newmemo += acclist[4];
- string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
- newmemo += ("-" + sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (isMulity)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- if (acclist.Length > 7)
- {
- for (int i = 7; i < acclist.Length; i++)
- {
- newOtherMemo += acclist[i];
- newOtherMemo += "-";
- }
- }
- }
- else
- {
- if (acclist.Length >= 7)
- {
- newmemo += acclist[6];
- newmemo += "-";
- }
- for (int i = 0; i < acclist.Length; i++)
- {
- if (i == 5)
- {
- continue;
- }
- if (i >= 7)
- {
- newOtherMemo += acclist[i];
- newOtherMemo += "-";
- }
- else
- {
- if (i == 6)
- {
- continue;
- }
- else
- newmemo += acclist[i];
- if (i != 2 && i != 3)
- {
- newmemo += "-";
- }
- }
- }
- string sName = getShopSNameByName(father.seller_nick);
- newmemo += (sName);
- if (father.buyer_nick.IndexOf("*") < 0)
- {
- newmemo += ("-" + father.buyer_nick);
- }
- newmemo += ("-" + father.receiver_state);
- if (cusInfo != null)
- {
- newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
- }
- if (itemMemo.IndexOf("顺丰到付") != -1)
- {
- entity.IsSF = 2;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
- }
- else if (itemMemo.IndexOf("顺丰寄付") != -1)
- {
- //if (newmemo.IndexOf("顺丰寄付") == -1)
- // newmemo += ("-顺丰寄付");
- entity.IsSF = 1;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
- }
- if (itemMemo.IndexOf("加急") != -1)
- {
- //if (newmemo.IndexOf("加急") == -1)
- // newmemo += ("-加急");
- entity.IsUrgency = true;
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
- }
- }
- if (isMulity)
- {
- newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
- }
- newmemo = newmemo.Replace("\n", " ");
- entity.seller_memo = newmemo;
- entity.OtherMemo = newOtherMemo;
- if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
- {
- string odt = commonHelper.getDateFromString(newOtherMemo);
- if (odt.Length > 0)
- {
- entity.OldCustomerTime = Convert.ToDateTime(odt);
- }
- }
- if (entity.IsOldCustomer == 0)
- {
- if (entity.OrderState > 2 && entity.DesignUserId > 0)
- {
- //到了设计那边,就更新memo,状态不设置
- }
- else
- {
- int oldRes = isOldAndInsertCustomerInfo(father, entity);
- if (oldRes > 0)
- {
- entity.IsOldCustomer = 1;
- if (oldRes == 2) entity.IsOldCustomerMore = 1;
- int curHour = DateTime.Now.Hour;
- int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
- if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
- {
- initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- else
- {
- CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
- if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
- {
- entity.OrderState = Convert.ToInt32(OrderState.待设计);
- entity.DesignUserId = initSysDesignerId;
- entity.WaitDesignTime = DateTime.Now;
- }
- }
- }
- }
- }
- if (ishave)
- {
- entity.Update();
- }
- else
- {
- entity.Create();
- }
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
- }
- public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
- {
- DateTime nowTime = DateTime.Now;
- if (nowTime.Hour >= 17)
- {
- return 0;
- }
- string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';";
- DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"]) != Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计
- {
- int designId = Convert.ToInt32(dr["DesignUserId"]);
- 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;
- DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
- if (dt_user.Rows.Count > 0)
- {
- return designId;
- }
- else
- return 0;
- }
- }
- return 0;
- }
- public static int getProductIdByName(string proName)
- {
- string dname = proName;
- if (dname == "暧心贴")
- {
- dname = "暖心贴";
- }
- string sql = "select top 1 * from ce_erpproduct where uuid='" + dname + "';";
- DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
- if (dt.Rows.Count > 0)
- {
- return Convert.ToInt32(dt.Rows[0]["ID"]);
- }
- return 0;
- }
- public static string getShopSNameByName(string seller_nick)
- {
- string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
- DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
- if (dt.Rows.Count > 0)
- {
- return Convert.ToString(dt.Rows[0]["SName"]);
- }
- return "";
- }
- //public static string getShopRealName(string seller_nick)
- //{
- // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';";
- // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- // if (dt.Rows.Count > 0)
- // {
- // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString())
- // return Convert.ToString(dt.Rows[0]["ShopName"]);
- // }
- // return seller_nick;
- //}
- public static DataRow getRelationOrder(string buyer, string sampTid)
- {
- string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer + "' and seller_memo not like '%补差价%' and tid<>'" + sampTid + "' order by id desc";
- DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0];
- if (dt.Rows.Count > 0)
- {
- DataRow need = dt.Rows[0];
- if (dt.Rows.Count == 1)
- {
- return need;
- }
- int idx = 0;
- foreach (DataRow dr in dt.Rows)
- {
- if (idx != 0)
- {
- int day = Convert.ToDateTime(need["pay_time"]).Day;
- int nday = Convert.ToDateTime(dr["pay_time"]).Day;
- if (day == nday)
- {
- need = dr;
- }
- }
- idx++;
- }
- return need;
- }
- return null;
- }
- public static DataRow getUserInfoByAccount(string account)
- {
- string sql = "select * from view_erpuser where isOpen=1 and Account='" + account + "'";
- DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- return dt.Rows[0];
- }
- return null;
- }
- public static string getShopNameByECode(string code)
- {
- string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
- DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- return dt.Rows[0]["ShopName"].ToString();
- }
- return "";
- }
- // 时间戳转为C#格式时间
- public static DateTime StampToDateTime(string timeStamp)
- {
- DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- long lTime = long.Parse(timeStamp + "0000");
- TimeSpan toNow = new TimeSpan(lTime);
- return dateTimeStart.Add(toNow);
- }
- public static void Api_Tmc_CreateNewOrder(string res)
- {
- Api_trade_fullinfo_get_response_Obj fullObj = null;
- if (res == "") return;
- try
- {
- res = GetUTF8String(Encoding.UTF8.GetBytes(res));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_trade_fullinfo_get_response_Obj>(res);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- if (fullObj == null)
- {
- Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull");
- return;
- }
- ContentItem tObj = null;
- if (fullObj.response.data.content.Count > 0)
- {
- tObj = fullObj.response.data.content[0];
- }
- if (tObj == null)
- {
- return;
- }
- //未付款,未成功的单不需要
- if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID")
- {
- return;
- }
- List<Api_trade_fullinfo_get_response_Obj.LinesItem> orderList = tObj.lines;
- StringBuilder sql = new StringBuilder();
- CeErpTrade trade = CeErpTrade.Get(tObj.refOid);
- bool isCreate = false;
- if (trade == null)
- {
- trade = new CeErpTrade();
- isCreate = true;
- }
- //原始单创建
- trade.tid = tObj.refOid;
- if (tObj.posCode != null)
- trade.posCode = tObj.posCode;
- //trade.num = tObj.num;
- trade.status = tObj.status;
- trade.seller_flag = tObj.flag;
- trade.type = tObj.refType;
- trade.price = Convert.ToDouble(tObj.totalPrice);
- trade.discount_fee = Convert.ToDouble(tObj.discountFee);
- trade.total_fee = Convert.ToDouble(tObj.totalFee);
- trade.created = StampToDateTime(tObj.orderTime);
- if (tObj.payTime != null)
- {
- trade.pay_time = StampToDateTime(tObj.payTime);
- }
- if (tObj.modifyTime != null)
- {
- trade.modified = StampToDateTime(tObj.modifyTime);
- }
- if (tObj.finishTime != null)
- {
- trade.end_time = StampToDateTime(tObj.finishTime);
- }
- trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
- trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
- //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
- trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
- if (trade.seller_nick == "")
- {
- trade.seller_nick = getShopNameByECode(trade.posCode);
- }
- trade.payment = Convert.ToDouble(tObj.payment);
- //trade.receiver_name = tObj.receiver_name;
- trade.receiver_state = tObj.receiverState;
- trade.receiver_city = tObj.receiverCity;
- trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
- trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
- //trade.receiver_address = tObj.receiver_address;
- //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile);
- //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone);
- //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null)
- //{
- // trade.consign_time = tObj.consign_time;
- //}
- if (tObj.shippingTime != null)
- {
- trade.delivery_time = StampToDateTime(tObj.shippingTime);
- }
- //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo);
- trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo);
- trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo);
- if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
- {
- if (tObj.refType == "TMALL" || tObj.refType == "TB")
- {
- string[] acclist = tObj.sellerMemo.Split('-');
- List<string> list = new List<string>(acclist);
- string buyer_nick = "";
- if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
- {
- if (list.Count > 3)
- {
- buyer_nick = list[3];
- }
- }
- else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("寄样") != -1)
- {
- if (list.Count > 3)
- {
- buyer_nick = list[3];
- }
- }
- else if (trade.seller_memo.IndexOf("拿样订单") != -1)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
- {
- if (list.Count > 1)
- {
- buyer_nick = list[1];
- }
- }
- else
- {
- if (list.Count > 5)
- {
- buyer_nick = list[5];
- }
- }
- tObj.sellerMemo = string.Join("-", list);
- tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
- trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
- }
- }
- if (isCreate)
- {
- trade.Create();
- }
- else
- {
- trade.Update();
- }
- bool isXianhuo = false;
- string xianhuoMemo = "(" + trade.tid + ")现货-";
- //order表创建
- foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
- {
- bool orderCreate = false;
- CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
- if (order == null)
- {
- order = new CeErpTradeOrder();
- orderCreate = true;
- }
- order.tid = trade.tid;
- order.oid = item.refOlId;
- order.buyer_nick = trade.buyer_nick;
- order.refund_status = item.refundStatus;
- order.status = trade.status;
- order.title = item.title;
- order.price = Convert.ToDouble(item.price);
- if (item.picUrl != null)
- order.pic_path = item.picUrl;
- order.num = Convert.ToDouble(item.num.ToString());
- order.payment = Convert.ToDouble(item.price);
- if (item.refSpuId != null && item.refSpuId != "")
- {
- order.spu_id = item.refSpuId;
- }
- //order.adjust_fee = Convert.ToDouble(item.price);
- if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1) && item.standards.IndexOf("定制") == -1)
- {
- order.sku_properties_name = item.standards;
- order.sku_id = item.refSkuId;
- isXianhuo = true;
- xianhuoMemo += order.sku_properties_name;
- xianhuoMemo += ("-数量:" + order.num + "; ");
- }
- if (orderCreate)
- {
- order.Create();
- }
- else
- {
- order.Update();
- }
- }
- //if (isXianhuo)
- //{
- // xianhuoMemo += "-";
- // xianhuoMemo += trade.seller_nick;
- //}
- //cell表创建
- CeErpTradeCell entity = null;
- entity = CeErpTradeCell.GetByCtid(tObj.refOid);
- if (entity == null)
- {
- try
- {
- entity = new CeErpTradeCell();
- entity.ctid = tObj.refOid;
- entity.tid = tObj.refOid;
- entity.payment = Convert.ToDouble(tObj.payment);
- if (tObj.payTime != null)
- {
- entity.pay_time = StampToDateTime(tObj.payTime);
- }
- CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- if (isXianhuo)
- {
- entity.OrderState = 6;//现货直接下单完成
- entity.seller_memo = xianhuoMemo;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
- entity.IsXianHuo = 1;
- entity.FinishPlaceTime = entity.pay_time;
- if (xianhuoMemo.IndexOf("封酒贴") != -1)
- {
- entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
- if (trade.buyer_memo != "")
- {
- entity.OrderState = 2; //买家有备注的要设计
- entity.ProductId = 1;
- entity.IsXianHuo = 0;
- xianhuoMemo = xianhuoMemo.Replace("现货", "");
- xianhuoMemo = xianhuoMemo.Replace(" ", "");
- entity.seller_memo = xianhuoMemo;
- }
- }
- else if (xianhuoMemo.IndexOf("喜字贴") != -1)
- {
- entity.SupplierId = 70; //智涛
- }
- //if (trade != null)
- //{
- // trade.seller_memo = xianhuoMemo;
- // trade.Update();
- //}
- }
- entity.Create();
- commonHelper.setSpuData(trade);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- }
- if (tObj.sellerMemo.Length > 0)
- {
- try
- {
- createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|" + ex.Message);
- }
- }
- ////生成档案客户信息
- //insertCustomerInfo(tObj);
- }
- public static int isOldCustomerOrder(CeErpTrade father)
- {
- if (father.seller_nick == "") return 0;
- CeErpCustomer cusone = null;
- cusone = CeErpCustomer.GetByNick(father.buyer_nick);
- if (cusone != null)
- {
- return 1;
- }
- return 0;
- }
- public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
- {
- if (father.seller_nick == "") return 0;
- CeErpCustomer cus = null;
- cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
- if (cus == null)
- {
- cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
- }
- int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
- //CeErpCustomer cusone = null;
- //cusone = CeErpCustomer.GetByNick(father.buyer_nick);
- if (cus != null)
- {
- if (cus.lastbuy_time.ToString() == "") return 0;
- if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
- //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
- //cus.phone = Obj.receiver_mobile;
- cus.buyer_id = father.buyer_id;
- int returnNum = 0;
- int lastpCount = cus.product_count;
- if (cus.lastTid == father.tid)
- {
- if (pcount != cus.product_count)
- {
- cus.product_count = pcount;
- cus.Update();
- }
- }
- else
- {
- TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
- cus.buyer_nick = father.buyer_nick;
- cus.buy_day = Convert.ToInt32(tsday.TotalDays);
- cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
- cus.buy_count = cus.buy_count + 1;
- cus.lastbuy_time2 = cus.lastbuy_time;
- cus.lastbuy_time = father.pay_time;
- cus.product_count = pcount;
- cus.lastTid2 = cus.lastTid;
- cus.lastTid = father.tid;
- cus.Update();
- }
- if (cus.buy_day > 1)
- {
- if (pcount > lastpCount && cus.product_count != 0)
- {
- cus.isMore = 1;
- returnNum = 2;
- }
- else
- returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
- }
- else
- {
- returnNum = 0;
- }
- return returnNum;
- }
- //else if (cusone != null)
- //{
- // cusone.seller_nick = father.seller_nick;
- // TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
- // cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
- // cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
- // cusone.buy_count = cusone.buy_count + 1;
- // cusone.lastbuy_time2 = cusone.lastbuy_time;
- // cusone.lastbuy_time = father.pay_time;
- // cusone.product_count = pcount;
- // cusone.lastTid2 = cusone.lastTid;
- // cusone.lastTid = father.tid;
- // cusone.Update();
- // return 1;
- //}
- else
- {
- try
- {
- cus = new CeErpCustomer();
- cus.buyer_nick = father.buyer_nick;
- cus.seller_nick = father.seller_nick;
- cus.buyer_id = father.buyer_id;
- //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
- //cus.phone = Obj.receiver_mobile;
- cus.buy_day = 0;
- cus.buy_count = 1;
- cus.lastbuy_time = father.pay_time;
- cus.lastTid = father.tid;
- cus.total_fee = Convert.ToDouble(father.payment);
- cus.product_count = pcount;
- cus.Create();
- //StringBuilder sql = new StringBuilder();
- //sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
- //DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
- //if (dt.Rows.Count > 0)
- //{
- // return true;
- //}
- return 0;
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
- }
- }
- return 0;
- }
- public static void removeOldCustomerInfo(CeErpTrade trade)
- {
- CeErpCustomer cus = null;
- cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
- if (cus != null)
- {
- if (cus.lastTid == trade.tid)
- {
- if (cus.buy_count > 1)
- {
- cus.lastTid = cus.lastTid2;
- cus.lastbuy_time = cus.lastbuy_time2;
- cus.buy_count = cus.buy_count - 1;
- cus.Update();
- }
- else
- {
- CeErpCustomer.Del(cus.ID);
- }
- }
- }
- }
- //接收到--新订单生成消息
- public static void API_Tmc_TradeBuyerPay(string content)
- {
- Api_tmc_trade_info_Obj fullObj = null;
- if (content == "") return;
- try
- {
- content = GetUTF8String(Encoding.UTF8.GetBytes(content));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
- }
- catch (Exception ex)
- {
- }
- if (fullObj == null)
- {
- Console.WriteLine("Api_tmc_trade_info_Obj isNull");
- return;
- }
- Content tObj = fullObj.content;
- string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test();
- Api_Tmc_CreateNewOrder(res);
- }
- //推送接收到卖家备注修改
- public static void API_Tmc_TradeMemoModified(string content)
- {
- Api_tmc_trade_info_Obj fullObj = null;
- if (content == "") return;
- try
- {
- content = GetUTF8String(Encoding.UTF8.GetBytes(content));
- //res = res.Replace(" ", "");
- fullObj = JsonConvert.DeserializeObject<Api_tmc_trade_info_Obj>(content);
- }
- catch (Exception ex)
- {
- }
- if (fullObj == null)
- {
- Console.WriteLine("Api_tmc_trade_info_Obj isNull");
- return;
- }
- Content tObj = fullObj.content;
- //原始表--没有这个单,不能拆分
- CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid);
- if (mainEn == null) return;
- createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo);
- }
- public static int orderAudit(int shopId)
- {
- try
- {
- CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
- if (ceErpShop == null) return 2;
- if (!ceErpShop.orderAudit) return 2;
- return -1;
- }
- catch (Exception ex)
- {
- return 2;
- }
- }
- public static void autoCell(string tid)
- {
- if (tid.Length == 0)
- {
- return;
- }
- DateTime nowTime = DateTime.Now;
- if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
- {
- return;
- }
- try
- {
- 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);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- bool changeBl = false;
- //int c = Convert.ToInt32(result);// / 20 + 1;
- foreach (DataRow dr in dt.Rows)
- {
- if (nowTime.Hour > 12 && nowTime.Hour < 17)
- {
- //这段时间白班晚班平均分配
- if (changeBl)
- {
- changeBl = false;
- }
- else
- {
- changeBl = true;
- }
- }
- else
- changeBl = false;
- string IsOldCustomer = dr["IsOldCustomer"].ToString();
- string res = "";
- CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
- int userId = 0;
- if (ceErpShop != null)
- {
- userId = ceErpShop.UserID;
- }
- SqlParameter[] sqlParameter = {
- new SqlParameter("@inctid", SqlDbType.VarChar,200),
- new SqlParameter("@intype", SqlDbType.Int,5),
- new SqlParameter("@res", SqlDbType.VarChar, 50) };
- sqlParameter[0].Value = dr["ctid"].ToString();
- sqlParameter[1].Value = changeBl ? 1 : 0;
- sqlParameter[2].Direction = ParameterDirection.Output;
- if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
- {
- DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
- }
- else
- {
- DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
- }
- res = sqlParameter[2].Value.ToString();
- }
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
- }
- }
- }
- }
|