sync.order.cs 718 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230
  1. using BizCom;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using NHibernate.Linq;
  5. using NHibernate.Mapping;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.OpenXmlFormats.Shared;
  8. using NPOI.SS.Formula.Eval;
  9. using NPOI.SS.Formula.Functions;
  10. using NPOI.SS.Formula.Udf;
  11. using SiteCore.Redis;
  12. using SiteCore.taobao;
  13. using SiteCore.taoObj;
  14. using SQLData;
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Generic;
  18. using System.ComponentModel.Design;
  19. using System.Data;
  20. using System.Data.SqlClient;
  21. using System.Data.SqlTypes;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.Drawing.Drawing2D;
  25. using System.IO;
  26. using System.Linq;
  27. using System.Net;
  28. using System.Net.Security;
  29. using System.Reflection.Emit;
  30. using System.Security.Cryptography;
  31. using System.Security.Cryptography.X509Certificates;
  32. using System.Security.Policy;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using System.Web.UI;
  37. using System.Web;
  38. using System.Web.UI.WebControls;
  39. using Utils;
  40. using Utils.Serialization;
  41. using static NHibernate.Linq.Visitors.LeftJoinDetector;
  42. using static SiteCore.taoObj.Api_trade_info;
  43. using static SiteCore.taoObj.Api_waybill_code_response_Obj;
  44. using static SiteCore.taoObj.work_core_vo;
  45. using static System.Net.Mime.MediaTypeNames;
  46. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  47. using NPOI.Util;
  48. using static NPOI.HSSF.Util.HSSFColor;
  49. using BizCom.Enum;
  50. using NPOI.POIFS.Properties;
  51. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  52. using static SiteCore.taoObj.Api_tmc_refund_info_Obj;
  53. using System.Threading.Tasks;
  54. using SiteCore.taoObj.WebApi;
  55. namespace SiteCore.Handler
  56. {
  57. public partial class sync
  58. {
  59. public void get_erp_orderlist()
  60. {
  61. string poscode = CurrentUser.UserPost.Post.Code;
  62. DataStruct dStruct = GetPostStruct();
  63. //commonHelper.setDeliveryUnusualOrder2();
  64. //string a = SecurityHelper.DecryptSymmetric("kncY+n90QZs=");
  65. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  66. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  67. //banniuApiHelper.sendLogisticsInfo(null);
  68. //commonHelper.autoDistributeToSupplier(CeErpTradeCell.GetByCode("260112211259328680"));
  69. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  70. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2811249339088067154");
  71. //int sid = commonHelper.autoDistributeToSupplier(entity);
  72. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  73. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1769473929000,\"deliveryType\":\"OFFLINE\",\"discountFee\":88.8,\"flag\":\"NONE\",\"latestDeliveryTime\":1769646723000,\"lines\":[{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":71.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i1/2209098428402/O1CN014lFiOR2BwAlLj73pn_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323534103881\",\"refSkuId\":\"5676891964027\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-好运120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":71.2,\"totalPrice\":81.0,\"totalSellPrice\":71.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":43.8,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN018Wkqi22BwAlJzJCsN_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":49.8,\"refOlId\":\"32103763323544103881\",\"refSkuId\":\"5676891964037\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":43.8,\"singleFee\":43.8,\"spuOuterId\":\"QZB_1\",\"standards\":\"款式四-【五条装】-条幅-缝筒-送绳子\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":43.8,\"totalPrice\":49.8,\"totalSellPrice\":43.8},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":43.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/2209098428402/O1CN01RnBV0A2BwAlKIJfa7_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":24.6,\"refOlId\":\"32103763323554103881\",\"refSkuId\":\"5676891964016\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":21.6,\"singleFee\":21.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-福到160x80cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":43.2,\"totalPrice\":49.2,\"totalSellPrice\":43.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2209098428402/O1CN01nxyqK62BwAlGPAQSL_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323564103881\",\"refSkuId\":\"5681379297700\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-万事顺120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":43.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2209098428402/O1CN01D2zZO22BwAlMiuBcu_!!2209098428402.png\",\"platServiceFee\":0.0,\"price\":24.6,\"refOlId\":\"32103763323574103881\",\"refSkuId\":\"5681379297697\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":21.6,\"singleFee\":21.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-福来160x80cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":43.2,\"totalPrice\":49.2,\"totalSellPrice\":43.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":71.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN01odXukd2BwAlMiF0Li_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323584103881\",\"refSkuId\":\"5676891964031\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-发财120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":71.2,\"totalPrice\":81.0,\"totalSellPrice\":71.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN01f4HKJm2BwAlKyCeeJ_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323594103881\",\"refSkuId\":\"5676891964017\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-福到120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2209098428402/O1CN01ycsFfI2BwAlKdCqcx_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323604103881\",\"refSkuId\":\"5676891964019\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-钱来120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN01jC9Fda2BwAlLfWEmv_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323614103881\",\"refSkuId\":\"5676891964021\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-喜乐120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":43.8,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i2/2209098428402/O1CN01IiOKnv2BwAlJz5e9z_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":49.8,\"refOlId\":\"32103763323624103881\",\"refSkuId\":\"5676891964036\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":43.8,\"singleFee\":43.8,\"spuOuterId\":\"QZB_1\",\"standards\":\"款式三【五条装】-条幅-缝筒-送绳子\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":43.8,\"totalPrice\":49.8,\"totalSellPrice\":43.8},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":43.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN01DNwVBD2BwAlPrsRI5_!!2209098428402.png\",\"platServiceFee\":0.0,\"price\":24.6,\"refOlId\":\"32103763323634103881\",\"refSkuId\":\"5681379297699\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":21.6,\"singleFee\":21.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-万事顺160x80cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":43.2,\"totalPrice\":49.2,\"totalSellPrice\":43.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":2,\"outerId\":\"QZB_1\",\"payment\":71.2,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/2209098428402/O1CN01S0IogQ2BwAlN8vq4B_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323644103881\",\"refSkuId\":\"5681379297698\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-福来120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":71.2,\"totalPrice\":81.0,\"totalSellPrice\":71.2},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i1/2209098428402/O1CN01HXQ0VP2BwAlKdHwvM_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323654103881\",\"refSkuId\":\"5676891964025\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-如意120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6},{\"dividePostFee\":0.0,\"latestDeliveryTime\":1769646723000,\"mark2\":[],\"num\":1,\"outerId\":\"QZB_1\",\"payment\":35.6,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2209098428402/O1CN01DP994m2BwAlJYJGxF_!!2209098428402.jpg\",\"platServiceFee\":0.0,\"price\":40.5,\"refOlId\":\"32103763323664103881\",\"refSkuId\":\"5676891964033\",\"refSpuId\":\"860739190401\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":35.6,\"singleFee\":35.6,\"spuOuterId\":\"QZB_1\",\"standards\":\"现货-暴富120x240cm-条幅-四角打孔-送挂钩\",\"status\":\"NOT_SHIPPED\",\"title\":\"新年装饰挂布定制2025蛇年氛围感背景布元旦网红拍照书法旗帜布置\",\"totalFee\":35.6,\"totalPrice\":40.5,\"totalSellPrice\":35.6}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1769474375000,\"openBuyerId\":\"AAG0RHraABkUZRPgSx3LCGSA\",\"openBuyerNick\":\"f**\",\"openSellerNick\":\"鼎怡旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1769473877000,\"payTime\":1769473923000,\"payment\":644.4,\"platServiceFee\":0.0,\"posCode\":\"dingyi\",\"posId\":598810,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"上海市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"黄浦区\",\"receiverId\":\"64eedcf615544863ccce8b2194d7cb4c$\",\"receiverState\":\"上海\",\"receiverTown\":\"淮海中路街道\",\"refOid\":\"32103763323524103881\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"sysTags\":[],\"totalFee\":644.4,\"totalPrice\":733.2,\"totalSellPrice\":644.4,\"type\":\"SALE\"}}");
  74. //refundTmcHelper.Api_TmcRefundMsg("{\"content\":{\"afterStatus\":\"SUCCESS\",\"createTime\":1735287446000,\"desc\":\"\",\"interceptInvestor\":\"NONE\",\"interceptStatus\":\"NONE\",\"interceptType\":\"NONE\",\"lines\":[{\"num\":2,\"outerId\":\"\",\"price\":50.0,\"refAid\":\"313001208133750610\",\"refAlId\":\"313001208133750610\",\"refBoughtSkuId\":\"\",\"refOid\":\"4181722704291751006\",\"refOlId\":\"4181722704291751006\",\"refSkuId\":\"0\",\"refSpuId\":\"865893808768\",\"refundFee\":98.86,\"refundStatus\":\"SUCCESS\",\"title\":\"新年会抽奖券定制2025蛇年公司活动正副可撕代金券打印纪念票根奖品兑换尾牙晚宴邀请卡号码牌创意入场券设计\",\"totalFee\":98.86,\"type\":1}],\"logisticsCompany\":\"\",\"logisticsOrderNo\":\"\",\"mark2\":[],\"openBuyerNick\":\"0**\",\"openSellerNick\":\"万慕办公旗舰店\",\"posCode\":\"wanmu\",\"posId\":598798,\"reason\":\"订单信息拍错(规格/尺码/颜色等)\",\"receiverCity\":\"\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"\",\"receiverId\":\"\",\"receiverState\":\"\",\"receiverTown\":\"\",\"receiverZip\":\"\",\"refAid\":\"313001208133750610\",\"refOid\":\"4181722704291751006\",\"refPlatform\":\"TB\",\"refType\":\"TMALL\",\"refundCreateTime\":1735287358000,\"refundFee\":\"98.86\",\"refundPhase\":\"ON_SALE\",\"refundTime\":1735289443000,\"refundUpdateTime\":1735289443000,\"refundVersion\":1735287358100,\"senderAddress\":\"\",\"senderCity\":\"\",\"senderCountry\":\"中国\",\"senderDistrict\":\"\",\"senderMobile\":\"\",\"senderName\":\"\",\"senderPhone\":\"\",\"senderState\":\"\",\"senderTown\":\"\",\"senderZip\":\"\",\"status\":\"SUCCESS\",\"statusCode\":\"SUCCESS\",\"statusName\":\"退款成功\",\"totalFee\":\"98.86\",\"type\":\"REFUND\",\"updateTime\":1735289479000}}");
  75. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  76. //string res = apiHelper.API_GetWaybill("YTO-PDD-CYT", "250703-469248284251412");
  77. //preSalesHelper.dealMessageInfo("{\"bizOrder\":{\"id\":235819,\"parentId\":null,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderNo\":\"4624034580248409502\",\"shopId\":4,\"shopCode\":\"aolifu\",\"customerId\":345874,\"customerServiceId\":3184,\"thirdOrderId\":\"4624034580248409502\",\"orderPlatform\":\"TMALL\",\"openBuyerId\":\"AAEORHraABkUZRHgSx6ksuhU\",\"openBuyerNick\":\"tb278604202340\",\"openSellerNick\":\"奥丽芙旗舰店\",\"productUrl\":null,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"payAmount\":125.0,\"unrefundedAmount\":125.0,\"discountAmount\":5.0,\"csDiscountAmount\":-35.0,\"num\":13,\"province\":\"山西省\",\"city\":\"吕梁市\",\"area\":\"孝义市\",\"receiverTown\":\"孝义市\",\"address\":null,\"thirdReceiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"receiverName\":null,\"receiverMobile\":null,\"weChatId\":null,\"phone\":null,\"designContent\":\"\",\"designPics\":\"[]\",\"weChatQrPics\":\"[]\",\"addressFileUrl\":\"\",\"thirdFlag\":\"NONE\",\"remark\":null,\"sellerRemark\":\"\",\"buyerRemark\":\"\",\"timeoutRemark\":null,\"discountRemark\":null,\"status\":\"NOT_SHIPPED\",\"refundStatus\":0,\"internalStatus\":2,\"auditStatus\":null,\"auditUserId\":null,\"auditor\":null,\"customTag\":null,\"isRepurchase\":false,\"isOffline\":false,\"paymentFile\":null,\"orderTime\":\"2025-07-10 14:46:13\",\"modifyTime\":\"2025-07-10 14:46:37\",\"payTime\":\"2025-07-10 14:46:37\",\"confirmTime\":\"2025-07-10 14:51:23\",\"auditTime\":null,\"shippingTime\":null,\"finishTime\":null,\"erpCustomerServiceId\":3319,\"openBuyerID\":\"AAEORHraABkUZRHgSx6ksuhU\",\"orderFrom\":\"10\",\"receiverId\":\"4679677a0c7af72f1e8d0e672d57c575$\",\"bizOrderItems\":[{\"id\":310334,\"orderId\":235819,\"thirdOrderItemId\":\"4624034580248409502\",\"thirdSpuId\":\"740203900330\",\"thirdSkuId\":\"0\",\"title\":\"pvc贴纸定制防水不干胶圆形贴标自粘商标logo广告二维码标签印刷\",\"specification\":\"\",\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i3/2433960672/O1CN01D0ZzzR1GppCHSoBjD_!!4611686018427382496-0-item_pic.jpg\",\"price\":10.0,\"sellPrice\":9.62,\"amount\":9.62,\"totalPrice\":130.0,\"totalSellPrice\":125.0,\"totalAmount\":125.0,\"num\":13,\"refundStatus\":\"NO_REFUND\"}],\"bizOrderSplits\":[{\"id\":151557,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328848\",\"splitNo\":\"C1_4624034580248409502\",\"splitInfoNo\":\"C2+1\",\"splitAmount\":52.64,\"quoteRecordId\":520208,\"quoteAmount\":40.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328848)-[C2+1]-80x20mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328848\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":40.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":80.00,\"width\":20.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"80x20mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":40.00,\"numberType\":\"\",\"isDianziOrder\":0},{\"id\":151558,\"orderSource\":\"10\",\"orderType\":\"10\",\"orderId\":235819,\"bizOrderNo\":\"4624034580248409502\",\"spuId\":\"740203900330\",\"customerId\":345874,\"designerId\":null,\"uniqueNo\":\"250710145121328853\",\"splitNo\":\"C2_4624034580248409502\",\"splitInfoNo\":\"C2+2\",\"splitAmount\":72.36,\"quoteRecordId\":520209,\"quoteAmount\":55.0,\"parentSplitNo\":null,\"compensateAmount\":0,\"internalStatus\":2,\"designStatus\":null,\"errorStatus\":0,\"errorReason\":null,\"backTime\":null,\"syncErpFlag\":0,\"syncErpMsg\":null,\"designTimeoutType\":null,\"isToDesignSys\":false,\"isSpot\":false,\"isRepurchase\":false,\"isGift\":0,\"isUrgent\":false,\"isCombinedShipping\":false,\"designEstimateTime\":null,\"designFinishTime\":null,\"shippingTime\":null,\"finalDraftTime\":null,\"sampleMark\":0,\"sfMark\":0,\"wechatMark\":0,\"sendGiftMark\":0,\"addWechatMark\":0,\"otherMark\":null,\"systemRemark\":\"(250710145121328853)-[C2+2]-90x50mm-200张-铜版纸不干胶覆亮膜模切\",\"otherRemark\":\"-老客户改稿 之前下单号:13935850820ma\",\"followOrderRemark\":null,\"timeoutRemark\":null,\"workshopNote\":\"\",\"isPreShipping\":0,\"workOrderFiles\":null,\"checkOrderTime\":null,\"refundStatus\":0,\"refundAmount\":0.0,\"afterSaleStatus\":0,\"afterSaleReason\":null,\"afterSalePayAmount\":null,\"afterSalePics\":null,\"afterSaleBackPics\":null,\"afterSaleBackReason\":null,\"afterSaleMethod\":null,\"afterSaleRemark\":null,\"afterSaleTime\":null,\"afterSaleFinishTime\":null,\"erpCustomerServiceId\":3319,\"OrderSn\":\"250710145121328853\",\"orderFrom\":\"10\",\"ptid\":\"4624034580248409502\",\"offerAmount\":55.0,\"paymentFile\":null,\"cate1Id\":\"770260a9d3ee11efba6a00163e010e55\",\"cate1\":\"不干胶\",\"cate2Id\":\"77026444d3ee11efba6a00163e010e55\",\"cate2\":\"平张不干胶\",\"cate3Id\":\"7702655dd3ee11efba6a00163e010e55\",\"productCategory\":\"铜版纸不干胶\",\"sceneId\":0,\"scene\":\"合版印刷\",\"materialId\":15,\"material\":\"铜版纸不干胶\",\"craft\":\"[{\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 11, \\\"productCraftName\\\": \\\"覆亮膜\\\"}, {\\\"isAfterCraft\\\": false, \\\"productCraftId\\\": 163, \\\"productCraftName\\\": \\\"模切\\\"}]\",\"numbers\":1,\"opSceneId\":\"\",\"opScene\":\"\",\"length\":90.00,\"width\":50.00,\"height\":0,\"recSize\":\"\",\"sizeUnit\":\"mm\",\"size\":\"90x50mm\",\"numberUnit\":\"张\",\"quantity\":200,\"productQuantity\":\"200张\",\"discountAmount\":55.00,\"numberType\":\"\",\"isDianziOrder\":0}]}}");
  78. /*string path = "C:\\Users\\231010\\Downloads\\tids.txt";
  79. string path1 = "C:\\Users\\231010\\Downloads\\tid.txt";
  80. string tids = File.ReadAllText(path);
  81. List<string> list = tids.Split(',').ToList();
  82. int index = 0;
  83. foreach (string item in list)
  84. {
  85. CeErpTrade ceErpTrade = CeErpTrade.Get(item.Replace("'", ""));
  86. try
  87. {
  88. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_nick = '{0}' or buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  89. if (string.IsNullOrEmpty(ceErpTrade.buyer_nick))
  90. {
  91. sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WITH(NOLOCK) WHERE (buyer_id = '{1}' ) and status = 'COMPLETE' and seller_nick = '{2}' and tid <> '{3}' AND end_time < '{4}' and payment >= 20", ceErpTrade.buyer_nick, ceErpTrade.buyer_id, ceErpTrade.seller_nick, ceErpTrade.tid, ceErpTrade.pay_time);
  92. }
  93. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  94. List<string> tidList = new List<string>();
  95. if (dataTable != null && dataTable.Rows.Count > 0)
  96. {
  97. foreach (DataRow row in dataTable.Rows)
  98. {
  99. tidList.Add("'" + row["tid"].ToString() + "'");
  100. }
  101. }
  102. if (tidList.Count > 0)
  103. {
  104. sql = string.Format("SELECT count(*) as number FROM [dbo].[CE_ErpTradeCell] WITH(NOLOCK) WHERE tid in ({0}) AND IsSample = 0 ", string.Join(",", tidList));
  105. dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  106. if (dataTable != null && dataTable.Rows.Count > 0)
  107. {
  108. int count = Convert.ToInt32(dataTable.Rows[0]["number"]);
  109. if (count > 0)
  110. {
  111. Debug.WriteLine(index++);
  112. continue;
  113. }
  114. }
  115. }
  116. File.AppendAllText(path1, ceErpTrade.tid + "\n");
  117. }
  118. catch (Exception e)
  119. {
  120. File.AppendAllText(path1, "e:" + ceErpTrade.tid + "\n");
  121. }
  122. Debug.WriteLine(index++);
  123. }*/
  124. //string a = commonHelper.convertQNMemo("48x61mm-4款各40个-铜版纸-不干胶-覆膜模切-tb963561715-金陵-顺丰到付.粘成品.6.5cm牙签-老客户改稿找金陵拉群-16发", CeErpTradeCell.GetByCtid("2879265072537265386"));
  125. List<string> lw = new List<string>();
  126. string tid = GetPostString("ctid");
  127. string date1 = GetPostString("date1");
  128. //12-1 修改
  129. string urgent = GetPostString("urgent");
  130. string back = GetPostString("back");
  131. string offlineSearch = GetPostString("offlineSearch");
  132. int paramsCount = 0;
  133. if (!string.IsNullOrWhiteSpace(urgent))
  134. {
  135. if (urgent.Equals("true"))
  136. {
  137. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  138. }
  139. }
  140. if (!string.IsNullOrWhiteSpace(back))
  141. {
  142. if (back.Equals("true"))
  143. {
  144. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  145. }
  146. }
  147. if (!string.IsNullOrWhiteSpace(offlineSearch))
  148. {
  149. if (offlineSearch.Equals("true"))
  150. {
  151. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  152. }
  153. }
  154. //end
  155. string date2 = GetPostString("date2");
  156. string buyernick = GetPostString("buyer_nick");
  157. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  158. {
  159. if (tid.Length <= 0 && buyernick.Length <= 0)
  160. {
  161. return;
  162. }
  163. }
  164. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  165. {
  166. if (tid.Length > 0)
  167. {
  168. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  169. if (ceErpTradeCell != null)
  170. {
  171. tid = ceErpTradeCell.tid;
  172. }
  173. List<string> select_tid = getTidByCtidMore(tid);
  174. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  175. }
  176. if (buyernick.Length > 0)
  177. {
  178. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  179. }
  180. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  181. if (dw.Length > 0)
  182. {
  183. lw.Add(dw);
  184. }
  185. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  186. {
  187. string usershop = "0," + CurrentUser.User.pemShop;
  188. lw.Add(string.Format("ShopId in ({0})", usershop));
  189. }
  190. }
  191. else
  192. {
  193. if (ex_psize == 0)
  194. {
  195. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  196. }
  197. if (PKey != "admin" && poscode != "SysAdmin")
  198. {
  199. string usershop = "0," + CurrentUser.User.pemShop;
  200. lw.Add(string.Format("ShopId in ({0})", usershop));
  201. paramsCount++;
  202. }
  203. }
  204. string uploaddate1 = GetPostString("uploaddate1");
  205. string uploaddate2 = GetPostString("uploaddate2");
  206. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  207. if (update.Length > 0) lw.Add(update);
  208. string deliverydate1 = GetPostString("deliverydate1");
  209. string deliverydate2 = GetPostString("deliverydate2");
  210. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  211. if (deliverydate.Length > 0)
  212. {
  213. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  214. };
  215. string shopname = GetPostString("shopname");
  216. if (shopname.Length > 0)
  217. {
  218. CeErpShop ceErpShop = CeErpShop.GetShopIdByName(shopname);
  219. if (ceErpShop != null)
  220. {
  221. lw.Add(string.Format("shopId = {0}", ceErpShop.ID));
  222. }
  223. }
  224. string addwechat = GetPostString("addwechat");
  225. if (addwechat.Length > 0)
  226. {
  227. int addWt = Convert.ToInt32(addwechat);
  228. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  229. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  230. }
  231. string customer = GetPostString("customer");
  232. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  233. string design = GetPostString("design");
  234. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  235. string orderState = GetPostString("orderState");
  236. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  237. string address = GetPostString("address");
  238. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  239. string sellermemo = GetPostString("seller_memo");
  240. if (sellermemo.Length > 0)
  241. {
  242. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  243. }
  244. string otherMemo = GetPostString("otherMemo");
  245. if (otherMemo.Length > 0)
  246. {
  247. lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  248. }
  249. string backReason = GetPostString("backReason");
  250. if (backReason.Length > 0)
  251. {
  252. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  253. }
  254. string apdate1 = GetPostString("apdate1");
  255. string apdate2 = GetPostString("apdate2");
  256. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  257. if (dwap.Length > 0) lw.Add(dwap);
  258. string price1 = GetPostString("price1");
  259. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  260. string price2 = GetPostString("price2");
  261. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  262. string isoldcustomer = GetPostString("isoldcus");
  263. string buyer_id = GetPostString("buyer_id");
  264. if (buyer_id.Length > 0) lw.Add(string.Format("buyer_id = '{0}'", buyer_id));
  265. string spudata = GetPostString("spudata");
  266. if ("0".Equals(spudata))
  267. {
  268. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  269. }
  270. if ("1".Equals(spudata))
  271. {
  272. lw.Add(string.Format("spu_id <> ''"));
  273. }
  274. string finishdate1 = GetPostString("finishdate1");
  275. string finishdate2 = GetPostString("finishdate2");
  276. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  277. bool isFinish = false;
  278. if (finishdate.Length > 0)
  279. {
  280. lw.Add(finishdate);
  281. isFinish = true;
  282. paramsCount++;
  283. }
  284. if (isoldcustomer.Length > 0)
  285. {
  286. if ("2".Equals(isoldcustomer))
  287. {
  288. lw.Add(string.Format("VipCustomer=1"));
  289. }
  290. else
  291. {
  292. lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  293. }
  294. }
  295. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  296. if (ex_psize > 0)
  297. {
  298. int UserID = CurrentUser.UserID;
  299. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  300. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  301. {
  302. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  303. }
  304. dStruct.Order = "pay_time desc";
  305. }
  306. string isNew = GetPostString("isNew");
  307. if (isNew == "true")
  308. {
  309. lw.Add(string.Format("IsNew = {0}", 1));
  310. }
  311. string overtime = GetPostString("overtime");
  312. if (overtime == "1")
  313. {
  314. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  315. }
  316. String usePost = CurrentUser.UserPost.Post.Code;
  317. if (usePost.Equals("Operation") == true)
  318. {
  319. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  320. }
  321. else
  322. {
  323. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  324. }
  325. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  326. if (dStruct.PageSize == 100000)
  327. {
  328. dStruct.Order = "";
  329. }
  330. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  331. DataTable dt = null;
  332. string tablename = "view_orderlist";
  333. if (isFinish)
  334. {
  335. tablename = "view_orderlist_end";
  336. }
  337. dt = WebCache.GetData(tablename, dStruct);
  338. if (dt != null && dt.Rows.Count > 0)
  339. {
  340. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  341. foreach (DataRow dr in dt.Rows)
  342. {
  343. try
  344. {
  345. if (dr["refund_fees"] != null)
  346. {
  347. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  348. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  349. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  350. if (payment == refund_fees)
  351. {
  352. dr["refund_fees"] = Math.Round(refund_fees, 2);
  353. }
  354. else if (refund_fees == total_fee)
  355. {
  356. dr["refund_fees"] = payment;
  357. }
  358. else
  359. {
  360. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  361. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  362. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  363. }
  364. }
  365. // 对象操作
  366. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  367. ceErpTradeCell.ctid = dr["ctid"].ToString();
  368. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  369. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  370. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  371. if (dStruct.PageSize != 100000)
  372. {
  373. if (dr["DispatchSort"].ToString() == "2")
  374. {
  375. dr["gongchuang"] = 200;
  376. }
  377. else if ("外协".Equals(dr["ToType"].ToString()))
  378. {
  379. dr["gongchuang"] = 200;
  380. }
  381. else if ("内部".Equals(dr["ToType"].ToString()))
  382. {
  383. dr["gongchuang"] = -1;
  384. }
  385. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  386. {
  387. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  388. dr["gongchuang"] = response.code;
  389. }
  390. }
  391. }
  392. catch (NullReferenceException ex)
  393. {
  394. // 处理空引用异常
  395. dr["refund_fees"] = "0.00";
  396. }
  397. }
  398. }
  399. writeGridDataTableJson(dStruct.TotalCount, dt);
  400. }
  401. public void get_erp_orderlist_sumprice()
  402. {
  403. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  404. return;
  405. List<string> lw = new List<string>();
  406. string tid = GetPostString("ctid");
  407. string date1 = GetPostString("date1");
  408. string date2 = GetPostString("date2");
  409. if (tid.Length > 0 || date1.Length > 0)
  410. {
  411. lw.Add(string.Format("ctid like '%{0}%'", tid));
  412. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  413. if (dw.Length > 0) lw.Add(dw);
  414. }
  415. else
  416. {
  417. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  418. }
  419. string shopname = GetPostString("shopname");
  420. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  421. string buyernick = GetPostString("buyer_nick");
  422. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  423. string customer = GetPostString("customer");
  424. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  425. string design = GetPostString("design");
  426. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  427. string orderState = GetPostString("orderState");
  428. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  429. string address = GetPostString("address");
  430. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  431. string sellermemo = GetPostString("seller_memo");
  432. if (sellermemo.Length > 0)
  433. {
  434. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  435. }
  436. string apdate1 = GetPostString("apdate1");
  437. string apdate2 = GetPostString("apdate2");
  438. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  439. if (dwap.Length > 0) lw.Add(dwap);
  440. string price1 = GetPostString("price1");
  441. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  442. string price2 = GetPostString("price2");
  443. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  444. string isoldcustomer = GetPostString("isoldcus");
  445. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  446. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  447. if (PKey != "admin")
  448. {
  449. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  450. lw.Add(string.Format("shopId in ({0})", usershop));
  451. }
  452. //dStruct.Fileds = "tid,ctid,SplitTag,pay_time,seller_nick,buyer_nick,payment,seller_memo,OrderState,status,CustomerTb,DesignUserName,DesignPrice,end_time,WaitDesignTime,FinishDesignTime,FinishDeliveryTime,buyer_message,SupplierName,OutSid,receiver_name,receiver_mobile,receiver_state,receiver_city,receiver_address,isRefund,IsUrgency";
  453. string mainWhere = string.Join(" and ", lw.ToArray());
  454. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  455. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  456. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  457. decimal total = 0;
  458. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  459. {
  460. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  461. }
  462. var res = new
  463. {
  464. data = total
  465. };
  466. string ro_jsond = JsonConvert.SerializeObject(res);
  467. returnSuccess(ro_jsond);
  468. return;
  469. }
  470. public void get_erp_CustomerServiceGather()
  471. {
  472. string userWhere = "", orderWhere = "";
  473. List<string> lw = new List<string>();
  474. string customer = GetPostString("customer");
  475. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  476. string shopname = GetPostString("shopname");
  477. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  478. string date1 = GetPostString("date1");
  479. string date2 = GetPostString("date2");
  480. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  481. if (dw.Length > 0) lw.Add(dw);
  482. orderWhere = string.Join(" and ", lw.ToArray());
  483. string sql = string.Format("select a.Name CusName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitRelease,0) WaitRelease, isnull(e.WaitRob,0) WaitRob, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  484. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  485. "left join " +
  486. "( " +
  487. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  488. ") as b on a.ID = b.CustomerUserId " +
  489. "left join " +
  490. "( " +
  491. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  492. ") as d on a.ID = d.CustomerUserId " +
  493. "left join " +
  494. "( " +
  495. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  496. ") as e on a.ID = e.CustomerUserId " +
  497. "left join " +
  498. "( " +
  499. " select CustomerUserId, RefundCount, RefundSum from " +
  500. " ( " +
  501. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  502. " from CE_ErpTradeRefund a " +
  503. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  504. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  505. " group by CustomerUserId " +
  506. " ) as a " +
  507. ") as f on a.ID = f.CustomerUserId " +
  508. "where a.PostCode = 'CustomerService'",
  509. userWhere, orderWhere);
  510. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  511. writeGridDataTableJson(dt.Rows.Count, dt);
  512. //writeGridDataTableJson(dt.Rows.Count, dt);
  513. }
  514. //设计汇总
  515. public void get_erp_DesignerGather()
  516. {
  517. string userWhere = "", orderWhere = "";
  518. List<string> lw = new List<string>();
  519. string Designer = GetPostString("designer");
  520. int org = GetPostInt("org");
  521. if (Designer.Length > 0)
  522. {
  523. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  524. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  525. }
  526. else if (org > 0)
  527. {
  528. userWhere = string.Format(" where OrgID ={0}", org);
  529. }
  530. string shopname = GetPostString("shopname");
  531. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  532. string state = GetPostString("state");
  533. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  534. string OrderArea = GetPostString("order_area");
  535. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  536. string date1 = GetPostString("date1");
  537. string date2 = GetPostString("date2");
  538. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  539. if (dw.Length > 0) lw.Add(dw);
  540. string UpDate1 = GetPostString("UpDate1");
  541. string UpDate2 = GetPostString("UpDate2");
  542. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  543. if (dw.Length > 0) lw.Add(dw);
  544. orderWhere = string.Join(" and ", lw.ToArray());
  545. string sql = string.Format("select *,cast(cast(z.DesignFinish as float) / (case z.AllOrder when 0 then 1 else z.AllOrder end) * 100 as numeric(18,2)) as FinalizationRate from (" +
  546. "select a.Name DesignerName,isnull(b.Amount,0) Amount, isnull(b.AllOrder,0) AllOrder, isnull(d.WaitDesign,0) WaitDesign, isnull(e.Designing,0) Designing, isnull(g.DesignFinish,0) DesignFinish, isnull(f.RefundCount,0) RefundCount, isnull(f.RefundSum,0) RefundSum " +
  547. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  548. "left join " +
  549. "( " +
  550. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  551. ") as b on a.ID = b.DesignUserId " +
  552. "left join " +
  553. "( " +
  554. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  555. ") as d on a.ID = d.DesignUserId " +
  556. "left join " +
  557. "( " +
  558. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  559. ") as e on a.ID = e.DesignUserId " +
  560. "left join " +
  561. "( " +
  562. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  563. ") as g on a.ID = g.DesignUserId " +
  564. "left join " +
  565. "( " +
  566. " select CustomerUserId, RefundCount, RefundSum from " +
  567. " ( " +
  568. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  569. " from CE_ErpTradeRefund a " +
  570. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  571. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  572. " group by CustomerUserId " +
  573. " ) as a " +
  574. ") as f on a.ID = f.CustomerUserId " +
  575. "where a.PostCode = 'Designer') as z",
  576. userWhere, orderWhere);
  577. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  578. writeGridDataTableJson(dt.Rows.Count, dt);
  579. }
  580. //删除tradecell的订单
  581. public void del_erp_cellorder()
  582. {
  583. if (UrlPostParmsCheck("ctid"))
  584. {
  585. string eid = GetPostString("ctid");
  586. CeErpTradeCell.DelByCtid(eid);
  587. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  588. returnSuccessMsg("删除成功");
  589. }
  590. }
  591. public void clear_erp_refundstate()
  592. {
  593. if (UrlPostParmsCheck("ids"))
  594. {
  595. string eids = GetPostString("ids");
  596. string[] ctidList = eids.Split(',');
  597. foreach (string ctid in ctidList)
  598. {
  599. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  600. if (entity != null)
  601. {
  602. entity.IsRefund = 0;
  603. entity.Update();
  604. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  605. }
  606. else
  607. continue;
  608. }
  609. returnSuccessMsg("操作成功");
  610. return;
  611. }
  612. returnErrorMsg("缺少必要参数");
  613. }
  614. public void set_erp_urgency()
  615. {
  616. if (UrlPostParmsCheck("ctid"))
  617. {
  618. string eid = GetPostString("ctid");
  619. CeErpTradeCell entity = null;
  620. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  621. if (entity != null)
  622. {
  623. double prices = commonHelper.calculationPrice(entity);
  624. if (prices <= 100)
  625. {
  626. returnErrorMsg("此订单金额不足100元,无法加急。");
  627. return;
  628. }
  629. string utime = GetPostString("urgencytime");
  630. if (utime.Length > 0)
  631. {
  632. entity.UrgencyTime = Convert.ToDateTime(utime);
  633. }
  634. else
  635. {
  636. returnErrorMsg("请选择加急时间");
  637. return;
  638. }
  639. if (entity.OrderState <= 4)
  640. {
  641. //entity.seller_memo = entity.seller_memo + "-加急";
  642. string smemo = entity.seller_memo;
  643. int kindex = smemo.IndexOf(")");
  644. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  645. if (lastoneStr != "-")
  646. {
  647. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  648. }
  649. string prememo = smemo.Substring(0, kindex + 2);
  650. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  651. int lastkindex = lastmemo.IndexOf("(");
  652. DateTime urgtime = Convert.ToDateTime(utime);
  653. string newlastmemo = "";
  654. if (lastkindex == 0)
  655. {
  656. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  657. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  658. }
  659. else
  660. {
  661. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  662. }
  663. entity.seller_memo = prememo + newlastmemo;
  664. }
  665. entity.IsUrgency = true;
  666. entity.UpdateTime = DateTime.Now;
  667. entity.Update();
  668. ApiVo apiVo = new ApiVo();
  669. apiVo.orderNumber = entity.ctid;
  670. apiVo.actionName = "changeDesign";
  671. apiVo.orderRemarks = entity.seller_memo;
  672. apiVo.remarkSign = 3;
  673. designHelper.API_WorkCore(apiVo); //changeDesign
  674. CeErpSukuraData.createInfo(entity.ctid, 7);
  675. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  676. returnSuccessMsg("设置成功!");
  677. return;
  678. }
  679. returnErrorMsg("找不到记录");
  680. }
  681. }
  682. public void set_erp_reset()
  683. {
  684. if (UrlPostParmsCheck("ctid"))
  685. {
  686. string eid = GetPostString("ctid");
  687. CeErpTradeCell entity = null;
  688. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  689. if (entity != null)
  690. {
  691. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  692. {
  693. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  694. {
  695. returnErrorMsg("财务要求已下单已发货无法重置");
  696. return;
  697. }
  698. }
  699. entity.IsUrgency = false;
  700. entity.seller_memo = "";
  701. entity.OtherMemo = "";
  702. entity.OrderState = 0;
  703. entity.IsReturn = 0;
  704. //entity.IsRefund = 0;
  705. entity.MemoOpt = 0;
  706. entity.AfterSaleState = 0;
  707. entity.AfterSaleResponsible = "";
  708. entity.AfterSaleUserId = 0;
  709. entity.IsNeedBill = 0;
  710. entity.CustomerUserId = 0;
  711. entity.DesignUserId = 0;
  712. entity.SupplierId = 0;
  713. entity.PlaceUserId = 0;
  714. entity.ptid = "";
  715. entity.IsSample = 0;
  716. entity.IsXianHuo = 0;
  717. entity.isDianziOrder = 0;
  718. entity.DispatchSort = 0;
  719. entity.IsVerifyToSupplier = false;
  720. entity.FinishPlaceTime = null;
  721. entity.Update();
  722. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  723. if (trade != null)
  724. {
  725. trade.seller_memo = "";
  726. trade.Update();
  727. }
  728. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  729. returnSuccessMsg("重置成功!");
  730. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  731. if (desginBill != null)
  732. {
  733. desginBill.isDel = 1;
  734. desginBill.Update();
  735. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  736. }
  737. ApiVo apiVo = new ApiVo();
  738. apiVo.orderNumber = entity.ctid;
  739. apiVo.actionName = "resetDesign";
  740. designHelper.API_WorkCore(apiVo);//resetDesign
  741. return;
  742. }
  743. returnErrorMsg("找不到记录");
  744. }
  745. }
  746. public void save_erp_sellermemo()
  747. {
  748. if (UrlPostParmsCheck("ctid"))
  749. {
  750. string ctid = GetPostString("ctid");
  751. CeErpTradeCell entity = null;
  752. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  753. if (entity != null)
  754. {
  755. string memo = GetPostString("seller_memo");
  756. string qn_memo = GetPostString("qn_memo");
  757. memo = memo.Replace(" ", "");
  758. if (memo.Contains("补差"))
  759. {
  760. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  761. return;
  762. }
  763. List<string> bitList = new List<string>
  764. {
  765. "\\","/",":","*","?", "\"","<" ,">","|"
  766. };
  767. bool isIn = false;
  768. foreach (string bit in bitList)
  769. {
  770. if (memo.Contains(bit))
  771. {
  772. isIn = true;
  773. }
  774. }
  775. if (isIn)
  776. {
  777. returnErrorMsg("不能使用 一些符合作为文件名");
  778. return;
  779. }
  780. if (entity.seller_memo != memo)
  781. {
  782. if (entity.IsSample == 2)
  783. {
  784. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  785. return;
  786. }
  787. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  788. {
  789. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  790. {
  791. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  792. return;
  793. }
  794. /*if (CurrentUser.UserPost.Post.Code != "Place")
  795. {
  796. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  797. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  798. {
  799. returnErrorMsg("售前系统订单无法再此修改!");
  800. return;
  801. }
  802. }*/
  803. }
  804. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  805. }
  806. if (!string.IsNullOrEmpty(qn_memo) && !(entity.IsSample > 0 || entity.ctid.Contains("N_") || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物")))
  807. {
  808. if (entity.OrderState >= 5)
  809. {
  810. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  811. return;
  812. }
  813. string delMemo = commonHelper.convertQNMemo(qn_memo, ref entity);
  814. if (string.IsNullOrEmpty(delMemo))
  815. {
  816. returnErrorMsg("备注不规范,无法识别");
  817. return;
  818. }
  819. memo = delMemo;
  820. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统千牛修改为:" + memo, entity.OrderState, 1);
  821. }
  822. //commonHelper.getCytPrice(entity);
  823. int memoopt = GetPostInt("MemoOpt");
  824. Boolean ismemoopt = false;
  825. if (memoopt > 0)
  826. {
  827. string stropt = "";
  828. if (memoopt == 1)
  829. {
  830. stropt = "“改稿”";
  831. ismemoopt = true;
  832. }
  833. else if (memoopt == 2)
  834. {
  835. stropt = "“定稿”";
  836. }
  837. else if (memoopt == 3)
  838. {
  839. stropt = "“查货”";
  840. CeErpSukuraData.createInfo(entity.ctid, 6);
  841. }
  842. entity.MemoOpt = Convert.ToInt32(memoopt);
  843. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  844. }
  845. if (entity.OrderState < 5)
  846. {
  847. memo = memo.Replace("(", "(");
  848. memo = memo.Replace(")", ")");
  849. }
  850. /* if (entity.OrderState < 3)
  851. {
  852. entity.DispatchSort = 0;
  853. }*/
  854. entity.seller_memo = memo;
  855. entity.UpdateTime = DateTime.Now;
  856. entity.Update();
  857. ApiVo apiVo = new ApiVo();
  858. apiVo.orderNumber = entity.ctid;
  859. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  860. apiVo.orderRemarks = memo;
  861. apiVo.remarkSign = memoopt;
  862. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  863. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  864. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  865. {
  866. //dataHelper.api_orderBack(entity.ctid, "0", "");
  867. }
  868. if (entity.seller_memo.Contains("改稿"))
  869. {
  870. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  871. }
  872. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  873. returnSuccessMsg("保存成功!");
  874. return;
  875. }
  876. returnErrorMsg("找不到记录");
  877. }
  878. }
  879. public void ins_erp_checkorder()
  880. {
  881. if (UrlPostParmsCheck("ctid"))
  882. {
  883. string ctid = GetPostString("ctid");
  884. CeErpTradeCell entity = null;
  885. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  886. if (entity != null)
  887. {
  888. if (entity.OrderState < 6)
  889. {
  890. returnErrorMsg("下单完成后才可查货");
  891. return;
  892. }
  893. /*if (entity.OrderState > 6)
  894. {
  895. returnErrorMsg("订单已发货");
  896. return;
  897. }*/
  898. if (entity.FinishPlaceTime != null)
  899. {
  900. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  901. {
  902. returnErrorMsg("下单时间不足,无法查货");
  903. return;
  904. }
  905. }
  906. entity.MemoOpt = 3;
  907. entity.CheckOrderTime = DateTime.Now;
  908. entity.UpdateTime = DateTime.Now;
  909. entity.Update();
  910. CeErpSukuraData.createInfo(entity.ctid, 6);
  911. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  912. returnSuccessMsg("操作成功!");
  913. return;
  914. }
  915. returnErrorMsg("找不到记录");
  916. }
  917. }
  918. public void save_erp_othermemo()
  919. {
  920. if (UrlPostParmsCheck("ctid"))
  921. {
  922. string ctid = GetPostString("ctid");
  923. CeErpTradeCell entity = null;
  924. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  925. if (entity != null)
  926. {
  927. entity.OtherMemo = GetPostString("otherMemo");
  928. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  929. {
  930. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  931. StringBuilder sql = new StringBuilder();
  932. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  933. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  934. if (dt != null && dt.Rows.Count > 0)
  935. {
  936. foreach (DataRow dr in dt.Rows)
  937. {
  938. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  939. {
  940. //品类一直
  941. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  942. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  943. if (ceErpSampleCustomer == null)
  944. {
  945. ceErpSampleCustomer = new CeErpSampleCustomer();
  946. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  947. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  948. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  949. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  950. ceErpSampleCustomer.shopId = entity.ShopId;
  951. }
  952. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  953. ceErpSampleCustomer.lastTid = entity.tid;
  954. if (ceErpSampleCustomer.ID > 0)
  955. {
  956. ceErpSampleCustomer.Update();
  957. }
  958. else
  959. {
  960. ceErpSampleCustomer.Create();
  961. }
  962. }
  963. }
  964. }
  965. }
  966. //if (entity.IsOldCustomer == 1)
  967. //{
  968. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  969. //{
  970. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  971. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  972. //}
  973. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  974. //{
  975. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  976. // {
  977. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  978. // {
  979. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  980. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  981. // }
  982. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  983. // {
  984. // entity.OrderState = 2;
  985. // entity.DesignUserId = 0;
  986. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  987. // }
  988. // else
  989. // {
  990. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  991. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  992. // }
  993. // }
  994. //}
  995. //}
  996. entity.UpdateTime = DateTime.Now;
  997. entity.Update();
  998. returnSuccessMsg("保存成功!");
  999. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  1000. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  1001. if (entity.OtherMemo.Contains("改稿"))
  1002. {
  1003. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  1004. }
  1005. return;
  1006. }
  1007. returnErrorMsg("找不到记录");
  1008. }
  1009. }
  1010. public void save_erp_customermemo()
  1011. {
  1012. if (UrlPostParmsCheck("ctid"))
  1013. {
  1014. string ctid = GetPostString("ctid");
  1015. CeErpTradeCell entity = null;
  1016. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  1017. if (entity != null)
  1018. {
  1019. entity.UpdateTime = DateTime.Now;
  1020. entity.CustomerMemo = GetPostString("CustomerMemo");
  1021. entity.Update();
  1022. ApiVo apiVo = new ApiVo();
  1023. apiVo.orderNumber = entity.ctid;
  1024. apiVo.actionName = "followRemarks";
  1025. apiVo.orderRemarks = entity.CustomerMemo;
  1026. designHelper.API_WorkCore(apiVo);//followRemarks
  1027. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  1028. returnSuccessMsg("保存成功!");
  1029. return;
  1030. }
  1031. returnErrorMsg("找不到记录");
  1032. }
  1033. }
  1034. public void upd_erp_addmemotag()
  1035. {
  1036. if (UrlPostParmsCheck("ctid"))
  1037. {
  1038. ;
  1039. string eid = GetPostString("ctid");
  1040. string sfTagstr = GetPostString("memotag");
  1041. CeErpTradeCell entity = null;
  1042. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1043. if (entity != null)
  1044. {
  1045. ApiVo apiVo = new ApiVo();
  1046. if (entity.OrderState == 0)
  1047. {
  1048. returnErrorMsg("请先领单");
  1049. return;
  1050. }
  1051. //撤销顺丰
  1052. if (sfTagstr == "撤销顺丰")
  1053. {
  1054. entity.IsSF = 0;
  1055. string reMsg = "";
  1056. string oldmemo = entity.seller_memo;
  1057. if (entity.OrderState < 5)
  1058. {
  1059. oldmemo = oldmemo.Replace("顺丰到付", "");
  1060. oldmemo = oldmemo.Replace("顺丰寄付", "");
  1061. entity.seller_memo = oldmemo;
  1062. }
  1063. else
  1064. {
  1065. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  1066. {
  1067. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  1068. }
  1069. }
  1070. entity.Update();
  1071. apiVo.orderNumber = entity.ctid;
  1072. apiVo.actionName = "orderRemarks";
  1073. apiVo.orderRemarks = entity.seller_memo;
  1074. apiVo.isSf = entity.IsSF.ToString();
  1075. designHelper.API_WorkCore(apiVo);//orderRemarks
  1076. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  1077. returnSuccessMsg("撤销成功!" + reMsg);
  1078. return;
  1079. }
  1080. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  1081. {
  1082. //string oldmemo = entity.seller_memo;
  1083. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  1084. string sfStr = GetPostString("memotag");
  1085. string smemo = entity.seller_memo;
  1086. int kindex = smemo.IndexOf(")");
  1087. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  1088. if (lastoneStr != "-")
  1089. {
  1090. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  1091. }
  1092. string prememo = smemo.Substring(0, kindex + 2);
  1093. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  1094. int lastkindex = lastmemo.IndexOf("(");
  1095. string newlastmemo = "";
  1096. if (lastkindex == 0)
  1097. {
  1098. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1099. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1100. }
  1101. else
  1102. {
  1103. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1104. }
  1105. entity.seller_memo = prememo + newlastmemo;
  1106. }
  1107. string sfTagMSg = "";
  1108. if (sfTagstr == "顺丰寄付")
  1109. {
  1110. entity.IsSF = 1;
  1111. sfTagMSg = "顺丰寄付";
  1112. }
  1113. else if (sfTagstr == "顺丰到付")
  1114. {
  1115. entity.IsSF = 2;
  1116. sfTagMSg = "顺丰到付";
  1117. }
  1118. if (entity.SupplierId == 19 && entity.OrderState == 6)
  1119. {
  1120. string deliveryWayName = "";
  1121. if (sfTagstr == "撤销顺丰")
  1122. {
  1123. sfTagstr = "普通快递";
  1124. }
  1125. if (sfTagstr == "顺丰寄付")
  1126. {
  1127. sfTagstr = "顺丰特快寄付";
  1128. }
  1129. if (sfTagstr == "顺丰到付")
  1130. {
  1131. sfTagstr = "顺丰特快到付";
  1132. }
  1133. string result = apichyHelper.updateExpressMark(entity.tid, sfTagstr);
  1134. if ("修改失败".Equals(result))
  1135. {
  1136. returnErrorMsg("修改失败");
  1137. return;
  1138. }
  1139. }
  1140. entity.Update();
  1141. apiVo = new ApiVo();
  1142. apiVo.orderNumber = entity.ctid;
  1143. apiVo.actionName = "orderRemarks";
  1144. apiVo.orderRemarks = entity.seller_memo;
  1145. apiVo.isSf = entity.IsSF.ToString();
  1146. designHelper.API_WorkCore(apiVo);//orderRemarks
  1147. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1148. returnSuccessMsg("标记成功!");
  1149. return;
  1150. }
  1151. returnErrorMsg("找不到记录");
  1152. }
  1153. }
  1154. public void upd_erp_ordertag()
  1155. {
  1156. if (UrlPostParmsCheck("ctid"))
  1157. {
  1158. string eid = GetPostString("ctid");
  1159. CeErpTradeCell entity = null;
  1160. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1161. if (entity != null)
  1162. {
  1163. int tag = GetPostInt("wechattag");
  1164. //if(tag==4 && entity.IsSample == 2)
  1165. //{
  1166. // returnErrorMsg("补差价单不能标记微信单");
  1167. // return;
  1168. //}
  1169. entity.wechatTag = tag;
  1170. entity.Update();
  1171. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1172. if (tag == 1)
  1173. {
  1174. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1175. if (cash == null)
  1176. {
  1177. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1178. cash = new CeErpReturnCash();
  1179. cash.tid = entity.tid;
  1180. cash.seller_nick = main.seller_nick;
  1181. cash.payment = trade.payment;
  1182. cash.buyer_nick = main.buyer_nick;
  1183. cash.cashstate = 0;
  1184. cash.rtype = "微信返现";
  1185. cash.returnprice = 0;
  1186. cash.created = DateTime.Now;
  1187. cash.con = "订单标记微信单";
  1188. cash.img = "";
  1189. cash.applyuserid = CurrentUser.UserID;
  1190. cash.Create();
  1191. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1192. }
  1193. else
  1194. {
  1195. cash.cashstate = 0;
  1196. cash.Update();
  1197. }
  1198. CeErpSukuraData.createInfo(entity.ctid, 9);
  1199. }
  1200. else if (tag == 2)
  1201. {
  1202. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1203. if (cash == null)
  1204. {
  1205. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1206. cash = new CeErpReturnCash();
  1207. cash.tid = entity.tid;
  1208. cash.seller_nick = main.seller_nick;
  1209. cash.payment = trade.payment;
  1210. cash.buyer_nick = main.buyer_nick;
  1211. cash.cashstate = 0;
  1212. cash.rtype = "推购返现";
  1213. cash.returnprice = 5;
  1214. cash.created = DateTime.Now;
  1215. cash.con = "订单标记推购单";
  1216. cash.img = "";
  1217. cash.applyuserid = CurrentUser.UserID;
  1218. cash.Create();
  1219. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1220. }
  1221. else
  1222. {
  1223. cash.cashstate = 0;
  1224. cash.Update();
  1225. }
  1226. CeErpSukuraData.createInfo(entity.ctid, 9);
  1227. }
  1228. else if (tag == 3)
  1229. {
  1230. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1231. if (pers == null)
  1232. {
  1233. pers = new CeErpPersuade();
  1234. pers.ctid = entity.ctid;
  1235. pers.pstate = 0;
  1236. pers.created = DateTime.Now;
  1237. pers.applyuserid = CurrentUser.UserID;
  1238. pers.Create();
  1239. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1240. }
  1241. else
  1242. {
  1243. pers.pstate = 0;
  1244. pers.Update();
  1245. }
  1246. }
  1247. else if (tag == 4 || tag == 5)
  1248. {
  1249. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1250. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1251. if (pers == null)
  1252. {
  1253. pers = CeErpStayGoods.GetByTid(entity.tid);
  1254. }
  1255. if (pers == null)
  1256. {
  1257. pers = new CeErpStayGoods();
  1258. pers.t_id = entity.tid;
  1259. pers.ctid = entity.ctid;
  1260. pers.status = "待审核";
  1261. pers.audit_type = 0;
  1262. if (tag == 4)
  1263. {
  1264. pers.stay_type = "微信推购";
  1265. }
  1266. else
  1267. {
  1268. pers.stay_type = "旺旺推购";
  1269. }
  1270. if (entity.IsXianHuo == 0)
  1271. {
  1272. pers.product_id = entity.ProductId;
  1273. }
  1274. pers.wangwang = main.buyer_nick;
  1275. pers.shop_name = main.seller_nick;
  1276. pers.creata_time = DateTime.Now;
  1277. pers.create_u_id = CurrentUser.UserID;
  1278. pers.create_u_name = CurrentUser.UserName;
  1279. pers.Create();
  1280. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1281. }
  1282. else
  1283. {
  1284. pers.ctid = entity.ctid;
  1285. pers.audit_type = 0;
  1286. pers.Update();
  1287. }
  1288. CeErpSukuraData.createInfo(entity.ctid, 10);
  1289. }
  1290. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1291. returnSuccessMsg("标记成功!");
  1292. return;
  1293. }
  1294. returnErrorMsg("找不到记录");
  1295. }
  1296. }
  1297. public void upd_erp_ordertag_cancel()
  1298. {
  1299. if (UrlPostParmsCheck("ctid"))
  1300. {
  1301. string eid = GetPostString("ctid");
  1302. CeErpTradeCell entity = null;
  1303. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1304. if (entity != null)
  1305. {
  1306. entity.wechatTag = 0;
  1307. entity.Update();
  1308. CeErpStayGoods pers = CeErpStayGoods.GetByCtid(entity.ctid);
  1309. if (pers != null)
  1310. {
  1311. pers.status = "取消推购";
  1312. pers.audit_type = 3;
  1313. pers.Update();
  1314. }
  1315. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1316. returnSuccessMsg("标记成功!");
  1317. return;
  1318. }
  1319. returnErrorMsg("找不到记录");
  1320. }
  1321. }
  1322. public void upd_erp_addweichattag()
  1323. {
  1324. if (UrlPostParmsCheck("ctid"))
  1325. {
  1326. ;
  1327. string eid = GetPostString("ctid");
  1328. CeErpTradeCell entity = null;
  1329. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1330. if (entity != null)
  1331. {
  1332. if (entity.IsAddWechat > 0)
  1333. {
  1334. returnErrorMsg("此单已经标记过了");
  1335. return;
  1336. }
  1337. string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
  1338. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1339. if (dt.Rows.Count > 0)
  1340. {
  1341. entity.IsAddWechat = 2;
  1342. }
  1343. else
  1344. {
  1345. entity.IsAddWechat = 1;
  1346. }
  1347. entity.Update();
  1348. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1349. returnSuccessMsg("标记成功!");
  1350. return;
  1351. }
  1352. returnErrorMsg("找不到记录");
  1353. }
  1354. }
  1355. public void upd_erp_getmyorder()
  1356. {
  1357. if (UrlPostParmsCheck("ctid"))
  1358. {
  1359. string eid = GetPostString("ctid");
  1360. CeErpTradeCell entity = null;
  1361. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1362. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1363. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1364. {
  1365. returnErrorMsg("台湾客户需填写身份证号!");
  1366. return;
  1367. }
  1368. if (commonHelper.isFarAddress(father.receiver_state) && father.delivery_paymant == 0)
  1369. {
  1370. returnErrorMsg("偏远地区需要填写物流费!");
  1371. return;
  1372. }
  1373. if (entity != null)
  1374. {
  1375. if (entity.ctid.IndexOf("C") != -1)
  1376. {
  1377. StringBuilder sql = new StringBuilder();
  1378. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1379. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1380. if (dt.Rows.Count > 0)
  1381. {
  1382. decimal total = 0;
  1383. foreach (DataRow dr in dt.Rows)
  1384. {
  1385. total += Convert.ToDecimal(dr["payment"]);
  1386. }
  1387. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1388. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1389. {
  1390. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1391. return;
  1392. }
  1393. }
  1394. }
  1395. if (entity.OrderState == -1)
  1396. {
  1397. returnErrorMsg("待审核订单无法领取!");
  1398. return;
  1399. }
  1400. entity.CustomerUserId = CurrentUser.UserID;
  1401. if (entity.OrderState < 2)
  1402. {
  1403. entity.OrderState = 2;
  1404. if (entity.ShopId != 0)
  1405. {
  1406. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1407. }
  1408. }
  1409. entity.UpdateTime = DateTime.Now;
  1410. entity.Update();
  1411. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1412. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1413. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1414. {
  1415. //dataHelper.api_orderBack(entity.ctid, "0", "");
  1416. }
  1417. returnSuccessMsg("领单成功!");
  1418. return;
  1419. }
  1420. returnErrorMsg("找不到记录");
  1421. }
  1422. }
  1423. public void getmyorder_from_init()
  1424. {
  1425. if (UrlPostParmsCheck("ctid"))
  1426. {
  1427. string eid = GetPostString("ctid");
  1428. CeErpTradeCell entity = null;
  1429. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1430. if (entity != null)
  1431. {
  1432. string sellerMemo = GetPostString("sellerMemo");
  1433. if (sellerMemo.Length > 0)
  1434. {
  1435. entity.seller_memo = sellerMemo;
  1436. }
  1437. string oterhMemo = GetPostString("otherMemo");
  1438. if (oterhMemo.Length > 0)
  1439. {
  1440. entity.OtherMemo = oterhMemo;
  1441. }
  1442. int urg = GetPostInt("urgency");
  1443. entity.IsUrgency = (urg == 1 ? true : false);
  1444. int wechat = GetPostInt("wechat");
  1445. int command = GetPostInt("command");
  1446. if (wechat == 1)
  1447. {
  1448. entity.wechatTag = 1;
  1449. }
  1450. if (command == 1)
  1451. {
  1452. entity.wechatTag = 2;
  1453. }
  1454. string pPro = GetPostString("pprofession");
  1455. if (pPro.Length > 0)
  1456. {
  1457. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1458. string spro = GetPostString("profession");
  1459. if (spro.Length > 0)
  1460. {
  1461. entity.ProfessionId = Convert.ToInt32(spro);
  1462. }
  1463. }
  1464. string proId = GetPostString("productId");
  1465. if (proId.Length > 0)
  1466. {
  1467. entity.ProductId = Convert.ToInt32(proId);
  1468. }
  1469. entity.Material = GetPostString("material");
  1470. entity.Craft = GetPostString("craft");
  1471. entity.CustomerUserId = CurrentUser.UserID;
  1472. if (entity.OrderState < 2)
  1473. {
  1474. entity.OrderState = 2;
  1475. if (entity.ShopId != 0)
  1476. {
  1477. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1478. }
  1479. }
  1480. entity.Update();
  1481. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1482. returnSuccessMsg("领单成功!");
  1483. return;
  1484. }
  1485. returnErrorMsg("找不到记录");
  1486. }
  1487. }
  1488. public void upd_erp_setrelationorder()
  1489. {
  1490. if (UrlPostParmsCheck("ctid"))
  1491. {
  1492. ;
  1493. string eid = GetPostString("ctid");
  1494. string ftid = GetPostString("ftid");
  1495. CeErpTradeCell entity = null;
  1496. CeErpTradeCell fentity = null;
  1497. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1498. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1499. if (fentity == null)
  1500. {
  1501. returnErrorMsg("找不到关联的主订单");
  1502. return;
  1503. }
  1504. if (entity != null)
  1505. {
  1506. if (entity.OrderState >= 5)
  1507. {
  1508. returnErrorMsg("本单已经设计完成无法关联");
  1509. return;
  1510. }
  1511. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1512. {
  1513. returnErrorMsg("线下单续审核后才能关联!");
  1514. return;
  1515. }
  1516. entity.ptid = ftid;
  1517. entity.OrderState = fentity.OrderState;
  1518. //entity.status = fentity.status;
  1519. entity.CustomerUserId = fentity.CustomerUserId;
  1520. entity.DesignUserId = fentity.DesignUserId;
  1521. entity.seller_memo = "补差价单:" + ftid;
  1522. entity.IsSample = 2;
  1523. entity.Update();
  1524. ApiVo apiVo = new ApiVo();
  1525. apiVo.orderNumber = ftid;
  1526. apiVo.payment = entity.payment;
  1527. apiVo.actionName = "repairDesign";
  1528. designHelper.API_WorkCore(apiVo);//repairDesign
  1529. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1530. returnSuccessMsg("关联成功!");
  1531. return;
  1532. }
  1533. else
  1534. returnErrorMsg("找不到记录");
  1535. }
  1536. }
  1537. public void download_erp_neworder()
  1538. {
  1539. string seller = GetPostString("seller_nick");
  1540. string tid = GetPostString("tid");
  1541. if (seller.Length <= 0 || tid.Length <= 0)
  1542. {
  1543. returnErrorMsg("数据错误");
  1544. }
  1545. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1546. //{
  1547. // returnErrorMsg("找不到店铺Sessionkey");
  1548. //}
  1549. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1550. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1551. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1552. if (res.IndexOf("refOid") == -1)
  1553. {
  1554. returnErrorMsg("下载订单数据失败");
  1555. return;
  1556. }
  1557. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1558. returnSuccessMsg("下载完成");
  1559. //tmcHelper.createNewOrder(res);
  1560. //CeErpTrade entr = null;
  1561. //entr = CeErpTrade.Get(tid);
  1562. //if (entr != null)
  1563. //{
  1564. // returnSuccess("下载成功");
  1565. // //下载成功之后,Cell表生成对应的订单;
  1566. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1567. //}
  1568. //else
  1569. //{
  1570. // returnErrorMsg("下载失败或者创建订单失败");
  1571. //}
  1572. }
  1573. public void set_erp_atersale()
  1574. {
  1575. if (UrlPostParmsCheck("ctid"))
  1576. {
  1577. string eid = GetPostString("ctid");
  1578. string reason = GetPostString("AfterSaleReason");
  1579. CeErpTradeCell entity = null;
  1580. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1581. if (entity != null)
  1582. {
  1583. /*if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1584. {
  1585. returnErrorMsg("此订单已经在售后");
  1586. return;
  1587. }*/
  1588. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1589. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1590. entity.AfterSaleTime = DateTime.Now;
  1591. entity.HandleTime = null;
  1592. entity.Update();
  1593. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1594. returnSuccessMsg("转售后成功!");
  1595. return;
  1596. }
  1597. returnErrorMsg("找不到记录");
  1598. }
  1599. }
  1600. public void set_erp_withdraw()
  1601. {
  1602. if (UrlPostParmsCheck("ctid"))
  1603. {
  1604. try
  1605. {
  1606. string eid = GetPostString("ctid");//商品id
  1607. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1608. CeWithdraw ceWithdrawSelect = null;
  1609. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1610. if (ceWithdrawSelect != null)
  1611. {
  1612. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1613. {
  1614. ceWithdrawSelect.status = -1;
  1615. ceWithdrawSelect.Update();
  1616. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1617. returnSuccessMsg("重新发起审核成功");
  1618. return;
  1619. }
  1620. else
  1621. {
  1622. returnSuccessMsg("请勿重复申请!");
  1623. return;
  1624. }
  1625. }
  1626. else
  1627. {
  1628. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1629. if (string.IsNullOrEmpty(CustomerUserId))
  1630. {
  1631. CustomerUserId = "-1";
  1632. }
  1633. int Userid = CurrentUser.UserID;//用户id
  1634. CeWithdraw ceWithdraw = new CeWithdraw();
  1635. ceWithdraw.tid = eid;
  1636. ceWithdraw.userid = Userid;
  1637. ceWithdraw.providerid = CustomerUserId;
  1638. ceWithdraw.status = 3;
  1639. ceWithdraw.creationtime = DateTime.Now;
  1640. ceWithdraw.Create();
  1641. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1642. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1643. return;
  1644. }
  1645. }
  1646. catch
  1647. {
  1648. returnErrorMsg("申请撤回订单失败");
  1649. return;
  1650. }
  1651. }
  1652. }
  1653. public void ins_erp_billinfo()
  1654. {
  1655. if (UrlPostParmsCheck("ctid"))
  1656. {
  1657. string eid = GetPostString("ctid");
  1658. CeErpTradeCell entity = null;
  1659. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1660. if (entity != null)
  1661. {
  1662. CeErpBill bill = CeErpBill.GetByTid(eid);
  1663. bool isHave = false;
  1664. if (bill != null)
  1665. {
  1666. isHave = true;
  1667. if (bill.state != 4)
  1668. {
  1669. returnErrorMsg("此单已经申请过发票了");
  1670. return;
  1671. }
  1672. }
  1673. if (entity.IsNeedBill == 0)
  1674. {
  1675. entity.IsNeedBill = 1;
  1676. }
  1677. entity.Update();
  1678. string errjson = "";
  1679. try
  1680. {
  1681. CeErpBill bill_entity = new CeErpBill();
  1682. bill_entity.tid = entity.tid;
  1683. bill_entity.title = GetPostString("title");
  1684. string taxstr = GetPostString("tax");
  1685. taxstr = taxstr.Replace(" ", "");
  1686. bill_entity.tax = taxstr;
  1687. bill_entity.bank = GetPostString("bank");
  1688. string bankacstr = GetPostString("bankac");
  1689. bankacstr = bankacstr.Replace(" ", "");
  1690. bill_entity.bankac = bankacstr;
  1691. bill_entity.address = GetPostString("address");
  1692. bill_entity.phone = GetPostString("phone");
  1693. bill_entity.price = GetPostString("price");
  1694. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1695. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1696. {
  1697. billCount += 1;
  1698. }
  1699. string prebill = "ltb";
  1700. for (int idx = 1; idx <= 1; idx++)
  1701. {
  1702. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1703. string billoid = prebill + idx + dtstr;
  1704. bill_entity.billOrderId += billoid;
  1705. if (idx < billCount)
  1706. {
  1707. bill_entity.billOrderId += ",";
  1708. }
  1709. }
  1710. bill_entity.productId = GetPostInt("ProductName");
  1711. bill_entity.num = GetPostInt("num");
  1712. bill_entity.unit = GetPostString("unit");
  1713. bill_entity.type = GetPostString("type");
  1714. bill_entity.sendType = GetPostString("SendType");
  1715. bill_entity.email = GetPostString("email");
  1716. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1717. bill_entity.shopName = GetPostString("ShopName");
  1718. bill_entity.applymemo = GetPostString("applyMemo");
  1719. bill_entity.createTime = DateTime.Now;
  1720. bill_entity.state = 0;
  1721. bill_entity.userId = CurrentUser.UserID;
  1722. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1723. bill_entity.Create();
  1724. }
  1725. catch (Exception ex)
  1726. {
  1727. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1728. returnErrorMsg("创建发票出错!");
  1729. return;
  1730. }
  1731. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1732. returnSuccessMsg("发票申请成功!");
  1733. return;
  1734. }
  1735. returnErrorMsg("找不到记录");
  1736. }
  1737. }
  1738. public void ins_erp_neworder()
  1739. {
  1740. if (UrlPostParmsCheck("receiver_name"))
  1741. {
  1742. CeErpTrade entity = new CeErpTrade();
  1743. string plat_form = GetPostString("platform");
  1744. string preStr = "N_";
  1745. if (plat_form == "拼多多")
  1746. {
  1747. preStr = "P_";
  1748. }
  1749. else if (plat_form == "阿里巴巴")
  1750. {
  1751. preStr = "A_";
  1752. }
  1753. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1754. entity.seller_nick = GetPostString("seller_nick");
  1755. entity.buyer_nick = GetPostString("buyer_nick");
  1756. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1757. entity.total_fee = entity.payment;
  1758. entity.pay_time = DateTime.Now;
  1759. entity.status = "NOT_SHIPPED";
  1760. entity.receiver_name = GetPostString("receiver_name");
  1761. entity.receiver_mobile = GetPostString("receiver_mobile");
  1762. entity.receiver_state = GetPostString("receiver_state");
  1763. entity.receiver_city = GetPostString("receiver_city");
  1764. entity.receiver_district = GetPostString("receiver_district");
  1765. entity.receiver_address = GetPostString("receiver_address");
  1766. if (entity.receiver_state == "" || entity.receiver_city == "")
  1767. {
  1768. returnErrorMsg("收件地址不能为空");
  1769. return;
  1770. }
  1771. int shopId = 0;
  1772. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1773. if (nShop != null)
  1774. {
  1775. shopId = nShop.ID;
  1776. }
  1777. if (shopId != 34 && entity.payment == 0)
  1778. {
  1779. returnErrorMsg("公司自用的单金额才能为0");
  1780. return;
  1781. }
  1782. entity.Create();
  1783. CeErpTradeCell entitycell = new CeErpTradeCell();
  1784. entitycell.ctid = entity.tid;
  1785. entitycell.tid = entity.tid;
  1786. entitycell.ShopId = shopId;
  1787. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1788. entitycell.OrderState = 0;
  1789. entitycell.pay_time = entity.pay_time;
  1790. entitycell.IsOffLineOrder = 1;
  1791. entitycell.Create();
  1792. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1793. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1794. return;
  1795. }
  1796. }
  1797. public void ins_erp_neworder2()
  1798. {
  1799. if (UrlPostParmsCheck("receiver_name"))
  1800. {
  1801. //string plat_form = GetPostString("platform");
  1802. string preStr = "X_";
  1803. string memo = GetPostString("memo");
  1804. string productId = GetPostString("productId");
  1805. string primg = GetPostString("proofimg");
  1806. string sellerNick = GetPostString("seller_nick");
  1807. string addFrom = GetPostString("addfrom");
  1808. if (addFrom == "1")
  1809. {
  1810. preStr = "N_";
  1811. }
  1812. int shopId = 0;
  1813. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1814. if (nShop != null)
  1815. {
  1816. shopId = nShop.ID;
  1817. }
  1818. else
  1819. {
  1820. returnErrorMsg("找不到对应店铺");
  1821. return;
  1822. }
  1823. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1824. {
  1825. returnErrorMsg("必须上传付款凭证");
  1826. return;
  1827. }
  1828. CeErpTrade entity = new CeErpTrade();
  1829. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1830. entity.seller_nick = sellerNick;
  1831. entity.buyer_nick = GetPostString("buyer_nick");
  1832. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1833. entity.total_fee = entity.payment;
  1834. entity.pay_time = DateTime.Now;
  1835. entity.status = "NOT_SHIPPED";
  1836. entity.receiver_name = GetPostString("receiver_name");
  1837. entity.receiver_mobile = GetPostString("receiver_mobile");
  1838. entity.receiver_state = GetPostString("receiver_state");
  1839. entity.receiver_city = GetPostString("receiver_city");
  1840. entity.receiver_district = GetPostString("receiver_district");
  1841. entity.receiver_address = GetPostString("receiver_address");
  1842. entity.seller_memo = memo;
  1843. entity.orderFrom = 20;
  1844. entity.orderType = 15;
  1845. if (entity.receiver_state == "" || entity.receiver_city == "")
  1846. {
  1847. returnErrorMsg("收件地址不能为空");
  1848. return;
  1849. }
  1850. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1851. {
  1852. returnErrorMsg("公司自用的单金额才能为0");
  1853. return;
  1854. }
  1855. entity.Create();
  1856. string toWhere = GetPostString("towhere");
  1857. string oldOrder = GetPostString("oldOrder");
  1858. CeErpTradeCell entitycell = new CeErpTradeCell();
  1859. entitycell.ctid = entity.tid;
  1860. //唯一标识
  1861. entitycell.OrderSn = entity.tid;
  1862. string orderSn = commonHelper.generateDateTimeRandomNos();
  1863. if (orderSn != "")
  1864. {
  1865. entitycell.OrderSn = orderSn;
  1866. }
  1867. entitycell.tid = entity.tid;
  1868. //if (preStr == "X_")
  1869. //{
  1870. entitycell.IsOffLineOrder = 1;
  1871. if ("1".Equals(oldOrder))
  1872. {
  1873. entitycell.IsOldCustomer = 1;
  1874. }
  1875. //}
  1876. entitycell.CustomerUserId = CurrentUser.UserID;
  1877. entitycell.PayProofImg = primg;
  1878. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1879. entitycell.ProductId = Convert.ToInt32(productId);
  1880. entitycell.ShopId = shopId;
  1881. entitycell.UpdateTime = DateTime.Now;
  1882. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1883. if (entitycell.ProductId > 0)
  1884. {
  1885. CeErpProduct ceErpProduct = CeErpProduct.GetById(entitycell.ProductId);
  1886. if (ceErpProduct.CreateTime != null && DateTime.Compare(ceErpProduct.CreateTime, DateTime.Now.AddDays(-90)) > 0)
  1887. {
  1888. entitycell.NewProduct = 1;
  1889. }
  1890. }
  1891. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1892. {
  1893. entitycell.IsXianHuo = 1;
  1894. }
  1895. entitycell.pay_time = entity.pay_time;
  1896. if (toWhere == "1")
  1897. {
  1898. entitycell.OrderState = 2;
  1899. }
  1900. else
  1901. {
  1902. entitycell.OrderState = 6;
  1903. entitycell.FinishPlaceTime = entitycell.pay_time;
  1904. }
  1905. if (shopId == 94)
  1906. {
  1907. entitycell.OrderState = 4;
  1908. entitycell.WaitDesignTime = entitycell.pay_time;
  1909. entitycell.StartDesignTime = entitycell.pay_time;
  1910. entitycell.DesignUserId = 218;
  1911. }
  1912. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114 && shopId != 158))
  1913. {
  1914. entitycell.OrderState = -1;//修改12-5
  1915. CeWithdraw ceWithdraw = new CeWithdraw();
  1916. ceWithdraw.tid = entity.tid;
  1917. ceWithdraw.providerid = "-1";
  1918. ceWithdraw.status = -1;
  1919. ceWithdraw.creationtime = DateTime.Now;
  1920. ceWithdraw.userid = 4634;
  1921. ceWithdraw.Create();
  1922. }
  1923. entitycell.Create();
  1924. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1925. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1926. {
  1927. addPlaceRegist(entitycell, CurrentUser.UserID);
  1928. }
  1929. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1930. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1931. return;
  1932. }
  1933. }
  1934. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1935. {
  1936. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1937. entity.PlactTime = tradecell.pay_time;
  1938. entity.AddUserId = userid;
  1939. entity.FileName = tradecell.seller_memo;
  1940. entity.Supplier = 24;
  1941. entity.CreateTime = DateTime.Now;
  1942. entity.Did = tradecell.ctid;
  1943. entity.tid = tradecell.tid;
  1944. entity.splitTag = tradecell.SplitTag;
  1945. entity.CurState = "未完成";
  1946. entity.Create();
  1947. }
  1948. public void get_erp_offlinelist()
  1949. {
  1950. DataStruct dStruct = GetPostStruct();
  1951. List<string> lw = new List<string>();
  1952. string tid = GetPostString("ctid");
  1953. string date1 = GetPostString("date1");
  1954. string date2 = GetPostString("date2");
  1955. if (tid.Length > 0 || date1.Length > 0)
  1956. {
  1957. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1958. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1959. if (dw.Length > 0) lw.Add(dw);
  1960. }
  1961. else
  1962. {
  1963. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1964. }
  1965. string shopname = GetPostString("shopname");
  1966. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1967. string buyernick = GetPostString("buyer_nick");
  1968. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1969. string customer = GetPostString("customer");
  1970. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1971. string design = GetPostString("design");
  1972. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1973. string orderState = GetPostString("orderState");
  1974. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1975. string address = GetPostString("address");
  1976. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  1977. string sellermemo = GetPostString("seller_memo");
  1978. if (sellermemo.Length > 0)
  1979. {
  1980. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1981. }
  1982. string price1 = GetPostString("price1");
  1983. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1984. string price2 = GetPostString("price2");
  1985. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1986. //if (PKey != "admin")
  1987. //{
  1988. // string usershop = CurrentUser.User.pemShop;
  1989. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1990. //}
  1991. //if (ex_psize > 0)
  1992. //{
  1993. dStruct.Order = "pay_time desc";
  1994. //}
  1995. //else
  1996. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1997. lw.Add(string.Format("IsOffLineOrder=1"));
  1998. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1999. DataTable dt = null;
  2000. dt = WebCache.GetData("view_erptradecell", dStruct);
  2001. writeGridDataTableJson(dStruct.TotalCount, dt);
  2002. }
  2003. public void get_erp_returncashrecord()
  2004. {
  2005. DataStruct dStruct = GetPostStruct();
  2006. List<string> lw = new List<string>();
  2007. string tid = GetPostString("ctid");
  2008. if (tid.Length > 0)
  2009. {
  2010. lw.Add(string.Format("tid like '%{0}%'", tid));
  2011. dStruct.Order = "id desc";
  2012. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2013. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  2014. //writeGridDataTableJson(dStruct.TotalCount, dt);
  2015. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2016. return;
  2017. }
  2018. returnErrorMsg("id数据错误!");
  2019. }
  2020. public void ins_erp_returncashrecord()
  2021. {
  2022. if (UrlPostParmsCheck("tid"))
  2023. {
  2024. string tid = GetPostString("tid");
  2025. string retype = GetPostString("type");
  2026. StringBuilder sql = new StringBuilder();
  2027. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  2028. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2029. if (dt.Rows.Count > 0)
  2030. {
  2031. returnErrorMsg("相同返现类型记录已存在");
  2032. return;
  2033. }
  2034. CeErpReturnCash entity = new CeErpReturnCash();
  2035. entity.tid = tid;
  2036. entity.seller_nick = GetPostString("seller_nick");
  2037. string pment = GetPostString("payment");
  2038. if (pment.Length > 0)
  2039. {
  2040. entity.payment = Convert.ToDouble(pment);
  2041. }
  2042. entity.buyer_nick = GetPostString("buyer_nick");
  2043. entity.cashstate = 0;
  2044. entity.rtype = retype;
  2045. string rPrice = GetPostString("returnprice");
  2046. if (rPrice.Length > 0)
  2047. {
  2048. entity.returnprice = Convert.ToDouble(rPrice);
  2049. }
  2050. entity.created = DateTime.Now;
  2051. entity.con = GetPostString("con");
  2052. entity.img = GetPostString("img");
  2053. entity.applyuserid = CurrentUser.UserID;
  2054. entity.Create();
  2055. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  2056. returnSuccessMsg("操作成功!");
  2057. return;
  2058. }
  2059. }
  2060. public void set_erp_predelivery()
  2061. {
  2062. if (UrlPostParmsCheck("ctid"))
  2063. {
  2064. string eid = GetPostString("ctid");
  2065. CeErpTradeCell entity = null;
  2066. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2067. if (entity != null)
  2068. {
  2069. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  2070. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  2071. //{
  2072. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  2073. // return;
  2074. //}
  2075. entity.IsPreDelivery = 1;
  2076. entity.Update();
  2077. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2078. returnSuccessMsg("预发货成功!");
  2079. return;
  2080. //string shop = GetPostString("seller_nick");
  2081. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  2082. //string comName = GetPostString("comName");
  2083. //string comCode = GetPostString("comCode");
  2084. //string outSid = GetPostString("outSid");//运单号
  2085. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  2086. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  2087. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  2088. //string apires = "";
  2089. //if (deliveryType == "虚拟发货")
  2090. //{
  2091. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  2092. //}
  2093. //else
  2094. //{
  2095. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  2096. //}
  2097. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  2098. ////{
  2099. //if (apires.IndexOf("发货成功") != -1)
  2100. //{
  2101. // if (deliveryType != "虚拟发货")
  2102. // {
  2103. // //还要插入快递信息到 快递信息表
  2104. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  2105. // exinfo.tid = eid;
  2106. // exinfo.out_sid = outSid;
  2107. // exinfo.company_code = comCode;
  2108. // exinfo.company_name = comName;
  2109. // exinfo.delivery_memo = deliveryMemo;
  2110. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  2111. // exinfo.deliveryType = deliveryType;
  2112. // exinfo.Create();
  2113. // }
  2114. // returnSuccessMsg("发货成功!");
  2115. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  2116. //}
  2117. //else
  2118. //{
  2119. // returnErrorMsg("淘宝发货失败!!");
  2120. //}
  2121. //return;
  2122. }
  2123. returnErrorMsg("找不到订单记录");
  2124. }
  2125. }
  2126. public void get_erp_unusuallist()
  2127. {
  2128. DataStruct dStruct = GetPostStruct();
  2129. List<string> lw = new List<string>();
  2130. string tid = GetPostString("ctid");
  2131. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  2132. string shopname = GetPostString("shopname");
  2133. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2134. string buyernick = GetPostString("buyer_nick");
  2135. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2136. string ResponsibleMan = GetPostString("responsible");
  2137. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  2138. string date1 = GetPostString("date1");
  2139. string date2 = GetPostString("date2");
  2140. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2141. if (dw.Length > 0) lw.Add(dw);
  2142. string price1 = GetPostString("price1");
  2143. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2144. string price2 = GetPostString("price2");
  2145. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2146. string orderState = GetPostString("orderState");
  2147. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2148. string sellermemo = GetPostString("seller_memo");
  2149. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2150. lw.Add(string.Format("UnusualTag > 0"));
  2151. lw.Add(string.Format("IsRefund<={0}", 1));
  2152. dStruct.Order = "pay_time desc";
  2153. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2154. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2155. writeGridDataTableJson(dStruct.TotalCount, dt);
  2156. }
  2157. public void set_erp_unusualtonomal()
  2158. {
  2159. if (UrlPostParmsCheck("ctid"))
  2160. {
  2161. string eid = GetPostString("ctid");
  2162. CeErpTradeCell entity = null;
  2163. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2164. if (entity != null)
  2165. {
  2166. entity.UnusualTag = -1;
  2167. entity.Update();
  2168. returnSuccessMsg("忽略成功!");
  2169. return;
  2170. }
  2171. returnErrorMsg("找不到记录");
  2172. }
  2173. }
  2174. public void ins_erp_unusualreason()
  2175. {
  2176. if (UrlPostParmsCheck("ctid"))
  2177. {
  2178. string eid = GetPostString("ctid");
  2179. CeErpTradeCell entity = null;
  2180. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2181. if (entity != null)
  2182. {
  2183. entity.MemoOpt = 4;
  2184. entity.UnusualCon = GetPostString("con");
  2185. entity.Update();
  2186. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2187. if (trade != null)
  2188. {
  2189. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2190. }
  2191. //查货是否超时
  2192. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2193. if (ceErpTradeCellExtend == null)
  2194. {
  2195. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2196. ceErpTradeCellExtend.ctid = entity.ctid;
  2197. }
  2198. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2199. {
  2200. ceErpTradeCellExtend.CheckOut += 1;
  2201. }
  2202. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2203. if (ceErpTradeCellExtend.ID > 0)
  2204. {
  2205. ceErpTradeCellExtend.Update();
  2206. }
  2207. else
  2208. {
  2209. ceErpTradeCellExtend.Create();
  2210. }
  2211. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2212. returnSuccessMsg("操作成功!");
  2213. return;
  2214. }
  2215. returnErrorMsg("找不到记录");
  2216. }
  2217. }
  2218. public void upd_erp_sampleorder()
  2219. {
  2220. if (UrlPostParmsCheck("ctid"))
  2221. {
  2222. string eid = GetPostString("ctid");
  2223. string[] eArr = eid.Split(',');
  2224. if (eArr.Length > 1)
  2225. {
  2226. List<string> eLst = new List<string>();
  2227. for (int i = 0; i < eArr.Length; i++)
  2228. {
  2229. eLst.Add("'" + eArr[i] + "'");
  2230. }
  2231. eid = string.Join(",", eLst.ToArray());
  2232. }
  2233. else
  2234. {
  2235. eid = "'" + eid + "'";
  2236. }
  2237. StringBuilder sql = new StringBuilder();
  2238. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2239. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2240. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2241. if (dt.Rows.Count > 0)
  2242. {
  2243. string errmsg = "";
  2244. foreach (DataRow dr in dt.Rows)
  2245. {
  2246. StringBuilder sqlsb = new StringBuilder();
  2247. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2248. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2249. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2250. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2251. //string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2252. /*if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2253. {
  2254. continue;
  2255. }
  2256. else
  2257. {
  2258. string emsg = commonHelper.KeepChinese(apires);
  2259. errmsg += emsg;
  2260. }*/
  2261. }
  2262. if (errmsg.Length > 0)
  2263. {
  2264. returnErrorMsg(errmsg);
  2265. return;
  2266. }
  2267. returnSuccessMsg("操作成功");
  2268. return;
  2269. }
  2270. returnErrorMsg("找不到记录");
  2271. }
  2272. }
  2273. public void upd_erp_transcustomer()
  2274. {
  2275. if (UrlPostParmsCheck("ctid"))
  2276. {
  2277. string eid = GetPostString("ctid");
  2278. int userid = GetPostInt("CustomerUserId");
  2279. CeErpTradeCell entity = null;
  2280. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2281. if (entity != null)
  2282. {
  2283. //string[] mlist = entity.seller_memo.Split('-');
  2284. //string sql = "select * from view_erpuser where id=" + userid;
  2285. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2286. //if (dt != null && dt.Rows.Count > 0)
  2287. //{
  2288. // string nmemo = "";
  2289. // for(int i = 0; i < mlist.Length - 1; i++)
  2290. // {
  2291. // nmemo += mlist[i];
  2292. // nmemo += "-";
  2293. // }
  2294. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2295. // entity.seller_memo = nmemo;
  2296. //}
  2297. entity.CustomerUserId = userid;
  2298. entity.Update();
  2299. returnSuccessMsg("操作成功!");
  2300. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2301. return;
  2302. }
  2303. returnErrorMsg("找不到记录");
  2304. }
  2305. }
  2306. public void upd_erp_transdesigner()
  2307. {
  2308. if (UrlPostParmsCheck("ctid"))
  2309. {
  2310. string eids = GetPostString("ctid");
  2311. string[] ctidList = eids.Split(',');
  2312. int userid = GetPostInt("DesignUserId");
  2313. foreach (string ctid in ctidList)
  2314. {
  2315. CeErpTradeCell entity = null;
  2316. CeErpDesignerBill entitys = null;
  2317. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2318. entitys = CeErpDesignerBill.GetByTid(ctid);
  2319. if (entity != null)
  2320. {
  2321. if (entity.OrderState > 4)
  2322. {
  2323. continue;
  2324. }
  2325. //存在退款不能流转
  2326. if (entity.IsRefund > 0)
  2327. {
  2328. continue;
  2329. }
  2330. entity.DesignUserId = userid;
  2331. entity.WaitDesignTime = DateTime.Now;
  2332. entity.Update();
  2333. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2334. }
  2335. }
  2336. returnSuccessMsg("操作成功!");
  2337. }
  2338. }
  2339. public void upd_erp_distributedesigner()
  2340. {
  2341. if (UrlPostParmsCheck("ctid"))
  2342. {
  2343. string eid = GetPostString("ctid");
  2344. int userid = GetPostInt("DesignUserId");
  2345. string[] idlist = eid.Split(',');
  2346. if (idlist.Length <= 0)
  2347. {
  2348. returnErrorMsg("订单不能为空");
  2349. return;
  2350. }
  2351. foreach (string ctid in idlist)
  2352. {
  2353. CeErpTradeCell entity = null;
  2354. CeErpDesignerBill entitys = null;
  2355. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2356. else continue;
  2357. if (entity != null)
  2358. {
  2359. if (userid == 2125 || userid == 3542)
  2360. { }
  2361. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2362. {
  2363. returnErrorMsg("金额错误的订单无法指派");
  2364. return;
  2365. }
  2366. if (entity.OrderState >= 5)
  2367. {
  2368. returnErrorMsg("已经设计完成无法指派");
  2369. return;
  2370. }
  2371. if (entity.OrderState == -1)
  2372. {
  2373. returnErrorMsg("审核中的订单无法指派");
  2374. return;
  2375. }
  2376. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2377. {
  2378. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2379. return;
  2380. }
  2381. //157赖橙帆 159林晨 73 静之颖
  2382. if (entity.OrderState > 3 && entity.DispatchSort == 2 && userid != 3542 && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Summarize" && CurrentUser.UserID != 157 && CurrentUser.UserID != 159 && CurrentUser.UserID != 1479 && CurrentUser.UserID != 73)
  2383. {
  2384. returnErrorMsg("指派设计共创无法再次指派!");
  2385. return;
  2386. }
  2387. entity.OrderState = 3;
  2388. if (entity.SupplierId == 0)
  2389. {
  2390. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2391. entity.SupplierId = suid;
  2392. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2393. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2394. }
  2395. if (userid == 2125 && entity.seller_memo != "")
  2396. {
  2397. //apiDesign.API_GetPrintData_CreateOrder(entity);
  2398. }
  2399. List<int> shopIds = new List<int>() { 17, 21, 52, 54, 64, 63, 66, 49, 67, 105, 35, 57, 53, 65, 87, 140, 26, 45, 2, 77, 122, 121, 153, 154, 158 };
  2400. if (userid == 3542 && entity.seller_memo != "")
  2401. {
  2402. string userPost = CurrentUser.UserPost.Post.Code;
  2403. if (CurrentUser.UserID == 4516 || CurrentUser.UserID == 73 || shopIds.Contains(entity.ShopId))
  2404. {
  2405. userPost = "SysAdmin";
  2406. }
  2407. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2408. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2409. if (response.msg != "设计共创:成功")
  2410. {
  2411. returnErrorMsg(response.msg);
  2412. return;
  2413. }
  2414. entity.DispatchSort = 2;
  2415. }
  2416. else
  2417. {
  2418. if (entity.DispatchSort == 2)
  2419. {
  2420. ApiVo apiVo = new ApiVo();
  2421. apiVo.actionName = "closeDesign";
  2422. apiVo.orderNumber = entity.ctid;
  2423. designHelper.API_WorkCore(apiVo);//closeDesign
  2424. }
  2425. entity.DispatchSort = 0;
  2426. }
  2427. entity.DesignUserId = userid;
  2428. entity.WaitDesignTime = DateTime.Now;
  2429. entity.UpdateTime = DateTime.Now;
  2430. entity.Update();
  2431. string name = commonHelper.getUserNameById(userid);
  2432. commonHelper.UpdateRelationOrder(entity.ctid);
  2433. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2434. }
  2435. }
  2436. returnSuccessMsg("操作成功!");
  2437. return;
  2438. }
  2439. }
  2440. public string getTidByCtid(string ctid)
  2441. {
  2442. string tid = "";
  2443. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2444. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2445. if (dataTable != null && dataTable.Rows.Count > 0)
  2446. {
  2447. tid = dataTable.Rows[0]["tid"].ToString();
  2448. }
  2449. return tid;
  2450. }
  2451. public List<string> getTidByCtidMore(string ctid)
  2452. {
  2453. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or tid = '{0}' or orderSn = '{0}' or ( ParentSplitNo = '{0}' and IsSample =2) or (ptid = '{0}' and IsSample =2 ))", ctid);
  2454. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2455. List<string> list = new List<string>();
  2456. if (dataTable != null && dataTable.Rows.Count > 0)
  2457. {
  2458. foreach (DataRow item in dataTable.Rows)
  2459. {
  2460. list.Add("'" + item["tid"].ToString() + "'");
  2461. }
  2462. }
  2463. return list;
  2464. }
  2465. public List<string> getTidByCtidLike(string ctid)
  2466. {
  2467. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2468. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2469. List<string> list = new List<string>();
  2470. if (dataTable != null && dataTable.Rows.Count > 0)
  2471. {
  2472. foreach (DataRow item in dataTable.Rows)
  2473. {
  2474. list.Add("'" + item["tid"].ToString() + "'");
  2475. }
  2476. }
  2477. return list;
  2478. }
  2479. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2480. {
  2481. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2482. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2483. List<string> list = new List<string>();
  2484. if (dataTable != null && dataTable.Rows.Count > 0)
  2485. {
  2486. foreach (DataRow item in dataTable.Rows)
  2487. {
  2488. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2489. {
  2490. continue;
  2491. }
  2492. list.Add("'" + item["receiverId"].ToString() + "'");
  2493. }
  2494. }
  2495. return list;
  2496. }
  2497. public void get_erp_myorderlist()
  2498. {
  2499. DataStruct dStruct = GetPostStruct();
  2500. List<string> lw = new List<string>();
  2501. string tid = GetPostString("ctid");
  2502. if (tid.Length > 0)
  2503. {
  2504. string select_tid = getTidByCtid(tid);
  2505. lw.Add(string.Format("tid='{0}'", select_tid));
  2506. }
  2507. else
  2508. {
  2509. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2510. }
  2511. //12-1 修改
  2512. string urgent = GetPostString("urgent");
  2513. string back = GetPostString("back");
  2514. string offlineSearch = GetPostString("offlineSearch");
  2515. if (!string.IsNullOrWhiteSpace(urgent))
  2516. {
  2517. if (urgent.Equals("true"))
  2518. {
  2519. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2520. }
  2521. }
  2522. if (!string.IsNullOrWhiteSpace(back))
  2523. {
  2524. if (back.Equals("true"))
  2525. {
  2526. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2527. }
  2528. }
  2529. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2530. {
  2531. if (offlineSearch.Equals("true"))
  2532. {
  2533. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2534. }
  2535. }
  2536. //end
  2537. string shopname = GetPostString("shopname");
  2538. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2539. string buyernick = GetPostString("buyer_nick");
  2540. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2541. string design = GetPostString("design");
  2542. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2543. string orderState = GetPostString("orderState");
  2544. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2545. string sellermemo = GetPostString("seller_memo");
  2546. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2547. string date1 = GetPostString("date1");
  2548. string date2 = GetPostString("date2");
  2549. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2550. if (dw.Length > 0) lw.Add(dw);
  2551. string price1 = GetPostString("price1");
  2552. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2553. string price2 = GetPostString("price2");
  2554. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2555. string urgency = GetPostString("urgency");
  2556. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2557. string after = GetPostString("after");
  2558. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2559. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2560. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2561. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2562. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2563. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2564. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2565. if (dt != null && dt.Rows.Count > 0)
  2566. {
  2567. foreach (DataRow dr in dt.Rows)
  2568. {
  2569. try
  2570. {
  2571. // 对象操作
  2572. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2573. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2574. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2575. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2576. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2577. if (dStruct.PageSize != 100000)
  2578. {
  2579. if (dr["DispatchSort"].ToString() == "2")
  2580. {
  2581. dr["gongchuang"] = 200;
  2582. }
  2583. else if ("外协".Equals(dr["ToType"].ToString()))
  2584. {
  2585. dr["gongchuang"] = 200;
  2586. }
  2587. else if ("内部".Equals(dr["ToType"].ToString()))
  2588. {
  2589. dr["gongchuang"] = -1;
  2590. }
  2591. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2592. {
  2593. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2594. dr["gongchuang"] = response.code;
  2595. }
  2596. }
  2597. }
  2598. catch (NullReferenceException ex)
  2599. {
  2600. }
  2601. }
  2602. }
  2603. writeGridDataTableJson(dStruct.TotalCount, dt);
  2604. }
  2605. public void get_erp_myreturnorderlist()
  2606. {
  2607. DataStruct dStruct = GetPostStruct();
  2608. List<string> lw = new List<string>();
  2609. string tid = GetPostString("ctid");
  2610. if (tid.Length > 0)
  2611. {
  2612. string select_tid = getTidByCtid(tid);
  2613. lw.Add(string.Format("tid='{0}'", select_tid));
  2614. }
  2615. else
  2616. {
  2617. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2618. }
  2619. string shopname = GetPostString("shopname");
  2620. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2621. string buyernick = GetPostString("buyer_nick");
  2622. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2623. string design = GetPostString("design");
  2624. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2625. string orderState = GetPostString("orderState");
  2626. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2627. string sellermemo = GetPostString("seller_memo");
  2628. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2629. string date1 = GetPostString("date1");
  2630. string date2 = GetPostString("date2");
  2631. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2632. if (dw.Length > 0) lw.Add(dw);
  2633. string price1 = GetPostString("price1");
  2634. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2635. string price2 = GetPostString("price2");
  2636. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2637. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2638. {
  2639. lw.Add(string.Format("CusOrgID = 94"));
  2640. }
  2641. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2642. {
  2643. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2644. }
  2645. else
  2646. {
  2647. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2648. }
  2649. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2650. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2651. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2652. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2653. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2654. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2655. if (dt != null && dt.Rows.Count > 0)
  2656. {
  2657. foreach (DataRow dr in dt.Rows)
  2658. {
  2659. try
  2660. {
  2661. // 对象操作
  2662. if (dStruct.PageSize != 100000)
  2663. {
  2664. if (dr["DispatchSort"].ToString() == "2")
  2665. {
  2666. dr["gongchuang"] = 200;
  2667. }
  2668. else if ("外协".Equals(dr["ToType"].ToString()))
  2669. {
  2670. dr["gongchuang"] = 200;
  2671. }
  2672. else if ("内部".Equals(dr["ToType"].ToString()))
  2673. {
  2674. dr["gongchuang"] = -1;
  2675. }
  2676. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2677. {
  2678. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2679. dr["gongchuang"] = response.code;
  2680. }
  2681. }
  2682. }
  2683. catch (NullReferenceException ex)
  2684. {
  2685. // 处理空引用异常
  2686. }
  2687. }
  2688. }
  2689. writeGridDataTableJson(dStruct.TotalCount, dt);
  2690. }
  2691. public void get_erp_myorderlist_pregather()
  2692. {
  2693. string date1 = GetPostString("date1");
  2694. string date2 = GetPostString("date2");
  2695. int userId = CurrentUser.UserID; //客服id
  2696. string orderWhere = "";
  2697. List<string> lw = new List<string>();
  2698. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2699. if (dw.Length > 0) lw.Add(dw);
  2700. lw.Add(string.Format("CustomerUserId={0}", userId));
  2701. lw.Add(string.Format("OrderState<9"));
  2702. orderWhere = string.Join(" and ", lw.ToArray());
  2703. string orderWhere2 = "";
  2704. List<string> lw2 = new List<string>();
  2705. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2706. if (dw2.Length > 0) lw2.Add(dw2);
  2707. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2708. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2709. string sql = string.Format("select *" +
  2710. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2711. "left join(select CustomerUserId, count(ctid) as dCount from View_ErpTradeCell where OrderState = 6 and " + orderWhere2 + " group by CustomerUserId) b on a.CustomerUserId = b.CustomerUserId " +
  2712. "left join(select CustomerUserId, count(ctid) as jCount from View_ErpTradeCell where IsUrgency = 1 and " + orderWhere + " group by CustomerUserId) c on a.CustomerUserId = c.CustomerUserId " +
  2713. "left join(select CustomerUserId, count(ctid) as sCount from View_ErpTradeCell where AfterSaleState > 0 and CHARINDEX(','+CONVERT(varchar," + userId + ")+'_k,',','+ResponsibleUserId+',')>0 and " + orderWhere + " group by CustomerUserId) d on a.CustomerUserId = d.CustomerUserId");
  2714. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2715. //writeGridDataTableJson(dt.Rows.Count, dt);
  2716. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2717. }
  2718. public void upd_erp_publishorder()
  2719. {
  2720. if (UrlPostParmsCheck("ctid"))
  2721. {
  2722. string eid = GetPostString("ctid");
  2723. CeErpTradeCell entity = null;
  2724. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2725. if (entity != null)
  2726. {
  2727. entity.OrderState = 0; //发布后,变为待抢单
  2728. entity.Update();
  2729. commonHelper.UpdateRelationOrder(entity.ctid);
  2730. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2731. returnSuccessMsg("发布成功!");
  2732. return;
  2733. }
  2734. returnErrorMsg("找不到记录");
  2735. }
  2736. }
  2737. public void get_erp_my_tiporder()
  2738. {
  2739. StringBuilder sql = new StringBuilder();
  2740. int userId = 0;
  2741. if (CurrentUser != null) userId = CurrentUser.UserID;
  2742. string posCode = CurrentUser.UserPost.Post.Code;
  2743. string isTipedAfterSaleVerify = GetPostString("af");
  2744. DataTable dt = new DataTable();
  2745. if (posCode != "Supplier")
  2746. {
  2747. if (posCode == "CustomerService" || posCode == "Director")
  2748. {
  2749. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2750. }
  2751. else if (posCode == "Place" || posCode == "PlaceMr")
  2752. {
  2753. }
  2754. else
  2755. {
  2756. string teamIds = CurrentUser.User.TeamIds;
  2757. if (teamIds == "")
  2758. {
  2759. teamIds = "0";
  2760. }
  2761. sql.AppendFormat("select * from ce_erptradecell where (DesignUserId={0} or DesignUserId in (select ID from view_erpuser where OnDuty=0 and ID in ({1}))) and OrderState in (3,4) and IsReadTag>0 ", userId, teamIds);
  2762. }
  2763. if (sql.Length > 0)
  2764. {
  2765. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2766. }
  2767. }
  2768. if (dt.Rows.Count <= 0)
  2769. {
  2770. string key = "aftersale_order_" + userId;
  2771. if (RedisHelper.HasKey(key))
  2772. {
  2773. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2774. dt.Columns.Add("ctid", typeof(string));
  2775. dt.Columns.Add("IsReadTag", typeof(int));
  2776. foreach (var i in list)
  2777. {
  2778. DataRow data = dt.NewRow();
  2779. data["ctid"] = i;
  2780. data["IsReadTag"] = 4;
  2781. dt.Rows.Add(data);
  2782. }
  2783. RedisHelper.StringDelete(key);
  2784. }
  2785. }
  2786. if (dt.Rows.Count <= 0)
  2787. {
  2788. sql = new StringBuilder();
  2789. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2790. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2791. }
  2792. if (posCode == "Supplier")
  2793. {
  2794. string ids = CurrentUser.User.pemVend;
  2795. if (ids != null && ids.Length > 0)
  2796. {
  2797. string[] ids_list = ids.Split(',');
  2798. foreach (var item in ids_list)
  2799. {
  2800. string key = "return_order_" + item;
  2801. if (RedisHelper.HasKey(key))
  2802. {
  2803. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2804. dt.Columns.Add("ctid", typeof(string));
  2805. dt.Columns.Add("IsReadTag", typeof(int));
  2806. foreach (var i in list)
  2807. {
  2808. DataRow data = dt.NewRow();
  2809. data["ctid"] = i;
  2810. data["IsReadTag"] = 1;
  2811. dt.Rows.Add(data);
  2812. }
  2813. RedisHelper.StringDelete(key);
  2814. }
  2815. }
  2816. }
  2817. if (dt.Rows.Count <= 0)
  2818. {
  2819. sql = new StringBuilder();
  2820. sql.AppendFormat("select MemoOpt,SupplierId,ctid from ce_erptradecell where SupplierId in ({0}) and MemoOpt=3 and DATEDIFF(MINUTE,CheckOrderTime,GETDATE())<=3", CurrentUser.User.pemVend);
  2821. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2822. }
  2823. }
  2824. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2825. }
  2826. public void reset_erp_tiporder()
  2827. {
  2828. string ids = GetPostString("ids");
  2829. string[] ctidList = ids.Split(',');
  2830. foreach (string ctid in ctidList)
  2831. {
  2832. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2833. if (enty != null)
  2834. {
  2835. enty.IsReadTag = 0;
  2836. enty.Update();
  2837. }
  2838. }
  2839. returnSuccessMsg("成功!");
  2840. return;
  2841. }
  2842. public void get_erp_designlist()
  2843. {
  2844. DataStruct dStruct = GetPostStruct();
  2845. List<string> lw = new List<string>();
  2846. string tid = GetPostString("ctid");
  2847. if (tid.Length > 0)
  2848. {
  2849. string select_tid = getTidByCtid(tid);
  2850. lw.Add(string.Format("tid='{0}'", select_tid));
  2851. }
  2852. string shopname = GetPostString("shopname");
  2853. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2854. string buyernick = GetPostString("buyer_nick");
  2855. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2856. string customer = GetPostString("customer");
  2857. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2858. string design = GetPostString("design");
  2859. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2860. string orderState = GetPostString("orderState");
  2861. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2862. lw.Add(string.Format("OrderState<6"));
  2863. string address = GetPostString("address");
  2864. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2865. string sellermemo = GetPostString("seller_memo");
  2866. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2867. string date1 = GetPostString("date1");
  2868. string date2 = GetPostString("date2");
  2869. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2870. if (dw.Length > 0) lw.Add(dw);
  2871. string apdate1 = GetPostString("apdate1");
  2872. string apdate2 = GetPostString("apdate2");
  2873. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2874. if (dwap.Length > 0) lw.Add(dwap);
  2875. string price1 = GetPostString("price1");
  2876. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2877. string price2 = GetPostString("price2");
  2878. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2879. string designTime = GetPostString("designtime");
  2880. if (designTime.Length > 0)
  2881. {
  2882. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2883. }
  2884. string usershop = CurrentUser.User.pemShop;
  2885. if (usershop.Length > 0)
  2886. {
  2887. lw.Add(string.Format("shopId in ({0})", usershop));
  2888. }
  2889. int myOrgid = CurrentUser.UserPost.OrgID;
  2890. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2891. if (myOrgCode.IndexOf("Designer") != -1)
  2892. {
  2893. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2894. {
  2895. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2896. }
  2897. else
  2898. {
  2899. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2900. }
  2901. }
  2902. else
  2903. {
  2904. string orgId = GetPostString("designerhd");
  2905. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2906. }
  2907. if (tid.Length > 0 || buyernick.Length > 0)
  2908. {
  2909. lw.Add(string.Format("OrderState >= 3"));
  2910. }
  2911. else
  2912. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2913. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2914. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2915. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2916. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2917. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2918. if (dt != null && dt.Rows.Count > 0)
  2919. {
  2920. foreach (DataRow dr in dt.Rows)
  2921. {
  2922. try
  2923. {
  2924. // 对象操作
  2925. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2926. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2927. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2928. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2929. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2930. if (dStruct.PageSize != 100000)
  2931. {
  2932. if (dr["DispatchSort"].ToString() == "2")
  2933. {
  2934. dr["gongchuang"] = 200;
  2935. }
  2936. else if ("外协".Equals(dr["ToType"].ToString()))
  2937. {
  2938. dr["gongchuang"] = 200;
  2939. }
  2940. else if ("内部".Equals(dr["ToType"].ToString()))
  2941. {
  2942. dr["gongchuang"] = -1;
  2943. }
  2944. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2945. {
  2946. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2947. dr["gongchuang"] = response.code;
  2948. }
  2949. }
  2950. }
  2951. catch (NullReferenceException ex)
  2952. {
  2953. }
  2954. }
  2955. }
  2956. writeGridDataTableJson(dStruct.TotalCount, dt);
  2957. }
  2958. public void get_erp_mydesignlist()
  2959. {
  2960. DataStruct dStruct = GetPostStruct();
  2961. List<string> lw = new List<string>();
  2962. string tid = GetPostString("ctid");
  2963. if (tid.Length > 0)
  2964. {
  2965. string select_tid = getTidByCtid(tid);
  2966. lw.Add(string.Format("tid='{0}'", select_tid));
  2967. }
  2968. string shopname = GetPostString("shopname");
  2969. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2970. string buyernick = GetPostString("buyer_nick");
  2971. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2972. string customer = GetPostString("customer");
  2973. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2974. string orderState = GetPostString("orderState");
  2975. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2976. //lw.Add(string.Format("OrderState<6"));
  2977. string date1 = GetPostString("date1");
  2978. string date2 = GetPostString("date2");
  2979. string dw = GetDateWhere("pay_time", date1, date2);
  2980. if (dw.Length > 0) lw.Add(dw);
  2981. string apdate1 = GetPostString("apdate1");
  2982. string apdate2 = GetPostString("apdate2");
  2983. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2984. if (dwap.Length > 0) lw.Add(dwap);
  2985. string price1 = GetPostString("price1");
  2986. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2987. string price2 = GetPostString("price2");
  2988. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2989. string olddownload = GetPostString("olddown");
  2990. if (olddownload == "1")
  2991. {
  2992. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2993. }
  2994. else if (olddownload == "2")
  2995. {
  2996. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2997. }
  2998. string sellermemo = GetPostString("seller_memo");
  2999. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3000. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  3001. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  3002. {
  3003. if (CurrentUser.User.TeamIds.Length > 0)
  3004. {
  3005. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  3006. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3007. else
  3008. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  3009. }
  3010. else
  3011. {
  3012. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  3013. }
  3014. }
  3015. if (tid.Length <= 0)
  3016. {
  3017. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  3018. }
  3019. lw.Add(string.Format("IsReturn!=3"));
  3020. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  3021. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3022. string teamids = CurrentUser.User.TeamIds.ToString();
  3023. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3024. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  3025. if (dt != null && dt.Rows.Count > 0)
  3026. {
  3027. foreach (DataRow dr in dt.Rows)
  3028. {
  3029. try
  3030. {
  3031. // 对象操作
  3032. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  3033. ceErpTradeCell.ctid = dr["ctid"].ToString();
  3034. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  3035. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  3036. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  3037. if (dStruct.PageSize != 100000)
  3038. {
  3039. if (dr["DispatchSort"].ToString() == "2")
  3040. {
  3041. dr["gongchuang"] = 200;
  3042. }
  3043. else if ("外协".Equals(dr["ToType"].ToString()))
  3044. {
  3045. dr["gongchuang"] = 200;
  3046. }
  3047. else if ("内部".Equals(dr["ToType"].ToString()))
  3048. {
  3049. dr["gongchuang"] = -1;
  3050. }
  3051. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  3052. {
  3053. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  3054. dr["gongchuang"] = response.code;
  3055. }
  3056. }
  3057. }
  3058. catch (NullReferenceException ex)
  3059. {
  3060. }
  3061. }
  3062. }
  3063. writeGridDataTableJson(dStruct.TotalCount, dt);
  3064. }
  3065. public void set_erp_startdesign()
  3066. {
  3067. if (UrlPostParmsCheck("ctid"))
  3068. {
  3069. string eid = GetPostString("ctid");
  3070. CeErpTradeCell entity = null;
  3071. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3072. if (entity != null)
  3073. {
  3074. if (entity.OrderState != 3)
  3075. {
  3076. returnErrorMsg("请刷新,订单已经设计了");
  3077. return;
  3078. }
  3079. entity.StartDesignTime = DateTime.Now;
  3080. entity.OrderState = 4;
  3081. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  3082. {
  3083. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3084. entity.SupplierId = suid;
  3085. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3086. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3087. }
  3088. entity.UpdateTime = DateTime.Now;
  3089. //entity.MakeSupplier = suname;
  3090. entity.Update();
  3091. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3092. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3093. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  3094. commonHelper.getCytPrice(entity);
  3095. returnSuccessMsg("操作成功!");
  3096. return;
  3097. }
  3098. returnErrorMsg("找不到记录");
  3099. }
  3100. }
  3101. public void ins_erp_designselfmemo()
  3102. {
  3103. if (UrlPostParmsCheck("ctid"))
  3104. {
  3105. string eid = GetPostString("ctid");
  3106. string con = GetPostString("con");
  3107. CeErpTradeCell entity = null;
  3108. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3109. if (entity != null)
  3110. {
  3111. entity.DesignSelfMemo = con;
  3112. entity.Update();
  3113. returnSuccessMsg("操作成功!");
  3114. return;
  3115. }
  3116. returnErrorMsg("找不到记录");
  3117. }
  3118. }
  3119. public void ins_erp_designprice()
  3120. {
  3121. if (UrlPostParmsCheck("ctid"))
  3122. {
  3123. string eid = GetPostString("ctid");
  3124. int uid = CurrentUser.UserID;
  3125. string userName = CurrentUser.UserName;
  3126. CeErpTradeCell entity = null;
  3127. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  3128. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3129. if (entitys == null)
  3130. {
  3131. entitys = new CeErpDesignerBill();
  3132. }
  3133. if (entity != null)
  3134. {
  3135. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  3136. //entity.Number = Convert.ToInt32(GetPostString("number"));
  3137. entity.StartDesignTime = DateTime.Now;
  3138. entity.OrderState = 4;
  3139. string suname = "";
  3140. if (entity.SupplierId == 0)
  3141. {
  3142. int sid = commonHelper.autoDistributeToSupplier(entity);
  3143. entity.SupplierId = sid;
  3144. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3145. }
  3146. entity.Update();
  3147. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3148. if (ceErpUserPost != null)
  3149. {
  3150. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3151. if (ceErpPost != null)
  3152. {
  3153. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3154. {
  3155. entitys.tid = entity.ctid;
  3156. entitys.oid = entity.tid;
  3157. entitys.uid = uid;
  3158. entitys.userName = userName;
  3159. entitys.designerType = 1;
  3160. entitys.designerTypeText = "内部设计师";
  3161. entitys.price = Convert.ToDouble(GetPostString("price"));
  3162. entitys.designNum = GetPostInt("designNum");
  3163. entitys.modifyNum = GetPostInt("modifyNum");
  3164. entitys.designSize = GetPostString("designSize");
  3165. entitys.modifySize = GetPostString("modifySize");
  3166. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3167. {
  3168. entitys.create_time = DateTime.Now;
  3169. entitys.create_u_id = uid;
  3170. entitys.create_u_name = userName;
  3171. entitys.Save();
  3172. }
  3173. else
  3174. {
  3175. entitys.update_time = DateTime.Now;
  3176. entitys.update_u_id = uid;
  3177. entitys.update_u_name = userName;
  3178. entitys.Update();
  3179. }
  3180. }
  3181. }
  3182. }
  3183. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3184. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3185. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3186. if (suname != "")
  3187. {
  3188. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3189. }
  3190. commonHelper.getCytPrice(entity);
  3191. returnSuccessMsg("操作成功!");
  3192. return;
  3193. }
  3194. returnErrorMsg("找不到记录");
  3195. }
  3196. }
  3197. public void upload_erp_filecomplete()
  3198. {
  3199. if (UrlPostParmsCheck("ctid"))
  3200. {
  3201. string eid = GetPostString("ctid");
  3202. CeErpTradeCell entity = null;
  3203. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3204. if (entity != null)
  3205. {
  3206. entity.OrderState = 5; //设计完成
  3207. entity.Update();
  3208. returnSuccessMsg(eid + "上传成功,设计完成!");
  3209. return;
  3210. }
  3211. returnErrorMsg("找不到订单记录");
  3212. }
  3213. }
  3214. public void get_erp_designovertimelist()
  3215. {
  3216. DataStruct dStruct = GetPostStruct();
  3217. List<string> lw = new List<string>();
  3218. string tid = GetPostString("ctid");
  3219. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3220. string shopname = GetPostString("shopname");
  3221. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3222. string buyernick = GetPostString("buyer_nick");
  3223. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3224. string ResponsibleMan = GetPostString("responsible");
  3225. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3226. string date1 = GetPostString("date1");
  3227. string date2 = GetPostString("date2");
  3228. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3229. if (dw.Length > 0) lw.Add(dw);
  3230. string price1 = GetPostString("price1");
  3231. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3232. string price2 = GetPostString("price2");
  3233. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3234. string orderState = GetPostString("orderState");
  3235. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3236. string sellermemo = GetPostString("seller_memo");
  3237. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3238. lw.Add(string.Format("UnusualTag=3"));
  3239. lw.Add(string.Format("IsRefund<={0}", 1));
  3240. dStruct.Order = "WaitDesignTime desc";
  3241. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3242. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3243. writeGridDataTableJson(dStruct.TotalCount, dt);
  3244. }
  3245. //设计管理 获取抢单大厅列表
  3246. public void get_erp_grabinglist()
  3247. {
  3248. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3249. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3250. bool oldOrder = false;
  3251. if (org != null)
  3252. {
  3253. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3254. }
  3255. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3256. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3257. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3258. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3259. //先处理订单数据
  3260. if (dt.Rows.Count > 0)
  3261. {
  3262. Dictionary<string, int> design = null;
  3263. int count = 0;
  3264. foreach (DataRow row in dt.Rows)
  3265. {
  3266. if (map.ContainsKey(row["ShopId"].ToString()))
  3267. {
  3268. map.TryGetValue(row["ShopId"].ToString(), out design);
  3269. }
  3270. else
  3271. {
  3272. design = new Dictionary<string, int>();
  3273. }
  3274. if (design.ContainsKey(row["ProductId"].ToString()))
  3275. {
  3276. design.TryGetValue(row["ProductId"].ToString(), out count);
  3277. }
  3278. count++;
  3279. design[row["ProductId"].ToString()] = count;
  3280. map[row["ShopId"].ToString()] = design;
  3281. }
  3282. }
  3283. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3284. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3285. //把店铺排序和技能排序分类
  3286. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3287. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3288. if (design_dt.Rows.Count > 0)
  3289. {
  3290. Dictionary<string, string> design = null;
  3291. List<string> shopIds = null;
  3292. foreach (DataRow row in design_dt.Rows)
  3293. {
  3294. if ("0".Equals(row["designId"].ToString()))
  3295. {
  3296. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3297. {
  3298. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3299. }
  3300. else
  3301. {
  3302. shopIds = new List<string>();
  3303. }
  3304. shopIds.Add(row["shopId"].ToString());
  3305. shop_orders[row["orders"].ToString()] = shopIds;
  3306. }
  3307. else
  3308. {
  3309. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3310. {
  3311. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3312. }
  3313. else
  3314. {
  3315. design = new Dictionary<string, string>();
  3316. }
  3317. design[row["orders"].ToString()] = row["designId"].ToString();
  3318. design_orders[row["shopId"].ToString()] = design;
  3319. }
  3320. }
  3321. //处理成key value后根据key排序
  3322. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3323. foreach (List<string> val in shop_orders.Values)
  3324. {
  3325. if (val != null)
  3326. {
  3327. foreach (string key in val)
  3328. {
  3329. if (design_orders.ContainsKey(key.ToString()))
  3330. {
  3331. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3332. }
  3333. }
  3334. }
  3335. }
  3336. }
  3337. //校验哪个优先级有订单
  3338. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3339. foreach (string key in shop_orders.Keys)
  3340. {
  3341. List<string> ids = null;
  3342. shop_orders.TryGetValue(key, out ids);
  3343. //id为shopid
  3344. foreach (string id in ids)
  3345. {
  3346. Dictionary<string, int> list = null;
  3347. Dictionary<string, string> desing = null;
  3348. map.TryGetValue(id, out list);
  3349. design_orders.TryGetValue(id, out desing);
  3350. if (list != null && desing != null)
  3351. {
  3352. foreach (var item in desing)
  3353. {
  3354. int count = 0;
  3355. if (list.ContainsKey(item.Value))
  3356. {
  3357. list.TryGetValue(item.Value, out count);
  3358. if (count > 0)
  3359. {
  3360. designIds[id] = item.Value;
  3361. break;
  3362. }
  3363. }
  3364. }
  3365. }
  3366. }
  3367. if (designIds.Count > 0)
  3368. {
  3369. break;
  3370. }
  3371. }
  3372. DataTable table = new DataTable();
  3373. table.Columns.Add("tid", typeof(string));
  3374. table.Columns.Add("ctid", typeof(string));
  3375. table.Columns.Add("seller_nick", typeof(string));
  3376. table.Columns.Add("productName", typeof(string));
  3377. table.Columns.Add("pay_time", typeof(string));
  3378. table.Columns.Add("seller_memo", typeof(string));
  3379. if (designIds.Count > 0)
  3380. {
  3381. string shopId = "";
  3382. string productId = "";
  3383. foreach (var designInfo in designIds)
  3384. {
  3385. shopId = designInfo.Key;
  3386. productId = designInfo.Value;
  3387. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3388. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3389. if (dt.Rows.Count > 0)
  3390. {
  3391. foreach (DataRow row in dt.Rows)
  3392. {
  3393. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3394. {
  3395. DataRow data = table.NewRow();
  3396. data["ctid"] = row["ctid"].ToString();
  3397. data["tid"] = row["tid"].ToString();
  3398. data["seller_nick"] = ceErpShop.ShopName;
  3399. data["pay_time"] = row["pay_time"].ToString();
  3400. data["seller_memo"] = row["seller_memo"].ToString();
  3401. data["productName"] = ceErpProduct.PType;
  3402. table.Rows.Add(data);
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. writeGridDataTableJson(table.Rows.Count, table);
  3409. }
  3410. private object rushLockObject = new object();
  3411. public void set_erp_grabingorder()
  3412. {
  3413. if (UrlPostParmsCheck("ctid"))
  3414. {
  3415. int total = CurrentUser.User.Person.Total;
  3416. int userId = CurrentUser.User.ID;
  3417. int noFinish = CurrentUser.User.Person.NoFinish;
  3418. int finalization = CurrentUser.User.Person.Finalization;
  3419. string eids = GetPostString("ctid");
  3420. string key = "RushKey_" + userId;
  3421. int count = 0;
  3422. if (erpRedis.RedisHelper.KeyExists(key))
  3423. {
  3424. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3425. if (redisCount != null)
  3426. {
  3427. count = Convert.ToInt32(redisCount);
  3428. }
  3429. }
  3430. if (count >= total)
  3431. {
  3432. returnErrorMsg("半小时内已经抢" + total + "单");
  3433. return;
  3434. }
  3435. string[] ctidlist = eids.Split(',');
  3436. if (count + ctidlist.Length > total)
  3437. {
  3438. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3439. return;
  3440. }
  3441. int itag = 0;
  3442. lock (rushLockObject)
  3443. {
  3444. if (ctidlist.Length > 0)
  3445. {
  3446. string[] dtList = new string[ctidlist.Length];
  3447. for (int i = 0; i < ctidlist.Length; i++)
  3448. {
  3449. dtList[i] = "'" + ctidlist[i] + "'";
  3450. }
  3451. string sql_user = string.Format("select OrderState from CE_ErpTradeCell where DesignUserId = {0} and WaitDesignTime BETWEEN '{1}' and '{2}'", userId, DateTime.Now.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  3452. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3453. if (dt_user.Rows.Count > 0)
  3454. {
  3455. int doing = 0;//未定稿
  3456. int finish = 0;//已完成
  3457. foreach (DataRow dr in dt_user.Rows)
  3458. {
  3459. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3460. {
  3461. doing++;
  3462. }
  3463. else
  3464. {
  3465. finish++;
  3466. }
  3467. }
  3468. if (doing >= noFinish)
  3469. {
  3470. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3471. return;
  3472. }
  3473. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3474. {
  3475. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3476. return;
  3477. }
  3478. }
  3479. //校验选择单子状态
  3480. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3481. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3482. if (dt.Rows.Count > 0)
  3483. {
  3484. List<string> list = new List<string>();
  3485. foreach (DataRow dr in dt.Rows)
  3486. {
  3487. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3488. {
  3489. list.Add(dr["ctid"].ToString());
  3490. }
  3491. }
  3492. if (list.Count > 0)
  3493. {
  3494. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3495. return;
  3496. }
  3497. }
  3498. foreach (string ctid in ctidlist)
  3499. {
  3500. CeErpTradeCell entity = null;
  3501. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3502. if (entity != null)
  3503. {
  3504. entity.OrderState = 3;
  3505. entity.DesignUserId = CurrentUser.UserID;
  3506. entity.WaitDesignTime = DateTime.Now;
  3507. entity.StartDesignTime = DateTime.Now;
  3508. entity.Update();
  3509. commonHelper.UpdateRelationOrder(entity.ctid);
  3510. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3511. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3512. itag++;
  3513. }
  3514. }
  3515. }
  3516. }
  3517. count += ctidlist.Length;
  3518. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3519. if (itag == 0)
  3520. returnErrorMsg("没有找到相关订单");
  3521. else
  3522. returnSuccessMsg("抢单成功!");
  3523. return;
  3524. }
  3525. }
  3526. public void get_erp_waitorderlist()
  3527. {
  3528. DataStruct dStruct = GetPostStruct();
  3529. List<string> lw = new List<string>();
  3530. string tid = GetPostString("ctid");
  3531. if (tid.Length > 0)
  3532. {
  3533. string select_tid = getTidByCtid(tid);
  3534. lw.Add(string.Format("tid='{0}'", select_tid));
  3535. }
  3536. string shopname = GetPostString("shopname");
  3537. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3538. string buyernick = GetPostString("buyer_nick");
  3539. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3540. string customer = GetPostString("customer");
  3541. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3542. string design = GetPostString("design");
  3543. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3544. string orderState = GetPostString("orderState");
  3545. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3546. string supplier = GetPostString("supplier");
  3547. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3548. string sellermemo = GetPostString("seller_memo");
  3549. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3550. string otherMemo = GetPostString("otherMemo");
  3551. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3552. string address = GetPostString("address");
  3553. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  3554. string date1 = GetPostString("date1");
  3555. string date2 = GetPostString("date2");
  3556. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3557. if (dw.Length > 0) lw.Add(dw);
  3558. string price1 = GetPostString("price1");
  3559. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3560. string price2 = GetPostString("price2");
  3561. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3562. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3563. lw.Add(string.Format("IsSample != 2 "));
  3564. lw.Add(string.Format("OrderState = 5 "));
  3565. lw.Add(string.Format("IsRefund<={0}", 1));
  3566. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3567. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3568. string pagesize = GetPostString("pagesize");
  3569. if (pagesize != null)
  3570. {
  3571. dStruct.PageSize = 200;
  3572. }
  3573. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3574. List<string> tids = new List<string>();
  3575. if (dt != null)
  3576. {
  3577. dt.Columns.Add("compenPrice", typeof(double));
  3578. foreach (DataRow dr in dt.Rows)
  3579. {
  3580. if (Convert.IsDBNull(dr["compenPrice"]))
  3581. {
  3582. dr["compenPrice"] = 0;
  3583. }
  3584. tids.Add("'" + dr["tid"].ToString() + "'");
  3585. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3586. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3587. {
  3588. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3589. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3590. entity.SupplierId = suid;
  3591. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3592. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3593. entity.Update();
  3594. }
  3595. }
  3596. }
  3597. if (tids.Count > 0)
  3598. {
  3599. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3600. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3601. if (dt_price != null && dt_price.Rows.Count > 0)
  3602. {
  3603. foreach (DataRow dr in dt_price.Rows)
  3604. {
  3605. foreach (DataRow row in dt.Rows)
  3606. {
  3607. if (row["tid"].Equals(dr["ptid"]))
  3608. {
  3609. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3610. break;
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. writeGridDataTableJson(dStruct.TotalCount, dt);
  3617. }
  3618. public void get_erp_supplierwaitorderlist()
  3619. {
  3620. DataStruct dStruct = GetPostStruct();
  3621. List<string> lw = new List<string>();
  3622. string tid = GetPostString("ctid");
  3623. if (tid.Length > 0)
  3624. {
  3625. string select_tid = getTidByCtid(tid);
  3626. lw.Add(string.Format("tid='{0}'", select_tid));
  3627. }
  3628. string shopname = GetPostString("shopname");
  3629. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3630. string sellermemo = GetPostString("seller_memo");
  3631. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3632. string date1 = GetPostString("date1");
  3633. string date2 = GetPostString("date2");
  3634. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3635. if (dw.Length > 0) lw.Add(dw);
  3636. lw.Add(string.Format("OrderState = 5 "));
  3637. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3638. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3639. {
  3640. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3641. }
  3642. string supplier = GetPostString("supplier");
  3643. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3644. {
  3645. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3646. }
  3647. lw.Add(string.Format("IsRefund<={0}", 1));
  3648. dStruct.Order = "FinishDesignTime desc";
  3649. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3650. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3651. if (dt != null)
  3652. {
  3653. foreach (DataRow dr in dt.Rows)
  3654. {
  3655. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  3656. }
  3657. }
  3658. writeGridDataTableJson(dStruct.TotalCount, dt);
  3659. }
  3660. public void upd_erp_verifytosupplier()
  3661. {
  3662. if (UrlPostParmsCheck("ctid"))
  3663. {
  3664. string eids = GetPostString("ctid");
  3665. CeErpTradeCell entity = null;
  3666. string[] eidsList = eids.Split(',');
  3667. if (eidsList.Length <= 0)
  3668. {
  3669. returnErrorMsg("订单号不能空");
  3670. return;
  3671. }
  3672. List<string> tLst = new List<string>();
  3673. foreach (string ctidstr in eidsList)
  3674. {
  3675. tLst.Add("'" + ctidstr + "'");
  3676. CeErpDataSendOrderInfo.createObject(ctidstr);
  3677. }
  3678. string needtids = string.Join(",", tLst.ToArray());
  3679. StringBuilder sql = new StringBuilder();
  3680. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3681. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 AND OrderState = 5 and ctid in ({0});", needtids, CurrentUser.UserID);
  3682. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3683. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3684. returnSuccessMsg("操作成功!");
  3685. return;
  3686. /**foreach (string ctidstr in eidsList)
  3687. {
  3688. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3689. if (entity != null)
  3690. {
  3691. if (entity.SupplierId == 0)
  3692. {
  3693. continue;
  3694. }
  3695. entity.IsVerifyToSupplier = true;
  3696. if (entity.IsReturn == 1) //1是供应商打回
  3697. {
  3698. entity.IsReturn = 0;
  3699. }
  3700. entity.FinishPlaceTime = DateTime.Now;
  3701. entity.PlaceUserId = CurrentUser.UserID;
  3702. entity.Update();
  3703. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3704. }
  3705. }
  3706. returnSuccessMsg("操作成功!");
  3707. return;**/
  3708. }
  3709. }
  3710. public void upd_erp_supplierback()
  3711. {
  3712. if (UrlPostParmsCheck("ctid"))
  3713. {
  3714. string eid = GetPostString("ctid");
  3715. string reason = GetPostString("returnreason");
  3716. CeErpTradeCell entity = null;
  3717. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3718. if (entity != null)
  3719. {
  3720. string message = "操作成功!";
  3721. string isDown = "";
  3722. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3723. {
  3724. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3725. isDown = "被点击下载";
  3726. }
  3727. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3728. {
  3729. string key = "return_order_" + entity.SupplierId;
  3730. List<string> list = new List<string>();
  3731. if (RedisHelper.HasKey(key))
  3732. {
  3733. object data = RedisHelper.StringGet(key);
  3734. list = Convert.ToString(data).Split(',').ToList();
  3735. }
  3736. list.Add(eid);
  3737. RedisHelper.StringSet(key, string.Join(",", list));
  3738. }
  3739. entity.IsVerifyToSupplier = false;
  3740. entity.IsReturn = 1;
  3741. entity.IsHaveNewOrder = 0;
  3742. entity.ReturnTime = DateTime.Now;
  3743. entity.ReturnReason = reason;
  3744. if (entity.OrderState == 6)
  3745. {
  3746. entity.OrderState = 5;
  3747. }
  3748. entity.Update();
  3749. CeErpSukuraData.createInfo(entity.ctid, 5);
  3750. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason + "-" + isDown, entity.OrderState);
  3751. returnSuccessMsg(message);
  3752. return;
  3753. }
  3754. returnErrorMsg("找不到订单记录");
  3755. }
  3756. }
  3757. public void upd_erp_toaftersaleorder()
  3758. {
  3759. if (UrlPostParmsCheck("ctid"))
  3760. {
  3761. string eid = GetPostString("ctid");
  3762. string reason = GetPostString("returnreason");
  3763. CeErpTradeCell entity = null;
  3764. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3765. if (entity != null)
  3766. {
  3767. if (entity.isAfterSaleOrder != 1)
  3768. {
  3769. returnErrorMsg("带S的售后单才能打回给售后");
  3770. return;
  3771. }
  3772. if (entity.OrderState >= 5)
  3773. {
  3774. returnErrorMsg("已经设计完成了不能打回给售后");
  3775. return;
  3776. }
  3777. entity.OrderState = 0;
  3778. entity.IsReturn = 3;
  3779. entity.ReturnTime = DateTime.Now;
  3780. entity.UpdateTime = DateTime.Now;
  3781. entity.ReturnReason = reason;
  3782. entity.Update();
  3783. CeErpSukuraData.createInfo(entity.ctid, 5);
  3784. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3785. returnSuccessMsg("操作成功!");
  3786. return;
  3787. }
  3788. returnErrorMsg("找不到订单记录");
  3789. }
  3790. }
  3791. public void upd_erp_aftersaletodesign()
  3792. {
  3793. if (UrlPostParmsCheck("ctid"))
  3794. {
  3795. string eid = GetPostString("ctid");
  3796. CeErpTradeCell entity = null;
  3797. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3798. if (entity != null)
  3799. {
  3800. entity.OrderState = 3;
  3801. entity.IsReturn = 0;
  3802. entity.UpdateTime = DateTime.Now;
  3803. entity.Update();
  3804. CeErpSukuraData.createInfo(entity.ctid, 5);
  3805. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3806. returnSuccessMsg("操作成功!");
  3807. return;
  3808. }
  3809. returnErrorMsg("找不到订单记录");
  3810. }
  3811. }
  3812. public void assign_erp_supplier()
  3813. {
  3814. if (UrlPostParmsCheck("ctid"))
  3815. {
  3816. string eids = GetPostString("ctid");
  3817. int sid = GetPostInt("SupplierName");
  3818. string fromTag = GetPostString("tag");
  3819. string[] eidList = eids.Split(',');
  3820. if (eidList.Length <= 0)
  3821. {
  3822. returnErrorMsg("指派不能为空");
  3823. return;
  3824. }
  3825. string errMsg = "";
  3826. string suname = commonHelper.getSupplierNameById(sid);
  3827. foreach (string ctid in eidList)
  3828. {
  3829. CeErpTradeCell entity = null;
  3830. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3831. if (entity != null)
  3832. {
  3833. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3834. {
  3835. errMsg += (ctid + "指派失败!!!");
  3836. continue;
  3837. }
  3838. entity.SupplierId = sid;
  3839. entity.Update();
  3840. commonHelper.UpdateRelationOrder(entity.ctid);
  3841. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3842. if (entity.OrderState >= 6)
  3843. {
  3844. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3845. //{
  3846. // string msl = entity.MakeSupplier;
  3847. // string[] mslist = msl.Split(',');
  3848. // sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={2} where ID in (select top {1} ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, mslist.Length,sid);
  3849. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3850. //}
  3851. //else
  3852. //{
  3853. StringBuilder sql = new StringBuilder();
  3854. sql.AppendFormat("update ce_erptradecell2 with(rowlock) set SupplierId={1},MakeSupplier='{2}' where ID in (select top 1 ID from ce_erptradecell2 where ctid='{0}' order by ID desc)", entity.ctid, sid, entity.MakeSupplier);
  3855. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3856. //}
  3857. }
  3858. }
  3859. else
  3860. {
  3861. continue;
  3862. }
  3863. }
  3864. if (errMsg.Length > 0)
  3865. {
  3866. returnErrorMsg(errMsg);
  3867. return;
  3868. }
  3869. returnSuccessMsg("操作成功!");
  3870. return;
  3871. }
  3872. }
  3873. public void assign_erp_makesupplier()
  3874. {
  3875. if (UrlPostParmsCheck("ctid"))
  3876. {
  3877. string eids = GetPostString("ctid");
  3878. string sname = GetPostString("SupplierName");
  3879. string[] eidList = eids.Split(',');
  3880. if (eidList.Length <= 0)
  3881. {
  3882. returnErrorMsg("指派不能为空");
  3883. return;
  3884. }
  3885. List<string> tLst = new List<string>();
  3886. foreach (string ctid in eidList)
  3887. {
  3888. CeErpTradeCell entity = null;
  3889. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3890. if (entity != null)
  3891. {
  3892. entity.MakeSupplier = sname;
  3893. entity.Update();
  3894. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3895. tLst.Add("'" + ctid + "'");
  3896. }
  3897. else
  3898. {
  3899. continue;
  3900. }
  3901. }
  3902. string ctids = string.Join(",", tLst.ToArray());
  3903. StringBuilder sql2 = new StringBuilder();
  3904. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3905. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3906. returnSuccessMsg("操作成功!");
  3907. return;
  3908. }
  3909. }
  3910. public void ins_erp_returnreason()
  3911. {
  3912. if (UrlPostParmsCheck("ctid"))
  3913. {
  3914. string eid = GetPostString("ctid");
  3915. CeErpTradeCell entity = null;
  3916. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3917. string userpost = CurrentUser.UserPost.Post.Code;
  3918. if (entity != null)
  3919. {
  3920. bool isPlace = false;
  3921. if (entity.OrderState > 6)
  3922. {
  3923. returnErrorMsg("已发货无法打回!");
  3924. return;
  3925. }
  3926. if (entity.OrderState == 6)
  3927. {
  3928. isPlace = true;
  3929. }
  3930. bool isNeedUpdateCell2 = false;
  3931. if (entity.OrderState >= 6)
  3932. {
  3933. isNeedUpdateCell2 = true;
  3934. }
  3935. int returnTag = 2;
  3936. if (userpost == "Supplier")
  3937. {
  3938. returnTag = 1;
  3939. }
  3940. int toType = GetPostInt("totype");
  3941. string fromType = "3";
  3942. if (entity.OrderState < 5)
  3943. {
  3944. fromType = "3";
  3945. }
  3946. else
  3947. {
  3948. fromType = "4";
  3949. }
  3950. if (entity.IsXianHuo == 0)
  3951. {
  3952. if (returnTag == 2)
  3953. {
  3954. if (toType == 1)
  3955. {
  3956. entity.OrderState = 0;
  3957. entity.ReturnUserType = 1;
  3958. string clearman = GetPostString("clearman");
  3959. if (!string.IsNullOrEmpty(clearman))
  3960. {
  3961. entity.DesignUserId = 0;
  3962. }
  3963. }
  3964. else
  3965. {
  3966. entity.OrderState = 3;
  3967. entity.ReturnUserType = 2;
  3968. }
  3969. entity.IsReadTag = 1;
  3970. }
  3971. else if (returnTag == 1)
  3972. {
  3973. entity.OrderState = 5;
  3974. }
  3975. entity.IsVerifyToSupplier = false;
  3976. }
  3977. if (entity.IsXianHuo == 1)
  3978. {
  3979. entity.OrderState = 5;
  3980. }
  3981. entity.UnusualTag = 0;
  3982. entity.UnusualTime = null;
  3983. entity.UnusualCon = "";
  3984. entity.IsReturn = returnTag;
  3985. entity.ReturnTime = DateTime.Now;
  3986. entity.UpdateTime = DateTime.Now;
  3987. entity.ReturnReason = GetPostString("returnreason");
  3988. entity.Update();
  3989. if (entity.OrderState == 3)
  3990. {
  3991. ApiVo apiVo = new ApiVo();
  3992. apiVo.orderNumber = entity.ctid;
  3993. apiVo.actionName = "rebutDesign";
  3994. apiVo.orderRemarks = entity.ReturnReason;
  3995. designHelper.API_WorkCore(apiVo);//rebutDesign
  3996. }
  3997. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3998. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3999. {
  4000. //dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  4001. }
  4002. //CeErpSukuraData.createInfo(entity.ctid, 5);
  4003. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4004. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4005. if (isPlace)
  4006. {
  4007. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  4008. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4009. if (dth != null && dth.Rows.Count > 0)
  4010. {
  4011. dataSendOrderBean dataSendOrderBean = null;
  4012. foreach (DataRow item in dth.Rows)
  4013. {
  4014. try
  4015. {
  4016. dataSendOrderBean = new dataSendOrderBean();
  4017. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  4018. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  4019. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  4020. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  4021. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  4022. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  4023. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  4024. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  4025. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  4026. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  4027. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  4028. dataSendOrderBean.Radio1723534706288 = "打回";
  4029. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  4030. if (result != null)
  4031. {
  4032. if ("0".Equals(result.errcode))
  4033. {
  4034. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  4035. }
  4036. else
  4037. {
  4038. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  4039. }
  4040. }
  4041. }
  4042. catch (Exception ex)
  4043. {
  4044. }
  4045. }
  4046. }
  4047. }
  4048. returnSuccessMsg("操作成功!");
  4049. return;
  4050. }
  4051. returnErrorMsg("找不到订单记录");
  4052. }
  4053. }
  4054. public void cyt_erp_returnreason()
  4055. {
  4056. if (UrlPostParmsCheck("ctid"))
  4057. {
  4058. string eid = GetPostString("ctid");
  4059. CeErpTradeCell entity = null;
  4060. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4061. string userpost = CurrentUser.UserPost.Post.Code;
  4062. if (entity != null)
  4063. {
  4064. if (entity.OrderState > 6)
  4065. {
  4066. returnErrorMsg("已发货无法打回!");
  4067. return;
  4068. }
  4069. JObject jsonObject = new JObject
  4070. {
  4071. { "Userid", "77886" },
  4072. { "Pwd", "lt666888" },
  4073. { "LTOrderId",eid }
  4074. };
  4075. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  4076. JObject jsonObjects = JObject.Parse(response);
  4077. string msg = (string)jsonObjects["msg"];
  4078. if (msg != "取消成功")
  4079. {
  4080. returnErrorMsg(msg);
  4081. return;
  4082. }
  4083. bool isNeedUpdateCell2 = false;
  4084. if (entity.OrderState >= 6)
  4085. {
  4086. isNeedUpdateCell2 = true;
  4087. }
  4088. int returnTag = 2;
  4089. if (userpost == "Supplier")
  4090. {
  4091. returnTag = 1;
  4092. }
  4093. if (entity.IsXianHuo == 0)
  4094. {
  4095. if (returnTag == 2)
  4096. {
  4097. int toType = GetPostInt("totype");
  4098. if (toType == 1)
  4099. {
  4100. entity.OrderState = 0;
  4101. entity.ReturnUserType = 1;
  4102. }
  4103. else
  4104. {
  4105. entity.OrderState = 4;
  4106. entity.ReturnUserType = 2;
  4107. }
  4108. entity.IsReadTag = 1;
  4109. }
  4110. else if (returnTag == 1)
  4111. {
  4112. entity.OrderState = 5;
  4113. }
  4114. entity.IsVerifyToSupplier = false;
  4115. }
  4116. entity.UnusualTag = 0;
  4117. entity.UnusualTime = null;
  4118. entity.UnusualCon = "";
  4119. entity.IsReturn = returnTag;
  4120. entity.ReturnTime = DateTime.Now;
  4121. entity.ReturnReason = GetPostString("returnreason");
  4122. entity.Update();
  4123. if (entity.OrderState == 4)
  4124. {
  4125. ApiVo apiVo = new ApiVo();
  4126. apiVo.orderNumber = entity.ctid;
  4127. apiVo.actionName = "rebutDesign";
  4128. apiVo.orderRemarks = entity.ReturnReason;
  4129. designHelper.API_WorkCore(apiVo);//rebutDesign
  4130. }
  4131. CeErpSukuraData.createInfo(entity.ctid, 5);
  4132. //apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  4133. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  4134. if (isNeedUpdateCell2)
  4135. {
  4136. if (entity.MakeSupplier.IndexOf(",") != -1)
  4137. {
  4138. StringBuilder sql2 = new StringBuilder();
  4139. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 2 ID from ce_erptradecell2 where ctid='{1}' order by ID desc) ", entity.ReturnReason, entity.ctid, returnTag);
  4140. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4141. }
  4142. else
  4143. {
  4144. StringBuilder sql2 = new StringBuilder();
  4145. sql2.AppendFormat("update ce_erptradecell2 WITH(ROWLOCK) set BackState='已打回',ReturnReason='{0}',IsReturn={2} where ID in (select top 1 ID from ce_erptradecell2 where ctid='{1}' order by ID desc)", entity.ReturnReason, entity.ctid, returnTag);
  4146. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4147. }
  4148. }
  4149. returnSuccessMsg("操作成功!");
  4150. return;
  4151. }
  4152. returnErrorMsg("找不到订单记录");
  4153. }
  4154. }
  4155. public void upd_erp_xianhuoreturntag()
  4156. {
  4157. if (UrlPostParmsCheck("ctid"))
  4158. {
  4159. string eids = GetPostString("ctid");
  4160. string[] ctids = eids.Split(',');
  4161. foreach (string ctid in ctids)
  4162. {
  4163. CeErpTradeCell entity = null;
  4164. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4165. if (entity != null)
  4166. {
  4167. entity.IsReturn = 0;
  4168. entity.Update();
  4169. CeErpSukuraData.createInfo(entity.ctid, 5);
  4170. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4171. }
  4172. }
  4173. returnSuccessMsg("操作成功!");
  4174. return;
  4175. }
  4176. }
  4177. public void get_erp_waitdeliverylist()
  4178. {
  4179. DataStruct dStruct = GetPostStruct();
  4180. List<string> lw = new List<string>();
  4181. string tid = GetPostString("ctid");
  4182. if (tid.Length > 0)
  4183. {
  4184. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4185. if (tid.Length > 5)
  4186. {
  4187. List<string> tids = getTidByCtidLike(tid);
  4188. if (tids.Count > 0 && tids.Count < 10)
  4189. {
  4190. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4191. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4192. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4193. {
  4194. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4195. }*/
  4196. }
  4197. }
  4198. lw.Add(tid_sql);
  4199. }
  4200. string shopname = GetPostString("shopname");
  4201. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4202. string buyernick = GetPostString("buyer_nick");
  4203. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4204. //if (tid.Length == 0 && buyernick.Length == 0)
  4205. //{
  4206. // lw.Add(string.Format("IsRefund<={0}", 1));
  4207. //}
  4208. string customer = GetPostString("customer");
  4209. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4210. string design = GetPostString("design");
  4211. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4212. string orderState = GetPostString("orderState");
  4213. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4214. string address = GetPostString("address");
  4215. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4216. string sellermemo = GetPostString("seller_memo");
  4217. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4218. string supplier = GetPostString("supplier");
  4219. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4220. string OrderArea = GetPostString("order_area");
  4221. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4222. string placedate1 = GetPostString("placedate1");
  4223. string placedate2 = GetPostString("placedate2");
  4224. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4225. if (fdw.Length > 0) lw.Add(fdw);
  4226. string price1 = GetPostString("price1");
  4227. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4228. string price2 = GetPostString("price2");
  4229. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4230. string unusualCon = GetPostString("unusualcon");
  4231. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4232. string otherMemo = GetPostString("otherMemo");
  4233. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4234. string posTag = CurrentUser.UserPost.Post.Code;
  4235. if (posTag == "Supplier")
  4236. {
  4237. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4238. }
  4239. else
  4240. {
  4241. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4242. {
  4243. string usershop = CurrentUser.User.pemShop;
  4244. lw.Add(string.Format("ShopId in ({0})", usershop));
  4245. }
  4246. }
  4247. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4248. lw.Add(string.Format("type != 'PDD' "));
  4249. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4250. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4251. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4252. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4253. writeGridDataTableJson(dStruct.TotalCount, dt);
  4254. }
  4255. public void get_erp_changedeliverylist()
  4256. {
  4257. DataStruct dStruct = GetPostStruct();
  4258. List<string> lw = new List<string>();
  4259. string tid = GetPostString("ctid");
  4260. if (tid.Length > 0)
  4261. {
  4262. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4263. if (tid.Length > 5)
  4264. {
  4265. List<string> tids = getTidByCtidLike(tid);
  4266. if (tids.Count > 0 && tids.Count < 10)
  4267. {
  4268. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4269. }
  4270. }
  4271. lw.Add(tid_sql);
  4272. }
  4273. string shopname = GetPostString("shopname");
  4274. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4275. string buyernick = GetPostString("buyer_nick");
  4276. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4277. //if (tid.Length == 0 && buyernick.Length == 0)
  4278. //{
  4279. // lw.Add(string.Format("IsRefund<={0}", 1));
  4280. //}
  4281. string customer = GetPostString("customer");
  4282. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4283. string design = GetPostString("design");
  4284. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4285. string orderState = GetPostString("orderState");
  4286. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4287. string address = GetPostString("address");
  4288. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4289. string sellermemo = GetPostString("seller_memo");
  4290. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4291. string supplier = GetPostString("supplier");
  4292. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4293. string OrderArea = GetPostString("order_area");
  4294. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4295. string placedate1 = GetPostString("placedate1");
  4296. string placedate2 = GetPostString("placedate2");
  4297. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4298. if (fdw.Length > 0) lw.Add(fdw);
  4299. string price1 = GetPostString("price1");
  4300. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4301. string price2 = GetPostString("price2");
  4302. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4303. string unusualCon = GetPostString("unusualcon");
  4304. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4305. string otherMemo = GetPostString("otherMemo");
  4306. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4307. string posTag = CurrentUser.UserPost.Post.Code;
  4308. if (posTag == "Supplier")
  4309. {
  4310. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4311. }
  4312. else
  4313. {
  4314. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4315. {
  4316. string usershop = CurrentUser.User.pemShop;
  4317. lw.Add(string.Format("ShopId in ({0})", usershop));
  4318. }
  4319. }
  4320. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4321. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4322. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4323. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4324. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4325. /*if (tid.Length > 0)
  4326. {
  4327. List<string> tids = new List<string>();
  4328. if (dt != null && dt.Rows.Count > 0)
  4329. {
  4330. foreach (DataRow item in dt.Rows)
  4331. {
  4332. tids.Add("'" + item["tid"] + "'");
  4333. }
  4334. }
  4335. if (tids.Count > 0)
  4336. {
  4337. lw.RemoveAt(0);
  4338. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4339. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4340. dt = WebCache.GetData("view_erptradecell", dStruct);
  4341. }
  4342. }*/
  4343. writeGridDataTableJson(dStruct.TotalCount, dt);
  4344. }
  4345. public void get_erp_pddderiving()
  4346. {
  4347. DataStruct dStruct = GetPostStruct();
  4348. List<string> lw = new List<string>();
  4349. string tid = GetPostString("ctid");
  4350. if (tid.Length > 0)
  4351. {
  4352. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4353. if (tid.Length > 5)
  4354. {
  4355. List<string> tids = getTidByCtidLike(tid);
  4356. if (tids.Count > 0 && tids.Count < 10)
  4357. {
  4358. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4359. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4360. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4361. {
  4362. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4363. }*/
  4364. }
  4365. }
  4366. lw.Add(tid_sql);
  4367. }
  4368. string shopname = GetPostString("shopname");
  4369. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4370. string buyernick = GetPostString("buyer_nick");
  4371. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4372. //if (tid.Length == 0 && buyernick.Length == 0)
  4373. //{
  4374. // lw.Add(string.Format("IsRefund<={0}", 1));
  4375. //}
  4376. string customer = GetPostString("customer");
  4377. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4378. string design = GetPostString("design");
  4379. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4380. string orderState = GetPostString("orderState");
  4381. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4382. string address = GetPostString("address");
  4383. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4384. string sellermemo = GetPostString("seller_memo");
  4385. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4386. string supplier = GetPostString("supplier");
  4387. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4388. string OrderArea = GetPostString("order_area");
  4389. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4390. string placedate1 = GetPostString("placedate1");
  4391. string placedate2 = GetPostString("placedate2");
  4392. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4393. if (fdw.Length > 0) lw.Add(fdw);
  4394. string price1 = GetPostString("price1");
  4395. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4396. string price2 = GetPostString("price2");
  4397. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4398. string unusualCon = GetPostString("unusualcon");
  4399. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4400. string posTag = CurrentUser.UserPost.Post.Code;
  4401. if (posTag == "Supplier")
  4402. {
  4403. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4404. }
  4405. else
  4406. {
  4407. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4408. {
  4409. string usershop = CurrentUser.User.pemShop;
  4410. lw.Add(string.Format("ShopId in ({0})", usershop));
  4411. }
  4412. }
  4413. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4414. lw.Add(string.Format("type = 'PDD' "));
  4415. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4416. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4417. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4418. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4419. /*if (tid.Length > 0)
  4420. {
  4421. List<string> tids = new List<string>();
  4422. if (dt != null && dt.Rows.Count > 0)
  4423. {
  4424. foreach (DataRow item in dt.Rows)
  4425. {
  4426. tids.Add("'" + item["tid"] + "'");
  4427. }
  4428. }
  4429. if (tids.Count > 0)
  4430. {
  4431. lw.RemoveAt(0);
  4432. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4433. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4434. dt = WebCache.GetData("view_erptradecell", dStruct);
  4435. }
  4436. }*/
  4437. writeGridDataTableJson(dStruct.TotalCount, dt);
  4438. }
  4439. public void get_erp_jdderiving()
  4440. {
  4441. DataStruct dStruct = GetPostStruct();
  4442. List<string> lw = new List<string>();
  4443. string tid = GetPostString("ctid");
  4444. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4445. string shopname = GetPostString("shopname");
  4446. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4447. string buyernick = GetPostString("buyer_nick");
  4448. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4449. //if (tid.Length == 0 && buyernick.Length == 0)
  4450. //{
  4451. // lw.Add(string.Format("IsRefund<={0}", 1));
  4452. //}
  4453. string customer = GetPostString("customer");
  4454. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4455. string design = GetPostString("design");
  4456. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4457. string orderState = GetPostString("orderState");
  4458. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4459. string address = GetPostString("address");
  4460. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  4461. string sellermemo = GetPostString("seller_memo");
  4462. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4463. string supplier = GetPostString("supplier");
  4464. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4465. string OrderArea = GetPostString("order_area");
  4466. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4467. string placedate1 = GetPostString("placedate1");
  4468. string placedate2 = GetPostString("placedate2");
  4469. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4470. if (fdw.Length > 0) lw.Add(fdw);
  4471. string price1 = GetPostString("price1");
  4472. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4473. string price2 = GetPostString("price2");
  4474. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4475. string unusualCon = GetPostString("unusualcon");
  4476. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4477. string posTag = CurrentUser.UserPost.Post.Code;
  4478. if (posTag == "Supplier")
  4479. {
  4480. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4481. }
  4482. lw.Add(string.Format("OrderState = 6 "));
  4483. lw.Add(string.Format("type = 'JD' "));
  4484. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4485. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4486. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4487. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4488. writeGridDataTableJson(dStruct.TotalCount, dt);
  4489. }
  4490. public void get_erp_demoorderlist()
  4491. {
  4492. DataStruct dStruct = GetPostStruct();
  4493. List<string> lw = new List<string>();
  4494. string tid = GetPostString("ctid");
  4495. if (tid.Length > 0)
  4496. {
  4497. string select_tid = getTidByCtid(tid);
  4498. lw.Add(string.Format("tid='{0}'", select_tid));
  4499. }
  4500. string shopname = GetPostString("shopname");
  4501. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4502. string buyernick = GetPostString("buyer_nick");
  4503. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4504. string customer = GetPostString("customer");
  4505. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4506. string design = GetPostString("design");
  4507. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4508. string orderState = GetPostString("orderState");
  4509. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4510. string address = GetPostString("address");
  4511. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4512. string sellermemo = GetPostString("seller_memo");
  4513. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4514. string supplier = GetPostString("supplier");
  4515. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4516. string OrderArea = GetPostString("order_area");
  4517. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4518. string date1 = GetPostString("date1");
  4519. string date2 = GetPostString("date2");
  4520. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4521. if (dw.Length > 0) lw.Add(dw);
  4522. string price1 = GetPostString("price1");
  4523. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4524. string price2 = GetPostString("price2");
  4525. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4526. string posTag = CurrentUser.UserPost.Post.Code;
  4527. if (posTag == "Supplier")
  4528. {
  4529. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4530. }
  4531. //lw.Add(string.Format("OrderState = 6 "));
  4532. lw.Add(string.Format("IsSample={0}", 3));
  4533. lw.Add(string.Format("IsRefund<={0}", 1));
  4534. dStruct.Order = "pay_time desc";
  4535. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4536. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4537. writeGridDataTableJson(dStruct.TotalCount, dt);
  4538. }
  4539. public void save_erp_checkmemo()
  4540. {
  4541. if (UrlPostParmsCheck("ctid"))
  4542. {
  4543. string ctid = GetPostString("ctid");
  4544. CeErpTradeCell entity = null;
  4545. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4546. if (entity != null)
  4547. {
  4548. entity.CheckMemo = GetPostString("CheckMemo");
  4549. entity.Update();
  4550. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4551. if (trade != null)
  4552. {
  4553. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4554. }
  4555. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4556. returnSuccessMsg("保存成功!");
  4557. return;
  4558. }
  4559. returnErrorMsg("找不到记录");
  4560. }
  4561. }
  4562. public void get_erp_returnlist()
  4563. {
  4564. DataStruct dStruct = GetPostStruct();
  4565. List<string> lw = new List<string>();
  4566. string tid = GetPostString("ctid");
  4567. if (tid.Length > 0)
  4568. {
  4569. string select_tid = getTidByCtid(tid);
  4570. lw.Add(string.Format("tid='{0}'", select_tid));
  4571. }
  4572. string shopname = GetPostString("shopname");
  4573. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4574. string buyernick = GetPostString("buyer_nick");
  4575. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4576. string customer = GetPostString("customer");
  4577. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4578. string design = GetPostString("design");
  4579. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4580. string orderState = GetPostString("orderState");
  4581. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4582. string address = GetPostString("address");
  4583. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4584. string sellermemo = GetPostString("seller_memo");
  4585. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4586. string supplier = GetPostString("supplier");
  4587. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4588. string date1 = GetPostString("date1");
  4589. string date2 = GetPostString("date2");
  4590. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4591. if (dw.Length > 0) lw.Add(dw);
  4592. string bdate1 = GetPostString("backdate1");
  4593. string bdate2 = GetPostString("backdate2");
  4594. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4595. if (dw_back.Length > 0) lw.Add(dw_back);
  4596. string price1 = GetPostString("price1");
  4597. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4598. string price2 = GetPostString("price2");
  4599. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4600. lw.Add(string.Format("IsReturn>0"));
  4601. lw.Add(string.Format("IsXianHuo=0"));
  4602. lw.Add(string.Format("IsReturn!=3"));
  4603. string backtype = GetPostString("backtype");
  4604. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4605. dStruct.Order = "FinishDesignTime desc";
  4606. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4607. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4608. writeGridDataTableJson(dStruct.TotalCount, dt);
  4609. }
  4610. public void get_erp_today_sumreturn()
  4611. {
  4612. DataStruct dStruct = GetPostStruct();
  4613. List<string> lw = new List<string>();
  4614. string bdate1 = GetPostString("returnTimeS");
  4615. string bdate2 = GetPostString("returnTimeE");
  4616. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4617. if (dw_back.Length > 0) lw.Add(dw_back);
  4618. lw.Add(string.Format("IsReturn=0"));
  4619. lw.Add(string.Format("IsXianHuo=0"));
  4620. string mainWhere = string.Join(" and ", lw.ToArray());
  4621. string sql = "";
  4622. if (dw_back.Length > 0)
  4623. {
  4624. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4625. }
  4626. else
  4627. {
  4628. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + " and ReturnTime >= '" + DateTime.Now.Date + "') as today_finish from view_erptradecell where ReturnTime >= '" + DateTime.Now.Date + "'";
  4629. }
  4630. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4631. decimal total = 0, today_finish = 0;
  4632. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4633. {
  4634. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4635. }
  4636. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4637. {
  4638. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4639. }
  4640. var res = new
  4641. {
  4642. data = total,
  4643. data1 = today_finish,
  4644. };
  4645. string ro_jsond = JsonConvert.SerializeObject(res);
  4646. returnSuccess(ro_jsond);
  4647. return;
  4648. }
  4649. public void get_erp_allreturnlist()
  4650. {
  4651. DataStruct dStruct = GetPostStruct();
  4652. List<string> lw = new List<string>();
  4653. string tid = GetPostString("ctid");
  4654. if (tid.Length > 0)
  4655. {
  4656. string select_tid = getTidByCtid(tid);
  4657. lw.Add(string.Format("tid='{0}'", select_tid));
  4658. }
  4659. string shopname = GetPostString("shopname");
  4660. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4661. string buyernick = GetPostString("buyer_nick");
  4662. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4663. string customer = GetPostString("customer");
  4664. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4665. string design = GetPostString("design");
  4666. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4667. string orderState = GetPostString("orderState");
  4668. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4669. string address = GetPostString("address");
  4670. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4671. string sellermemo = GetPostString("seller_memo");
  4672. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4673. string supplier = GetPostString("supplier");
  4674. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4675. string date1 = GetPostString("date1");
  4676. string date2 = GetPostString("date2");
  4677. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4678. if (dw.Length > 0) lw.Add(dw);
  4679. string bdate1 = GetPostString("backdate1");
  4680. string bdate2 = GetPostString("backdate2");
  4681. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4682. if (dw_back.Length > 0) lw.Add(dw_back);
  4683. string price1 = GetPostString("price1");
  4684. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4685. string price2 = GetPostString("price2");
  4686. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4687. string backreason = GetPostString("backreason");
  4688. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4689. lw.Add(string.Format("IsXianHuo=0"));
  4690. lw.Add(string.Format("ReturnTime != ''"));
  4691. string backtype = GetPostString("backtype");
  4692. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4693. string posTag = CurrentUser.UserPost.Post.Code;
  4694. if (posTag == "Supplier")
  4695. {
  4696. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4697. }
  4698. else
  4699. {
  4700. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  4701. {
  4702. string usershop = CurrentUser.User.pemShop;
  4703. lw.Add(string.Format("ShopId in ({0})", usershop));
  4704. }
  4705. }
  4706. dStruct.Order = "FinishDesignTime desc";
  4707. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4708. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4709. writeGridDataTableJson(dStruct.TotalCount, dt);
  4710. }
  4711. public void get_erp_aftersalereturnlist()
  4712. {
  4713. DataStruct dStruct = GetPostStruct();
  4714. List<string> lw = new List<string>();
  4715. string tid = GetPostString("ctid");
  4716. if (tid.Length > 0)
  4717. {
  4718. string select_tid = getTidByCtid(tid);
  4719. lw.Add(string.Format("tid='{0}'", select_tid));
  4720. }
  4721. string shopname = GetPostString("shopname");
  4722. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4723. string buyernick = GetPostString("buyer_nick");
  4724. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4725. string customer = GetPostString("customer");
  4726. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4727. string design = GetPostString("design");
  4728. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4729. string orderState = GetPostString("orderState");
  4730. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4731. string address = GetPostString("address");
  4732. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4733. string sellermemo = GetPostString("seller_memo");
  4734. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4735. string supplier = GetPostString("supplier");
  4736. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4737. string date1 = GetPostString("date1");
  4738. string date2 = GetPostString("date2");
  4739. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4740. if (dw.Length > 0) lw.Add(dw);
  4741. string bdate1 = GetPostString("backdate1");
  4742. string bdate2 = GetPostString("backdate2");
  4743. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4744. if (dw_back.Length > 0) lw.Add(dw_back);
  4745. string price1 = GetPostString("price1");
  4746. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4747. string price2 = GetPostString("price2");
  4748. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4749. lw.Add(string.Format("IsReturn=3"));
  4750. string backtype = GetPostString("backtype");
  4751. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4752. string backreason = GetPostString("backreason");
  4753. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4754. dStruct.Order = "ReturnTime desc";
  4755. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4756. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4757. writeGridDataTableJson(dStruct.TotalCount, dt);
  4758. }
  4759. public void get_erp_xianhuoreturnlist()
  4760. {
  4761. DataStruct dStruct = GetPostStruct();
  4762. List<string> lw = new List<string>();
  4763. string tid = GetPostString("ctid");
  4764. if (tid.Length > 0)
  4765. {
  4766. string select_tid = getTidByCtid(tid);
  4767. lw.Add(string.Format("tid='{0}'", select_tid));
  4768. }
  4769. string shopname = GetPostString("shopname");
  4770. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4771. string buyernick = GetPostString("buyer_nick");
  4772. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4773. string customer = GetPostString("customer");
  4774. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4775. string design = GetPostString("design");
  4776. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4777. string orderState = GetPostString("orderState");
  4778. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4779. string address = GetPostString("address");
  4780. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4781. string sellermemo = GetPostString("seller_memo");
  4782. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4783. string supplier = GetPostString("supplier");
  4784. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4785. string OrderArea = GetPostString("order_area");
  4786. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4787. string date1 = GetPostString("date1");
  4788. string date2 = GetPostString("date2");
  4789. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4790. if (dw.Length > 0) lw.Add(dw);
  4791. string price1 = GetPostString("price1");
  4792. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4793. string price2 = GetPostString("price2");
  4794. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4795. string posTag = CurrentUser.UserPost.Post.Code;
  4796. if (posTag == "Supplier")
  4797. {
  4798. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4799. }
  4800. lw.Add(string.Format("OrderState=6 "));
  4801. lw.Add(string.Format("IsXianHuo=1 "));
  4802. lw.Add(string.Format("IsReturn>0 "));
  4803. lw.Add(string.Format("IsReturn < 3"));
  4804. lw.Add(string.Format("IsRefund<={0}", 1));
  4805. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4806. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4807. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4808. writeGridDataTableJson(dStruct.TotalCount, dt);
  4809. }
  4810. public void set_erp_orderdelivery()
  4811. {
  4812. if (UrlPostParmsCheck("ctid"))
  4813. {
  4814. string eid = GetPostString("ctid");
  4815. CeErpTradeCell entity = null;
  4816. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4817. if (entity != null)
  4818. {
  4819. if (entity.OrderState >= 7)
  4820. {
  4821. returnErrorMsg("此单已发货,无需重复发货");
  4822. return;
  4823. }
  4824. if (entity.OrderState != 6)
  4825. {
  4826. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4827. return;
  4828. }
  4829. string shop = GetPostString("seller_nick");
  4830. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4831. string comName = GetPostString("comName");
  4832. string comCode = GetPostString("comCode");
  4833. string outSid = GetPostString("outSid");
  4834. string deliveryType = GetPostString("deliveryType");
  4835. string deliveryMemo = GetPostString("deliveryMemo");
  4836. outSid = outSid.Trim();
  4837. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4838. if (mainEn == null)
  4839. {
  4840. returnErrorMsg("找不到原始订单记录");
  4841. return;
  4842. }
  4843. bool isInitOrderDeliv = false;
  4844. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4845. {
  4846. isInitOrderDeliv = true;
  4847. }
  4848. string apires = "";
  4849. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4850. if (entity.ctid.IndexOf("N") != -1 || entity.ctid.IndexOf("P") != -1 || entity.ctid.IndexOf("A") != -1 || entity.ctid.IndexOf("X") != -1 || entity.ctid.IndexOf("S") != -1)
  4851. {
  4852. apires = "发货成功true";
  4853. }
  4854. else
  4855. {
  4856. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4857. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid, entity.ctid);
  4858. }
  4859. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4860. {
  4861. entity.OrderState = 7;//发货后订单已发货
  4862. entity.OutSid = outSid;
  4863. entity.MemoOpt = 0;
  4864. entity.UpdateTime = DateTime.Now;
  4865. entity.FinishDeliveryTime = DateTime.Now;
  4866. entity.Update();
  4867. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4868. commonHelper.UpdateRelationOrder(entity.ctid);
  4869. //还要插入快递信息到 快递信息表
  4870. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4871. exinfo.tid = eid;
  4872. exinfo.out_sid = outSid;
  4873. exinfo.company_code = comCode;
  4874. exinfo.company_name = comName;
  4875. exinfo.delivery_memo = deliveryMemo;
  4876. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4877. exinfo.deliveryType = deliveryType;
  4878. exinfo.printUser = CurrentUser.UserName;
  4879. exinfo.print_time = DateTime.Now;
  4880. exinfo.Create();
  4881. returnSuccessMsg("发货操作成功!");
  4882. commonHelper.UpdateRelationOrder(entity.ctid);
  4883. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4884. CeErpSukuraData.createInfo(entity.ctid, 4);
  4885. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  4886. {
  4887. commonHelper.sendCytExpress(exinfo);
  4888. }
  4889. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4890. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid + ",备注:" + deliveryMemo, entity.OrderState);
  4891. }
  4892. else
  4893. {
  4894. string errmsg = commonHelper.KeepChinese(apires);
  4895. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4896. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4897. }
  4898. return;
  4899. }
  4900. returnErrorMsg("找不到订单记录");
  4901. }
  4902. }
  4903. public void set_erp_multidelivery()
  4904. {
  4905. string eids = GetPostString("tids");
  4906. string[] eidList = eids.Split(',');
  4907. if (eidList.Length <= 0)
  4908. {
  4909. returnErrorMsg("发货不能为空");
  4910. return;
  4911. }
  4912. foreach (string ctid in eidList)
  4913. {
  4914. if (ctid.Length <= 0) continue;
  4915. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4916. if (expInfo != null)
  4917. {
  4918. StringBuilder sql = new StringBuilder();
  4919. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4920. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4921. if (dt.Rows.Count > 0)
  4922. {
  4923. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4924. {
  4925. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4926. expInfo.state = "异常";
  4927. expInfo.isMultiDelivery = 1;
  4928. expInfo.Update();
  4929. continue;
  4930. }
  4931. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4932. {
  4933. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4934. expInfo.state = "异常";
  4935. expInfo.Update();
  4936. continue;
  4937. }
  4938. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4939. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4940. bool isInitOrderDeliv = false;
  4941. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4942. {
  4943. isInitOrderDeliv = true;
  4944. expInfo.isMultiDelivery = 1;
  4945. }
  4946. if (ctid.IndexOf("N") != -1)
  4947. {
  4948. StringBuilder sqlbucha = new StringBuilder();
  4949. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4950. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4951. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4952. commonHelper.UpdateRelationOrder(ctid);
  4953. expInfo.delivery_memo = "发货成功";
  4954. expInfo.state = "发货成功";
  4955. expInfo.isMultiDelivery = 1;
  4956. expInfo.Update();
  4957. }
  4958. else
  4959. {
  4960. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4961. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid, ctid);
  4962. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4963. {
  4964. expInfo.delivery_memo = "发货成功";
  4965. expInfo.state = "发货成功";
  4966. expInfo.isMultiDelivery = 1;
  4967. expInfo.Update();
  4968. commonHelper.UpdateRelationOrder(ctid);
  4969. CeErpSukuraData.createInfo(ctid, 4);
  4970. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4971. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4972. }
  4973. else
  4974. {
  4975. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4976. expInfo.state = "异常";
  4977. expInfo.Update();
  4978. }
  4979. }
  4980. }
  4981. }
  4982. }
  4983. returnSuccessMsg("操作完成");
  4984. }
  4985. public void reset_erp_memoopt()
  4986. {
  4987. if (UrlPostParmsCheck("ctid"))
  4988. {
  4989. string eid = GetPostString("ctid");
  4990. CeErpTradeCell entity = null;
  4991. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4992. if (entity != null)
  4993. {
  4994. string stropt = "";
  4995. if (entity.MemoOpt == 1)
  4996. {
  4997. stropt = "“改稿”";
  4998. }
  4999. else if (entity.MemoOpt == 2)
  5000. {
  5001. stropt = "“定稿”";
  5002. }
  5003. else if (entity.MemoOpt == 3)
  5004. {
  5005. stropt = "“完成查货”";
  5006. CeErpSukuraData.createInfo(entity.ctid, 6);
  5007. }
  5008. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  5009. entity.UpdateTime = DateTime.Now;
  5010. entity.MemoOpt = 0;
  5011. entity.Update();
  5012. returnSuccessMsg("操作成功!");
  5013. return;
  5014. }
  5015. returnErrorMsg("找不到记录");
  5016. }
  5017. }
  5018. public void get_erp_deliveryunusual()
  5019. {
  5020. DataStruct dStruct = GetPostStruct();
  5021. List<string> lw = new List<string>();
  5022. string tid = GetPostString("ctid");
  5023. if (tid.Length > 0)
  5024. {
  5025. string select_tid = getTidByCtid(tid);
  5026. lw.Add(string.Format("tid='{0}'", select_tid));
  5027. }
  5028. string shopname = GetPostString("shopname");
  5029. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5030. string buyernick = GetPostString("buyer_nick");
  5031. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  5032. string customer = GetPostString("customer");
  5033. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5034. string design = GetPostString("design");
  5035. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5036. string sellermemo = GetPostString("seller_memo");
  5037. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5038. string supplier = GetPostString("supplier");
  5039. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5040. string date1 = GetPostString("date1");
  5041. string date2 = GetPostString("date2");
  5042. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5043. if (dw.Length > 0) lw.Add(dw);
  5044. string placedate1 = GetPostString("placedate1");
  5045. string placedate2 = GetPostString("placedate2");
  5046. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5047. if (dw_place.Length > 0) lw.Add(dw_place);
  5048. string price1 = GetPostString("price1");
  5049. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5050. string price2 = GetPostString("price2");
  5051. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5052. string unusualCon = GetPostString("unusualcon");
  5053. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  5054. string posTag = CurrentUser.UserPost.Post.Code;
  5055. if (posTag == "Supplier")
  5056. {
  5057. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5058. }
  5059. lw.Add(string.Format("OrderState = 6"));
  5060. lw.Add(string.Format("UnusualTag = 5"));
  5061. lw.Add(string.Format("IsRefund<={0}", 1));
  5062. dStruct.Order = "FinishPlaceTime desc";
  5063. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5064. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5065. writeGridDataTableJson(dStruct.TotalCount, dt);
  5066. }
  5067. public void get_erp_deliveryedlist()
  5068. {
  5069. DataStruct dStruct = GetPostStruct();
  5070. List<string> lw = new List<string>();
  5071. string tid = GetPostString("ctid");
  5072. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5073. string shopname = GetPostString("shopname");
  5074. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5075. string buyernick = GetPostString("buyer_nick");
  5076. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5077. string customer = GetPostString("customer");
  5078. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5079. string design = GetPostString("design");
  5080. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5081. string sellermemo = GetPostString("seller_memo");
  5082. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5083. string logistics = GetPostString("logistics");
  5084. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5085. string date1 = GetPostString("date1");
  5086. string date2 = GetPostString("date2");
  5087. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5088. //if (dw.Length > 0) lw.Add(dw);
  5089. string placedate1 = GetPostString("placedate1");
  5090. string placedate2 = GetPostString("placedate2");
  5091. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5092. if (fdw.Length > 0) lw.Add(fdw);
  5093. string devdate1 = GetPostString("deliverydate1");
  5094. string devdate2 = GetPostString("deliverydate2");
  5095. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5096. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5097. string price1 = GetPostString("price1");
  5098. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5099. string price2 = GetPostString("price2");
  5100. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5101. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5102. {
  5103. if (tid.Length > 0)
  5104. {
  5105. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5106. if (tid.Length > 5)
  5107. {
  5108. List<string> tids = getTidByCtidLike(tid);
  5109. if (tids.Count > 0 && tids.Count < 10)
  5110. {
  5111. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5112. }
  5113. }
  5114. lw.Add(tid_sql);
  5115. }
  5116. if (buyernick.Length > 0)
  5117. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5118. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5119. if (dw.Length > 0) lw.Add(dw);
  5120. }
  5121. else
  5122. {
  5123. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  5124. }
  5125. string posTag = CurrentUser.UserPost.Post.Code;
  5126. if (posTag == "Supplier")
  5127. {
  5128. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5129. }
  5130. else
  5131. {
  5132. string supplier = GetPostString("supplier");
  5133. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5134. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5135. {
  5136. string usershop = CurrentUser.User.pemShop;
  5137. lw.Add(string.Format("ShopId in ({0})", usershop));
  5138. }
  5139. }
  5140. lw.Add(string.Format(" OrderState IN (7, 8)"));
  5141. lw.Add(string.Format("type != 'PDD' "));
  5142. lw.Add(string.Format("IsRefund!={0}", 2));
  5143. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5144. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5145. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5146. /*if (tid.Length > 0)
  5147. {
  5148. List<string> tids = new List<string>();
  5149. if (dt != null && dt.Rows.Count > 0)
  5150. {
  5151. foreach (DataRow item in dt.Rows)
  5152. {
  5153. tids.Add("'" + item["tid"] + "'");
  5154. }
  5155. }
  5156. if (tids.Count > 0)
  5157. {
  5158. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5159. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5160. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5161. dt = WebCache.GetData("view_erptradecell", dStruct);
  5162. }
  5163. }*/
  5164. if (dt != null)
  5165. {
  5166. foreach (DataRow dr in dt.Rows)
  5167. {
  5168. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5169. }
  5170. }
  5171. writeGridDataTableJson(dStruct.TotalCount, dt);
  5172. }
  5173. public void get_erp_pdddeliveryed()
  5174. {
  5175. DataStruct dStruct = GetPostStruct();
  5176. List<string> lw = new List<string>();
  5177. string tid = GetPostString("ctid");
  5178. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5179. string shopname = GetPostString("shopname");
  5180. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5181. string buyernick = GetPostString("buyer_nick");
  5182. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5183. string customer = GetPostString("customer");
  5184. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5185. string design = GetPostString("design");
  5186. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5187. string sellermemo = GetPostString("seller_memo");
  5188. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5189. string logistics = GetPostString("logistics");
  5190. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5191. string date1 = GetPostString("date1");
  5192. string date2 = GetPostString("date2");
  5193. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5194. //if (dw.Length > 0) lw.Add(dw);
  5195. string placedate1 = GetPostString("placedate1");
  5196. string placedate2 = GetPostString("placedate2");
  5197. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5198. if (fdw.Length > 0) lw.Add(fdw);
  5199. string devdate1 = GetPostString("deliverydate1");
  5200. string devdate2 = GetPostString("deliverydate2");
  5201. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5202. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5203. string price1 = GetPostString("price1");
  5204. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5205. string price2 = GetPostString("price2");
  5206. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5207. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5208. {
  5209. if (tid.Length > 0)
  5210. {
  5211. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5212. if (tid.Length > 5)
  5213. {
  5214. List<string> tids = getTidByCtidLike(tid);
  5215. if (tids.Count > 0 && tids.Count < 10)
  5216. {
  5217. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5218. }
  5219. }
  5220. lw.Add(tid_sql);
  5221. }
  5222. if (buyernick.Length > 0)
  5223. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5224. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5225. if (dw.Length > 0) lw.Add(dw);
  5226. }
  5227. else
  5228. {
  5229. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5230. }
  5231. string posTag = CurrentUser.UserPost.Post.Code;
  5232. if (posTag == "Supplier")
  5233. {
  5234. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5235. }
  5236. else
  5237. {
  5238. if (posTag != "wxDesigner" && posTag != "Designer" && posTag != "DesignerMr" && posTag != "wxDesignerMr" && posTag != "SysAdmin")
  5239. {
  5240. string usershop = CurrentUser.User.pemShop;
  5241. lw.Add(string.Format("ShopId in ({0})", usershop));
  5242. }
  5243. string supplier = GetPostString("supplier");
  5244. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5245. }
  5246. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5247. lw.Add(string.Format("type = 'PDD' "));
  5248. lw.Add(string.Format("IsRefund!={0}", 2));
  5249. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5251. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5252. /* if (tid.Length > 0)
  5253. {
  5254. List<string> tids = new List<string>();
  5255. if (dt != null && dt.Rows.Count > 0)
  5256. {
  5257. foreach (DataRow item in dt.Rows)
  5258. {
  5259. tids.Add("'" + item["tid"] + "'");
  5260. }
  5261. }
  5262. if (tids.Count > 0)
  5263. {
  5264. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5265. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5266. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5267. dt = WebCache.GetData("view_erptradecell", dStruct);
  5268. }
  5269. }*/
  5270. foreach (DataRow dr in dt.Rows)
  5271. {
  5272. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5273. }
  5274. writeGridDataTableJson(dStruct.TotalCount, dt);
  5275. }
  5276. public void get_erp_jddeliveryed()
  5277. {
  5278. DataStruct dStruct = GetPostStruct();
  5279. List<string> lw = new List<string>();
  5280. string tid = GetPostString("ctid");
  5281. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5282. string shopname = GetPostString("shopname");
  5283. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5284. string buyernick = GetPostString("buyer_nick");
  5285. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5286. string customer = GetPostString("customer");
  5287. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5288. string design = GetPostString("design");
  5289. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5290. string sellermemo = GetPostString("seller_memo");
  5291. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5292. string date1 = GetPostString("date1");
  5293. string date2 = GetPostString("date2");
  5294. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5295. //if (dw.Length > 0) lw.Add(dw);
  5296. string placedate1 = GetPostString("placedate1");
  5297. string placedate2 = GetPostString("placedate2");
  5298. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5299. if (fdw.Length > 0) lw.Add(fdw);
  5300. string devdate1 = GetPostString("deliverydate1");
  5301. string devdate2 = GetPostString("deliverydate2");
  5302. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5303. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5304. string price1 = GetPostString("price1");
  5305. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5306. string price2 = GetPostString("price2");
  5307. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5308. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5309. {
  5310. if (tid.Length > 0)
  5311. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5312. if (buyernick.Length > 0)
  5313. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5314. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5315. if (dw.Length > 0) lw.Add(dw);
  5316. }
  5317. else
  5318. {
  5319. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5320. }
  5321. string posTag = CurrentUser.UserPost.Post.Code;
  5322. if (posTag == "Supplier")
  5323. {
  5324. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5325. }
  5326. else
  5327. {
  5328. string supplier = GetPostString("supplier");
  5329. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5330. }
  5331. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5332. lw.Add(string.Format("type = 'JD' "));
  5333. lw.Add(string.Format("IsRefund!={0}", 2));
  5334. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5335. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5336. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5337. foreach (DataRow dr in dt.Rows)
  5338. {
  5339. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5340. }
  5341. writeGridDataTableJson(dStruct.TotalCount, dt);
  5342. }
  5343. public void get_erp_allplacelist()
  5344. {
  5345. DataStruct dStruct = GetPostStruct();
  5346. List<string> lw = new List<string>();
  5347. string tid = GetPostString("ctid");
  5348. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5349. string shopname = GetPostString("shopname");
  5350. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5351. string buyernick = GetPostString("buyer_nick");
  5352. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5353. string customer = GetPostString("customer");
  5354. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5355. string design = GetPostString("design");
  5356. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5357. string sellermemo = GetPostString("seller_memo");
  5358. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5359. string supplier = GetPostString("supplier");
  5360. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5361. string date1 = GetPostString("date1");
  5362. string date2 = GetPostString("date2");
  5363. string pldate1 = GetPostString("placedate1");
  5364. string pldate2 = GetPostString("placedate2");
  5365. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5366. //if (dw.Length > 0) lw.Add(dw);
  5367. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5368. {
  5369. if (tid.Length > 0)
  5370. {
  5371. string select_tid = getTidByCtid(tid);
  5372. lw.Add(string.Format("tid='{0}'", select_tid));
  5373. }
  5374. if (buyernick.Length > 0)
  5375. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5376. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5377. if (dw.Length > 0) lw.Add(dw);
  5378. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5379. if (dw_place.Length > 0) lw.Add(dw_place);
  5380. }
  5381. else
  5382. {
  5383. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5384. {
  5385. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5386. }
  5387. }
  5388. string price1 = GetPostString("price1");
  5389. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5390. string price2 = GetPostString("price2");
  5391. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5392. string posTag = CurrentUser.UserPost.Post.Code;
  5393. if (posTag == "Supplier")
  5394. {
  5395. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5396. }
  5397. lw.Add(string.Format("OrderState >= 6"));
  5398. lw.Add(string.Format("IsSample != 2 "));
  5399. //lw.Add(string.Format("isDianziOrder = 0 "));
  5400. lw.Add(string.Format("SupplierId > 0 "));
  5401. //lw.Add(string.Format("IsRefund<={0}", 1));
  5402. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5403. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5404. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5405. foreach (DataRow dr in dt.Rows)
  5406. {
  5407. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5408. }
  5409. writeGridDataTableJson(dStruct.TotalCount, dt);
  5410. }
  5411. public void get_erp_financeallplacelist()
  5412. {
  5413. DataStruct dStruct = GetPostStruct();
  5414. List<string> lw = new List<string>();
  5415. string tid = GetPostString("ctid");
  5416. string shopname = GetPostString("shopname");
  5417. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5418. string buyernick = GetPostString("buyer_nick");
  5419. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5420. string customer = GetPostString("customer");
  5421. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5422. string design = GetPostString("design");
  5423. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5424. string sellermemo = GetPostString("seller_memo");
  5425. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5426. string supplier = GetPostString("supplier");
  5427. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5428. string date1 = GetPostString("date1");
  5429. string date2 = GetPostString("date2");
  5430. string pldate1 = GetPostString("placedate1");
  5431. string pldate2 = GetPostString("placedate2");
  5432. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5433. {
  5434. if (tid.Length > 0)
  5435. {
  5436. string select_tid = getTidByCtid(tid);
  5437. lw.Add(string.Format("tid='{0}'", select_tid));
  5438. }
  5439. if (buyernick.Length > 0)
  5440. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5441. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5442. if (dw.Length > 0) lw.Add(dw);
  5443. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5444. if (dw_place.Length > 0) lw.Add(dw_place);
  5445. }
  5446. else
  5447. {
  5448. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5449. {
  5450. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5451. }
  5452. }
  5453. string price1 = GetPostString("price1");
  5454. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5455. string price2 = GetPostString("price2");
  5456. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5457. string posTag = CurrentUser.UserPost.Post.Code;
  5458. if (posTag == "Supplier")
  5459. {
  5460. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5461. }
  5462. //lw.Add(string.Format("OrderState >= 6"));
  5463. lw.Add(string.Format("IsSample != 2 "));
  5464. lw.Add(string.Format("isDianziOrder = 0 "));
  5465. //lw.Add(string.Format("IsRefund<={0}", 1));
  5466. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5467. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5468. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5469. foreach (DataRow dr in dt.Rows)
  5470. {
  5471. dr["receiver_address"] = dr["receiver_name"].ToString() + " " + dr["receiver_mobile"].ToString() + " " + dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_district"].ToString() + dr["receiver_address"].ToString();
  5472. }
  5473. writeGridDataTableJson(dStruct.TotalCount, dt);
  5474. }
  5475. public void get_erp_expresslist()
  5476. {
  5477. int listtype = GetInt("ltype");
  5478. DataStruct dStruct = GetPostStruct();
  5479. List<string> lw = new List<string>();
  5480. string tid = GetPostString("tid");
  5481. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5482. string outsid = GetPostString("out_sid");
  5483. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5484. string importer = GetPostString("ImportUserName");
  5485. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5486. string file = GetPostString("import_file");
  5487. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5488. string printman = GetPostString("printman");
  5489. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5490. string date1 = GetPostString("date1");
  5491. string date2 = GetPostString("date2");
  5492. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5493. if (dw.Length > 0) lw.Add(dw);
  5494. string fdate1 = GetPostString("finishdate1");
  5495. string fdate2 = GetPostString("finishdate2");
  5496. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5497. if (fdw.Length > 0) lw.Add(fdw);
  5498. string supplierId = GetPostString("supplierId");
  5499. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5500. if (listtype == 1)
  5501. {
  5502. lw.Add(string.Format("importUserId !=0"));
  5503. }
  5504. string posTag = CurrentUser.UserPost.Post.Code;
  5505. if (posTag == "Supplier")
  5506. {
  5507. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5508. }
  5509. if (dStruct.PageSize != 100000)
  5510. {
  5511. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5512. }
  5513. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5514. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5515. writeGridDataTableJson(dStruct.TotalCount, dt);
  5516. }
  5517. public void set_erp_buchaorderdelivery()
  5518. {
  5519. if (UrlPostParmsCheck("ctid"))
  5520. {
  5521. string eid = GetPostString("ctid");
  5522. CeErpTradeCell entity = null;
  5523. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5524. if (entity != null)
  5525. {
  5526. if (entity.IsSample != 2)
  5527. {
  5528. returnErrorMsg("补差价单才能标记为已发货");
  5529. return;
  5530. }
  5531. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5532. entity.OrderState = 7;
  5533. entity.Update();
  5534. returnSuccessMsg("操作成功!");
  5535. return;
  5536. }
  5537. returnErrorMsg("找不到记录");
  5538. }
  5539. }
  5540. public void get_stdtemplates()
  5541. {
  5542. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5543. //string res = taobaoHelper.test();
  5544. string res = apiHelper.API_PrintTemplate();
  5545. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5546. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5547. {
  5548. int sidx = res.IndexOf("error_code");
  5549. int eidx = res.IndexOf("success");
  5550. string msg = res.Substring(sidx, eidx - sidx);
  5551. returnErrorMsg(msg);
  5552. return;
  5553. }
  5554. if (res.Length <= 0)
  5555. {
  5556. returnErrorMsg("模板数据为空!");
  5557. return;
  5558. }
  5559. ReturnSuccess(res);
  5560. }
  5561. public void cancel_print_order()
  5562. {
  5563. if (UrlPostParmsCheck("ctid"))
  5564. {
  5565. string ctid = GetPostString("ctid");
  5566. CeErpTradeCell entity = null;
  5567. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5568. if (entity != null)
  5569. {
  5570. string res = "";
  5571. string code = entity.LastBillWaybillCode;
  5572. if (code == "")
  5573. {
  5574. code = entity.OutSid;
  5575. }
  5576. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5577. XLog.SaveLog(0, "取消面单" + res);
  5578. }
  5579. }
  5580. }
  5581. public void set_erp_printwaybill()
  5582. {
  5583. if (UrlPostParmsCheck("ctid"))
  5584. {
  5585. string ctid = GetPostString("ctid");
  5586. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5587. string cpName = GetPostString("cpname");
  5588. string isTogether = GetPostString("together");
  5589. string printType = GetPostString("printType");
  5590. //var res_obj = new
  5591. //{
  5592. // restype = 1,
  5593. // data = "{\"response\":{\"data\":{\"content\":[{\"openOrderSubId\":\"\",\"parentWaybillCode\":\"\",\"platformType\":\"WB_PDD\",\"updateTime\":1686537867000,\"orderPlatform\":\"PDD\",\"openOrderId\":\"230611-632307127861975\",\"merchId\":1,\"props\":{\"ver\":\"8\",\"signature\":\"lYwcylRHKaeMOxfUvBg7ySYTGGur75biVxO5LTXxM3KeTpMaf6rIvIUFG0HtW4m7+JynVGS83sdGaIAYK3Rrr4QZZTKskIXWKGHKES7lmCP1yM7xD8Cm50aBAfelZo390L1PBb5WSn3EQB40vNIuV2itH2ajXqHtr93Mk2mDnno=\",\"dataVerification\":\"c609dcf70cf85832458adffe1aec3933\",\"encryptedData\":\"50830ac2124673c1abf81fc49c845bd5c55e9e4d1b2d03cd5f7b5445b79a95d763c60072c76649bec3effe329c02bc8c0a6ef3b43603bcfe31fd83dea03352a019cd2ab261c89b883168484f512c03f3fd586e2d487f2b612ed74ffd7d00ccc933739947ca46579f6187e4e23417a7b4f5b09faeb3045aa995fc177d9cc854ba6c1f0f345ad92320e1ed2bbdabc285b86f92b1e705e70bf2d3472b375a0bff031b385a1d2365865b0723d1fd0ecafd45ef01cb1cbf70613d83aa09d5a8c381d2099f5badee8c39e757159f86d6162e1f4bda68723eabb70526c2c0671df7463b281c43bca1b1a4f47b8b59ed666e76353eb4bb5e0be1223c150c8ebd6c623bb2b2448a8c818a76da9fbf1bcc5c3ec45545439f9d4d508fd72b2b127a478cf42b81300fae885c06a0459006bf6fe95db21fab2d7ba9a9a5d635df5eae7ec96248e067dd9ee3fb86b6c93f85a4eb91a290474495cd82b345aa977427946ae6f4034c14fc9b62252657fc03aae9d13d58380affce3c3138690391f1b895da3413d764258aeb26a94ffacec8ab511693462c2bc039a6674b18f7a1bf82abfaf9ebbfd40b2ed77fc7ea95db5ef34c24ee93fc5107cfa13de5ff674f259df1817276ab05f1716c276bd517719a164ab0c4490250f5bd10b6fe1e8b2212fc91a99bc1c42fd6273ef3a68f9c7fc900dc0b2792c2810d361aa054db691ac4c6b578b146f31b9413d43b3af8b8b54ff606b500891e0cbac7d4c4fed8398ccf63ce952e1babe6dbb5deb469ad5f791f2f8df175c6bcfb2c2659441b1e3f4752ef3e727b80587b8a354abe6230263bf4f6e4460154342737ead1f7520f18570ecc633575f7c9d5c23f1c1fe578b5a495398bd14b641d76df38a36f6c6db025258cf02e59e04fa931c00a077bf91aa74ec3d2c03a5b83ded3ff73942699006b36390bed0372683e49cc06a5e906350dcc9ea96f42be381be814c3b9035b8385cdc6f1195b124bfbe42d05406dc7b5d76e096d938e31b5255532271fbc1786459c9081cc068c2f62ffc1a901686b55cd1e712e4bdcfe2a83c324366f8ea734c15332365a9f738746252472e44995d75c2114fbf804bf0769bda4310df5ee95cc94ccd965661cb446af66e048db112bad54dccdc650fa723761baa9449ee6af9196ef936f209310117b4b74aaf955bc1d279d00fe74e3ef9aa96023b714a710cf7e820437106eb10f0d17a4ad7fd100241c56d387e4c4caefbd9d4b438ba0b5799bec54da643f91a65c8fcc0c7dde39e7eca708e237b92a99133c48c9e2a0aaa616acfc0d7336abec25314628ae778e84b35a4319ad6f2ef87f271fd60eba53811ea02a4d5e023216e1dee04fc8960a2bfcaba873ba204cdc675f66f8230818f84e9d7e893867088469ec90e54b96fa78cde6a51e2a2ab4611dfbf4aa8f8c802547a5f24fbc2912786cfb045ef821aa277797211012c28fd836921dba83e1829325bbdf17ad0302e16455b4defbe5a5fadbdc3677505f1d4901531e1db7b13981f31556d743ad3d48eaf2c000be18d5b036837f979240fa3afee74790e82f01dcbd434ff129ecbfed3a0dabaa2a615bac9487a1197323476556eb05469ad8bf75ba95e82a527b93115b360a5920cc23c1f5cf885022dd65e1bd430ffa3d1baf6592b3d6a226c53161a11be8133d3f254ac845e69ed02dd3758cc9adccf42985d8695f8942e08d08d0b27ee49b4bacd4954fe6804e202318f9143feaec7569c7a0759d0d0ee7b537f95b21f4c8ba9743c12da95802ab2600bdecd7bb3c676207e624a35711287afaeeec6ca2be07eebbc4bf1a56c3615ad6830f3e7dd28ed88a6f9ce8b80727316f959b5f09d9a7545ce2609309e71662910fa702b59f8fc07b55c24a254a1e3237dbd054569832111658f3e747aaa619124e2c2467e241d30c1e756a1338a89bad3ce6b8c7fccbd656b1cfbd1cec8bb46e05a5f5f8d87c1f43058389bc64f1f4cbb3fefe5b427892a4064ed83855cdab9f645810170bdee8d8d0e2c5f1cea3732d4699071803a62f3bb056cdd019ac74ce899cc653b76765c0bafee7cfc17521cc3162e01efe25497fe04af1f91fe7033b66f34b08a9451149e4be0ab5b6ce0e2b236626eec93b1e645515fd98b781dceef19b299c692def81095d3114e091c0fb4d6f37d83bb47c1282efd0361716aaebf8b837cc8a17b7ade3305cedcc7736062ac8b4619eb7ee48d6ee954ae977ef4f393ceefe50117874556c30f892f522f0bdb94fa3faceef691579397c1666d21c3264e58eded67f95f6f5b17bf8737ef73d4fd6f66168a148be89368d262807d0817fb67c9580b8d03ea8009951754722?v=8&pv=1\",\"templateUrl\":\"https://file-link.pinduoduo.com/yto_one\"},\"updateBy\":0,\"tenantId\":34,\"waybillCode\":\"YT8910742640842\",\"id\":989598,\"partnerId\":794928,\"mark\":[],\"status\":\"USED\"}]},\"success\":true},\"_req_id\":\"W4Yffp19yC\"}"
  5594. //};
  5595. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5596. //ReturnSuccess(ro_json);
  5597. //return;
  5598. bool isUseLastWayBillCode = false;
  5599. CeErpTradeCell entity = null;
  5600. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5601. if (entity != null)
  5602. {
  5603. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5604. {
  5605. isUseLastWayBillCode = true;
  5606. }
  5607. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5608. {
  5609. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5610. return;
  5611. }
  5612. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5613. {
  5614. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5615. return;
  5616. }
  5617. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5618. {
  5619. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5620. return;
  5621. }
  5622. }
  5623. string res = "";
  5624. Api_waybill_code_response_Obj fullObj = null;
  5625. string pData_str = "";
  5626. string curUseWayBillCode = "";
  5627. if (isUseLastWayBillCode == false)
  5628. {
  5629. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5630. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5631. if (res.IndexOf("failure") != -1)
  5632. {
  5633. //int idx = res.IndexOf("sub_message");
  5634. //int idx2 = res.IndexOf("flag");
  5635. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5636. string errMsgNeed = commonHelper.KeepChinese(res);
  5637. var res_objd = new
  5638. {
  5639. restype = 0,
  5640. data = "获取面单失败" + errMsgNeed
  5641. };
  5642. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5643. returnSuccess(ro_jsond);
  5644. if (res.IndexOf("停发") != -1)
  5645. {
  5646. entity.UnusualCon = "物流停发";
  5647. entity.Update();
  5648. }
  5649. //returnErrorMsg("获取面单失败,"+emsg);
  5650. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5651. return;
  5652. }
  5653. else if (res.IndexOf("errorMsg") != -1)
  5654. {
  5655. //int idx = res.IndexOf("errorMsg");
  5656. //int idx2 = res.IndexOf("}]}");
  5657. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5658. string errMsgNeed = commonHelper.KeepChinese(res);
  5659. var res_objf = new
  5660. {
  5661. restype = 0,
  5662. data = "获取面单失败2" + errMsgNeed
  5663. };
  5664. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5665. if (res.IndexOf("停发") != -1)
  5666. {
  5667. entity.UnusualCon = "物流停发";
  5668. entity.Update();
  5669. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5670. if (trade != null)
  5671. {
  5672. //string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5673. }
  5674. }
  5675. returnSuccess(ro_jsonf);
  5676. //returnErrorMsg("获取面单失败," + emsg);
  5677. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5678. return;
  5679. }
  5680. try
  5681. {
  5682. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5683. //res = res.Replace(" ", "");
  5684. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5685. }
  5686. catch (Exception ex)
  5687. {
  5688. XLog.SaveLog(0, "生成fullObj" + res);
  5689. var res_objf = new
  5690. {
  5691. restype = 0,
  5692. data = "生成fullObj发生错误" + ex.Message
  5693. };
  5694. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5695. returnSuccess(ro_jsonf);
  5696. return;
  5697. }
  5698. if (fullObj.response.data.content.Count > 0)
  5699. {
  5700. ContentItem codeObj = fullObj.response.data.content[0];
  5701. if (cpCode.IndexOf("SFFQ-") != -1)
  5702. {
  5703. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5704. }
  5705. else
  5706. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5707. curUseWayBillCode = codeObj.waybillCode;
  5708. }
  5709. else
  5710. {
  5711. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5712. var res_objf = new
  5713. {
  5714. restype = 0,
  5715. data = "生成fullObj找不到快递单号waybillCode"
  5716. };
  5717. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5718. returnSuccess(ro_jsonf);
  5719. return;
  5720. }
  5721. }
  5722. else
  5723. {
  5724. //使用上次打印的快递单号
  5725. if (cpCode == "SFFQ-LY")
  5726. {
  5727. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5728. }
  5729. else
  5730. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5731. curUseWayBillCode = entity.LastBillWaybillCode;
  5732. }
  5733. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5734. {
  5735. var res_obje = new
  5736. {
  5737. restype = 0,
  5738. data = "获取加密打印数据失败"
  5739. };
  5740. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5741. returnSuccess(ro_jsone);
  5742. entity.LastBillCpCode = cpCode;
  5743. entity.LastBillWaybillCode = curUseWayBillCode;
  5744. entity.Update();
  5745. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5746. //returnErrorMsg("获取加密打印数据失败");
  5747. return;
  5748. }
  5749. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5750. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5751. string btnType = "";
  5752. string errorMsg = "";
  5753. if (entity != null)
  5754. {
  5755. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5756. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5757. //cpcode是 YTO-CAINIAO
  5758. //string comCode = cpCode.Split('-')[0].ToString();
  5759. string apires = "";
  5760. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5761. //isTogether=2是新的合包弹窗
  5762. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5763. {
  5764. if (ctid.IndexOf("N") != -1)
  5765. {
  5766. apires = "发货成功";
  5767. }
  5768. else
  5769. {
  5770. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode, entity.ctid);
  5771. }
  5772. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5773. //打单后发货
  5774. StringBuilder sql = new StringBuilder();
  5775. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5776. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5777. {
  5778. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5779. }
  5780. else
  5781. {
  5782. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5783. }
  5784. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5785. foreach (DataRow row in dt.Rows)
  5786. {
  5787. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5788. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5789. {
  5790. try
  5791. {
  5792. btnType = "待发货";
  5793. entity.OutSid = curUseWayBillCode;
  5794. entity.OrderState = 7;
  5795. entity.IsUrgency = false;
  5796. entity.LastBillCpCode = "";
  5797. entity.LastBillWaybillCode = "";
  5798. entity.FinishDeliveryTime = DateTime.Now;
  5799. entity.IsReturn = 0;
  5800. entity.MemoOpt = 0;
  5801. entity.UpdateTime = DateTime.Now;
  5802. entity.Update();
  5803. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5804. //还要插入快递信息到 快递信息表
  5805. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5806. exinfo.tid = entity.ctid;
  5807. exinfo.out_sid = curUseWayBillCode;
  5808. exinfo.company_code = cpCode;
  5809. exinfo.company_name = cpName;
  5810. exinfo.supplierUserName = supplierName;
  5811. exinfo.deliveryType = "发货成功";
  5812. exinfo.print_time = DateTime.Now;
  5813. exinfo.printUser = CurrentUser.UserName;
  5814. exinfo.postData = pData_str;
  5815. exinfo.Create();
  5816. commonHelper.UpdateRelationOrder(entity.ctid);
  5817. CeErpSukuraData.createInfo(ctid, 4);
  5818. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5819. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5820. {
  5821. commonHelper.sendCytExpress(exinfo);
  5822. }
  5823. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5824. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5825. }
  5826. catch (Exception ex)
  5827. {
  5828. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5829. }
  5830. }
  5831. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5832. {
  5833. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5834. if (entity.OrderState == 6)
  5835. {
  5836. entity.OrderState = 7;
  5837. }
  5838. entity.UpdateTime = DateTime.Now;
  5839. entity.FinishDeliveryTime = DateTime.Now;
  5840. btnType = "已发货";
  5841. entity.Update();
  5842. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5843. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5844. exinfo.tid = entity.ctid;
  5845. exinfo.out_sid = curUseWayBillCode;
  5846. exinfo.company_code = cpCode;
  5847. exinfo.company_name = cpName;
  5848. exinfo.supplierUserName = supplierName;
  5849. exinfo.deliveryType = "发货成功";
  5850. exinfo.print_time = DateTime.Now;
  5851. exinfo.printUser = CurrentUser.UserName;
  5852. exinfo.postData = pData_str;
  5853. exinfo.Create();
  5854. commonHelper.UpdateRelationOrder(entity.ctid);
  5855. CeErpSukuraData.createInfo(entity.ctid, 4);
  5856. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  5857. {
  5858. commonHelper.sendCytExpress(exinfo);
  5859. }
  5860. //不处理
  5861. }
  5862. else
  5863. {
  5864. entity.UpdateTime = DateTime.Now;
  5865. entity.LastBillCpCode = cpCode;
  5866. entity.LastBillWaybillCode = curUseWayBillCode;
  5867. entity.Update();
  5868. string errmsg = commonHelper.KeepChinese(apires);
  5869. var res_objz = new
  5870. {
  5871. restype = 0,
  5872. data = "打单后发货失败"
  5873. };
  5874. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5875. returnSuccess(ro_jsonz);
  5876. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5877. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5878. return;
  5879. }
  5880. }
  5881. }
  5882. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5883. {
  5884. string ctids = GetPostString("ctids");
  5885. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5886. List<string> list = new List<string>();
  5887. List<string> send_list = new List<string>();
  5888. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5889. CeErpTrade ceErpTrade = new CeErpTrade();
  5890. //可合包的合并一起发货
  5891. if (dt == null && string.IsNullOrEmpty(ctids))
  5892. {
  5893. var res_objz = new
  5894. {
  5895. restype = 0,
  5896. data = "打单后发货失败"
  5897. };
  5898. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5899. returnSuccess(ro_jsonz);
  5900. return;
  5901. }
  5902. if (!string.IsNullOrEmpty(ctids))
  5903. {
  5904. StringBuilder sql = new StringBuilder();
  5905. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5906. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5907. }
  5908. foreach (DataRow row in dt.Rows)
  5909. {
  5910. list.Add("'" + row["ctid"] + "'");
  5911. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5912. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5913. if (ctid.IndexOf("N") != -1)
  5914. {
  5915. apires = "发货成功";
  5916. }
  5917. else
  5918. {
  5919. if (!send_list.Contains(ceErpTrade.tid))
  5920. {
  5921. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode, ctid);
  5922. }
  5923. else
  5924. {
  5925. apires = "发货成功";
  5926. }
  5927. }
  5928. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5929. {
  5930. send_list.Add(ceErpTrade.tid);
  5931. try
  5932. {
  5933. btnType = "待发货";
  5934. ceErpTradeCell.OutSid = curUseWayBillCode;
  5935. ceErpTradeCell.OrderState = 7;
  5936. ceErpTradeCell.IsUrgency = false;
  5937. ceErpTradeCell.LastBillCpCode = "";
  5938. ceErpTradeCell.LastBillWaybillCode = "";
  5939. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5940. ceErpTradeCell.IsReturn = 0;
  5941. ceErpTradeCell.MemoOpt = 0;
  5942. ceErpTradeCell.UpdateTime = DateTime.Now;
  5943. ceErpTradeCell.Update();
  5944. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5945. //还要插入快递信息到 快递信息表
  5946. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5947. exinfo.tid = ceErpTradeCell.ctid;
  5948. exinfo.out_sid = curUseWayBillCode;
  5949. exinfo.company_code = cpCode;
  5950. exinfo.company_name = cpName;
  5951. exinfo.supplierUserName = supplierName;
  5952. exinfo.deliveryType = "发货成功";
  5953. exinfo.print_time = DateTime.Now;
  5954. exinfo.printUser = CurrentUser.UserName;
  5955. exinfo.postData = pData_str;
  5956. exinfo.Create();
  5957. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5958. CeErpSukuraData.createInfo(ctid, 4);
  5959. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5960. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80 || entity.SupplierId == 126)
  5961. {
  5962. commonHelper.sendCytExpress(exinfo);
  5963. }
  5964. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5965. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5966. }
  5967. catch (Exception ex)
  5968. {
  5969. XLog.SaveLog(0, "发货成功后更新数据失败," + ex);
  5970. }
  5971. }
  5972. else
  5973. {
  5974. ceErpTradeCell.UpdateTime = DateTime.Now;
  5975. ceErpTradeCell.LastBillCpCode = cpCode;
  5976. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5977. ceErpTradeCell.Update();
  5978. string errmsg = commonHelper.KeepChinese(apires);
  5979. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5980. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5981. }
  5982. }
  5983. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5984. }
  5985. }
  5986. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5987. var res_obj = new
  5988. {
  5989. restype = 1,
  5990. data = pData_str,
  5991. errorMsg
  5992. };
  5993. string ro_json = JsonConvert.SerializeObject(res_obj);
  5994. ReturnSuccess(ro_json);
  5995. return;
  5996. }
  5997. }
  5998. private string GetUTF8String(byte[] vs)
  5999. {
  6000. throw new NotImplementedException();
  6001. }
  6002. public void set_erp_printwaybill_cn()
  6003. {
  6004. if (UrlPostParmsCheck("ctid"))
  6005. {
  6006. string ctid = GetPostString("ctid");
  6007. string cpCode = GetPostString("cpcode");
  6008. string cpName = GetPostString("cpname");
  6009. string tempUrl = GetPostString("tempurl");
  6010. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6011. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  6012. //string res = taobaoHelper.test();
  6013. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6014. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  6015. {
  6016. int sidx = res.IndexOf("errorMsg");
  6017. int eidx = res.IndexOf("}");
  6018. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  6019. var res_objzxx = new
  6020. {
  6021. restype = 0,
  6022. data = msg
  6023. };
  6024. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  6025. returnSuccess(ro_jsonzxx);
  6026. //returnErrorMsg(msg);
  6027. return;
  6028. }
  6029. int idx = res.IndexOf("waybillCode");
  6030. int idx2 = res.IndexOf("printData");
  6031. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  6032. string eid = GetPostString("ctid");
  6033. CeErpTradeCell entity = null;
  6034. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6035. if (entity != null)
  6036. {
  6037. string osid = entity.OutSid;
  6038. entity.OutSid = osid + "," + outsid;
  6039. entity.FinishDeliveryTime = DateTime.Now;
  6040. entity.OrderState = 7;
  6041. entity.UpdateTime = DateTime.Now;
  6042. entity.IsReturn = 0;
  6043. entity.Update();
  6044. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  6045. exinfo.tid = entity.ctid;
  6046. exinfo.out_sid = outsid;
  6047. exinfo.company_code = cpCode;
  6048. exinfo.company_name = cpName;
  6049. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  6050. exinfo.deliveryType = "发货成功";
  6051. exinfo.print_time = DateTime.Now;
  6052. exinfo.printUser = CurrentUser.UserName;
  6053. exinfo.Create();
  6054. if (entity.SupplierId == 64 || entity.SupplierId == 80 || entity.SupplierId == 126)
  6055. {
  6056. commonHelper.sendCytExpress(exinfo);
  6057. }
  6058. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  6059. }
  6060. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  6061. var res_objz = new
  6062. {
  6063. restype = 1,
  6064. data = res
  6065. };
  6066. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  6067. returnSuccess(ro_jsonz);
  6068. //ReturnSuccess(res);
  6069. }
  6070. }
  6071. ////打单,打印面单 获取面单号
  6072. //public void set_erp_printwaybill()
  6073. //{
  6074. // if (UrlPostParmsCheck("ctid"))
  6075. // {
  6076. // string ctid = GetPostString("ctid");
  6077. // string cpCode = GetPostString("cpcode");
  6078. // string tempUrl = GetPostString("tempurl");
  6079. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  6080. // //string res = taobaoHelper.test();
  6081. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  6082. // if (res.IndexOf("error_response") != -1)
  6083. // {
  6084. // int sidx = res.IndexOf("sub_msg");
  6085. // int eidx = res.IndexOf("request_id");
  6086. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  6087. // returnErrorMsg(msg);
  6088. // return;
  6089. // }
  6090. // int idx = res.IndexOf("waybill_code");
  6091. // int idx2 = res.IndexOf("}]}");
  6092. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  6093. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  6094. // ReturnSuccess(res);
  6095. // }
  6096. //}
  6097. public void cancel_erp_aftersale()
  6098. {
  6099. if (UrlPostParmsCheck("ctid"))
  6100. {
  6101. string eid = GetPostString("ctid");
  6102. CeErpTradeCell entity = null;
  6103. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6104. if (entity != null)
  6105. {
  6106. //有过处理的售后,取消也不能删除 售 字,保留
  6107. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  6108. {
  6109. entity.AfterSaleState = 4;
  6110. }
  6111. else
  6112. entity.AfterSaleState = 0;
  6113. entity.UpdateTime = DateTime.Now;
  6114. entity.Update();
  6115. returnSuccessMsg("操作成功!");
  6116. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  6117. return;
  6118. }
  6119. returnErrorMsg("找不到订单记录");
  6120. }
  6121. }
  6122. public void get_erp_aftersalelist()
  6123. {
  6124. DataStruct dStruct = GetPostStruct();
  6125. List<string> lw = new List<string>();
  6126. int st = GetInt("st");
  6127. string tid = GetPostString("ctid");
  6128. if (st == 3)
  6129. {
  6130. if (tid.Length > 0)
  6131. {
  6132. string select_tid = getTidByCtid(tid);
  6133. lw.Add(string.Format("tid='{0}'", select_tid));
  6134. }
  6135. }
  6136. else
  6137. {
  6138. if (tid.Length > 0)
  6139. {
  6140. string select_tid = getTidByCtid(tid);
  6141. lw.Add(string.Format("tid='{0}'", select_tid));
  6142. }
  6143. }
  6144. string shopname = GetPostString("shopname");
  6145. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6146. string buyernick = GetPostString("buyer_nick");
  6147. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  6148. string sellermemo = GetPostString("seller_memo");
  6149. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6150. string orderState = GetPostString("orderState");
  6151. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  6152. string afterState = GetPostString("afterstate");
  6153. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6154. string date1 = GetPostString("date1");
  6155. string date2 = GetPostString("date2");
  6156. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6157. if (dw.Length > 0) lw.Add(dw);
  6158. string price1 = GetPostString("price1");
  6159. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6160. string price2 = GetPostString("price2");
  6161. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6162. //lw.Add(string.Format("IsRefund!={0}", 1));
  6163. string reason = GetPostString("reason");
  6164. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6165. string method = GetPostString("method");
  6166. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6167. string handler = GetPostString("handler");
  6168. if (handler.Length > 0)
  6169. {
  6170. lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6171. }
  6172. string handledate1 = GetPostString("handledate1");
  6173. string handledate2 = GetPostString("handledate2");
  6174. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6175. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6176. string finish1 = GetPostString("finishdate1");
  6177. string finish2 = GetPostString("finishdate2");
  6178. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6179. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6180. string afterdate1 = GetPostString("afterdate1");
  6181. string afterdate2 = GetPostString("afterdate2");
  6182. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6183. if (afterDate.Length > 0) lw.Add(afterDate);
  6184. string supplier = GetPostString("supplier");
  6185. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6186. string responsible = GetPostString("responsibleman");
  6187. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6188. string customer = GetPostString("customer");
  6189. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6190. string design = GetPostString("design");
  6191. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6192. string afterMemoType = GetPostString("aftermemotype");
  6193. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6194. string posCode = CurrentUser.UserPost.Post.Code;
  6195. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6196. //{
  6197. // string vstate = GetPostString("vstate");
  6198. // if (vstate.Length > 0)
  6199. // {
  6200. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6201. // }
  6202. // if (posCode == "Supplier")
  6203. // {
  6204. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6205. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6206. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6207. // }
  6208. // else
  6209. // {
  6210. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6211. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6212. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6213. // {
  6214. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6215. // }
  6216. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6217. // {
  6218. // int orgid = CurrentUser.UserPost.OrgID;
  6219. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6220. // }
  6221. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6222. // {
  6223. // string shopid = CurrentUser.User.pemShop;
  6224. // lw.Add(string.Format("shopId in ({0})", shopid));
  6225. // }
  6226. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6227. // //{
  6228. // // int org_id = CurrentUser.UserPost.OrgID;
  6229. // // lw.Add(string.Format("OrgID={0}", org_id));
  6230. // //}
  6231. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6232. // }
  6233. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6234. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6235. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6236. //}
  6237. if (st == 5)
  6238. {
  6239. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6240. {
  6241. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6242. {
  6243. string shopid = CurrentUser.User.pemShop;
  6244. lw.Add(string.Format("shopId in ({0})", shopid));
  6245. }
  6246. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6247. {
  6248. int mrOrgid = CurrentUser.UserPost.OrgID;
  6249. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6250. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6251. }
  6252. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6253. //{
  6254. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6255. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6256. //}
  6257. else
  6258. {
  6259. string userIdStr = "";
  6260. if (posCode == "CustomerService")
  6261. {
  6262. userIdStr = CurrentUser.UserID + "_k";
  6263. }
  6264. else if (posCode == "Designer" || posCode == "wxDesigner")
  6265. {
  6266. userIdStr = CurrentUser.UserID + "_s";
  6267. }
  6268. else if (posCode == "Place")
  6269. {
  6270. userIdStr = CurrentUser.UserID + "_x";
  6271. }
  6272. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6273. }
  6274. }
  6275. string placedate1 = GetPostString("placedate1");
  6276. string placedate2 = GetPostString("placedate2");
  6277. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6278. if (dwplace.Length > 0) lw.Add(dwplace);
  6279. string supState = GetPostString("supState");
  6280. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6281. string searchType = GetPostString("searchType");
  6282. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6283. {
  6284. lw.Add(string.Format("BackNum>1"));
  6285. }
  6286. lw.Add(string.Format("AfterSaleState>0"));
  6287. if (ex_psize > 0)
  6288. {
  6289. if (CurrentUser.UserPost.Post.Code == "Finance")
  6290. dStruct.Order = "pay_time desc";
  6291. else
  6292. dStruct.Order = "HandleTime desc";
  6293. }
  6294. else
  6295. dStruct.Order = "HandleTime desc";
  6296. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6297. DataTable dt = WebCache.GetData("view_test", dStruct);
  6298. writeGridDataTableJson(dStruct.TotalCount, dt);
  6299. }
  6300. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6301. //{
  6302. // lw.Add(string.Format("AfterSaleState=4"));
  6303. // string code = CurrentUser.UserPost.Post.Code;
  6304. // if (code == "CustomerService")
  6305. // {
  6306. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6307. // }
  6308. // else if (code == "Designer" || code == "DesignerMr")
  6309. // {
  6310. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6311. // }
  6312. // else if (code == "Place" || code == "PlaceMr")
  6313. // {
  6314. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6315. // }
  6316. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6317. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6318. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6319. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6320. //}
  6321. //else //处理中的售后,待处理和处理中合并
  6322. //{
  6323. // if (afterState.Length <= 0)
  6324. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6325. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6326. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6327. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6328. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6329. //}
  6330. }
  6331. public void get_erp_disagreeftersalelist()
  6332. {
  6333. DataStruct dStruct = GetPostStruct();
  6334. List<string> lw = new List<string>();
  6335. int st = 2;
  6336. string tid = GetPostString("ctid");
  6337. if (tid.Length > 0)
  6338. {
  6339. string select_tid = getTidByCtid(tid);
  6340. lw.Add(string.Format("tid='{0}'", select_tid));
  6341. }
  6342. string shopname = GetPostString("shopname");
  6343. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6344. string buyernick = GetPostString("buyer_nick");
  6345. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6346. string sellermemo = GetPostString("seller_memo");
  6347. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6348. string orderState = GetPostString("orderState");
  6349. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6350. string afterState = GetPostString("afterstate");
  6351. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6352. string date1 = GetPostString("date1");
  6353. string date2 = GetPostString("date2");
  6354. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6355. if (dw.Length > 0) lw.Add(dw);
  6356. string price1 = GetPostString("price1");
  6357. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6358. string price2 = GetPostString("price2");
  6359. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6360. //lw.Add(string.Format("IsRefund!={0}", 1));
  6361. string reason = GetPostString("reason");
  6362. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6363. string method = GetPostString("method");
  6364. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6365. string handler = GetPostString("handler");
  6366. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6367. string handledate1 = GetPostString("handledate1");
  6368. string handledate2 = GetPostString("handledate2");
  6369. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6370. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6371. string afterdate1 = GetPostString("afterdate1");
  6372. string afterdate2 = GetPostString("afterdate2");
  6373. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6374. if (afterDate.Length > 0) lw.Add(afterDate);
  6375. string backdate1 = GetPostString("backdate1");
  6376. string backdate2 = GetPostString("backdate2");
  6377. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6378. if (backDate.Length > 0) lw.Add(backDate);
  6379. string supplier = GetPostString("supplier");
  6380. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6381. string responsible = GetPostString("responsibleman");
  6382. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6383. string customer = GetPostString("customer");
  6384. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6385. string design = GetPostString("design");
  6386. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6387. string afterSaleMemo = GetPostString("afterSaleMemo");
  6388. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6389. string afterMemoType = GetPostString("aftermemotype");
  6390. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6391. string aftersakereason = GetPostString("aftersakereason");
  6392. if (aftersakereason.Length > 0)
  6393. {
  6394. if (aftersakereason == "1")
  6395. {
  6396. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6397. }
  6398. if (aftersakereason == "2")
  6399. {
  6400. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6401. }
  6402. }
  6403. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6404. string poscode = CurrentUser.UserPost.Post.Code;
  6405. if (poscode != "SysAdmin")
  6406. {
  6407. string shopid = CurrentUser.User.pemShop;
  6408. lw.Add(string.Format("shopId in ({0})", shopid));
  6409. }
  6410. string searchType = GetPostString("searchType");
  6411. if (searchType == "wait")
  6412. {
  6413. lw.Add(string.Format("HandleTime is null"));
  6414. }
  6415. if (searchType == "handling")
  6416. {
  6417. lw.Add(string.Format("HandleTime is not null "));
  6418. }
  6419. if (searchType == "back" || searchType == "puBack")
  6420. {
  6421. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6422. }
  6423. if (searchType == "reBack")
  6424. {
  6425. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6426. }
  6427. if (searchType == "moreBack")
  6428. {
  6429. lw.Add(string.Format("backNum > 1"));
  6430. }
  6431. lw.Add(string.Format("(AfterSaleState=5)"));
  6432. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6433. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6434. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6435. writeGridDataTableJson(dStruct.TotalCount, dt);
  6436. }
  6437. public void get_erp_handlingaftersalelist()
  6438. {
  6439. DataStruct dStruct = GetPostStruct();
  6440. List<string> lw = new List<string>();
  6441. int st = 2;
  6442. string tid = GetPostString("ctid");
  6443. if (tid.Length > 0)
  6444. {
  6445. string select_tid = getTidByCtid(tid);
  6446. lw.Add(string.Format("tid='{0}'", select_tid));
  6447. }
  6448. string shopname = GetPostString("shopname");
  6449. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6450. string buyernick = GetPostString("buyer_nick");
  6451. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6452. string sellermemo = GetPostString("seller_memo");
  6453. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6454. string orderState = GetPostString("orderState");
  6455. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6456. string searchType = GetPostString("searchType");
  6457. string afterState = GetPostString("afterstate");
  6458. if (searchType != "documentary")
  6459. {
  6460. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6461. }
  6462. string date1 = GetPostString("date1");
  6463. string date2 = GetPostString("date2");
  6464. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6465. if (dw.Length > 0) lw.Add(dw);
  6466. string price1 = GetPostString("price1");
  6467. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6468. string price2 = GetPostString("price2");
  6469. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6470. //lw.Add(string.Format("IsRefund!={0}", 1));
  6471. string reason = GetPostString("reason");
  6472. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6473. string method = GetPostString("method");
  6474. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6475. string handler = GetPostString("handler");
  6476. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6477. string handledate1 = GetPostString("handledate1");
  6478. string handledate2 = GetPostString("handledate2");
  6479. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6480. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6481. string afterdate1 = GetPostString("afterdate1");
  6482. string afterdate2 = GetPostString("afterdate2");
  6483. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6484. if (afterDate.Length > 0) lw.Add(afterDate);
  6485. string supplier = GetPostString("supplier");
  6486. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6487. string responsible = GetPostString("responsibleman");
  6488. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6489. string customer = GetPostString("customer");
  6490. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6491. string design = GetPostString("design");
  6492. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6493. string afterSaleMemo = GetPostString("afterSaleMemo");
  6494. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6495. string afterMemoType = GetPostString("aftermemotype");
  6496. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6497. string afterresult = GetPostString("afterresult");
  6498. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6499. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6500. string poscode = CurrentUser.UserPost.Post.Code;
  6501. if (poscode != "SysAdmin")
  6502. {
  6503. string shopid = CurrentUser.User.pemShop;
  6504. lw.Add(string.Format("shopId in ({0})", shopid));
  6505. }
  6506. if (searchType == "wait")
  6507. {
  6508. lw.Add(string.Format("HandleTime is null"));
  6509. }
  6510. if (searchType == "documentary")
  6511. {
  6512. lw.Add(string.Format(" AfterSaleState > 2 AND HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' AND AfterSalSend = 0 "));
  6513. afterState = "2";
  6514. }
  6515. if (searchType == "handling")
  6516. {
  6517. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6518. }
  6519. if (searchType == "back" || searchType == "puBack")
  6520. {
  6521. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6522. }
  6523. if (searchType == "reBack")
  6524. {
  6525. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6526. }
  6527. if (afterState.Length <= 0)
  6528. {
  6529. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6530. }
  6531. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6532. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6533. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6534. writeGridDataTableJson(dStruct.TotalCount, dt);
  6535. }
  6536. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6537. //public void get_erp_back_handlingaftersalelist()
  6538. //{
  6539. // DataStruct dStruct = GetPostStruct();
  6540. // List<string> lw = new List<string>();
  6541. // string tid = GetPostString("ctid");
  6542. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6543. // string shopname = GetPostString("shopname");
  6544. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6545. // string buyernick = GetPostString("buyer_nick");
  6546. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6547. // string sellermemo = GetPostString("seller_memo");
  6548. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6549. // string orderState = GetPostString("orderState");
  6550. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6551. // string afterState = GetPostString("afterstate");
  6552. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6553. // string date1 = GetPostString("date1");
  6554. // string date2 = GetPostString("date2");
  6555. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6556. // if (dw.Length > 0) lw.Add(dw);
  6557. // string price1 = GetPostString("price1");
  6558. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6559. // string price2 = GetPostString("price2");
  6560. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6561. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6562. // string reason = GetPostString("reason");
  6563. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6564. // string method = GetPostString("method");
  6565. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6566. // string handler = GetPostString("handler");
  6567. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6568. // string handledate1 = GetPostString("handledate1");
  6569. // string handledate2 = GetPostString("handledate2");
  6570. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6571. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6572. // string afterdate1 = GetPostString("afterdate1");
  6573. // string afterdate2 = GetPostString("afterdate2");
  6574. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6575. // if (afterDate.Length > 0) lw.Add(afterDate);
  6576. // string supplier = GetPostString("supplier");
  6577. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6578. // string responsible = GetPostString("responsibleman");
  6579. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6580. // string customer = GetPostString("customer");
  6581. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6582. // string design = GetPostString("design");
  6583. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6584. // string afterMemoType = GetPostString("aftermemotype");
  6585. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6586. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6587. // if (afterState.Length <= 0)
  6588. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6589. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6590. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6591. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6592. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6593. //}
  6594. public void get_erp_aftersaleverifylist()
  6595. {
  6596. DataStruct dStruct = GetPostStruct();
  6597. List<string> lw = new List<string>();
  6598. string tid = GetPostString("ctid");
  6599. if (tid.Length > 0)
  6600. {
  6601. string select_tid = getTidByCtid(tid);
  6602. lw.Add(string.Format("otid='{0}'", select_tid));
  6603. }
  6604. string shopname = GetPostString("shopname");
  6605. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6606. string buyernick = GetPostString("buyer_nick");
  6607. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6608. string sellermemo = GetPostString("seller_memo");
  6609. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6610. string orderState = GetPostString("orderState");
  6611. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6612. //lw.Add(string.Format("IsRefund!={0}", 1));
  6613. string reason = GetPostString("reason");
  6614. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6615. string method = GetPostString("method");
  6616. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6617. string handler = GetPostString("handler");
  6618. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6619. string handledate1 = GetPostString("handledate1");
  6620. string handledate2 = GetPostString("handledate2");
  6621. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6622. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6623. string finish1 = GetPostString("finishdate1");
  6624. string finish2 = GetPostString("finishdate2");
  6625. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6626. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6627. string supplier = GetPostString("supplier");
  6628. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6629. string responsible = GetPostString("responsibleman");
  6630. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6631. string posCode = CurrentUser.UserPost.Post.Code;
  6632. string vstate = GetPostString("vstate");
  6633. if (vstate.Length > 0)
  6634. {
  6635. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6636. }
  6637. if (posCode == "Supplier")
  6638. {
  6639. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6640. lw.Add(string.Format("VerifyState = 0"));
  6641. lw.Add("type = 1");
  6642. lw.Add(string.Format("AfterSaleState={0}", 3));
  6643. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6644. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6645. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6646. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6647. writeGridDataTableJson(dStruct.TotalCount, dt);
  6648. }
  6649. else if (posCode == "logistics")
  6650. {
  6651. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6652. lw.Add(string.Format("VerifyState = 0"));
  6653. lw.Add("type = 2");
  6654. lw.Add(string.Format("AfterSaleState={0}", 3));
  6655. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6656. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6657. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6658. writeGridDataTableJson(dStruct.TotalCount, dt);
  6659. }
  6660. else
  6661. {
  6662. lw.Add(string.Format("(AfterSaleState = 3)"));
  6663. lw.Add("type = 0");
  6664. string reasonState = GetPostString("reasonState");
  6665. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "Summarize" || posCode == "Finance")
  6666. {
  6667. if (reasonState == "2")
  6668. {
  6669. lw.Add("VerifyState = 3");
  6670. }
  6671. else if (reasonState == "1")
  6672. {
  6673. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6674. }
  6675. else
  6676. {
  6677. lw.Add("VerifyState in (0,3)");
  6678. }
  6679. //不加条件,可以看全部
  6680. }
  6681. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6682. {
  6683. int orgid = CurrentUser.UserPost.OrgID;
  6684. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6685. if (string.IsNullOrEmpty(manageOrgId))
  6686. {
  6687. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6688. }
  6689. else
  6690. {
  6691. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6692. }
  6693. if (reasonState == "1")
  6694. {
  6695. lw.Add("VerifyState = 3");
  6696. }
  6697. else if (reasonState == "2")
  6698. {
  6699. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6700. }
  6701. else
  6702. {
  6703. }
  6704. }
  6705. else
  6706. {
  6707. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6708. }
  6709. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6710. //{
  6711. // int org_id = CurrentUser.UserPost.OrgID;
  6712. // lw.Add(string.Format("OrgID={0}", org_id));
  6713. //}
  6714. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6715. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6716. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6717. writeGridDataTableJson(dStruct.TotalCount, dt);
  6718. }
  6719. }
  6720. public void get_erp_finishaftersalelist()
  6721. {
  6722. DataStruct dStruct = GetPostStruct();
  6723. List<string> lw = new List<string>();
  6724. int st = 4;
  6725. string tid = GetPostString("ctid");
  6726. if (tid.Length > 0)
  6727. {
  6728. string select_tid = getTidByCtid(tid);
  6729. lw.Add(string.Format("otid='{0}'", select_tid));
  6730. }
  6731. string shopname = GetPostString("shopname");
  6732. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6733. //lw.Add(string.Format("IsRefund!={0}", 1));
  6734. string reason = GetPostString("reason");
  6735. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6736. string method = GetPostString("method");
  6737. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6738. string buyernick = GetPostString("buyer_nick");
  6739. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6740. string handler = GetPostString("handler");
  6741. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6742. string handledate1 = GetPostString("handledate1");
  6743. string handledate2 = GetPostString("handledate2");
  6744. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6745. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6746. string finish1 = GetPostString("finishdate1");
  6747. string finish2 = GetPostString("finishdate2");
  6748. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6749. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6750. string supplier = GetPostString("supplier");
  6751. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6752. string responsible = GetPostString("responsibleman");
  6753. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6754. string vstate = GetPostString("vstate");
  6755. if (vstate.Length > 0)
  6756. {
  6757. if ("3".Equals(vstate))
  6758. {
  6759. lw.Add(string.Format("IsTem=1"));
  6760. }
  6761. else
  6762. {
  6763. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6764. }
  6765. }
  6766. lw.Add(string.Format("AfterSaleState=4"));
  6767. string code = CurrentUser.UserPost.Post.Code;
  6768. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6769. {
  6770. //不加条件,可以看全部
  6771. }
  6772. else if (code == "Supplier")
  6773. {
  6774. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6775. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6776. lw.Add("type = 1");
  6777. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6778. }
  6779. else if (code == "logistics")
  6780. {
  6781. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6782. lw.Add("type = 2");
  6783. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6784. }
  6785. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMaster" || CurrentUser.UserPost.Post.Code == "CustomerMr" || CurrentUser.UserPost.Post.Code == "DesignerMr" || CurrentUser.UserPost.Post.Code == "wxDesignerMr" || CurrentUser.UserPost.Post.Code == "Designerhd" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  6786. {
  6787. lw.Add("type = 0");
  6788. int orgid = CurrentUser.UserPost.OrgID;
  6789. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6790. if (string.IsNullOrEmpty(manageOrgIds))
  6791. {
  6792. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6793. }
  6794. else
  6795. {
  6796. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6797. }
  6798. }
  6799. else
  6800. {
  6801. lw.Add("type = 0");
  6802. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6803. }
  6804. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6805. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6806. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6807. writeGridDataTableJson(dStruct.TotalCount, dt);
  6808. }
  6809. public void handle_erp_aftersale()
  6810. {
  6811. if (UrlPostParmsCheck("ctid"))
  6812. {
  6813. string eid = GetPostString("ctid");
  6814. string responStr = GetPostString("AfterSaleResponsible");
  6815. if (responStr.Length <= 0)
  6816. {
  6817. returnErrorMsg("售后责任人不能为空");
  6818. return;
  6819. }
  6820. bool isDesign = false;
  6821. double designFree = 0.00;
  6822. int responsibleId = 0;
  6823. CeErpTradeCell entity = null;
  6824. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6825. if (entity != null)
  6826. {
  6827. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6828. string afterMethod = GetPostString("AfterSaleMethod");
  6829. if (isNeedNewOrder == 1)
  6830. {
  6831. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6832. bool ishav = true;
  6833. if (newentity == null)
  6834. {
  6835. newentity = entity.Clone() as CeErpTradeCell;
  6836. ishav = false;
  6837. newentity.ctid = "S_" + entity.ctid;
  6838. newentity.OrderState = 0;
  6839. //唯一标识
  6840. newentity.OrderSn = newentity.ctid;
  6841. string orderSn = commonHelper.generateDateTimeRandomNos();
  6842. if (orderSn != "")
  6843. {
  6844. newentity.OrderSn = orderSn;
  6845. }
  6846. }
  6847. newentity.UpdateTime = DateTime.Now;
  6848. newentity.AfterSaleState = 0;
  6849. newentity.AfterSaleMethod = afterMethod;
  6850. if (!ishav)
  6851. {
  6852. string memo_str = newentity.seller_memo;
  6853. memo_str = memo_str.Replace("(", "(");
  6854. memo_str = memo_str.Replace(")", ")");
  6855. int sIndex = memo_str.IndexOf("(");
  6856. int eIndex = memo_str.IndexOf(")");
  6857. if (sIndex == -1 || eIndex == -1)
  6858. {
  6859. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6860. return;
  6861. }
  6862. string first = memo_str.Substring(0, sIndex + 1);
  6863. string memoCtid = newentity.OrderSn;
  6864. //if (memoCtid.IndexOf("C") != -1)
  6865. //{
  6866. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6867. //if (CIdx.IndexOf("+") != -1)
  6868. //{
  6869. //CIdx = "C" + CIdx.Split('+')[1];
  6870. //}
  6871. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6872. //}
  6873. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6874. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6875. string newMemo = first + memoCtid + last;
  6876. newentity.seller_memo = newMemo;
  6877. newentity.FinishPlaceTime = null;
  6878. newentity.UnusualTag = 0;
  6879. newentity.UnusualCon = "";
  6880. newentity.UnusualTime = null;
  6881. newentity.AfterSaleMemo = "";
  6882. newentity.AfterSaleMethod = afterMethod;
  6883. newentity.AfterSalePreTime = null;
  6884. newentity.AfterSaleReason = "";
  6885. newentity.AfterSaleResponsible = "";
  6886. newentity.AfterSaleState = 0;
  6887. newentity.AfterSaleTime = null;
  6888. newentity.AfterSaleUserId = 0;
  6889. newentity.AfterSaleSupplierState = 0;
  6890. newentity.LastBillWaybillCode = "";
  6891. newentity.LastBillCpCode = "";
  6892. newentity.FinishAfterSaleTime = null;
  6893. newentity.HandleTime = null;
  6894. newentity.IsSF = 0;
  6895. newentity.IsOldCustomer = 0;
  6896. newentity.UrgencyTime = null;
  6897. newentity.ResponsibleUserId = "";
  6898. newentity.IsVerifyToSupplier = false;
  6899. newentity.payment = 0;
  6900. newentity.CheckMemo = "";
  6901. newentity.OutSid = "";
  6902. newentity.CheckOrderTime = null;
  6903. newentity.MemoOpt = 0;
  6904. newentity.IsReturn = 0;
  6905. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6906. }
  6907. newentity.isAfterSaleOrder = 1;
  6908. newentity.IsRefund = 0;
  6909. string receiveMobile = GetPostString("receiver_mobile");
  6910. if (receiveMobile.Length > 0)
  6911. {
  6912. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6913. if (trade != null)
  6914. {
  6915. trade.receiver_name = GetPostString("receiver_name");
  6916. trade.receiver_mobile = receiveMobile;
  6917. trade.receiver_state = GetPostString("receiver_state");
  6918. trade.receiver_city = GetPostString("receiver_city");
  6919. trade.receiver_district = GetPostString("receiver_district");
  6920. trade.receiver_address = GetPostString("receiver_address");
  6921. newentity.IsOffLineOrder = 1;
  6922. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6923. }
  6924. }
  6925. string st = GetPostString("ToState");
  6926. if (st.Length > 0)
  6927. {
  6928. if (newentity.OrderState <= 3)
  6929. {
  6930. newentity.WaitDesignTime = DateTime.Now;
  6931. newentity.StartDesignTime = null;
  6932. newentity.FinishDesignTime = null;
  6933. newentity.OrderState = 3;
  6934. if (st == "下单员")
  6935. {
  6936. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6937. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6938. {
  6939. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6940. }
  6941. }
  6942. else
  6943. {
  6944. newentity.WaitDesignTime = DateTime.Now;
  6945. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6946. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6947. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6948. {
  6949. DataRow user = dt1.Rows[0];
  6950. //找主管
  6951. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6952. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6953. if (dt != null && dt.Rows.Count > 0)
  6954. {
  6955. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6956. newentity.DesignUserId = designMr;
  6957. string key = "aftersale_order_" + designMr;
  6958. if (RedisHelper.HasKey(key))
  6959. {
  6960. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6961. list.Add(newentity.ctid);
  6962. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6963. }
  6964. }
  6965. //账号正常
  6966. if (user["State"].ToString() == "0")
  6967. {
  6968. newentity.DesignUserId = entity.DesignUserId;
  6969. string key = "aftersale_order_" + entity.DesignUserId;
  6970. if (RedisHelper.HasKey(key))
  6971. {
  6972. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6973. list.Add(newentity.ctid);
  6974. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6975. }
  6976. }
  6977. }
  6978. }
  6979. }
  6980. if (entity.IsXianHuo == 1)
  6981. {
  6982. newentity.OrderState = 6;
  6983. entity.FinishPlaceTime = DateTime.Now;
  6984. }
  6985. }
  6986. if (ishav)
  6987. {
  6988. newentity.Update();
  6989. }
  6990. else
  6991. {
  6992. newentity.Create();
  6993. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6994. newCellExtend.ctid = newentity.ctid;
  6995. newCellExtend.orderFrom = 20;
  6996. newCellExtend.orderType = 30;
  6997. if (st == "下单员")
  6998. {
  6999. }
  7000. else
  7001. {
  7002. newCellExtend.ReprintTime = DateTime.Now;
  7003. }
  7004. newCellExtend.Create();
  7005. }
  7006. if (st != "下单员")
  7007. {
  7008. if (entity.DispatchSort == 2)
  7009. {
  7010. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  7011. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  7012. }
  7013. }
  7014. }
  7015. //处理售后扩展
  7016. string resIdStr = GetPostString("ResponsibleUserId");
  7017. string refundFees = GetPostString("refundFrees");
  7018. int IsComplain = GetPostInt("isComplain");
  7019. int IsBad = GetPostInt("isBad");
  7020. string IsOriginal = GetPostString("isOriginal");
  7021. double diffResultPrice = GetPostDouble("diffResultPrice");
  7022. string textResult = GetPostString("textResult");
  7023. string supplierResponsible = GetPostString("supplierResponsible");
  7024. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  7025. if (ceErpTradeAfterSaleExtend == null)
  7026. {
  7027. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7028. ceErpTradeAfterSaleExtend.tid = eid;
  7029. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7030. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7031. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7032. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7033. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7034. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7035. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7036. ceErpTradeAfterSaleExtend.Create();
  7037. }
  7038. else
  7039. {
  7040. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  7041. {
  7042. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  7043. }
  7044. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  7045. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  7046. ceErpTradeAfterSaleExtend.TextResult = textResult;
  7047. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  7048. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  7049. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  7050. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  7051. ceErpTradeAfterSaleExtend.Update();
  7052. }
  7053. int gysid = GetPostInt("ResponsibleSupId");
  7054. if (entity.AfterSaleUserId == 0)
  7055. {
  7056. entity.AfterSaleUserId = CurrentUser.UserID;
  7057. }
  7058. entity.ResponsibleUserId = resIdStr;
  7059. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  7060. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  7061. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  7062. {
  7063. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7064. int backNum = 0;
  7065. if (number != null)
  7066. {
  7067. backNum = number.BackNum;
  7068. }
  7069. char[] separator = { ',' };
  7070. string[] sArray = resIdStr.Split(separator);
  7071. string[] refundFreeList = { };
  7072. if (refundFees.Length > 0)
  7073. {
  7074. refundFreeList = refundFees.Split(separator);
  7075. }
  7076. int index = -1;
  7077. List<int> responsibleIds = new List<int>();
  7078. foreach (string i in sArray)
  7079. {
  7080. index++;
  7081. if (i.Length <= 0) continue;
  7082. char[] separator2 = { '_' };
  7083. string idstr = i.Split(separator2)[0];
  7084. string idtype = i.Split(separator2)[1];
  7085. double refudFree = 0;
  7086. if (refundFreeList.Length > 0)
  7087. {
  7088. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  7089. }
  7090. if (idtype == "s")
  7091. {
  7092. isDesign = true;
  7093. designFree = refudFree;
  7094. }
  7095. int userId = Convert.ToInt32(idstr);
  7096. int type = 0;
  7097. if (idtype == "g")
  7098. {
  7099. type = 1;
  7100. }
  7101. if (idtype == "w")
  7102. {
  7103. type = 2;
  7104. }
  7105. if (idtype == "t")
  7106. {
  7107. type = 3;
  7108. }
  7109. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  7110. if (ceErpTradeResponsible == null)
  7111. {
  7112. ceErpTradeResponsible = new CeErpTradeResponsible();
  7113. ceErpTradeResponsible.tid = eid;
  7114. ceErpTradeResponsible.UserId = userId;
  7115. ceErpTradeResponsible.createdTime = DateTime.Now;
  7116. ceErpTradeResponsible.type = type;
  7117. if (type == 1)
  7118. {
  7119. ceErpTradeResponsible.IsSup = 1;
  7120. }
  7121. if (type == 2)
  7122. {
  7123. ceErpTradeResponsible.IsFlow = 1;
  7124. }
  7125. }
  7126. int state = 0;
  7127. //已认可的不需要再次认可
  7128. if (sArray.Length > 1 && ceErpTradeResponsible.VerifyState == 1)
  7129. {
  7130. state = 1;
  7131. }
  7132. ceErpTradeResponsible.RefundFee = refudFree;
  7133. ceErpTradeResponsible.VerifyState = state;
  7134. if (userId == 2125 || idtype == "w")
  7135. {
  7136. ceErpTradeResponsible.VerifyState = 1;
  7137. }
  7138. if (idtype == "w" && userId == 101)
  7139. {
  7140. ceErpTradeResponsible.VerifyState = state;
  7141. }
  7142. if (ceErpTradeResponsible.ID > 0)
  7143. {
  7144. ceErpTradeResponsible.Update();
  7145. }
  7146. else
  7147. {
  7148. ceErpTradeResponsible.Create();
  7149. }
  7150. if (isDesign)
  7151. {
  7152. responsibleId = ceErpTradeResponsible.ID;
  7153. }
  7154. responsibleIds.Add(ceErpTradeResponsible.ID);
  7155. }
  7156. CeErpTradeResponsible.ExecuteNonQuery(string.Format("update CE_ErpTradeResponsible set VerifyState =-1 where tid='" + eid + "' and ID NOT IN (" + string.Join(",", responsibleIds) + ")"));
  7157. CeErpTradeResponsible.NumByTid(backNum, eid);
  7158. }
  7159. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  7160. if (ceErpTradeCellExtend != null)
  7161. {
  7162. ceErpTradeCellExtend.returnVisit = 0;
  7163. ceErpTradeCellExtend.Update();
  7164. }
  7165. if (entity.HandleTime != null)
  7166. {
  7167. if (entity.AfterSaleState == 1)
  7168. {
  7169. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  7170. }
  7171. else
  7172. {
  7173. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  7174. }
  7175. }
  7176. else
  7177. {
  7178. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  7179. entity.HandleTime = DateTime.Now;
  7180. }
  7181. bool isCompale = false;
  7182. if (entity.AfterSaleState == 5)
  7183. {
  7184. isCompale = true;
  7185. entity.AfterSaleState = 3;
  7186. }
  7187. entity.AfterSaleSupplierState = 0;
  7188. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  7189. {
  7190. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  7191. }
  7192. string sImgs = GetPostString("img");
  7193. entity.AfterSaleSupplierImg = sImgs;
  7194. entity.supRefundType = GetPostString("supRefundType");
  7195. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  7196. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  7197. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  7198. entity.AfterSaleMemoType = GetPostString("MemoType");
  7199. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  7200. {
  7201. //entity.AfterSaleSupplierState = 2;
  7202. }
  7203. string df = GetPostString("DeductFee");
  7204. if (df == "")
  7205. {
  7206. df = "0";
  7207. }
  7208. string rf = GetPostString("RefundFee");
  7209. if (rf == "")
  7210. {
  7211. rf = "0";
  7212. }
  7213. string pm = GetPostString("AfterSalePayment");
  7214. if (pm == "")
  7215. {
  7216. pm = "0";
  7217. }
  7218. entity.AfterSalePayment = Convert.ToDouble(pm);
  7219. entity.DeductFee = Convert.ToDouble(df);
  7220. entity.RefundFee = Convert.ToDouble(rf);
  7221. entity.UpdateTime = DateTime.Now;
  7222. entity.Update();
  7223. string toState = GetPostString("ToState");
  7224. string original = GetPostString("isOriginal");
  7225. ApiVo apiVo = new ApiVo();
  7226. apiVo.orderNumber = entity.ctid;
  7227. apiVo.actionName = "afterDesign";
  7228. apiVo.orderRemarks = entity.AfterSaleMethod;
  7229. apiVo.reasonRemarks = entity.AfterSaleReason;
  7230. apiVo.isDesign = isDesign;
  7231. apiVo.designFree = designFree;
  7232. apiVo.responsibleId = responsibleId;
  7233. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7234. if (toState == "设计师")
  7235. {
  7236. apiVo.isOriginal = Convert.ToBoolean(original);
  7237. }
  7238. designHelper.API_WorkCore(apiVo);//afterDesign
  7239. CeErpMethod methodSql = new CeErpMethod();
  7240. methodSql.con = entity.AfterSaleMethod;
  7241. methodSql.addTime = DateTime.Now;
  7242. methodSql.Create();
  7243. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7244. CeErpMethod.ExecuteNonQuery(delsql);
  7245. if (isCompale)
  7246. {
  7247. aftersale_data_change(entity.ctid);
  7248. }
  7249. returnSuccessMsg("操作成功!");
  7250. return;
  7251. }
  7252. returnErrorMsg("找不到订单记录");
  7253. }
  7254. }
  7255. public void ins_erp_toresponsible()
  7256. {
  7257. if (UrlPostParmsCheck("ctid"))
  7258. {
  7259. string eid = GetPostString("ctid");
  7260. CeErpTradeCell entity = null;
  7261. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7262. if (entity != null)
  7263. {
  7264. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7265. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7266. {
  7267. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7268. return;
  7269. }
  7270. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7271. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7272. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7273. if (entity.AfterSalePreTime == null)
  7274. {
  7275. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7276. {
  7277. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7278. }
  7279. }
  7280. entity.AfterSalePreTime = DateTime.Now;
  7281. //预完成给售后主管审核客户问题直接完成
  7282. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7283. {
  7284. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7285. {
  7286. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7287. }
  7288. }
  7289. ceErpTradeAfterSaleExtend.DisagreeTime = null;
  7290. ceErpTradeAfterSaleExtend.Update();
  7291. entity.AfterSaleUserId = CurrentUser.UserID;
  7292. entity.AfterSaleState = 2;
  7293. entity.UpdateTime = DateTime.Now;
  7294. entity.Update();
  7295. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7296. aftersale_data_change(entity.ctid);
  7297. returnSuccessMsg("操作成功!");
  7298. return;
  7299. }
  7300. returnErrorMsg("找不到订单记录");
  7301. }
  7302. }
  7303. public void cancel_erp_aftersaleanddelnew()
  7304. {
  7305. if (UrlPostParmsCheck("ctid"))
  7306. {
  7307. string eid = GetPostString("ctid");
  7308. CeErpTradeCell entity = null;
  7309. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7310. if (entity != null)
  7311. {
  7312. entity.AfterSaleState = 0;
  7313. entity.AfterSaleReason = "";
  7314. entity.AfterSaleMethod = "";
  7315. entity.AfterSaleMemo = "";
  7316. entity.AfterSaleResponsible = "";
  7317. entity.ResponsibleUserId = "";
  7318. entity.DeductFee = 0;
  7319. entity.RefundFee = 0;
  7320. entity.IsArbitrate = 0;
  7321. CeErpTradeResponsible.DelByTid(eid, -1);
  7322. entity.Update();
  7323. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7324. if (after != null)
  7325. {
  7326. if (after.OrderState < 5)
  7327. CeErpTradeCell.DelByCtid("S_" + eid);
  7328. }
  7329. returnSuccessMsg("操作成功!");
  7330. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7331. return;
  7332. }
  7333. returnErrorMsg("找不到订单记录");
  7334. }
  7335. }
  7336. public void get_erp_aftersale_pregather()
  7337. {
  7338. List<string> lw = new List<string>();
  7339. int st = GetInt("st");
  7340. string tid = GetPostString("ctid");
  7341. if (tid.Length > 0)
  7342. {
  7343. string select_tid = getTidByCtid(tid);
  7344. lw.Add(string.Format("tid='{0}'", select_tid));
  7345. }
  7346. string shopname = GetPostString("shopname");
  7347. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7348. string buyernick = GetPostString("buyer_nick");
  7349. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7350. string sellermemo = GetPostString("seller_memo");
  7351. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7352. string orderState = GetPostString("orderState");
  7353. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7354. string reason = GetPostString("reason");
  7355. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7356. string method = GetPostString("method");
  7357. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7358. string handler = GetPostString("handler");
  7359. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7360. string handledate1 = GetPostString("handledate1");
  7361. string handledate2 = GetPostString("handledate2");
  7362. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7363. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7364. string supplier = GetPostString("supplier");
  7365. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7366. string responsible = GetPostString("responsibleman");
  7367. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7368. string customer = GetPostString("customer");
  7369. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7370. string design = GetPostString("design");
  7371. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7372. string afterMemoType = GetPostString("aftermemotype");
  7373. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7374. string afterSaleMemo = GetPostString("afterSaleMemo");
  7375. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7376. string afterresult = GetPostString("afterresult");
  7377. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7378. string poscode = CurrentUser.UserPost.Post.Code;
  7379. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7380. {
  7381. string shopid = CurrentUser.User.pemShop;
  7382. lw.Add(string.Format("shopId in ({0})", shopid));
  7383. }
  7384. var mainwhere = string.Join(" and ", lw.ToArray());
  7385. string ro_json = "";
  7386. string type = GetPostString("gather_type");
  7387. int number = 0;
  7388. if (poscode == "AfterSale")
  7389. {
  7390. //处理中
  7391. if (type == "Handling")
  7392. {
  7393. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7394. DataTable dt = null;
  7395. try
  7396. {
  7397. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7398. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7399. }
  7400. catch (Exception e)
  7401. {
  7402. dt = new DataTable();
  7403. }
  7404. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7405. return;
  7406. }
  7407. if (type == "Wait")
  7408. {
  7409. //待处理
  7410. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7411. DataTable dt1 = null;
  7412. try
  7413. {
  7414. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7415. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7416. }
  7417. catch (Exception e)
  7418. {
  7419. dt1 = new DataTable();
  7420. }
  7421. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7422. return;
  7423. }
  7424. if (type == "back")
  7425. {
  7426. //打回
  7427. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7428. DataTable dt2 = null;
  7429. try
  7430. {
  7431. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7432. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7433. }
  7434. catch (Exception e)
  7435. {
  7436. dt2 = new DataTable();
  7437. }
  7438. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7439. return;
  7440. }
  7441. if (type == "preCompletion")
  7442. {
  7443. //预完成
  7444. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7445. DataTable dt3 = null;
  7446. try
  7447. {
  7448. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7449. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7450. }
  7451. catch (Exception e)
  7452. {
  7453. dt3 = new DataTable();
  7454. }
  7455. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7456. return;
  7457. }
  7458. if (type == "documentary")
  7459. {
  7460. //跟单中
  7461. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7462. DataTable dt4 = null;
  7463. try
  7464. {
  7465. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7466. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7467. }
  7468. catch (Exception e)
  7469. {
  7470. dt4 = new DataTable();
  7471. }
  7472. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7473. return;
  7474. }
  7475. if (type == "reBack")
  7476. {
  7477. //被打回
  7478. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7479. DataTable dt1 = null;
  7480. try
  7481. {
  7482. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7483. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7484. }
  7485. catch (Exception e)
  7486. {
  7487. dt1 = new DataTable();
  7488. }
  7489. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7490. return;
  7491. }
  7492. }
  7493. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7494. {
  7495. if (type == "puBack")
  7496. {
  7497. //退回
  7498. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7499. DataTable dt = null;
  7500. try
  7501. {
  7502. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7503. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7504. }
  7505. catch (Exception e)
  7506. {
  7507. dt = new DataTable();
  7508. }
  7509. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7510. return;
  7511. }
  7512. if (type == "reBack")
  7513. {
  7514. //打回
  7515. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7516. DataTable dt1 = null;
  7517. try
  7518. {
  7519. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7520. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7521. }
  7522. catch (Exception e)
  7523. {
  7524. dt1 = new DataTable();
  7525. }
  7526. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7527. return;
  7528. }
  7529. if (type == "examEd")
  7530. {
  7531. //已审核
  7532. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7533. DataTable dt2 = null;
  7534. try
  7535. {
  7536. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7537. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7538. }
  7539. catch (Exception e)
  7540. {
  7541. dt2 = new DataTable();
  7542. }
  7543. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7544. return;
  7545. }
  7546. if (type == "waitExam")
  7547. {
  7548. //待审核
  7549. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7550. DataTable dt3 = null;
  7551. try
  7552. {
  7553. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7554. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7555. }
  7556. catch (Exception e)
  7557. {
  7558. dt3 = new DataTable();
  7559. }
  7560. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7561. return;
  7562. }
  7563. if (type == "Handling")
  7564. {
  7565. //处理中
  7566. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7567. DataTable dt4 = null;
  7568. try
  7569. {
  7570. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7571. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7572. }
  7573. catch (Exception e)
  7574. {
  7575. dt4 = new DataTable();
  7576. }
  7577. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7578. return;
  7579. }
  7580. if (type == "Wait")
  7581. {
  7582. //待处理
  7583. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7584. DataTable dt5 = null;
  7585. try
  7586. {
  7587. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7588. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7589. }
  7590. catch (Exception e)
  7591. {
  7592. dt5 = new DataTable();
  7593. }
  7594. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7595. return;
  7596. }
  7597. if (type == "documentary")
  7598. {
  7599. //跟单中
  7600. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate > 2 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSalSend = 0 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7601. DataTable dt6 = null;
  7602. try
  7603. {
  7604. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7605. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7606. }
  7607. catch (Exception e)
  7608. {
  7609. dt6 = new DataTable();
  7610. }
  7611. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7612. return;
  7613. }
  7614. }
  7615. returnSuccess(ro_json);
  7616. }
  7617. public void end_erp_aftersale()
  7618. {
  7619. if (UrlPostParmsCheck("ctid"))
  7620. {
  7621. string eid = GetPostString("ctid");
  7622. CeErpTradeCell entity = null;
  7623. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7624. if (entity != null)
  7625. {
  7626. string stype = GetPostString("stype");
  7627. string typeStr = stype;
  7628. entity.AfterSaleState = 4;
  7629. entity.FinishAfterSaleTime = DateTime.Now;
  7630. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7631. entity.Update();
  7632. ApiVo apiVo = new ApiVo();
  7633. apiVo.orderNumber = entity.ctid;
  7634. apiVo.actionName = "afterOver";
  7635. designHelper.API_WorkCore(apiVo); //afterOver
  7636. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7637. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7638. CeErpSukuraData.createInfo(entity.ctid, 8);
  7639. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7640. returnSuccessMsg("操作成功!");
  7641. return;
  7642. }
  7643. returnErrorMsg("找不到订单记录");
  7644. }
  7645. }
  7646. public void ins_erp_finishaftersale()
  7647. {
  7648. if (UrlPostParmsCheck("id"))
  7649. {
  7650. string eid = GetPostString("id");
  7651. CeErpTradeResponsible entity = null;
  7652. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7653. if (entity != null)
  7654. {
  7655. entity.VerifyState = 1;
  7656. entity.VerifyTime = DateTime.Now;
  7657. entity.Update();
  7658. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7659. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7660. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7661. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7662. if (dt.Rows.Count <= 0)
  7663. {
  7664. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7665. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7666. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7667. CeErpSukuraData.createInfo(entity.tid, 8);
  7668. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7669. {
  7670. CeErpDesignerBill.Del(entity.tid);
  7671. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7672. }
  7673. }
  7674. returnSuccessMsg("操作成功!");
  7675. return;
  7676. }
  7677. returnErrorMsg("找不到订单记录");
  7678. }
  7679. }
  7680. public void upd_erp_arbitrateaftersale()
  7681. {
  7682. if (UrlPostParmsCheck("id"))
  7683. {
  7684. string eid = GetPostString("id");
  7685. CeErpTradeResponsible entity = null;
  7686. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7687. if (entity != null)
  7688. {
  7689. entity.IsArbitrate = 1;
  7690. entity.ArbitradeMemo = GetPostString("reason");
  7691. entity.VerifyState = 2;
  7692. entity.Update();
  7693. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7694. if (tradecell != null)
  7695. {
  7696. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7697. tradecell.IsArbitrate = 1;
  7698. tradecell.Update();
  7699. }
  7700. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7701. returnSuccessMsg("操作成功!");
  7702. return;
  7703. }
  7704. returnErrorMsg("找不到订单记录");
  7705. }
  7706. }
  7707. public void upd_erp_backaftersale()
  7708. {
  7709. if (UrlPostParmsCheck("tid"))
  7710. {
  7711. string eid = GetPostString("tid");
  7712. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7713. int backNum = 0;
  7714. if (number != null)
  7715. {
  7716. backNum = number.BackNum;
  7717. }
  7718. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7719. CeErpTradeCell entity = null;
  7720. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7721. if (entity != null)
  7722. {
  7723. entity.AfterSaleBackReason = GetPostString("backreason");
  7724. entity.AfterSaleState = 1;
  7725. entity.AfterSaleSupplierState = 0;
  7726. entity.UpdateTime = DateTime.Now;
  7727. entity.Update();
  7728. returnSuccessMsg("操作成功!");
  7729. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7730. return;
  7731. }
  7732. returnErrorMsg("找不到订单记录");
  7733. }
  7734. }
  7735. public void get_erp_supplieraftersalelist()
  7736. {
  7737. DataStruct dStruct = GetPostStruct();
  7738. List<string> lw = new List<string>();
  7739. string tid = GetPostString("ctid");
  7740. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7741. string shopname = GetPostString("shopname");
  7742. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7743. string buyernick = GetPostString("buyer_nick");
  7744. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7745. string sellermemo = GetPostString("seller_memo");
  7746. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7747. string orderState = GetPostString("orderState");
  7748. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7749. string afterState = GetPostString("afterstate");
  7750. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7751. string date1 = GetPostString("date1");
  7752. string date2 = GetPostString("date2");
  7753. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7754. if (dw.Length > 0) lw.Add(dw);
  7755. string price1 = GetPostString("price1");
  7756. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7757. string price2 = GetPostString("price2");
  7758. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7759. string reason = GetPostString("reason");
  7760. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7761. string method = GetPostString("method");
  7762. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7763. string handledate1 = GetPostString("handledate1");
  7764. string handledate2 = GetPostString("handledate2");
  7765. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7766. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7767. string handler = GetPostString("handler");
  7768. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7769. string afterdate1 = GetPostString("afterdate1");
  7770. string afterdate2 = GetPostString("afterdate2");
  7771. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7772. if (afterDate.Length > 0) lw.Add(afterDate);
  7773. string customer = GetPostString("customer");
  7774. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7775. string design = GetPostString("design");
  7776. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7777. string afterMemoType = GetPostString("aftermemotype");
  7778. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7779. string vstate = GetPostString("vstate");
  7780. if (vstate.Length > 0)
  7781. {
  7782. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7783. }
  7784. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7785. string supplier = GetPostString("supplier");
  7786. int supid = commonHelper.getSupplierIDByName(supplier);
  7787. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7788. string posCode = CurrentUser.UserPost.Post.Code;
  7789. if (posCode == "Supplier")
  7790. {
  7791. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7792. }
  7793. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7794. {
  7795. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7796. }
  7797. else
  7798. {
  7799. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7800. }
  7801. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7802. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7803. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7804. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7805. writeGridDataTableJson(dStruct.TotalCount, dt);
  7806. }
  7807. public void upd_erp_supverifyaftersale()
  7808. {
  7809. if (UrlPostParmsCheck("id"))
  7810. {
  7811. string id = GetPostString("id");
  7812. int st = GetPostInt("afterstate");
  7813. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7814. CeErpTradeCell entity = null;
  7815. if (ceErpTradeResponsible != null)
  7816. {
  7817. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7818. }
  7819. string afmemo = GetPostString("supmemo");
  7820. string image = GetPostString("image");
  7821. if (entity != null)
  7822. {
  7823. entity.AfterSaleSupplierState = st;
  7824. entity.AfterSaleSupplierMemo = afmemo;
  7825. if (st == 1)
  7826. {
  7827. ceErpTradeResponsible.VerifyState = 1;
  7828. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7829. ceErpTradeResponsible.Update();
  7830. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7831. if (isAll)
  7832. {
  7833. entity.AfterSaleState = 4;
  7834. entity.FinishAfterSaleTime = DateTime.Now;
  7835. }
  7836. }
  7837. else
  7838. {
  7839. CeErpTradeResponsible.dateByTid(entity.ctid);
  7840. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7841. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7842. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7843. if (num <= 1)
  7844. {
  7845. entity.AfterSaleState = 1;
  7846. }
  7847. else
  7848. {
  7849. entity.AfterSaleState = 5;
  7850. }
  7851. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7852. if (ceErpTradeAfterSaleExtend != null)
  7853. {
  7854. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7855. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7856. ceErpTradeAfterSaleExtend.Update();
  7857. }
  7858. else
  7859. {
  7860. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7861. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7862. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7863. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7864. ceErpTradeAfterSaleExtend.Create();
  7865. }
  7866. }
  7867. if (entity.AfterSaleState == 4)
  7868. {
  7869. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7870. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7871. {
  7872. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7873. }
  7874. ApiVo apiVo = new ApiVo();
  7875. apiVo.orderNumber = entity.ctid;
  7876. apiVo.actionName = "afterOver";
  7877. designHelper.API_WorkCore(apiVo); //afterOver
  7878. }
  7879. entity.UpdateTime = DateTime.Now;
  7880. entity.Update();
  7881. returnSuccessMsg("操作成功!");
  7882. CeErpSukuraData.createInfo(entity.ctid, 8);
  7883. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7884. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7885. return;
  7886. }
  7887. returnErrorMsg("找不到订单记录");
  7888. }
  7889. }
  7890. public void upd_erp_masteraftersale()
  7891. {
  7892. if (UrlPostParmsCheck("id"))
  7893. {
  7894. string id = GetPostString("id");
  7895. int st = GetPostInt("afterstate");
  7896. string afmemo = GetPostString("supmemo");
  7897. string image = GetPostString("image");
  7898. string textResult = GetPostString("textResult");
  7899. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7900. if (ceErpTradeResponsible != null)
  7901. {
  7902. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7903. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7904. ceErpTradeResponsible.Update();
  7905. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7906. if (entity != null)
  7907. {
  7908. entity.AfterSaleSupplierState = st;
  7909. entity.AfterSaleSupplierMemo = afmemo;
  7910. if (st == 1)
  7911. {
  7912. }
  7913. else
  7914. {
  7915. CeErpTradeResponsible.dateByTid(entity.ctid);
  7916. //退回到售后
  7917. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7918. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7919. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7920. if (num <= 1)
  7921. {
  7922. entity.AfterSaleState = 1;
  7923. }
  7924. else
  7925. {
  7926. entity.AfterSaleState = 5;
  7927. }
  7928. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7929. if (ceErpTradeAfterSaleExtend != null)
  7930. {
  7931. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7932. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7933. ceErpTradeAfterSaleExtend.Update();
  7934. }
  7935. else
  7936. {
  7937. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7938. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7939. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7940. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7941. ceErpTradeAfterSaleExtend.Create();
  7942. }
  7943. }
  7944. entity.UpdateTime = DateTime.Now;
  7945. entity.Update();
  7946. returnSuccessMsg("操作成功!");
  7947. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7948. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7949. return;
  7950. }
  7951. }
  7952. returnErrorMsg("找不到订单记录");
  7953. }
  7954. }
  7955. public void upd_erp_personaftersale()
  7956. {
  7957. if (UrlPostParmsCheck("id"))
  7958. {
  7959. //林小连
  7960. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7961. {
  7962. upd_erp_masteraftersale();
  7963. return;
  7964. }
  7965. string id = GetPostString("id");
  7966. int st = GetPostInt("afterstate");
  7967. string afmemo = GetPostString("supmemo");
  7968. string image = GetPostString("image");
  7969. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7970. if (ceErpTradeResponsible != null)
  7971. {
  7972. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7973. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7974. ceErpTradeResponsible.Update();
  7975. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7976. if (entity != null)
  7977. {
  7978. entity.AfterSaleSupplierMemo = afmemo;
  7979. entity.AfterSaleSupplierState = st;
  7980. if (st == 1)
  7981. {
  7982. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7983. if (isAll)
  7984. {
  7985. entity.AfterSaleState = 4;
  7986. entity.FinishAfterSaleTime = DateTime.Now;
  7987. }
  7988. }
  7989. else
  7990. {
  7991. CeErpTradeResponsible.dateByTid(entity.ctid);
  7992. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7993. if (ceErpTradeAfterSaleExtend != null)
  7994. {
  7995. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7996. ceErpTradeAfterSaleExtend.Update();
  7997. }
  7998. else
  7999. {
  8000. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  8001. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  8002. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  8003. ceErpTradeAfterSaleExtend.Create();
  8004. }
  8005. //退回到主管
  8006. //entity.AfterSaleState = 2;
  8007. }
  8008. if (entity.AfterSaleState == 4)
  8009. {
  8010. ApiVo apiVo = new ApiVo();
  8011. apiVo.orderNumber = entity.ctid;
  8012. apiVo.actionName = "afterOver";
  8013. designHelper.API_WorkCore(apiVo); //afterOver
  8014. }
  8015. entity.UpdateTime = DateTime.Now;
  8016. entity.Update();
  8017. returnSuccessMsg("操作成功!");
  8018. CeErpSukuraData.createInfo(entity.ctid, 8);
  8019. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  8020. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  8021. return;
  8022. }
  8023. }
  8024. returnErrorMsg("找不到订单记录");
  8025. }
  8026. }
  8027. public void set_erp_supplierrefundtag()
  8028. {
  8029. if (UrlPostParmsCheck("ctid"))
  8030. {
  8031. string eid = GetPostString("ctid");
  8032. CeErpTradeCell entity = null;
  8033. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  8034. if (entity != null)
  8035. {
  8036. entity.IsSupplierRefund = GetPostInt("tag");
  8037. entity.Update();
  8038. returnSuccessMsg("操作成功!");
  8039. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  8040. return;
  8041. }
  8042. returnErrorMsg("找不到订单记录");
  8043. }
  8044. }
  8045. public void get_erp_refundlist()
  8046. {
  8047. DataStruct dStruct = GetPostStruct();
  8048. List<string> lw = new List<string>();
  8049. string tid = GetPostString("tid");
  8050. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8051. //string rid = GetPostString("refund_id");
  8052. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  8053. string shopname = GetPostString("shopname");
  8054. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8055. string buyernick = GetPostString("buyer_nick");
  8056. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8057. string customer = GetPostString("customer");
  8058. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8059. string design = GetPostString("design");
  8060. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8061. string sellermemo = GetPostString("seller_memo");
  8062. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8063. //string date1 = GetPostString("date1");
  8064. //string date2 = GetPostString("date2");
  8065. //string dateType = GetPostString("dateType");
  8066. //if (dateType.Length > 0)
  8067. //{
  8068. // if (dateType == "1001") dateType = "0";
  8069. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  8070. // if (searchDT.Count == 2)
  8071. // {
  8072. // date1 = searchDT[0].ToString();
  8073. // date2 = searchDT[1].ToString();
  8074. // }
  8075. //}
  8076. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8077. //if (dw.Length > 0) lw.Add(dw);
  8078. string redate1 = GetPostString("refunddate1");
  8079. string redate2 = GetPostString("refunddate2");
  8080. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8081. if (dwdate.Length > 0) lw.Add(dwdate);
  8082. string price1 = GetPostString("price1");
  8083. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8084. string price2 = GetPostString("price2");
  8085. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8086. string ispartrefund = GetPostString("ispartrefund");
  8087. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8088. string refundState = GetPostString("refundvstate");
  8089. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  8090. int st = GetInt("st");
  8091. if (st == 2) //待确认列表中,把state=3已确认的也显示
  8092. {
  8093. string responsible = GetPostString("responsibleman");
  8094. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8095. lw.Add(string.Format("RefundState>={0}", st));
  8096. string code = CurrentUser.UserPost.Post.Code;
  8097. if (code == "CustomerService")
  8098. {
  8099. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  8100. }
  8101. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  8102. {
  8103. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  8104. }
  8105. else if (code == "Place" || code == "PlaceMr")
  8106. {
  8107. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  8108. }
  8109. dStruct.Order = "RefundState asc,created desc";
  8110. }
  8111. else if (st == 10)
  8112. {
  8113. string responsible = GetPostString("responsibleman");
  8114. if (responsible == "空白")
  8115. {
  8116. lw.Add(string.Format("ResponsibleUserName = ''"));
  8117. }
  8118. else if (responsible.Length > 0)
  8119. {
  8120. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8121. }
  8122. lw.Add(string.Format("RefundState>=0"));
  8123. dStruct.Order = "created desc";
  8124. }
  8125. else
  8126. {
  8127. string responsible = GetPostString("responsibleman");
  8128. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  8129. lw.Add(string.Format("RefundState={0}", st));
  8130. dStruct.Order = "created desc";
  8131. }
  8132. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8133. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  8134. dt.Columns.Add("refund_fees");
  8135. foreach (DataRow dr in dt.Rows)
  8136. {
  8137. String status = dr["status"].ToString();
  8138. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8139. {
  8140. dr["refund_fees"] = dr["refund_fee"];
  8141. }
  8142. else
  8143. {
  8144. dr["refund_fees"] = "0.0";
  8145. }
  8146. }
  8147. writeGridDataTableJson(dStruct.TotalCount, dt);
  8148. }
  8149. public void get_erp_refunddesignlist()
  8150. {
  8151. DataStruct dStruct = GetPostStruct();
  8152. List<string> lw = new List<string>();
  8153. string tid = GetPostString("tid");
  8154. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8155. string shopname = GetPostString("shopname");
  8156. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8157. string buyernick = GetPostString("buyer_nick");
  8158. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8159. string customer = GetPostString("customer");
  8160. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8161. string design = GetPostString("design");
  8162. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  8163. string sellermemo = GetPostString("seller_memo");
  8164. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  8165. string redate1 = GetPostString("refunddate1");
  8166. string redate2 = GetPostString("refunddate2");
  8167. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  8168. if (dwdate.Length > 0) lw.Add(dwdate);
  8169. string price1 = GetPostString("price1");
  8170. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8171. string price2 = GetPostString("price2");
  8172. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8173. string ispartrefund = GetPostString("ispartrefund");
  8174. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  8175. string designerorg = GetPostString("designerorg");
  8176. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  8177. string refundState = GetPostString("refundState");
  8178. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  8179. int myOrgid = CurrentUser.UserPost.OrgID;
  8180. string myOrgCode = CurrentUser.UserPost.Post.Code;
  8181. if ("Designer".Equals(myOrgCode))//设计师能看到的
  8182. {
  8183. if (CurrentUser.User.TeamIds.Length > 0)
  8184. {
  8185. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  8186. }
  8187. else
  8188. {
  8189. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  8190. }
  8191. }
  8192. else if ("SysAdmin".Equals(myOrgCode))
  8193. {
  8194. }
  8195. else
  8196. {
  8197. if (CurrentUser.User.ManageOrgIds.Length > 0)
  8198. {
  8199. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  8200. }
  8201. else
  8202. {
  8203. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  8204. }
  8205. }
  8206. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8207. dStruct.Order = "created desc";
  8208. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8209. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8210. dt.Columns.Add("refund_fees");
  8211. foreach (DataRow dr in dt.Rows)
  8212. {
  8213. String status = dr["status"].ToString();
  8214. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8215. {
  8216. dr["refund_fees"] = dr["refund_fee"];
  8217. }
  8218. else
  8219. {
  8220. dr["refund_fees"] = "0.0";
  8221. }
  8222. }
  8223. writeGridDataTableJson(dStruct.TotalCount, dt);
  8224. }
  8225. public void handle_erp_refundtag()
  8226. {
  8227. if (UrlPostParmsCheck("refund_id"))
  8228. {
  8229. string eid = GetPostString("refund_id");
  8230. string respMan = GetPostString("ResponsibleName");
  8231. if (respMan.Length <= 0)
  8232. {
  8233. returnErrorMsg("责任人不能为空");
  8234. return;
  8235. }
  8236. CeErpTradeRefund entity = null;
  8237. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8238. if (entity != null)
  8239. {
  8240. entity.ResponsibleUserName = respMan;
  8241. string userid = GetPostString("ResponsibleUserId");
  8242. if (userid.Length > 0)
  8243. {
  8244. entity.ResponsibleUserId = userid;
  8245. }
  8246. entity.Memo = GetPostString("Memo");
  8247. if (respMan.IndexOf("客服") != -1 ||
  8248. respMan.IndexOf("设计师") != -1 ||
  8249. respMan.IndexOf("下单员") != -1)
  8250. {
  8251. entity.RefundState = 2;
  8252. }
  8253. else
  8254. {
  8255. entity.RefundState = 3;
  8256. }
  8257. entity.modified = DateTime.Now;
  8258. entity.Update();
  8259. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8260. returnSuccessMsg("操作成功!");
  8261. return;
  8262. }
  8263. returnErrorMsg("找不到订单记录");
  8264. }
  8265. }
  8266. public void handle_erp_designrefundtag()
  8267. {
  8268. if (UrlPostParmsCheck("refund_id"))
  8269. {
  8270. string eid = GetPostString("refund_id");
  8271. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8272. if (ceErpTradeCellExtend == null)
  8273. {
  8274. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8275. ceErpTradeCellExtend.ctid = eid;
  8276. }
  8277. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8278. if (ceErpTradeCellExtend.ID > 0)
  8279. {
  8280. ceErpTradeCellExtend.Update();
  8281. }
  8282. else
  8283. {
  8284. ceErpTradeCellExtend.Create();
  8285. }
  8286. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8287. returnSuccessMsg("操作成功!");
  8288. return;
  8289. }
  8290. returnErrorMsg("找不到订单记录");
  8291. }
  8292. public void upd_erp_refundverify()
  8293. {
  8294. if (UrlPostParmsCheck("refund_id"))
  8295. {
  8296. string eid = GetPostString("refund_id");
  8297. CeErpTradeRefund entity = null;
  8298. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8299. if (entity != null)
  8300. {
  8301. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8302. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8303. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8304. {
  8305. entity.RefundState = 2;
  8306. }
  8307. else
  8308. {
  8309. entity.RefundState = 3;
  8310. }
  8311. entity.Update();
  8312. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8313. returnSuccessMsg("操作成功!");
  8314. return;
  8315. }
  8316. returnErrorMsg("找不到订单记录");
  8317. }
  8318. }
  8319. public void upd_erp_refundapprove()
  8320. {
  8321. if (UrlPostParmsCheck("refund_id"))
  8322. {
  8323. string eid = GetPostString("refund_id");
  8324. CeErpTradeRefund entity = null;
  8325. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8326. if (entity != null)
  8327. {
  8328. int apr = GetPostInt("approve");
  8329. if (apr == 0)
  8330. {
  8331. entity.RefundState = 1;
  8332. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8333. }
  8334. else if (apr == 1)
  8335. {
  8336. entity.RefundState = 3;
  8337. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8338. }
  8339. entity.modified = DateTime.Now;
  8340. entity.Update();
  8341. returnSuccessMsg("操作成功!");
  8342. return;
  8343. }
  8344. returnErrorMsg("找不到订单记录");
  8345. }
  8346. }
  8347. public void get_erp_billlist()
  8348. {
  8349. DataStruct dStruct = GetPostStruct();
  8350. List<string> lw = new List<string>();
  8351. string title = GetPostString("title");
  8352. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8353. string tid = GetPostString("tid");
  8354. string tids = GetPostString("tids");
  8355. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8356. if (tids.Length > 0)
  8357. {
  8358. tids = "'" + tids + "'";
  8359. tids = tids.Replace(",", "','");
  8360. lw.Add(string.Format("tid in ({0})", tids));
  8361. }
  8362. string shopname = GetPostString("shopname");
  8363. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8364. string buyernick = GetPostString("buyer_nick");
  8365. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8366. string customer = GetPostString("customer");
  8367. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8368. string date1 = GetPostString("date1");
  8369. string date2 = GetPostString("date2");
  8370. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8371. if (dw.Length > 0) lw.Add(dw);
  8372. string price1 = GetPostString("price1");
  8373. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8374. string price2 = GetPostString("price2");
  8375. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8376. string returndate1 = GetPostString("returndate1");
  8377. string returndate2 = GetPostString("returndate2");
  8378. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8379. if (dw1.Length > 0) lw.Add(dw1);
  8380. string billtype = GetPostString("billtype");
  8381. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8382. string billstate = GetPostString("billstate");
  8383. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8384. string usershop = CurrentUser.User.pemShop;
  8385. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8386. dStruct.Order = "createTime desc";
  8387. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8388. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8389. //foreach (DataRow dr in dt.Rows)
  8390. //{
  8391. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8392. //}
  8393. writeGridDataTableJson(dStruct.TotalCount, dt);
  8394. }
  8395. public void modify_erp_billinfo()
  8396. {
  8397. if (UrlPostParmsCheck("ID"))
  8398. {
  8399. string eid = GetPostString("ID");
  8400. CeErpBill bill_entity = null;
  8401. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8402. if (bill_entity != null)
  8403. {
  8404. bill_entity.tid = GetPostString("tid");
  8405. bill_entity.title = GetPostString("title");
  8406. bill_entity.tax = GetPostString("tax");
  8407. bill_entity.bank = GetPostString("bank");
  8408. bill_entity.bankac = GetPostString("bankac");
  8409. bill_entity.address = GetPostString("address");
  8410. bill_entity.phone = GetPostString("phone");
  8411. bill_entity.price = GetPostString("price");
  8412. bill_entity.productId = GetPostInt("ProductName");
  8413. bill_entity.num = GetPostInt("num");
  8414. bill_entity.unit = GetPostString("unit");
  8415. bill_entity.type = GetPostString("type");
  8416. bill_entity.sendType = GetPostString("SendType");
  8417. bill_entity.email = GetPostString("email");
  8418. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8419. bill_entity.shopName = GetPostString("ShopName");
  8420. bill_entity.applymemo = GetPostString("applymemo");
  8421. bill_entity.modifyTime = DateTime.Now;
  8422. bill_entity.createTime = DateTime.Now;
  8423. bill_entity.state = 0;
  8424. bill_entity.Update();
  8425. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8426. returnSuccessMsg("发票修改成功!");
  8427. return;
  8428. }
  8429. returnErrorMsg("找不到对应记录");
  8430. }
  8431. }
  8432. public void set_erp_invoicing()
  8433. {
  8434. if (UrlPostParmsCheck("id"))
  8435. {
  8436. try
  8437. {
  8438. string eid = GetPostString("id");
  8439. CeErpBill bill_entity = null;
  8440. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8441. if (bill_entity != null)
  8442. {
  8443. int ComId = GetPostInt("ComId");
  8444. //string memo = GetPostString("Memo");
  8445. int allInfo = GetPostInt("allinfo");
  8446. string clert = CurrentUser.User.Name;
  8447. //string detailValue = GetPostString("detailvalue");
  8448. string billId = bill_entity.billOrderId;
  8449. string[] billIdList = billId.Split(',');
  8450. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8451. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8452. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8453. {
  8454. billCount += 1;
  8455. }
  8456. if (billId.Length <= 0 || billIdList.Length != billCount)
  8457. {
  8458. bill_entity.billOrderId = "";
  8459. string prebill = "ltb";
  8460. for (int idx = 1; idx <= billCount; idx++)
  8461. {
  8462. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8463. string billoid = prebill + idx + dtstr;
  8464. bill_entity.billOrderId += billoid;
  8465. if (idx < billCount)
  8466. {
  8467. bill_entity.billOrderId += ",";
  8468. }
  8469. }
  8470. }
  8471. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8472. if (bill_entity.state == 5)
  8473. {
  8474. string errMsg = bill_entity.failerror;
  8475. string[] errlist = errMsg.Split('|');
  8476. string[] errTags = new string[errlist.Length];
  8477. for (int itag = 0; itag < errlist.Length; itag++)
  8478. {
  8479. if (errlist[itag].Length <= 0) continue;
  8480. errTags[itag] = errlist[itag].Split('&')[0];
  8481. }
  8482. for (int iii = 0; iii < errTags.Length; iii++)
  8483. {
  8484. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8485. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8486. if (billOrderList.Length >= erroBillOrderTag)
  8487. {
  8488. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8489. if (needModifyBillId.Length <= 19)
  8490. {
  8491. needModifyBillId = needModifyBillId + "1";
  8492. }
  8493. else
  8494. {
  8495. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8496. last = last + 1;
  8497. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8498. }
  8499. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8500. }
  8501. }
  8502. }
  8503. bool isHaveBillSucces = false;
  8504. string totalRes = "";
  8505. bill_entity.failerror = "";
  8506. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8507. {
  8508. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8509. totalRes += res;
  8510. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8511. {
  8512. isHaveBillSucces = true;
  8513. bill_entity.comId = ComId;
  8514. bill_entity.state = 1;
  8515. bill_entity.executeTime = DateTime.Now;
  8516. bill_entity.executeUser = clert;
  8517. }
  8518. else
  8519. {
  8520. bill_entity.state = 5;
  8521. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8522. }
  8523. }
  8524. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8525. bill_entity.Update();
  8526. if (isHaveBillSucces)
  8527. {
  8528. StringBuilder sql = new StringBuilder();
  8529. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8530. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8531. }
  8532. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8533. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8534. {
  8535. returnErrorMsg("开票失败");
  8536. }
  8537. else
  8538. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8539. return;
  8540. }
  8541. returnErrorMsg("找不到对应记录");
  8542. }
  8543. catch (Exception ex)
  8544. {
  8545. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8546. returnErrorMsg("操作失败");
  8547. }
  8548. }
  8549. }
  8550. public void get_erp_invoicing_back()
  8551. {
  8552. if (UrlPostParmsCheck("id"))
  8553. {
  8554. try
  8555. {
  8556. string id = GetPostString("id");
  8557. CeErpBill entiy = CeErpBill.Get(id);
  8558. if (entiy != null)
  8559. {
  8560. if (entiy.state == 0)
  8561. {
  8562. returnErrorMsg("发票还未开具");
  8563. return;
  8564. }
  8565. string[] billOrderList = entiy.billOrderId.Split(',');
  8566. int iTag = 0;
  8567. entiy.fplsh = "";
  8568. entiy.fpdm = "";
  8569. entiy.fphm = "";
  8570. foreach (string billOrderId in billOrderList)
  8571. {
  8572. iTag++;
  8573. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8574. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8575. {
  8576. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8577. try
  8578. {
  8579. Invoicing_get_response_Obj iObj = null;
  8580. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8581. if (iObj != null)
  8582. {
  8583. entiy.state = 2;
  8584. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8585. entiy.fpdm += iObj.list[0].c_fpdm;
  8586. entiy.fphm += iObj.list[0].c_fphm;
  8587. if (iTag < billOrderList.Length)
  8588. {
  8589. entiy.fplsh += ",";
  8590. entiy.fpdm += ",";
  8591. entiy.fphm += ",";
  8592. }
  8593. entiy.Update();
  8594. }
  8595. StringBuilder sql = new StringBuilder();
  8596. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8597. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8598. returnSuccessMsg("开票成功");
  8599. }
  8600. catch (Exception ex)
  8601. {
  8602. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8603. }
  8604. return;
  8605. }
  8606. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8607. {
  8608. var res_obj = new
  8609. {
  8610. data = "开票中"
  8611. };
  8612. string ro_json = JsonConvert.SerializeObject(res_obj);
  8613. returnSuccess(ro_json);
  8614. return;
  8615. }
  8616. else
  8617. {
  8618. int eidx = res.IndexOf("c_resultmsg");
  8619. int lidx = res.IndexOf("c_status");
  8620. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8621. entiy.state = 5;
  8622. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8623. entiy.Update();
  8624. returnErrorMsg("开票失败");
  8625. return;
  8626. }
  8627. }
  8628. }
  8629. }
  8630. catch (Exception ex)
  8631. {
  8632. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8633. }
  8634. return;
  8635. }
  8636. }
  8637. public void get_erp_invoicing()
  8638. {
  8639. if (UrlPostParmsCheck("id"))
  8640. {
  8641. try
  8642. {
  8643. string id = GetPostString("id");
  8644. CeErpBill entiy = CeErpBill.Get(id);
  8645. if (entiy != null)
  8646. {
  8647. if (entiy.state == 0)
  8648. {
  8649. returnErrorMsg("发票还未开具");
  8650. return;
  8651. }
  8652. if (entiy.sendType == "纸质发票")
  8653. {
  8654. if (entiy.img.Length <= 0)
  8655. {
  8656. returnErrorMsg("查无纸质发票");
  8657. return;
  8658. }
  8659. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8660. returnSuccess(returnres);
  8661. return;
  8662. }
  8663. string[] billOrderList = entiy.billOrderId.Split(',');
  8664. int iTag = 0;
  8665. string fpUrl = "";
  8666. entiy.fplsh = "";
  8667. entiy.fpdm = "";
  8668. entiy.fphm = "";
  8669. foreach (string billOrderId in billOrderList)
  8670. {
  8671. iTag++;
  8672. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8673. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8674. {
  8675. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8676. Invoicing_get_response_Obj iObj = null;
  8677. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8678. if (iObj != null)
  8679. {
  8680. //entiy.state = 2;
  8681. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8682. entiy.fpdm += iObj.list[0].c_fpdm;
  8683. entiy.fphm += iObj.list[0].c_fphm;
  8684. if (iTag < billOrderList.Length)
  8685. {
  8686. entiy.fplsh += ",";
  8687. entiy.fpdm += ",";
  8688. entiy.fphm += ",";
  8689. }
  8690. entiy.Update();
  8691. fpUrl += iObj.list[0].c_url + ",";
  8692. }
  8693. //returnSuccess(res);
  8694. StringBuilder sql = new StringBuilder();
  8695. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8696. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8697. }
  8698. else
  8699. {
  8700. int eidx = res.IndexOf("c_resultmsg");
  8701. //int lidx = res.IndexOf("c_status");
  8702. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8703. //开票失败
  8704. entiy.state = 5;
  8705. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8706. entiy.Update();
  8707. returnErrorMsg("开票失败");
  8708. return;
  8709. }
  8710. }
  8711. var returnObj = new
  8712. {
  8713. data = fpUrl
  8714. };
  8715. string ro_json = JsonConvert.SerializeObject(returnObj);
  8716. returnSuccess(ro_json);
  8717. }
  8718. }
  8719. catch (Exception ex)
  8720. {
  8721. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8722. }
  8723. return;
  8724. }
  8725. }
  8726. public void save_erp_billimg()
  8727. {
  8728. if (UrlPostParmsCheck("id"))
  8729. {
  8730. string eid = GetPostString("id");
  8731. CeErpBill bill_entity = null;
  8732. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8733. if (bill_entity != null)
  8734. {
  8735. bill_entity.img = GetPostString("img");
  8736. bill_entity.executeTime = DateTime.Now;
  8737. bill_entity.state = 2;
  8738. bill_entity.Update();
  8739. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8740. returnSuccessMsg("保存成功");
  8741. }
  8742. return;
  8743. }
  8744. }
  8745. public void upd_erp_billreturnback()
  8746. {
  8747. if (UrlPostParmsCheck("id"))
  8748. {
  8749. int eid = GetPostInt("id");
  8750. CeErpBill bill_entity = null;
  8751. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8752. if (bill_entity != null)
  8753. {
  8754. bill_entity.state = 3;
  8755. bill_entity.returnReason = GetPostString("reason");
  8756. bill_entity.Update();
  8757. returnSuccessMsg("驳回成功!");
  8758. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8759. }
  8760. return;
  8761. }
  8762. }
  8763. public void cancel_erp_bill()
  8764. {
  8765. if (UrlPostParmsCheck("id"))
  8766. {
  8767. int eid = GetPostInt("id");
  8768. int detailValue = GetPostInt("detailvalue");
  8769. CeErpBill bill_entity = null;
  8770. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8771. string cres = "";
  8772. string gres = "";
  8773. if (bill_entity != null)
  8774. {
  8775. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8776. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8777. {
  8778. int iTag = 0;
  8779. bill_entity.fplsh = "";
  8780. bill_entity.fpdm = "";
  8781. bill_entity.fphm = "";
  8782. foreach (string billOrderId in billOrderList)
  8783. {
  8784. iTag++;
  8785. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8786. if (gres.IndexOf("success") != -1)
  8787. {
  8788. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8789. Invoicing_get_response_Obj iObj = null;
  8790. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8791. if (iObj != null)
  8792. {
  8793. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8794. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8795. bill_entity.fphm += iObj.list[0].c_fphm;
  8796. if (iTag < billOrderList.Length)
  8797. {
  8798. bill_entity.fplsh += ",";
  8799. bill_entity.fpdm += ",";
  8800. bill_entity.fphm += ",";
  8801. }
  8802. bill_entity.Update();
  8803. }
  8804. }
  8805. else
  8806. {
  8807. returnErrorMsg(gres);
  8808. return;
  8809. }
  8810. }
  8811. }
  8812. if (bill_entity.sendType == "纸质发票")
  8813. {
  8814. //作废
  8815. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8816. //if (DateTime.Now.Month == extime.Month)
  8817. //{
  8818. //cres = taobaoHelper.cancel_invoicing(eid);
  8819. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8820. //{
  8821. bill_entity.state = 4;//已作废
  8822. bill_entity.Update();
  8823. returnSuccessMsg("发票已作废");
  8824. return;
  8825. //}
  8826. //else
  8827. //{
  8828. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8829. // bill_entity.Update();
  8830. // returnErrorMsg(cres);
  8831. // return;
  8832. //}
  8833. //}
  8834. //else
  8835. //{
  8836. // returnErrorMsg("纸质发票只能作废本月的发票");
  8837. // return;
  8838. //}
  8839. }
  8840. //红冲
  8841. int redTag = 0;
  8842. string[] fpdmList = bill_entity.fpdm.Split(',');
  8843. string[] fphmList = bill_entity.fphm.Split(',');
  8844. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8845. {
  8846. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8847. return;
  8848. }
  8849. foreach (string billOrderId in billOrderList)
  8850. {
  8851. redTag++;
  8852. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8853. cres += onecres;
  8854. cres += ",";
  8855. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8856. {
  8857. bill_entity.state = 4;//已作废
  8858. //bill_entity.Update();
  8859. //returnSuccessMsg("发票已红冲");
  8860. }
  8861. else if (onecres.IndexOf("重复冲红") != -1)
  8862. {
  8863. bill_entity.state = 4;//已作废
  8864. //bill_entity.Update();
  8865. //returnSuccessMsg("发票已红冲");
  8866. }
  8867. else
  8868. {
  8869. string errmsg = commonHelper.KeepChinese(onecres);
  8870. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8871. }
  8872. }
  8873. bill_entity.Update();
  8874. if (cres.IndexOf("失败") != -1)
  8875. returnErrorMsg("红冲失败");
  8876. else
  8877. returnSuccessMsg("发票已红冲");
  8878. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8879. return;
  8880. }
  8881. return;
  8882. }
  8883. }
  8884. public void del_erp_billorder()
  8885. {
  8886. if (UrlPostParmsCheck("id"))
  8887. {
  8888. string eid = GetPostString("id");
  8889. CeErpBill.Del(eid);
  8890. CeErpBill bill = CeErpBill.Get(eid);
  8891. if (bill != null)
  8892. {
  8893. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8894. }
  8895. returnSuccessMsg("删除成功");
  8896. }
  8897. }
  8898. public void finish_erp_bill()
  8899. {
  8900. if (UrlPostParmsCheck("ids"))
  8901. {
  8902. string eids = GetPostString("ids");
  8903. string[] list = eids.Split(',');
  8904. foreach (string eid in list)
  8905. {
  8906. CeErpBill bill = CeErpBill.Get(eid);
  8907. if (bill != null)
  8908. {
  8909. bill.state = 2;
  8910. bill.Update();
  8911. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8912. }
  8913. }
  8914. returnSuccessMsg("操作成功");
  8915. }
  8916. }
  8917. public void get_erp_returncash()
  8918. {
  8919. DataStruct dStruct = GetPostStruct();
  8920. List<string> lw = new List<string>();
  8921. string tid = GetPostString("tid");
  8922. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8923. string shopname = GetPostString("shopname");
  8924. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8925. string buyernick = GetPostString("buyer_nick");
  8926. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8927. string customer = GetPostString("customer");
  8928. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8929. string returndate1 = GetPostString("returndate1");
  8930. string returndate2 = GetPostString("returndate2");
  8931. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8932. if (dw.Length > 0) lw.Add(dw);
  8933. string finishDate1 = GetPostString("finishdate1");
  8934. string finishDate2 = GetPostString("finishdate2");
  8935. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8936. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8937. string returntype = GetPostString("returntype");
  8938. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8939. string returnvstate = GetPostString("returnvstate");
  8940. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8941. dStruct.Order = "created desc";
  8942. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8943. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8944. writeGridDataTableJson(dStruct.TotalCount, dt);
  8945. }
  8946. public void get_erp_staygoods()
  8947. {
  8948. DataStruct dStruct = GetPostStruct();
  8949. List<string> lw = new List<string>();
  8950. string tid = GetPostString("tid");
  8951. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8952. string shopname = GetPostString("shopname");
  8953. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8954. string wangwang = GetPostString("wangwang");
  8955. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8956. string customer = GetPostString("customer");
  8957. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8958. string returndate1 = GetPostString("returndate1");
  8959. string returndate2 = GetPostString("returndate2");
  8960. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8961. if (dw.Length > 0) lw.Add(dw);
  8962. string finishDate1 = GetPostString("finishdate1");
  8963. string finishDate2 = GetPostString("finishdate2");
  8964. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8965. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8966. string returnvstate = GetPostString("returnvstate");
  8967. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8968. string persuadetype = GetPostString("persuadetype");
  8969. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8970. string customerOrg = GetPostString("customerOrg");
  8971. if (customerOrg.Length > 0)
  8972. {
  8973. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8974. }
  8975. string designerorg = GetPostString("designerorg");
  8976. if (designerorg.Length > 0)
  8977. {
  8978. lw.Add(string.Format("OrgID = {0}", designerorg));
  8979. }
  8980. dStruct.Order = "creata_time desc";
  8981. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8982. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8983. writeGridDataTableJson(dStruct.TotalCount, dt);
  8984. }
  8985. public void upd_erp_staygoods()
  8986. {
  8987. if (UrlPostParmsCheck("id"))
  8988. {
  8989. int eid = GetPostInt("id");
  8990. CeErpStayGoods entity = null;
  8991. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8992. if (entity != null)
  8993. {
  8994. entity.audit_type = 1;
  8995. entity.audit_time = DateTime.Now;
  8996. entity.audit_u_id = CurrentUser.UserID;
  8997. entity.audit_u_name = CurrentUser.UserName;
  8998. entity.Update();
  8999. returnSuccessMsg("审核成功!");
  9000. return;
  9001. }
  9002. returnErrorMsg("找不到订单记录");
  9003. }
  9004. }
  9005. public void upd_erp_stayGoodsback()
  9006. {
  9007. if (UrlPostParmsCheck("id"))
  9008. {
  9009. int eid = GetPostInt("id");
  9010. CeErpStayGoods entity = null;
  9011. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  9012. if (entity != null)
  9013. {
  9014. entity.audit_text = GetPostString("reason");
  9015. entity.audit_type = 2;
  9016. entity.audit_time = DateTime.Now;
  9017. entity.audit_u_id = CurrentUser.UserID;
  9018. entity.audit_u_name = CurrentUser.UserName;
  9019. entity.Update();
  9020. returnSuccessMsg("退回成功!");
  9021. return;
  9022. }
  9023. returnErrorMsg("找不到订单记录");
  9024. }
  9025. }
  9026. public void upd_erp_returncashverify()
  9027. {
  9028. if (UrlPostParmsCheck("ID"))
  9029. {
  9030. int eid = GetPostInt("ID");
  9031. CeErpReturnCash entity = null;
  9032. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9033. if (entity != null)
  9034. {
  9035. entity.cashstate = 1;
  9036. entity.verifytime = DateTime.Now;
  9037. entity.verifyuserid = CurrentUser.UserID;
  9038. entity.Update();
  9039. returnSuccessMsg("审核成功!");
  9040. return;
  9041. }
  9042. returnErrorMsg("找不到订单记录");
  9043. }
  9044. }
  9045. public void upd_all_erp_returncashverify()
  9046. {
  9047. if (UrlPostParmsCheck("ID"))
  9048. {
  9049. String[] list = GetPostString("ID").Split(',');
  9050. CeErpReturnCash entity = null;
  9051. for (int i = 0; i < list.Length; i++)
  9052. {
  9053. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  9054. if (entity != null)
  9055. {
  9056. if (entity.cashstate == 1)
  9057. {
  9058. returnErrorMsg("已审核过的订单不需要在审核!");
  9059. return;
  9060. }
  9061. entity.cashstate = 1;
  9062. entity.verifytime = DateTime.Now;
  9063. entity.verifyuserid = CurrentUser.UserID;
  9064. entity.Update();
  9065. }
  9066. }
  9067. returnSuccessMsg("审核成功!");
  9068. return;
  9069. }
  9070. }
  9071. public void upd_erp_returncashback()
  9072. {
  9073. if (UrlPostParmsCheck("ID"))
  9074. {
  9075. int eid = GetPostInt("ID");
  9076. CeErpReturnCash entity = null;
  9077. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9078. if (entity != null)
  9079. {
  9080. entity.backreason = GetPostString("reason");
  9081. entity.cashstate = 2;
  9082. entity.verifytime = DateTime.Now;
  9083. entity.verifyuserid = CurrentUser.UserID;
  9084. entity.Update();
  9085. returnSuccessMsg("退回成功!");
  9086. return;
  9087. }
  9088. returnErrorMsg("找不到订单记录");
  9089. }
  9090. }
  9091. public void upd_erp_returnprice()
  9092. {
  9093. if (UrlPostParmsCheck("ID"))
  9094. {
  9095. int eid = GetPostInt("ID");
  9096. CeErpReturnCash entity = null;
  9097. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  9098. if (entity != null)
  9099. {
  9100. if (entity.cashstate == 1)
  9101. {
  9102. returnErrorMsg("审核通过了不能改");
  9103. return;
  9104. }
  9105. entity.returnprice = GetPostDouble("returnprice");
  9106. entity.Update();
  9107. returnSuccessMsg("修改成功!");
  9108. return;
  9109. }
  9110. returnErrorMsg("找不到订单记录");
  9111. }
  9112. }
  9113. public void del_erp_returncash()
  9114. {
  9115. if (UrlPostParmsCheck("ID"))
  9116. {
  9117. int eid = GetPostInt("ID");
  9118. CeErpReturnCash.Del(eid);
  9119. returnSuccessMsg("操作成功");
  9120. return;
  9121. }
  9122. }
  9123. public void test_for_do_sql()
  9124. {
  9125. string sql = GetPostString("sqlstr");
  9126. if (sql.Length > 0)
  9127. {
  9128. try
  9129. {
  9130. DbHelper.DbConn.ExecuteNonQuery(sql);
  9131. var res_obj = new
  9132. {
  9133. data = "成功",
  9134. };
  9135. string ro_json = JsonConvert.SerializeObject(res_obj);
  9136. returnSuccess(ro_json);
  9137. }
  9138. catch (Exception ex)
  9139. {
  9140. var res_obj = new
  9141. {
  9142. data = ex.Message,
  9143. };
  9144. string ro_json = JsonConvert.SerializeObject(res_obj);
  9145. returnSuccess(ro_json);
  9146. }
  9147. }
  9148. }
  9149. public void get_user_info()
  9150. {
  9151. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  9152. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  9153. }
  9154. public void get_total_data()
  9155. {
  9156. int userId = CurrentUser.UserID;
  9157. string sql = "";
  9158. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9159. {
  9160. sql = string.Format("SELECT c.ID, COALESCE(SUM(CASE WHEN OrderState = 8 THEN payment ELSE 0 END), 0) AS orderAmount, COALESCE(SUM(CASE WHEN OrderState = 8 THEN 1 ELSE 0 END), 0) AS orderCount, COALESCE(SUM(CASE WHEN OrderState = 3 THEN payment ELSE 0 END), 0) AS orderBeginAmount, COALESCE(SUM(CASE WHEN OrderState = 3 THEN 1 ELSE 0 END), 0) AS orderBeginCount, COALESCE(SUM(CASE WHEN OrderState = 4 THEN payment ELSE 0 END), 0) AS orderFinishAmount, COALESCE(SUM(CASE WHEN OrderState = 4 THEN 1 ELSE 0 END), 0) AS orderFinishCount, COALESCE(SUM(CASE WHEN IsRefund > 1 THEN 1 ELSE 0 END), 0) AS refundCount, COALESCE(SUM(CASE WHEN IsRefund > 1 THEN payment ELSE 0 END), 0) AS refundAmount FROM CE_ErpUser c LEFT JOIN view_ErpTradeCell v ON c.ID = v.DesignUserId WHERE c.ID = {0} GROUP BY c.ID;", userId);
  9161. }
  9162. else
  9163. {
  9164. sql = string.Format("select d.id,isnull(a.orderAmount,0) as orderAmount,isnull(a.orderCount,0) as orderCount,isnull(b.refundCount,0) as refundCount, isnull(b.refundAmount,0) as refundAmount,isnull(c.afterAmount,0) as afterAmount,isnull(c.afterCount,0) as afterCount from " +
  9165. "(select ID from CE_ErpUser where ID = {0}) d " +
  9166. "left join " +
  9167. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  9168. ") a on d.ID = a.id left join " +
  9169. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  9170. ") b on a.id = b.id1 left join" +
  9171. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  9172. ") c on a.id = c.id2;", userId);
  9173. }
  9174. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9175. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9176. }
  9177. public void get_date_area_total_data2()
  9178. {
  9179. int userId = CurrentUser.UserID;
  9180. string date_type = GetPostString("timetype");
  9181. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9182. string sql = "";
  9183. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9184. {
  9185. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  9186. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  9187. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9188. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9189. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9190. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  9191. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9192. ") a on e.ID = a.id left join " +
  9193. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  9194. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9195. ") b on a.id = b.id1 " +
  9196. "left join " +
  9197. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9198. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  9199. ") c on a.id = c.id2 " +
  9200. "left join " +
  9201. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9202. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9203. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9204. }
  9205. else
  9206. {
  9207. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  9208. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  9209. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9210. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9211. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9212. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9213. ") a on e.ID = a.id left join " +
  9214. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9215. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9216. ") c on a.id = c.id2 " +
  9217. "left join " +
  9218. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9219. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9220. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9221. }
  9222. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9223. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9224. }
  9225. public void get_date_area_total_data()
  9226. {
  9227. int userId = CurrentUser.UserID;
  9228. string date_type = GetPostString("timetype");
  9229. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9230. string date1 = searchDT[0].ToString();
  9231. string date2 = searchDT[1].ToString();
  9232. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9233. {
  9234. SqlParameter[] sqlParameter ={
  9235. new SqlParameter("@userId", SqlDbType.Int,4),
  9236. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9237. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9238. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9239. };
  9240. sqlParameter[0].Value = userId;
  9241. sqlParameter[1].Value = date1;
  9242. sqlParameter[2].Value = date2;
  9243. sqlParameter[3].Direction = ParameterDirection.Output;
  9244. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9245. string res = sqlParameter[3].Value.ToString();
  9246. var res_obj = new
  9247. {
  9248. data = res
  9249. };
  9250. string ro_json = JsonConvert.SerializeObject(res_obj);
  9251. returnSuccess(ro_json);
  9252. }
  9253. else
  9254. {
  9255. SqlParameter[] sqlParameter ={
  9256. new SqlParameter("@userId", SqlDbType.Int,4),
  9257. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9258. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9259. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9260. };
  9261. sqlParameter[0].Value = userId;
  9262. sqlParameter[1].Value = date1;
  9263. sqlParameter[2].Value = date2;
  9264. sqlParameter[3].Direction = ParameterDirection.Output;
  9265. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9266. string res = sqlParameter[3].Value.ToString();
  9267. var res_obj = new
  9268. {
  9269. data = res
  9270. };
  9271. string ro_json = JsonConvert.SerializeObject(res_obj);
  9272. returnSuccess(ro_json);
  9273. }
  9274. //writeGridDataViewJson(dt.Rows.Count, dv);
  9275. }
  9276. public void get_order_list()
  9277. {
  9278. string strFields = GetPostString("paraFields");
  9279. string strOrder = GetPostString("paraOrder");
  9280. string strWhere = GetPostString("paraWhere");
  9281. string strPageSize = GetPostString("paraPageSize");
  9282. DataStruct dStruct = GetPostStruct();
  9283. dStruct.PageSize = int.Parse(strPageSize);
  9284. dStruct.Fileds = strFields;
  9285. dStruct.Order = strOrder;
  9286. dStruct.MainWhere = strWhere;
  9287. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9288. writeGridDataTableJson(dStruct.TotalCount, dt);
  9289. }
  9290. ////获取待开始订单列表
  9291. //public void get_wait_design_order_list()
  9292. //{
  9293. // string date_type = GetPostString("date_type");
  9294. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9295. // DataStruct dStruct = GetPostStruct();
  9296. // dStruct.PageSize = 1000;
  9297. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9298. // List<string> lw = new List<string>();
  9299. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9300. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9301. // dStruct.Order = "WaitDesignTime asc";
  9302. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9303. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9304. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9305. //}
  9306. //获取完成单量排名
  9307. public void get_finish_order_count_ranking()
  9308. {
  9309. /* string date_type = GetPostString("date_type");
  9310. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9311. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9312. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9313. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9314. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9315. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9316. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9317. writeGridDataTableJson(0, new DataTable());
  9318. }
  9319. public void get_finish_order_amount_ranking()
  9320. {
  9321. /*string date_type = GetPostString("date_type");
  9322. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9323. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9324. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9325. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9326. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9327. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9328. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9329. writeGridDataTableJson(0, new DataTable());
  9330. }
  9331. public void get_finish_refund_count_ranking()
  9332. {
  9333. string date_type = GetPostString("date_type");
  9334. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9335. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9336. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9337. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9338. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9339. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9340. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9341. writeGridDataTableJson(dt.Rows.Count, dt);
  9342. }
  9343. public void get_finish_refund_amount_ranking()
  9344. {
  9345. string date_type = GetPostString("date_type");
  9346. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9347. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9348. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9349. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9350. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9351. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9352. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9353. writeGridDataTableJson(dt.Rows.Count, dt);
  9354. }
  9355. public void set_erp_finishorder_director()
  9356. {
  9357. if (UrlPostParmsCheck("ctid"))
  9358. {
  9359. string eid = GetPostString("ctid");
  9360. CeErpTradeCell entity = null;
  9361. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9362. if (entity != null)
  9363. {
  9364. entity.OrderState = 8;
  9365. entity.Update();
  9366. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9367. returnSuccessMsg("操作成功!");
  9368. return;
  9369. }
  9370. returnErrorMsg("找不到记录");
  9371. }
  9372. }
  9373. public void get_erp_placeregistlist()
  9374. {
  9375. DataStruct dStruct = GetPostStruct();
  9376. List<string> lw = new List<string>();
  9377. string outsid = GetPostString("outsid");
  9378. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9379. string memo = GetPostString("memo");
  9380. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9381. string filename = GetPostString("filename");
  9382. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9383. string islate = GetPostString("islate");
  9384. if (islate.Length > 0)
  9385. {
  9386. if (islate == "1")
  9387. lw.Add(string.Format("OutLate>0"));
  9388. else
  9389. lw.Add(string.Format("OutLate=0"));
  9390. }
  9391. string placedate1 = GetPostString("placedate1");
  9392. string placedate2 = GetPostString("placedate2");
  9393. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9394. if (dw.Length > 0) lw.Add(dw);
  9395. string deliveryDate1 = GetPostString("deliverydate1");
  9396. string deliveryDate2 = GetPostString("deliverydate2");
  9397. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9398. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9399. dStruct.Order = "ID desc";
  9400. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9401. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9402. writeGridDataTableJson(dStruct.TotalCount, dt);
  9403. }
  9404. public void ins_erp_placeregist()
  9405. {
  9406. if (UrlPostParmsCheck("id"))
  9407. {
  9408. string eid = GetPostString("id");
  9409. CeErpPlaceRegister entity = null;
  9410. if (eid == "0")//新增
  9411. {
  9412. entity = new CeErpPlaceRegister();
  9413. string xdTime = GetPostString("placeTime");
  9414. if (xdTime.Length > 0)
  9415. {
  9416. entity.PlactTime = Convert.ToDateTime(xdTime);
  9417. }
  9418. string fhTime = GetPostString("deliveryTime");
  9419. if (fhTime.Length > 0)
  9420. {
  9421. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9422. }
  9423. string preTime = GetPostString("preOutTime");
  9424. if (preTime.Length > 0)
  9425. {
  9426. entity.PreOutTime = Convert.ToDateTime(preTime);
  9427. }
  9428. entity.DeliveryCount = GetPostInt("deliveryCount");
  9429. entity.ReceiveCount = GetPostInt("receiveCount");
  9430. entity.OutSid = GetPostString("outSid");
  9431. entity.FileName = GetPostString("fileName");
  9432. entity.Memo = GetPostString("memo");
  9433. entity.AddUserId = CurrentUser.UserID;
  9434. entity.CreateTime = DateTime.Now;
  9435. entity.Img = GetPostString("img");
  9436. entity.Supplier = GetPostInt("supplier");
  9437. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9438. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9439. {
  9440. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9441. DateTime dt2 = (DateTime)entity.PreOutTime;
  9442. TimeSpan span = dt1.Subtract(dt2);
  9443. if (span.Days > 0)
  9444. {
  9445. entity.OutLate = span.Days;
  9446. }
  9447. }
  9448. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9449. entity.Create();
  9450. returnSuccessMsg("添加成功!");
  9451. return;
  9452. }
  9453. else //修改
  9454. {
  9455. entity = CeErpPlaceRegister.Get(eid);
  9456. if (entity != null)
  9457. {
  9458. string xdTime = GetPostString("placeTime");
  9459. if (xdTime.Length > 0)
  9460. {
  9461. entity.PlactTime = Convert.ToDateTime(xdTime);
  9462. }
  9463. string fhTime = GetPostString("deliveryTime");
  9464. if (fhTime.Length > 0)
  9465. {
  9466. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9467. }
  9468. string preTime = GetPostString("preOutTime");
  9469. if (preTime.Length > 0)
  9470. {
  9471. entity.PreOutTime = Convert.ToDateTime(preTime);
  9472. }
  9473. entity.DeliveryCount = GetPostInt("deliveryCount");
  9474. entity.ReceiveCount = GetPostInt("receiveCount");
  9475. if (entity.DeliveryCount == entity.ReceiveCount)
  9476. {
  9477. entity.CurState = "已完成";
  9478. }
  9479. else
  9480. {
  9481. entity.CurState = "未完成";
  9482. }
  9483. entity.OutSid = GetPostString("outSid");
  9484. entity.FileName = GetPostString("fileName");
  9485. entity.Memo = GetPostString("memo");
  9486. entity.Img = GetPostString("img");
  9487. entity.Supplier = GetPostInt("supplier");
  9488. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9489. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9490. {
  9491. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9492. DateTime dt2 = (DateTime)entity.PreOutTime;
  9493. TimeSpan span = dt1.Subtract(dt2);
  9494. if (span.Days > 0)
  9495. {
  9496. entity.OutLate = span.Days;
  9497. }
  9498. }
  9499. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9500. entity.Update();
  9501. returnSuccessMsg("修改成功");
  9502. return;
  9503. }
  9504. returnErrorMsg("找不到对应的记录");
  9505. return;
  9506. }
  9507. }
  9508. returnErrorMsg("缺少必要参数");
  9509. }
  9510. public void del_erp_placeregist()
  9511. {
  9512. string eid = GetPostString("id");
  9513. CeErpPlaceRegister.Del(eid);
  9514. returnSuccessMsg("删除成功!");
  9515. return;
  9516. }
  9517. public void ins_erp_placeregistbyorder()
  9518. {
  9519. string ctid = GetPostString("ctid");
  9520. if (ctid.Length > 0)
  9521. {
  9522. StringBuilder sql = new StringBuilder();
  9523. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9524. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9525. if (dt.Rows.Count > 0)
  9526. {
  9527. foreach (DataRow dr in dt.Rows)
  9528. {
  9529. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9530. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9531. entity.AddUserId = CurrentUser.UserID;
  9532. entity.tid = dr["tid"].ToString();
  9533. entity.Did = Convert.ToString(dr["ctid"]);
  9534. entity.splitTag = dr["SplitTag"].ToString();
  9535. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9536. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9537. if (pre_ctid.Length > 0)
  9538. {
  9539. sellmemo = sellmemo.Replace(pre_ctid, "");
  9540. }
  9541. sellmemo = sellmemo.Replace("[", "");
  9542. sellmemo = sellmemo.Replace("]", "");
  9543. entity.FileName = sellmemo;
  9544. string count = dr["ProductCount"].ToString();
  9545. int usecount = commonHelper.getIntCountFromString(count);
  9546. entity.DeliveryCount = usecount;
  9547. entity.CurState = "未完成";
  9548. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9549. {
  9550. entity.Supplier = 24;//dl手提袋定制
  9551. }
  9552. else
  9553. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9554. entity.CreateTime = DateTime.Now;
  9555. entity.Create();
  9556. }
  9557. returnSuccessMsg("操作成功");
  9558. return;
  9559. }
  9560. returnErrorMsg("没有找到对应订单");
  9561. return;
  9562. }
  9563. returnErrorMsg("缺少订单编号");
  9564. return;
  9565. }
  9566. public void get_erp_persuadelist()
  9567. {
  9568. DataStruct dStruct = GetPostStruct();
  9569. List<string> lw = new List<string>();
  9570. string ctid = GetPostString("ctid");
  9571. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9572. string shopname = GetPostString("shopname");
  9573. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9574. string buyernick = GetPostString("buyer_nick");
  9575. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9576. string customer = GetPostString("customer");
  9577. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9578. string returndate1 = GetPostString("returndate1");
  9579. string returndate2 = GetPostString("returndate2");
  9580. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9581. if (dw.Length > 0) lw.Add(dw);
  9582. string finishDate1 = GetPostString("finishdate1");
  9583. string finishDate2 = GetPostString("finishdate2");
  9584. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9585. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9586. string persuadetype = GetPostString("persuadetype");
  9587. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9588. string returnvstate = GetPostString("returnvstate");
  9589. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9590. dStruct.Order = "created desc";
  9591. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9592. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9593. writeGridDataTableJson(dStruct.TotalCount, dt);
  9594. }
  9595. public void upd_erp_returnpersuadeback()
  9596. {
  9597. if (UrlPostParmsCheck("ID"))
  9598. {
  9599. int eid = GetPostInt("ID");
  9600. CeErpPersuade entity = null;
  9601. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9602. if (entity != null)
  9603. {
  9604. entity.backreason = GetPostString("reason");
  9605. entity.pstate = 2;
  9606. entity.verifytime = DateTime.Now;
  9607. entity.verifyuserid = CurrentUser.UserID;
  9608. entity.Update();
  9609. returnSuccessMsg("退回成功!");
  9610. return;
  9611. }
  9612. returnErrorMsg("找不到订单记录");
  9613. }
  9614. }
  9615. public void upd_erp_returnpersuadeverify()
  9616. {
  9617. if (UrlPostParmsCheck("ID"))
  9618. {
  9619. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9620. {
  9621. returnErrorMsg("暂无权限审核");
  9622. return;
  9623. }
  9624. int eid = GetPostInt("ID");
  9625. CeErpPersuade entity = null;
  9626. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9627. if (entity != null)
  9628. {
  9629. entity.pstate = 1;
  9630. entity.verifytime = DateTime.Now;
  9631. entity.verifyuserid = CurrentUser.UserID;
  9632. entity.Update();
  9633. returnSuccessMsg("审核成功!");
  9634. return;
  9635. }
  9636. returnErrorMsg("找不到订单记录");
  9637. }
  9638. }
  9639. public void del_erp_persuade()
  9640. {
  9641. if (UrlPostParmsCheck("ID"))
  9642. {
  9643. int eid = GetPostInt("ID");
  9644. CeErpPersuade.Del(eid);
  9645. returnSuccessMsg("操作成功");
  9646. return;
  9647. }
  9648. }
  9649. public void get_erp_oldcustoupload()
  9650. {
  9651. DataStruct dStruct = GetPostStruct();
  9652. List<string> lw = new List<string>();
  9653. string buyernick = GetPostString("buyer_nick");
  9654. if (buyernick.Length > 0)
  9655. {
  9656. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9657. }
  9658. else
  9659. return;
  9660. dStruct.Order = "pay_time desc";
  9661. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9662. DataTable dt = null;
  9663. dt = WebCache.GetData("view_erptradecell", dStruct);
  9664. writeGridDataTableJson(dStruct.TotalCount, dt);
  9665. }
  9666. public void get_erp_checkorderlist()
  9667. {
  9668. DataStruct dStruct = GetPostStruct();
  9669. List<string> lw = new List<string>();
  9670. string tid = GetPostString("ctid");
  9671. if (tid.Length > 0)
  9672. {
  9673. string select_tid = getTidByCtid(tid);
  9674. lw.Add(string.Format("tid='{0}'", select_tid));
  9675. }
  9676. string shopname = GetPostString("shopname");
  9677. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9678. string buyernick = GetPostString("buyer_nick");
  9679. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9680. string customer = GetPostString("customer");
  9681. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9682. string design = GetPostString("design");
  9683. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9684. string orderState = GetPostString("orderState");
  9685. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9686. string address = GetPostString("address");
  9687. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9688. string sellermemo = GetPostString("seller_memo");
  9689. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9690. string supplier = GetPostString("supplier");
  9691. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9692. {
  9693. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9694. }
  9695. else
  9696. {
  9697. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9698. }
  9699. string date1 = GetPostString("date1");
  9700. string date2 = GetPostString("date2");
  9701. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9702. if (dw.Length > 0) lw.Add(dw);
  9703. string placedate1 = GetPostString("placedate1");
  9704. string placedate2 = GetPostString("placedate2");
  9705. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9706. if (fdw.Length > 0) lw.Add(fdw);
  9707. string price1 = GetPostString("price1");
  9708. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9709. string price2 = GetPostString("price2");
  9710. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9711. string checkst = GetPostString("checkstate");
  9712. if (checkst.Length > 0 && "10".Equals(checkst))
  9713. {
  9714. lw.Add(string.Format("CheckOut>0"));
  9715. }
  9716. else
  9717. {
  9718. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9719. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9720. }
  9721. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9722. {
  9723. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9724. }
  9725. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9726. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9727. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9728. writeGridDataTableJson(dStruct.TotalCount, dt);
  9729. }
  9730. public void ins_erp_startCheck()
  9731. {
  9732. if (UrlPostParmsCheck("ctid"))
  9733. {
  9734. string eid = GetPostString("ctid");
  9735. CeErpTradeCell entity = null;
  9736. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9737. if (entity != null)
  9738. {
  9739. entity.MemoOpt = 4;
  9740. entity.UpdateTime = DateTime.Now;
  9741. entity.Update();
  9742. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9743. CeErpSukuraData.createInfo(entity.ctid, 6);
  9744. returnSuccessMsg("操作成功!");
  9745. return;
  9746. }
  9747. returnErrorMsg("找不到记录");
  9748. }
  9749. }
  9750. public void upd_erp_sendXlw()
  9751. {
  9752. if (UrlPostParmsCheck("ctid"))
  9753. {
  9754. string eid = GetPostString("ctid");
  9755. CeErpTradeCell entity = null;
  9756. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9757. if (entity != null)
  9758. {
  9759. if (entity.IsSendGift == 1)
  9760. {
  9761. returnErrorMsg("请勿重复标记");
  9762. return;
  9763. }
  9764. entity.IsSendGift = 1;
  9765. entity.Update();
  9766. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9767. returnSuccessMsg("操作成功!");
  9768. return;
  9769. }
  9770. returnErrorMsg("找不到记录");
  9771. }
  9772. }
  9773. public void cancel_sendXlw()
  9774. {
  9775. if (UrlPostParmsCheck("ctid"))
  9776. {
  9777. string eid = GetPostString("ctid");
  9778. CeErpTradeCell entity = null;
  9779. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9780. if (entity != null)
  9781. {
  9782. if (entity.IsSendGift == 0)
  9783. {
  9784. returnErrorMsg("未标记小礼物");
  9785. return;
  9786. }
  9787. entity.IsSendGift = 0;
  9788. entity.Update();
  9789. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9790. returnSuccessMsg("操作成功!");
  9791. return;
  9792. }
  9793. returnErrorMsg("找不到记录");
  9794. }
  9795. }
  9796. public void get_erp_designbill()
  9797. {
  9798. DataStruct dStruct = GetPostStruct();
  9799. List<string> lw = new List<string>();
  9800. int isMy = GetInt("my");
  9801. if (isMy == 1)
  9802. {
  9803. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9804. }
  9805. string tid = GetPostString("tid");
  9806. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9807. string userName = GetPostString("design");
  9808. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9809. string price1 = GetPostString("price1");
  9810. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9811. string price2 = GetPostString("price2");
  9812. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9813. string rePrice1 = GetPostString("rePrice1");
  9814. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9815. string rePrice2 = GetPostString("rePrice2");
  9816. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9817. string designerType = GetPostString("designerType");
  9818. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9819. string orderState = GetPostString("orderState");
  9820. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9821. string endTime1 = GetPostString("endTime1");
  9822. string endTime2 = GetPostString("endTime2");
  9823. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9824. if (dw.Length > 0) lw.Add(dw);
  9825. string isDk = GetPostString("isDk");
  9826. if (isDk == "1")
  9827. {
  9828. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9829. }
  9830. else if (isDk == "0")
  9831. {
  9832. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9833. }
  9834. dStruct.Order = "oid, create_time desc";
  9835. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9836. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9837. writeGridDataTableJson(dStruct.TotalCount, dt);
  9838. }
  9839. public void upd_erp_designerbill()
  9840. {
  9841. if (UrlPostParmsCheck("ID"))
  9842. {
  9843. string eid = GetPostString("ID");
  9844. CeErpDesignerBill entity = null;
  9845. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9846. if (entity != null)
  9847. {
  9848. if (GetPostDouble("designerpirce") > 0)
  9849. {
  9850. entity.realPrice = GetPostDouble("designerpirce");
  9851. entity.update_time = DateTime.Now;
  9852. entity.update_u_id = CurrentUser.UserID;
  9853. entity.update_u_name = CurrentUser.UserName;
  9854. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9855. entity.Update();
  9856. returnSuccessMsg("操作成功!");
  9857. return;
  9858. }
  9859. else
  9860. {
  9861. entity.price = GetPostDouble("price");
  9862. entity.update_time = DateTime.Now;
  9863. entity.update_u_id = CurrentUser.UserID;
  9864. entity.update_u_name = CurrentUser.UserName;
  9865. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9866. entity.Update();
  9867. returnSuccessMsg("操作成功!");
  9868. return;
  9869. }
  9870. }
  9871. returnErrorMsg("找不到记录");
  9872. }
  9873. }
  9874. public void audit_erp_designerbill()
  9875. {
  9876. if (UrlPostParmsCheck("ID"))
  9877. {
  9878. string eid = GetPostString("ID");
  9879. CeErpDesignerBill entity = null;
  9880. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9881. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9882. if (entity != null)
  9883. {
  9884. entity.realPrice = GetPostDouble("designerpirce");
  9885. entity.update_time = DateTime.Now;
  9886. entity.update_u_id = CurrentUser.UserID;
  9887. entity.update_u_name = CurrentUser.UserName;
  9888. entity.isAudit = 1;
  9889. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9890. entity.Update();
  9891. if (orderEntity != null)
  9892. {
  9893. orderEntity.IsReadTag = 3;
  9894. orderEntity.Update();
  9895. }
  9896. returnSuccessMsg("操作成功!");
  9897. return;
  9898. }
  9899. returnErrorMsg("找不到记录");
  9900. }
  9901. }
  9902. public void all_audit_erp_designerbill()
  9903. {
  9904. if (UrlPostParmsCheck("idList"))
  9905. {
  9906. string[] list = GetPostString("idList").Split(',');
  9907. CeErpDesignerBill entity = null;
  9908. for (int i = 0; i < list.Length; i++)
  9909. {
  9910. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9911. if (entity == null) return;
  9912. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9913. if (orderEntity == null) return;
  9914. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9915. entity.update_time = DateTime.Now;
  9916. entity.update_u_id = CurrentUser.UserID;
  9917. entity.update_u_name = CurrentUser.UserName;
  9918. entity.isAudit = 1;
  9919. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9920. entity.Update();
  9921. orderEntity.IsReadTag = 3;
  9922. orderEntity.Update();
  9923. }
  9924. returnSuccessMsg("操作成功!");
  9925. return;
  9926. }
  9927. }
  9928. public void get_erp_sameorders()
  9929. {
  9930. if (UrlPostParmsCheck("ctid"))
  9931. {
  9932. string eid = GetPostString("ctid");
  9933. CeErpTradeCell entity = null;
  9934. entity = CeErpTradeCell.GetByCtid(eid);
  9935. if (entity != null)
  9936. {
  9937. StringBuilder sql = new StringBuilder();
  9938. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9939. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9940. var res = new
  9941. {
  9942. data = dt.Rows.Count
  9943. };
  9944. string ro_jsond = JsonConvert.SerializeObject(res);
  9945. returnSuccess(ro_jsond);
  9946. return;
  9947. }
  9948. returnErrorMsg("未找到订单");
  9949. return;
  9950. }
  9951. returnErrorMsg("缺少必要的参数");
  9952. }
  9953. public void get_erp_islasthavesameorder()
  9954. {
  9955. if (UrlPostParmsCheck("ctid"))
  9956. {
  9957. string eid = GetPostString("ctid");
  9958. string[] ctidList = eid.Split(',');
  9959. StringBuilder sql = new StringBuilder();
  9960. string tisCtid = "";
  9961. foreach (string ctid in ctidList)
  9962. {
  9963. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9964. if (entity != null)
  9965. {
  9966. sql = new StringBuilder();
  9967. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9968. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9969. if (dth.Rows.Count > 0)
  9970. {
  9971. tisCtid += entity.ctid;
  9972. tisCtid += ",";
  9973. }
  9974. }
  9975. }
  9976. if (tisCtid.Length > 0)
  9977. {
  9978. var res = new
  9979. {
  9980. data = tisCtid
  9981. };
  9982. string ro_jsond = JsonConvert.SerializeObject(res);
  9983. returnSuccess(ro_jsond);
  9984. }
  9985. else
  9986. {
  9987. var res = new
  9988. {
  9989. data = ""
  9990. };
  9991. string ro_jsond = JsonConvert.SerializeObject(res);
  9992. returnSuccess(ro_jsond);
  9993. }
  9994. return;
  9995. }
  9996. returnErrorMsg("缺少必要的参数");
  9997. }
  9998. public void file_client_down_url()
  9999. {
  10000. if (!UrlPostParmsCheck("userId"))
  10001. {
  10002. returnErrorMsg("缺少必要的参数");
  10003. }
  10004. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  10005. }
  10006. public void checkout_form_data()
  10007. {
  10008. if (!UrlPostParmsCheck("tid"))
  10009. {
  10010. returnErrorMsg("缺少必要的参数");
  10011. }
  10012. string tid = GetPostString("tid");
  10013. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  10014. if (ceErpOrderFormData != null)
  10015. {
  10016. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  10017. returnSuccess(ro_jsond);
  10018. return;
  10019. }
  10020. returnErrorMsg("尚未有文件!");
  10021. }
  10022. public void back_supplier_audit()
  10023. {
  10024. int userId = CurrentUser.UserID;
  10025. StringBuilder sql = new StringBuilder();
  10026. sql.AppendFormat("SELECT D.tid FROM CE_ErpUser A LEFT JOIN view_ErpUserPost B ON A.ID = B.UserID LEFT JOIN CE_ErpUserInfo C ON A.InfoID = C.ID LEFT JOIN CE_Withdraw D ON A.pemVend = D.providerid WHERE a.ID ='{0}' and d.status = 3;", userId);
  10027. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10028. if (dt.Rows.Count > 0)
  10029. {
  10030. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10031. }
  10032. else
  10033. {
  10034. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10035. }
  10036. }
  10037. public void back_supplier_query()
  10038. {
  10039. string eid = GetPostString("ctid");
  10040. if (eid != "")
  10041. {
  10042. StringBuilder sql = new StringBuilder();
  10043. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  10044. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10045. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10046. }
  10047. else
  10048. {
  10049. returnErrorMsg("找不到订单记录");
  10050. return;
  10051. }
  10052. }
  10053. public void verified_to_order()
  10054. {
  10055. int userId = CurrentUser.UserID;
  10056. StringBuilder sql = new StringBuilder();
  10057. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  10058. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10059. if (dt.Rows.Count > 0)
  10060. {
  10061. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10062. }
  10063. else
  10064. {
  10065. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10066. }
  10067. }
  10068. public void upd_supplier_audit()
  10069. {
  10070. if (UrlPostParmsCheck("ctid"))
  10071. {
  10072. string eid = GetPostString("ctid");
  10073. string reason = GetPostString("returnreason");
  10074. CeErpTradeCell entity = null;
  10075. CeWithdraw withdraw = null;
  10076. withdraw = CeWithdraw.GetByTid(eid);
  10077. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  10078. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  10079. {
  10080. if (withdraw != null)
  10081. {
  10082. if (!withdraw.userid.Equals(CurrentUser.UserID))
  10083. {
  10084. returnSuccessMsg("您没有权限操作!");
  10085. return;
  10086. }
  10087. else
  10088. {
  10089. if (reason.Equals("1"))
  10090. {
  10091. if (entity.OrderState == -1)
  10092. {
  10093. if (entity.FinishPlaceTime == null)
  10094. {
  10095. entity.OrderState = 2;
  10096. }
  10097. else
  10098. {
  10099. entity.OrderState = 6;
  10100. }
  10101. }
  10102. entity.Update();
  10103. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10104. if (withdraw != null)
  10105. {
  10106. withdraw.status = int.Parse(reason);
  10107. withdraw.Update();
  10108. }
  10109. returnSuccessMsg("操作成功!");
  10110. return;
  10111. }
  10112. else
  10113. {
  10114. withdraw.status = int.Parse(reason);
  10115. withdraw.acknowledgingtime = DateTime.Now;
  10116. withdraw.Update();
  10117. returnSuccessMsg("查看详细请点击线下订单查询");
  10118. return;
  10119. }
  10120. }
  10121. }
  10122. // 第一个字符是 'N'
  10123. }
  10124. if (eid[0] != 'N')
  10125. {
  10126. }
  10127. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  10128. {
  10129. entity.IsVerifyToSupplier = false;
  10130. entity.IsReturn = 1;
  10131. entity.ReturnTime = DateTime.Now;
  10132. entity.ReturnReason = reason;
  10133. if (entity.OrderState == 6)
  10134. {
  10135. entity.OrderState = 5;
  10136. }
  10137. entity.Update();
  10138. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  10139. if (withdraw != null)
  10140. {
  10141. withdraw.status = int.Parse(reason);
  10142. withdraw.Update();
  10143. }
  10144. returnSuccessMsg("操作成功!");
  10145. return;
  10146. }
  10147. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  10148. {
  10149. ;
  10150. if (withdraw != null)
  10151. {
  10152. withdraw.status = int.Parse(reason);
  10153. withdraw.acknowledgingtime = DateTime.Now;
  10154. withdraw.Update();
  10155. returnSuccessMsg("供应商取消撤回!");
  10156. return;
  10157. }
  10158. }
  10159. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  10160. {
  10161. if (entity.OrderState == -1)
  10162. {
  10163. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  10164. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10165. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  10166. {
  10167. returnErrorMsg("台湾客户需填写身份证!");
  10168. return;
  10169. }
  10170. if (commonHelper.isFarAddress(ceErpTrade.receiver_state) && ceErpTrade.delivery_paymant == 0 && entity.IsSF != 2)
  10171. {
  10172. returnErrorMsg("偏远地区需要填写物流费!");
  10173. return;
  10174. }
  10175. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  10176. {
  10177. returnErrorMsg("订单spu没有确认无法通过审核!");
  10178. return;
  10179. }
  10180. if (entity.FinishPlaceTime == null)
  10181. {
  10182. entity.OrderState = 2;
  10183. }
  10184. else
  10185. {
  10186. entity.OrderState = 3;
  10187. }
  10188. commonHelper.getCytPrice(entity);
  10189. if ((entity.OtherMemo.Contains("老客户") || entity.OtherMemo.Contains("老顾客")) && entity.OtherMemo.Contains("改稿"))
  10190. {
  10191. tmcHelper.dealOldCustomerEntityTag(ref entity, ceErpTrade);
  10192. }
  10193. if (entity.IsSample > 1 || entity.seller_memo.Contains("现货") || entity.seller_memo.Contains("礼物"))
  10194. {
  10195. entity.OrderState = 6;
  10196. }
  10197. }
  10198. entity.Update();
  10199. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  10200. if (withdraw != null)
  10201. {
  10202. withdraw.status = int.Parse(reason);
  10203. withdraw.Update();
  10204. }
  10205. returnSuccessMsg("操作成功!");
  10206. return;
  10207. }
  10208. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  10209. {
  10210. if (withdraw == null)
  10211. {
  10212. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  10213. return;
  10214. }
  10215. }
  10216. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  10217. {
  10218. if (withdraw != null)
  10219. {
  10220. withdraw.status = int.Parse(reason);
  10221. withdraw.acknowledgingtime = DateTime.Now;
  10222. withdraw.Update();
  10223. returnSuccessMsg("查看详细请点击线下订单查询");
  10224. return;
  10225. }
  10226. }
  10227. return;
  10228. }
  10229. }
  10230. //校验报价
  10231. public void refund_order_tip()
  10232. {
  10233. int userid = CurrentUser.UserID;
  10234. int sectionId = CurrentUser.UserPost.OrgID;
  10235. StringBuilder sql = new StringBuilder();
  10236. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10237. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10238. List<string> ids = new List<string>();
  10239. if (dth.Rows.Count > 0)
  10240. {
  10241. foreach (DataRow dr in dth.Rows)
  10242. {
  10243. ids.Add(dr["ID"].ToString());
  10244. }
  10245. try
  10246. {
  10247. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10248. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10249. }
  10250. catch (Exception ex)
  10251. {
  10252. }
  10253. }
  10254. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10255. }
  10256. public void refund_order_Design()
  10257. {
  10258. int userid = CurrentUser.UserID;
  10259. int sectionId = CurrentUser.UserPost.OrgID;
  10260. StringBuilder sql = new StringBuilder();
  10261. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10262. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10263. List<string> ids = new List<string>();
  10264. if (dth.Rows.Count > 0)
  10265. {
  10266. foreach (DataRow dr in dth.Rows)
  10267. {
  10268. ids.Add(dr["ID"].ToString());
  10269. }
  10270. try
  10271. {
  10272. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10273. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10274. }
  10275. catch (Exception ex)
  10276. {
  10277. }
  10278. }
  10279. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10280. }
  10281. public void change_order_info()
  10282. {
  10283. int userid = CurrentUser.UserID;
  10284. StringBuilder sql = new StringBuilder();
  10285. sql.AppendFormat("select top 1 c.*,o.seller_memo as seller_memo from CE_ErpMessageTip c left join CE_ErpTradeCell o on o.ctid = c.tid where (c.userId = '{0}' ) and c.isVisit = 0 and c.type = 2;", userid);
  10286. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10287. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10288. }
  10289. public void size_order_tip()
  10290. {
  10291. int userid = CurrentUser.UserID;
  10292. StringBuilder sql = new StringBuilder();
  10293. sql.AppendFormat("select top 1 * from CE_ErpMessageTip c where (c.userId = '{0}' ) and c.isVisit = 0 and c.type in (3,4);", userid);
  10294. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10295. List<string> ids = new List<string>();
  10296. if (dth.Rows.Count > 0)
  10297. {
  10298. foreach (DataRow dr in dth.Rows)
  10299. {
  10300. ids.Add(dr["ID"].ToString());
  10301. }
  10302. try
  10303. {
  10304. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10305. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10306. }
  10307. catch (Exception ex)
  10308. {
  10309. }
  10310. }
  10311. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10312. }
  10313. public void change_win_mome()
  10314. {
  10315. if (UrlPostParmsCheck("id,ctid"))
  10316. {
  10317. string id = GetPostString("id");
  10318. string ctid = GetPostString("ctid");
  10319. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10320. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10321. if (ce == null || ceErpMessageTip == null)
  10322. {
  10323. returnSuccessMsg("未找到对应的订单!");
  10324. return;
  10325. }
  10326. if (ce.OrderState >= 5)
  10327. {
  10328. ceErpMessageTip.isVisit = true;
  10329. ceErpMessageTip.Update();
  10330. returnSuccessMsg("已上传文件无法修改!");
  10331. return;
  10332. }
  10333. int type = GetPostInt("type");
  10334. string content = GetPostString("content");
  10335. if (type == 0)
  10336. {
  10337. content = content.Replace("(", "(");
  10338. content = content.Replace(")", ")");
  10339. string check = MidStrEx(content, "(", ")").Trim();
  10340. if (string.IsNullOrEmpty(check))
  10341. {
  10342. returnSuccessMsg("文件名格式不正确");
  10343. return;
  10344. }
  10345. }
  10346. ce.seller_memo = content;
  10347. ce.Update();
  10348. ceErpMessageTip.isVisit = true;
  10349. ceErpMessageTip.Update();
  10350. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10351. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10352. ApiVo apiVo = new ApiVo();
  10353. apiVo.orderNumber = ce.ctid;
  10354. apiVo.actionName = "demandDesign";
  10355. apiVo.orderRemarks = content;
  10356. apiVo.demandExamine = type + 1;
  10357. designHelper.API_WorkCore(apiVo);//demandDesign
  10358. returnSuccessMsg("修改成功!");
  10359. }
  10360. }
  10361. public static string MidStrEx(string sourse, string startstr, string endstr)
  10362. {
  10363. string result = string.Empty;
  10364. int startindex, endindex;
  10365. try
  10366. {
  10367. startindex = sourse.IndexOf(startstr);
  10368. if (startindex == -1)
  10369. return result;
  10370. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10371. endindex = tmpstr.IndexOf(endstr);
  10372. if (endindex == -1)
  10373. return result;
  10374. result = tmpstr.Remove(endindex);
  10375. }
  10376. catch (Exception ex)
  10377. {
  10378. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10379. }
  10380. return result;
  10381. }
  10382. public void refund_order_list()
  10383. {
  10384. int userid = CurrentUser.UserID;
  10385. int sectionId = CurrentUser.UserPost.OrgID;
  10386. StringBuilder sql = new StringBuilder();
  10387. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10388. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10389. DataStruct dStruct = GetPostStruct();
  10390. DataTable dt = null;
  10391. List<string> ids = new List<string>();
  10392. List<string> tids = new List<string>();
  10393. if (dth.Rows.Count > 0)
  10394. {
  10395. foreach (DataRow dr in dth.Rows)
  10396. {
  10397. tids.Add("'" + dr["tid"].ToString() + "'");
  10398. ids.Add(dr["id"].ToString());
  10399. }
  10400. try
  10401. {
  10402. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10403. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10404. List<string> lw = new List<string>();
  10405. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10406. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10407. dt = WebCache.GetData("view_orderlist", dStruct);
  10408. }
  10409. catch (Exception ex)
  10410. {
  10411. }
  10412. }
  10413. writeGridDataTableJson(dStruct.TotalCount, dt);
  10414. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10415. }
  10416. //新增
  10417. public void order_batch_downloads()
  10418. {
  10419. string ceid = GetPostString("tid");
  10420. String[] tid = ceid.Split(',');
  10421. order_batch_caiyingtong(tid);
  10422. /* (string success, string errors) = UploadFiles(tid);
  10423. returnSuccessMsg(success + errors);*/
  10424. return;
  10425. }
  10426. //报价接口
  10427. public void Get_To_Quote()
  10428. {
  10429. string ceid = GetPostString("ctid");
  10430. if (ceid != null)
  10431. {
  10432. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10433. if (entity != null)
  10434. {
  10435. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10436. {
  10437. return;
  10438. }
  10439. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10440. double price = 0;
  10441. if (cp == null)
  10442. {
  10443. JObject jsonObject12 = new JObject
  10444. {
  10445. { "UserId", "77886" },
  10446. { "Pwd", "lt666888" },
  10447. { "Filename", entity.seller_memo }
  10448. };
  10449. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10450. JObject jsonObjects1 = JObject.Parse(response1);
  10451. string ms1g = (string)jsonObjects1["msg"];
  10452. if (ms1g == "报价成功")
  10453. {
  10454. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10455. string data = (string)jsonObject1["price"];
  10456. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  10457. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10458. returnSuccessMsg("获取报价成功:" + data);
  10459. price = Convert.ToDouble(data);
  10460. }
  10461. else
  10462. {
  10463. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10464. return;
  10465. }
  10466. }
  10467. String[] beizhu = entity.seller_memo.Split('-');
  10468. String chanp = "";
  10469. if (beizhu.Length > 0)
  10470. {
  10471. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10472. }
  10473. else
  10474. {
  10475. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10476. }
  10477. JObject jsonObject = new JObject
  10478. {
  10479. { "UserId", "77886" },
  10480. { "Pwd", "lt666888" },
  10481. { "Filename", chanp }
  10482. };
  10483. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10484. JObject jsonObjects = JObject.Parse(response);
  10485. string msg = (string)jsonObjects["msg"];
  10486. if (msg == "报价成功")
  10487. {
  10488. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10489. string data = (string)jsonObject1["price"];
  10490. string sql_pay = "INSERT INTO CE_CaiYingTongLog (ctid, ctime,type,msg) VALUES ('" + entity.ctid + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'," + 2 + ",'" + data + "');";
  10491. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10492. returnSuccessMsg("获取报价成功:" + data);
  10493. price = Convert.ToDouble(data);
  10494. }
  10495. else
  10496. {
  10497. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10498. return;
  10499. }
  10500. if (price > 0)
  10501. {
  10502. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10503. if (ceErpTradeCellExtend == null)
  10504. {
  10505. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10506. ceErpTradeCellExtend.ctid = entity.ctid;
  10507. ceErpTradeCellExtend.payment_cyt = price;
  10508. ceErpTradeCellExtend.Create();
  10509. }
  10510. else
  10511. {
  10512. ceErpTradeCellExtend.payment_cyt = price;
  10513. ceErpTradeCellExtend.Update();
  10514. }
  10515. }
  10516. return;
  10517. }
  10518. }
  10519. else
  10520. {
  10521. returnErrorMsg("请至少选择一条数据");
  10522. return;
  10523. }
  10524. }
  10525. //新增
  10526. public void order_To_Supplier()
  10527. {
  10528. string ceid = GetPostString("tid");
  10529. String[] tid = ceid.Split(',');
  10530. if (tid.Length > 0)
  10531. {
  10532. try
  10533. {
  10534. for (int i = 0; i < tid.Length; i++)
  10535. {
  10536. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10537. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10538. entity.SupplierId = suid;
  10539. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10540. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10541. entity.Update();
  10542. }
  10543. }
  10544. catch (Exception ex)
  10545. {
  10546. returnErrorMsg("自动匹配供应商失败");
  10547. return;
  10548. }
  10549. }
  10550. else
  10551. {
  10552. returnErrorMsg("请至少选择一条数据");
  10553. return;
  10554. }
  10555. returnSuccessMsg("自动匹配供应商成功");
  10556. return;
  10557. }
  10558. public (string, string) UploadFiles(string[] urls)
  10559. {
  10560. string success = "";
  10561. string errors = "";
  10562. int userid = CurrentUser.UserID;
  10563. foreach (string url in urls)
  10564. {
  10565. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10566. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10567. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10568. {
  10569. JObject jsonObject = new JObject
  10570. {
  10571. { "Userid", "77886" },
  10572. { "pwd", "cyt86435015" },
  10573. { "content", base64FileContent },
  10574. { "ext", Path.GetExtension(fileName) }
  10575. };
  10576. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10577. JObject jsonObjects = JObject.Parse(response);
  10578. string msg = (string)jsonObjects["msg"];
  10579. if (msg.Equals("上传成功"))
  10580. {
  10581. success += url + " 上传成功";
  10582. }
  10583. else
  10584. {
  10585. errors += url + " 上传失败";
  10586. }
  10587. }
  10588. else
  10589. {
  10590. errors += url + " 格式出现问题";
  10591. }
  10592. }
  10593. if (urls.Length == 0)
  10594. {
  10595. return (success, errors);
  10596. }
  10597. return (success, errors);
  10598. }
  10599. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10600. {
  10601. return true; //总是接受
  10602. }
  10603. public static string HttpPost(string url, string param = null)
  10604. {
  10605. HttpWebRequest request;
  10606. //如果是发送HTTPS请求
  10607. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10608. {
  10609. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10610. request = WebRequest.Create(url) as HttpWebRequest;
  10611. request.ProtocolVersion = HttpVersion.Version10;
  10612. }
  10613. else
  10614. {
  10615. request = WebRequest.Create(url) as HttpWebRequest;
  10616. }
  10617. request.Method = "POST";
  10618. request.ContentType = "application/json";
  10619. request.Accept = "*/*";
  10620. request.Timeout = 120000;
  10621. request.AllowAutoRedirect = false;
  10622. StreamWriter requestStream = null;
  10623. WebResponse response = null;
  10624. string responseStr = null;
  10625. try
  10626. {
  10627. requestStream = new StreamWriter(request.GetRequestStream());
  10628. requestStream.Write(param);
  10629. requestStream.Close();
  10630. response = request.GetResponse();
  10631. if (response != null)
  10632. {
  10633. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10634. responseStr = reader.ReadToEnd();
  10635. reader.Close();
  10636. }
  10637. }
  10638. catch (Exception ex)
  10639. {
  10640. return ex.Message;
  10641. }
  10642. finally
  10643. {
  10644. request = null;
  10645. requestStream = null;
  10646. response = null;
  10647. }
  10648. return responseStr;
  10649. }
  10650. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10651. {
  10652. string base64FileContent;
  10653. string fileName;
  10654. using (WebClient webClient = new WebClient())
  10655. {
  10656. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10657. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10658. {
  10659. using (Stream stream = response.GetResponseStream())
  10660. {
  10661. using (MemoryStream memoryStream = new MemoryStream())
  10662. {
  10663. stream.CopyTo(memoryStream);
  10664. byte[] fileBytes = memoryStream.ToArray();
  10665. base64FileContent = Convert.ToBase64String(fileBytes);
  10666. fileName = response.Headers["Content-Disposition"];
  10667. if (!string.IsNullOrEmpty(fileName))
  10668. {
  10669. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10670. if (index >= 0)
  10671. {
  10672. fileName = fileName.Substring(index + 9).Trim('\"');
  10673. }
  10674. }
  10675. else
  10676. {
  10677. fileName = Path.GetFileName(downloadUrl);
  10678. }
  10679. }
  10680. }
  10681. }
  10682. }
  10683. return (fileName, base64FileContent);
  10684. }
  10685. //新增
  10686. public void order_batch_caiyingtong(string[] downloadUrls)
  10687. {
  10688. try
  10689. {
  10690. //遍历文件
  10691. DataStruct dStruct = GetPostStruct();
  10692. DataTable dt = null;
  10693. int userid = CurrentUser.UserID;
  10694. List<string> ids = new List<string>();//失败组
  10695. List<string> tids = new List<string>();
  10696. using (WebClient webClient = new WebClient())
  10697. {
  10698. foreach (var url in downloadUrls)
  10699. {
  10700. try
  10701. {
  10702. tids.Add("'" + url + "'");
  10703. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10704. if (entity != null)
  10705. {
  10706. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10707. if (cp == null)
  10708. {
  10709. JObject jsonObject = new JObject
  10710. {
  10711. { "Userid", "77886" },
  10712. { "pwd", "lt666888" },
  10713. { "Filename",entity.seller_memo }
  10714. };
  10715. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10716. JObject jsonObjects = JObject.Parse(response);
  10717. string msg = (string)jsonObjects["msg"];
  10718. if (msg == "报价成功")
  10719. {
  10720. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10721. DownloadAndConvertToBase64(url1);
  10722. }
  10723. else
  10724. {
  10725. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10726. }
  10727. }
  10728. else
  10729. {
  10730. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10731. JObject jsonObject = new JObject
  10732. {
  10733. { "Userid", "77886" },
  10734. { "pwd", "lt666888" },
  10735. { "Filename",chanp }
  10736. };
  10737. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10738. JObject jsonObjects = JObject.Parse(response);
  10739. string msg = (string)jsonObjects["msg"];
  10740. if (msg == "报价成功")
  10741. {
  10742. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10743. DownloadAndConvertToBase64(url1);
  10744. }
  10745. else
  10746. {
  10747. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10748. }
  10749. }
  10750. }
  10751. // 上传文件到FTP
  10752. }
  10753. catch (Exception ex)
  10754. {
  10755. Console.WriteLine($"An error occurred: {ex.Message}");
  10756. }
  10757. }
  10758. List<string> lw = new List<string>();
  10759. lw.Add(string.Format("( OrderState < 6 )"));
  10760. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10761. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10762. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10763. if (dt.Rows.Count > 0)
  10764. {
  10765. foreach (DataRow dr in dt.Rows)
  10766. {
  10767. ids.Add(dr["ctid"].ToString());
  10768. }
  10769. }
  10770. String ErrorMsgs = "";
  10771. foreach (String id in ids)
  10772. {
  10773. ErrorMsgs += id + ",";
  10774. }
  10775. if (ErrorMsgs.Length > 1)
  10776. {
  10777. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10778. }
  10779. if (ErrorMsgs.Length < 1)
  10780. {
  10781. ErrorMsgs = "上传成功";
  10782. returnSuccessMsg(ErrorMsgs);
  10783. }
  10784. else
  10785. {
  10786. returnErrorMsg("以下订单" + ErrorMsgs);
  10787. }
  10788. }
  10789. // 删除文件夹及其内容
  10790. /* Directory.Delete(localDirectory, true);*/
  10791. }
  10792. catch { }
  10793. }
  10794. public void get_center_data()
  10795. {
  10796. int userId = CurrentUser.UserID;
  10797. string postCode = CurrentUser.UserPost.Post.Code;
  10798. List<string> lw = new List<string>();
  10799. List<string> ww = new List<string>();
  10800. DateTime currentTime = DateTime.Now;
  10801. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10802. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10803. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10804. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10805. string sql = " SELECT ";
  10806. string startTime = "2023-10-01 11:22:31";
  10807. //设计
  10808. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10809. {
  10810. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10811. ww.Add(string.Format("( SELECT COUNT ( * ) AS designCount FROM CE_ErpTradeCell WHERE pay_time < '{2}' AND OrderState < 5 AND IsReturn = 0 AND pay_time > '{0}' AND DesignUserId = {1} ) AS dc", startTime, userId, payTime));
  10812. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10813. ww.Add(string.Format("( SELECT COUNT ( * ) AS backCount FROM CE_ErpTradeCell WHERE OrderState = 4 AND ReturnTime IS NOT NULL AND pay_time > '{0}' AND DesignUserId = {1} ) AS bc", startTime, userId));
  10814. }
  10815. //客服
  10816. else if (postCode == "CustomerService" || postCode == "Director")
  10817. {
  10818. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10819. ww.Add(string.Format("( SELECT COUNT ( * ) AS designCount FROM CE_ErpTradeCell WHERE pay_time < '{2}' AND OrderState < 5 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS dc", startTime, userId, payTime));
  10820. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10821. ww.Add(string.Format("( SELECT COUNT ( * ) AS orderCount FROM CE_ErpTradeCell WHERE FinishDesignTime < '{2}' AND OrderState = 5 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS oc", startTime, userId, finishDesignTime));
  10822. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10823. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{2}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' AND CustomerUserId = {1} ) AS sc", startTime, userId, finishPlaceTime));
  10824. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10825. ww.Add(string.Format("( SELECT COUNT ( * ) AS backCount FROM CE_ErpTradeCell WHERE OrderState = 0 AND ReturnTime IS NOT NULL AND pay_time > '{0}' AND CustomerUserId = {1} ) AS bc", startTime, userId));
  10826. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10827. ww.Add(string.Format("( SELECT COUNT ( * ) AS refundCount FROM CE_ErpTradeCell WHERE IsRefund > 0 AND OrderState NOT IN ( 8, 9 ) AND pay_time > '{0}' AND CustomerUserId = {1} ) AS rc", startTime, userId));
  10828. }
  10829. //售后
  10830. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10831. {
  10832. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10833. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{1}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' ) AS sc", startTime, finishPlaceTime));
  10834. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10835. ww.Add(string.Format("( SELECT COUNT ( * ) AS refundCount FROM CE_ErpTradeCell WHERE IsRefund > 0 AND OrderState NOT IN ( 8, 9 ) AND pay_time > '{0}' ) AS rc", startTime));
  10836. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10837. ww.Add(string.Format("( SELECT COUNT ( * ) AS checkCount FROM CE_ErpTradeCell WHERE CheckOrderTime < '{1}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND pay_time > '{0}' ) AS cc", startTime, checkOrderTime));
  10838. }
  10839. //下单部
  10840. else if (postCode == "Place" || postCode == "PlaceMr")
  10841. {
  10842. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10843. ww.Add(string.Format("( SELECT COUNT ( * ) AS orderCount FROM CE_ErpTradeCell WHERE FinishDesignTime < '{1}' AND OrderState = 5 AND IsReturn = 0 AND pay_time > '{0}' ) AS oc", startTime, finishDesignTime));
  10844. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10845. ww.Add(string.Format("( SELECT COUNT ( * ) AS sendCount FROM CE_ErpTradeCell WHERE FinishPlaceTime < '{1}' AND OrderState = 6 AND IsReturn = 0 AND pay_time > '{0}' ) AS sc", startTime, finishPlaceTime));
  10846. }
  10847. //车间
  10848. else if (postCode == "Supplier")
  10849. {
  10850. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10851. ww.Add(string.Format("( SELECT COUNT ( * ) AS checkCount FROM CE_ErpTradeCell WHERE CheckOrderTime < '{1}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND pay_time > '{0}' AND SupplierId = {2} ) AS cc", startTime, checkOrderTime, userId));
  10852. }
  10853. DataTable dt = new DataTable();
  10854. if (lw.Count > 0)
  10855. {
  10856. sql += string.Join(" , ", lw);
  10857. sql += " FROM ";
  10858. sql += string.Join(" , ", ww);
  10859. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10860. }
  10861. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10862. }
  10863. public void get_center_data_list()
  10864. {
  10865. int userId = CurrentUser.UserID;
  10866. string postCode = CurrentUser.UserPost.Post.Code;
  10867. string shopIds = CurrentUser.User.pemShop;
  10868. DataStruct dStruct = GetPostStruct();
  10869. List<string> lw = new List<string>();
  10870. DateTime currentTime = DateTime.Now;
  10871. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10872. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10873. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10874. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10875. string startTime = "2023-10-01 11:22:31";
  10876. int order_type = GetPostInt("order_type");
  10877. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10878. {
  10879. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10880. if (order_type == 0)
  10881. {
  10882. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10883. }
  10884. else if (order_type == 3)
  10885. {
  10886. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10887. }
  10888. else
  10889. {
  10890. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10891. }
  10892. }
  10893. //客服
  10894. if (postCode == "CustomerService" || postCode == "Director")
  10895. {
  10896. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10897. if (order_type == 0)
  10898. {
  10899. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10900. }
  10901. else if (order_type == 1)
  10902. {
  10903. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10904. }
  10905. else if (order_type == 2)
  10906. {
  10907. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10908. }
  10909. else if (order_type == 3)
  10910. {
  10911. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10912. }
  10913. else if (order_type == 4)
  10914. {
  10915. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10916. }
  10917. else
  10918. {
  10919. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10920. }
  10921. }
  10922. //售后
  10923. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10924. {
  10925. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10926. if (shopIds != "")
  10927. {
  10928. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10929. }
  10930. if (order_type == 2)
  10931. {
  10932. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10933. }
  10934. else if (order_type == 4)
  10935. {
  10936. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10937. }
  10938. else if (order_type == 5)
  10939. {
  10940. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10941. }
  10942. else
  10943. {
  10944. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10945. }
  10946. }
  10947. //下单部
  10948. if (postCode == "Place" || postCode == "PlaceMr")
  10949. {
  10950. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10951. if (shopIds != "")
  10952. {
  10953. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10954. }
  10955. else if (order_type == 1)
  10956. {
  10957. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10958. }
  10959. else if (order_type == 2)
  10960. {
  10961. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10962. }
  10963. else
  10964. {
  10965. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10966. }
  10967. }
  10968. //车间
  10969. if (postCode == "Supplier")
  10970. {
  10971. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10972. if (order_type == 5)
  10973. {
  10974. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10975. }
  10976. else
  10977. {
  10978. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10979. }
  10980. }
  10981. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10982. dStruct.Fileds = "tid,ctid";
  10983. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10984. writeGridDataTableJson(dStruct.TotalCount, dt);
  10985. }
  10986. public void aftersale_audit_master()
  10987. {
  10988. if (UrlPostParmsCheck("ctid"))
  10989. {
  10990. string ctid = GetPostString("ctid");
  10991. if (ctid.Length > 0)
  10992. {
  10993. bool result = aftersale_data_change(ctid);
  10994. if (result)
  10995. {
  10996. returnSuccessMsg("修改成功!");
  10997. return;
  10998. }
  10999. }
  11000. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11001. }
  11002. }
  11003. public void aftersale_documentary_finish()
  11004. {
  11005. if (UrlPostParmsCheck("ctid"))
  11006. {
  11007. string ctid = GetPostString("ctid");
  11008. if (ctid.Length > 0)
  11009. {
  11010. List<string> list = new List<string>();
  11011. string[] ctid_list = ctid.Split(',');
  11012. foreach (var item in ctid_list)
  11013. {
  11014. try
  11015. {
  11016. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(item);
  11017. if (ceErpTradeAfterSaleExtend == null)
  11018. {
  11019. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11020. ceErpTradeAfterSaleExtend.tid = item;
  11021. }
  11022. ceErpTradeAfterSaleExtend.AfterSalSend = 1;
  11023. if (ceErpTradeAfterSaleExtend.ID > 0)
  11024. {
  11025. ceErpTradeAfterSaleExtend.Update();
  11026. }
  11027. else
  11028. {
  11029. ceErpTradeAfterSaleExtend.Create();
  11030. }
  11031. LogHelper.addLog(item, CurrentUser.UserID, "跟单完成", 6, 4);
  11032. }
  11033. catch (Exception ex)
  11034. {
  11035. list.Add(item);
  11036. }
  11037. }
  11038. if (list.Count > 0)
  11039. {
  11040. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11041. return;
  11042. }
  11043. returnSuccessMsg("修改成功!");
  11044. return;
  11045. }
  11046. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11047. }
  11048. }
  11049. public void aftersale_batch_audit_master()
  11050. {
  11051. if (UrlPostParmsCheck("ctids"))
  11052. {
  11053. string ctids = GetPostString("ctids");
  11054. if (ctids.Length > 0)
  11055. {
  11056. List<string> list = new List<string>();
  11057. string[] ctid_list = ctids.Split(',');
  11058. foreach (var item in ctid_list)
  11059. {
  11060. bool result = aftersale_data_change(item);
  11061. if (!result)
  11062. {
  11063. list.Add(item);
  11064. }
  11065. }
  11066. if (list.Count > 0)
  11067. {
  11068. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  11069. return;
  11070. }
  11071. returnSuccessMsg("修改成功!");
  11072. return;
  11073. }
  11074. returnErrorMsg("找不到指定售后单对应的原始订单!");
  11075. }
  11076. }
  11077. public bool aftersale_data_change(string ctid)
  11078. {
  11079. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11080. if (ceErpTradeCell != null)
  11081. {
  11082. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  11083. ceErpTradeCell.AfterSaleSupplierState = 0;
  11084. StringBuilder sql = new StringBuilder();
  11085. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  11086. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11087. CeErpTradeResponsible.DelByTid(ctid, 0);
  11088. if ((ceErpTradeCell.AfterSaleResponsible.IndexOf("客户问题") != -1 && ceErpTradeCell.AfterSaleResponsible.IndexOf(",客户问题") == -1) || (ceErpTradeCell.AfterSaleResponsible.IndexOf("系统问题") != -1 && ceErpTradeCell.AfterSaleResponsible.IndexOf(",系统问题") == -1) || ceErpTradeCell.supRefundType == "正常损耗" || ceErpTradeCell.supRefundType == "车间不售后" || ceErpTradeCell.supRefundType == "不售后" || ceErpTradeCell.supRefundType == "不理赔")
  11089. {
  11090. CeErpTradeResponsible.DelByTid(ctid, -1);
  11091. ceErpTradeCell.AfterSaleSupplierState = 1;
  11092. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11093. ceErpTradeCell.AfterSaleState = 4;
  11094. }
  11095. else
  11096. {
  11097. ceErpTradeCell.AfterSaleState = 3;
  11098. }
  11099. bool needCyt = false;
  11100. if (dt != null)
  11101. {
  11102. if (dt.Rows.Count == 1)
  11103. {
  11104. bool isEnd = false;
  11105. foreach (DataRow dr in dt.Rows)
  11106. {
  11107. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11108. {
  11109. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11110. isEnd = true;
  11111. }
  11112. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  11113. {
  11114. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11115. isEnd = true;
  11116. }
  11117. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11118. {
  11119. needCyt = true;
  11120. }
  11121. }
  11122. if (isEnd)
  11123. {
  11124. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11125. ceErpTradeCell.AfterSaleState = 4;
  11126. ceErpTradeCell.AfterSaleSupplierState = 1;
  11127. }
  11128. }
  11129. else
  11130. {
  11131. bool isAll = true;
  11132. foreach (DataRow dr in dt.Rows)
  11133. {
  11134. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  11135. {
  11136. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11137. continue;
  11138. }
  11139. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  11140. {
  11141. string path = "";
  11142. int OrgID = 0;
  11143. if (!Convert.IsDBNull(dr["OrgPath"]))
  11144. {
  11145. path = dr["OrgPath"].ToString();
  11146. }
  11147. if (!Convert.IsDBNull(dr["OrgID"]))
  11148. {
  11149. OrgID = Convert.ToInt32(dr["OrgID"]);
  11150. }
  11151. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  11152. {
  11153. CeErpTradeResponsible.DelById(dr["ID"], 1);
  11154. continue;
  11155. }
  11156. }
  11157. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  11158. {
  11159. needCyt = true;
  11160. }
  11161. isAll = false;
  11162. }
  11163. if (isAll)
  11164. {
  11165. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  11166. ceErpTradeCell.AfterSaleState = 4;
  11167. ceErpTradeCell.AfterSaleSupplierState = 1;
  11168. }
  11169. }
  11170. }
  11171. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  11172. {
  11173. commonHelper.sendCytAfterSale(ceErpTradeCell);
  11174. }
  11175. if (ceErpTradeCell.AfterSaleState == 4)
  11176. {
  11177. ApiVo apiVo = new ApiVo();
  11178. apiVo.orderNumber = ceErpTradeCell.ctid;
  11179. apiVo.actionName = "afterOver";
  11180. designHelper.API_WorkCore(apiVo); //afterOver
  11181. }
  11182. ceErpTradeCell.Update();
  11183. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  11184. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  11185. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  11186. return true;
  11187. }
  11188. return false;
  11189. }
  11190. public void get_erp_wechatorder()
  11191. {
  11192. DataStruct dStruct = GetPostStruct();
  11193. List<string> lw = new List<string>();
  11194. string tid = GetPostString("tid");
  11195. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11196. string shopname = GetPostString("shopname");
  11197. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11198. string buyernick = GetPostString("buyer_nick");
  11199. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11200. string customer = GetPostString("customer");
  11201. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11202. string returndate1 = GetPostString("returndate1");
  11203. string returndate2 = GetPostString("returndate2");
  11204. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11205. if (dw.Length > 0) lw.Add(dw);
  11206. string finishDate1 = GetPostString("finishdate1");
  11207. string finishDate2 = GetPostString("finishdate2");
  11208. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11209. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11210. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11211. dStruct.Order = "created desc";
  11212. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11213. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  11214. writeGridDataTableJson(dStruct.TotalCount, dt);
  11215. }
  11216. public void get_erp_wechatlist_sumprice()
  11217. {
  11218. DataStruct dStruct = GetPostStruct();
  11219. List<string> lw = new List<string>();
  11220. string tid = GetPostString("tid");
  11221. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  11222. string shopname = GetPostString("shopname");
  11223. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11224. string buyernick = GetPostString("buyer_nick");
  11225. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11226. string customer = GetPostString("customer");
  11227. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  11228. string returndate1 = GetPostString("returndate1");
  11229. string returndate2 = GetPostString("returndate2");
  11230. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  11231. if (dw.Length > 0) lw.Add(dw);
  11232. string finishDate1 = GetPostString("finishdate1");
  11233. string finishDate2 = GetPostString("finishdate2");
  11234. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  11235. if (dw_finish.Length > 0) lw.Add(dw_finish);
  11236. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  11237. string mainWhere = string.Join(" and ", lw.ToArray());
  11238. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  11239. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  11240. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  11241. decimal total = 0;
  11242. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  11243. {
  11244. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  11245. }
  11246. var res = new
  11247. {
  11248. data = total
  11249. };
  11250. string ro_jsond = JsonConvert.SerializeObject(res);
  11251. returnSuccess(ro_jsond);
  11252. return;
  11253. }
  11254. public void get_erp_qr_waitdeliverylist()
  11255. {
  11256. DataStruct dStruct = GetPostStruct();
  11257. List<string> lw = new List<string>();
  11258. string tid = GetPostString("ctid");
  11259. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  11260. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11261. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  11262. var res_objz = new
  11263. {
  11264. restype = 1,
  11265. data = dt
  11266. };
  11267. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  11268. returnSuccess(ro_jsonz);
  11269. }
  11270. public void get_erp_yield_list()
  11271. {
  11272. DataStruct dStruct = GetPostStruct();
  11273. List<string> lw = new List<string>();
  11274. string tid = GetPostString("ctid");
  11275. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  11276. string shopname = GetPostString("shopname");
  11277. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  11278. string buyernick = GetPostString("buyer_nick");
  11279. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  11280. //if (tid.Length == 0 && buyernick.Length == 0)
  11281. //{
  11282. // lw.Add(string.Format("IsRefund<={0}", 1));
  11283. //}
  11284. string customer = GetPostString("customer");
  11285. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11286. string design = GetPostString("design");
  11287. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11288. string orderState = GetPostString("orderState");
  11289. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  11290. string address = GetPostString("address");
  11291. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  11292. string sellermemo = GetPostString("seller_memo");
  11293. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11294. string supplier = GetPostString("supplier");
  11295. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11296. string OrderArea = GetPostString("order_area");
  11297. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11298. string placedate1 = GetPostString("placedate1");
  11299. string placedate2 = GetPostString("placedate2");
  11300. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11301. if (fdw.Length > 0) lw.Add(fdw);
  11302. string price1 = GetPostString("price1");
  11303. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11304. string price2 = GetPostString("price2");
  11305. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11306. string unusualCon = GetPostString("unusualcon");
  11307. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11308. string posTag = CurrentUser.UserPost.Post.Code;
  11309. if (posTag == "Supplier")
  11310. {
  11311. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11312. }
  11313. lw.Add(string.Format("OrderState = 6 "));
  11314. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11315. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11316. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11317. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11318. writeGridDataTableJson(dStruct.TotalCount, dt);
  11319. }
  11320. public void change_erp_sup_state()
  11321. {
  11322. if (UrlPostParmsCheck("ctid"))
  11323. {
  11324. string ctid = GetPostString("ctid");
  11325. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11326. if (ceErpTradeCell != null)
  11327. {
  11328. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11329. if (ceErpTradeCellExtend == null)
  11330. {
  11331. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11332. ceErpTradeCellExtend.ctid = ctid;
  11333. ceErpTradeCellExtend.SupState = 1;
  11334. ceErpTradeCellExtend.Create();
  11335. }
  11336. else
  11337. {
  11338. ceErpTradeCellExtend.SupState = 1;
  11339. ceErpTradeCellExtend.Update();
  11340. }
  11341. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11342. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11343. return;
  11344. }
  11345. returnErrorMsg("找不到订单");
  11346. }
  11347. }
  11348. public void supplier_all_downs()
  11349. {
  11350. if (UrlPostParmsCheck("tids"))
  11351. {
  11352. string tids = GetPostString("tids");
  11353. if (tids != null && tids.Length > 0)
  11354. {
  11355. StringBuilder sql = new StringBuilder();
  11356. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11357. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11358. sql = new StringBuilder();
  11359. sql.AppendFormat("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"), (int)OrderState.下单完成, CurrentUser.UserID, "下载设计文件");
  11360. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11361. string[] list = tids.Split(',');
  11362. foreach (string ctid in list)
  11363. {
  11364. CeErpSukuraData.createInfo(ctid, 3);
  11365. }
  11366. designHelper.api_approveDesign(tids); //approveDesign
  11367. returnSuccessMsg("下载成功!");
  11368. return;
  11369. }
  11370. returnErrorMsg("下载订单更新失败");
  11371. }
  11372. }
  11373. public void uploaderFileSuccess()
  11374. {
  11375. if (UrlPostParmsCheck("fileName"))
  11376. {
  11377. string fileName = GetPostString("fileName");
  11378. ApiVo apiVo = new ApiVo();
  11379. apiVo.orderNumber = fileName;
  11380. apiVo.actionName = "finishDesign";
  11381. designHelper.API_WorkCore(apiVo);//finishDesign
  11382. returnSuccessMsg("");
  11383. }
  11384. }
  11385. public void get_sample2_order()
  11386. {
  11387. if (UrlPostParmsCheck("ctid"))
  11388. {
  11389. string ctid = GetPostString("ctid");
  11390. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11391. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11392. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11393. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11394. double total = 0.0;
  11395. double order_price = 0.0;
  11396. if (dt_bu.Rows.Count > 0)
  11397. {
  11398. foreach (DataRow dr in dt_bu.Rows)
  11399. {
  11400. total += Convert.ToDouble(dr["payment"]);
  11401. }
  11402. }
  11403. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11404. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11405. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11406. string tid = ctid.Replace("S_", "");
  11407. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11408. double paymant = 0.0;
  11409. if (entity != null)
  11410. {
  11411. paymant = entity.payment;
  11412. }
  11413. string return_reason = "";
  11414. if (dt_after != null && dt_after.Rows.Count > 0)
  11415. {
  11416. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11417. }
  11418. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11419. }
  11420. }
  11421. public void get_erp_design_status()
  11422. {
  11423. string designName = GetPostString("designName");
  11424. DataStruct dStruct = GetPostStruct();
  11425. if (designName.Length > 0)
  11426. {
  11427. string sql_user = "select id,Name,TeamIds from view_ErpUser where (PostCode='Designer' or PostCode='DesignerMr' or PostCode='Designerhd' or PostCode='wxDesigner' or PostCode='wxDesignerMr') and isopen = 1";
  11428. sql_user += " and Name like '%" + designName + "%'";
  11429. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11430. List<string> ids_list = new List<string>();
  11431. if (user_table.Rows.Count > 0)
  11432. {
  11433. foreach (DataRow item in user_table.Rows)
  11434. {
  11435. ids_list.Add(item["id"].ToString());
  11436. string ids_s = item["TeamIds"].ToString();
  11437. if (ids_s.Length > 0)
  11438. {
  11439. ids_list.AddRange(ids_s.Split(','));
  11440. }
  11441. }
  11442. }
  11443. HashSet<string> set = new HashSet<string>(ids_list);
  11444. ids_list = set.ToList();
  11445. if (ids_list.Count > 0)
  11446. {
  11447. string sql = string.Format(" (PostCode='Designer' or PostCode='DesignerMr' or PostCode='Designerhd' or PostCode='wxDesigner' or PostCode='wxDesignerMr') and isopen = 1 and id in ({0})", string.Join(",", ids_list));
  11448. dStruct.MainWhere = sql;
  11449. DataTable dt = null;
  11450. dt = WebCache.GetData("view_ErpUser", dStruct);
  11451. writeGridDataTableJson(dStruct.TotalCount, dt);
  11452. }
  11453. }
  11454. }
  11455. public void change_erp_order_price()
  11456. {
  11457. string ctid = GetPostString("ctid");
  11458. double price = GetPostDouble("price");
  11459. if (ctid.Length > 0)
  11460. {
  11461. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11462. if (ceErpTradeCellExtend == null)
  11463. {
  11464. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11465. ceErpTradeCellExtend.ctid = ctid;
  11466. ceErpTradeCellExtend.payment_cyt = price;
  11467. ceErpTradeCellExtend.Create();
  11468. }
  11469. else
  11470. {
  11471. ceErpTradeCellExtend.payment_cyt = price;
  11472. ceErpTradeCellExtend.Update();
  11473. }
  11474. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11475. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11476. {
  11477. ceErpDataSendOrderInfo.isSync = false;
  11478. ceErpDataSendOrderInfo.Update();
  11479. }
  11480. if (ceErpDataSendOrderInfo == null)
  11481. {
  11482. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11483. ceErpDataSendOrderInfo.isSync = false;
  11484. ceErpDataSendOrderInfo.ctid = ctid;
  11485. ceErpDataSendOrderInfo.Create();
  11486. }
  11487. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11488. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11489. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11490. if (dth != null && dth.Rows.Count > 0 && ceErpTradeCellExtend.payment_cyt > 0)
  11491. {
  11492. dataSendOrderBean dataSendOrderBean = null;
  11493. foreach (DataRow item in dth.Rows)
  11494. {
  11495. try
  11496. {
  11497. dataSendOrderBean = new dataSendOrderBean();
  11498. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11499. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11500. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11501. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11502. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11503. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11504. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11505. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11506. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11507. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11508. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11509. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11510. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11511. if (result != null)
  11512. {
  11513. if ("0".Equals(result.errcode))
  11514. {
  11515. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11516. }
  11517. else
  11518. {
  11519. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11520. }
  11521. }
  11522. }
  11523. catch (Exception ex)
  11524. {
  11525. }
  11526. }
  11527. }
  11528. returnSuccessMsg("修改成功!");
  11529. return;
  11530. }
  11531. returnErrorMsg("找不到订单");
  11532. }
  11533. public void find_he_together()
  11534. {
  11535. string ctid = GetPostString("ctid");
  11536. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11537. List<string> list = new List<string>();
  11538. if (ceErpTradeCell != null)
  11539. {
  11540. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11541. {
  11542. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where tid='{0}' and ctid <> '{1}' and SupplierId = {2}", ceErpTradeCell.tid, ceErpTradeCell.ctid, ceErpTradeCell.SupplierId);
  11543. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11544. if (table != null && table.Rows.Count > 0)
  11545. {
  11546. foreach (TableRow row in table.Rows)
  11547. {
  11548. }
  11549. }
  11550. }
  11551. }
  11552. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11553. }
  11554. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11555. {
  11556. //chy----19
  11557. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11558. //GD-CYT-----64
  11559. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11560. //ZHX----3
  11561. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11562. //JK----97
  11563. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11564. //ZT----70
  11565. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11566. //GD-CYTUV---126
  11567. {126, new Dictionary<string, string> {{"uv", "uv"}}},
  11568. //LHCY-----98
  11569. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11570. //XD-----90
  11571. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11572. //CYCY-----14
  11573. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}},
  11574. //THLZY----122
  11575. {122, new Dictionary<string, string> {{ "烫画", "烫画" }, { "冷转印", "冷转印" }}}
  11576. };
  11577. //其他改名
  11578. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11579. {
  11580. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11581. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11582. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11583. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11584. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11585. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11586. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11587. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" },{ 129,"种子纸"},{ 125,"胶带"},{ 127,"PET透卡"}
  11588. };
  11589. //不统计
  11590. List<int> no_suppliers = new List<int>()
  11591. {
  11592. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11593. };
  11594. //配件单
  11595. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11596. {
  11597. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11598. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11599. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11600. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11601. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11602. {"旗杆",new List<string>(){ "班旗" } },
  11603. {"牙签",new List<string>(){ "不干胶" } }
  11604. };
  11605. public void get_place_order_data()
  11606. {
  11607. string date1 = GetPostString("date1");
  11608. string date2 = GetPostString("date2");
  11609. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11610. DateTime start = DateTime.Parse(starttime);
  11611. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11612. DateTime end = DateTime.Parse(endtime);
  11613. if (date1 != null && date1.Length > 0)
  11614. {
  11615. DateTime dateTime = DateTime.Parse(date1);
  11616. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11617. start = DateTime.Parse(starttime);
  11618. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11619. end = DateTime.Parse(endtime);
  11620. }
  11621. if (date2 != null && date2.Length > 0)
  11622. {
  11623. DateTime dateTime = DateTime.Parse(date2);
  11624. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11625. end = DateTime.Parse(endtime);
  11626. }
  11627. List<int> smSupplier = new List<int>() { 97, 121, 119, 80 };
  11628. string startMonthDate = commonHelper.FirstDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 00:00:00");
  11629. string endMonthDate = commonHelper.LastDayOfMonth(DateTime.Now).ToString("yyyy-MM-dd 23:59:59");
  11630. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime,AfterSaleState=0,AfterSaleReason = '',delivery=0 from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  11631. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11632. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState,AfterSaleReason,delivery=0 FROM view_ErpTradeCell WHERE ( AfterSalePreTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime IS NOT NULL", startMonthDate, endMonthDate);
  11633. DataTable afterSaleData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11634. data.Merge(afterSaleData);
  11635. sql = string.Format("SELECT SupplierId, ProductId, seller_memo, ProductCount, ProductName, payment, SupplierName, UnusualTime, FinishPlaceTime, OrderState, FinishDeliveryTime, AfterSaleState=0,AfterSaleReason = '',delivery=1 FROM view_ErpTradeCell WHERE orderstate = 6 AND IsSample = 0 AND SupplierId > 0 AND FinishPlaceTime > '2025-11-01 00:00:31.000' AND IsRefund <= 1 AND status = 'NOT_SHIPPED' AND LEN( ProductName ) > 0 AND SupplierId not in (86,10,105,86)", startMonthDate, endMonthDate);
  11636. DataTable deliveryData = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11637. data.Merge(deliveryData);
  11638. //获取商品发货时间
  11639. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  11640. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  11641. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  11642. foreach (DataRow datarow in timer_data.Rows)
  11643. {
  11644. List<CeErpSupplierProductTime> list = null;
  11645. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  11646. if (timer_map.ContainsKey(supplierId))
  11647. {
  11648. timer_map.TryGetValue(supplierId, out list);
  11649. }
  11650. else
  11651. {
  11652. list = new List<CeErpSupplierProductTime>();
  11653. timer_map.Add(supplierId, list);
  11654. timer_map.TryGetValue(supplierId, out list);
  11655. }
  11656. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  11657. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  11658. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  11659. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  11660. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  11661. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  11662. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  11663. list.Add(ceErpSupplierProductTime);
  11664. }
  11665. //不干胶-----1,卡片-----29
  11666. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11667. foreach (DataRow row in data.Rows)
  11668. {
  11669. int productId = Convert.ToInt32(row["ProductId"]);
  11670. string ProductName = row["ProductName"].ToString();
  11671. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11672. if (no_suppliers.Contains(supplierId))
  11673. {
  11674. continue;
  11675. }
  11676. string seller_memo = row["seller_memo"].ToString();
  11677. bool ispj = false;//是否配件单
  11678. bool isfirst = true;//第一个配
  11679. maps.Keys.ForEach(key =>
  11680. {
  11681. //备注包含配件
  11682. if (seller_memo.Contains(key) && isfirst)
  11683. {
  11684. List<string> list = maps[key];
  11685. ispj = true;
  11686. isfirst = false;
  11687. for (int i = 0; i < list.Count; i++)
  11688. {
  11689. if (seller_memo.Contains(list[i]))
  11690. {
  11691. ispj = false;
  11692. break;
  11693. }
  11694. }
  11695. }
  11696. });
  11697. if (ispj)
  11698. {
  11699. continue;
  11700. }
  11701. seller_memo = seller_memo.Replace("UV", "uv");
  11702. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11703. //吊牌归到卡片
  11704. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11705. seller_memo = seller_memo.Replace("卡套", "卡片");
  11706. seller_memo = seller_memo.Replace("封套", "卡片");
  11707. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11708. seller_memo = seller_memo.Replace("腰封", "卡片");
  11709. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11710. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11711. seller_memo = seller_memo.Replace("横幅", "条幅");
  11712. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11713. string map_key = "";
  11714. string type = "";
  11715. if (supplierMap.ContainsKey(supplierId))
  11716. {
  11717. foreach (var kvp in supplierMap[supplierId])
  11718. {
  11719. if (seller_memo.Contains(kvp.Key))
  11720. {
  11721. map_key = kvp.Value;
  11722. type = kvp.Value;
  11723. break;
  11724. }
  11725. }
  11726. }
  11727. if (map_key == "")
  11728. {
  11729. type = ProductName;
  11730. map_key = ProductName;
  11731. if (smSupplier.Contains(supplierId))
  11732. {
  11733. type = "数码";
  11734. map_key = "数码";
  11735. }
  11736. }
  11737. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11738. {
  11739. map_key = suppliers[supplierId];
  11740. }
  11741. map_key += "_" + row["SupplierName"].ToString();
  11742. Dictionary<string, int> map = null;
  11743. if (other_map.ContainsKey(map_key))
  11744. {
  11745. other_map.TryGetValue(map_key, out map);
  11746. }
  11747. else
  11748. {
  11749. map = new Dictionary<string, int>();
  11750. map.Add("dayDev", 0);//当天出货
  11751. map.Add("dayTotal", 0);//下单总数
  11752. map.Add("payTotal", 0);//500以上
  11753. map.Add("today", 0);//当天出货数量
  11754. map.Add("unusua", 0);//异常数
  11755. map.Add("aftersale", 0);//异常数
  11756. map.Add("deliveryNum", 0);//待发货数
  11757. other_map.Add(map_key, map);
  11758. other_map.TryGetValue(map_key, out map);
  11759. }
  11760. int afterSaleState = Convert.ToInt32(row["AfterSaleState"]);
  11761. int delivery = Convert.ToInt32(row["delivery"]);
  11762. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11763. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11764. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11765. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11766. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11767. //GD-CYT-----64
  11768. DateTime two = palceTimeStart.AddHours(14);
  11769. DateTime three = palceTimeStart.AddHours(15);
  11770. DateTime four = palceTimeStart.AddHours(16);
  11771. DateTime six = palceTimeStart.AddHours(18);
  11772. bool istoday = false;
  11773. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11774. {
  11775. //下午四点前 500-1000
  11776. string count = row["ProductCount"].ToString();
  11777. if (count != null && count.Length > 0)
  11778. {
  11779. int productCount = commonHelper.getPlaceProductCount(count);
  11780. if (productCount >= 500 && productCount <= 1000)
  11781. {
  11782. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11783. {
  11784. istoday = true;
  11785. }
  11786. }
  11787. }
  11788. }
  11789. //UV
  11790. else if ("uv".Equals(type))
  11791. {
  11792. //ZT----70
  11793. //ZHX----3
  11794. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11795. {
  11796. istoday = true;
  11797. }
  11798. //JK----97
  11799. //HZX----105
  11800. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11801. {
  11802. istoday = true;
  11803. }
  11804. if (DateTime.Compare(FinishPlaceTime, six) < 0 && (supplierId == 126))
  11805. {
  11806. istoday = true;
  11807. }
  11808. }
  11809. //帆布---52|条幅---27
  11810. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11811. {
  11812. //LHCY-----98
  11813. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11814. {
  11815. istoday = true;
  11816. }
  11817. }
  11818. //条幅
  11819. else if ("条幅".Equals(type))
  11820. {
  11821. //XD-----90
  11822. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11823. {
  11824. istoday = true;
  11825. }
  11826. }
  11827. //桌布
  11828. else if ("桌布".Equals(type))
  11829. {
  11830. //XD-----90
  11831. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11832. {
  11833. istoday = true;
  11834. }
  11835. }
  11836. //DL---10
  11837. //AYTW---119
  11838. //FS-CYT-DY ----80
  11839. //JK----97
  11840. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11841. {
  11842. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11843. {
  11844. istoday = true;
  11845. }
  11846. }
  11847. // QC---121
  11848. else if (supplierId == 121)
  11849. {
  11850. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11851. {
  11852. istoday = true;
  11853. }
  11854. }
  11855. if (afterSaleState == 0 && delivery == 0)
  11856. {
  11857. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11858. {
  11859. map["dayTotal"]++;
  11860. if (supplierId == 97)
  11861. {
  11862. supplierId = 97;
  11863. }
  11864. }
  11865. if (Convert.ToDecimal(row["payment"]) >= 500)
  11866. {
  11867. map["payTotal"]++;
  11868. }
  11869. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11870. {
  11871. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11872. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11873. {
  11874. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11875. {
  11876. map["today"]++;
  11877. }
  11878. }
  11879. else
  11880. {
  11881. if (supplierId == 80 || supplierId == 126)
  11882. {
  11883. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11884. {
  11885. map["today"]++;
  11886. }
  11887. }
  11888. else if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11889. {
  11890. map["today"]++;
  11891. }
  11892. }
  11893. }
  11894. if (istoday)
  11895. {
  11896. map["dayDev"]++;
  11897. }
  11898. }
  11899. else if (delivery == 0)
  11900. {
  11901. if (row["AfterSaleReason"].ToString().Contains("车间责任"))
  11902. {
  11903. map["aftersale"]++;
  11904. }
  11905. }
  11906. else
  11907. {
  11908. map["deliveryNum"]++;
  11909. try
  11910. {
  11911. if (istoday)
  11912. {
  11913. map["unusua"]++;
  11914. continue;
  11915. }
  11916. if (supplierId == 0 || productId == 0)
  11917. {
  11918. continue;
  11919. }
  11920. //没配置时间
  11921. if (!timer_map.ContainsKey(supplierId))
  11922. {
  11923. continue;
  11924. }
  11925. List<CeErpSupplierProductTime> timmerList = timer_map[supplierId];
  11926. if (timmerList.Count == 0)
  11927. {
  11928. continue;
  11929. }
  11930. string[] productIds = null;
  11931. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  11932. string sellmer_mome = row["seller_memo"].ToString();
  11933. string txtCount = row["ProductCount"].ToString();
  11934. DateTime placeTime = DateTime.Now;
  11935. if (string.IsNullOrEmpty(finishPlaceTime))
  11936. {
  11937. continue;
  11938. }
  11939. placeTime = DateTime.Parse(finishPlaceTime);
  11940. bool isSendTime = false;
  11941. foreach (CeErpSupplierProductTime productTime in timmerList)
  11942. {
  11943. string txtIds = productTime.productId;
  11944. string[] crafts = { };
  11945. int count = productTime.quantity;
  11946. if (string.IsNullOrEmpty(txtIds))
  11947. {
  11948. continue;
  11949. }
  11950. if (count > 0)
  11951. {
  11952. int quantity = commonHelper.handleProductCount(txtCount, true);
  11953. //订单数量大于写入的数量则跳过
  11954. if (quantity > count)
  11955. {
  11956. continue;
  11957. }
  11958. }
  11959. productIds = txtIds.Split(',');
  11960. if (productIds.Contains(productId.ToString()))
  11961. {
  11962. string textCraft = productTime.craft;
  11963. textCraft = textCraft.Replace(",", ",");//统一格式
  11964. if (!string.IsNullOrEmpty(textCraft))
  11965. {
  11966. crafts = textCraft.Split(',');
  11967. }
  11968. if (crafts.Length > 0)
  11969. {
  11970. bool isinCraft = false;
  11971. for (int i = 0; i < crafts.Length; i++)
  11972. {
  11973. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  11974. {
  11975. isinCraft = true;
  11976. break;
  11977. }
  11978. }
  11979. //有写工艺并且备注中没匹配中则跳过
  11980. if (!isinCraft)
  11981. {
  11982. continue;
  11983. }
  11984. }
  11985. DateTime deadLine = DateTime.Parse(productTime.deadLine);
  11986. DateTime dayDeadLine = DateTime.Parse(productTime.dayDeadLine);
  11987. int sendDay = productTime.sendDay;
  11988. //订单发货时间
  11989. DateTime sendtime = placeTime;
  11990. //下单时间小于当日发货时间则不用判断
  11991. //当日发货必须发货
  11992. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  11993. {
  11994. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  11995. }
  11996. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  11997. {
  11998. //在截稿时间之前下单的可以减去一天时间
  11999. sendDay = Math.Max(1, sendDay - 1);
  12000. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  12001. }
  12002. else
  12003. {
  12004. sendDay = Math.Max(1, sendDay - 1);
  12005. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  12006. }
  12007. //判断有没有到发货日期大于0还没到发货时间
  12008. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) < 0)
  12009. {
  12010. //匹配到就不要继续匹配了
  12011. isSendTime = true;
  12012. break;
  12013. }
  12014. }
  12015. }
  12016. if (isSendTime)
  12017. {
  12018. map["unusua"]++;
  12019. }
  12020. }
  12021. catch (Exception ex)
  12022. {
  12023. XLog.SaveLog(0, row["ctid"].ToString() + "更新发货异常订单错误:" + ex);
  12024. }
  12025. }
  12026. }
  12027. DataTable dt = new DataTable();
  12028. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12029. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12030. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  12031. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  12032. dt.Columns.Add(new DataColumn("today", typeof(string)));
  12033. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12034. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  12035. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  12036. dt.Columns.Add(new DataColumn("aftersale", typeof(string)));
  12037. dt.Columns.Add(new DataColumn("deliveryNum", typeof(string)));
  12038. other_map.Keys.ForEach(key =>
  12039. {
  12040. DataRow dr = dt.NewRow();
  12041. Dictionary<string, int> map = other_map[key];
  12042. string[] key_list = key.Split('_');
  12043. dr[0] = key_list[0];
  12044. dr[1] = key_list[1];
  12045. if (key_list.Length > 2)
  12046. {
  12047. dr[1] += "(" + key_list[2] + ")";
  12048. }
  12049. dr[2] = map["dayTotal"];
  12050. dr[3] = map["payTotal"];
  12051. dr[4] = map["today"];
  12052. dr[5] = map["unusua"];
  12053. dr[6] = map["dayDev"];
  12054. double rate = 0.00;
  12055. if (map["dayDev"] > 0)
  12056. {
  12057. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  12058. }
  12059. dr[7] = rate.ToString();
  12060. dr[8] = map["aftersale"];
  12061. dr[9] = map["deliveryNum"];
  12062. dt.Rows.Add(dr);
  12063. });
  12064. DataView dv = new DataView(dt);
  12065. dv.Sort = "SupplierName";
  12066. //dv.Sort = "ProductName desc";
  12067. DataTable dtNew = dv.ToTable();
  12068. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12069. }
  12070. public void get_place_all_order_data()
  12071. {
  12072. string date1 = GetPostString("date1");
  12073. string date2 = GetPostString("date2");
  12074. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  12075. DateTime start = DateTime.Parse(starttime);
  12076. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  12077. DateTime end = DateTime.Parse(endtime);
  12078. if (date1 != null && date1.Length > 0)
  12079. {
  12080. DateTime dateTime = DateTime.Parse(date1);
  12081. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  12082. start = DateTime.Parse(starttime);
  12083. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  12084. end = DateTime.Parse(endtime);
  12085. }
  12086. if (date2 != null && date2.Length > 0)
  12087. {
  12088. DateTime dateTime = DateTime.Parse(date2);
  12089. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  12090. end = DateTime.Parse(endtime);
  12091. }
  12092. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  12093. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( FinishDeliveryTime BETWEEN '{0}' AND '{1}' ) AND IsSample = 0 and SupplierId > 0 ", starttime, endtime);
  12094. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12095. string timer_sql = string.Format("select * from CE_ErpSupplierProductTime");
  12096. DataTable timer_data = DbHelper.DbConn.ExecuteDataset(timer_sql).Tables[0];
  12097. Dictionary<int, List<CeErpSupplierProductTime>> timer_map = new Dictionary<int, List<CeErpSupplierProductTime>>();
  12098. foreach (DataRow datarow in timer_data.Rows)
  12099. {
  12100. List<CeErpSupplierProductTime> list = null;
  12101. int supplierId = Convert.ToInt32(datarow["SupplierId"]);
  12102. if (timer_map.ContainsKey(supplierId))
  12103. {
  12104. timer_map.TryGetValue(supplierId, out list);
  12105. }
  12106. else
  12107. {
  12108. list = new List<CeErpSupplierProductTime>();
  12109. timer_map.Add(supplierId, list);
  12110. timer_map.TryGetValue(supplierId, out list);
  12111. }
  12112. CeErpSupplierProductTime ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12113. ceErpSupplierProductTime.quantity = Convert.ToInt32(datarow["quantity"]);
  12114. ceErpSupplierProductTime.dayDeadLine = datarow["dayDeadLine"].ToString();
  12115. ceErpSupplierProductTime.deadLine = datarow["deadLine"].ToString();
  12116. ceErpSupplierProductTime.productId = datarow["productId"].ToString();
  12117. ceErpSupplierProductTime.craft = datarow["craft"].ToString();
  12118. ceErpSupplierProductTime.sendDay = Convert.ToInt32(datarow["sendDay"]);
  12119. list.Add(ceErpSupplierProductTime);
  12120. }
  12121. List<int> smSupplier = new List<int>() { 97, 121, 119, 80 };
  12122. foreach (DataRow row in data.Rows)
  12123. {
  12124. //存储数据
  12125. int productId = Convert.ToInt32(row["ProductId"]);
  12126. string ProductName = row["ProductName"].ToString();
  12127. int supplierId = Convert.ToInt32(row["SupplierId"]);
  12128. if (no_suppliers.Contains(supplierId))
  12129. {
  12130. continue;
  12131. }
  12132. string seller_memo = row["seller_memo"].ToString();
  12133. bool ispj = false;//是否配件单
  12134. bool isfirst = true;//第一个配
  12135. maps.Keys.ForEach(key =>
  12136. {
  12137. //备注包含配件
  12138. if (seller_memo.Contains(key) && isfirst)
  12139. {
  12140. List<string> list = maps[key];
  12141. ispj = true;
  12142. isfirst = false;
  12143. for (int i = 0; i < list.Count; i++)
  12144. {
  12145. if (seller_memo.Contains(list[i]))
  12146. {
  12147. ispj = false;
  12148. break;
  12149. }
  12150. }
  12151. }
  12152. });
  12153. if (ispj)
  12154. {
  12155. continue;
  12156. }
  12157. seller_memo = seller_memo.Replace("UV", "uv");
  12158. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  12159. //吊牌归到卡片
  12160. seller_memo = seller_memo.Replace("吊牌", "卡片");
  12161. seller_memo = seller_memo.Replace("卡套", "卡片");
  12162. seller_memo = seller_memo.Replace("封套", "卡片");
  12163. seller_memo = seller_memo.Replace("吸管套", "卡片");
  12164. seller_memo = seller_memo.Replace("腰封", "卡片");
  12165. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  12166. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  12167. seller_memo = seller_memo.Replace("横幅", "条幅");
  12168. seller_memo = seller_memo.Replace("锦旗", "条幅");
  12169. string map_key = "";
  12170. string type = "";
  12171. if (supplierMap.ContainsKey(supplierId))
  12172. {
  12173. foreach (var kvp in supplierMap[supplierId])
  12174. {
  12175. if (seller_memo.Contains(kvp.Key))
  12176. {
  12177. map_key = kvp.Value;
  12178. type = kvp.Value;
  12179. break;
  12180. }
  12181. }
  12182. }
  12183. if (map_key == "")
  12184. {
  12185. type = ProductName;
  12186. map_key = ProductName;
  12187. if (smSupplier.Contains(supplierId))
  12188. {
  12189. type = "数码";
  12190. map_key = "数码";
  12191. }
  12192. }
  12193. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  12194. {
  12195. map_key = suppliers[supplierId];
  12196. }
  12197. map_key += "_" + row["SupplierName"].ToString();
  12198. Dictionary<string, int> map = null;
  12199. if (other_map.ContainsKey(map_key))
  12200. {
  12201. other_map.TryGetValue(map_key, out map);
  12202. }
  12203. else
  12204. {
  12205. map = new Dictionary<string, int>();
  12206. map.Add("all", 0);//全部
  12207. map.Add("unusua", 0);//异常数
  12208. map.Add("normal", 0);//正常数
  12209. map.Add("noMatch", 0);//未匹配
  12210. other_map.Add(map_key, map);
  12211. other_map.TryGetValue(map_key, out map);
  12212. }
  12213. //处理是否超时
  12214. string finishPlaceTime = row["FinishPlaceTime"].ToString();
  12215. string sellmer_mome = row["seller_memo"].ToString();
  12216. string txtCount = row["ProductCount"].ToString();
  12217. string FinishDeliveryTime = row["FinishDeliveryTime"].ToString();
  12218. map["all"]++;
  12219. if (string.IsNullOrEmpty(finishPlaceTime))
  12220. {
  12221. map["noMatch"]++;
  12222. continue;
  12223. }
  12224. if (string.IsNullOrEmpty(FinishDeliveryTime))
  12225. {
  12226. map["noMatch"]++;
  12227. continue;
  12228. }
  12229. if (!timer_map.ContainsKey(supplierId))
  12230. {
  12231. map["noMatch"]++;
  12232. continue;
  12233. }
  12234. List<CeErpSupplierProductTime> lists = timer_map[supplierId];
  12235. if (lists.Count > 0)
  12236. {
  12237. bool isComplate = false;
  12238. string[] productIds = null;
  12239. foreach (CeErpSupplierProductTime ceErpSupplierProductTime in lists)
  12240. {
  12241. string[] crafts = { };
  12242. if (string.IsNullOrEmpty(ceErpSupplierProductTime.productId))
  12243. {
  12244. continue;
  12245. }
  12246. if (ceErpSupplierProductTime.quantity > 0)
  12247. {
  12248. int quantity = commonHelper.handleProductCount(txtCount, true);
  12249. //订单数量大于写入的数量则跳过
  12250. if (quantity > ceErpSupplierProductTime.quantity)
  12251. {
  12252. continue;
  12253. }
  12254. }
  12255. productIds = ceErpSupplierProductTime.productId.Split(',');
  12256. if (productIds.Contains(productId.ToString()))
  12257. {
  12258. string textCraft = ceErpSupplierProductTime.craft;
  12259. textCraft = textCraft.Replace(",", ",");//统一格式
  12260. if (!string.IsNullOrEmpty(textCraft))
  12261. {
  12262. crafts = textCraft.Split(',');
  12263. }
  12264. if (crafts.Length > 0)
  12265. {
  12266. bool isinCraft = false;
  12267. for (int i = 0; i < crafts.Length; i++)
  12268. {
  12269. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12270. {
  12271. isinCraft = true;
  12272. break;
  12273. }
  12274. }
  12275. //有写工艺并且备注中没匹配中则跳过
  12276. if (!isinCraft)
  12277. {
  12278. continue;
  12279. }
  12280. }
  12281. DateTime deadLine = DateTime.Parse(ceErpSupplierProductTime.deadLine);
  12282. DateTime dayDeadLine = DateTime.Parse(ceErpSupplierProductTime.dayDeadLine);
  12283. int sendDay = ceErpSupplierProductTime.sendDay;
  12284. //订单发货时间
  12285. DateTime placeTime = DateTime.Parse(finishPlaceTime);
  12286. DateTime sendtime = DateTime.Now;//预计发货时间
  12287. DateTime dateTime = DateTime.Parse(FinishDeliveryTime);//实际发货时间
  12288. //下单时间小于当日发货时间则不用判断
  12289. //当日发货必须发货
  12290. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12291. {
  12292. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59"));
  12293. }
  12294. else if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12295. {
  12296. //在截稿时间之前下单的可以减去一天时间
  12297. sendDay = Math.Max(1, sendDay - 1);
  12298. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 00:00:00")).AddDays(sendDay);
  12299. }
  12300. else
  12301. {
  12302. sendDay = Math.Max(1, sendDay - 1);
  12303. sendtime = DateTime.Parse(placeTime.ToString("yyyy-MM-dd 23:59:59")).AddDays(sendDay);
  12304. }
  12305. isComplate = true;
  12306. //判断有没有到发货日期大于0还没到发货时间
  12307. if (DateTime.Compare(sendtime.Date, dateTime.Date) < 0)
  12308. {
  12309. //匹配到就不要继续匹配了
  12310. map["unusua"]++;
  12311. break;
  12312. }
  12313. else
  12314. {
  12315. map["normal"]++;
  12316. break;
  12317. }
  12318. }
  12319. }
  12320. if (!isComplate)
  12321. {
  12322. map["noMatch"]++;
  12323. continue;
  12324. }
  12325. }
  12326. else
  12327. {
  12328. map["noMatch"]++;
  12329. }
  12330. }
  12331. DataTable dt = new DataTable();
  12332. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  12333. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  12334. dt.Columns.Add(new DataColumn("all", typeof(string)));
  12335. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  12336. dt.Columns.Add(new DataColumn("normal", typeof(string)));
  12337. dt.Columns.Add(new DataColumn("noMatch", typeof(string)));
  12338. dt.Columns.Add(new DataColumn("shipmentRate", typeof(string)));
  12339. other_map.Keys.ForEach(key =>
  12340. {
  12341. DataRow dr = dt.NewRow();
  12342. Dictionary<string, int> map = other_map[key];
  12343. string[] key_list = key.Split('_');
  12344. dr[0] = key_list[0];
  12345. dr[1] = key_list[1];
  12346. if (key_list.Length > 2)
  12347. {
  12348. dr[1] += "(" + key_list[2] + ")";
  12349. }
  12350. dr[2] = map["all"];
  12351. dr[3] = map["unusua"];
  12352. dr[4] = map["normal"];
  12353. dr[5] = map["noMatch"];
  12354. double rate = 0.00;
  12355. if (map["all"] > 0)
  12356. {
  12357. rate = Math.Round(((Convert.ToDouble(map["normal"]) + Convert.ToDouble(map["noMatch"])) / Convert.ToDouble(map["all"])), 2) * 100;
  12358. }
  12359. dr[6] = rate.ToString();
  12360. dt.Rows.Add(dr);
  12361. });
  12362. DataView dv = new DataView(dt);
  12363. dv.Sort = "SupplierName";
  12364. //dv.Sort = "ProductName desc";
  12365. DataTable dtNew = dv.ToTable();
  12366. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  12367. }
  12368. public void check_order_desing_info()
  12369. {
  12370. string ctid = GetPostString("ctid");
  12371. if (!string.IsNullOrEmpty(ctid))
  12372. {
  12373. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12374. if (ceErpTradeCell != null)
  12375. {
  12376. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  12377. returnSuccess(JsonConvert.SerializeObject(new { response }));
  12378. return;
  12379. }
  12380. returnErrorMsg("找不到订单");
  12381. return;
  12382. }
  12383. returnErrorMsg("找不到订单");
  12384. }
  12385. public void get_timeout_detail()
  12386. {
  12387. string poscode = CurrentUser.UserPost.Post.Code;
  12388. DataStruct dStruct = GetPostStruct();
  12389. List<string> lw = new List<string>();
  12390. string id = GetPostString("id");
  12391. string pay_date1 = GetPostString("pay_date1");
  12392. string pay_date2 = GetPostString("pay_date2");
  12393. int type = GetPostInt("type");
  12394. if (type == 0)
  12395. {
  12396. if (pay_date1.Length > 0)
  12397. {
  12398. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  12399. }
  12400. if (pay_date2.Length > 0)
  12401. {
  12402. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  12403. }
  12404. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  12405. }
  12406. if (type == 1)
  12407. {
  12408. if (pay_date1.Length > 0)
  12409. {
  12410. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  12411. }
  12412. if (pay_date2.Length > 0)
  12413. {
  12414. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  12415. }
  12416. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  12417. }
  12418. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12419. DataTable dt = null;
  12420. dt = WebCache.GetData("view_orderlist", dStruct);
  12421. writeGridDataTableJson(dStruct.TotalCount, dt);
  12422. }
  12423. public void saveUrgentChargePrice()
  12424. {
  12425. string ctid = GetPostString("ctid");
  12426. if (!string.IsNullOrEmpty(ctid))
  12427. {
  12428. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12429. if (ceErpTradeCell != null)
  12430. {
  12431. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  12432. if (prices <= 100)
  12433. {
  12434. returnErrorMsg("此订单金额不足100元,无法加急。");
  12435. return;
  12436. }
  12437. double price = GetPostDouble("price");
  12438. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  12439. if (ceErpTradeCellExtend == null)
  12440. {
  12441. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12442. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  12443. }
  12444. ceErpTradeCellExtend.urgentCharge = price;
  12445. if (ceErpTradeCellExtend.ID > 0)
  12446. {
  12447. ceErpTradeCellExtend.Update();
  12448. }
  12449. else
  12450. {
  12451. ceErpTradeCellExtend.Save();
  12452. }
  12453. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  12454. returnSuccessMsg("修改成功!");
  12455. return;
  12456. }
  12457. returnErrorMsg("找不到订单");
  12458. return;
  12459. }
  12460. returnErrorMsg("找不到订单");
  12461. }
  12462. public void finish_erp_order()
  12463. {
  12464. string ctid = GetPostString("ctid");
  12465. if (!string.IsNullOrEmpty(ctid))
  12466. {
  12467. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  12468. {
  12469. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12470. if (ceErpTradeCell != null)
  12471. {
  12472. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  12473. ceErpTradeCell.Update();
  12474. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  12475. returnSuccessMsg("修改成功!");
  12476. return;
  12477. }
  12478. }
  12479. }
  12480. returnErrorMsg("找不到订单");
  12481. }
  12482. public void get_trade_order_list()
  12483. {
  12484. string tid = GetPostString("tid");
  12485. if (!string.IsNullOrEmpty(tid))
  12486. {
  12487. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  12488. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12489. writeGridDataTableJson(data.Rows.Count, data);
  12490. return;
  12491. }
  12492. returnErrorMsg("找不到订单");
  12493. }
  12494. public void save_cell_spu()
  12495. {
  12496. string ctid = GetPostString("ctid");
  12497. string spu_id = GetPostString("spu_id");
  12498. if (!string.IsNullOrEmpty(ctid))
  12499. {
  12500. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12501. if (ceErpTradeCellExtend == null)
  12502. {
  12503. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12504. ceErpTradeCellExtend.ctid = ctid;
  12505. }
  12506. ceErpTradeCellExtend.spu_id = spu_id;
  12507. if (!string.IsNullOrEmpty(spu_id))
  12508. {
  12509. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12510. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  12511. }
  12512. if (ceErpTradeCellExtend.ID == 0)
  12513. {
  12514. ceErpTradeCellExtend.Create();
  12515. }
  12516. else
  12517. {
  12518. ceErpTradeCellExtend.Update();
  12519. }
  12520. returnSuccessMsg("修改成功!");
  12521. return;
  12522. }
  12523. returnErrorMsg("找不到订单");
  12524. }
  12525. public void change_express_info()
  12526. {
  12527. string ctid = GetPostString("ctid");
  12528. string transNo = GetPostString("transNo");
  12529. string transCom = GetPostString("transCom");
  12530. if (!string.IsNullOrEmpty(ctid))
  12531. {
  12532. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12533. if (ceErpTradeCellExtend == null)
  12534. {
  12535. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12536. ceErpTradeCellExtend.ctid = ctid;
  12537. }
  12538. ceErpTradeCellExtend.modExpressNo = transNo;
  12539. ceErpTradeCellExtend.modExpressCom = transCom;
  12540. ceErpTradeCellExtend.readMod = 2;
  12541. if (ceErpTradeCellExtend.ID == 0)
  12542. {
  12543. ceErpTradeCellExtend.Create();
  12544. }
  12545. else
  12546. {
  12547. ceErpTradeCellExtend.Update();
  12548. }
  12549. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  12550. returnSuccessMsg("修改成功!");
  12551. return;
  12552. }
  12553. returnErrorMsg("找不到订单");
  12554. }
  12555. public void get_change_express_list()
  12556. {
  12557. DataStruct dStruct = GetPostStruct();
  12558. List<string> lw = new List<string>();
  12559. int st = 2;
  12560. string tid = GetPostString("ctid");
  12561. if (tid.Length > 0)
  12562. {
  12563. string select_tid = getTidByCtid(tid);
  12564. lw.Add(string.Format("tid='{0}'", select_tid));
  12565. }
  12566. string shopname = GetPostString("shopname");
  12567. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12568. string buyernick = GetPostString("buyer_nick");
  12569. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12570. string sellermemo = GetPostString("seller_memo");
  12571. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12572. string supplier = GetPostString("supplier");
  12573. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12574. string customer = GetPostString("customer");
  12575. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12576. string design = GetPostString("design");
  12577. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12578. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12579. string poscode = CurrentUser.UserPost.Post.Code;
  12580. if (poscode != "SysAdmin")
  12581. {
  12582. string shopid = CurrentUser.User.pemShop;
  12583. lw.Add(string.Format("shopId in ({0})", shopid));
  12584. }
  12585. lw.Add("readMod = 2");
  12586. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12587. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  12588. writeGridDataTableJson(dStruct.TotalCount, dt);
  12589. }
  12590. public void deal_express_complete()
  12591. {
  12592. string ctid = GetPostString("ctid");
  12593. if (!string.IsNullOrEmpty(ctid))
  12594. {
  12595. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12596. if (ceErpTradeCellExtend == null)
  12597. {
  12598. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12599. ceErpTradeCellExtend.ctid = ctid;
  12600. }
  12601. ceErpTradeCellExtend.readMod = 1;
  12602. if (ceErpTradeCellExtend.ID == 0)
  12603. {
  12604. ceErpTradeCellExtend.Create();
  12605. }
  12606. else
  12607. {
  12608. ceErpTradeCellExtend.Update();
  12609. }
  12610. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  12611. returnSuccessMsg("修改成功!");
  12612. return;
  12613. }
  12614. returnErrorMsg("找不到订单");
  12615. }
  12616. public void aftersale_return_visit()
  12617. {
  12618. string ctid = GetPostString("ctid");
  12619. if (!string.IsNullOrEmpty(ctid))
  12620. {
  12621. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  12622. if (ceErpTradeCellExtend == null)
  12623. {
  12624. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  12625. ceErpTradeCellExtend.ctid = ctid;
  12626. }
  12627. ceErpTradeCellExtend.returnVisit = 1;
  12628. if (ceErpTradeCellExtend.ID == 0)
  12629. {
  12630. ceErpTradeCellExtend.Create();
  12631. }
  12632. else
  12633. {
  12634. ceErpTradeCellExtend.Update();
  12635. }
  12636. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12637. if (ceErpTradeAfterSaleExtend != null)
  12638. {
  12639. ceErpTradeAfterSaleExtend.TextResult = "";
  12640. ceErpTradeAfterSaleExtend.Update();
  12641. }
  12642. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  12643. returnSuccessMsg("修改成功!");
  12644. return;
  12645. }
  12646. returnErrorMsg("找不到订单");
  12647. }
  12648. public void orderPlaceInfo()
  12649. {
  12650. string ctids = GetPostString("ctids");
  12651. string[] list = ctids.Split(',');
  12652. foreach (string ctid in list)
  12653. {
  12654. CeErpSukuraData.createInfo(ctid, 3);
  12655. }
  12656. StringBuilder sql = new StringBuilder();
  12657. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  12658. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  12659. designHelper.api_approveDesign(ctids); //approveDesign
  12660. returnSuccessMsg("");
  12661. }
  12662. public void get_issue_list()
  12663. {
  12664. DataStruct dStruct = GetPostStruct();
  12665. List<string> lw = new List<string>();
  12666. int st = 2;
  12667. string tid = GetPostString("ctid");
  12668. if (tid.Length > 0)
  12669. {
  12670. string select_tid = getTidByCtid(tid);
  12671. lw.Add(string.Format("tid='{0}'", select_tid));
  12672. }
  12673. string shopname = GetPostString("shopname");
  12674. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  12675. string buyernick = GetPostString("buyer_nick");
  12676. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  12677. string sellermemo = GetPostString("seller_memo");
  12678. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  12679. string supplier = GetPostString("supplier");
  12680. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  12681. string customer = GetPostString("customer");
  12682. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  12683. string design = GetPostString("design");
  12684. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  12685. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  12686. string poscode = CurrentUser.UserPost.Post.Code;
  12687. if (poscode != "SysAdmin")
  12688. {
  12689. string shopid = CurrentUser.User.pemShop;
  12690. lw.Add(string.Format("shopId in ({0})", shopid));
  12691. }
  12692. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  12693. {
  12694. lw.Add("IssueState = 1");
  12695. }
  12696. else
  12697. {
  12698. string iisstate = GetPostString("iisstate");
  12699. if ("1".Equals(iisstate))
  12700. {
  12701. lw.Add("IssueState =1");
  12702. }
  12703. else if ("2".Equals(iisstate))
  12704. {
  12705. lw.Add("IssueState = 2");
  12706. }
  12707. else
  12708. {
  12709. lw.Add("IssueState > 0");
  12710. }
  12711. }
  12712. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12713. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  12714. writeGridDataTableJson(dStruct.TotalCount, dt);
  12715. }
  12716. public void saveIssueContent()
  12717. {
  12718. string ctid = GetPostString("ctid");
  12719. if (!string.IsNullOrEmpty(ctid))
  12720. {
  12721. string content = GetPostString("content");
  12722. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12723. if (ceErpTradeAfterSaleExtend == null)
  12724. {
  12725. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  12726. ceErpTradeAfterSaleExtend.tid = ctid;
  12727. }
  12728. ceErpTradeAfterSaleExtend.IssueContent = content;
  12729. ceErpTradeAfterSaleExtend.IssueState = 1;
  12730. if (ceErpTradeAfterSaleExtend.ID > 0)
  12731. {
  12732. ceErpTradeAfterSaleExtend.Update();
  12733. }
  12734. else
  12735. {
  12736. ceErpTradeAfterSaleExtend.Create();
  12737. }
  12738. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  12739. returnSuccessMsg("添加成功!");
  12740. return;
  12741. }
  12742. returnErrorMsg("找不到订单");
  12743. }
  12744. public void dealIssueContent()
  12745. {
  12746. string ctid = GetPostString("ctid");
  12747. if (!string.IsNullOrEmpty(ctid))
  12748. {
  12749. string content = GetPostString("content");
  12750. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  12751. if (ceErpTradeAfterSaleExtend != null)
  12752. {
  12753. ceErpTradeAfterSaleExtend.IssueState = 2;
  12754. ceErpTradeAfterSaleExtend.Update();
  12755. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  12756. returnSuccessMsg("修改完成!");
  12757. return;
  12758. }
  12759. }
  12760. returnErrorMsg("找不到订单");
  12761. }
  12762. public void set_tid_attachments()
  12763. {
  12764. string tid = GetPostString("tid");
  12765. string atta = GetPostString("atta");
  12766. if (!string.IsNullOrEmpty(tid))
  12767. {
  12768. if (string.IsNullOrEmpty(atta))
  12769. {
  12770. returnErrorMsg("文件地址为空");
  12771. return;
  12772. }
  12773. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12774. if (ceErpTradeCell != null)
  12775. {
  12776. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12777. if (ceErpTrade == null)
  12778. {
  12779. returnErrorMsg("找不到订单");
  12780. return;
  12781. }
  12782. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  12783. bool isSend = false;
  12784. if (dt != null && dt.Rows.Count > 0)
  12785. {
  12786. foreach (DataRow row in dt.Rows)
  12787. {
  12788. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  12789. {
  12790. isSend = true;
  12791. }
  12792. }
  12793. if (isSend)
  12794. {
  12795. returnErrorMsg("已发货无法修改");
  12796. return;
  12797. }
  12798. ceErpTrade.Attachments = atta;
  12799. ceErpTrade.Update();
  12800. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12801. returnSuccessMsg("上传成功!");
  12802. return;
  12803. }
  12804. }
  12805. }
  12806. returnErrorMsg("找不到订单");
  12807. }
  12808. public void get_tid_attachments()
  12809. {
  12810. string tid = GetPostString("tid");
  12811. if (!string.IsNullOrEmpty(tid))
  12812. {
  12813. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12814. if (ceErpTradeCell != null)
  12815. {
  12816. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12817. if (ceErpTrade == null)
  12818. {
  12819. returnErrorMsg("找不到订单");
  12820. return;
  12821. }
  12822. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12823. return;
  12824. }
  12825. }
  12826. returnErrorMsg("找不到订单");
  12827. }
  12828. public void check_erp_sameorders()
  12829. {
  12830. if (UrlPostParmsCheck("ctid"))
  12831. {
  12832. string eid = GetPostString("ctid");
  12833. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12834. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12835. if (entity != null && ceErpTrade != null)
  12836. {
  12837. if (entity.OrderState > 6)
  12838. {
  12839. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12840. return;
  12841. }
  12842. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12843. List<string> ids = new List<string>();
  12844. if (dt != null && dt.Rows.Count > 1)
  12845. {
  12846. bool needhe = true;
  12847. foreach (DataRow dr in dt.Rows)
  12848. {
  12849. ids.Add("'" + dr["ctid"] + "'");
  12850. /* //备注有合包
  12851. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12852. {
  12853. needhe = true;
  12854. }
  12855. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12856. {
  12857. needhe = true;
  12858. }
  12859. //顺丰快递
  12860. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12861. {
  12862. needhe = true;
  12863. }*/
  12864. }
  12865. if (!needhe)
  12866. {
  12867. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12868. return;
  12869. }
  12870. StringBuilder sql = new StringBuilder();
  12871. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12872. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12873. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12874. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12875. foreach (DataRow dr in dt.Rows)
  12876. {
  12877. dr["dstate"] = 0;
  12878. dr["dnumber"] = 0;
  12879. foreach (DataRow row in dt1.Rows)
  12880. {
  12881. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12882. {
  12883. dr["dstate"] = 2;
  12884. dr["default"] = 1;
  12885. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12886. }
  12887. }
  12888. if (eid.Equals(dr["ctid"].ToString()))
  12889. {
  12890. dr["dstate"] = 1;
  12891. dr["default"] = 1;
  12892. }
  12893. }
  12894. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12895. return;
  12896. }
  12897. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12898. return;
  12899. }
  12900. returnErrorMsg("未找到订单");
  12901. return;
  12902. }
  12903. returnErrorMsg("缺少必要的参数");
  12904. }
  12905. public void get_mark_number()
  12906. {
  12907. string eid = GetPostString("ctid");
  12908. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12909. if (entity != null)
  12910. {
  12911. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12912. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12913. int current = 1;
  12914. if (ceErpDeliverMark == null)
  12915. {
  12916. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12917. List<string> ids = new List<string>();
  12918. if (dt != null && dt.Rows.Count > 1)
  12919. {
  12920. foreach (DataRow dr in dt.Rows)
  12921. {
  12922. ids.Add("'" + dr["ctid"] + "'");
  12923. }
  12924. //查询已有的编号
  12925. StringBuilder sql = new StringBuilder();
  12926. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12927. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12928. if (dt1 == null || dt1.Rows.Count == 0)
  12929. {
  12930. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12931. List<int> list_number = new List<int>();
  12932. foreach (DataRow row in numbers.Rows)
  12933. {
  12934. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12935. }
  12936. //查询空余编号
  12937. for (int i = 0; i < list_number.Count + 2; i++)
  12938. {
  12939. if (!list_number.Contains(current))
  12940. {
  12941. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12942. //防止查询过程中有新数据生成
  12943. if (ceErpDeliverMark1 == null)
  12944. {
  12945. break;
  12946. }
  12947. }
  12948. current++;
  12949. }
  12950. }
  12951. else
  12952. {
  12953. foreach (DataRow row in dt1.Rows)
  12954. {
  12955. current = Convert.ToInt32(row["markNumber"]);
  12956. }
  12957. }
  12958. ceErpDeliverMark = new CeErpDeliverMark();
  12959. ceErpDeliverMark.ctid = eid;
  12960. ceErpDeliverMark.createtime = DateTime.Now;
  12961. if (ceErpTrade != null)
  12962. {
  12963. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12964. }
  12965. ceErpDeliverMark.markNumber = current;
  12966. ceErpDeliverMark.Create();
  12967. }
  12968. }
  12969. else
  12970. {
  12971. current = ceErpDeliverMark.markNumber;
  12972. }
  12973. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12974. return;
  12975. }
  12976. }
  12977. public void aftersaleCytSend()
  12978. {
  12979. string ctid = GetPostString("ctid");
  12980. if (!string.IsNullOrEmpty(ctid))
  12981. {
  12982. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12983. if (ceErpTradeCell != null)
  12984. {
  12985. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12986. }
  12987. returnSuccessMsg("推送成功");
  12988. return;
  12989. }
  12990. returnErrorMsg("缺少必要的参数");
  12991. }
  12992. public void packOrderInfo()
  12993. {
  12994. string ctids = GetPostString("ctids");
  12995. if (!string.IsNullOrEmpty(ctids))
  12996. {
  12997. string[] ctid_list = ctids.Split(',');
  12998. if (ctid_list.Length > 100)
  12999. {
  13000. returnErrorMsg("单次下载次数不能超过100个");
  13001. return;
  13002. }
  13003. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  13004. StringBuilder sql = new StringBuilder();
  13005. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  13006. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13007. int supplierId = 0;
  13008. StringBuilder insterSql = new StringBuilder();
  13009. for (int i = 0; i < dt.Rows.Count; i++)
  13010. {
  13011. DataRow row = dt.Rows[i];
  13012. if (i == 0)
  13013. {
  13014. supplierId = Convert.ToInt32(row["SupplierId"]);
  13015. }
  13016. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  13017. {
  13018. returnErrorMsg("同车间的订单才能一起打包");
  13019. return;
  13020. }
  13021. int orderState = Convert.ToInt32(row["OrderState"]);
  13022. if (orderState != 5)
  13023. {
  13024. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  13025. return;
  13026. }
  13027. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  13028. }
  13029. CeErpPackData ceErpPackData = new CeErpPackData();
  13030. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + CurrentUser.UserID + ".zip";
  13031. ceErpPackData.supplierId = supplierId;
  13032. ceErpPackData.createtime = DateTime.Now;
  13033. ceErpPackData.createBy = CurrentUser.UserID;
  13034. ceErpPackData.createName = CurrentUser.UserName;
  13035. ceErpPackData.Create();
  13036. if (ceErpPackData.ID > 0)
  13037. {
  13038. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  13039. DbHelper.DbConn.ExecuteNonQuery(inSql);
  13040. }
  13041. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  13042. returnSuccessMsg("打包成功");
  13043. return;
  13044. }
  13045. returnErrorMsg("缺少必要的参数");
  13046. }
  13047. public void rePackOrderInfo()
  13048. {
  13049. string id = GetPostString("id");
  13050. if (!string.IsNullOrEmpty(id))
  13051. {
  13052. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  13053. if (ceErpPackData == null)
  13054. {
  13055. returnSuccessMsg("查无数据");
  13056. return;
  13057. }
  13058. ceErpPackData.upStatus = 0;
  13059. ceErpPackData.message = "";
  13060. ceErpPackData.Update();
  13061. returnSuccessMsg("打包成功");
  13062. return;
  13063. }
  13064. returnErrorMsg("缺少必要的参数");
  13065. }
  13066. public void backPackOrderInfo()
  13067. {
  13068. string id = GetPostString("id");
  13069. if (!string.IsNullOrEmpty(id))
  13070. {
  13071. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  13072. if (ceErpPackData == null)
  13073. {
  13074. returnSuccessMsg("查无数据");
  13075. return;
  13076. }
  13077. ceErpPackData.upStatus = 4;
  13078. ceErpPackData.Update();
  13079. List<string> list = new List<string>();
  13080. StringBuilder sql = new StringBuilder();
  13081. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  13082. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13083. for (int i = 0; i < dt.Rows.Count; i++)
  13084. {
  13085. DataRow row = dt.Rows[i];
  13086. list.Add("'" + row["ctid"].ToString() + "'");
  13087. }
  13088. string textCtids = string.Join(",", list);
  13089. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=5,IsVerifyToSupplier=0,IsReturn=1,ReturnTime=GETDATE(),ReturnReason='无法打包' where ctid in ({0}) and OrderState=6", textCtids));
  13090. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", textCtids, (int)OrderState.下单完成, 0, "无法打包退回"));
  13091. returnSuccessMsg("退回成功");
  13092. return;
  13093. }
  13094. returnErrorMsg("缺少必要的参数");
  13095. }
  13096. public void addPackDownNum()
  13097. {
  13098. string id = GetPostString("id");
  13099. if (!string.IsNullOrEmpty(id))
  13100. {
  13101. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  13102. returnSuccessMsg("下载成功");
  13103. return;
  13104. }
  13105. returnErrorMsg("缺少必要的参数");
  13106. }
  13107. public void get_pack_list()
  13108. {
  13109. DataStruct dStruct = GetPostStruct();
  13110. List<string> lw = new List<string>();
  13111. string supplier = GetPostString("supplier");
  13112. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  13113. string posTag = CurrentUser.UserPost.Post.Code;
  13114. if (posTag == "Supplier")
  13115. {
  13116. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13117. }
  13118. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13119. dStruct.Order = "createtime desc";
  13120. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  13121. writeGridDataTableJson(dStruct.TotalCount, dt);
  13122. }
  13123. public void get_pack_order_list()
  13124. {
  13125. string packId = GetPostString("packId");
  13126. if (string.IsNullOrEmpty(packId))
  13127. {
  13128. returnErrorMsg("缺少必要的参数");
  13129. return;
  13130. }
  13131. StringBuilder sql = new StringBuilder();
  13132. sql.AppendFormat("select c.ctid,c.seller_memo,i.message from CE_ErpPackDataItem i left join CE_ErpTradeCell c on i.ctid=c.ctid where i.packId = {0}", packId);
  13133. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13134. if (dt == null || dt.Rows.Count == 0)
  13135. {
  13136. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  13137. return;
  13138. }
  13139. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  13140. return;
  13141. }
  13142. public void get_supplier_product_time_list()
  13143. {
  13144. DataStruct dStruct = GetPostStruct();
  13145. List<string> lw = new List<string>();
  13146. string txtKey = GetPostString("txtKey");
  13147. if (txtKey.Length > 0)
  13148. {
  13149. lw.Add(string.Format("(supplierName = '{0}' or productName like '%{0}%')", txtKey));
  13150. }
  13151. string posTag = CurrentUser.UserPost.Post.Code;
  13152. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13153. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  13154. writeGridDataTableJson(dStruct.TotalCount, dt);
  13155. }
  13156. public void saveSupplierProductTime()
  13157. {
  13158. string productId = GetPostString("productId");
  13159. if (string.IsNullOrEmpty(productId))
  13160. {
  13161. returnErrorMsg("缺少必要的参数");
  13162. return;
  13163. }
  13164. string productName = GetPostString("productName");
  13165. int supplierId = GetPostInt("supplierId");
  13166. if (supplierId == 0)
  13167. {
  13168. returnErrorMsg("缺少必要的参数");
  13169. return;
  13170. }
  13171. int quantity = GetPostInt("quantity");
  13172. int sendDay = GetPostInt("sendTime");
  13173. string supplierName = GetPostString("supplierName");
  13174. string craft = GetPostString("craft");
  13175. string deadLine = GetPostString("deadLine");
  13176. string dayDeadLine = GetPostString("dayDeadLine");
  13177. try
  13178. {
  13179. int eid = GetPostInt("eid");
  13180. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13181. if (ceErpSupplierProductTime == null)
  13182. {
  13183. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  13184. }
  13185. ceErpSupplierProductTime.productId = productId;
  13186. ceErpSupplierProductTime.productName = productName;
  13187. ceErpSupplierProductTime.supplierId = supplierId;
  13188. ceErpSupplierProductTime.supplierName = supplierName;
  13189. ceErpSupplierProductTime.craft = craft;
  13190. ceErpSupplierProductTime.sendDay = sendDay;
  13191. ceErpSupplierProductTime.quantity = quantity;
  13192. if (!string.IsNullOrEmpty(deadLine))
  13193. {
  13194. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  13195. }
  13196. if (!string.IsNullOrEmpty(dayDeadLine))
  13197. {
  13198. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  13199. }
  13200. if (ceErpSupplierProductTime.ID == 0)
  13201. {
  13202. ceErpSupplierProductTime.Save();
  13203. }
  13204. else
  13205. {
  13206. ceErpSupplierProductTime.Update();
  13207. }
  13208. }
  13209. catch (Exception e)
  13210. {
  13211. }
  13212. returnSuccessMsg("保存成功");
  13213. return;
  13214. }
  13215. public void delSupplierProductTime()
  13216. {
  13217. int eid = GetPostInt("eid");
  13218. if (eid > 0)
  13219. {
  13220. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  13221. if (ceErpSupplierProductTime == null)
  13222. {
  13223. returnErrorMsg("查无数据");
  13224. return;
  13225. }
  13226. ceErpSupplierProductTime.Delete();
  13227. returnSuccessMsg("保存成功");
  13228. return;
  13229. }
  13230. returnErrorMsg("缺少必要的参数");
  13231. }
  13232. public void getExpressInfo()
  13233. {
  13234. string ctid = GetPostString("ctid");
  13235. if (!string.IsNullOrEmpty(ctid))
  13236. {
  13237. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13238. if (ceErpTradeCell != null)
  13239. {
  13240. string outSid = ceErpTradeCell.OutSid;
  13241. if (outSid.Length > 0)
  13242. {
  13243. string sql = string.Format("SELECT out_sid FROM [dbo].[CE_ErpExpressInfo] WHERE (out_sid in ({0}) or tid = '{1}') and ISNULL(DATALENGTH(postData), 0)>0;", "'" + outSid.Replace(",", "','") + "'", ceErpTradeCell.tid);
  13244. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13245. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  13246. return;
  13247. }
  13248. }
  13249. returnErrorMsg("查无记录");
  13250. return;
  13251. }
  13252. returnErrorMsg("缺少必要的参数");
  13253. }
  13254. public void getExpressPostData()
  13255. {
  13256. string express = GetPostString("express");
  13257. if (!string.IsNullOrEmpty(express))
  13258. {
  13259. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  13260. if (ceErpExpressInfo != null)
  13261. {
  13262. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  13263. return;
  13264. }
  13265. }
  13266. returnErrorMsg("缺少必要的参数");
  13267. }
  13268. public void checkSupplierOrder()
  13269. {
  13270. string ctids = GetPostString("ctids");
  13271. if (ctids != null)
  13272. {
  13273. List<string> list = new List<string>();
  13274. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  13275. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13276. for (int i = 0; i < dt.Rows.Count; i++)
  13277. {
  13278. DataRow row = dt.Rows[i];
  13279. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  13280. {
  13281. continue;
  13282. }
  13283. list.Add(row["seller_memo"].ToString());
  13284. }
  13285. if (list.Count > 0)
  13286. {
  13287. DbHelper.DbConn.ExecuteNonQuery(string.Format("insert into CE_ErpTradeLog(tid,orderstate,userid,operatetime,con) select ctid,{1},{2},getdate(),'{3}' from ce_erptradecell where ctid in ({0}) ;", "'" + ctids.Replace(",", "','") + "'", (int)OrderState.下单完成, CurrentUser.UserID, "点击下载按钮"));
  13288. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  13289. return;
  13290. }
  13291. }
  13292. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  13293. return;
  13294. }
  13295. public void addPersonId()
  13296. {
  13297. string tid = GetPostString("tid");
  13298. string personId = GetPostString("personId");
  13299. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13300. if (ceErpTrade != null)
  13301. {
  13302. ceErpTrade.receiver_zip = personId;
  13303. ceErpTrade.Update();
  13304. LogHelper.addLog(tid, CurrentUser.UserID, "身份证号:" + personId, 6);
  13305. returnSuccessMsg("保存成功");
  13306. return;
  13307. }
  13308. returnErrorMsg("缺少必要的参数");
  13309. }
  13310. public void addDeliveryPaymant()
  13311. {
  13312. string tid = GetPostString("tid");
  13313. string paymant = GetPostString("paymant");
  13314. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13315. if (ceErpTrade != null)
  13316. {
  13317. if (!string.IsNullOrEmpty(paymant))
  13318. {
  13319. ceErpTrade.delivery_paymant = Convert.ToDouble(paymant);
  13320. }
  13321. ceErpTrade.Update();
  13322. LogHelper.addLog(tid, CurrentUser.UserID, "偏远物流费:" + paymant, 6);
  13323. returnSuccessMsg("保存成功");
  13324. return;
  13325. }
  13326. returnErrorMsg("缺少必要的参数");
  13327. }
  13328. public void saveCellFile()
  13329. {
  13330. string tid = GetPostString("tid");
  13331. string ctid = GetPostString("ctid");
  13332. string urls = GetPostString("urls");
  13333. string type = GetPostString("type");
  13334. string del = GetPostString("del");
  13335. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13336. {
  13337. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13338. {
  13339. ctid = tid;
  13340. }
  13341. if ("1".Equals(del))
  13342. {
  13343. CeErpTradeCellFile.delByCtid(tid, ctid, tradeCellFile.ToString());
  13344. }
  13345. string[] list = urls.Split(',');
  13346. if (!string.IsNullOrEmpty(urls) && list.Length > 0)
  13347. {
  13348. foreach (string item in list)
  13349. {
  13350. CeErpTradeCellFile ceErpTradeCellFile = new CeErpTradeCellFile(tid, ctid, item, tradeCellFile.ToString());
  13351. ceErpTradeCellFile.Create();
  13352. LogHelper.addLog(ctid, CurrentUser.UserID, "上传客户文件:" + item, 6);
  13353. }
  13354. }
  13355. returnSuccessMsg("保存成功");
  13356. return;
  13357. }
  13358. returnErrorMsg("缺少必要的参数");
  13359. }
  13360. public void getCellFile()
  13361. {
  13362. string tid = GetPostString("tid");
  13363. string ctid = GetPostString("ctid");
  13364. string type = GetPostString("type");
  13365. if (Enum.TryParse(type, out TradeCellFile tradeCellFile))
  13366. {
  13367. if (tradeCellFile == TradeCellFile.AUTH_FILE)
  13368. {
  13369. ctid = tid;
  13370. }
  13371. string sql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeCellFile] WHERE isDel=0 and tid='{0}' and ctid='{1}' and type='{2}';", tid, ctid, tradeCellFile);
  13372. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13373. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  13374. return;
  13375. }
  13376. returnErrorMsg("缺少必要的参数");
  13377. }
  13378. public void delCellFile()
  13379. {
  13380. string id = GetPostString("id");
  13381. if (string.IsNullOrEmpty(id))
  13382. {
  13383. returnErrorMsg("缺少必要的参数");
  13384. return;
  13385. }
  13386. CeErpTradeCellFile ceErpTradeCellFile = CeErpTradeCellFile.Get(id);
  13387. CeErpTradeCellFile.delByID(id);
  13388. LogHelper.addLog(ceErpTradeCellFile.ctid, CurrentUser.UserID, "删除客户文件", 6);
  13389. returnSuccessMsg("保存成功");
  13390. }
  13391. public void getInvoiceOrder()
  13392. {
  13393. string tid = GetPostString("tid");
  13394. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  13395. List<string> tids = new List<string>();
  13396. if (!string.IsNullOrEmpty(ceErpTrade.buyer_nick) && !string.IsNullOrEmpty(ceErpTrade.buyer_id))
  13397. {
  13398. string sql = string.Format("SELECT tid FROM [dbo].[CE_ErpTrade] WHERE buyer_id = '{0}' AND seller_nick = '{1}' order by pay_time desc;", ceErpTrade.buyer_id, ceErpTrade.seller_nick);
  13399. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13400. foreach (DataRow dr in dt.Rows)
  13401. {
  13402. tids.Add("'" + dr["tid"].ToString() + "'");
  13403. }
  13404. }
  13405. else
  13406. {
  13407. tids.Add("'" + ceErpTrade.tid + "'");
  13408. }
  13409. DataTable cell_dt = new DataTable();
  13410. if (tids.Count > 0)
  13411. {
  13412. cell_dt = DbHelper.DbConn.ExecuteDataset(string.Format("SELECT * FROM [dbo].[CE_ErpTradeCell] WHERE tid in ({0});", string.Join(",", tids))).Tables[0];
  13413. }
  13414. ReturnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(cell_dt));
  13415. return;
  13416. }
  13417. public void getOrderLogInfo()
  13418. {
  13419. string ctid = GetPostString("ctid");
  13420. if (!string.IsNullOrEmpty(ctid))
  13421. {
  13422. StringBuilder sql = new StringBuilder();
  13423. sql.AppendFormat("select * from view_erptradelog where tid='{0}' order by id;", ctid);
  13424. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  13425. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(ds.Tables[0])) + "}");
  13426. return;
  13427. }
  13428. returnErrorMsg("缺少必要的参数");
  13429. }
  13430. public void setCellTeampId()
  13431. {
  13432. string ctid = GetPostString("ctid");
  13433. string tempId = GetPostString("tempId");
  13434. if (!string.IsNullOrEmpty(ctid))
  13435. {
  13436. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13437. if (ceErpTradeCellExtend == null)
  13438. {
  13439. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13440. ceErpTradeCellExtend.ctid = ctid;
  13441. }
  13442. ceErpTradeCellExtend.tempId = tempId;
  13443. if (ceErpTradeCellExtend.ID > 0)
  13444. {
  13445. ceErpTradeCellExtend.Update();
  13446. }
  13447. else
  13448. {
  13449. ceErpTradeCellExtend.Create();
  13450. }
  13451. designHelper.API_sendTempInfo(ctid, tempId);
  13452. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "修改模板id" + tempId, 6);
  13453. returnSuccessMsg("保存成功");
  13454. return;
  13455. }
  13456. returnErrorMsg("缺少必要的参数");
  13457. }
  13458. public void saveJointorder()
  13459. {
  13460. string ctid = GetPostString("ctid");
  13461. if (!string.IsNullOrEmpty(ctid))
  13462. {
  13463. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  13464. if (ceErpTradeCellExtend == null)
  13465. {
  13466. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  13467. ceErpTradeCellExtend.ctid = ctid;
  13468. }
  13469. if (ceErpTradeCellExtend.IsJoint == 1)
  13470. {
  13471. ceErpTradeCellExtend.IsJoint = 0;
  13472. }
  13473. else
  13474. {
  13475. ceErpTradeCellExtend.IsJoint = 1;
  13476. }
  13477. if (ceErpTradeCellExtend.ID > 0)
  13478. {
  13479. ceErpTradeCellExtend.Update();
  13480. }
  13481. else
  13482. {
  13483. ceErpTradeCellExtend.Create();
  13484. }
  13485. returnSuccessMsg("保存成功");
  13486. return;
  13487. }
  13488. returnErrorMsg("缺少必要的参数");
  13489. }
  13490. public void applyOrderBack()
  13491. {
  13492. string ctid = GetPostString("ctid");
  13493. string reason = GetPostString("reason");
  13494. if (!string.IsNullOrEmpty(ctid))
  13495. {
  13496. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13497. if (ceErpTradeCell == null)
  13498. {
  13499. returnErrorMsg("找不到订单");
  13500. return;
  13501. }
  13502. if (ceErpTradeCell.OrderState != 5 && ceErpTradeCell.OrderState != 6)
  13503. {
  13504. returnErrorMsg("待下单已下单才能申请");
  13505. return;
  13506. }
  13507. //下单后24小时后无法申请
  13508. if (ceErpTradeCell.OrderState == 6 && ceErpTradeCell.FinishPlaceTime != null)
  13509. {
  13510. DateTime now = DateTime.Now;
  13511. if (!string.IsNullOrEmpty(ceErpTradeCell.FinishPlaceTime.ToString()) && DateTime.Compare(DateTime.Parse(ceErpTradeCell.FinishPlaceTime.ToString()), now.AddHours(-24)) < 0)
  13512. {
  13513. returnErrorMsg("下单后24小时后无法申请");
  13514. return;
  13515. }
  13516. }
  13517. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}'", ceErpTradeCell.ctid);
  13518. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13519. if (dataTable != null && dataTable.Rows.Count > 0)
  13520. {
  13521. foreach (DataRow row in dataTable.Rows)
  13522. {
  13523. if (row["Con"].ToString().Contains("拒绝打回"))
  13524. {
  13525. returnErrorMsg("被拒绝过无法继续申请");
  13526. return;
  13527. }
  13528. }
  13529. }
  13530. ceErpTradeCell.IsReturn = 4;
  13531. ceErpTradeCell.Update();
  13532. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请打回:" + reason, ceErpTradeCell.OrderState);
  13533. returnSuccessMsg("保存成功");
  13534. return;
  13535. }
  13536. returnErrorMsg("缺少必要的参数");
  13537. }
  13538. public void cancelApplyOrderBack()
  13539. {
  13540. string ctid = GetPostString("ctid");
  13541. if (!string.IsNullOrEmpty(ctid))
  13542. {
  13543. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13544. if (ceErpTradeCell == null)
  13545. {
  13546. returnErrorMsg("找不到订单");
  13547. return;
  13548. }
  13549. if (ceErpTradeCell.IsReturn != 4)
  13550. {
  13551. returnErrorMsg("订单未在申请阶段");
  13552. return;
  13553. }
  13554. ceErpTradeCell.IsReturn = 0;
  13555. ceErpTradeCell.Update();
  13556. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "取消申请打回", ceErpTradeCell.OrderState);
  13557. returnSuccessMsg("保存成功");
  13558. return;
  13559. }
  13560. returnErrorMsg("缺少必要的参数");
  13561. }
  13562. public void get_erp_applybackorderlist()
  13563. {
  13564. DataStruct dStruct = GetPostStruct();
  13565. List<string> lw = new List<string>();
  13566. string tid = GetPostString("ctid");
  13567. if (tid.Length > 0)
  13568. {
  13569. string select_tid = getTidByCtid(tid);
  13570. lw.Add(string.Format("tid='{0}'", select_tid));
  13571. }
  13572. string shopname = GetPostString("shopname");
  13573. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  13574. string buyernick = GetPostString("buyer_nick");
  13575. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  13576. string customer = GetPostString("customer");
  13577. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  13578. string design = GetPostString("design");
  13579. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  13580. string orderState = GetPostString("orderState");
  13581. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  13582. string supplier = GetPostString("supplier");
  13583. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  13584. string sellermemo = GetPostString("seller_memo");
  13585. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  13586. string otherMemo = GetPostString("otherMemo");
  13587. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  13588. string address = GetPostString("address");
  13589. if (address.Length > 0) lw.Add(string.Format("(receiver_address like '%{0}%' or receiver_state like '%{0}%' or receiver_city like '%{0}%' or receiver_name like '%{0}%' or receiver_mobile like '%{0}%')", address));
  13590. string date1 = GetPostString("date1");
  13591. string date2 = GetPostString("date2");
  13592. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  13593. if (dw.Length > 0) lw.Add(dw);
  13594. string price1 = GetPostString("price1");
  13595. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  13596. string price2 = GetPostString("price2");
  13597. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  13598. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13599. {
  13600. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13601. lw.Add(string.Format("OrderState = 6"));
  13602. }
  13603. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13604. {
  13605. lw.Add("OrderState in (5,6) ");
  13606. }
  13607. lw.Add(string.Format("IsReturn = 4"));
  13608. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  13609. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  13610. string pagesize = GetPostString("pagesize");
  13611. if (pagesize != null)
  13612. {
  13613. dStruct.PageSize = 200;
  13614. }
  13615. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  13616. writeGridDataTableJson(dStruct.TotalCount, dt);
  13617. }
  13618. public void refuseBackOrder()
  13619. {
  13620. string ctid = GetPostString("ctid");
  13621. if (!string.IsNullOrEmpty(ctid))
  13622. {
  13623. string reason = GetPostString("returnreason");
  13624. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  13625. if (ceErpTradeCell == null)
  13626. {
  13627. returnErrorMsg("找不到订单");
  13628. return;
  13629. }
  13630. string sql = string.Format("select Con,UserId from CE_ErpTradeLog where tid = '{0}' order by ID desc", ceErpTradeCell.ctid);
  13631. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13632. int userId = 0;
  13633. if (dataTable != null && dataTable.Rows.Count > 0)
  13634. {
  13635. foreach (DataRow row in dataTable.Rows)
  13636. {
  13637. if (row["Con"].ToString().Contains("申请打回:"))
  13638. {
  13639. userId = Convert.ToInt32(row["UserId"]);
  13640. }
  13641. }
  13642. }
  13643. if (userId > 0)
  13644. {
  13645. CeErpMessageTip ct = new CeErpMessageTip();
  13646. ct.tid = ceErpTradeCell.ctid;
  13647. ct.sectionId = 0;
  13648. ct.userId = userId;
  13649. ct.type = 4;
  13650. ct.isVisit = false;
  13651. ct.content = ceErpTradeCell.ctid + ",申请打回被拒绝:" + reason;
  13652. ct.Create();
  13653. }
  13654. ceErpTradeCell.IsReturn = 0;
  13655. ceErpTradeCell.Update();
  13656. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "拒绝打回:" + reason, ceErpTradeCell.OrderState);
  13657. returnSuccessMsg("保存成功");
  13658. return;
  13659. }
  13660. returnErrorMsg("缺少必要的参数");
  13661. }
  13662. public void passApplyBack()
  13663. {
  13664. if (UrlPostParmsCheck("ctid"))
  13665. {
  13666. string eid = GetPostString("ctid");
  13667. CeErpTradeCell entity = null;
  13668. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  13669. string userpost = CurrentUser.UserPost.Post.Code;
  13670. if (entity != null)
  13671. {
  13672. string message = "操作成功!";
  13673. string isDown = "";
  13674. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  13675. {
  13676. message = "订单有被点击下载。请注意沟通是否已下载完!";
  13677. isDown = "被点击下载";
  13678. }
  13679. bool isPlace = false;
  13680. if (entity.OrderState > 6)
  13681. {
  13682. returnErrorMsg("已发货无法打回!");
  13683. return;
  13684. }
  13685. if (entity.OrderState == 6)
  13686. {
  13687. isPlace = true;
  13688. }
  13689. bool isNeedUpdateCell2 = false;
  13690. if (entity.OrderState >= 6)
  13691. {
  13692. isNeedUpdateCell2 = true;
  13693. }
  13694. int returnTag = 2;
  13695. if (userpost == "Supplier")
  13696. {
  13697. returnTag = 1;
  13698. }
  13699. int toType = GetPostInt("totype");
  13700. string fromType = "3";
  13701. if (entity.OrderState < 5)
  13702. {
  13703. fromType = "3";
  13704. }
  13705. else
  13706. {
  13707. fromType = "4";
  13708. }
  13709. if (entity.IsXianHuo == 0)
  13710. {
  13711. if (returnTag == 2)
  13712. {
  13713. if (toType == 1)
  13714. {
  13715. entity.OrderState = 0;
  13716. entity.ReturnUserType = 1;
  13717. string clearman = GetPostString("clearman");
  13718. if (!string.IsNullOrEmpty(clearman))
  13719. {
  13720. entity.DesignUserId = 0;
  13721. }
  13722. }
  13723. else
  13724. {
  13725. entity.OrderState = 3;
  13726. entity.ReturnUserType = 2;
  13727. }
  13728. entity.IsReadTag = 1;
  13729. }
  13730. else if (returnTag == 1)
  13731. {
  13732. entity.OrderState = 5;
  13733. }
  13734. entity.IsVerifyToSupplier = false;
  13735. }
  13736. if (entity.IsXianHuo == 1)
  13737. {
  13738. entity.OrderState = 5;
  13739. }
  13740. entity.IsVerifyToSupplier = false;
  13741. entity.IsHaveNewOrder = 0;
  13742. entity.UnusualTag = 0;
  13743. entity.UnusualTime = null;
  13744. entity.UnusualCon = "";
  13745. entity.IsReturn = returnTag;
  13746. entity.ReturnTime = DateTime.Now;
  13747. entity.UpdateTime = DateTime.Now;
  13748. entity.ReturnReason = GetPostString("returnreason");
  13749. entity.Update();
  13750. if (entity.OrderState == 3)
  13751. {
  13752. ApiVo apiVo = new ApiVo();
  13753. apiVo.orderNumber = entity.ctid;
  13754. apiVo.actionName = "rebutDesign";
  13755. apiVo.orderRemarks = entity.ReturnReason;
  13756. designHelper.API_WorkCore(apiVo);//rebutDesign
  13757. }
  13758. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason + isDown, entity.OrderState);
  13759. if (isPlace)
  13760. {
  13761. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  13762. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  13763. if (dth != null && dth.Rows.Count > 0)
  13764. {
  13765. dataSendOrderBean dataSendOrderBean = null;
  13766. foreach (DataRow item in dth.Rows)
  13767. {
  13768. try
  13769. {
  13770. dataSendOrderBean = new dataSendOrderBean();
  13771. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  13772. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  13773. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  13774. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  13775. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  13776. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  13777. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  13778. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  13779. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  13780. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  13781. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  13782. dataSendOrderBean.Radio1723534706288 = "打回";
  13783. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  13784. if (result != null)
  13785. {
  13786. if ("0".Equals(result.errcode))
  13787. {
  13788. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  13789. }
  13790. else
  13791. {
  13792. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  13793. }
  13794. }
  13795. }
  13796. catch (Exception ex)
  13797. {
  13798. }
  13799. }
  13800. }
  13801. }
  13802. returnSuccessMsg(message);
  13803. return;
  13804. }
  13805. returnErrorMsg("找不到订单记录");
  13806. }
  13807. }
  13808. public void getApplyBackCount()
  13809. {
  13810. string sql = string.Format("SELECT top 1 ctid FROM [dbo].[CE_ErpTradeCell]");
  13811. List<string> lw = new List<string>();
  13812. lw.Add("IsReturn = 4");
  13813. if (CurrentUser.UserPost.Post.Code == "Supplier")
  13814. {
  13815. lw.Add("OrderState = 6");
  13816. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  13817. }
  13818. else if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  13819. {
  13820. lw.Add("OrderState = 5");
  13821. }
  13822. else
  13823. {
  13824. ReturnSuccess("{" + string.Format("\"data\":{0}", "0") + "}");
  13825. return;
  13826. }
  13827. sql += " where " + string.Join(" and ", lw.ToArray());
  13828. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  13829. List<string> list = new List<string>();
  13830. if (dataTable != null && dataTable.Rows.Count > 0)
  13831. {
  13832. foreach (DataRow row in dataTable.Rows)
  13833. {
  13834. list.Add(row["ctid"].ToString());
  13835. }
  13836. }
  13837. ReturnSuccess("{" + string.Format("\"data\":{0}", "\"" + string.Join(",", list) + "\"") + "}");
  13838. return;
  13839. }
  13840. }
  13841. }