| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559 |
- 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.交易关闭);
- //}
- }
- static List<string> postcodes = new List<string>()
- {
- "yujia","taolai","zhufan","dingyi","lingtao","yangguangmao","xinkeli","yuejia","maiyu","xiyinshuo","SP","zhuosheng","aolifu","GQ"
- };
- 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" || postcodes.IndexOf(tObj.posCode) > -1)
- {
- 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)
- {
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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)
- {
- entity.OrderState = -1;
- }
- 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);
- }
- }
- }
- }
|