| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507 |
- 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"
- };
- 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.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.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;
- //}
- 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.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;
- }
- }
- //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);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|cell创建" + ex.Message);
- }
- }
- 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);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, res + "|2|" + ex.Message);
- }
- }
- }
- 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;
- }
- 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 (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;
- }
- 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.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;
- father.create_time = DateTime.Now;
- father.Update();
- entity.Create();
- CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
- }
- else
- {
- entity.IsSample = 1;
- 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;
- }
- 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 + "';";
- CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
- 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)
- {
- string sql_pay = "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
- CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
- LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
- string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
- CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
- }
- }
- string orderSql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeOrder] WHERE tid = '{0}' and total_fee > 0", father.tid);
- DataTable table = SqlHelper.ExecuteDataSet(orderSql).Tables[0];
- if (table != null && table.Rows.Count == 1)
- {
- string cellSql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid = '{0}'", father.tid);
- DataTable data = SqlHelper.ExecuteDataSet(cellSql).Tables[0];
- if (data != null && data.Rows.Count > 0)
- {
- foreach (DataRow row in data.Rows)
- {
- CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(row["ctid"].ToString());
- if (ceErpTradeCellExtend == null)
- {
- ceErpTradeCellExtend = new CeErpTradeCellExtend();
- ceErpTradeCellExtend.ctid = row["ctid"].ToString();
- }
- ceErpTradeCellExtend.spu_id = table.Rows[0]["spu_id"].ToString();
- if (ceErpTradeCellExtend.ID == 0)
- {
- ceErpTradeCellExtend.Create();
- }
- else
- {
- ceErpTradeCellExtend.Update();
- }
- }
- }
- }
- //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.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 (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 (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.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 (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;
- //唯一标识
- entity.OrderSn = ctid;
- /*string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }*/
- 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 (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;
- //唯一标识
- entity.OrderSn = ctid;
- /* string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }*/
- 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 += father.tid;
- 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 (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;
- //唯一标识
- entity.OrderSn = ctid;
- /* string orderSn = dataHelper.getSaleOrderSn();
- if (orderSn != "")
- {
- entity.OrderSn = orderSn;
- }*/
- 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 (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);
- //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();
- }
- 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);
- }
- }
- }
- }
|