sync.order.cs 638 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816
  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. namespace SiteCore.Handler
  49. {
  50. public partial class sync
  51. {
  52. public void get_erp_orderlist()
  53. {
  54. string poscode = CurrentUser.UserPost.Post.Code;
  55. DataStruct dStruct = GetPostStruct();
  56. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\uv特殊工艺价格(1).xls");
  57. //apiHelper.Api_SyncOrderByTime("598825");
  58. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  59. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  60. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  61. //banniuApiHelper.sendLogisticsInfo(null);
  62. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  63. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  64. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  65. //int sid = commonHelper.autoDistributeToSupplier(entity);
  66. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  67. //tmcHelper.Api_TmcTradeMsg("{\"content\":{\"businessType\":\"GUARANTEE\",\"buyerMemo\":\"\",\"consolidateType\":\"\",\"createTime\":1747793700000,\"deliveryType\":\"OFFLINE\",\"discountFee\":15.0,\"flag\":\"NONE\",\"latestDeliveryTime\":1748015999000,\"lines\":[{\"mark2\":[],\"num\":2,\"outerId\":\"JSBHUVZYT\",\"payment\":85.0,\"picUrl\":\"https://img.alicdn.com/bao/uploaded/i4/2200806677467/O1CN01aEDI6s251wFlRwWHL_!!0-item_pic.jpg\",\"platServiceFee\":0.0,\"price\":50.0,\"refOlId\":\"4348532702415998633\",\"refSkuId\":\"0\",\"refSpuId\":\"620901028368\",\"refundStatus\":\"NO_REFUND\",\"sellPrice\":42.5,\"singleFee\":42.5,\"spuOuterId\":\"JSBHUVZYT\",\"standards\":\"\",\"status\":\"NOT_SHIPPED\",\"title\":\"【狂欢价】水晶标贴金属标签LOGO贴纸定制车热uv转印贴透明商标打印设备移丝印广告自粘刻字烫金定做公司防水不干胶印刷\",\"totalFee\":85.0,\"totalPrice\":100.0,\"totalSellPrice\":85.0}],\"logisticsOrderNo\":\"\",\"mark2\":[],\"modifyTime\":1747794079000,\"openBuyerId\":\"AAEmRHraABkUZRPgSx1NTPcZ\",\"openBuyerNick\":\"排**\",\"openSellerNick\":\"翊喜旗舰店\",\"orderSource\":\"SYNC\",\"orderTime\":1747793522000,\"payTime\":1747793695000,\"payment\":85.0,\"platServiceFee\":0.0,\"posCode\":\"yixi\",\"posId\":598788,\"postFee\":0.0,\"props\":{\"payType\":\"ALI_PAY\",\"govSubsidyAmount\":0},\"receivedPayment\":0.0,\"receiverCity\":\"梅州市\",\"receiverCountry\":\"中国\",\"receiverDistrict\":\"梅江区\",\"receiverId\":\"c01bdfe140ea76155b427e6b00424547$\",\"receiverState\":\"广东省\",\"receiverTown\":\"三角镇\",\"refOid\":\"4348532702415998633\",\"refType\":\"TMALL\",\"refundStatus\":\"NO_REFUND\",\"sellerMemo\":\"34.5x25.5mm-210个-UV转印贴-彩色-模切-排排坐唱山歌歌-小钰-()-老客户改稿\",\"serviceFee\":0.0,\"status\":\"NOT_SHIPPED\",\"totalFee\":85.0,\"totalPrice\":100.0,\"totalSellPrice\":85.0,\"type\":\"SALE\"}}");
  68. //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}}");
  69. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  70. //commonHelper.loginGetOrder(2152);
  71. List<string> lw = new List<string>();
  72. string tid = GetPostString("ctid");
  73. string date1 = GetPostString("date1");
  74. //12-1 修改
  75. string urgent = GetPostString("urgent");
  76. string back = GetPostString("back");
  77. string offlineSearch = GetPostString("offlineSearch");
  78. int paramsCount = 0;
  79. if (!string.IsNullOrWhiteSpace(urgent))
  80. {
  81. if (urgent.Equals("true"))
  82. {
  83. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  84. }
  85. }
  86. if (!string.IsNullOrWhiteSpace(back))
  87. {
  88. if (back.Equals("true"))
  89. {
  90. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  91. }
  92. }
  93. if (!string.IsNullOrWhiteSpace(offlineSearch))
  94. {
  95. if (offlineSearch.Equals("true"))
  96. {
  97. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  98. }
  99. }
  100. //end
  101. string date2 = GetPostString("date2");
  102. string buyernick = GetPostString("buyer_nick");
  103. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  104. {
  105. if (tid.Length <= 0 && buyernick.Length <= 0)
  106. {
  107. return;
  108. }
  109. }
  110. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  111. {
  112. if (tid.Length > 0)
  113. {
  114. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCode(tid);
  115. if (ceErpTradeCell != null)
  116. {
  117. tid = ceErpTradeCell.tid;
  118. }
  119. List<string> select_tid = getTidByCtidMore(tid);
  120. lw.Add(string.Format("tid in ({0})", string.Join(",", select_tid)));
  121. }
  122. if (buyernick.Length > 0)
  123. {
  124. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  125. }
  126. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  127. if (dw.Length > 0)
  128. {
  129. lw.Add(dw);
  130. }
  131. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  132. {
  133. string usershop = CurrentUser.User.pemShop;
  134. lw.Add(string.Format("ShopId in ({0})", usershop));
  135. }
  136. }
  137. else
  138. {
  139. if (ex_psize == 0)
  140. {
  141. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  142. }
  143. if (PKey != "admin")
  144. {
  145. string usershop = CurrentUser.User.pemShop;
  146. lw.Add(string.Format("ShopId in ({0})", usershop));
  147. paramsCount++;
  148. }
  149. }
  150. string uploaddate1 = GetPostString("uploaddate1");
  151. string uploaddate2 = GetPostString("uploaddate2");
  152. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  153. if (update.Length > 0) lw.Add(update);
  154. string deliverydate1 = GetPostString("deliverydate1");
  155. string deliverydate2 = GetPostString("deliverydate2");
  156. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  157. if (deliverydate.Length > 0)
  158. {
  159. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  160. };
  161. string shopname = GetPostString("shopname");
  162. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  163. string addwechat = GetPostString("addwechat");
  164. if (addwechat.Length > 0)
  165. {
  166. int addWt = Convert.ToInt32(addwechat);
  167. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  168. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  169. }
  170. string customer = GetPostString("customer");
  171. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  172. string design = GetPostString("design");
  173. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  174. string orderState = GetPostString("orderState");
  175. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  176. string address = GetPostString("address");
  177. 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));
  178. string sellermemo = GetPostString("seller_memo");
  179. if (sellermemo.Length > 0)
  180. {
  181. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  182. }
  183. string backReason = GetPostString("backReason");
  184. if (backReason.Length > 0)
  185. {
  186. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  187. }
  188. string apdate1 = GetPostString("apdate1");
  189. string apdate2 = GetPostString("apdate2");
  190. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  191. if (dwap.Length > 0) lw.Add(dwap);
  192. string price1 = GetPostString("price1");
  193. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  194. string price2 = GetPostString("price2");
  195. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  196. string isoldcustomer = GetPostString("isoldcus");
  197. string spudata = GetPostString("spudata");
  198. if ("0".Equals(spudata))
  199. {
  200. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  201. }
  202. if ("1".Equals(spudata))
  203. {
  204. lw.Add(string.Format("spu_id <> ''"));
  205. }
  206. string finishdate1 = GetPostString("finishdate1");
  207. string finishdate2 = GetPostString("finishdate2");
  208. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  209. bool isFinish = false;
  210. if (finishdate.Length > 0)
  211. {
  212. lw.Add(finishdate);
  213. isFinish = true;
  214. paramsCount++;
  215. }
  216. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  217. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  218. if (ex_psize > 0)
  219. {
  220. int UserID = CurrentUser.UserID;
  221. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  222. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  223. {
  224. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  225. }
  226. dStruct.Order = "pay_time desc";
  227. }
  228. string isNew = GetPostString("isNew");
  229. if (isNew == "true")
  230. {
  231. lw.Add(string.Format("IsNew = {0}", 1));
  232. }
  233. string overtime = GetPostString("overtime");
  234. if (overtime == "1")
  235. {
  236. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  237. }
  238. String usePost = CurrentUser.UserPost.Post.Code;
  239. if (usePost.Equals("Operation") == true)
  240. {
  241. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  242. }
  243. else
  244. {
  245. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  246. }
  247. //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";
  248. if (dStruct.PageSize == 100000)
  249. {
  250. dStruct.Order = "";
  251. }
  252. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  253. DataTable dt = null;
  254. string tablename = "view_orderlist";
  255. if (isFinish)
  256. {
  257. tablename = "view_orderlist_end";
  258. }
  259. dt = WebCache.GetData(tablename, dStruct);
  260. if (dt != null && dt.Rows.Count > 0)
  261. {
  262. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  263. foreach (DataRow dr in dt.Rows)
  264. {
  265. try
  266. {
  267. if (dr["refund_fees"] != null)
  268. {
  269. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  270. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  271. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  272. if (payment == refund_fees)
  273. {
  274. dr["refund_fees"] = Math.Round(refund_fees, 2);
  275. }
  276. else if (refund_fees == total_fee)
  277. {
  278. dr["refund_fees"] = payment;
  279. }
  280. else
  281. {
  282. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  283. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  284. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  285. }
  286. }
  287. // 对象操作
  288. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  289. ceErpTradeCell.ctid = dr["ctid"].ToString();
  290. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  291. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  292. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  293. if (dStruct.PageSize != 100000)
  294. {
  295. if (dr["DispatchSort"].ToString() == "2")
  296. {
  297. dr["gongchuang"] = 200;
  298. }
  299. else if ("外协".Equals(dr["ToType"].ToString()))
  300. {
  301. dr["gongchuang"] = 200;
  302. }
  303. else if ("内部".Equals(dr["ToType"].ToString()))
  304. {
  305. dr["gongchuang"] = -1;
  306. }
  307. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  308. {
  309. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  310. dr["gongchuang"] = response.code;
  311. }
  312. }
  313. }
  314. catch (NullReferenceException ex)
  315. {
  316. // 处理空引用异常
  317. dr["refund_fees"] = "0.00";
  318. }
  319. }
  320. }
  321. writeGridDataTableJson(dStruct.TotalCount, dt);
  322. }
  323. public void get_erp_orderlist_sumprice()
  324. {
  325. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  326. return;
  327. List<string> lw = new List<string>();
  328. string tid = GetPostString("ctid");
  329. string date1 = GetPostString("date1");
  330. string date2 = GetPostString("date2");
  331. if (tid.Length > 0 || date1.Length > 0)
  332. {
  333. lw.Add(string.Format("ctid like '%{0}%'", tid));
  334. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  335. if (dw.Length > 0) lw.Add(dw);
  336. }
  337. else
  338. {
  339. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  340. }
  341. string shopname = GetPostString("shopname");
  342. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  343. string buyernick = GetPostString("buyer_nick");
  344. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  345. string customer = GetPostString("customer");
  346. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  347. string design = GetPostString("design");
  348. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  349. string orderState = GetPostString("orderState");
  350. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  351. string address = GetPostString("address");
  352. 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));
  353. string sellermemo = GetPostString("seller_memo");
  354. if (sellermemo.Length > 0)
  355. {
  356. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  357. }
  358. string apdate1 = GetPostString("apdate1");
  359. string apdate2 = GetPostString("apdate2");
  360. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  361. if (dwap.Length > 0) lw.Add(dwap);
  362. string price1 = GetPostString("price1");
  363. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  364. string price2 = GetPostString("price2");
  365. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  366. string isoldcustomer = GetPostString("isoldcus");
  367. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  368. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  369. if (PKey != "admin")
  370. {
  371. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  372. lw.Add(string.Format("shopId in ({0})", usershop));
  373. }
  374. //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";
  375. string mainWhere = string.Join(" and ", lw.ToArray());
  376. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  377. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  378. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  379. decimal total = 0;
  380. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  381. {
  382. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  383. }
  384. var res = new
  385. {
  386. data = total
  387. };
  388. string ro_jsond = JsonConvert.SerializeObject(res);
  389. returnSuccess(ro_jsond);
  390. return;
  391. }
  392. public void get_erp_CustomerServiceGather()
  393. {
  394. string userWhere = "", orderWhere = "";
  395. List<string> lw = new List<string>();
  396. string customer = GetPostString("customer");
  397. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  398. string shopname = GetPostString("shopname");
  399. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  400. string date1 = GetPostString("date1");
  401. string date2 = GetPostString("date2");
  402. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  403. if (dw.Length > 0) lw.Add(dw);
  404. orderWhere = string.Join(" and ", lw.ToArray());
  405. 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 " +
  406. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  407. "left join " +
  408. "( " +
  409. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  410. ") as b on a.ID = b.CustomerUserId " +
  411. "left join " +
  412. "( " +
  413. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  414. ") as d on a.ID = d.CustomerUserId " +
  415. "left join " +
  416. "( " +
  417. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  418. ") as e on a.ID = e.CustomerUserId " +
  419. "left join " +
  420. "( " +
  421. " select CustomerUserId, RefundCount, RefundSum from " +
  422. " ( " +
  423. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  424. " from CE_ErpTradeRefund a " +
  425. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  426. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  427. " group by CustomerUserId " +
  428. " ) as a " +
  429. ") as f on a.ID = f.CustomerUserId " +
  430. "where a.PostCode = 'CustomerService'",
  431. userWhere, orderWhere);
  432. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  433. writeGridDataTableJson(dt.Rows.Count, dt);
  434. //writeGridDataTableJson(dt.Rows.Count, dt);
  435. }
  436. //设计汇总
  437. public void get_erp_DesignerGather()
  438. {
  439. string userWhere = "", orderWhere = "";
  440. List<string> lw = new List<string>();
  441. string Designer = GetPostString("designer");
  442. int org = GetPostInt("org");
  443. if (Designer.Length > 0)
  444. {
  445. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  446. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  447. }
  448. else if (org > 0)
  449. {
  450. userWhere = string.Format(" where OrgID ={0}", org);
  451. }
  452. string shopname = GetPostString("shopname");
  453. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  454. string state = GetPostString("state");
  455. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  456. string OrderArea = GetPostString("order_area");
  457. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  458. string date1 = GetPostString("date1");
  459. string date2 = GetPostString("date2");
  460. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  461. if (dw.Length > 0) lw.Add(dw);
  462. string UpDate1 = GetPostString("UpDate1");
  463. string UpDate2 = GetPostString("UpDate2");
  464. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  465. if (dw.Length > 0) lw.Add(dw);
  466. orderWhere = string.Join(" and ", lw.ToArray());
  467. 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 (" +
  468. "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 " +
  469. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  470. "left join " +
  471. "( " +
  472. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  473. ") as b on a.ID = b.DesignUserId " +
  474. "left join " +
  475. "( " +
  476. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  477. ") as d on a.ID = d.DesignUserId " +
  478. "left join " +
  479. "( " +
  480. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  481. ") as e on a.ID = e.DesignUserId " +
  482. "left join " +
  483. "( " +
  484. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  485. ") as g on a.ID = g.DesignUserId " +
  486. "left join " +
  487. "( " +
  488. " select CustomerUserId, RefundCount, RefundSum from " +
  489. " ( " +
  490. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  491. " from CE_ErpTradeRefund a " +
  492. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  493. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  494. " group by CustomerUserId " +
  495. " ) as a " +
  496. ") as f on a.ID = f.CustomerUserId " +
  497. "where a.PostCode = 'Designer') as z",
  498. userWhere, orderWhere);
  499. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  500. writeGridDataTableJson(dt.Rows.Count, dt);
  501. }
  502. //删除tradecell的订单
  503. public void del_erp_cellorder()
  504. {
  505. if (UrlPostParmsCheck("ctid"))
  506. {
  507. string eid = GetPostString("ctid");
  508. CeErpTradeCell.DelByCtid(eid);
  509. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  510. returnSuccessMsg("删除成功");
  511. }
  512. }
  513. public void clear_erp_refundstate()
  514. {
  515. if (UrlPostParmsCheck("ids"))
  516. {
  517. string eids = GetPostString("ids");
  518. string[] ctidList = eids.Split(',');
  519. foreach (string ctid in ctidList)
  520. {
  521. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  522. if (entity != null)
  523. {
  524. entity.IsRefund = 0;
  525. entity.Update();
  526. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  527. }
  528. else
  529. continue;
  530. }
  531. returnSuccessMsg("操作成功");
  532. return;
  533. }
  534. returnErrorMsg("缺少必要参数");
  535. }
  536. public void set_erp_urgency()
  537. {
  538. if (UrlPostParmsCheck("ctid"))
  539. {
  540. string eid = GetPostString("ctid");
  541. CeErpTradeCell entity = null;
  542. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  543. if (entity != null)
  544. {
  545. double prices = commonHelper.calculationPrice(entity);
  546. if (prices <= 100)
  547. {
  548. returnErrorMsg("此订单金额不足100元,无法加急。");
  549. return;
  550. }
  551. string utime = GetPostString("urgencytime");
  552. if (utime.Length > 0)
  553. {
  554. entity.UrgencyTime = Convert.ToDateTime(utime);
  555. }
  556. else
  557. {
  558. returnErrorMsg("请选择加急时间");
  559. return;
  560. }
  561. if (entity.OrderState <= 4)
  562. {
  563. //entity.seller_memo = entity.seller_memo + "-加急";
  564. string smemo = entity.seller_memo;
  565. int kindex = smemo.IndexOf(")");
  566. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  567. if (lastoneStr != "-")
  568. {
  569. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  570. }
  571. string prememo = smemo.Substring(0, kindex + 2);
  572. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  573. int lastkindex = lastmemo.IndexOf("(");
  574. DateTime urgtime = Convert.ToDateTime(utime);
  575. string newlastmemo = "";
  576. if (lastkindex == 0)
  577. {
  578. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  579. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  580. }
  581. else
  582. {
  583. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  584. }
  585. entity.seller_memo = prememo + newlastmemo;
  586. }
  587. entity.IsUrgency = true;
  588. entity.UpdateTime = DateTime.Now;
  589. entity.Update();
  590. ApiVo apiVo = new ApiVo();
  591. apiVo.orderNumber = entity.ctid;
  592. apiVo.actionName = "changeDesign";
  593. apiVo.orderRemarks = entity.seller_memo;
  594. apiVo.remarkSign = 3;
  595. designHelper.API_WorkCore(apiVo); //changeDesign
  596. CeErpSukuraData.createInfo(entity.ctid, 7);
  597. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  598. returnSuccessMsg("设置成功!");
  599. return;
  600. }
  601. returnErrorMsg("找不到记录");
  602. }
  603. }
  604. public void set_erp_reset()
  605. {
  606. if (UrlPostParmsCheck("ctid"))
  607. {
  608. string eid = GetPostString("ctid");
  609. CeErpTradeCell entity = null;
  610. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  611. if (entity != null)
  612. {
  613. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  614. {
  615. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  616. {
  617. returnErrorMsg("财务要求已下单已发货无法重置");
  618. return;
  619. }
  620. }
  621. entity.IsUrgency = false;
  622. entity.seller_memo = "";
  623. entity.OtherMemo = "";
  624. entity.OrderState = 0;
  625. entity.IsReturn = 0;
  626. //entity.IsRefund = 0;
  627. entity.MemoOpt = 0;
  628. entity.AfterSaleState = 0;
  629. entity.AfterSaleResponsible = "";
  630. entity.AfterSaleUserId = 0;
  631. entity.IsNeedBill = 0;
  632. entity.CustomerUserId = 0;
  633. entity.DesignUserId = 0;
  634. entity.SupplierId = 0;
  635. entity.PlaceUserId = 0;
  636. entity.ptid = "";
  637. entity.IsSample = 0;
  638. entity.IsXianHuo = 0;
  639. entity.isDianziOrder = 0;
  640. entity.DispatchSort = 0;
  641. entity.FinishPlaceTime = null;
  642. entity.Update();
  643. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  644. if (trade != null)
  645. {
  646. trade.seller_memo = "";
  647. trade.Update();
  648. }
  649. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  650. returnSuccessMsg("重置成功!");
  651. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  652. if (desginBill != null)
  653. {
  654. desginBill.isDel = 1;
  655. desginBill.Update();
  656. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  657. }
  658. ApiVo apiVo = new ApiVo();
  659. apiVo.orderNumber = entity.ctid;
  660. apiVo.actionName = "resetDesign";
  661. designHelper.API_WorkCore(apiVo);//resetDesign
  662. return;
  663. }
  664. returnErrorMsg("找不到记录");
  665. }
  666. }
  667. public void save_erp_sellermemo()
  668. {
  669. if (UrlPostParmsCheck("ctid"))
  670. {
  671. string ctid = GetPostString("ctid");
  672. CeErpTradeCell entity = null;
  673. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  674. if (entity != null)
  675. {
  676. string memo = GetPostString("seller_memo");
  677. memo = memo.Replace(" ", "");
  678. if (memo.Contains("补差"))
  679. {
  680. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  681. return;
  682. }
  683. List<string> bitList = new List<string>
  684. {
  685. "\\","/",":","*","?", "\"","<" ,">","|"
  686. };
  687. bool isIn = false;
  688. foreach (string bit in bitList)
  689. {
  690. if (memo.Contains(bit))
  691. {
  692. isIn = true;
  693. }
  694. }
  695. if (isIn)
  696. {
  697. returnErrorMsg("不能使用 一些符合作为文件名");
  698. return;
  699. }
  700. if (entity.seller_memo != memo)
  701. {
  702. if (entity.IsSample == 2)
  703. {
  704. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  705. return;
  706. }
  707. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  708. {
  709. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  710. {
  711. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  712. return;
  713. }
  714. /*if (CurrentUser.UserPost.Post.Code != "Place")
  715. {
  716. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  717. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  718. {
  719. returnErrorMsg("售前系统订单无法再此修改!");
  720. return;
  721. }
  722. }*/
  723. }
  724. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  725. }
  726. commonHelper.getCytPrice(entity);
  727. int memoopt = GetPostInt("MemoOpt");
  728. Boolean ismemoopt = false;
  729. if (memoopt > 0)
  730. {
  731. string stropt = "";
  732. if (memoopt == 1)
  733. {
  734. stropt = "“改稿”";
  735. ismemoopt = true;
  736. }
  737. else if (memoopt == 2)
  738. {
  739. stropt = "“定稿”";
  740. }
  741. else if (memoopt == 3)
  742. {
  743. stropt = "“查货”";
  744. CeErpSukuraData.createInfo(entity.ctid, 6);
  745. }
  746. entity.MemoOpt = Convert.ToInt32(memoopt);
  747. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  748. }
  749. if (entity.OrderState < 5)
  750. {
  751. memo = memo.Replace("(", "(");
  752. memo = memo.Replace(")", ")");
  753. }
  754. if (entity.OrderState < 3)
  755. {
  756. entity.DispatchSort = 0;
  757. }
  758. entity.seller_memo = memo;
  759. entity.UpdateTime = DateTime.Now;
  760. entity.Update();
  761. ApiVo apiVo = new ApiVo();
  762. apiVo.orderNumber = entity.ctid;
  763. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  764. apiVo.orderRemarks = memo;
  765. apiVo.remarkSign = memoopt;
  766. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  767. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  768. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  769. {
  770. dataHelper.api_orderBack(entity.ctid, "0", "");
  771. }
  772. if (entity.seller_memo.Contains("改稿"))
  773. {
  774. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  775. }
  776. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  777. returnSuccessMsg("保存成功!");
  778. return;
  779. }
  780. returnErrorMsg("找不到记录");
  781. }
  782. }
  783. public void ins_erp_checkorder()
  784. {
  785. if (UrlPostParmsCheck("ctid"))
  786. {
  787. string ctid = GetPostString("ctid");
  788. CeErpTradeCell entity = null;
  789. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  790. if (entity != null)
  791. {
  792. if (entity.OrderState < 6)
  793. {
  794. returnErrorMsg("下单完成后才可查货");
  795. return;
  796. }
  797. /*if (entity.OrderState > 6)
  798. {
  799. returnErrorMsg("订单已发货");
  800. return;
  801. }*/
  802. if (entity.FinishPlaceTime != null)
  803. {
  804. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  805. {
  806. returnErrorMsg("下单时间不足,无法查货");
  807. return;
  808. }
  809. }
  810. entity.MemoOpt = 3;
  811. entity.CheckOrderTime = DateTime.Now;
  812. entity.UpdateTime = DateTime.Now;
  813. entity.Update();
  814. CeErpSukuraData.createInfo(entity.ctid, 6);
  815. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  816. returnSuccessMsg("操作成功!");
  817. return;
  818. }
  819. returnErrorMsg("找不到记录");
  820. }
  821. }
  822. public void save_erp_othermemo()
  823. {
  824. if (UrlPostParmsCheck("ctid"))
  825. {
  826. string ctid = GetPostString("ctid");
  827. CeErpTradeCell entity = null;
  828. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  829. if (entity != null)
  830. {
  831. entity.OtherMemo = GetPostString("otherMemo");
  832. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  833. {
  834. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  835. StringBuilder sql = new StringBuilder();
  836. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  837. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  838. if (dt != null && dt.Rows.Count > 0)
  839. {
  840. foreach (DataRow dr in dt.Rows)
  841. {
  842. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  843. {
  844. //品类一直
  845. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  846. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  847. if (ceErpSampleCustomer == null)
  848. {
  849. ceErpSampleCustomer = new CeErpSampleCustomer();
  850. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  851. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  852. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  853. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  854. ceErpSampleCustomer.shopId = entity.ShopId;
  855. }
  856. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  857. ceErpSampleCustomer.lastTid = entity.tid;
  858. if (ceErpSampleCustomer.ID > 0)
  859. {
  860. ceErpSampleCustomer.Update();
  861. }
  862. else
  863. {
  864. ceErpSampleCustomer.Create();
  865. }
  866. }
  867. }
  868. }
  869. }
  870. //if (entity.IsOldCustomer == 1)
  871. //{
  872. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  873. //{
  874. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  875. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  876. //}
  877. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  878. //{
  879. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  880. // {
  881. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  882. // {
  883. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  884. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  885. // }
  886. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  887. // {
  888. // entity.OrderState = 2;
  889. // entity.DesignUserId = 0;
  890. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  891. // }
  892. // else
  893. // {
  894. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  895. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  896. // }
  897. // }
  898. //}
  899. //}
  900. entity.UpdateTime = DateTime.Now;
  901. entity.Update();
  902. returnSuccessMsg("保存成功!");
  903. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  904. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  905. if (entity.OtherMemo.Contains("改稿"))
  906. {
  907. commonHelper.sendSpuData(entity, ceErpTradeCellExtend);
  908. }
  909. return;
  910. }
  911. returnErrorMsg("找不到记录");
  912. }
  913. }
  914. public void save_erp_customermemo()
  915. {
  916. if (UrlPostParmsCheck("ctid"))
  917. {
  918. string ctid = GetPostString("ctid");
  919. CeErpTradeCell entity = null;
  920. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  921. if (entity != null)
  922. {
  923. entity.UpdateTime = DateTime.Now;
  924. entity.CustomerMemo = GetPostString("CustomerMemo");
  925. entity.Update();
  926. ApiVo apiVo = new ApiVo();
  927. apiVo.orderNumber = entity.ctid;
  928. apiVo.actionName = "followRemarks";
  929. apiVo.orderRemarks = entity.CustomerMemo;
  930. designHelper.API_WorkCore(apiVo);//followRemarks
  931. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  932. returnSuccessMsg("保存成功!");
  933. return;
  934. }
  935. returnErrorMsg("找不到记录");
  936. }
  937. }
  938. public void upd_erp_addmemotag()
  939. {
  940. if (UrlPostParmsCheck("ctid"))
  941. {
  942. ;
  943. string eid = GetPostString("ctid");
  944. string sfTagstr = GetPostString("memotag");
  945. CeErpTradeCell entity = null;
  946. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  947. if (entity != null)
  948. {
  949. ApiVo apiVo = new ApiVo();
  950. if (entity.OrderState == 0)
  951. {
  952. returnErrorMsg("请先领单");
  953. return;
  954. }
  955. //撤销顺丰
  956. if (sfTagstr == "撤销顺丰")
  957. {
  958. entity.IsSF = 0;
  959. string reMsg = "";
  960. string oldmemo = entity.seller_memo;
  961. if (entity.OrderState < 5)
  962. {
  963. oldmemo = oldmemo.Replace("顺丰到付", "");
  964. oldmemo = oldmemo.Replace("顺丰寄付", "");
  965. entity.seller_memo = oldmemo;
  966. }
  967. else
  968. {
  969. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  970. {
  971. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  972. }
  973. }
  974. entity.Update();
  975. apiVo.orderNumber = entity.ctid;
  976. apiVo.actionName = "orderRemarks";
  977. apiVo.orderRemarks = entity.seller_memo;
  978. apiVo.isSf = entity.IsSF.ToString();
  979. designHelper.API_WorkCore(apiVo);//orderRemarks
  980. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  981. returnSuccessMsg("撤销成功!" + reMsg);
  982. return;
  983. }
  984. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  985. {
  986. //string oldmemo = entity.seller_memo;
  987. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  988. string sfStr = GetPostString("memotag");
  989. string smemo = entity.seller_memo;
  990. int kindex = smemo.IndexOf(")");
  991. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  992. if (lastoneStr != "-")
  993. {
  994. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  995. }
  996. string prememo = smemo.Substring(0, kindex + 2);
  997. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  998. int lastkindex = lastmemo.IndexOf("(");
  999. string newlastmemo = "";
  1000. if (lastkindex == 0)
  1001. {
  1002. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  1003. newlastmemo = "(" + sfStr + "." + useLastmemo;
  1004. }
  1005. else
  1006. {
  1007. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  1008. }
  1009. entity.seller_memo = prememo + newlastmemo;
  1010. }
  1011. string sfTagMSg = "";
  1012. if (sfTagstr == "顺丰寄付")
  1013. {
  1014. entity.IsSF = 1;
  1015. sfTagMSg = "顺丰寄付";
  1016. }
  1017. else if (sfTagstr == "顺丰到付")
  1018. {
  1019. entity.IsSF = 2;
  1020. sfTagMSg = "顺丰到付";
  1021. }
  1022. entity.Update();
  1023. apiVo = new ApiVo();
  1024. apiVo.orderNumber = entity.ctid;
  1025. apiVo.actionName = "orderRemarks";
  1026. apiVo.orderRemarks = entity.seller_memo;
  1027. apiVo.isSf = entity.IsSF.ToString();
  1028. designHelper.API_WorkCore(apiVo);//orderRemarks
  1029. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1030. returnSuccessMsg("标记成功!");
  1031. return;
  1032. }
  1033. returnErrorMsg("找不到记录");
  1034. }
  1035. }
  1036. public void upd_erp_ordertag()
  1037. {
  1038. if (UrlPostParmsCheck("ctid"))
  1039. {
  1040. string eid = GetPostString("ctid");
  1041. CeErpTradeCell entity = null;
  1042. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1043. if (entity != null)
  1044. {
  1045. int tag = GetPostInt("wechattag");
  1046. //if(tag==4 && entity.IsSample == 2)
  1047. //{
  1048. // returnErrorMsg("补差价单不能标记微信单");
  1049. // return;
  1050. //}
  1051. entity.wechatTag = tag;
  1052. entity.Update();
  1053. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1054. if (tag == 1)
  1055. {
  1056. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1057. if (cash == null)
  1058. {
  1059. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1060. cash = new CeErpReturnCash();
  1061. cash.tid = entity.tid;
  1062. cash.seller_nick = main.seller_nick;
  1063. cash.payment = trade.payment;
  1064. cash.buyer_nick = main.buyer_nick;
  1065. cash.cashstate = 0;
  1066. cash.rtype = "微信返现";
  1067. cash.returnprice = 0;
  1068. cash.created = DateTime.Now;
  1069. cash.con = "订单标记微信单";
  1070. cash.img = "";
  1071. cash.applyuserid = CurrentUser.UserID;
  1072. cash.Create();
  1073. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1074. }
  1075. else
  1076. {
  1077. cash.cashstate = 0;
  1078. cash.Update();
  1079. }
  1080. CeErpSukuraData.createInfo(entity.ctid, 9);
  1081. }
  1082. else if (tag == 2)
  1083. {
  1084. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1085. if (cash == null)
  1086. {
  1087. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1088. cash = new CeErpReturnCash();
  1089. cash.tid = entity.tid;
  1090. cash.seller_nick = main.seller_nick;
  1091. cash.payment = trade.payment;
  1092. cash.buyer_nick = main.buyer_nick;
  1093. cash.cashstate = 0;
  1094. cash.rtype = "推购返现";
  1095. cash.returnprice = 5;
  1096. cash.created = DateTime.Now;
  1097. cash.con = "订单标记推购单";
  1098. cash.img = "";
  1099. cash.applyuserid = CurrentUser.UserID;
  1100. cash.Create();
  1101. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1102. }
  1103. else
  1104. {
  1105. cash.cashstate = 0;
  1106. cash.Update();
  1107. }
  1108. CeErpSukuraData.createInfo(entity.ctid, 9);
  1109. }
  1110. else if (tag == 3)
  1111. {
  1112. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1113. if (pers == null)
  1114. {
  1115. pers = new CeErpPersuade();
  1116. pers.ctid = entity.ctid;
  1117. pers.pstate = 0;
  1118. pers.created = DateTime.Now;
  1119. pers.applyuserid = CurrentUser.UserID;
  1120. pers.Create();
  1121. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1122. }
  1123. else
  1124. {
  1125. pers.pstate = 0;
  1126. pers.Update();
  1127. }
  1128. }
  1129. else if (tag == 4 || tag == 5)
  1130. {
  1131. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1132. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1133. if (pers == null)
  1134. {
  1135. pers = new CeErpStayGoods();
  1136. pers.t_id = entity.tid;
  1137. pers.status = "待审核";
  1138. pers.audit_type = 0;
  1139. if (tag == 4)
  1140. {
  1141. pers.stay_type = "微信推购";
  1142. }
  1143. else
  1144. {
  1145. pers.stay_type = "旺旺推购";
  1146. }
  1147. if (entity.IsXianHuo == 0)
  1148. {
  1149. pers.product_id = entity.ProductId;
  1150. }
  1151. pers.wangwang = main.buyer_nick;
  1152. pers.shop_name = main.seller_nick;
  1153. pers.creata_time = DateTime.Now;
  1154. pers.create_u_id = CurrentUser.UserID;
  1155. pers.create_u_name = CurrentUser.UserName;
  1156. pers.Create();
  1157. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1158. }
  1159. else
  1160. {
  1161. pers.audit_type = 0;
  1162. pers.Update();
  1163. }
  1164. CeErpSukuraData.createInfo(entity.ctid, 10);
  1165. }
  1166. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1167. returnSuccessMsg("标记成功!");
  1168. return;
  1169. }
  1170. returnErrorMsg("找不到记录");
  1171. }
  1172. }
  1173. public void upd_erp_ordertag_cancel()
  1174. {
  1175. if (UrlPostParmsCheck("ctid"))
  1176. {
  1177. string eid = GetPostString("ctid");
  1178. CeErpTradeCell entity = null;
  1179. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1180. if (entity != null)
  1181. {
  1182. entity.wechatTag = 0;
  1183. entity.Update();
  1184. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1185. if (pers != null)
  1186. {
  1187. pers.status = "取消推购";
  1188. pers.audit_type = 3;
  1189. pers.Update();
  1190. }
  1191. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1192. returnSuccessMsg("标记成功!");
  1193. return;
  1194. }
  1195. returnErrorMsg("找不到记录");
  1196. }
  1197. }
  1198. public void upd_erp_addweichattag()
  1199. {
  1200. if (UrlPostParmsCheck("ctid"))
  1201. {
  1202. ;
  1203. string eid = GetPostString("ctid");
  1204. CeErpTradeCell entity = null;
  1205. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1206. if (entity != null)
  1207. {
  1208. if (entity.IsAddWechat > 0)
  1209. {
  1210. returnErrorMsg("此单已经标记过了");
  1211. return;
  1212. }
  1213. 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);
  1214. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1215. if (dt.Rows.Count > 0)
  1216. {
  1217. entity.IsAddWechat = 2;
  1218. }
  1219. else
  1220. {
  1221. entity.IsAddWechat = 1;
  1222. }
  1223. entity.Update();
  1224. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1225. returnSuccessMsg("标记成功!");
  1226. return;
  1227. }
  1228. returnErrorMsg("找不到记录");
  1229. }
  1230. }
  1231. public void upd_erp_getmyorder()
  1232. {
  1233. if (UrlPostParmsCheck("ctid"))
  1234. {
  1235. ;
  1236. string eid = GetPostString("ctid");
  1237. CeErpTradeCell entity = null;
  1238. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1239. CeErpTrade father = CeErpTrade.Get(entity.tid);
  1240. if (father.receiver_state.Contains("台湾") && string.IsNullOrEmpty(father.receiver_zip))
  1241. {
  1242. returnErrorMsg("台湾客户需填写身份证号!");
  1243. return;
  1244. }
  1245. if (entity != null)
  1246. {
  1247. if (entity.ctid.IndexOf("C") != -1)
  1248. {
  1249. StringBuilder sql = new StringBuilder();
  1250. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1251. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1252. if (dt.Rows.Count > 0)
  1253. {
  1254. decimal total = 0;
  1255. foreach (DataRow dr in dt.Rows)
  1256. {
  1257. total += Convert.ToDecimal(dr["payment"]);
  1258. }
  1259. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1260. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1261. {
  1262. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1263. return;
  1264. }
  1265. }
  1266. }
  1267. if (entity.OrderState == -1)
  1268. {
  1269. returnErrorMsg("待审核订单无法领取!");
  1270. return;
  1271. }
  1272. entity.CustomerUserId = CurrentUser.UserID;
  1273. if (entity.OrderState < 2)
  1274. {
  1275. entity.OrderState = 2;
  1276. if (entity.ShopId != 0)
  1277. {
  1278. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1279. }
  1280. }
  1281. entity.UpdateTime = DateTime.Now;
  1282. entity.Update();
  1283. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1284. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  1285. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  1286. {
  1287. dataHelper.api_orderBack(entity.ctid, "0", "");
  1288. }
  1289. returnSuccessMsg("领单成功!");
  1290. return;
  1291. }
  1292. returnErrorMsg("找不到记录");
  1293. }
  1294. }
  1295. public void getmyorder_from_init()
  1296. {
  1297. if (UrlPostParmsCheck("ctid"))
  1298. {
  1299. string eid = GetPostString("ctid");
  1300. CeErpTradeCell entity = null;
  1301. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1302. if (entity != null)
  1303. {
  1304. string sellerMemo = GetPostString("sellerMemo");
  1305. if (sellerMemo.Length > 0)
  1306. {
  1307. entity.seller_memo = sellerMemo;
  1308. }
  1309. string oterhMemo = GetPostString("otherMemo");
  1310. if (oterhMemo.Length > 0)
  1311. {
  1312. entity.OtherMemo = oterhMemo;
  1313. }
  1314. int urg = GetPostInt("urgency");
  1315. entity.IsUrgency = (urg == 1 ? true : false);
  1316. int wechat = GetPostInt("wechat");
  1317. int command = GetPostInt("command");
  1318. if (wechat == 1)
  1319. {
  1320. entity.wechatTag = 1;
  1321. }
  1322. if (command == 1)
  1323. {
  1324. entity.wechatTag = 2;
  1325. }
  1326. string pPro = GetPostString("pprofession");
  1327. if (pPro.Length > 0)
  1328. {
  1329. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1330. string spro = GetPostString("profession");
  1331. if (spro.Length > 0)
  1332. {
  1333. entity.ProfessionId = Convert.ToInt32(spro);
  1334. }
  1335. }
  1336. string proId = GetPostString("productId");
  1337. if (proId.Length > 0)
  1338. {
  1339. entity.ProductId = Convert.ToInt32(proId);
  1340. }
  1341. entity.Material = GetPostString("material");
  1342. entity.Craft = GetPostString("craft");
  1343. entity.CustomerUserId = CurrentUser.UserID;
  1344. if (entity.OrderState < 2)
  1345. {
  1346. entity.OrderState = 2;
  1347. if (entity.ShopId != 0)
  1348. {
  1349. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1350. }
  1351. }
  1352. entity.Update();
  1353. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1354. returnSuccessMsg("领单成功!");
  1355. return;
  1356. }
  1357. returnErrorMsg("找不到记录");
  1358. }
  1359. }
  1360. public void upd_erp_setrelationorder()
  1361. {
  1362. if (UrlPostParmsCheck("ctid"))
  1363. {
  1364. ;
  1365. string eid = GetPostString("ctid");
  1366. string ftid = GetPostString("ftid");
  1367. CeErpTradeCell entity = null;
  1368. CeErpTradeCell fentity = null;
  1369. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1370. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1371. if (fentity == null)
  1372. {
  1373. returnErrorMsg("找不到关联的主订单");
  1374. return;
  1375. }
  1376. if (entity != null)
  1377. {
  1378. if (entity.OrderState >= 5)
  1379. {
  1380. returnErrorMsg("本单已经设计完成无法关联");
  1381. return;
  1382. }
  1383. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1384. {
  1385. returnErrorMsg("线下单续审核后才能关联!");
  1386. return;
  1387. }
  1388. entity.ptid = ftid;
  1389. entity.OrderState = fentity.OrderState;
  1390. //entity.status = fentity.status;
  1391. entity.CustomerUserId = fentity.CustomerUserId;
  1392. entity.DesignUserId = fentity.DesignUserId;
  1393. entity.seller_memo = "补差价单:" + ftid;
  1394. entity.IsSample = 2;
  1395. entity.Update();
  1396. ApiVo apiVo = new ApiVo();
  1397. apiVo.orderNumber = ftid;
  1398. apiVo.payment = entity.payment;
  1399. apiVo.actionName = "repairDesign";
  1400. designHelper.API_WorkCore(apiVo);//repairDesign
  1401. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1402. returnSuccessMsg("关联成功!");
  1403. return;
  1404. }
  1405. else
  1406. returnErrorMsg("找不到记录");
  1407. }
  1408. }
  1409. public void download_erp_neworder()
  1410. {
  1411. string seller = GetPostString("seller_nick");
  1412. string tid = GetPostString("tid");
  1413. if (seller.Length <= 0 || tid.Length <= 0)
  1414. {
  1415. returnErrorMsg("数据错误");
  1416. }
  1417. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1418. //{
  1419. // returnErrorMsg("找不到店铺Sessionkey");
  1420. //}
  1421. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1422. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1423. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1424. if (res.IndexOf("refOid") == -1)
  1425. {
  1426. returnErrorMsg("下载订单数据失败");
  1427. return;
  1428. }
  1429. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1430. returnSuccessMsg("下载完成");
  1431. //tmcHelper.createNewOrder(res);
  1432. //CeErpTrade entr = null;
  1433. //entr = CeErpTrade.Get(tid);
  1434. //if (entr != null)
  1435. //{
  1436. // returnSuccess("下载成功");
  1437. // //下载成功之后,Cell表生成对应的订单;
  1438. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1439. //}
  1440. //else
  1441. //{
  1442. // returnErrorMsg("下载失败或者创建订单失败");
  1443. //}
  1444. }
  1445. public void set_erp_atersale()
  1446. {
  1447. if (UrlPostParmsCheck("ctid"))
  1448. {
  1449. string eid = GetPostString("ctid");
  1450. string reason = GetPostString("AfterSaleReason");
  1451. CeErpTradeCell entity = null;
  1452. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1453. if (entity != null)
  1454. {
  1455. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1456. {
  1457. returnErrorMsg("此订单已经在售后");
  1458. return;
  1459. }
  1460. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1461. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1462. entity.AfterSaleTime = DateTime.Now;
  1463. entity.Update();
  1464. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1465. returnSuccessMsg("转售后成功!");
  1466. return;
  1467. }
  1468. returnErrorMsg("找不到记录");
  1469. }
  1470. }
  1471. public void set_erp_withdraw()
  1472. {
  1473. if (UrlPostParmsCheck("ctid"))
  1474. {
  1475. try
  1476. {
  1477. string eid = GetPostString("ctid");//商品id
  1478. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1479. CeWithdraw ceWithdrawSelect = null;
  1480. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1481. if (ceWithdrawSelect != null)
  1482. {
  1483. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1484. {
  1485. ceWithdrawSelect.status = -1;
  1486. ceWithdrawSelect.Update();
  1487. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1488. returnSuccessMsg("重新发起审核成功");
  1489. return;
  1490. }
  1491. else
  1492. {
  1493. returnSuccessMsg("请勿重复申请!");
  1494. return;
  1495. }
  1496. }
  1497. else
  1498. {
  1499. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1500. if (string.IsNullOrEmpty(CustomerUserId))
  1501. {
  1502. CustomerUserId = "-1";
  1503. }
  1504. int Userid = CurrentUser.UserID;//用户id
  1505. CeWithdraw ceWithdraw = new CeWithdraw();
  1506. ceWithdraw.tid = eid;
  1507. ceWithdraw.userid = Userid;
  1508. ceWithdraw.providerid = CustomerUserId;
  1509. ceWithdraw.status = 3;
  1510. ceWithdraw.creationtime = DateTime.Now;
  1511. ceWithdraw.Create();
  1512. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1513. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1514. return;
  1515. }
  1516. }
  1517. catch
  1518. {
  1519. returnErrorMsg("申请撤回订单失败");
  1520. return;
  1521. }
  1522. }
  1523. }
  1524. public void ins_erp_billinfo()
  1525. {
  1526. if (UrlPostParmsCheck("ctid"))
  1527. {
  1528. string eid = GetPostString("ctid");
  1529. CeErpTradeCell entity = null;
  1530. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1531. if (entity != null)
  1532. {
  1533. CeErpBill bill = CeErpBill.GetByTid(eid);
  1534. bool isHave = false;
  1535. if (bill != null)
  1536. {
  1537. isHave = true;
  1538. if (bill.state != 4)
  1539. {
  1540. returnErrorMsg("此单已经申请过发票了");
  1541. return;
  1542. }
  1543. }
  1544. if (entity.IsNeedBill == 0)
  1545. {
  1546. entity.IsNeedBill = 1;
  1547. }
  1548. entity.Update();
  1549. string errjson = "";
  1550. try
  1551. {
  1552. CeErpBill bill_entity = new CeErpBill();
  1553. bill_entity.tid = entity.tid;
  1554. bill_entity.title = GetPostString("title");
  1555. string taxstr = GetPostString("tax");
  1556. taxstr = taxstr.Replace(" ", "");
  1557. bill_entity.tax = taxstr;
  1558. bill_entity.bank = GetPostString("bank");
  1559. string bankacstr = GetPostString("bankac");
  1560. bankacstr = bankacstr.Replace(" ", "");
  1561. bill_entity.bankac = bankacstr;
  1562. bill_entity.address = GetPostString("address");
  1563. bill_entity.phone = GetPostString("phone");
  1564. bill_entity.price = GetPostString("price");
  1565. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1566. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1567. {
  1568. billCount += 1;
  1569. }
  1570. string prebill = "ltb";
  1571. for (int idx = 1; idx <= billCount; idx++)
  1572. {
  1573. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1574. string billoid = prebill + idx + dtstr;
  1575. bill_entity.billOrderId += billoid;
  1576. if (idx < billCount)
  1577. {
  1578. bill_entity.billOrderId += ",";
  1579. }
  1580. }
  1581. bill_entity.productId = GetPostInt("ProductName");
  1582. bill_entity.num = GetPostInt("num");
  1583. bill_entity.unit = GetPostString("unit");
  1584. bill_entity.type = GetPostString("type");
  1585. bill_entity.sendType = GetPostString("SendType");
  1586. bill_entity.email = GetPostString("email");
  1587. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1588. bill_entity.shopName = GetPostString("ShopName");
  1589. bill_entity.applymemo = GetPostString("applyMemo");
  1590. bill_entity.createTime = DateTime.Now;
  1591. bill_entity.state = 0;
  1592. bill_entity.userId = CurrentUser.UserID;
  1593. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1594. bill_entity.Create();
  1595. }
  1596. catch (Exception ex)
  1597. {
  1598. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1599. returnErrorMsg("创建发票出错!");
  1600. return;
  1601. }
  1602. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1603. returnSuccessMsg("发票申请成功!");
  1604. return;
  1605. }
  1606. returnErrorMsg("找不到记录");
  1607. }
  1608. }
  1609. public void ins_erp_neworder()
  1610. {
  1611. if (UrlPostParmsCheck("receiver_name"))
  1612. {
  1613. CeErpTrade entity = new CeErpTrade();
  1614. string plat_form = GetPostString("platform");
  1615. string preStr = "N_";
  1616. if (plat_form == "拼多多")
  1617. {
  1618. preStr = "P_";
  1619. }
  1620. else if (plat_form == "阿里巴巴")
  1621. {
  1622. preStr = "A_";
  1623. }
  1624. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1625. entity.seller_nick = GetPostString("seller_nick");
  1626. entity.buyer_nick = GetPostString("buyer_nick");
  1627. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1628. entity.total_fee = entity.payment;
  1629. entity.pay_time = DateTime.Now;
  1630. entity.status = "NOT_SHIPPED";
  1631. entity.receiver_name = GetPostString("receiver_name");
  1632. entity.receiver_mobile = GetPostString("receiver_mobile");
  1633. entity.receiver_state = GetPostString("receiver_state");
  1634. entity.receiver_city = GetPostString("receiver_city");
  1635. entity.receiver_district = GetPostString("receiver_district");
  1636. entity.receiver_address = GetPostString("receiver_address");
  1637. if (entity.receiver_state == "" || entity.receiver_city == "")
  1638. {
  1639. returnErrorMsg("收件地址不能为空");
  1640. return;
  1641. }
  1642. int shopId = 0;
  1643. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1644. if (nShop != null)
  1645. {
  1646. shopId = nShop.ID;
  1647. }
  1648. if (shopId != 34 && entity.payment == 0)
  1649. {
  1650. returnErrorMsg("公司自用的单金额才能为0");
  1651. return;
  1652. }
  1653. entity.Create();
  1654. CeErpTradeCell entitycell = new CeErpTradeCell();
  1655. entitycell.ctid = entity.tid;
  1656. entitycell.tid = entity.tid;
  1657. entitycell.ShopId = shopId;
  1658. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1659. entitycell.OrderState = 0;
  1660. entitycell.pay_time = entity.pay_time;
  1661. entitycell.IsOffLineOrder = 1;
  1662. entitycell.Create();
  1663. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1664. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1665. return;
  1666. }
  1667. }
  1668. public void ins_erp_neworder2()
  1669. {
  1670. if (UrlPostParmsCheck("receiver_name"))
  1671. {
  1672. //string plat_form = GetPostString("platform");
  1673. string preStr = "X_";
  1674. string memo = GetPostString("memo");
  1675. string productId = GetPostString("productId");
  1676. string primg = GetPostString("proofimg");
  1677. string sellerNick = GetPostString("seller_nick");
  1678. string addFrom = GetPostString("addfrom");
  1679. if (addFrom == "1")
  1680. {
  1681. preStr = "N_";
  1682. }
  1683. int shopId = 0;
  1684. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1685. if (nShop != null)
  1686. {
  1687. shopId = nShop.ID;
  1688. }
  1689. else
  1690. {
  1691. returnErrorMsg("找不到对应店铺");
  1692. return;
  1693. }
  1694. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1695. {
  1696. returnErrorMsg("必须上传付款凭证");
  1697. return;
  1698. }
  1699. CeErpTrade entity = new CeErpTrade();
  1700. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1701. entity.seller_nick = sellerNick;
  1702. entity.buyer_nick = GetPostString("buyer_nick");
  1703. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1704. entity.total_fee = entity.payment;
  1705. entity.pay_time = DateTime.Now;
  1706. entity.status = "NOT_SHIPPED";
  1707. entity.receiver_name = GetPostString("receiver_name");
  1708. entity.receiver_mobile = GetPostString("receiver_mobile");
  1709. entity.receiver_state = GetPostString("receiver_state");
  1710. entity.receiver_city = GetPostString("receiver_city");
  1711. entity.receiver_district = GetPostString("receiver_district");
  1712. entity.receiver_address = GetPostString("receiver_address");
  1713. entity.seller_memo = memo;
  1714. entity.orderFrom = 20;
  1715. entity.orderType = 15;
  1716. if (entity.receiver_state == "" || entity.receiver_city == "")
  1717. {
  1718. returnErrorMsg("收件地址不能为空");
  1719. return;
  1720. }
  1721. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1722. {
  1723. returnErrorMsg("公司自用的单金额才能为0");
  1724. return;
  1725. }
  1726. entity.Create();
  1727. string toWhere = GetPostString("towhere");
  1728. CeErpTradeCell entitycell = new CeErpTradeCell();
  1729. entitycell.ctid = entity.tid;
  1730. //唯一标识
  1731. entitycell.OrderSn = entity.tid;
  1732. string orderSn = dataHelper.getSaleOrderSn();
  1733. if (orderSn != "")
  1734. {
  1735. entitycell.OrderSn = orderSn;
  1736. }
  1737. entitycell.tid = entity.tid;
  1738. //if (preStr == "X_")
  1739. //{
  1740. entitycell.IsOffLineOrder = 1;
  1741. //}
  1742. entitycell.CustomerUserId = CurrentUser.UserID;
  1743. entitycell.PayProofImg = primg;
  1744. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1745. entitycell.ProductId = Convert.ToInt32(productId);
  1746. entitycell.ShopId = shopId;
  1747. entitycell.UpdateTime = DateTime.Now;
  1748. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1749. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1750. {
  1751. entitycell.IsXianHuo = 1;
  1752. }
  1753. entitycell.pay_time = entity.pay_time;
  1754. if (toWhere == "1")
  1755. {
  1756. entitycell.OrderState = 2;
  1757. }
  1758. else
  1759. {
  1760. entitycell.OrderState = 6;
  1761. entitycell.FinishPlaceTime = entitycell.pay_time;
  1762. }
  1763. if (shopId == 94)
  1764. {
  1765. entitycell.OrderState = 4;
  1766. entitycell.WaitDesignTime = entitycell.pay_time;
  1767. entitycell.StartDesignTime = entitycell.pay_time;
  1768. entitycell.DesignUserId = 218;
  1769. }
  1770. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1771. {
  1772. entitycell.OrderState = -1;//修改12-5
  1773. CeWithdraw ceWithdraw = new CeWithdraw();
  1774. ceWithdraw.tid = entity.tid;
  1775. ceWithdraw.providerid = "-1";
  1776. ceWithdraw.status = -1;
  1777. ceWithdraw.creationtime = DateTime.Now;
  1778. ceWithdraw.userid = 1337;
  1779. ceWithdraw.Create();
  1780. }
  1781. entitycell.Create();
  1782. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1783. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1784. {
  1785. addPlaceRegist(entitycell, CurrentUser.UserID);
  1786. }
  1787. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1788. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1789. return;
  1790. }
  1791. }
  1792. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1793. {
  1794. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1795. entity.PlactTime = tradecell.pay_time;
  1796. entity.AddUserId = userid;
  1797. entity.FileName = tradecell.seller_memo;
  1798. entity.Supplier = 24;
  1799. entity.CreateTime = DateTime.Now;
  1800. entity.Did = tradecell.ctid;
  1801. entity.tid = tradecell.tid;
  1802. entity.splitTag = tradecell.SplitTag;
  1803. entity.CurState = "未完成";
  1804. entity.Create();
  1805. }
  1806. public void get_erp_offlinelist()
  1807. {
  1808. DataStruct dStruct = GetPostStruct();
  1809. List<string> lw = new List<string>();
  1810. string tid = GetPostString("ctid");
  1811. string date1 = GetPostString("date1");
  1812. string date2 = GetPostString("date2");
  1813. if (tid.Length > 0 || date1.Length > 0)
  1814. {
  1815. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1816. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1817. if (dw.Length > 0) lw.Add(dw);
  1818. }
  1819. else
  1820. {
  1821. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1822. }
  1823. string shopname = GetPostString("shopname");
  1824. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1825. string buyernick = GetPostString("buyer_nick");
  1826. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1827. string customer = GetPostString("customer");
  1828. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1829. string design = GetPostString("design");
  1830. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1831. string orderState = GetPostString("orderState");
  1832. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1833. string address = GetPostString("address");
  1834. 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));
  1835. string sellermemo = GetPostString("seller_memo");
  1836. if (sellermemo.Length > 0)
  1837. {
  1838. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1839. }
  1840. string price1 = GetPostString("price1");
  1841. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1842. string price2 = GetPostString("price2");
  1843. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1844. //if (PKey != "admin")
  1845. //{
  1846. // string usershop = CurrentUser.User.pemShop;
  1847. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1848. //}
  1849. //if (ex_psize > 0)
  1850. //{
  1851. dStruct.Order = "pay_time desc";
  1852. //}
  1853. //else
  1854. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1855. lw.Add(string.Format("IsOffLineOrder=1"));
  1856. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1857. DataTable dt = null;
  1858. dt = WebCache.GetData("view_erptradecell", dStruct);
  1859. writeGridDataTableJson(dStruct.TotalCount, dt);
  1860. }
  1861. public void get_erp_returncashrecord()
  1862. {
  1863. DataStruct dStruct = GetPostStruct();
  1864. List<string> lw = new List<string>();
  1865. string tid = GetPostString("ctid");
  1866. if (tid.Length > 0)
  1867. {
  1868. lw.Add(string.Format("tid like '%{0}%'", tid));
  1869. dStruct.Order = "id desc";
  1870. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1871. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1872. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1873. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1874. return;
  1875. }
  1876. returnErrorMsg("id数据错误!");
  1877. }
  1878. public void ins_erp_returncashrecord()
  1879. {
  1880. if (UrlPostParmsCheck("tid"))
  1881. {
  1882. string tid = GetPostString("tid");
  1883. string retype = GetPostString("type");
  1884. StringBuilder sql = new StringBuilder();
  1885. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1886. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1887. if (dt.Rows.Count > 0)
  1888. {
  1889. returnErrorMsg("相同返现类型记录已存在");
  1890. return;
  1891. }
  1892. CeErpReturnCash entity = new CeErpReturnCash();
  1893. entity.tid = tid;
  1894. entity.seller_nick = GetPostString("seller_nick");
  1895. string pment = GetPostString("payment");
  1896. if (pment.Length > 0)
  1897. {
  1898. entity.payment = Convert.ToDouble(pment);
  1899. }
  1900. entity.buyer_nick = GetPostString("buyer_nick");
  1901. entity.cashstate = 0;
  1902. entity.rtype = retype;
  1903. string rPrice = GetPostString("returnprice");
  1904. if (rPrice.Length > 0)
  1905. {
  1906. entity.returnprice = Convert.ToDouble(rPrice);
  1907. }
  1908. entity.created = DateTime.Now;
  1909. entity.con = GetPostString("con");
  1910. entity.img = GetPostString("img");
  1911. entity.applyuserid = CurrentUser.UserID;
  1912. entity.Create();
  1913. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1914. returnSuccessMsg("操作成功!");
  1915. return;
  1916. }
  1917. }
  1918. public void set_erp_predelivery()
  1919. {
  1920. if (UrlPostParmsCheck("ctid"))
  1921. {
  1922. string eid = GetPostString("ctid");
  1923. CeErpTradeCell entity = null;
  1924. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1925. if (entity != null)
  1926. {
  1927. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1928. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1929. //{
  1930. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1931. // return;
  1932. //}
  1933. entity.IsPreDelivery = 1;
  1934. entity.Update();
  1935. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1936. returnSuccessMsg("预发货成功!");
  1937. return;
  1938. //string shop = GetPostString("seller_nick");
  1939. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1940. //string comName = GetPostString("comName");
  1941. //string comCode = GetPostString("comCode");
  1942. //string outSid = GetPostString("outSid");//运单号
  1943. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1944. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1945. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1946. //string apires = "";
  1947. //if (deliveryType == "虚拟发货")
  1948. //{
  1949. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1950. //}
  1951. //else
  1952. //{
  1953. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1954. //}
  1955. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1956. ////{
  1957. //if (apires.IndexOf("发货成功") != -1)
  1958. //{
  1959. // if (deliveryType != "虚拟发货")
  1960. // {
  1961. // //还要插入快递信息到 快递信息表
  1962. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1963. // exinfo.tid = eid;
  1964. // exinfo.out_sid = outSid;
  1965. // exinfo.company_code = comCode;
  1966. // exinfo.company_name = comName;
  1967. // exinfo.delivery_memo = deliveryMemo;
  1968. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1969. // exinfo.deliveryType = deliveryType;
  1970. // exinfo.Create();
  1971. // }
  1972. // returnSuccessMsg("发货成功!");
  1973. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1974. //}
  1975. //else
  1976. //{
  1977. // returnErrorMsg("淘宝发货失败!!");
  1978. //}
  1979. //return;
  1980. }
  1981. returnErrorMsg("找不到订单记录");
  1982. }
  1983. }
  1984. public void get_erp_unusuallist()
  1985. {
  1986. DataStruct dStruct = GetPostStruct();
  1987. List<string> lw = new List<string>();
  1988. string tid = GetPostString("ctid");
  1989. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1990. string shopname = GetPostString("shopname");
  1991. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1992. string buyernick = GetPostString("buyer_nick");
  1993. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1994. string ResponsibleMan = GetPostString("responsible");
  1995. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1996. string date1 = GetPostString("date1");
  1997. string date2 = GetPostString("date2");
  1998. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1999. if (dw.Length > 0) lw.Add(dw);
  2000. string price1 = GetPostString("price1");
  2001. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2002. string price2 = GetPostString("price2");
  2003. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2004. string orderState = GetPostString("orderState");
  2005. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2006. string sellermemo = GetPostString("seller_memo");
  2007. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2008. lw.Add(string.Format("UnusualTag > 0"));
  2009. lw.Add(string.Format("IsRefund<={0}", 1));
  2010. dStruct.Order = "pay_time desc";
  2011. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2012. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2013. writeGridDataTableJson(dStruct.TotalCount, dt);
  2014. }
  2015. public void set_erp_unusualtonomal()
  2016. {
  2017. if (UrlPostParmsCheck("ctid"))
  2018. {
  2019. string eid = GetPostString("ctid");
  2020. CeErpTradeCell entity = null;
  2021. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2022. if (entity != null)
  2023. {
  2024. entity.UnusualTag = -1;
  2025. entity.Update();
  2026. returnSuccessMsg("忽略成功!");
  2027. return;
  2028. }
  2029. returnErrorMsg("找不到记录");
  2030. }
  2031. }
  2032. public void ins_erp_unusualreason()
  2033. {
  2034. if (UrlPostParmsCheck("ctid"))
  2035. {
  2036. string eid = GetPostString("ctid");
  2037. CeErpTradeCell entity = null;
  2038. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2039. if (entity != null)
  2040. {
  2041. entity.MemoOpt = 4;
  2042. entity.UnusualCon = GetPostString("con");
  2043. entity.Update();
  2044. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2045. if (trade != null)
  2046. {
  2047. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2048. }
  2049. //查货是否超时
  2050. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2051. if (ceErpTradeCellExtend == null)
  2052. {
  2053. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2054. ceErpTradeCellExtend.ctid = entity.ctid;
  2055. }
  2056. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2057. {
  2058. ceErpTradeCellExtend.CheckOut += 1;
  2059. }
  2060. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2061. if (ceErpTradeCellExtend.ID > 0)
  2062. {
  2063. ceErpTradeCellExtend.Update();
  2064. }
  2065. else
  2066. {
  2067. ceErpTradeCellExtend.Create();
  2068. }
  2069. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2070. returnSuccessMsg("操作成功!");
  2071. return;
  2072. }
  2073. returnErrorMsg("找不到记录");
  2074. }
  2075. }
  2076. public void upd_erp_sampleorder()
  2077. {
  2078. if (UrlPostParmsCheck("ctid"))
  2079. {
  2080. string eid = GetPostString("ctid");
  2081. string[] eArr = eid.Split(',');
  2082. if (eArr.Length > 1)
  2083. {
  2084. List<string> eLst = new List<string>();
  2085. for (int i = 0; i < eArr.Length; i++)
  2086. {
  2087. eLst.Add("'" + eArr[i] + "'");
  2088. }
  2089. eid = string.Join(",", eLst.ToArray());
  2090. }
  2091. else
  2092. {
  2093. eid = "'" + eid + "'";
  2094. }
  2095. StringBuilder sql = new StringBuilder();
  2096. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2097. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2098. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2099. if (dt.Rows.Count > 0)
  2100. {
  2101. string errmsg = "";
  2102. foreach (DataRow dr in dt.Rows)
  2103. {
  2104. StringBuilder sqlsb = new StringBuilder();
  2105. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2106. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2107. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2108. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2109. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2110. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2111. {
  2112. continue;
  2113. }
  2114. else
  2115. {
  2116. string emsg = commonHelper.KeepChinese(apires);
  2117. errmsg += emsg;
  2118. }
  2119. }
  2120. if (errmsg.Length > 0)
  2121. {
  2122. returnErrorMsg(errmsg);
  2123. return;
  2124. }
  2125. returnSuccessMsg("操作成功");
  2126. return;
  2127. }
  2128. returnErrorMsg("找不到记录");
  2129. }
  2130. }
  2131. public void upd_erp_transcustomer()
  2132. {
  2133. if (UrlPostParmsCheck("ctid"))
  2134. {
  2135. string eid = GetPostString("ctid");
  2136. int userid = GetPostInt("CustomerUserId");
  2137. CeErpTradeCell entity = null;
  2138. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2139. if (entity != null)
  2140. {
  2141. //string[] mlist = entity.seller_memo.Split('-');
  2142. //string sql = "select * from view_erpuser where id=" + userid;
  2143. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2144. //if (dt != null && dt.Rows.Count > 0)
  2145. //{
  2146. // string nmemo = "";
  2147. // for(int i = 0; i < mlist.Length - 1; i++)
  2148. // {
  2149. // nmemo += mlist[i];
  2150. // nmemo += "-";
  2151. // }
  2152. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2153. // entity.seller_memo = nmemo;
  2154. //}
  2155. entity.CustomerUserId = userid;
  2156. entity.Update();
  2157. returnSuccessMsg("操作成功!");
  2158. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2159. return;
  2160. }
  2161. returnErrorMsg("找不到记录");
  2162. }
  2163. }
  2164. public void upd_erp_transdesigner()
  2165. {
  2166. if (UrlPostParmsCheck("ctid"))
  2167. {
  2168. string eids = GetPostString("ctid");
  2169. string[] ctidList = eids.Split(',');
  2170. int userid = GetPostInt("DesignUserId");
  2171. foreach (string ctid in ctidList)
  2172. {
  2173. CeErpTradeCell entity = null;
  2174. CeErpDesignerBill entitys = null;
  2175. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2176. entitys = CeErpDesignerBill.GetByTid(ctid);
  2177. if (entity != null)
  2178. {
  2179. if (entity.OrderState > 4)
  2180. {
  2181. continue;
  2182. }
  2183. //存在退款不能流转
  2184. if (entity.IsRefund > 0)
  2185. {
  2186. continue;
  2187. }
  2188. entity.DesignUserId = userid;
  2189. entity.WaitDesignTime = DateTime.Now;
  2190. entity.Update();
  2191. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2192. }
  2193. }
  2194. returnSuccessMsg("操作成功!");
  2195. }
  2196. }
  2197. public void upd_erp_distributedesigner()
  2198. {
  2199. if (UrlPostParmsCheck("ctid"))
  2200. {
  2201. string eid = GetPostString("ctid");
  2202. int userid = GetPostInt("DesignUserId");
  2203. string[] idlist = eid.Split(',');
  2204. if (idlist.Length <= 0)
  2205. {
  2206. returnErrorMsg("订单不能为空");
  2207. return;
  2208. }
  2209. foreach (string ctid in idlist)
  2210. {
  2211. CeErpTradeCell entity = null;
  2212. CeErpDesignerBill entitys = null;
  2213. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2214. else continue;
  2215. if (entity != null)
  2216. {
  2217. if (userid == 2125 || userid == 3542)
  2218. { }
  2219. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2220. {
  2221. returnErrorMsg("金额错误的订单无法指派");
  2222. return;
  2223. }
  2224. if (entity.OrderState >= 5)
  2225. {
  2226. returnErrorMsg("已经设计完成无法指派");
  2227. return;
  2228. }
  2229. if (entity.OrderState == -1)
  2230. {
  2231. returnErrorMsg("审核中的订单无法指派");
  2232. return;
  2233. }
  2234. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2235. {
  2236. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2237. return;
  2238. }
  2239. //157赖橙帆 159林晨 73 静之颖
  2240. 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)
  2241. {
  2242. returnErrorMsg("指派设计共创无法再次指派!");
  2243. return;
  2244. }
  2245. entity.OrderState = 3;
  2246. if (entity.SupplierId == 0)
  2247. {
  2248. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2249. entity.SupplierId = suid;
  2250. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2251. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2252. }
  2253. if (userid == 2125 && entity.seller_memo != "")
  2254. {
  2255. apiDesign.API_GetPrintData_CreateOrder(entity);
  2256. }
  2257. if (userid == 3542 && entity.seller_memo != "")
  2258. {
  2259. string userPost = CurrentUser.UserPost.Post.Code;
  2260. if (CurrentUser.UserID == 73)
  2261. {
  2262. userPost = "SysAdmin";
  2263. }
  2264. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2265. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2266. if (response.msg != "设计共创:成功")
  2267. {
  2268. returnErrorMsg(response.msg);
  2269. return;
  2270. }
  2271. entity.DispatchSort = 2;
  2272. }
  2273. else
  2274. {
  2275. if (entity.DispatchSort == 2)
  2276. {
  2277. ApiVo apiVo = new ApiVo();
  2278. apiVo.actionName = "closeDesign";
  2279. apiVo.orderNumber = entity.ctid;
  2280. designHelper.API_WorkCore(apiVo);//closeDesign
  2281. }
  2282. entity.DispatchSort = 0;
  2283. }
  2284. entity.DesignUserId = userid;
  2285. entity.WaitDesignTime = DateTime.Now;
  2286. entity.UpdateTime = DateTime.Now;
  2287. entity.Update();
  2288. string name = commonHelper.getUserNameById(userid);
  2289. commonHelper.UpdateRelationOrder(entity.ctid);
  2290. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2291. }
  2292. }
  2293. returnSuccessMsg("操作成功!");
  2294. return;
  2295. }
  2296. }
  2297. public string getTidByCtid(string ctid)
  2298. {
  2299. string tid = "";
  2300. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2301. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2302. if (dataTable != null && dataTable.Rows.Count > 0)
  2303. {
  2304. tid = dataTable.Rows[0]["tid"].ToString();
  2305. }
  2306. return tid;
  2307. }
  2308. public List<string> getTidByCtidMore(string ctid)
  2309. {
  2310. 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);
  2311. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2312. List<string> list = new List<string>();
  2313. if (dataTable != null && dataTable.Rows.Count > 0)
  2314. {
  2315. foreach (DataRow item in dataTable.Rows)
  2316. {
  2317. list.Add("'" + item["tid"].ToString() + "'");
  2318. }
  2319. }
  2320. return list;
  2321. }
  2322. public List<string> getTidByCtidLike(string ctid)
  2323. {
  2324. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid = '{0}' or orderSn = '{0}')", ctid);
  2325. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2326. List<string> list = new List<string>();
  2327. if (dataTable != null && dataTable.Rows.Count > 0)
  2328. {
  2329. foreach (DataRow item in dataTable.Rows)
  2330. {
  2331. list.Add("'" + item["tid"].ToString() + "'");
  2332. }
  2333. }
  2334. return list;
  2335. }
  2336. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2337. {
  2338. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2339. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2340. List<string> list = new List<string>();
  2341. if (dataTable != null && dataTable.Rows.Count > 0)
  2342. {
  2343. foreach (DataRow item in dataTable.Rows)
  2344. {
  2345. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2346. {
  2347. continue;
  2348. }
  2349. list.Add("'" + item["receiverId"].ToString() + "'");
  2350. }
  2351. }
  2352. return list;
  2353. }
  2354. public void get_erp_myorderlist()
  2355. {
  2356. DataStruct dStruct = GetPostStruct();
  2357. List<string> lw = new List<string>();
  2358. string tid = GetPostString("ctid");
  2359. if (tid.Length > 0)
  2360. {
  2361. string select_tid = getTidByCtid(tid);
  2362. lw.Add(string.Format("tid='{0}'", select_tid));
  2363. }
  2364. else
  2365. {
  2366. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2367. }
  2368. //12-1 修改
  2369. string urgent = GetPostString("urgent");
  2370. string back = GetPostString("back");
  2371. string offlineSearch = GetPostString("offlineSearch");
  2372. if (!string.IsNullOrWhiteSpace(urgent))
  2373. {
  2374. if (urgent.Equals("true"))
  2375. {
  2376. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2377. }
  2378. }
  2379. if (!string.IsNullOrWhiteSpace(back))
  2380. {
  2381. if (back.Equals("true"))
  2382. {
  2383. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2384. }
  2385. }
  2386. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2387. {
  2388. if (offlineSearch.Equals("true"))
  2389. {
  2390. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2391. }
  2392. }
  2393. //end
  2394. string shopname = GetPostString("shopname");
  2395. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2396. string buyernick = GetPostString("buyer_nick");
  2397. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2398. string design = GetPostString("design");
  2399. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2400. string orderState = GetPostString("orderState");
  2401. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2402. string sellermemo = GetPostString("seller_memo");
  2403. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2404. string date1 = GetPostString("date1");
  2405. string date2 = GetPostString("date2");
  2406. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2407. if (dw.Length > 0) lw.Add(dw);
  2408. string price1 = GetPostString("price1");
  2409. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2410. string price2 = GetPostString("price2");
  2411. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2412. string urgency = GetPostString("urgency");
  2413. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2414. string after = GetPostString("after");
  2415. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2416. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2417. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2418. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2419. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2420. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2421. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2422. if (dt != null && dt.Rows.Count > 0)
  2423. {
  2424. foreach (DataRow dr in dt.Rows)
  2425. {
  2426. try
  2427. {
  2428. // 对象操作
  2429. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2430. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2431. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2432. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2433. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2434. if (dStruct.PageSize != 100000)
  2435. {
  2436. if (dr["DispatchSort"].ToString() == "2")
  2437. {
  2438. dr["gongchuang"] = 200;
  2439. }
  2440. else if ("外协".Equals(dr["ToType"].ToString()))
  2441. {
  2442. dr["gongchuang"] = 200;
  2443. }
  2444. else if ("内部".Equals(dr["ToType"].ToString()))
  2445. {
  2446. dr["gongchuang"] = -1;
  2447. }
  2448. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2449. {
  2450. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2451. dr["gongchuang"] = response.code;
  2452. }
  2453. }
  2454. }
  2455. catch (NullReferenceException ex)
  2456. {
  2457. }
  2458. }
  2459. }
  2460. writeGridDataTableJson(dStruct.TotalCount, dt);
  2461. }
  2462. public void get_erp_myreturnorderlist()
  2463. {
  2464. DataStruct dStruct = GetPostStruct();
  2465. List<string> lw = new List<string>();
  2466. string tid = GetPostString("ctid");
  2467. if (tid.Length > 0)
  2468. {
  2469. string select_tid = getTidByCtid(tid);
  2470. lw.Add(string.Format("tid='{0}'", select_tid));
  2471. }
  2472. else
  2473. {
  2474. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2475. }
  2476. string shopname = GetPostString("shopname");
  2477. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2478. string buyernick = GetPostString("buyer_nick");
  2479. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2480. string design = GetPostString("design");
  2481. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2482. string orderState = GetPostString("orderState");
  2483. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2484. string sellermemo = GetPostString("seller_memo");
  2485. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2486. string date1 = GetPostString("date1");
  2487. string date2 = GetPostString("date2");
  2488. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2489. if (dw.Length > 0) lw.Add(dw);
  2490. string price1 = GetPostString("price1");
  2491. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2492. string price2 = GetPostString("price2");
  2493. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2494. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  2495. {
  2496. lw.Add(string.Format("CusOrgID = 94"));
  2497. }
  2498. else if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2499. {
  2500. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2501. }
  2502. else
  2503. {
  2504. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2505. }
  2506. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2507. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2508. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2509. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2510. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2511. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2512. if (dt != null && dt.Rows.Count > 0)
  2513. {
  2514. foreach (DataRow dr in dt.Rows)
  2515. {
  2516. try
  2517. {
  2518. // 对象操作
  2519. if (dStruct.PageSize != 100000)
  2520. {
  2521. if (dr["DispatchSort"].ToString() == "2")
  2522. {
  2523. dr["gongchuang"] = 200;
  2524. }
  2525. else if ("外协".Equals(dr["ToType"].ToString()))
  2526. {
  2527. dr["gongchuang"] = 200;
  2528. }
  2529. else if ("内部".Equals(dr["ToType"].ToString()))
  2530. {
  2531. dr["gongchuang"] = -1;
  2532. }
  2533. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2534. {
  2535. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2536. dr["gongchuang"] = response.code;
  2537. }
  2538. }
  2539. }
  2540. catch (NullReferenceException ex)
  2541. {
  2542. // 处理空引用异常
  2543. }
  2544. }
  2545. }
  2546. writeGridDataTableJson(dStruct.TotalCount, dt);
  2547. }
  2548. public void get_erp_myorderlist_pregather()
  2549. {
  2550. string date1 = GetPostString("date1");
  2551. string date2 = GetPostString("date2");
  2552. int userId = CurrentUser.UserID; //客服id
  2553. string orderWhere = "";
  2554. List<string> lw = new List<string>();
  2555. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2556. if (dw.Length > 0) lw.Add(dw);
  2557. lw.Add(string.Format("CustomerUserId={0}", userId));
  2558. lw.Add(string.Format("OrderState<9"));
  2559. orderWhere = string.Join(" and ", lw.ToArray());
  2560. string orderWhere2 = "";
  2561. List<string> lw2 = new List<string>();
  2562. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2563. if (dw2.Length > 0) lw2.Add(dw2);
  2564. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2565. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2566. string sql = string.Format("select *" +
  2567. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2568. "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 " +
  2569. "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 " +
  2570. "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");
  2571. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2572. //writeGridDataTableJson(dt.Rows.Count, dt);
  2573. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2574. }
  2575. public void upd_erp_publishorder()
  2576. {
  2577. if (UrlPostParmsCheck("ctid"))
  2578. {
  2579. string eid = GetPostString("ctid");
  2580. CeErpTradeCell entity = null;
  2581. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2582. if (entity != null)
  2583. {
  2584. entity.OrderState = 0; //发布后,变为待抢单
  2585. entity.Update();
  2586. commonHelper.UpdateRelationOrder(entity.ctid);
  2587. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2588. returnSuccessMsg("发布成功!");
  2589. return;
  2590. }
  2591. returnErrorMsg("找不到记录");
  2592. }
  2593. }
  2594. public void get_erp_my_tiporder()
  2595. {
  2596. StringBuilder sql = new StringBuilder();
  2597. int userId = 0;
  2598. if (CurrentUser != null) userId = CurrentUser.UserID;
  2599. string posCode = CurrentUser.UserPost.Post.Code;
  2600. string isTipedAfterSaleVerify = GetPostString("af");
  2601. DataTable dt = new DataTable();
  2602. if (posCode != "Supplier")
  2603. {
  2604. if (posCode == "CustomerService" || posCode == "Director")
  2605. {
  2606. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2607. }
  2608. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2609. {
  2610. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2611. }
  2612. else
  2613. {
  2614. string teamIds = CurrentUser.User.TeamIds;
  2615. if (teamIds == "")
  2616. {
  2617. teamIds = "0";
  2618. }
  2619. 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);
  2620. }
  2621. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2622. }
  2623. if (dt.Rows.Count <= 0)
  2624. {
  2625. string key = "aftersale_order_" + userId;
  2626. if (RedisHelper.HasKey(key))
  2627. {
  2628. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2629. dt.Columns.Add("ctid", typeof(string));
  2630. dt.Columns.Add("IsReadTag", typeof(int));
  2631. foreach (var i in list)
  2632. {
  2633. DataRow data = dt.NewRow();
  2634. data["ctid"] = i;
  2635. data["IsReadTag"] = 4;
  2636. dt.Rows.Add(data);
  2637. }
  2638. RedisHelper.StringDelete(key);
  2639. }
  2640. }
  2641. if (dt.Rows.Count <= 0)
  2642. {
  2643. sql = new StringBuilder();
  2644. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2645. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2646. }
  2647. if (posCode == "Supplier")
  2648. {
  2649. string ids = CurrentUser.User.pemVend;
  2650. if (ids != null && ids.Length > 0)
  2651. {
  2652. string[] ids_list = ids.Split(',');
  2653. foreach (var item in ids_list)
  2654. {
  2655. string key = "return_order_" + item;
  2656. if (RedisHelper.HasKey(key))
  2657. {
  2658. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2659. dt.Columns.Add("ctid", typeof(string));
  2660. dt.Columns.Add("IsReadTag", typeof(int));
  2661. foreach (var i in list)
  2662. {
  2663. DataRow data = dt.NewRow();
  2664. data["ctid"] = i;
  2665. data["IsReadTag"] = 1;
  2666. dt.Rows.Add(data);
  2667. }
  2668. RedisHelper.StringDelete(key);
  2669. }
  2670. }
  2671. }
  2672. if (dt.Rows.Count <= 0)
  2673. {
  2674. sql = new StringBuilder();
  2675. 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);
  2676. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2677. }
  2678. }
  2679. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2680. }
  2681. public void reset_erp_tiporder()
  2682. {
  2683. string ids = GetPostString("ids");
  2684. string[] ctidList = ids.Split(',');
  2685. foreach (string ctid in ctidList)
  2686. {
  2687. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2688. if (enty != null)
  2689. {
  2690. enty.IsReadTag = 0;
  2691. enty.Update();
  2692. }
  2693. }
  2694. returnSuccessMsg("成功!");
  2695. return;
  2696. }
  2697. public void get_erp_designlist()
  2698. {
  2699. DataStruct dStruct = GetPostStruct();
  2700. List<string> lw = new List<string>();
  2701. string tid = GetPostString("ctid");
  2702. if (tid.Length > 0)
  2703. {
  2704. string select_tid = getTidByCtid(tid);
  2705. lw.Add(string.Format("tid='{0}'", select_tid));
  2706. }
  2707. string shopname = GetPostString("shopname");
  2708. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2709. string buyernick = GetPostString("buyer_nick");
  2710. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2711. string customer = GetPostString("customer");
  2712. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2713. string design = GetPostString("design");
  2714. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2715. string orderState = GetPostString("orderState");
  2716. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2717. lw.Add(string.Format("OrderState<6"));
  2718. string address = GetPostString("address");
  2719. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2720. string sellermemo = GetPostString("seller_memo");
  2721. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2722. string date1 = GetPostString("date1");
  2723. string date2 = GetPostString("date2");
  2724. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2725. if (dw.Length > 0) lw.Add(dw);
  2726. string apdate1 = GetPostString("apdate1");
  2727. string apdate2 = GetPostString("apdate2");
  2728. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2729. if (dwap.Length > 0) lw.Add(dwap);
  2730. string price1 = GetPostString("price1");
  2731. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2732. string price2 = GetPostString("price2");
  2733. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2734. string designTime = GetPostString("designtime");
  2735. if (designTime.Length > 0)
  2736. {
  2737. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2738. }
  2739. string usershop = CurrentUser.User.pemShop;
  2740. if (usershop.Length > 0)
  2741. {
  2742. lw.Add(string.Format("shopId in ({0})", usershop));
  2743. }
  2744. int myOrgid = CurrentUser.UserPost.OrgID;
  2745. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2746. if (myOrgCode.IndexOf("Designer") != -1)
  2747. {
  2748. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2749. {
  2750. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2751. }
  2752. else
  2753. {
  2754. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2755. }
  2756. }
  2757. else
  2758. {
  2759. string orgId = GetPostString("designerhd");
  2760. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2761. }
  2762. if (tid.Length > 0 || buyernick.Length > 0)
  2763. {
  2764. lw.Add(string.Format("OrderState >= 3"));
  2765. }
  2766. else
  2767. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2768. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2769. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2770. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2771. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2772. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2773. if (dt != null && dt.Rows.Count > 0)
  2774. {
  2775. foreach (DataRow dr in dt.Rows)
  2776. {
  2777. try
  2778. {
  2779. // 对象操作
  2780. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2781. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2782. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2783. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2784. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2785. if (dStruct.PageSize != 100000)
  2786. {
  2787. if (dr["DispatchSort"].ToString() == "2")
  2788. {
  2789. dr["gongchuang"] = 200;
  2790. }
  2791. else if ("外协".Equals(dr["ToType"].ToString()))
  2792. {
  2793. dr["gongchuang"] = 200;
  2794. }
  2795. else if ("内部".Equals(dr["ToType"].ToString()))
  2796. {
  2797. dr["gongchuang"] = -1;
  2798. }
  2799. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2800. {
  2801. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2802. dr["gongchuang"] = response.code;
  2803. }
  2804. }
  2805. }
  2806. catch (NullReferenceException ex)
  2807. {
  2808. }
  2809. }
  2810. }
  2811. writeGridDataTableJson(dStruct.TotalCount, dt);
  2812. }
  2813. public void get_erp_mydesignlist()
  2814. {
  2815. DataStruct dStruct = GetPostStruct();
  2816. List<string> lw = new List<string>();
  2817. string tid = GetPostString("ctid");
  2818. if (tid.Length > 0)
  2819. {
  2820. string select_tid = getTidByCtid(tid);
  2821. lw.Add(string.Format("tid='{0}'", select_tid));
  2822. }
  2823. string shopname = GetPostString("shopname");
  2824. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2825. string buyernick = GetPostString("buyer_nick");
  2826. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2827. string customer = GetPostString("customer");
  2828. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2829. string orderState = GetPostString("orderState");
  2830. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2831. //lw.Add(string.Format("OrderState<6"));
  2832. string date1 = GetPostString("date1");
  2833. string date2 = GetPostString("date2");
  2834. string dw = GetDateWhere("pay_time", date1, date2);
  2835. if (dw.Length > 0) lw.Add(dw);
  2836. string apdate1 = GetPostString("apdate1");
  2837. string apdate2 = GetPostString("apdate2");
  2838. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2839. if (dwap.Length > 0) lw.Add(dwap);
  2840. string price1 = GetPostString("price1");
  2841. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2842. string price2 = GetPostString("price2");
  2843. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2844. string olddownload = GetPostString("olddown");
  2845. if (olddownload == "1")
  2846. {
  2847. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2848. }
  2849. else if (olddownload == "2")
  2850. {
  2851. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2852. }
  2853. string sellermemo = GetPostString("seller_memo");
  2854. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2855. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2856. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2857. {
  2858. if (CurrentUser.User.TeamIds.Length > 0)
  2859. {
  2860. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2861. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2862. else
  2863. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2864. }
  2865. else
  2866. {
  2867. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2868. }
  2869. }
  2870. if (tid.Length <= 0)
  2871. {
  2872. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2873. }
  2874. lw.Add(string.Format("IsReturn!=3"));
  2875. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2876. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2877. string teamids = CurrentUser.User.TeamIds.ToString();
  2878. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2879. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2880. if (dt != null && dt.Rows.Count > 0)
  2881. {
  2882. foreach (DataRow dr in dt.Rows)
  2883. {
  2884. try
  2885. {
  2886. // 对象操作
  2887. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2888. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2889. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2890. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2891. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2892. if (dStruct.PageSize != 100000)
  2893. {
  2894. if (dr["DispatchSort"].ToString() == "2")
  2895. {
  2896. dr["gongchuang"] = 200;
  2897. }
  2898. else if ("外协".Equals(dr["ToType"].ToString()))
  2899. {
  2900. dr["gongchuang"] = 200;
  2901. }
  2902. else if ("内部".Equals(dr["ToType"].ToString()))
  2903. {
  2904. dr["gongchuang"] = -1;
  2905. }
  2906. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2907. {
  2908. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2909. dr["gongchuang"] = response.code;
  2910. }
  2911. }
  2912. }
  2913. catch (NullReferenceException ex)
  2914. {
  2915. }
  2916. }
  2917. }
  2918. writeGridDataTableJson(dStruct.TotalCount, dt);
  2919. }
  2920. public void set_erp_startdesign()
  2921. {
  2922. if (UrlPostParmsCheck("ctid"))
  2923. {
  2924. string eid = GetPostString("ctid");
  2925. CeErpTradeCell entity = null;
  2926. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2927. if (entity != null)
  2928. {
  2929. if (entity.OrderState != 3)
  2930. {
  2931. returnErrorMsg("请刷新,订单已经设计了");
  2932. return;
  2933. }
  2934. entity.StartDesignTime = DateTime.Now;
  2935. entity.OrderState = 4;
  2936. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2937. {
  2938. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2939. entity.SupplierId = suid;
  2940. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2941. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2942. }
  2943. entity.UpdateTime = DateTime.Now;
  2944. //entity.MakeSupplier = suname;
  2945. entity.Update();
  2946. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2947. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2948. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2949. commonHelper.getCytPrice(entity);
  2950. returnSuccessMsg("操作成功!");
  2951. return;
  2952. }
  2953. returnErrorMsg("找不到记录");
  2954. }
  2955. }
  2956. public void ins_erp_designselfmemo()
  2957. {
  2958. if (UrlPostParmsCheck("ctid"))
  2959. {
  2960. string eid = GetPostString("ctid");
  2961. string con = GetPostString("con");
  2962. CeErpTradeCell entity = null;
  2963. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2964. if (entity != null)
  2965. {
  2966. entity.DesignSelfMemo = con;
  2967. entity.Update();
  2968. returnSuccessMsg("操作成功!");
  2969. return;
  2970. }
  2971. returnErrorMsg("找不到记录");
  2972. }
  2973. }
  2974. public void ins_erp_designprice()
  2975. {
  2976. if (UrlPostParmsCheck("ctid"))
  2977. {
  2978. string eid = GetPostString("ctid");
  2979. int uid = CurrentUser.UserID;
  2980. string userName = CurrentUser.UserName;
  2981. CeErpTradeCell entity = null;
  2982. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2983. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2984. if (entitys == null)
  2985. {
  2986. entitys = new CeErpDesignerBill();
  2987. }
  2988. if (entity != null)
  2989. {
  2990. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2991. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2992. entity.StartDesignTime = DateTime.Now;
  2993. entity.OrderState = 4;
  2994. string suname = "";
  2995. if (entity.SupplierId == 0)
  2996. {
  2997. int sid = commonHelper.autoDistributeToSupplier(entity);
  2998. entity.SupplierId = sid;
  2999. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3000. }
  3001. entity.Update();
  3002. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  3003. if (ceErpUserPost != null)
  3004. {
  3005. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  3006. if (ceErpPost != null)
  3007. {
  3008. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  3009. {
  3010. entitys.tid = entity.ctid;
  3011. entitys.oid = entity.tid;
  3012. entitys.uid = uid;
  3013. entitys.userName = userName;
  3014. entitys.designerType = 1;
  3015. entitys.designerTypeText = "内部设计师";
  3016. entitys.price = Convert.ToDouble(GetPostString("price"));
  3017. entitys.designNum = GetPostInt("designNum");
  3018. entitys.modifyNum = GetPostInt("modifyNum");
  3019. entitys.designSize = GetPostString("designSize");
  3020. entitys.modifySize = GetPostString("modifySize");
  3021. if (CeErpDesignerBill.GetByTid("ctid") == null)
  3022. {
  3023. entitys.create_time = DateTime.Now;
  3024. entitys.create_u_id = uid;
  3025. entitys.create_u_name = userName;
  3026. entitys.Save();
  3027. }
  3028. else
  3029. {
  3030. entitys.update_time = DateTime.Now;
  3031. entitys.update_u_id = uid;
  3032. entitys.update_u_name = userName;
  3033. entitys.Update();
  3034. }
  3035. }
  3036. }
  3037. }
  3038. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  3039. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  3040. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  3041. if (suname != "")
  3042. {
  3043. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3044. }
  3045. commonHelper.getCytPrice(entity);
  3046. returnSuccessMsg("操作成功!");
  3047. return;
  3048. }
  3049. returnErrorMsg("找不到记录");
  3050. }
  3051. }
  3052. public void upload_erp_filecomplete()
  3053. {
  3054. if (UrlPostParmsCheck("ctid"))
  3055. {
  3056. string eid = GetPostString("ctid");
  3057. CeErpTradeCell entity = null;
  3058. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3059. if (entity != null)
  3060. {
  3061. entity.OrderState = 5; //设计完成
  3062. entity.Update();
  3063. returnSuccessMsg(eid + "上传成功,设计完成!");
  3064. return;
  3065. }
  3066. returnErrorMsg("找不到订单记录");
  3067. }
  3068. }
  3069. public void get_erp_designovertimelist()
  3070. {
  3071. DataStruct dStruct = GetPostStruct();
  3072. List<string> lw = new List<string>();
  3073. string tid = GetPostString("ctid");
  3074. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3075. string shopname = GetPostString("shopname");
  3076. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3077. string buyernick = GetPostString("buyer_nick");
  3078. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3079. string ResponsibleMan = GetPostString("responsible");
  3080. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3081. string date1 = GetPostString("date1");
  3082. string date2 = GetPostString("date2");
  3083. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3084. if (dw.Length > 0) lw.Add(dw);
  3085. string price1 = GetPostString("price1");
  3086. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3087. string price2 = GetPostString("price2");
  3088. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3089. string orderState = GetPostString("orderState");
  3090. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3091. string sellermemo = GetPostString("seller_memo");
  3092. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3093. lw.Add(string.Format("UnusualTag=3"));
  3094. lw.Add(string.Format("IsRefund<={0}", 1));
  3095. dStruct.Order = "WaitDesignTime desc";
  3096. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3097. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3098. writeGridDataTableJson(dStruct.TotalCount, dt);
  3099. }
  3100. //设计管理 获取抢单大厅列表
  3101. public void get_erp_grabinglist()
  3102. {
  3103. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3104. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3105. bool oldOrder = false;
  3106. if (org != null)
  3107. {
  3108. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3109. }
  3110. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3111. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3112. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3113. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3114. //先处理订单数据
  3115. if (dt.Rows.Count > 0)
  3116. {
  3117. Dictionary<string, int> design = null;
  3118. int count = 0;
  3119. foreach (DataRow row in dt.Rows)
  3120. {
  3121. if (map.ContainsKey(row["ShopId"].ToString()))
  3122. {
  3123. map.TryGetValue(row["ShopId"].ToString(), out design);
  3124. }
  3125. else
  3126. {
  3127. design = new Dictionary<string, int>();
  3128. }
  3129. if (design.ContainsKey(row["ProductId"].ToString()))
  3130. {
  3131. design.TryGetValue(row["ProductId"].ToString(), out count);
  3132. }
  3133. count++;
  3134. design[row["ProductId"].ToString()] = count;
  3135. map[row["ShopId"].ToString()] = design;
  3136. }
  3137. }
  3138. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3139. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3140. //把店铺排序和技能排序分类
  3141. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3142. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3143. if (design_dt.Rows.Count > 0)
  3144. {
  3145. Dictionary<string, string> design = null;
  3146. List<string> shopIds = null;
  3147. foreach (DataRow row in design_dt.Rows)
  3148. {
  3149. if ("0".Equals(row["designId"].ToString()))
  3150. {
  3151. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3152. {
  3153. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3154. }
  3155. else
  3156. {
  3157. shopIds = new List<string>();
  3158. }
  3159. shopIds.Add(row["shopId"].ToString());
  3160. shop_orders[row["orders"].ToString()] = shopIds;
  3161. }
  3162. else
  3163. {
  3164. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3165. {
  3166. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3167. }
  3168. else
  3169. {
  3170. design = new Dictionary<string, string>();
  3171. }
  3172. design[row["orders"].ToString()] = row["designId"].ToString();
  3173. design_orders[row["shopId"].ToString()] = design;
  3174. }
  3175. }
  3176. //处理成key value后根据key排序
  3177. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3178. foreach (List<string> val in shop_orders.Values)
  3179. {
  3180. if (val != null)
  3181. {
  3182. foreach (string key in val)
  3183. {
  3184. if (design_orders.ContainsKey(key.ToString()))
  3185. {
  3186. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. //校验哪个优先级有订单
  3193. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3194. foreach (string key in shop_orders.Keys)
  3195. {
  3196. List<string> ids = null;
  3197. shop_orders.TryGetValue(key, out ids);
  3198. //id为shopid
  3199. foreach (string id in ids)
  3200. {
  3201. Dictionary<string, int> list = null;
  3202. Dictionary<string, string> desing = null;
  3203. map.TryGetValue(id, out list);
  3204. design_orders.TryGetValue(id, out desing);
  3205. if (list != null && desing != null)
  3206. {
  3207. foreach (var item in desing)
  3208. {
  3209. int count = 0;
  3210. if (list.ContainsKey(item.Value))
  3211. {
  3212. list.TryGetValue(item.Value, out count);
  3213. if (count > 0)
  3214. {
  3215. designIds[id] = item.Value;
  3216. break;
  3217. }
  3218. }
  3219. }
  3220. }
  3221. }
  3222. if (designIds.Count > 0)
  3223. {
  3224. break;
  3225. }
  3226. }
  3227. DataTable table = new DataTable();
  3228. table.Columns.Add("tid", typeof(string));
  3229. table.Columns.Add("ctid", typeof(string));
  3230. table.Columns.Add("seller_nick", typeof(string));
  3231. table.Columns.Add("productName", typeof(string));
  3232. table.Columns.Add("pay_time", typeof(string));
  3233. table.Columns.Add("seller_memo", typeof(string));
  3234. if (designIds.Count > 0)
  3235. {
  3236. string shopId = "";
  3237. string productId = "";
  3238. foreach (var designInfo in designIds)
  3239. {
  3240. shopId = designInfo.Key;
  3241. productId = designInfo.Value;
  3242. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3243. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3244. if (dt.Rows.Count > 0)
  3245. {
  3246. foreach (DataRow row in dt.Rows)
  3247. {
  3248. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3249. {
  3250. DataRow data = table.NewRow();
  3251. data["ctid"] = row["ctid"].ToString();
  3252. data["tid"] = row["tid"].ToString();
  3253. data["seller_nick"] = ceErpShop.ShopName;
  3254. data["pay_time"] = row["pay_time"].ToString();
  3255. data["seller_memo"] = row["seller_memo"].ToString();
  3256. data["productName"] = ceErpProduct.PType;
  3257. table.Rows.Add(data);
  3258. }
  3259. }
  3260. }
  3261. }
  3262. }
  3263. writeGridDataTableJson(table.Rows.Count, table);
  3264. }
  3265. private object rushLockObject = new object();
  3266. public void set_erp_grabingorder()
  3267. {
  3268. if (UrlPostParmsCheck("ctid"))
  3269. {
  3270. int total = CurrentUser.User.Person.Total;
  3271. int userId = CurrentUser.User.ID;
  3272. int noFinish = CurrentUser.User.Person.NoFinish;
  3273. int finalization = CurrentUser.User.Person.Finalization;
  3274. string eids = GetPostString("ctid");
  3275. string key = "RushKey_" + userId;
  3276. int count = 0;
  3277. if (erpRedis.RedisHelper.KeyExists(key))
  3278. {
  3279. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3280. if (redisCount != null)
  3281. {
  3282. count = Convert.ToInt32(redisCount);
  3283. }
  3284. }
  3285. if (count >= total)
  3286. {
  3287. returnErrorMsg("半小时内已经抢" + total + "单");
  3288. return;
  3289. }
  3290. string[] ctidlist = eids.Split(',');
  3291. if (count + ctidlist.Length > total)
  3292. {
  3293. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3294. return;
  3295. }
  3296. int itag = 0;
  3297. lock (rushLockObject)
  3298. {
  3299. if (ctidlist.Length > 0)
  3300. {
  3301. string[] dtList = new string[ctidlist.Length];
  3302. for (int i = 0; i < ctidlist.Length; i++)
  3303. {
  3304. dtList[i] = "'" + ctidlist[i] + "'";
  3305. }
  3306. 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"));
  3307. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3308. if (dt_user.Rows.Count > 0)
  3309. {
  3310. int doing = 0;//未定稿
  3311. int finish = 0;//已完成
  3312. foreach (DataRow dr in dt_user.Rows)
  3313. {
  3314. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3315. {
  3316. doing++;
  3317. }
  3318. else
  3319. {
  3320. finish++;
  3321. }
  3322. }
  3323. if (doing >= noFinish)
  3324. {
  3325. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3326. return;
  3327. }
  3328. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3329. {
  3330. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3331. return;
  3332. }
  3333. }
  3334. //校验选择单子状态
  3335. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3336. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3337. if (dt.Rows.Count > 0)
  3338. {
  3339. List<string> list = new List<string>();
  3340. foreach (DataRow dr in dt.Rows)
  3341. {
  3342. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3343. {
  3344. list.Add(dr["ctid"].ToString());
  3345. }
  3346. }
  3347. if (list.Count > 0)
  3348. {
  3349. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3350. return;
  3351. }
  3352. }
  3353. foreach (string ctid in ctidlist)
  3354. {
  3355. CeErpTradeCell entity = null;
  3356. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3357. if (entity != null)
  3358. {
  3359. entity.OrderState = 3;
  3360. entity.DesignUserId = CurrentUser.UserID;
  3361. entity.WaitDesignTime = DateTime.Now;
  3362. entity.StartDesignTime = DateTime.Now;
  3363. entity.Update();
  3364. commonHelper.UpdateRelationOrder(entity.ctid);
  3365. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3366. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3367. itag++;
  3368. }
  3369. }
  3370. }
  3371. }
  3372. count += ctidlist.Length;
  3373. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3374. if (itag == 0)
  3375. returnErrorMsg("没有找到相关订单");
  3376. else
  3377. returnSuccessMsg("抢单成功!");
  3378. return;
  3379. }
  3380. }
  3381. public void get_erp_waitorderlist()
  3382. {
  3383. DataStruct dStruct = GetPostStruct();
  3384. List<string> lw = new List<string>();
  3385. string tid = GetPostString("ctid");
  3386. if (tid.Length > 0)
  3387. {
  3388. string select_tid = getTidByCtid(tid);
  3389. lw.Add(string.Format("tid='{0}'", select_tid));
  3390. }
  3391. string shopname = GetPostString("shopname");
  3392. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3393. string buyernick = GetPostString("buyer_nick");
  3394. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3395. string customer = GetPostString("customer");
  3396. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3397. string design = GetPostString("design");
  3398. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3399. string orderState = GetPostString("orderState");
  3400. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3401. string supplier = GetPostString("supplier");
  3402. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3403. string sellermemo = GetPostString("seller_memo");
  3404. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3405. string otherMemo = GetPostString("otherMemo");
  3406. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3407. string address = GetPostString("address");
  3408. 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));
  3409. string date1 = GetPostString("date1");
  3410. string date2 = GetPostString("date2");
  3411. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3412. if (dw.Length > 0) lw.Add(dw);
  3413. string price1 = GetPostString("price1");
  3414. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3415. string price2 = GetPostString("price2");
  3416. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3417. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3418. lw.Add(string.Format("IsSample != 2 "));
  3419. lw.Add(string.Format("OrderState = 5 "));
  3420. lw.Add(string.Format("IsRefund<={0}", 1));
  3421. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3422. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3423. string pagesize = GetPostString("pagesize");
  3424. if (pagesize != null)
  3425. {
  3426. dStruct.PageSize = 200;
  3427. }
  3428. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3429. List<string> tids = new List<string>();
  3430. if (dt != null)
  3431. {
  3432. dt.Columns.Add("compenPrice", typeof(double));
  3433. foreach (DataRow dr in dt.Rows)
  3434. {
  3435. if (Convert.IsDBNull(dr["compenPrice"]))
  3436. {
  3437. dr["compenPrice"] = 0;
  3438. }
  3439. tids.Add("'" + dr["tid"].ToString() + "'");
  3440. 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();
  3441. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3442. {
  3443. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3444. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3445. entity.SupplierId = suid;
  3446. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3447. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3448. entity.Update();
  3449. }
  3450. }
  3451. }
  3452. string sql = string.Format("select ptid,payment from CE_ErpTradeCell where ptid in (" + string.Join(",", tids) + ") and IsSample = 2");
  3453. DataTable dt_price = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3454. if (dt_price != null && dt_price.Rows.Count > 0)
  3455. {
  3456. foreach (DataRow dr in dt_price.Rows)
  3457. {
  3458. foreach (DataRow row in dt.Rows)
  3459. {
  3460. if (row["tid"].Equals(dr["ptid"]))
  3461. {
  3462. row["compenPrice"] = Convert.ToDouble(row["compenPrice"]) + Convert.ToDouble(dr["payment"]);
  3463. break;
  3464. }
  3465. }
  3466. }
  3467. }
  3468. writeGridDataTableJson(dStruct.TotalCount, dt);
  3469. }
  3470. public void get_erp_supplierwaitorderlist()
  3471. {
  3472. DataStruct dStruct = GetPostStruct();
  3473. List<string> lw = new List<string>();
  3474. string tid = GetPostString("ctid");
  3475. if (tid.Length > 0)
  3476. {
  3477. string select_tid = getTidByCtid(tid);
  3478. lw.Add(string.Format("tid='{0}'", select_tid));
  3479. }
  3480. string shopname = GetPostString("shopname");
  3481. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3482. string sellermemo = GetPostString("seller_memo");
  3483. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3484. string date1 = GetPostString("date1");
  3485. string date2 = GetPostString("date2");
  3486. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3487. if (dw.Length > 0) lw.Add(dw);
  3488. lw.Add(string.Format("OrderState = 5 "));
  3489. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3490. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3491. {
  3492. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3493. }
  3494. string supplier = GetPostString("supplier");
  3495. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3496. {
  3497. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3498. }
  3499. lw.Add(string.Format("IsRefund<={0}", 1));
  3500. dStruct.Order = "FinishDesignTime desc";
  3501. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3502. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3503. if (dt != null)
  3504. {
  3505. foreach (DataRow dr in dt.Rows)
  3506. {
  3507. 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();
  3508. }
  3509. }
  3510. writeGridDataTableJson(dStruct.TotalCount, dt);
  3511. }
  3512. public void upd_erp_verifytosupplier()
  3513. {
  3514. if (UrlPostParmsCheck("ctid"))
  3515. {
  3516. string eids = GetPostString("ctid");
  3517. CeErpTradeCell entity = null;
  3518. string[] eidsList = eids.Split(',');
  3519. if (eidsList.Length <= 0)
  3520. {
  3521. returnErrorMsg("订单号不能空");
  3522. return;
  3523. }
  3524. List<string> tLst = new List<string>();
  3525. foreach (string ctidstr in eidsList)
  3526. {
  3527. tLst.Add("'" + ctidstr + "'");
  3528. CeErpDataSendOrderInfo.createObject(ctidstr);
  3529. }
  3530. string needtids = string.Join(",", tLst.ToArray());
  3531. StringBuilder sql = new StringBuilder();
  3532. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3533. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1},IsHaveNewOrder=0 where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3534. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3535. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3536. returnSuccessMsg("操作成功!");
  3537. return;
  3538. /**foreach (string ctidstr in eidsList)
  3539. {
  3540. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3541. if (entity != null)
  3542. {
  3543. if (entity.SupplierId == 0)
  3544. {
  3545. continue;
  3546. }
  3547. entity.IsVerifyToSupplier = true;
  3548. if (entity.IsReturn == 1) //1是供应商打回
  3549. {
  3550. entity.IsReturn = 0;
  3551. }
  3552. entity.FinishPlaceTime = DateTime.Now;
  3553. entity.PlaceUserId = CurrentUser.UserID;
  3554. entity.Update();
  3555. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3556. }
  3557. }
  3558. returnSuccessMsg("操作成功!");
  3559. return;**/
  3560. }
  3561. }
  3562. public void upd_erp_supplierback()
  3563. {
  3564. if (UrlPostParmsCheck("ctid"))
  3565. {
  3566. string eid = GetPostString("ctid");
  3567. string reason = GetPostString("returnreason");
  3568. CeErpTradeCell entity = null;
  3569. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3570. if (entity != null)
  3571. {
  3572. string message = "操作成功!";
  3573. if (entity.OrderState == 6 || entity.IsHaveNewOrder == 2)
  3574. {
  3575. message = "订单有被点击下载。请注意沟通是否已下载完!";
  3576. }
  3577. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3578. {
  3579. string key = "return_order_" + entity.SupplierId;
  3580. List<string> list = new List<string>();
  3581. if (RedisHelper.HasKey(key))
  3582. {
  3583. object data = RedisHelper.StringGet(key);
  3584. list = Convert.ToString(data).Split(',').ToList();
  3585. }
  3586. list.Add(eid);
  3587. RedisHelper.StringSet(key, string.Join(",", list));
  3588. }
  3589. entity.IsVerifyToSupplier = false;
  3590. entity.IsReturn = 1;
  3591. entity.IsHaveNewOrder = 0;
  3592. entity.ReturnTime = DateTime.Now;
  3593. entity.ReturnReason = reason;
  3594. if (entity.OrderState == 6)
  3595. {
  3596. entity.OrderState = 5;
  3597. }
  3598. entity.Update();
  3599. CeErpSukuraData.createInfo(entity.ctid, 5);
  3600. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3601. returnSuccessMsg(message);
  3602. return;
  3603. }
  3604. returnErrorMsg("找不到订单记录");
  3605. }
  3606. }
  3607. public void upd_erp_toaftersaleorder()
  3608. {
  3609. if (UrlPostParmsCheck("ctid"))
  3610. {
  3611. string eid = GetPostString("ctid");
  3612. string reason = GetPostString("returnreason");
  3613. CeErpTradeCell entity = null;
  3614. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3615. if (entity != null)
  3616. {
  3617. if (entity.isAfterSaleOrder != 1)
  3618. {
  3619. returnErrorMsg("带S的售后单才能打回给售后");
  3620. return;
  3621. }
  3622. if (entity.OrderState >= 5)
  3623. {
  3624. returnErrorMsg("已经设计完成了不能打回给售后");
  3625. return;
  3626. }
  3627. entity.OrderState = 0;
  3628. entity.IsReturn = 3;
  3629. entity.ReturnTime = DateTime.Now;
  3630. entity.UpdateTime = DateTime.Now;
  3631. entity.ReturnReason = reason;
  3632. entity.Update();
  3633. CeErpSukuraData.createInfo(entity.ctid, 5);
  3634. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3635. returnSuccessMsg("操作成功!");
  3636. return;
  3637. }
  3638. returnErrorMsg("找不到订单记录");
  3639. }
  3640. }
  3641. public void upd_erp_aftersaletodesign()
  3642. {
  3643. if (UrlPostParmsCheck("ctid"))
  3644. {
  3645. string eid = GetPostString("ctid");
  3646. CeErpTradeCell entity = null;
  3647. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3648. if (entity != null)
  3649. {
  3650. entity.OrderState = 3;
  3651. entity.IsReturn = 0;
  3652. entity.UpdateTime = DateTime.Now;
  3653. entity.Update();
  3654. CeErpSukuraData.createInfo(entity.ctid, 5);
  3655. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3656. returnSuccessMsg("操作成功!");
  3657. return;
  3658. }
  3659. returnErrorMsg("找不到订单记录");
  3660. }
  3661. }
  3662. public void assign_erp_supplier()
  3663. {
  3664. if (UrlPostParmsCheck("ctid"))
  3665. {
  3666. string eids = GetPostString("ctid");
  3667. int sid = GetPostInt("SupplierName");
  3668. string fromTag = GetPostString("tag");
  3669. string[] eidList = eids.Split(',');
  3670. if (eidList.Length <= 0)
  3671. {
  3672. returnErrorMsg("指派不能为空");
  3673. return;
  3674. }
  3675. string errMsg = "";
  3676. string suname = commonHelper.getSupplierNameById(sid);
  3677. foreach (string ctid in eidList)
  3678. {
  3679. CeErpTradeCell entity = null;
  3680. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3681. if (entity != null)
  3682. {
  3683. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3684. {
  3685. errMsg += (ctid + "指派失败!!!");
  3686. continue;
  3687. }
  3688. entity.SupplierId = sid;
  3689. entity.Update();
  3690. commonHelper.UpdateRelationOrder(entity.ctid);
  3691. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3692. if (entity.OrderState >= 6)
  3693. {
  3694. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3695. //{
  3696. // string msl = entity.MakeSupplier;
  3697. // string[] mslist = msl.Split(',');
  3698. // 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);
  3699. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3700. //}
  3701. //else
  3702. //{
  3703. StringBuilder sql = new StringBuilder();
  3704. 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);
  3705. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3706. //}
  3707. }
  3708. }
  3709. else
  3710. {
  3711. continue;
  3712. }
  3713. }
  3714. if (errMsg.Length > 0)
  3715. {
  3716. returnErrorMsg(errMsg);
  3717. return;
  3718. }
  3719. returnSuccessMsg("操作成功!");
  3720. return;
  3721. }
  3722. }
  3723. public void assign_erp_makesupplier()
  3724. {
  3725. if (UrlPostParmsCheck("ctid"))
  3726. {
  3727. string eids = GetPostString("ctid");
  3728. string sname = GetPostString("SupplierName");
  3729. string[] eidList = eids.Split(',');
  3730. if (eidList.Length <= 0)
  3731. {
  3732. returnErrorMsg("指派不能为空");
  3733. return;
  3734. }
  3735. List<string> tLst = new List<string>();
  3736. foreach (string ctid in eidList)
  3737. {
  3738. CeErpTradeCell entity = null;
  3739. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3740. if (entity != null)
  3741. {
  3742. entity.MakeSupplier = sname;
  3743. entity.Update();
  3744. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3745. tLst.Add("'" + ctid + "'");
  3746. }
  3747. else
  3748. {
  3749. continue;
  3750. }
  3751. }
  3752. string ctids = string.Join(",", tLst.ToArray());
  3753. StringBuilder sql2 = new StringBuilder();
  3754. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3755. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3756. returnSuccessMsg("操作成功!");
  3757. return;
  3758. }
  3759. }
  3760. public void ins_erp_returnreason()
  3761. {
  3762. if (UrlPostParmsCheck("ctid"))
  3763. {
  3764. string eid = GetPostString("ctid");
  3765. CeErpTradeCell entity = null;
  3766. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3767. string userpost = CurrentUser.UserPost.Post.Code;
  3768. if (entity != null)
  3769. {
  3770. bool isPlace = false;
  3771. if (entity.OrderState > 6)
  3772. {
  3773. returnErrorMsg("已发货无法打回!");
  3774. return;
  3775. }
  3776. if (entity.OrderState == 6)
  3777. {
  3778. isPlace = true;
  3779. }
  3780. bool isNeedUpdateCell2 = false;
  3781. if (entity.OrderState >= 6)
  3782. {
  3783. isNeedUpdateCell2 = true;
  3784. }
  3785. int returnTag = 2;
  3786. if (userpost == "Supplier")
  3787. {
  3788. returnTag = 1;
  3789. }
  3790. int toType = GetPostInt("totype");
  3791. string fromType = "3";
  3792. if (entity.OrderState < 5)
  3793. {
  3794. fromType = "3";
  3795. }
  3796. else
  3797. {
  3798. fromType = "4";
  3799. }
  3800. if (entity.IsXianHuo == 0)
  3801. {
  3802. if (returnTag == 2)
  3803. {
  3804. if (toType == 1)
  3805. {
  3806. entity.OrderState = 0;
  3807. entity.ReturnUserType = 1;
  3808. string clearman = GetPostString("clearman");
  3809. if (!string.IsNullOrEmpty(clearman))
  3810. {
  3811. entity.DesignUserId = 0;
  3812. }
  3813. }
  3814. else
  3815. {
  3816. entity.OrderState = 3;
  3817. entity.ReturnUserType = 2;
  3818. }
  3819. entity.IsReadTag = 1;
  3820. }
  3821. else if (returnTag == 1)
  3822. {
  3823. entity.OrderState = 5;
  3824. }
  3825. entity.IsVerifyToSupplier = false;
  3826. }
  3827. if (entity.IsXianHuo == 1)
  3828. {
  3829. entity.OrderState = 5;
  3830. }
  3831. entity.UnusualTag = 0;
  3832. entity.UnusualTime = null;
  3833. entity.UnusualCon = "";
  3834. entity.IsReturn = returnTag;
  3835. entity.ReturnTime = DateTime.Now;
  3836. entity.UpdateTime = DateTime.Now;
  3837. entity.ReturnReason = GetPostString("returnreason");
  3838. entity.Update();
  3839. if (entity.OrderState == 3)
  3840. {
  3841. ApiVo apiVo = new ApiVo();
  3842. apiVo.orderNumber = entity.ctid;
  3843. apiVo.actionName = "rebutDesign";
  3844. apiVo.orderRemarks = entity.ReturnReason;
  3845. designHelper.API_WorkCore(apiVo);//rebutDesign
  3846. }
  3847. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3848. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3849. {
  3850. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3851. }
  3852. CeErpSukuraData.createInfo(entity.ctid, 5);
  3853. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3854. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3855. if (isPlace)
  3856. {
  3857. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3858. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3859. if (dth != null && dth.Rows.Count > 0)
  3860. {
  3861. dataSendOrderBean dataSendOrderBean = null;
  3862. foreach (DataRow item in dth.Rows)
  3863. {
  3864. try
  3865. {
  3866. dataSendOrderBean = new dataSendOrderBean();
  3867. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3868. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3869. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3870. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3871. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3872. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3873. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3874. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3875. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3876. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3877. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3878. dataSendOrderBean.Radio1723534706288 = "打回";
  3879. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3880. if (result != null)
  3881. {
  3882. if ("0".Equals(result.errcode))
  3883. {
  3884. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3885. }
  3886. else
  3887. {
  3888. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3889. }
  3890. }
  3891. }
  3892. catch (Exception ex)
  3893. {
  3894. }
  3895. }
  3896. }
  3897. }
  3898. if (isNeedUpdateCell2)
  3899. {
  3900. if (entity.MakeSupplier.IndexOf(",") != -1)
  3901. {
  3902. StringBuilder sql2 = new StringBuilder();
  3903. 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);
  3904. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3905. }
  3906. else
  3907. {
  3908. StringBuilder sql2 = new StringBuilder();
  3909. 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);
  3910. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3911. }
  3912. }
  3913. returnSuccessMsg("操作成功!");
  3914. return;
  3915. }
  3916. returnErrorMsg("找不到订单记录");
  3917. }
  3918. }
  3919. public void cyt_erp_returnreason()
  3920. {
  3921. if (UrlPostParmsCheck("ctid"))
  3922. {
  3923. string eid = GetPostString("ctid");
  3924. CeErpTradeCell entity = null;
  3925. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3926. string userpost = CurrentUser.UserPost.Post.Code;
  3927. if (entity != null)
  3928. {
  3929. if (entity.OrderState > 6)
  3930. {
  3931. returnErrorMsg("已发货无法打回!");
  3932. return;
  3933. }
  3934. JObject jsonObject = new JObject
  3935. {
  3936. { "Userid", "77886" },
  3937. { "Pwd", "lt666888" },
  3938. { "LTOrderId",eid }
  3939. };
  3940. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3941. JObject jsonObjects = JObject.Parse(response);
  3942. string msg = (string)jsonObjects["msg"];
  3943. if (msg != "取消成功")
  3944. {
  3945. returnErrorMsg(msg);
  3946. return;
  3947. }
  3948. bool isNeedUpdateCell2 = false;
  3949. if (entity.OrderState >= 6)
  3950. {
  3951. isNeedUpdateCell2 = true;
  3952. }
  3953. int returnTag = 2;
  3954. if (userpost == "Supplier")
  3955. {
  3956. returnTag = 1;
  3957. }
  3958. if (entity.IsXianHuo == 0)
  3959. {
  3960. if (returnTag == 2)
  3961. {
  3962. int toType = GetPostInt("totype");
  3963. if (toType == 1)
  3964. {
  3965. entity.OrderState = 0;
  3966. entity.ReturnUserType = 1;
  3967. }
  3968. else
  3969. {
  3970. entity.OrderState = 4;
  3971. entity.ReturnUserType = 2;
  3972. }
  3973. entity.IsReadTag = 1;
  3974. }
  3975. else if (returnTag == 1)
  3976. {
  3977. entity.OrderState = 5;
  3978. }
  3979. entity.IsVerifyToSupplier = false;
  3980. }
  3981. entity.UnusualTag = 0;
  3982. entity.UnusualTime = null;
  3983. entity.UnusualCon = "";
  3984. entity.IsReturn = returnTag;
  3985. entity.ReturnTime = DateTime.Now;
  3986. entity.ReturnReason = GetPostString("returnreason");
  3987. entity.Update();
  3988. if (entity.OrderState == 4)
  3989. {
  3990. ApiVo apiVo = new ApiVo();
  3991. apiVo.orderNumber = entity.ctid;
  3992. apiVo.actionName = "rebutDesign";
  3993. apiVo.orderRemarks = entity.ReturnReason;
  3994. designHelper.API_WorkCore(apiVo);//rebutDesign
  3995. }
  3996. CeErpSukuraData.createInfo(entity.ctid, 5);
  3997. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3998. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3999. if (isNeedUpdateCell2)
  4000. {
  4001. if (entity.MakeSupplier.IndexOf(",") != -1)
  4002. {
  4003. StringBuilder sql2 = new StringBuilder();
  4004. 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);
  4005. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4006. }
  4007. else
  4008. {
  4009. StringBuilder sql2 = new StringBuilder();
  4010. 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);
  4011. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  4012. }
  4013. }
  4014. returnSuccessMsg("操作成功!");
  4015. return;
  4016. }
  4017. returnErrorMsg("找不到订单记录");
  4018. }
  4019. }
  4020. public void upd_erp_xianhuoreturntag()
  4021. {
  4022. if (UrlPostParmsCheck("ctid"))
  4023. {
  4024. string eids = GetPostString("ctid");
  4025. string[] ctids = eids.Split(',');
  4026. foreach (string ctid in ctids)
  4027. {
  4028. CeErpTradeCell entity = null;
  4029. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4030. if (entity != null)
  4031. {
  4032. entity.IsReturn = 0;
  4033. entity.Update();
  4034. CeErpSukuraData.createInfo(entity.ctid, 5);
  4035. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  4036. }
  4037. }
  4038. returnSuccessMsg("操作成功!");
  4039. return;
  4040. }
  4041. }
  4042. public void get_erp_waitdeliverylist()
  4043. {
  4044. DataStruct dStruct = GetPostStruct();
  4045. List<string> lw = new List<string>();
  4046. string tid = GetPostString("ctid");
  4047. if (tid.Length > 0)
  4048. {
  4049. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4050. if (tid.Length > 5)
  4051. {
  4052. List<string> tids = getTidByCtidLike(tid);
  4053. if (tids.Count > 0 && tids.Count < 10)
  4054. {
  4055. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4056. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4057. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4058. {
  4059. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4060. }*/
  4061. }
  4062. }
  4063. lw.Add(tid_sql);
  4064. }
  4065. string shopname = GetPostString("shopname");
  4066. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4067. string buyernick = GetPostString("buyer_nick");
  4068. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4069. //if (tid.Length == 0 && buyernick.Length == 0)
  4070. //{
  4071. // lw.Add(string.Format("IsRefund<={0}", 1));
  4072. //}
  4073. string customer = GetPostString("customer");
  4074. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4075. string design = GetPostString("design");
  4076. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4077. string orderState = GetPostString("orderState");
  4078. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4079. string address = GetPostString("address");
  4080. 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));
  4081. string sellermemo = GetPostString("seller_memo");
  4082. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4083. string supplier = GetPostString("supplier");
  4084. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4085. string OrderArea = GetPostString("order_area");
  4086. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4087. string placedate1 = GetPostString("placedate1");
  4088. string placedate2 = GetPostString("placedate2");
  4089. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4090. if (fdw.Length > 0) lw.Add(fdw);
  4091. string price1 = GetPostString("price1");
  4092. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4093. string price2 = GetPostString("price2");
  4094. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4095. string unusualCon = GetPostString("unusualcon");
  4096. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4097. string otherMemo = GetPostString("otherMemo");
  4098. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4099. string posTag = CurrentUser.UserPost.Post.Code;
  4100. if (posTag == "Supplier")
  4101. {
  4102. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4103. }
  4104. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4105. lw.Add(string.Format("type != 'PDD' "));
  4106. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4107. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4108. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4109. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4110. writeGridDataTableJson(dStruct.TotalCount, dt);
  4111. }
  4112. public void get_erp_changedeliverylist()
  4113. {
  4114. DataStruct dStruct = GetPostStruct();
  4115. List<string> lw = new List<string>();
  4116. string tid = GetPostString("ctid");
  4117. if (tid.Length > 0)
  4118. {
  4119. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4120. if (tid.Length > 5)
  4121. {
  4122. List<string> tids = getTidByCtidLike(tid);
  4123. if (tids.Count > 0 && tids.Count < 10)
  4124. {
  4125. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4126. }
  4127. }
  4128. lw.Add(tid_sql);
  4129. }
  4130. string shopname = GetPostString("shopname");
  4131. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4132. string buyernick = GetPostString("buyer_nick");
  4133. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4134. //if (tid.Length == 0 && buyernick.Length == 0)
  4135. //{
  4136. // lw.Add(string.Format("IsRefund<={0}", 1));
  4137. //}
  4138. string customer = GetPostString("customer");
  4139. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4140. string design = GetPostString("design");
  4141. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4142. string orderState = GetPostString("orderState");
  4143. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4144. string address = GetPostString("address");
  4145. 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));
  4146. string sellermemo = GetPostString("seller_memo");
  4147. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4148. string supplier = GetPostString("supplier");
  4149. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4150. string OrderArea = GetPostString("order_area");
  4151. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4152. string placedate1 = GetPostString("placedate1");
  4153. string placedate2 = GetPostString("placedate2");
  4154. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4155. if (fdw.Length > 0) lw.Add(fdw);
  4156. string price1 = GetPostString("price1");
  4157. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4158. string price2 = GetPostString("price2");
  4159. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4160. string unusualCon = GetPostString("unusualcon");
  4161. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4162. string otherMemo = GetPostString("otherMemo");
  4163. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4164. string posTag = CurrentUser.UserPost.Post.Code;
  4165. if (posTag == "Supplier")
  4166. {
  4167. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4168. }
  4169. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4170. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4171. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4172. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4173. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4174. /*if (tid.Length > 0)
  4175. {
  4176. List<string> tids = new List<string>();
  4177. if (dt != null && dt.Rows.Count > 0)
  4178. {
  4179. foreach (DataRow item in dt.Rows)
  4180. {
  4181. tids.Add("'" + item["tid"] + "'");
  4182. }
  4183. }
  4184. if (tids.Count > 0)
  4185. {
  4186. lw.RemoveAt(0);
  4187. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4188. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4189. dt = WebCache.GetData("view_erptradecell", dStruct);
  4190. }
  4191. }*/
  4192. writeGridDataTableJson(dStruct.TotalCount, dt);
  4193. }
  4194. public void get_erp_pddderiving()
  4195. {
  4196. DataStruct dStruct = GetPostStruct();
  4197. List<string> lw = new List<string>();
  4198. string tid = GetPostString("ctid");
  4199. if (tid.Length > 0)
  4200. {
  4201. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4202. if (tid.Length > 5)
  4203. {
  4204. List<string> tids = getTidByCtidLike(tid);
  4205. if (tids.Count > 0 && tids.Count < 10)
  4206. {
  4207. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4208. /* List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4209. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4210. {
  4211. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4212. }*/
  4213. }
  4214. }
  4215. lw.Add(tid_sql);
  4216. }
  4217. string shopname = GetPostString("shopname");
  4218. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4219. string buyernick = GetPostString("buyer_nick");
  4220. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4221. //if (tid.Length == 0 && buyernick.Length == 0)
  4222. //{
  4223. // lw.Add(string.Format("IsRefund<={0}", 1));
  4224. //}
  4225. string customer = GetPostString("customer");
  4226. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4227. string design = GetPostString("design");
  4228. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4229. string orderState = GetPostString("orderState");
  4230. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4231. string address = GetPostString("address");
  4232. 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));
  4233. string sellermemo = GetPostString("seller_memo");
  4234. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4235. string supplier = GetPostString("supplier");
  4236. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4237. string OrderArea = GetPostString("order_area");
  4238. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4239. string placedate1 = GetPostString("placedate1");
  4240. string placedate2 = GetPostString("placedate2");
  4241. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4242. if (fdw.Length > 0) lw.Add(fdw);
  4243. string price1 = GetPostString("price1");
  4244. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4245. string price2 = GetPostString("price2");
  4246. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4247. string unusualCon = GetPostString("unusualcon");
  4248. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4249. string posTag = CurrentUser.UserPost.Post.Code;
  4250. if (posTag == "Supplier")
  4251. {
  4252. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4253. }
  4254. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4255. lw.Add(string.Format("type = 'PDD' "));
  4256. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4257. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4258. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4259. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4260. /*if (tid.Length > 0)
  4261. {
  4262. List<string> tids = new List<string>();
  4263. if (dt != null && dt.Rows.Count > 0)
  4264. {
  4265. foreach (DataRow item in dt.Rows)
  4266. {
  4267. tids.Add("'" + item["tid"] + "'");
  4268. }
  4269. }
  4270. if (tids.Count > 0)
  4271. {
  4272. lw.RemoveAt(0);
  4273. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4274. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4275. dt = WebCache.GetData("view_erptradecell", dStruct);
  4276. }
  4277. }*/
  4278. writeGridDataTableJson(dStruct.TotalCount, dt);
  4279. }
  4280. public void get_erp_jdderiving()
  4281. {
  4282. DataStruct dStruct = GetPostStruct();
  4283. List<string> lw = new List<string>();
  4284. string tid = GetPostString("ctid");
  4285. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4286. string shopname = GetPostString("shopname");
  4287. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4288. string buyernick = GetPostString("buyer_nick");
  4289. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4290. //if (tid.Length == 0 && buyernick.Length == 0)
  4291. //{
  4292. // lw.Add(string.Format("IsRefund<={0}", 1));
  4293. //}
  4294. string customer = GetPostString("customer");
  4295. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4296. string design = GetPostString("design");
  4297. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4298. string orderState = GetPostString("orderState");
  4299. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4300. string address = GetPostString("address");
  4301. 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));
  4302. string sellermemo = GetPostString("seller_memo");
  4303. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4304. string supplier = GetPostString("supplier");
  4305. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4306. string OrderArea = GetPostString("order_area");
  4307. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4308. string placedate1 = GetPostString("placedate1");
  4309. string placedate2 = GetPostString("placedate2");
  4310. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4311. if (fdw.Length > 0) lw.Add(fdw);
  4312. string price1 = GetPostString("price1");
  4313. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4314. string price2 = GetPostString("price2");
  4315. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4316. string unusualCon = GetPostString("unusualcon");
  4317. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4318. string posTag = CurrentUser.UserPost.Post.Code;
  4319. if (posTag == "Supplier")
  4320. {
  4321. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4322. }
  4323. lw.Add(string.Format("OrderState = 6 "));
  4324. lw.Add(string.Format("type = 'JD' "));
  4325. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4326. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4327. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4328. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4329. writeGridDataTableJson(dStruct.TotalCount, dt);
  4330. }
  4331. public void get_erp_demoorderlist()
  4332. {
  4333. DataStruct dStruct = GetPostStruct();
  4334. List<string> lw = new List<string>();
  4335. string tid = GetPostString("ctid");
  4336. if (tid.Length > 0)
  4337. {
  4338. string select_tid = getTidByCtid(tid);
  4339. lw.Add(string.Format("tid='{0}'", select_tid));
  4340. }
  4341. string shopname = GetPostString("shopname");
  4342. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4343. string buyernick = GetPostString("buyer_nick");
  4344. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4345. string customer = GetPostString("customer");
  4346. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4347. string design = GetPostString("design");
  4348. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4349. string orderState = GetPostString("orderState");
  4350. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4351. string address = GetPostString("address");
  4352. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4353. string sellermemo = GetPostString("seller_memo");
  4354. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4355. string supplier = GetPostString("supplier");
  4356. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4357. string OrderArea = GetPostString("order_area");
  4358. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4359. string date1 = GetPostString("date1");
  4360. string date2 = GetPostString("date2");
  4361. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4362. if (dw.Length > 0) lw.Add(dw);
  4363. string price1 = GetPostString("price1");
  4364. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4365. string price2 = GetPostString("price2");
  4366. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4367. string posTag = CurrentUser.UserPost.Post.Code;
  4368. if (posTag == "Supplier")
  4369. {
  4370. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4371. }
  4372. //lw.Add(string.Format("OrderState = 6 "));
  4373. lw.Add(string.Format("IsSample={0}", 3));
  4374. lw.Add(string.Format("IsRefund<={0}", 1));
  4375. dStruct.Order = "pay_time desc";
  4376. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4377. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4378. writeGridDataTableJson(dStruct.TotalCount, dt);
  4379. }
  4380. public void save_erp_checkmemo()
  4381. {
  4382. if (UrlPostParmsCheck("ctid"))
  4383. {
  4384. string ctid = GetPostString("ctid");
  4385. CeErpTradeCell entity = null;
  4386. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4387. if (entity != null)
  4388. {
  4389. entity.CheckMemo = GetPostString("CheckMemo");
  4390. entity.Update();
  4391. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4392. if (trade != null)
  4393. {
  4394. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4395. }
  4396. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4397. returnSuccessMsg("保存成功!");
  4398. return;
  4399. }
  4400. returnErrorMsg("找不到记录");
  4401. }
  4402. }
  4403. public void get_erp_returnlist()
  4404. {
  4405. DataStruct dStruct = GetPostStruct();
  4406. List<string> lw = new List<string>();
  4407. string tid = GetPostString("ctid");
  4408. if (tid.Length > 0)
  4409. {
  4410. string select_tid = getTidByCtid(tid);
  4411. lw.Add(string.Format("tid='{0}'", select_tid));
  4412. }
  4413. string shopname = GetPostString("shopname");
  4414. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4415. string buyernick = GetPostString("buyer_nick");
  4416. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4417. string customer = GetPostString("customer");
  4418. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4419. string design = GetPostString("design");
  4420. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4421. string orderState = GetPostString("orderState");
  4422. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4423. string address = GetPostString("address");
  4424. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4425. string sellermemo = GetPostString("seller_memo");
  4426. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4427. string supplier = GetPostString("supplier");
  4428. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4429. string date1 = GetPostString("date1");
  4430. string date2 = GetPostString("date2");
  4431. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4432. if (dw.Length > 0) lw.Add(dw);
  4433. string bdate1 = GetPostString("backdate1");
  4434. string bdate2 = GetPostString("backdate2");
  4435. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4436. if (dw_back.Length > 0) lw.Add(dw_back);
  4437. string price1 = GetPostString("price1");
  4438. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4439. string price2 = GetPostString("price2");
  4440. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4441. lw.Add(string.Format("IsReturn>0"));
  4442. lw.Add(string.Format("IsXianHuo=0"));
  4443. lw.Add(string.Format("IsReturn!=3"));
  4444. string backtype = GetPostString("backtype");
  4445. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4446. dStruct.Order = "FinishDesignTime desc";
  4447. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4448. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4449. writeGridDataTableJson(dStruct.TotalCount, dt);
  4450. }
  4451. public void get_erp_today_sumreturn()
  4452. {
  4453. DataStruct dStruct = GetPostStruct();
  4454. List<string> lw = new List<string>();
  4455. string bdate1 = GetPostString("returnTimeS");
  4456. string bdate2 = GetPostString("returnTimeE");
  4457. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4458. if (dw_back.Length > 0) lw.Add(dw_back);
  4459. lw.Add(string.Format("IsReturn=0"));
  4460. lw.Add(string.Format("IsXianHuo=0"));
  4461. string mainWhere = string.Join(" and ", lw.ToArray());
  4462. string sql = "";
  4463. if (dw_back.Length > 0)
  4464. {
  4465. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4466. }
  4467. else
  4468. {
  4469. 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 + "'";
  4470. }
  4471. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4472. decimal total = 0, today_finish = 0;
  4473. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4474. {
  4475. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4476. }
  4477. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4478. {
  4479. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4480. }
  4481. var res = new
  4482. {
  4483. data = total,
  4484. data1 = today_finish,
  4485. };
  4486. string ro_jsond = JsonConvert.SerializeObject(res);
  4487. returnSuccess(ro_jsond);
  4488. return;
  4489. }
  4490. public void get_erp_allreturnlist()
  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 like '%{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 date1 = GetPostString("date1");
  4517. string date2 = GetPostString("date2");
  4518. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4519. if (dw.Length > 0) lw.Add(dw);
  4520. string bdate1 = GetPostString("backdate1");
  4521. string bdate2 = GetPostString("backdate2");
  4522. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4523. if (dw_back.Length > 0) lw.Add(dw_back);
  4524. string price1 = GetPostString("price1");
  4525. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4526. string price2 = GetPostString("price2");
  4527. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4528. string backreason = GetPostString("backreason");
  4529. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4530. lw.Add(string.Format("IsXianHuo=0"));
  4531. lw.Add(string.Format("ReturnTime != ''"));
  4532. string backtype = GetPostString("backtype");
  4533. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4534. dStruct.Order = "FinishDesignTime 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 get_erp_aftersalereturnlist()
  4540. {
  4541. DataStruct dStruct = GetPostStruct();
  4542. List<string> lw = new List<string>();
  4543. string tid = GetPostString("ctid");
  4544. if (tid.Length > 0)
  4545. {
  4546. string select_tid = getTidByCtid(tid);
  4547. lw.Add(string.Format("tid='{0}'", select_tid));
  4548. }
  4549. string shopname = GetPostString("shopname");
  4550. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4551. string buyernick = GetPostString("buyer_nick");
  4552. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4553. string customer = GetPostString("customer");
  4554. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4555. string design = GetPostString("design");
  4556. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4557. string orderState = GetPostString("orderState");
  4558. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4559. string address = GetPostString("address");
  4560. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4561. string sellermemo = GetPostString("seller_memo");
  4562. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4563. string supplier = GetPostString("supplier");
  4564. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4565. string date1 = GetPostString("date1");
  4566. string date2 = GetPostString("date2");
  4567. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4568. if (dw.Length > 0) lw.Add(dw);
  4569. string bdate1 = GetPostString("backdate1");
  4570. string bdate2 = GetPostString("backdate2");
  4571. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4572. if (dw_back.Length > 0) lw.Add(dw_back);
  4573. string price1 = GetPostString("price1");
  4574. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4575. string price2 = GetPostString("price2");
  4576. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4577. lw.Add(string.Format("IsReturn=3"));
  4578. string backtype = GetPostString("backtype");
  4579. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4580. string backreason = GetPostString("backreason");
  4581. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4582. dStruct.Order = "ReturnTime desc";
  4583. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4584. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4585. writeGridDataTableJson(dStruct.TotalCount, dt);
  4586. }
  4587. public void get_erp_xianhuoreturnlist()
  4588. {
  4589. DataStruct dStruct = GetPostStruct();
  4590. List<string> lw = new List<string>();
  4591. string tid = GetPostString("ctid");
  4592. if (tid.Length > 0)
  4593. {
  4594. string select_tid = getTidByCtid(tid);
  4595. lw.Add(string.Format("tid='{0}'", select_tid));
  4596. }
  4597. string shopname = GetPostString("shopname");
  4598. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4599. string buyernick = GetPostString("buyer_nick");
  4600. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4601. string customer = GetPostString("customer");
  4602. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4603. string design = GetPostString("design");
  4604. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4605. string orderState = GetPostString("orderState");
  4606. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4607. string address = GetPostString("address");
  4608. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4609. string sellermemo = GetPostString("seller_memo");
  4610. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4611. string supplier = GetPostString("supplier");
  4612. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4613. string OrderArea = GetPostString("order_area");
  4614. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4615. string date1 = GetPostString("date1");
  4616. string date2 = GetPostString("date2");
  4617. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4618. if (dw.Length > 0) lw.Add(dw);
  4619. string price1 = GetPostString("price1");
  4620. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4621. string price2 = GetPostString("price2");
  4622. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4623. string posTag = CurrentUser.UserPost.Post.Code;
  4624. if (posTag == "Supplier")
  4625. {
  4626. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4627. }
  4628. lw.Add(string.Format("OrderState=6 "));
  4629. lw.Add(string.Format("IsXianHuo=1 "));
  4630. lw.Add(string.Format("IsReturn>0 "));
  4631. lw.Add(string.Format("IsReturn!=3"));
  4632. lw.Add(string.Format("IsRefund<={0}", 1));
  4633. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4634. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4635. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4636. writeGridDataTableJson(dStruct.TotalCount, dt);
  4637. }
  4638. public void set_erp_orderdelivery()
  4639. {
  4640. if (UrlPostParmsCheck("ctid"))
  4641. {
  4642. string eid = GetPostString("ctid");
  4643. CeErpTradeCell entity = null;
  4644. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4645. if (entity != null)
  4646. {
  4647. if (entity.OrderState >= 7)
  4648. {
  4649. returnErrorMsg("此单已发货,无需重复发货");
  4650. return;
  4651. }
  4652. if (entity.OrderState != 6)
  4653. {
  4654. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4655. return;
  4656. }
  4657. string shop = GetPostString("seller_nick");
  4658. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4659. string comName = GetPostString("comName");
  4660. string comCode = GetPostString("comCode");
  4661. string outSid = GetPostString("outSid");
  4662. string deliveryType = GetPostString("deliveryType");
  4663. string deliveryMemo = GetPostString("deliveryMemo");
  4664. outSid = outSid.Trim();
  4665. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4666. if (mainEn == null)
  4667. {
  4668. returnErrorMsg("找不到原始订单记录");
  4669. return;
  4670. }
  4671. bool isInitOrderDeliv = false;
  4672. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4673. {
  4674. isInitOrderDeliv = true;
  4675. }
  4676. string apires = "";
  4677. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4678. 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)
  4679. {
  4680. apires = "发货成功true";
  4681. }
  4682. else
  4683. {
  4684. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4685. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4686. }
  4687. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4688. {
  4689. entity.OrderState = 7;//发货后订单已发货
  4690. entity.OutSid = outSid;
  4691. entity.MemoOpt = 0;
  4692. entity.UpdateTime = DateTime.Now;
  4693. entity.FinishDeliveryTime = DateTime.Now;
  4694. entity.Update();
  4695. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4696. commonHelper.UpdateRelationOrder(entity.ctid);
  4697. //还要插入快递信息到 快递信息表
  4698. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4699. exinfo.tid = eid;
  4700. exinfo.out_sid = outSid;
  4701. exinfo.company_code = comCode;
  4702. exinfo.company_name = comName;
  4703. exinfo.delivery_memo = deliveryMemo;
  4704. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4705. exinfo.deliveryType = deliveryType;
  4706. exinfo.Create();
  4707. returnSuccessMsg("发货操作成功!");
  4708. commonHelper.UpdateRelationOrder(entity.ctid);
  4709. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4710. CeErpSukuraData.createInfo(entity.ctid, 4);
  4711. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  4712. {
  4713. commonHelper.sendCytExpress(exinfo);
  4714. }
  4715. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4716. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4717. }
  4718. else
  4719. {
  4720. string errmsg = commonHelper.KeepChinese(apires);
  4721. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4722. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4723. }
  4724. return;
  4725. }
  4726. returnErrorMsg("找不到订单记录");
  4727. }
  4728. }
  4729. public void set_erp_multidelivery()
  4730. {
  4731. string eids = GetPostString("tids");
  4732. string[] eidList = eids.Split(',');
  4733. if (eidList.Length <= 0)
  4734. {
  4735. returnErrorMsg("发货不能为空");
  4736. return;
  4737. }
  4738. foreach (string ctid in eidList)
  4739. {
  4740. if (ctid.Length <= 0) continue;
  4741. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4742. if (expInfo != null)
  4743. {
  4744. StringBuilder sql = new StringBuilder();
  4745. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4746. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4747. if (dt.Rows.Count > 0)
  4748. {
  4749. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4750. {
  4751. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4752. expInfo.state = "异常";
  4753. expInfo.isMultiDelivery = 1;
  4754. expInfo.Update();
  4755. continue;
  4756. }
  4757. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4758. {
  4759. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4760. expInfo.state = "异常";
  4761. expInfo.Update();
  4762. continue;
  4763. }
  4764. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4765. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4766. bool isInitOrderDeliv = false;
  4767. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4768. {
  4769. isInitOrderDeliv = true;
  4770. expInfo.isMultiDelivery = 1;
  4771. }
  4772. if (ctid.IndexOf("N") != -1)
  4773. {
  4774. StringBuilder sqlbucha = new StringBuilder();
  4775. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4776. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4777. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4778. commonHelper.UpdateRelationOrder(ctid);
  4779. expInfo.delivery_memo = "发货成功";
  4780. expInfo.state = "发货成功";
  4781. expInfo.isMultiDelivery = 1;
  4782. expInfo.Update();
  4783. }
  4784. else
  4785. {
  4786. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4787. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4788. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4789. {
  4790. expInfo.delivery_memo = "发货成功";
  4791. expInfo.state = "发货成功";
  4792. expInfo.isMultiDelivery = 1;
  4793. expInfo.Update();
  4794. commonHelper.UpdateRelationOrder(ctid);
  4795. CeErpSukuraData.createInfo(ctid, 4);
  4796. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4797. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4798. }
  4799. else
  4800. {
  4801. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4802. expInfo.state = "异常";
  4803. expInfo.Update();
  4804. }
  4805. }
  4806. }
  4807. }
  4808. }
  4809. returnSuccessMsg("操作完成");
  4810. }
  4811. public void reset_erp_memoopt()
  4812. {
  4813. if (UrlPostParmsCheck("ctid"))
  4814. {
  4815. string eid = GetPostString("ctid");
  4816. CeErpTradeCell entity = null;
  4817. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4818. if (entity != null)
  4819. {
  4820. string stropt = "";
  4821. if (entity.MemoOpt == 1)
  4822. {
  4823. stropt = "“改稿”";
  4824. }
  4825. else if (entity.MemoOpt == 2)
  4826. {
  4827. stropt = "“定稿”";
  4828. }
  4829. else if (entity.MemoOpt == 3)
  4830. {
  4831. stropt = "“完成查货”";
  4832. CeErpSukuraData.createInfo(entity.ctid, 6);
  4833. }
  4834. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4835. entity.UpdateTime = DateTime.Now;
  4836. entity.MemoOpt = 0;
  4837. entity.Update();
  4838. returnSuccessMsg("操作成功!");
  4839. return;
  4840. }
  4841. returnErrorMsg("找不到记录");
  4842. }
  4843. }
  4844. public void get_erp_deliveryunusual()
  4845. {
  4846. DataStruct dStruct = GetPostStruct();
  4847. List<string> lw = new List<string>();
  4848. string tid = GetPostString("ctid");
  4849. if (tid.Length > 0)
  4850. {
  4851. string select_tid = getTidByCtid(tid);
  4852. lw.Add(string.Format("tid='{0}'", select_tid));
  4853. }
  4854. string shopname = GetPostString("shopname");
  4855. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4856. string buyernick = GetPostString("buyer_nick");
  4857. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4858. string customer = GetPostString("customer");
  4859. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4860. string design = GetPostString("design");
  4861. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4862. string sellermemo = GetPostString("seller_memo");
  4863. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4864. string supplier = GetPostString("supplier");
  4865. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4866. string date1 = GetPostString("date1");
  4867. string date2 = GetPostString("date2");
  4868. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4869. if (dw.Length > 0) lw.Add(dw);
  4870. string placedate1 = GetPostString("placedate1");
  4871. string placedate2 = GetPostString("placedate2");
  4872. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4873. if (dw_place.Length > 0) lw.Add(dw_place);
  4874. string price1 = GetPostString("price1");
  4875. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4876. string price2 = GetPostString("price2");
  4877. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4878. string unusualCon = GetPostString("unusualcon");
  4879. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4880. string posTag = CurrentUser.UserPost.Post.Code;
  4881. if (posTag == "Supplier")
  4882. {
  4883. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4884. }
  4885. lw.Add(string.Format("OrderState = 6"));
  4886. lw.Add(string.Format("UnusualTag = 5"));
  4887. lw.Add(string.Format("IsRefund<={0}", 1));
  4888. dStruct.Order = "FinishPlaceTime desc";
  4889. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4890. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4891. writeGridDataTableJson(dStruct.TotalCount, dt);
  4892. }
  4893. public void get_erp_deliveryedlist()
  4894. {
  4895. DataStruct dStruct = GetPostStruct();
  4896. List<string> lw = new List<string>();
  4897. string tid = GetPostString("ctid");
  4898. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4899. string shopname = GetPostString("shopname");
  4900. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4901. string buyernick = GetPostString("buyer_nick");
  4902. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4903. string customer = GetPostString("customer");
  4904. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4905. string design = GetPostString("design");
  4906. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4907. string sellermemo = GetPostString("seller_memo");
  4908. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4909. string logistics = GetPostString("logistics");
  4910. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4911. string date1 = GetPostString("date1");
  4912. string date2 = GetPostString("date2");
  4913. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4914. //if (dw.Length > 0) lw.Add(dw);
  4915. string placedate1 = GetPostString("placedate1");
  4916. string placedate2 = GetPostString("placedate2");
  4917. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4918. if (fdw.Length > 0) lw.Add(fdw);
  4919. string devdate1 = GetPostString("deliverydate1");
  4920. string devdate2 = GetPostString("deliverydate2");
  4921. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4922. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4923. string price1 = GetPostString("price1");
  4924. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4925. string price2 = GetPostString("price2");
  4926. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4927. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4928. {
  4929. if (tid.Length > 0)
  4930. {
  4931. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4932. if (tid.Length > 5)
  4933. {
  4934. List<string> tids = getTidByCtidLike(tid);
  4935. if (tids.Count > 0 && tids.Count < 10)
  4936. {
  4937. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4938. }
  4939. }
  4940. lw.Add(tid_sql);
  4941. }
  4942. if (buyernick.Length > 0)
  4943. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4944. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4945. if (dw.Length > 0) lw.Add(dw);
  4946. }
  4947. else
  4948. {
  4949. lw.Add(string.Format("pay_time >= DATEADD(DAY, -31, GETDATE()) "));
  4950. }
  4951. string posTag = CurrentUser.UserPost.Post.Code;
  4952. if (posTag == "Supplier")
  4953. {
  4954. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4955. }
  4956. else
  4957. {
  4958. string supplier = GetPostString("supplier");
  4959. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4960. }
  4961. lw.Add(string.Format(" OrderState IN (7, 8)"));
  4962. lw.Add(string.Format("type != 'PDD' "));
  4963. lw.Add(string.Format("IsRefund!={0}", 2));
  4964. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4965. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4966. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4967. /*if (tid.Length > 0)
  4968. {
  4969. List<string> tids = new List<string>();
  4970. if (dt != null && dt.Rows.Count > 0)
  4971. {
  4972. foreach (DataRow item in dt.Rows)
  4973. {
  4974. tids.Add("'" + item["tid"] + "'");
  4975. }
  4976. }
  4977. if (tids.Count > 0)
  4978. {
  4979. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4980. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4981. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4982. dt = WebCache.GetData("view_erptradecell", dStruct);
  4983. }
  4984. }*/
  4985. if (dt != null)
  4986. {
  4987. foreach (DataRow dr in dt.Rows)
  4988. {
  4989. 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();
  4990. }
  4991. }
  4992. writeGridDataTableJson(dStruct.TotalCount, dt);
  4993. }
  4994. public void get_erp_pdddeliveryed()
  4995. {
  4996. DataStruct dStruct = GetPostStruct();
  4997. List<string> lw = new List<string>();
  4998. string tid = GetPostString("ctid");
  4999. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5000. string shopname = GetPostString("shopname");
  5001. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5002. string buyernick = GetPostString("buyer_nick");
  5003. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5004. string customer = GetPostString("customer");
  5005. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5006. string design = GetPostString("design");
  5007. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5008. string sellermemo = GetPostString("seller_memo");
  5009. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5010. string logistics = GetPostString("logistics");
  5011. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  5012. string date1 = GetPostString("date1");
  5013. string date2 = GetPostString("date2");
  5014. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5015. //if (dw.Length > 0) lw.Add(dw);
  5016. string placedate1 = GetPostString("placedate1");
  5017. string placedate2 = GetPostString("placedate2");
  5018. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5019. if (fdw.Length > 0) lw.Add(fdw);
  5020. string devdate1 = GetPostString("deliverydate1");
  5021. string devdate2 = GetPostString("deliverydate2");
  5022. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5023. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5024. string price1 = GetPostString("price1");
  5025. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5026. string price2 = GetPostString("price2");
  5027. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5028. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5029. {
  5030. if (tid.Length > 0)
  5031. {
  5032. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  5033. if (tid.Length > 5)
  5034. {
  5035. List<string> tids = getTidByCtidLike(tid);
  5036. if (tids.Count > 0 && tids.Count < 10)
  5037. {
  5038. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  5039. }
  5040. }
  5041. lw.Add(tid_sql);
  5042. }
  5043. if (buyernick.Length > 0)
  5044. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5045. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5046. if (dw.Length > 0) lw.Add(dw);
  5047. }
  5048. else
  5049. {
  5050. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  5051. }
  5052. string posTag = CurrentUser.UserPost.Post.Code;
  5053. if (posTag == "Supplier")
  5054. {
  5055. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5056. }
  5057. else
  5058. {
  5059. string supplier = GetPostString("supplier");
  5060. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5061. }
  5062. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5063. lw.Add(string.Format("type = 'PDD' "));
  5064. lw.Add(string.Format("IsRefund!={0}", 2));
  5065. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5066. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5067. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5068. /* if (tid.Length > 0)
  5069. {
  5070. List<string> tids = new List<string>();
  5071. if (dt != null && dt.Rows.Count > 0)
  5072. {
  5073. foreach (DataRow item in dt.Rows)
  5074. {
  5075. tids.Add("'" + item["tid"] + "'");
  5076. }
  5077. }
  5078. if (tids.Count > 0)
  5079. {
  5080. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  5081. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  5082. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5083. dt = WebCache.GetData("view_erptradecell", dStruct);
  5084. }
  5085. }*/
  5086. foreach (DataRow dr in dt.Rows)
  5087. {
  5088. 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();
  5089. }
  5090. writeGridDataTableJson(dStruct.TotalCount, dt);
  5091. }
  5092. public void get_erp_jddeliveryed()
  5093. {
  5094. DataStruct dStruct = GetPostStruct();
  5095. List<string> lw = new List<string>();
  5096. string tid = GetPostString("ctid");
  5097. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5098. string shopname = GetPostString("shopname");
  5099. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5100. string buyernick = GetPostString("buyer_nick");
  5101. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5102. string customer = GetPostString("customer");
  5103. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5104. string design = GetPostString("design");
  5105. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5106. string sellermemo = GetPostString("seller_memo");
  5107. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5108. string date1 = GetPostString("date1");
  5109. string date2 = GetPostString("date2");
  5110. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5111. //if (dw.Length > 0) lw.Add(dw);
  5112. string placedate1 = GetPostString("placedate1");
  5113. string placedate2 = GetPostString("placedate2");
  5114. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5115. if (fdw.Length > 0) lw.Add(fdw);
  5116. string devdate1 = GetPostString("deliverydate1");
  5117. string devdate2 = GetPostString("deliverydate2");
  5118. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5119. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5120. string price1 = GetPostString("price1");
  5121. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5122. string price2 = GetPostString("price2");
  5123. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5124. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5125. {
  5126. if (tid.Length > 0)
  5127. lw.Add(string.Format("ctid like '%{0}%'", tid));
  5128. if (buyernick.Length > 0)
  5129. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5130. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5131. if (dw.Length > 0) lw.Add(dw);
  5132. }
  5133. else
  5134. {
  5135. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5136. }
  5137. string posTag = CurrentUser.UserPost.Post.Code;
  5138. if (posTag == "Supplier")
  5139. {
  5140. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5141. }
  5142. else
  5143. {
  5144. string supplier = GetPostString("supplier");
  5145. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5146. }
  5147. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  5148. lw.Add(string.Format("type = 'JD' "));
  5149. lw.Add(string.Format("IsRefund!={0}", 2));
  5150. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5151. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5152. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  5153. foreach (DataRow dr in dt.Rows)
  5154. {
  5155. 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();
  5156. }
  5157. writeGridDataTableJson(dStruct.TotalCount, dt);
  5158. }
  5159. public void get_erp_allplacelist()
  5160. {
  5161. DataStruct dStruct = GetPostStruct();
  5162. List<string> lw = new List<string>();
  5163. string tid = GetPostString("ctid");
  5164. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5165. string shopname = GetPostString("shopname");
  5166. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5167. string buyernick = GetPostString("buyer_nick");
  5168. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5169. string customer = GetPostString("customer");
  5170. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5171. string design = GetPostString("design");
  5172. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5173. string sellermemo = GetPostString("seller_memo");
  5174. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5175. string supplier = GetPostString("supplier");
  5176. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5177. string date1 = GetPostString("date1");
  5178. string date2 = GetPostString("date2");
  5179. string pldate1 = GetPostString("placedate1");
  5180. string pldate2 = GetPostString("placedate2");
  5181. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5182. //if (dw.Length > 0) lw.Add(dw);
  5183. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5184. {
  5185. if (tid.Length > 0)
  5186. {
  5187. string select_tid = getTidByCtid(tid);
  5188. lw.Add(string.Format("tid='{0}'", select_tid));
  5189. }
  5190. if (buyernick.Length > 0)
  5191. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5192. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5193. if (dw.Length > 0) lw.Add(dw);
  5194. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5195. if (dw_place.Length > 0) lw.Add(dw_place);
  5196. }
  5197. else
  5198. {
  5199. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5200. {
  5201. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5202. }
  5203. }
  5204. string price1 = GetPostString("price1");
  5205. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5206. string price2 = GetPostString("price2");
  5207. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5208. string posTag = CurrentUser.UserPost.Post.Code;
  5209. if (posTag == "Supplier")
  5210. {
  5211. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5212. }
  5213. lw.Add(string.Format("OrderState >= 6"));
  5214. lw.Add(string.Format("IsSample != 2 "));
  5215. //lw.Add(string.Format("isDianziOrder = 0 "));
  5216. lw.Add(string.Format("SupplierId > 0 "));
  5217. //lw.Add(string.Format("IsRefund<={0}", 1));
  5218. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5219. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5220. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5221. foreach (DataRow dr in dt.Rows)
  5222. {
  5223. 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();
  5224. }
  5225. writeGridDataTableJson(dStruct.TotalCount, dt);
  5226. }
  5227. public void get_erp_financeallplacelist()
  5228. {
  5229. DataStruct dStruct = GetPostStruct();
  5230. List<string> lw = new List<string>();
  5231. string tid = GetPostString("ctid");
  5232. string shopname = GetPostString("shopname");
  5233. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5234. string buyernick = GetPostString("buyer_nick");
  5235. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5236. string customer = GetPostString("customer");
  5237. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5238. string design = GetPostString("design");
  5239. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5240. string sellermemo = GetPostString("seller_memo");
  5241. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5242. string supplier = GetPostString("supplier");
  5243. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5244. string date1 = GetPostString("date1");
  5245. string date2 = GetPostString("date2");
  5246. string pldate1 = GetPostString("placedate1");
  5247. string pldate2 = GetPostString("placedate2");
  5248. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5249. {
  5250. if (tid.Length > 0)
  5251. {
  5252. string select_tid = getTidByCtid(tid);
  5253. lw.Add(string.Format("tid='{0}'", select_tid));
  5254. }
  5255. if (buyernick.Length > 0)
  5256. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5257. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5258. if (dw.Length > 0) lw.Add(dw);
  5259. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5260. if (dw_place.Length > 0) lw.Add(dw_place);
  5261. }
  5262. else
  5263. {
  5264. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5265. {
  5266. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5267. }
  5268. }
  5269. string price1 = GetPostString("price1");
  5270. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5271. string price2 = GetPostString("price2");
  5272. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5273. string posTag = CurrentUser.UserPost.Post.Code;
  5274. if (posTag == "Supplier")
  5275. {
  5276. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5277. }
  5278. //lw.Add(string.Format("OrderState >= 6"));
  5279. lw.Add(string.Format("IsSample != 2 "));
  5280. lw.Add(string.Format("isDianziOrder = 0 "));
  5281. //lw.Add(string.Format("IsRefund<={0}", 1));
  5282. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5283. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5284. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5285. foreach (DataRow dr in dt.Rows)
  5286. {
  5287. 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();
  5288. }
  5289. writeGridDataTableJson(dStruct.TotalCount, dt);
  5290. }
  5291. public void get_erp_expresslist()
  5292. {
  5293. int listtype = GetInt("ltype");
  5294. DataStruct dStruct = GetPostStruct();
  5295. List<string> lw = new List<string>();
  5296. string tid = GetPostString("tid");
  5297. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5298. string outsid = GetPostString("out_sid");
  5299. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5300. string importer = GetPostString("ImportUserName");
  5301. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5302. string file = GetPostString("import_file");
  5303. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5304. string printman = GetPostString("printman");
  5305. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5306. string date1 = GetPostString("date1");
  5307. string date2 = GetPostString("date2");
  5308. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5309. if (dw.Length > 0) lw.Add(dw);
  5310. string fdate1 = GetPostString("finishdate1");
  5311. string fdate2 = GetPostString("finishdate2");
  5312. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5313. if (fdw.Length > 0) lw.Add(fdw);
  5314. string supplierId = GetPostString("supplierId");
  5315. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5316. if (listtype == 1)
  5317. {
  5318. lw.Add(string.Format("importUserId !=0"));
  5319. }
  5320. string posTag = CurrentUser.UserPost.Post.Code;
  5321. if (posTag == "Supplier")
  5322. {
  5323. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5324. }
  5325. if (dStruct.PageSize != 100000)
  5326. {
  5327. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5328. }
  5329. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5330. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5331. writeGridDataTableJson(dStruct.TotalCount, dt);
  5332. }
  5333. public void set_erp_buchaorderdelivery()
  5334. {
  5335. if (UrlPostParmsCheck("ctid"))
  5336. {
  5337. string eid = GetPostString("ctid");
  5338. CeErpTradeCell entity = null;
  5339. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5340. if (entity != null)
  5341. {
  5342. if (entity.IsSample != 2)
  5343. {
  5344. returnErrorMsg("补差价单才能标记为已发货");
  5345. return;
  5346. }
  5347. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5348. entity.OrderState = 7;
  5349. entity.Update();
  5350. returnSuccessMsg("操作成功!");
  5351. return;
  5352. }
  5353. returnErrorMsg("找不到记录");
  5354. }
  5355. }
  5356. public void get_stdtemplates()
  5357. {
  5358. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5359. //string res = taobaoHelper.test();
  5360. string res = apiHelper.API_PrintTemplate();
  5361. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5362. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5363. {
  5364. int sidx = res.IndexOf("error_code");
  5365. int eidx = res.IndexOf("success");
  5366. string msg = res.Substring(sidx, eidx - sidx);
  5367. returnErrorMsg(msg);
  5368. return;
  5369. }
  5370. if (res.Length <= 0)
  5371. {
  5372. returnErrorMsg("模板数据为空!");
  5373. return;
  5374. }
  5375. ReturnSuccess(res);
  5376. }
  5377. public void cancel_print_order()
  5378. {
  5379. if (UrlPostParmsCheck("ctid"))
  5380. {
  5381. string ctid = GetPostString("ctid");
  5382. CeErpTradeCell entity = null;
  5383. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5384. if (entity != null)
  5385. {
  5386. string res = "";
  5387. string code = entity.LastBillWaybillCode;
  5388. if (code == "")
  5389. {
  5390. code = entity.OutSid;
  5391. }
  5392. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5393. XLog.SaveLog(0, "取消面单" + res);
  5394. }
  5395. }
  5396. }
  5397. public void set_erp_printwaybill()
  5398. {
  5399. if (UrlPostParmsCheck("ctid"))
  5400. {
  5401. string ctid = GetPostString("ctid");
  5402. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5403. string cpName = GetPostString("cpname");
  5404. string isTogether = GetPostString("together");
  5405. string printType = GetPostString("printType");
  5406. //var res_obj = new
  5407. //{
  5408. // restype = 1,
  5409. // 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\"}"
  5410. //};
  5411. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5412. //ReturnSuccess(ro_json);
  5413. //return;
  5414. bool isUseLastWayBillCode = false;
  5415. CeErpTradeCell entity = null;
  5416. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5417. if (entity != null)
  5418. {
  5419. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5420. {
  5421. isUseLastWayBillCode = true;
  5422. }
  5423. if (entity.OrderState == 7 && "delivering".Equals(printType))
  5424. {
  5425. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5426. return;
  5427. }
  5428. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5429. {
  5430. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5431. return;
  5432. }
  5433. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5434. {
  5435. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5436. return;
  5437. }
  5438. }
  5439. string res = "";
  5440. Api_waybill_code_response_Obj fullObj = null;
  5441. string pData_str = "";
  5442. string curUseWayBillCode = "";
  5443. if (isUseLastWayBillCode == false)
  5444. {
  5445. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5446. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5447. if (res.IndexOf("failure") != -1)
  5448. {
  5449. //int idx = res.IndexOf("sub_message");
  5450. //int idx2 = res.IndexOf("flag");
  5451. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5452. string errMsgNeed = commonHelper.KeepChinese(res);
  5453. var res_objd = new
  5454. {
  5455. restype = 0,
  5456. data = "获取面单失败" + errMsgNeed
  5457. };
  5458. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5459. returnSuccess(ro_jsond);
  5460. if (res.IndexOf("停发") != -1)
  5461. {
  5462. entity.UnusualCon = "物流停发";
  5463. entity.Update();
  5464. }
  5465. //returnErrorMsg("获取面单失败,"+emsg);
  5466. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5467. return;
  5468. }
  5469. else if (res.IndexOf("errorMsg") != -1)
  5470. {
  5471. //int idx = res.IndexOf("errorMsg");
  5472. //int idx2 = res.IndexOf("}]}");
  5473. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5474. string errMsgNeed = commonHelper.KeepChinese(res);
  5475. var res_objf = new
  5476. {
  5477. restype = 0,
  5478. data = "获取面单失败2" + errMsgNeed
  5479. };
  5480. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5481. if (res.IndexOf("停发") != -1)
  5482. {
  5483. entity.UnusualCon = "物流停发";
  5484. entity.Update();
  5485. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5486. if (trade != null)
  5487. {
  5488. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5489. }
  5490. }
  5491. returnSuccess(ro_jsonf);
  5492. //returnErrorMsg("获取面单失败," + emsg);
  5493. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5494. return;
  5495. }
  5496. try
  5497. {
  5498. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5499. //res = res.Replace(" ", "");
  5500. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5501. }
  5502. catch (Exception ex)
  5503. {
  5504. XLog.SaveLog(0, "生成fullObj" + res);
  5505. var res_objf = new
  5506. {
  5507. restype = 0,
  5508. data = "生成fullObj发生错误" + ex.Message
  5509. };
  5510. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5511. returnSuccess(ro_jsonf);
  5512. return;
  5513. }
  5514. if (fullObj.response.data.content.Count > 0)
  5515. {
  5516. ContentItem codeObj = fullObj.response.data.content[0];
  5517. if (cpCode.IndexOf("SFFQ-") != -1)
  5518. {
  5519. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5520. }
  5521. else
  5522. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5523. curUseWayBillCode = codeObj.waybillCode;
  5524. }
  5525. else
  5526. {
  5527. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5528. var res_objf = new
  5529. {
  5530. restype = 0,
  5531. data = "生成fullObj找不到快递单号waybillCode"
  5532. };
  5533. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5534. returnSuccess(ro_jsonf);
  5535. return;
  5536. }
  5537. }
  5538. else
  5539. {
  5540. //使用上次打印的快递单号
  5541. if (cpCode == "SFFQ-LY")
  5542. {
  5543. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5544. }
  5545. else
  5546. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5547. curUseWayBillCode = entity.LastBillWaybillCode;
  5548. }
  5549. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5550. {
  5551. var res_obje = new
  5552. {
  5553. restype = 0,
  5554. data = "获取加密打印数据失败"
  5555. };
  5556. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5557. returnSuccess(ro_jsone);
  5558. entity.LastBillCpCode = cpCode;
  5559. entity.LastBillWaybillCode = curUseWayBillCode;
  5560. entity.Update();
  5561. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5562. //returnErrorMsg("获取加密打印数据失败");
  5563. return;
  5564. }
  5565. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5566. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5567. string btnType = "";
  5568. string errorMsg = "";
  5569. if (entity != null)
  5570. {
  5571. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5572. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5573. //cpcode是 YTO-CAINIAO
  5574. //string comCode = cpCode.Split('-')[0].ToString();
  5575. string apires = "";
  5576. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5577. //isTogether=2是新的合包弹窗
  5578. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5579. {
  5580. if (ctid.IndexOf("N") != -1)
  5581. {
  5582. apires = "发货成功";
  5583. }
  5584. else
  5585. {
  5586. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5587. }
  5588. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5589. //打单后发货
  5590. StringBuilder sql = new StringBuilder();
  5591. sql.AppendFormat("select ctid from CE_ErpTradeCell where SupplierId={0} ", entity.SupplierId);
  5592. if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) > 0)
  5593. {
  5594. sql.AppendFormat(" and tid = '{0}'", mainEn.tid);
  5595. }
  5596. else
  5597. {
  5598. sql.AppendFormat(" and ctid = '{0}'", entity.ctid);
  5599. }
  5600. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5601. foreach (DataRow row in dt.Rows)
  5602. {
  5603. entity = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5604. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5605. {
  5606. try
  5607. {
  5608. btnType = "待发货";
  5609. entity.OutSid = curUseWayBillCode;
  5610. entity.OrderState = 7;
  5611. entity.IsUrgency = false;
  5612. entity.LastBillCpCode = "";
  5613. entity.LastBillWaybillCode = "";
  5614. entity.FinishDeliveryTime = DateTime.Now;
  5615. entity.IsReturn = 0;
  5616. entity.MemoOpt = 0;
  5617. entity.UpdateTime = DateTime.Now;
  5618. entity.Update();
  5619. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5620. //还要插入快递信息到 快递信息表
  5621. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5622. exinfo.tid = entity.ctid;
  5623. exinfo.out_sid = curUseWayBillCode;
  5624. exinfo.company_code = cpCode;
  5625. exinfo.company_name = cpName;
  5626. exinfo.supplierUserName = supplierName;
  5627. exinfo.deliveryType = "发货成功";
  5628. exinfo.print_time = DateTime.Now;
  5629. exinfo.printUser = CurrentUser.UserName;
  5630. exinfo.postData = pData_str;
  5631. exinfo.Create();
  5632. commonHelper.UpdateRelationOrder(entity.ctid);
  5633. CeErpSukuraData.createInfo(ctid, 4);
  5634. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5635. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5636. {
  5637. commonHelper.sendCytExpress(exinfo);
  5638. }
  5639. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5640. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5641. }
  5642. catch (Exception ex)
  5643. {
  5644. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5645. }
  5646. }
  5647. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5648. {
  5649. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5650. if (entity.OrderState == 6)
  5651. {
  5652. entity.OrderState = 7;
  5653. }
  5654. entity.UpdateTime = DateTime.Now;
  5655. entity.FinishDeliveryTime = DateTime.Now;
  5656. btnType = "已发货";
  5657. entity.Update();
  5658. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5659. exinfo.tid = entity.ctid;
  5660. exinfo.out_sid = curUseWayBillCode;
  5661. exinfo.company_code = cpCode;
  5662. exinfo.company_name = cpName;
  5663. exinfo.supplierUserName = supplierName;
  5664. exinfo.deliveryType = "发货成功";
  5665. exinfo.print_time = DateTime.Now;
  5666. exinfo.printUser = CurrentUser.UserName;
  5667. exinfo.postData = pData_str;
  5668. exinfo.Create();
  5669. commonHelper.UpdateRelationOrder(entity.ctid);
  5670. CeErpSukuraData.createInfo(entity.ctid, 4);
  5671. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5672. {
  5673. commonHelper.sendCytExpress(exinfo);
  5674. }
  5675. //不处理
  5676. }
  5677. else
  5678. {
  5679. entity.UpdateTime = DateTime.Now;
  5680. entity.LastBillCpCode = cpCode;
  5681. entity.LastBillWaybillCode = curUseWayBillCode;
  5682. entity.Update();
  5683. string errmsg = commonHelper.KeepChinese(apires);
  5684. var res_objz = new
  5685. {
  5686. restype = 0,
  5687. data = "打单后发货失败"
  5688. };
  5689. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5690. returnSuccess(ro_jsonz);
  5691. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5692. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5693. return;
  5694. }
  5695. }
  5696. }
  5697. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5698. {
  5699. string ctids = GetPostString("ctids");
  5700. DataTable dt = commonHelper.getSameOrderList(entity, mainEn);
  5701. List<string> list = new List<string>();
  5702. List<string> send_list = new List<string>();
  5703. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5704. CeErpTrade ceErpTrade = new CeErpTrade();
  5705. //可合包的合并一起发货
  5706. if (dt == null && string.IsNullOrEmpty(ctids))
  5707. {
  5708. var res_objz = new
  5709. {
  5710. restype = 0,
  5711. data = "打单后发货失败"
  5712. };
  5713. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5714. returnSuccess(ro_jsonz);
  5715. return;
  5716. }
  5717. if (!string.IsNullOrEmpty(ctids))
  5718. {
  5719. StringBuilder sql = new StringBuilder();
  5720. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  5721. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  5722. }
  5723. foreach (DataRow row in dt.Rows)
  5724. {
  5725. list.Add("'" + row["ctid"] + "'");
  5726. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5727. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5728. if (ctid.IndexOf("N") != -1)
  5729. {
  5730. apires = "发货成功";
  5731. }
  5732. else
  5733. {
  5734. if (!send_list.Contains(ceErpTrade.tid))
  5735. {
  5736. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5737. }
  5738. else
  5739. {
  5740. apires = "发货成功";
  5741. }
  5742. }
  5743. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5744. {
  5745. send_list.Add(ceErpTrade.tid);
  5746. try
  5747. {
  5748. btnType = "待发货";
  5749. ceErpTradeCell.OutSid = curUseWayBillCode;
  5750. ceErpTradeCell.OrderState = 7;
  5751. ceErpTradeCell.IsUrgency = false;
  5752. ceErpTradeCell.LastBillCpCode = "";
  5753. ceErpTradeCell.LastBillWaybillCode = "";
  5754. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5755. ceErpTradeCell.IsReturn = 0;
  5756. ceErpTradeCell.MemoOpt = 0;
  5757. ceErpTradeCell.UpdateTime = DateTime.Now;
  5758. ceErpTradeCell.Update();
  5759. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5760. //还要插入快递信息到 快递信息表
  5761. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5762. exinfo.tid = ceErpTradeCell.ctid;
  5763. exinfo.out_sid = curUseWayBillCode;
  5764. exinfo.company_code = cpCode;
  5765. exinfo.company_name = cpName;
  5766. exinfo.supplierUserName = supplierName;
  5767. exinfo.deliveryType = "发货成功";
  5768. exinfo.print_time = DateTime.Now;
  5769. exinfo.printUser = CurrentUser.UserName;
  5770. exinfo.postData = pData_str;
  5771. exinfo.Create();
  5772. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5773. CeErpSukuraData.createInfo(ctid, 4);
  5774. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5775. if (ceErpTradeCell.SupplierId == 64 || ceErpTradeCell.SupplierId == 80)
  5776. {
  5777. commonHelper.sendCytExpress(exinfo);
  5778. }
  5779. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5780. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5781. }
  5782. catch (Exception ex)
  5783. {
  5784. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5785. }
  5786. }
  5787. else
  5788. {
  5789. ceErpTradeCell.UpdateTime = DateTime.Now;
  5790. ceErpTradeCell.LastBillCpCode = cpCode;
  5791. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5792. ceErpTradeCell.Update();
  5793. string errmsg = commonHelper.KeepChinese(apires);
  5794. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5795. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5796. }
  5797. }
  5798. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5799. }
  5800. }
  5801. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5802. var res_obj = new
  5803. {
  5804. restype = 1,
  5805. data = pData_str,
  5806. errorMsg
  5807. };
  5808. string ro_json = JsonConvert.SerializeObject(res_obj);
  5809. ReturnSuccess(ro_json);
  5810. return;
  5811. }
  5812. }
  5813. private string GetUTF8String(byte[] vs)
  5814. {
  5815. throw new NotImplementedException();
  5816. }
  5817. public void set_erp_printwaybill_cn()
  5818. {
  5819. if (UrlPostParmsCheck("ctid"))
  5820. {
  5821. string ctid = GetPostString("ctid");
  5822. string cpCode = GetPostString("cpcode");
  5823. string cpName = GetPostString("cpname");
  5824. string tempUrl = GetPostString("tempurl");
  5825. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5826. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5827. //string res = taobaoHelper.test();
  5828. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5829. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5830. {
  5831. int sidx = res.IndexOf("errorMsg");
  5832. int eidx = res.IndexOf("}");
  5833. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5834. var res_objzxx = new
  5835. {
  5836. restype = 0,
  5837. data = msg
  5838. };
  5839. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5840. returnSuccess(ro_jsonzxx);
  5841. //returnErrorMsg(msg);
  5842. return;
  5843. }
  5844. int idx = res.IndexOf("waybillCode");
  5845. int idx2 = res.IndexOf("printData");
  5846. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5847. string eid = GetPostString("ctid");
  5848. CeErpTradeCell entity = null;
  5849. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5850. if (entity != null)
  5851. {
  5852. string osid = entity.OutSid;
  5853. entity.OutSid = osid + "," + outsid;
  5854. entity.FinishDeliveryTime = DateTime.Now;
  5855. entity.OrderState = 7;
  5856. entity.UpdateTime = DateTime.Now;
  5857. entity.IsReturn = 0;
  5858. entity.Update();
  5859. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5860. exinfo.tid = entity.ctid;
  5861. exinfo.out_sid = outsid;
  5862. exinfo.company_code = cpCode;
  5863. exinfo.company_name = cpName;
  5864. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5865. exinfo.deliveryType = "发货成功";
  5866. exinfo.print_time = DateTime.Now;
  5867. exinfo.printUser = CurrentUser.UserName;
  5868. exinfo.Create();
  5869. if (entity.SupplierId == 64 || entity.SupplierId == 80)
  5870. {
  5871. commonHelper.sendCytExpress(exinfo);
  5872. }
  5873. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5874. }
  5875. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5876. var res_objz = new
  5877. {
  5878. restype = 1,
  5879. data = res
  5880. };
  5881. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5882. returnSuccess(ro_jsonz);
  5883. //ReturnSuccess(res);
  5884. }
  5885. }
  5886. ////打单,打印面单 获取面单号
  5887. //public void set_erp_printwaybill()
  5888. //{
  5889. // if (UrlPostParmsCheck("ctid"))
  5890. // {
  5891. // string ctid = GetPostString("ctid");
  5892. // string cpCode = GetPostString("cpcode");
  5893. // string tempUrl = GetPostString("tempurl");
  5894. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5895. // //string res = taobaoHelper.test();
  5896. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5897. // if (res.IndexOf("error_response") != -1)
  5898. // {
  5899. // int sidx = res.IndexOf("sub_msg");
  5900. // int eidx = res.IndexOf("request_id");
  5901. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5902. // returnErrorMsg(msg);
  5903. // return;
  5904. // }
  5905. // int idx = res.IndexOf("waybill_code");
  5906. // int idx2 = res.IndexOf("}]}");
  5907. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5908. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5909. // ReturnSuccess(res);
  5910. // }
  5911. //}
  5912. public void cancel_erp_aftersale()
  5913. {
  5914. if (UrlPostParmsCheck("ctid"))
  5915. {
  5916. string eid = GetPostString("ctid");
  5917. CeErpTradeCell entity = null;
  5918. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5919. if (entity != null)
  5920. {
  5921. //有过处理的售后,取消也不能删除 售 字,保留
  5922. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5923. {
  5924. entity.AfterSaleState = 4;
  5925. }
  5926. else
  5927. entity.AfterSaleState = 0;
  5928. entity.UpdateTime = DateTime.Now;
  5929. entity.Update();
  5930. returnSuccessMsg("操作成功!");
  5931. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5932. return;
  5933. }
  5934. returnErrorMsg("找不到订单记录");
  5935. }
  5936. }
  5937. public void get_erp_aftersalelist()
  5938. {
  5939. DataStruct dStruct = GetPostStruct();
  5940. List<string> lw = new List<string>();
  5941. int st = GetInt("st");
  5942. string tid = GetPostString("ctid");
  5943. if (st == 3)
  5944. {
  5945. if (tid.Length > 0)
  5946. {
  5947. string select_tid = getTidByCtid(tid);
  5948. lw.Add(string.Format("tid='{0}'", select_tid));
  5949. }
  5950. }
  5951. else
  5952. {
  5953. if (tid.Length > 0)
  5954. {
  5955. string select_tid = getTidByCtid(tid);
  5956. lw.Add(string.Format("tid='{0}'", select_tid));
  5957. }
  5958. }
  5959. string shopname = GetPostString("shopname");
  5960. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5961. string buyernick = GetPostString("buyer_nick");
  5962. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5963. string sellermemo = GetPostString("seller_memo");
  5964. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5965. string orderState = GetPostString("orderState");
  5966. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5967. string afterState = GetPostString("afterstate");
  5968. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5969. string date1 = GetPostString("date1");
  5970. string date2 = GetPostString("date2");
  5971. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5972. if (dw.Length > 0) lw.Add(dw);
  5973. string price1 = GetPostString("price1");
  5974. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5975. string price2 = GetPostString("price2");
  5976. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5977. //lw.Add(string.Format("IsRefund!={0}", 1));
  5978. string reason = GetPostString("reason");
  5979. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5980. string method = GetPostString("method");
  5981. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5982. string handler = GetPostString("handler");
  5983. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5984. string handledate1 = GetPostString("handledate1");
  5985. string handledate2 = GetPostString("handledate2");
  5986. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5987. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5988. string finish1 = GetPostString("finishdate1");
  5989. string finish2 = GetPostString("finishdate2");
  5990. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5991. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5992. string afterdate1 = GetPostString("afterdate1");
  5993. string afterdate2 = GetPostString("afterdate2");
  5994. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5995. if (afterDate.Length > 0) lw.Add(afterDate);
  5996. string supplier = GetPostString("supplier");
  5997. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5998. string responsible = GetPostString("responsibleman");
  5999. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6000. string customer = GetPostString("customer");
  6001. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6002. string design = GetPostString("design");
  6003. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6004. string afterMemoType = GetPostString("aftermemotype");
  6005. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6006. string posCode = CurrentUser.UserPost.Post.Code;
  6007. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  6008. //{
  6009. // string vstate = GetPostString("vstate");
  6010. // if (vstate.Length > 0)
  6011. // {
  6012. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6013. // }
  6014. // if (posCode == "Supplier")
  6015. // {
  6016. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6017. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6018. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6019. // }
  6020. // else
  6021. // {
  6022. // lw.Add(string.Format("AfterSaleState = {0}", st));
  6023. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  6024. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  6025. // {
  6026. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  6027. // }
  6028. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  6029. // {
  6030. // int orgid = CurrentUser.UserPost.OrgID;
  6031. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  6032. // }
  6033. // else if (CurrentUser.UserPost.Post.Code == "Director")
  6034. // {
  6035. // string shopid = CurrentUser.User.pemShop;
  6036. // lw.Add(string.Format("shopId in ({0})", shopid));
  6037. // }
  6038. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6039. // //{
  6040. // // int org_id = CurrentUser.UserPost.OrgID;
  6041. // // lw.Add(string.Format("OrgID={0}", org_id));
  6042. // //}
  6043. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  6044. // }
  6045. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6046. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6047. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6048. //}
  6049. if (st == 5)
  6050. {
  6051. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  6052. {
  6053. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  6054. {
  6055. string shopid = CurrentUser.User.pemShop;
  6056. lw.Add(string.Format("shopId in ({0})", shopid));
  6057. }
  6058. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  6059. {
  6060. int mrOrgid = CurrentUser.UserPost.OrgID;
  6061. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  6062. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  6063. }
  6064. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  6065. //{
  6066. // int mrOrgid = CurrentUser.UserPost.OrgID;
  6067. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  6068. //}
  6069. else
  6070. {
  6071. string userIdStr = "";
  6072. if (posCode == "CustomerService")
  6073. {
  6074. userIdStr = CurrentUser.UserID + "_k";
  6075. }
  6076. else if (posCode == "Designer" || posCode == "wxDesigner")
  6077. {
  6078. userIdStr = CurrentUser.UserID + "_s";
  6079. }
  6080. else if (posCode == "Place")
  6081. {
  6082. userIdStr = CurrentUser.UserID + "_x";
  6083. }
  6084. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  6085. }
  6086. }
  6087. string placedate1 = GetPostString("placedate1");
  6088. string placedate2 = GetPostString("placedate2");
  6089. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6090. if (dwplace.Length > 0) lw.Add(dwplace);
  6091. string supState = GetPostString("supState");
  6092. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6093. string searchType = GetPostString("searchType");
  6094. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6095. {
  6096. lw.Add(string.Format("BackNum>1"));
  6097. }
  6098. lw.Add(string.Format("AfterSaleState>0"));
  6099. if (ex_psize > 0)
  6100. {
  6101. if (CurrentUser.UserPost.Post.Code == "Finance")
  6102. dStruct.Order = "pay_time desc";
  6103. else
  6104. dStruct.Order = "HandleTime desc";
  6105. }
  6106. else
  6107. dStruct.Order = "HandleTime desc";
  6108. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6109. DataTable dt = WebCache.GetData("view_test", dStruct);
  6110. writeGridDataTableJson(dStruct.TotalCount, dt);
  6111. }
  6112. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6113. //{
  6114. // lw.Add(string.Format("AfterSaleState=4"));
  6115. // string code = CurrentUser.UserPost.Post.Code;
  6116. // if (code == "CustomerService")
  6117. // {
  6118. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6119. // }
  6120. // else if (code == "Designer" || code == "DesignerMr")
  6121. // {
  6122. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6123. // }
  6124. // else if (code == "Place" || code == "PlaceMr")
  6125. // {
  6126. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6127. // }
  6128. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6129. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6130. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6131. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6132. //}
  6133. //else //处理中的售后,待处理和处理中合并
  6134. //{
  6135. // if (afterState.Length <= 0)
  6136. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6137. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6138. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6139. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6140. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6141. //}
  6142. }
  6143. public void get_erp_disagreeftersalelist()
  6144. {
  6145. DataStruct dStruct = GetPostStruct();
  6146. List<string> lw = new List<string>();
  6147. int st = 2;
  6148. string tid = GetPostString("ctid");
  6149. if (tid.Length > 0)
  6150. {
  6151. string select_tid = getTidByCtid(tid);
  6152. lw.Add(string.Format("tid='{0}'", select_tid));
  6153. }
  6154. string shopname = GetPostString("shopname");
  6155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6156. string buyernick = GetPostString("buyer_nick");
  6157. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6158. string sellermemo = GetPostString("seller_memo");
  6159. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6160. string orderState = GetPostString("orderState");
  6161. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6162. string afterState = GetPostString("afterstate");
  6163. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6164. string date1 = GetPostString("date1");
  6165. string date2 = GetPostString("date2");
  6166. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6167. if (dw.Length > 0) lw.Add(dw);
  6168. string price1 = GetPostString("price1");
  6169. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6170. string price2 = GetPostString("price2");
  6171. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6172. //lw.Add(string.Format("IsRefund!={0}", 1));
  6173. string reason = GetPostString("reason");
  6174. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6175. string method = GetPostString("method");
  6176. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6177. string handler = GetPostString("handler");
  6178. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6179. string handledate1 = GetPostString("handledate1");
  6180. string handledate2 = GetPostString("handledate2");
  6181. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6182. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6183. string afterdate1 = GetPostString("afterdate1");
  6184. string afterdate2 = GetPostString("afterdate2");
  6185. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6186. if (afterDate.Length > 0) lw.Add(afterDate);
  6187. string backdate1 = GetPostString("backdate1");
  6188. string backdate2 = GetPostString("backdate2");
  6189. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6190. if (backDate.Length > 0) lw.Add(backDate);
  6191. string supplier = GetPostString("supplier");
  6192. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6193. string responsible = GetPostString("responsibleman");
  6194. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6195. string customer = GetPostString("customer");
  6196. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6197. string design = GetPostString("design");
  6198. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6199. string afterSaleMemo = GetPostString("afterSaleMemo");
  6200. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6201. string afterMemoType = GetPostString("aftermemotype");
  6202. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6203. string aftersakereason = GetPostString("aftersakereason");
  6204. if (aftersakereason.Length > 0)
  6205. {
  6206. if (aftersakereason == "1")
  6207. {
  6208. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6209. }
  6210. if (aftersakereason == "2")
  6211. {
  6212. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6213. }
  6214. }
  6215. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6216. string poscode = CurrentUser.UserPost.Post.Code;
  6217. if (poscode != "SysAdmin")
  6218. {
  6219. string shopid = CurrentUser.User.pemShop;
  6220. lw.Add(string.Format("shopId in ({0})", shopid));
  6221. }
  6222. string searchType = GetPostString("searchType");
  6223. if (searchType == "wait")
  6224. {
  6225. lw.Add(string.Format("HandleTime is null"));
  6226. }
  6227. if (searchType == "handling")
  6228. {
  6229. lw.Add(string.Format("HandleTime is not null "));
  6230. }
  6231. if (searchType == "back" || searchType == "puBack")
  6232. {
  6233. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6234. }
  6235. if (searchType == "reBack")
  6236. {
  6237. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6238. }
  6239. if (searchType == "moreBack")
  6240. {
  6241. lw.Add(string.Format("backNum > 1"));
  6242. }
  6243. lw.Add(string.Format("(AfterSaleState=5)"));
  6244. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6245. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6246. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6247. writeGridDataTableJson(dStruct.TotalCount, dt);
  6248. }
  6249. public void get_erp_handlingaftersalelist()
  6250. {
  6251. DataStruct dStruct = GetPostStruct();
  6252. List<string> lw = new List<string>();
  6253. int st = 2;
  6254. string tid = GetPostString("ctid");
  6255. if (tid.Length > 0)
  6256. {
  6257. string select_tid = getTidByCtid(tid);
  6258. lw.Add(string.Format("tid='{0}'", select_tid));
  6259. }
  6260. string shopname = GetPostString("shopname");
  6261. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6262. string buyernick = GetPostString("buyer_nick");
  6263. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6264. string sellermemo = GetPostString("seller_memo");
  6265. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6266. string orderState = GetPostString("orderState");
  6267. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6268. string afterState = GetPostString("afterstate");
  6269. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6270. string date1 = GetPostString("date1");
  6271. string date2 = GetPostString("date2");
  6272. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6273. if (dw.Length > 0) lw.Add(dw);
  6274. string price1 = GetPostString("price1");
  6275. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6276. string price2 = GetPostString("price2");
  6277. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6278. //lw.Add(string.Format("IsRefund!={0}", 1));
  6279. string reason = GetPostString("reason");
  6280. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6281. string method = GetPostString("method");
  6282. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6283. string handler = GetPostString("handler");
  6284. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6285. string handledate1 = GetPostString("handledate1");
  6286. string handledate2 = GetPostString("handledate2");
  6287. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6288. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6289. string afterdate1 = GetPostString("afterdate1");
  6290. string afterdate2 = GetPostString("afterdate2");
  6291. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6292. if (afterDate.Length > 0) lw.Add(afterDate);
  6293. string supplier = GetPostString("supplier");
  6294. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6295. string responsible = GetPostString("responsibleman");
  6296. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6297. string customer = GetPostString("customer");
  6298. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6299. string design = GetPostString("design");
  6300. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6301. string afterSaleMemo = GetPostString("afterSaleMemo");
  6302. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6303. string afterMemoType = GetPostString("aftermemotype");
  6304. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6305. string afterresult = GetPostString("afterresult");
  6306. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6307. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6308. string poscode = CurrentUser.UserPost.Post.Code;
  6309. if (poscode != "SysAdmin")
  6310. {
  6311. string shopid = CurrentUser.User.pemShop;
  6312. lw.Add(string.Format("shopId in ({0})", shopid));
  6313. }
  6314. string searchType = GetPostString("searchType");
  6315. if (searchType == "wait")
  6316. {
  6317. lw.Add(string.Format("HandleTime is null"));
  6318. }
  6319. if (searchType == "documentary")
  6320. {
  6321. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6322. }
  6323. if (searchType == "handling")
  6324. {
  6325. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6326. }
  6327. if (searchType == "back" || searchType == "puBack")
  6328. {
  6329. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6330. }
  6331. if (searchType == "reBack")
  6332. {
  6333. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6334. }
  6335. if (afterState.Length <= 0)
  6336. {
  6337. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6338. }
  6339. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6340. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6341. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6342. writeGridDataTableJson(dStruct.TotalCount, dt);
  6343. }
  6344. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6345. //public void get_erp_back_handlingaftersalelist()
  6346. //{
  6347. // DataStruct dStruct = GetPostStruct();
  6348. // List<string> lw = new List<string>();
  6349. // string tid = GetPostString("ctid");
  6350. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6351. // string shopname = GetPostString("shopname");
  6352. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6353. // string buyernick = GetPostString("buyer_nick");
  6354. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6355. // string sellermemo = GetPostString("seller_memo");
  6356. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6357. // string orderState = GetPostString("orderState");
  6358. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6359. // string afterState = GetPostString("afterstate");
  6360. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6361. // string date1 = GetPostString("date1");
  6362. // string date2 = GetPostString("date2");
  6363. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6364. // if (dw.Length > 0) lw.Add(dw);
  6365. // string price1 = GetPostString("price1");
  6366. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6367. // string price2 = GetPostString("price2");
  6368. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6369. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6370. // string reason = GetPostString("reason");
  6371. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6372. // string method = GetPostString("method");
  6373. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6374. // string handler = GetPostString("handler");
  6375. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6376. // string handledate1 = GetPostString("handledate1");
  6377. // string handledate2 = GetPostString("handledate2");
  6378. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6379. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6380. // string afterdate1 = GetPostString("afterdate1");
  6381. // string afterdate2 = GetPostString("afterdate2");
  6382. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6383. // if (afterDate.Length > 0) lw.Add(afterDate);
  6384. // string supplier = GetPostString("supplier");
  6385. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6386. // string responsible = GetPostString("responsibleman");
  6387. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6388. // string customer = GetPostString("customer");
  6389. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6390. // string design = GetPostString("design");
  6391. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6392. // string afterMemoType = GetPostString("aftermemotype");
  6393. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6394. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6395. // if (afterState.Length <= 0)
  6396. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6397. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6398. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6399. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6400. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6401. //}
  6402. public void get_erp_aftersaleverifylist()
  6403. {
  6404. DataStruct dStruct = GetPostStruct();
  6405. List<string> lw = new List<string>();
  6406. string tid = GetPostString("ctid");
  6407. if (tid.Length > 0)
  6408. {
  6409. string select_tid = getTidByCtid(tid);
  6410. lw.Add(string.Format("otid='{0}'", select_tid));
  6411. }
  6412. string shopname = GetPostString("shopname");
  6413. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6414. string buyernick = GetPostString("buyer_nick");
  6415. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6416. string sellermemo = GetPostString("seller_memo");
  6417. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6418. string orderState = GetPostString("orderState");
  6419. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6420. //lw.Add(string.Format("IsRefund!={0}", 1));
  6421. string reason = GetPostString("reason");
  6422. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6423. string method = GetPostString("method");
  6424. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6425. string handler = GetPostString("handler");
  6426. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6427. string handledate1 = GetPostString("handledate1");
  6428. string handledate2 = GetPostString("handledate2");
  6429. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6430. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6431. string finish1 = GetPostString("finishdate1");
  6432. string finish2 = GetPostString("finishdate2");
  6433. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6434. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6435. string supplier = GetPostString("supplier");
  6436. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6437. string responsible = GetPostString("responsibleman");
  6438. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6439. string posCode = CurrentUser.UserPost.Post.Code;
  6440. string vstate = GetPostString("vstate");
  6441. if (vstate.Length > 0)
  6442. {
  6443. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6444. }
  6445. if (posCode == "Supplier")
  6446. {
  6447. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6448. lw.Add(string.Format("VerifyState = 0"));
  6449. lw.Add("type = 1");
  6450. lw.Add(string.Format("AfterSaleState={0}", 3));
  6451. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6452. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6453. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6454. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6455. writeGridDataTableJson(dStruct.TotalCount, dt);
  6456. }
  6457. else if (posCode == "logistics")
  6458. {
  6459. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6460. lw.Add(string.Format("VerifyState = 0"));
  6461. lw.Add("type = 2");
  6462. lw.Add(string.Format("AfterSaleState={0}", 3));
  6463. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6464. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6465. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6466. writeGridDataTableJson(dStruct.TotalCount, dt);
  6467. }
  6468. else
  6469. {
  6470. lw.Add(string.Format("(AfterSaleState = 3)"));
  6471. string reasonState = GetPostString("reasonState");
  6472. lw.Add("type = 0");
  6473. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6474. || posCode == "Summarize" || posCode == "Finance")
  6475. {
  6476. if (reasonState == "2")
  6477. {
  6478. lw.Add("VerifyState = 3");
  6479. }
  6480. else if (reasonState == "1")
  6481. {
  6482. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6483. }
  6484. else
  6485. {
  6486. lw.Add("VerifyState in (0,3)");
  6487. }
  6488. //不加条件,可以看全部
  6489. }
  6490. 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")
  6491. {
  6492. int orgid = CurrentUser.UserPost.OrgID;
  6493. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6494. if (string.IsNullOrEmpty(manageOrgId))
  6495. {
  6496. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6497. }
  6498. else
  6499. {
  6500. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6501. }
  6502. if (reasonState == "1")
  6503. {
  6504. lw.Add("VerifyState = 3");
  6505. }
  6506. else if (reasonState == "2")
  6507. {
  6508. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6509. }
  6510. else
  6511. {
  6512. }
  6513. }
  6514. else
  6515. {
  6516. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6517. }
  6518. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6519. //{
  6520. // int org_id = CurrentUser.UserPost.OrgID;
  6521. // lw.Add(string.Format("OrgID={0}", org_id));
  6522. //}
  6523. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6524. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6525. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6526. writeGridDataTableJson(dStruct.TotalCount, dt);
  6527. }
  6528. }
  6529. public void get_erp_finishaftersalelist()
  6530. {
  6531. DataStruct dStruct = GetPostStruct();
  6532. List<string> lw = new List<string>();
  6533. int st = 4;
  6534. string tid = GetPostString("ctid");
  6535. if (tid.Length > 0)
  6536. {
  6537. string select_tid = getTidByCtid(tid);
  6538. lw.Add(string.Format("otid='{0}'", select_tid));
  6539. }
  6540. string shopname = GetPostString("shopname");
  6541. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6542. //lw.Add(string.Format("IsRefund!={0}", 1));
  6543. string reason = GetPostString("reason");
  6544. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6545. string method = GetPostString("method");
  6546. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6547. string buyernick = GetPostString("buyer_nick");
  6548. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6549. string handler = GetPostString("handler");
  6550. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6551. string handledate1 = GetPostString("handledate1");
  6552. string handledate2 = GetPostString("handledate2");
  6553. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6554. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6555. string finish1 = GetPostString("finishdate1");
  6556. string finish2 = GetPostString("finishdate2");
  6557. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6558. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6559. string supplier = GetPostString("supplier");
  6560. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6561. string responsible = GetPostString("responsibleman");
  6562. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6563. string vstate = GetPostString("vstate");
  6564. if (vstate.Length > 0)
  6565. {
  6566. if ("3".Equals(vstate))
  6567. {
  6568. lw.Add(string.Format("IsTem=1"));
  6569. }
  6570. else
  6571. {
  6572. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6573. }
  6574. }
  6575. lw.Add(string.Format("AfterSaleState=4"));
  6576. string code = CurrentUser.UserPost.Post.Code;
  6577. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6578. {
  6579. //不加条件,可以看全部
  6580. }
  6581. else if (code == "Supplier")
  6582. {
  6583. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6584. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6585. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6586. }
  6587. else if (code == "logistics")
  6588. {
  6589. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6590. lw.Add("type = 2");
  6591. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6592. }
  6593. 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")
  6594. {
  6595. int orgid = CurrentUser.UserPost.OrgID;
  6596. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6597. if (string.IsNullOrEmpty(manageOrgIds))
  6598. {
  6599. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6600. }
  6601. else
  6602. {
  6603. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6604. }
  6605. }
  6606. else
  6607. {
  6608. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6609. }
  6610. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6611. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6612. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6613. writeGridDataTableJson(dStruct.TotalCount, dt);
  6614. }
  6615. public void handle_erp_aftersale()
  6616. {
  6617. if (UrlPostParmsCheck("ctid"))
  6618. {
  6619. string eid = GetPostString("ctid");
  6620. string responStr = GetPostString("AfterSaleResponsible");
  6621. if (responStr.Length <= 0)
  6622. {
  6623. returnErrorMsg("售后责任人不能为空");
  6624. return;
  6625. }
  6626. bool isDesign = false;
  6627. double designFree = 0.00;
  6628. int responsibleId = 0;
  6629. CeErpTradeCell entity = null;
  6630. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6631. if (entity != null)
  6632. {
  6633. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6634. string afterMethod = GetPostString("AfterSaleMethod");
  6635. if (isNeedNewOrder == 1)
  6636. {
  6637. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6638. bool ishav = true;
  6639. if (newentity == null)
  6640. {
  6641. newentity = entity.Clone() as CeErpTradeCell;
  6642. ishav = false;
  6643. newentity.ctid = "S_" + entity.ctid;
  6644. newentity.OrderState = 0;
  6645. //唯一标识
  6646. newentity.OrderSn = newentity.ctid;
  6647. string orderSn = dataHelper.getSaleOrderSn();
  6648. if (orderSn != "")
  6649. {
  6650. newentity.OrderSn = orderSn;
  6651. }
  6652. }
  6653. newentity.UpdateTime = DateTime.Now;
  6654. newentity.AfterSaleState = 0;
  6655. newentity.AfterSaleMethod = afterMethod;
  6656. if (!ishav)
  6657. {
  6658. string memo_str = newentity.seller_memo;
  6659. memo_str = memo_str.Replace("(", "(");
  6660. memo_str = memo_str.Replace(")", ")");
  6661. int sIndex = memo_str.IndexOf("(");
  6662. int eIndex = memo_str.IndexOf(")");
  6663. if (sIndex == -1 || eIndex == -1)
  6664. {
  6665. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6666. return;
  6667. }
  6668. string first = memo_str.Substring(0, sIndex + 1);
  6669. string memoCtid = newentity.OrderSn;
  6670. //if (memoCtid.IndexOf("C") != -1)
  6671. //{
  6672. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6673. //if (CIdx.IndexOf("+") != -1)
  6674. //{
  6675. //CIdx = "C" + CIdx.Split('+')[1];
  6676. //}
  6677. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6678. //}
  6679. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6680. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6681. string newMemo = first + memoCtid + last;
  6682. newentity.seller_memo = newMemo;
  6683. newentity.FinishPlaceTime = null;
  6684. newentity.UnusualTag = 0;
  6685. newentity.UnusualCon = "";
  6686. newentity.UnusualTime = null;
  6687. newentity.AfterSaleMemo = "";
  6688. newentity.AfterSaleMethod = afterMethod;
  6689. newentity.AfterSalePreTime = null;
  6690. newentity.AfterSaleReason = "";
  6691. newentity.AfterSaleResponsible = "";
  6692. newentity.AfterSaleState = 0;
  6693. newentity.AfterSaleTime = null;
  6694. newentity.AfterSaleUserId = 0;
  6695. newentity.AfterSaleSupplierState = 0;
  6696. newentity.LastBillWaybillCode = "";
  6697. newentity.LastBillCpCode = "";
  6698. newentity.FinishAfterSaleTime = null;
  6699. newentity.HandleTime = null;
  6700. newentity.IsSF = 0;
  6701. newentity.IsOldCustomer = 0;
  6702. newentity.UrgencyTime = null;
  6703. newentity.ResponsibleUserId = "";
  6704. newentity.IsVerifyToSupplier = false;
  6705. newentity.payment = 0;
  6706. newentity.CheckMemo = "";
  6707. newentity.OutSid = "";
  6708. newentity.CheckOrderTime = null;
  6709. newentity.MemoOpt = 0;
  6710. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6711. }
  6712. newentity.isAfterSaleOrder = 1;
  6713. newentity.IsRefund = 0;
  6714. string receiveMobile = GetPostString("receiver_mobile");
  6715. if (receiveMobile.Length > 0)
  6716. {
  6717. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6718. if (trade != null)
  6719. {
  6720. trade.receiver_name = GetPostString("receiver_name");
  6721. trade.receiver_mobile = receiveMobile;
  6722. trade.receiver_state = GetPostString("receiver_state");
  6723. trade.receiver_city = GetPostString("receiver_city");
  6724. trade.receiver_district = GetPostString("receiver_district");
  6725. trade.receiver_address = GetPostString("receiver_address");
  6726. newentity.IsOffLineOrder = 1;
  6727. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6728. }
  6729. }
  6730. string st = GetPostString("ToState");
  6731. if (st.Length > 0)
  6732. {
  6733. if (newentity.OrderState <= 3)
  6734. {
  6735. newentity.WaitDesignTime = DateTime.Now;
  6736. newentity.StartDesignTime = null;
  6737. newentity.FinishDesignTime = null;
  6738. newentity.OrderState = 3;
  6739. if (st == "下单员")
  6740. {
  6741. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6742. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6743. {
  6744. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6745. }
  6746. }
  6747. else
  6748. {
  6749. newentity.WaitDesignTime = DateTime.Now;
  6750. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6751. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6752. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6753. {
  6754. DataRow user = dt1.Rows[0];
  6755. //找主管
  6756. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6757. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6758. if (dt != null && dt.Rows.Count > 0)
  6759. {
  6760. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6761. newentity.DesignUserId = designMr;
  6762. string key = "aftersale_order_" + designMr;
  6763. if (RedisHelper.HasKey(key))
  6764. {
  6765. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6766. list.Add(newentity.ctid);
  6767. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6768. }
  6769. }
  6770. //账号正常
  6771. if (user["State"].ToString() == "0")
  6772. {
  6773. newentity.DesignUserId = entity.DesignUserId;
  6774. string key = "aftersale_order_" + entity.DesignUserId;
  6775. if (RedisHelper.HasKey(key))
  6776. {
  6777. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6778. list.Add(newentity.ctid);
  6779. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6780. }
  6781. }
  6782. }
  6783. }
  6784. }
  6785. if (entity.IsXianHuo == 1)
  6786. {
  6787. newentity.OrderState = 6;
  6788. entity.FinishPlaceTime = DateTime.Now;
  6789. }
  6790. }
  6791. if (ishav)
  6792. {
  6793. newentity.Update();
  6794. }
  6795. else
  6796. {
  6797. newentity.Create();
  6798. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6799. newCellExtend.ctid = newentity.ctid;
  6800. newCellExtend.orderFrom = 20;
  6801. newCellExtend.orderType = 30;
  6802. if (st == "下单员")
  6803. {
  6804. }
  6805. else
  6806. {
  6807. newCellExtend.ReprintTime = DateTime.Now;
  6808. }
  6809. newCellExtend.Create();
  6810. }
  6811. if (st != "下单员")
  6812. {
  6813. if (entity.DispatchSort == 2)
  6814. {
  6815. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6816. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6817. }
  6818. }
  6819. }
  6820. //处理售后扩展
  6821. string resIdStr = GetPostString("ResponsibleUserId");
  6822. string refundFees = GetPostString("refundFrees");
  6823. int IsComplain = GetPostInt("isComplain");
  6824. int IsBad = GetPostInt("isBad");
  6825. string IsOriginal = GetPostString("isOriginal");
  6826. double diffResultPrice = GetPostDouble("diffResultPrice");
  6827. string textResult = GetPostString("textResult");
  6828. string supplierResponsible = GetPostString("supplierResponsible");
  6829. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6830. if (ceErpTradeAfterSaleExtend == null)
  6831. {
  6832. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6833. ceErpTradeAfterSaleExtend.tid = eid;
  6834. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6835. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6836. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6837. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6838. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6839. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6840. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6841. ceErpTradeAfterSaleExtend.Create();
  6842. }
  6843. else
  6844. {
  6845. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6846. {
  6847. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6848. }
  6849. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6850. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6851. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6852. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6853. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6854. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6855. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6856. ceErpTradeAfterSaleExtend.Update();
  6857. }
  6858. int gysid = GetPostInt("ResponsibleSupId");
  6859. if (entity.AfterSaleUserId == 0)
  6860. {
  6861. entity.AfterSaleUserId = CurrentUser.UserID;
  6862. }
  6863. entity.ResponsibleUserId = resIdStr;
  6864. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6865. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6866. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6867. {
  6868. CeErpTradeResponsible.DelByTid(eid, -1);
  6869. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6870. int backNum = 0;
  6871. if (number != null)
  6872. {
  6873. backNum = number.BackNum;
  6874. }
  6875. char[] separator = { ',' };
  6876. string[] sArray = resIdStr.Split(separator);
  6877. string[] refundFreeList = { };
  6878. if (refundFees.Length > 0)
  6879. {
  6880. refundFreeList = refundFees.Split(separator);
  6881. }
  6882. int index = -1;
  6883. foreach (string i in sArray)
  6884. {
  6885. index++;
  6886. if (i.Length <= 0) continue;
  6887. char[] separator2 = { '_' };
  6888. string idstr = i.Split(separator2)[0];
  6889. string idtype = i.Split(separator2)[1];
  6890. double refudFree = 0;
  6891. if (refundFreeList.Length > 0)
  6892. {
  6893. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6894. }
  6895. if (idtype == "s")
  6896. {
  6897. isDesign = true;
  6898. designFree = refudFree;
  6899. }
  6900. int userId = Convert.ToInt32(idstr);
  6901. int type = 0;
  6902. if (idtype == "g")
  6903. {
  6904. type = 1;
  6905. }
  6906. if (idtype == "w")
  6907. {
  6908. type = 2;
  6909. }
  6910. if (idtype == "t")
  6911. {
  6912. type = 3;
  6913. }
  6914. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6915. if (ceErpTradeResponsible == null)
  6916. {
  6917. ceErpTradeResponsible = new CeErpTradeResponsible();
  6918. ceErpTradeResponsible.tid = eid;
  6919. ceErpTradeResponsible.UserId = userId;
  6920. ceErpTradeResponsible.createdTime = DateTime.Now;
  6921. ceErpTradeResponsible.type = type;
  6922. if (type == 1)
  6923. {
  6924. ceErpTradeResponsible.IsSup = 1;
  6925. }
  6926. if (type == 2)
  6927. {
  6928. ceErpTradeResponsible.IsFlow = 1;
  6929. }
  6930. }
  6931. ceErpTradeResponsible.RefundFee = refudFree;
  6932. ceErpTradeResponsible.VerifyState = 0;
  6933. if (userId == 2125 || idtype == "w")
  6934. {
  6935. ceErpTradeResponsible.VerifyState = 1;
  6936. }
  6937. if (idtype == "w" && userId == 101)
  6938. {
  6939. ceErpTradeResponsible.VerifyState = 0;
  6940. }
  6941. if (ceErpTradeResponsible.ID > 0)
  6942. {
  6943. ceErpTradeResponsible.Update();
  6944. }
  6945. else
  6946. {
  6947. ceErpTradeResponsible.Create();
  6948. }
  6949. if (isDesign)
  6950. {
  6951. responsibleId = ceErpTradeResponsible.ID;
  6952. }
  6953. }
  6954. CeErpTradeResponsible.NumByTid(backNum, eid);
  6955. }
  6956. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6957. if (ceErpTradeCellExtend != null)
  6958. {
  6959. ceErpTradeCellExtend.returnVisit = 0;
  6960. ceErpTradeCellExtend.Update();
  6961. }
  6962. if (entity.HandleTime != null)
  6963. {
  6964. if (entity.AfterSaleState == 1)
  6965. {
  6966. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6967. }
  6968. else
  6969. {
  6970. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6971. }
  6972. }
  6973. else
  6974. {
  6975. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6976. entity.HandleTime = DateTime.Now;
  6977. }
  6978. bool isCompale = false;
  6979. if (entity.AfterSaleState == 5)
  6980. {
  6981. isCompale = true;
  6982. entity.AfterSaleState = 3;
  6983. }
  6984. entity.AfterSaleSupplierState = 0;
  6985. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6986. {
  6987. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6988. }
  6989. string sImgs = GetPostString("img");
  6990. entity.AfterSaleSupplierImg = sImgs;
  6991. entity.supRefundType = GetPostString("supRefundType");
  6992. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6993. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6994. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6995. entity.AfterSaleMemoType = GetPostString("MemoType");
  6996. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6997. {
  6998. //entity.AfterSaleSupplierState = 2;
  6999. }
  7000. string df = GetPostString("DeductFee");
  7001. if (df == "")
  7002. {
  7003. df = "0";
  7004. }
  7005. string rf = GetPostString("RefundFee");
  7006. if (rf == "")
  7007. {
  7008. rf = "0";
  7009. }
  7010. string pm = GetPostString("AfterSalePayment");
  7011. if (pm == "")
  7012. {
  7013. pm = "0";
  7014. }
  7015. entity.AfterSalePayment = Convert.ToDouble(pm);
  7016. entity.DeductFee = Convert.ToDouble(df);
  7017. entity.RefundFee = Convert.ToDouble(rf);
  7018. entity.UpdateTime = DateTime.Now;
  7019. entity.Update();
  7020. string toState = GetPostString("ToState");
  7021. string original = GetPostString("isOriginal");
  7022. ApiVo apiVo = new ApiVo();
  7023. apiVo.orderNumber = entity.ctid;
  7024. apiVo.actionName = "afterDesign";
  7025. apiVo.orderRemarks = entity.AfterSaleMethod;
  7026. apiVo.reasonRemarks = entity.AfterSaleReason;
  7027. apiVo.isDesign = isDesign;
  7028. apiVo.designFree = designFree;
  7029. apiVo.responsibleId = responsibleId;
  7030. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  7031. if (toState == "设计师")
  7032. {
  7033. apiVo.isOriginal = Convert.ToBoolean(original);
  7034. }
  7035. designHelper.API_WorkCore(apiVo);//afterDesign
  7036. CeErpMethod methodSql = new CeErpMethod();
  7037. methodSql.con = entity.AfterSaleMethod;
  7038. methodSql.addTime = DateTime.Now;
  7039. methodSql.Create();
  7040. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  7041. CeErpMethod.ExecuteNonQuery(delsql);
  7042. if (isCompale)
  7043. {
  7044. aftersale_data_change(entity.ctid);
  7045. }
  7046. returnSuccessMsg("操作成功!");
  7047. return;
  7048. }
  7049. returnErrorMsg("找不到订单记录");
  7050. }
  7051. }
  7052. public void ins_erp_toresponsible()
  7053. {
  7054. if (UrlPostParmsCheck("ctid"))
  7055. {
  7056. string eid = GetPostString("ctid");
  7057. CeErpTradeCell entity = null;
  7058. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7059. if (entity != null)
  7060. {
  7061. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7062. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  7063. {
  7064. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  7065. return;
  7066. }
  7067. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  7068. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7069. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7070. if (entity.AfterSalePreTime == null)
  7071. {
  7072. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  7073. {
  7074. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  7075. }
  7076. }
  7077. entity.AfterSalePreTime = DateTime.Now;
  7078. //预完成给售后主管审核客户问题直接完成
  7079. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  7080. {
  7081. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  7082. {
  7083. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  7084. }
  7085. }
  7086. ceErpTradeAfterSaleExtend.Update();
  7087. entity.AfterSaleState = 2;
  7088. entity.UpdateTime = DateTime.Now;
  7089. entity.Update();
  7090. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7091. aftersale_data_change(entity.ctid);
  7092. returnSuccessMsg("操作成功!");
  7093. return;
  7094. }
  7095. returnErrorMsg("找不到订单记录");
  7096. }
  7097. }
  7098. public void cancel_erp_aftersaleanddelnew()
  7099. {
  7100. if (UrlPostParmsCheck("ctid"))
  7101. {
  7102. string eid = GetPostString("ctid");
  7103. CeErpTradeCell entity = null;
  7104. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7105. if (entity != null)
  7106. {
  7107. entity.AfterSaleState = 0;
  7108. entity.AfterSaleReason = "";
  7109. entity.AfterSaleMethod = "";
  7110. entity.AfterSaleMemo = "";
  7111. entity.AfterSaleResponsible = "";
  7112. entity.ResponsibleUserId = "";
  7113. entity.DeductFee = 0;
  7114. entity.RefundFee = 0;
  7115. entity.IsArbitrate = 0;
  7116. CeErpTradeResponsible.DelByTid(eid, -1);
  7117. entity.Update();
  7118. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7119. if (after != null)
  7120. {
  7121. if (after.OrderState < 5)
  7122. CeErpTradeCell.DelByCtid("S_" + eid);
  7123. }
  7124. returnSuccessMsg("操作成功!");
  7125. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7126. return;
  7127. }
  7128. returnErrorMsg("找不到订单记录");
  7129. }
  7130. }
  7131. public void get_erp_aftersale_pregather()
  7132. {
  7133. List<string> lw = new List<string>();
  7134. int st = GetInt("st");
  7135. string tid = GetPostString("ctid");
  7136. if (tid.Length > 0)
  7137. {
  7138. string select_tid = getTidByCtid(tid);
  7139. lw.Add(string.Format("tid='{0}'", select_tid));
  7140. }
  7141. string shopname = GetPostString("shopname");
  7142. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7143. string buyernick = GetPostString("buyer_nick");
  7144. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7145. string sellermemo = GetPostString("seller_memo");
  7146. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7147. string orderState = GetPostString("orderState");
  7148. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7149. string reason = GetPostString("reason");
  7150. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7151. string method = GetPostString("method");
  7152. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7153. string handler = GetPostString("handler");
  7154. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7155. string handledate1 = GetPostString("handledate1");
  7156. string handledate2 = GetPostString("handledate2");
  7157. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7158. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7159. string supplier = GetPostString("supplier");
  7160. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7161. string responsible = GetPostString("responsibleman");
  7162. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7163. string customer = GetPostString("customer");
  7164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7165. string design = GetPostString("design");
  7166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7167. string afterMemoType = GetPostString("aftermemotype");
  7168. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7169. string afterSaleMemo = GetPostString("afterSaleMemo");
  7170. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7171. string afterresult = GetPostString("afterresult");
  7172. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7173. string poscode = CurrentUser.UserPost.Post.Code;
  7174. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7175. {
  7176. string shopid = CurrentUser.User.pemShop;
  7177. lw.Add(string.Format("shopId in ({0})", shopid));
  7178. }
  7179. var mainwhere = string.Join(" and ", lw.ToArray());
  7180. string ro_json = "";
  7181. string type = GetPostString("gather_type");
  7182. int number = 0;
  7183. if (poscode == "AfterSale")
  7184. {
  7185. //处理中
  7186. if (type == "Handling")
  7187. {
  7188. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7189. DataTable dt = null;
  7190. try
  7191. {
  7192. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7193. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7194. }
  7195. catch (Exception e)
  7196. {
  7197. dt = new DataTable();
  7198. }
  7199. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7200. return;
  7201. }
  7202. if (type == "Wait")
  7203. {
  7204. //待处理
  7205. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7206. DataTable dt1 = null;
  7207. try
  7208. {
  7209. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7210. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7211. }
  7212. catch (Exception e)
  7213. {
  7214. dt1 = new DataTable();
  7215. }
  7216. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7217. return;
  7218. }
  7219. if (type == "back")
  7220. {
  7221. //打回
  7222. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7223. DataTable dt2 = null;
  7224. try
  7225. {
  7226. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7227. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7228. }
  7229. catch (Exception e)
  7230. {
  7231. dt2 = new DataTable();
  7232. }
  7233. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7234. return;
  7235. }
  7236. if (type == "preCompletion")
  7237. {
  7238. //预完成
  7239. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7240. DataTable dt3 = null;
  7241. try
  7242. {
  7243. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7244. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7245. }
  7246. catch (Exception e)
  7247. {
  7248. dt3 = new DataTable();
  7249. }
  7250. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7251. return;
  7252. }
  7253. if (type == "documentary")
  7254. {
  7255. //跟单中
  7256. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7257. DataTable dt4 = null;
  7258. try
  7259. {
  7260. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7261. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7262. }
  7263. catch (Exception e)
  7264. {
  7265. dt4 = new DataTable();
  7266. }
  7267. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7268. return;
  7269. }
  7270. if (type == "reBack")
  7271. {
  7272. //被打回
  7273. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7274. DataTable dt1 = null;
  7275. try
  7276. {
  7277. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7278. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7279. }
  7280. catch (Exception e)
  7281. {
  7282. dt1 = new DataTable();
  7283. }
  7284. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7285. return;
  7286. }
  7287. }
  7288. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7289. {
  7290. if (type == "puBack")
  7291. {
  7292. //退回
  7293. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7294. DataTable dt = null;
  7295. try
  7296. {
  7297. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7298. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7299. }
  7300. catch (Exception e)
  7301. {
  7302. dt = new DataTable();
  7303. }
  7304. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7305. return;
  7306. }
  7307. if (type == "reBack")
  7308. {
  7309. //打回
  7310. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7311. DataTable dt1 = null;
  7312. try
  7313. {
  7314. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7315. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7316. }
  7317. catch (Exception e)
  7318. {
  7319. dt1 = new DataTable();
  7320. }
  7321. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7322. return;
  7323. }
  7324. if (type == "examEd")
  7325. {
  7326. //已审核
  7327. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7328. DataTable dt2 = null;
  7329. try
  7330. {
  7331. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7332. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7333. }
  7334. catch (Exception e)
  7335. {
  7336. dt2 = new DataTable();
  7337. }
  7338. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7339. return;
  7340. }
  7341. if (type == "waitExam")
  7342. {
  7343. //待审核
  7344. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7345. DataTable dt3 = null;
  7346. try
  7347. {
  7348. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7349. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7350. }
  7351. catch (Exception e)
  7352. {
  7353. dt3 = new DataTable();
  7354. }
  7355. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7356. return;
  7357. }
  7358. if (type == "Handling")
  7359. {
  7360. //处理中
  7361. string sql4 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7362. DataTable dt4 = null;
  7363. try
  7364. {
  7365. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7366. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7367. }
  7368. catch (Exception e)
  7369. {
  7370. dt4 = new DataTable();
  7371. }
  7372. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7373. return;
  7374. }
  7375. if (type == "Wait")
  7376. {
  7377. //待处理
  7378. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7379. DataTable dt5 = null;
  7380. try
  7381. {
  7382. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7383. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7384. }
  7385. catch (Exception e)
  7386. {
  7387. dt5 = new DataTable();
  7388. }
  7389. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7390. return;
  7391. }
  7392. if (type == "documentary")
  7393. {
  7394. //跟单中
  7395. string sql6 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7396. DataTable dt6 = null;
  7397. try
  7398. {
  7399. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7400. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7401. }
  7402. catch (Exception e)
  7403. {
  7404. dt6 = new DataTable();
  7405. }
  7406. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7407. return;
  7408. }
  7409. }
  7410. returnSuccess(ro_json);
  7411. }
  7412. public void end_erp_aftersale()
  7413. {
  7414. if (UrlPostParmsCheck("ctid"))
  7415. {
  7416. string eid = GetPostString("ctid");
  7417. CeErpTradeCell entity = null;
  7418. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7419. if (entity != null)
  7420. {
  7421. string stype = GetPostString("stype");
  7422. string typeStr = stype;
  7423. entity.AfterSaleState = 4;
  7424. entity.FinishAfterSaleTime = DateTime.Now;
  7425. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7426. entity.Update();
  7427. ApiVo apiVo = new ApiVo();
  7428. apiVo.orderNumber = entity.ctid;
  7429. apiVo.actionName = "afterOver";
  7430. designHelper.API_WorkCore(apiVo); //afterOver
  7431. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7432. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7433. CeErpSukuraData.createInfo(entity.ctid, 8);
  7434. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7435. returnSuccessMsg("操作成功!");
  7436. return;
  7437. }
  7438. returnErrorMsg("找不到订单记录");
  7439. }
  7440. }
  7441. public void ins_erp_finishaftersale()
  7442. {
  7443. if (UrlPostParmsCheck("id"))
  7444. {
  7445. string eid = GetPostString("id");
  7446. CeErpTradeResponsible entity = null;
  7447. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7448. if (entity != null)
  7449. {
  7450. entity.VerifyState = 1;
  7451. entity.VerifyTime = DateTime.Now;
  7452. entity.Update();
  7453. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7454. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7455. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7456. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7457. if (dt.Rows.Count <= 0)
  7458. {
  7459. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7460. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7461. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7462. CeErpSukuraData.createInfo(entity.tid, 8);
  7463. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7464. {
  7465. CeErpDesignerBill.Del(entity.tid);
  7466. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7467. }
  7468. }
  7469. returnSuccessMsg("操作成功!");
  7470. return;
  7471. }
  7472. returnErrorMsg("找不到订单记录");
  7473. }
  7474. }
  7475. public void upd_erp_arbitrateaftersale()
  7476. {
  7477. if (UrlPostParmsCheck("id"))
  7478. {
  7479. string eid = GetPostString("id");
  7480. CeErpTradeResponsible entity = null;
  7481. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7482. if (entity != null)
  7483. {
  7484. entity.IsArbitrate = 1;
  7485. entity.ArbitradeMemo = GetPostString("reason");
  7486. entity.VerifyState = 2;
  7487. entity.Update();
  7488. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7489. if (tradecell != null)
  7490. {
  7491. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7492. tradecell.IsArbitrate = 1;
  7493. tradecell.Update();
  7494. }
  7495. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7496. returnSuccessMsg("操作成功!");
  7497. return;
  7498. }
  7499. returnErrorMsg("找不到订单记录");
  7500. }
  7501. }
  7502. public void upd_erp_backaftersale()
  7503. {
  7504. if (UrlPostParmsCheck("tid"))
  7505. {
  7506. string eid = GetPostString("tid");
  7507. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7508. int backNum = 0;
  7509. if (number != null)
  7510. {
  7511. backNum = number.BackNum;
  7512. }
  7513. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7514. CeErpTradeCell entity = null;
  7515. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7516. if (entity != null)
  7517. {
  7518. entity.AfterSaleBackReason = GetPostString("backreason");
  7519. entity.AfterSaleState = 1;
  7520. entity.AfterSaleSupplierState = 0;
  7521. entity.UpdateTime = DateTime.Now;
  7522. entity.Update();
  7523. returnSuccessMsg("操作成功!");
  7524. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7525. return;
  7526. }
  7527. returnErrorMsg("找不到订单记录");
  7528. }
  7529. }
  7530. public void get_erp_supplieraftersalelist()
  7531. {
  7532. DataStruct dStruct = GetPostStruct();
  7533. List<string> lw = new List<string>();
  7534. string tid = GetPostString("ctid");
  7535. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7536. string shopname = GetPostString("shopname");
  7537. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7538. string buyernick = GetPostString("buyer_nick");
  7539. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7540. string sellermemo = GetPostString("seller_memo");
  7541. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7542. string orderState = GetPostString("orderState");
  7543. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7544. string afterState = GetPostString("afterstate");
  7545. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7546. string date1 = GetPostString("date1");
  7547. string date2 = GetPostString("date2");
  7548. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7549. if (dw.Length > 0) lw.Add(dw);
  7550. string price1 = GetPostString("price1");
  7551. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7552. string price2 = GetPostString("price2");
  7553. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7554. string reason = GetPostString("reason");
  7555. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7556. string method = GetPostString("method");
  7557. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7558. string handledate1 = GetPostString("handledate1");
  7559. string handledate2 = GetPostString("handledate2");
  7560. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7561. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7562. string handler = GetPostString("handler");
  7563. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7564. string afterdate1 = GetPostString("afterdate1");
  7565. string afterdate2 = GetPostString("afterdate2");
  7566. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7567. if (afterDate.Length > 0) lw.Add(afterDate);
  7568. string customer = GetPostString("customer");
  7569. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7570. string design = GetPostString("design");
  7571. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7572. string afterMemoType = GetPostString("aftermemotype");
  7573. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7574. string vstate = GetPostString("vstate");
  7575. if (vstate.Length > 0)
  7576. {
  7577. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7578. }
  7579. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7580. string supplier = GetPostString("supplier");
  7581. int supid = commonHelper.getSupplierIDByName(supplier);
  7582. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7583. string posCode = CurrentUser.UserPost.Post.Code;
  7584. if (posCode == "Supplier")
  7585. {
  7586. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7587. }
  7588. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7589. {
  7590. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7591. }
  7592. else
  7593. {
  7594. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7595. }
  7596. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7597. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7598. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7599. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7600. writeGridDataTableJson(dStruct.TotalCount, dt);
  7601. }
  7602. public void upd_erp_supverifyaftersale()
  7603. {
  7604. if (UrlPostParmsCheck("id"))
  7605. {
  7606. string id = GetPostString("id");
  7607. int st = GetPostInt("afterstate");
  7608. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7609. CeErpTradeCell entity = null;
  7610. if (ceErpTradeResponsible != null)
  7611. {
  7612. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7613. }
  7614. string afmemo = GetPostString("supmemo");
  7615. string image = GetPostString("image");
  7616. if (entity != null)
  7617. {
  7618. entity.AfterSaleSupplierState = st;
  7619. entity.AfterSaleSupplierMemo = afmemo;
  7620. if (st == 1)
  7621. {
  7622. ceErpTradeResponsible.VerifyState = 1;
  7623. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7624. ceErpTradeResponsible.Update();
  7625. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7626. if (isAll)
  7627. {
  7628. entity.AfterSaleState = 4;
  7629. entity.FinishAfterSaleTime = DateTime.Now;
  7630. }
  7631. }
  7632. else
  7633. {
  7634. CeErpTradeResponsible.dateByTid(entity.ctid);
  7635. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7636. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7637. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7638. if (num <= 1)
  7639. {
  7640. entity.AfterSaleState = 1;
  7641. }
  7642. else
  7643. {
  7644. entity.AfterSaleState = 5;
  7645. }
  7646. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7647. if (ceErpTradeAfterSaleExtend != null)
  7648. {
  7649. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7650. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7651. ceErpTradeAfterSaleExtend.Update();
  7652. }
  7653. else
  7654. {
  7655. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7656. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7657. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7658. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7659. ceErpTradeAfterSaleExtend.Create();
  7660. }
  7661. }
  7662. if (entity.AfterSaleState == 4)
  7663. {
  7664. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7665. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7666. {
  7667. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7668. }
  7669. ApiVo apiVo = new ApiVo();
  7670. apiVo.orderNumber = entity.ctid;
  7671. apiVo.actionName = "afterOver";
  7672. designHelper.API_WorkCore(apiVo); //afterOver
  7673. }
  7674. entity.UpdateTime = DateTime.Now;
  7675. entity.Update();
  7676. returnSuccessMsg("操作成功!");
  7677. CeErpSukuraData.createInfo(entity.ctid, 8);
  7678. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7679. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7680. return;
  7681. }
  7682. returnErrorMsg("找不到订单记录");
  7683. }
  7684. }
  7685. public void upd_erp_masteraftersale()
  7686. {
  7687. if (UrlPostParmsCheck("id"))
  7688. {
  7689. string id = GetPostString("id");
  7690. int st = GetPostInt("afterstate");
  7691. string afmemo = GetPostString("supmemo");
  7692. string image = GetPostString("image");
  7693. string textResult = GetPostString("textResult");
  7694. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7695. if (ceErpTradeResponsible != null)
  7696. {
  7697. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7698. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7699. ceErpTradeResponsible.Update();
  7700. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7701. if (entity != null)
  7702. {
  7703. entity.AfterSaleSupplierState = st;
  7704. entity.AfterSaleSupplierMemo = afmemo;
  7705. if (st == 1)
  7706. {
  7707. }
  7708. else
  7709. {
  7710. CeErpTradeResponsible.dateByTid(entity.ctid);
  7711. //退回到售后
  7712. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7713. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7714. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7715. if (num <= 1)
  7716. {
  7717. entity.AfterSaleState = 1;
  7718. }
  7719. else
  7720. {
  7721. entity.AfterSaleState = 5;
  7722. }
  7723. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7724. if (ceErpTradeAfterSaleExtend != null)
  7725. {
  7726. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7727. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7728. ceErpTradeAfterSaleExtend.Update();
  7729. }
  7730. else
  7731. {
  7732. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7733. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7734. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7735. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7736. ceErpTradeAfterSaleExtend.Create();
  7737. }
  7738. }
  7739. entity.UpdateTime = DateTime.Now;
  7740. entity.Update();
  7741. returnSuccessMsg("操作成功!");
  7742. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7743. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7744. return;
  7745. }
  7746. }
  7747. returnErrorMsg("找不到订单记录");
  7748. }
  7749. }
  7750. public void upd_erp_personaftersale()
  7751. {
  7752. if (UrlPostParmsCheck("id"))
  7753. {
  7754. //林小连
  7755. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7756. {
  7757. upd_erp_masteraftersale();
  7758. return;
  7759. }
  7760. string id = GetPostString("id");
  7761. int st = GetPostInt("afterstate");
  7762. string afmemo = GetPostString("supmemo");
  7763. string image = GetPostString("image");
  7764. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7765. if (ceErpTradeResponsible != null)
  7766. {
  7767. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7768. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7769. ceErpTradeResponsible.Update();
  7770. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7771. if (entity != null)
  7772. {
  7773. entity.AfterSaleSupplierMemo = afmemo;
  7774. entity.AfterSaleSupplierState = st;
  7775. if (st == 1)
  7776. {
  7777. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7778. if (isAll)
  7779. {
  7780. entity.AfterSaleState = 4;
  7781. entity.FinishAfterSaleTime = DateTime.Now;
  7782. }
  7783. }
  7784. else
  7785. {
  7786. CeErpTradeResponsible.dateByTid(entity.ctid);
  7787. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7788. if (ceErpTradeAfterSaleExtend != null)
  7789. {
  7790. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7791. ceErpTradeAfterSaleExtend.Update();
  7792. }
  7793. else
  7794. {
  7795. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7796. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7797. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7798. ceErpTradeAfterSaleExtend.Create();
  7799. }
  7800. //退回到主管
  7801. //entity.AfterSaleState = 2;
  7802. }
  7803. if (entity.AfterSaleState == 4)
  7804. {
  7805. ApiVo apiVo = new ApiVo();
  7806. apiVo.orderNumber = entity.ctid;
  7807. apiVo.actionName = "afterOver";
  7808. designHelper.API_WorkCore(apiVo); //afterOver
  7809. }
  7810. entity.UpdateTime = DateTime.Now;
  7811. entity.Update();
  7812. returnSuccessMsg("操作成功!");
  7813. CeErpSukuraData.createInfo(entity.ctid, 8);
  7814. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7815. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7816. return;
  7817. }
  7818. }
  7819. returnErrorMsg("找不到订单记录");
  7820. }
  7821. }
  7822. public void set_erp_supplierrefundtag()
  7823. {
  7824. if (UrlPostParmsCheck("ctid"))
  7825. {
  7826. string eid = GetPostString("ctid");
  7827. CeErpTradeCell entity = null;
  7828. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7829. if (entity != null)
  7830. {
  7831. entity.IsSupplierRefund = GetPostInt("tag");
  7832. entity.Update();
  7833. returnSuccessMsg("操作成功!");
  7834. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7835. return;
  7836. }
  7837. returnErrorMsg("找不到订单记录");
  7838. }
  7839. }
  7840. public void get_erp_refundlist()
  7841. {
  7842. DataStruct dStruct = GetPostStruct();
  7843. List<string> lw = new List<string>();
  7844. string tid = GetPostString("tid");
  7845. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7846. //string rid = GetPostString("refund_id");
  7847. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7848. string shopname = GetPostString("shopname");
  7849. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7850. string buyernick = GetPostString("buyer_nick");
  7851. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7852. string customer = GetPostString("customer");
  7853. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7854. string design = GetPostString("design");
  7855. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7856. string sellermemo = GetPostString("seller_memo");
  7857. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7858. //string date1 = GetPostString("date1");
  7859. //string date2 = GetPostString("date2");
  7860. //string dateType = GetPostString("dateType");
  7861. //if (dateType.Length > 0)
  7862. //{
  7863. // if (dateType == "1001") dateType = "0";
  7864. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7865. // if (searchDT.Count == 2)
  7866. // {
  7867. // date1 = searchDT[0].ToString();
  7868. // date2 = searchDT[1].ToString();
  7869. // }
  7870. //}
  7871. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7872. //if (dw.Length > 0) lw.Add(dw);
  7873. string redate1 = GetPostString("refunddate1");
  7874. string redate2 = GetPostString("refunddate2");
  7875. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7876. if (dwdate.Length > 0) lw.Add(dwdate);
  7877. string price1 = GetPostString("price1");
  7878. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7879. string price2 = GetPostString("price2");
  7880. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7881. string ispartrefund = GetPostString("ispartrefund");
  7882. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7883. string refundState = GetPostString("refundvstate");
  7884. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7885. int st = GetInt("st");
  7886. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7887. {
  7888. string responsible = GetPostString("responsibleman");
  7889. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7890. lw.Add(string.Format("RefundState>={0}", st));
  7891. string code = CurrentUser.UserPost.Post.Code;
  7892. if (code == "CustomerService")
  7893. {
  7894. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7895. }
  7896. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7897. {
  7898. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7899. }
  7900. else if (code == "Place" || code == "PlaceMr")
  7901. {
  7902. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7903. }
  7904. dStruct.Order = "RefundState asc,created desc";
  7905. }
  7906. else if (st == 10)
  7907. {
  7908. string responsible = GetPostString("responsibleman");
  7909. if (responsible == "空白")
  7910. {
  7911. lw.Add(string.Format("ResponsibleUserName = ''"));
  7912. }
  7913. else if (responsible.Length > 0)
  7914. {
  7915. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7916. }
  7917. lw.Add(string.Format("RefundState>=0"));
  7918. dStruct.Order = "created desc";
  7919. }
  7920. else
  7921. {
  7922. string responsible = GetPostString("responsibleman");
  7923. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7924. lw.Add(string.Format("RefundState={0}", st));
  7925. dStruct.Order = "created desc";
  7926. }
  7927. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7928. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7929. dt.Columns.Add("refund_fees");
  7930. foreach (DataRow dr in dt.Rows)
  7931. {
  7932. String status = dr["status"].ToString();
  7933. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7934. {
  7935. dr["refund_fees"] = dr["refund_fee"];
  7936. }
  7937. else
  7938. {
  7939. dr["refund_fees"] = "0.0";
  7940. }
  7941. }
  7942. writeGridDataTableJson(dStruct.TotalCount, dt);
  7943. }
  7944. public void get_erp_refunddesignlist()
  7945. {
  7946. DataStruct dStruct = GetPostStruct();
  7947. List<string> lw = new List<string>();
  7948. string tid = GetPostString("tid");
  7949. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7950. string shopname = GetPostString("shopname");
  7951. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7952. string buyernick = GetPostString("buyer_nick");
  7953. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7954. string customer = GetPostString("customer");
  7955. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7956. string design = GetPostString("design");
  7957. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7958. string sellermemo = GetPostString("seller_memo");
  7959. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7960. string redate1 = GetPostString("refunddate1");
  7961. string redate2 = GetPostString("refunddate2");
  7962. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7963. if (dwdate.Length > 0) lw.Add(dwdate);
  7964. string price1 = GetPostString("price1");
  7965. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7966. string price2 = GetPostString("price2");
  7967. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7968. string ispartrefund = GetPostString("ispartrefund");
  7969. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7970. string designerorg = GetPostString("designerorg");
  7971. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7972. string refundState = GetPostString("refundState");
  7973. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7974. int myOrgid = CurrentUser.UserPost.OrgID;
  7975. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7976. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7977. {
  7978. if (CurrentUser.User.TeamIds.Length > 0)
  7979. {
  7980. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7981. }
  7982. else
  7983. {
  7984. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7985. }
  7986. }
  7987. else if ("SysAdmin".Equals(myOrgCode))
  7988. {
  7989. }
  7990. else
  7991. {
  7992. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7993. {
  7994. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7995. }
  7996. else
  7997. {
  7998. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7999. }
  8000. }
  8001. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  8002. dStruct.Order = "created desc";
  8003. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8004. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  8005. dt.Columns.Add("refund_fees");
  8006. foreach (DataRow dr in dt.Rows)
  8007. {
  8008. String status = dr["status"].ToString();
  8009. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  8010. {
  8011. dr["refund_fees"] = dr["refund_fee"];
  8012. }
  8013. else
  8014. {
  8015. dr["refund_fees"] = "0.0";
  8016. }
  8017. }
  8018. writeGridDataTableJson(dStruct.TotalCount, dt);
  8019. }
  8020. public void handle_erp_refundtag()
  8021. {
  8022. if (UrlPostParmsCheck("refund_id"))
  8023. {
  8024. string eid = GetPostString("refund_id");
  8025. string respMan = GetPostString("ResponsibleName");
  8026. if (respMan.Length <= 0)
  8027. {
  8028. returnErrorMsg("责任人不能为空");
  8029. return;
  8030. }
  8031. CeErpTradeRefund entity = null;
  8032. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8033. if (entity != null)
  8034. {
  8035. entity.ResponsibleUserName = respMan;
  8036. string userid = GetPostString("ResponsibleUserId");
  8037. if (userid.Length > 0)
  8038. {
  8039. entity.ResponsibleUserId = userid;
  8040. }
  8041. entity.Memo = GetPostString("Memo");
  8042. if (respMan.IndexOf("客服") != -1 ||
  8043. respMan.IndexOf("设计师") != -1 ||
  8044. respMan.IndexOf("下单员") != -1)
  8045. {
  8046. entity.RefundState = 2;
  8047. }
  8048. else
  8049. {
  8050. entity.RefundState = 3;
  8051. }
  8052. entity.modified = DateTime.Now;
  8053. entity.Update();
  8054. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  8055. returnSuccessMsg("操作成功!");
  8056. return;
  8057. }
  8058. returnErrorMsg("找不到订单记录");
  8059. }
  8060. }
  8061. public void handle_erp_designrefundtag()
  8062. {
  8063. if (UrlPostParmsCheck("refund_id"))
  8064. {
  8065. string eid = GetPostString("refund_id");
  8066. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  8067. if (ceErpTradeCellExtend == null)
  8068. {
  8069. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  8070. ceErpTradeCellExtend.ctid = eid;
  8071. }
  8072. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  8073. if (ceErpTradeCellExtend.ID > 0)
  8074. {
  8075. ceErpTradeCellExtend.Update();
  8076. }
  8077. else
  8078. {
  8079. ceErpTradeCellExtend.Create();
  8080. }
  8081. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  8082. returnSuccessMsg("操作成功!");
  8083. return;
  8084. }
  8085. returnErrorMsg("找不到订单记录");
  8086. }
  8087. public void upd_erp_refundverify()
  8088. {
  8089. if (UrlPostParmsCheck("refund_id"))
  8090. {
  8091. string eid = GetPostString("refund_id");
  8092. CeErpTradeRefund entity = null;
  8093. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8094. if (entity != null)
  8095. {
  8096. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8097. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8098. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8099. {
  8100. entity.RefundState = 2;
  8101. }
  8102. else
  8103. {
  8104. entity.RefundState = 3;
  8105. }
  8106. entity.Update();
  8107. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8108. returnSuccessMsg("操作成功!");
  8109. return;
  8110. }
  8111. returnErrorMsg("找不到订单记录");
  8112. }
  8113. }
  8114. public void upd_erp_refundapprove()
  8115. {
  8116. if (UrlPostParmsCheck("refund_id"))
  8117. {
  8118. string eid = GetPostString("refund_id");
  8119. CeErpTradeRefund entity = null;
  8120. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8121. if (entity != null)
  8122. {
  8123. int apr = GetPostInt("approve");
  8124. if (apr == 0)
  8125. {
  8126. entity.RefundState = 1;
  8127. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8128. }
  8129. else if (apr == 1)
  8130. {
  8131. entity.RefundState = 3;
  8132. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8133. }
  8134. entity.modified = DateTime.Now;
  8135. entity.Update();
  8136. returnSuccessMsg("操作成功!");
  8137. return;
  8138. }
  8139. returnErrorMsg("找不到订单记录");
  8140. }
  8141. }
  8142. public void get_erp_billlist()
  8143. {
  8144. DataStruct dStruct = GetPostStruct();
  8145. List<string> lw = new List<string>();
  8146. string title = GetPostString("title");
  8147. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8148. string tid = GetPostString("tid");
  8149. string tids = GetPostString("tids");
  8150. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8151. if (tids.Length > 0)
  8152. {
  8153. tids = "'" + tids + "'";
  8154. tids = tids.Replace(",", "','");
  8155. lw.Add(string.Format("tid in ({0})", tids));
  8156. }
  8157. string shopname = GetPostString("shopname");
  8158. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8159. string buyernick = GetPostString("buyer_nick");
  8160. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8161. string customer = GetPostString("customer");
  8162. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8163. string date1 = GetPostString("date1");
  8164. string date2 = GetPostString("date2");
  8165. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8166. if (dw.Length > 0) lw.Add(dw);
  8167. string price1 = GetPostString("price1");
  8168. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8169. string price2 = GetPostString("price2");
  8170. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8171. string returndate1 = GetPostString("returndate1");
  8172. string returndate2 = GetPostString("returndate2");
  8173. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8174. if (dw1.Length > 0) lw.Add(dw1);
  8175. string billtype = GetPostString("billtype");
  8176. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8177. string billstate = GetPostString("billstate");
  8178. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8179. string usershop = CurrentUser.User.pemShop;
  8180. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8181. dStruct.Order = "createTime desc";
  8182. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8183. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8184. //foreach (DataRow dr in dt.Rows)
  8185. //{
  8186. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8187. //}
  8188. writeGridDataTableJson(dStruct.TotalCount, dt);
  8189. }
  8190. public void modify_erp_billinfo()
  8191. {
  8192. if (UrlPostParmsCheck("ID"))
  8193. {
  8194. string eid = GetPostString("ID");
  8195. CeErpBill bill_entity = null;
  8196. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8197. if (bill_entity != null)
  8198. {
  8199. bill_entity.tid = GetPostString("tid");
  8200. bill_entity.title = GetPostString("title");
  8201. bill_entity.tax = GetPostString("tax");
  8202. bill_entity.bank = GetPostString("bank");
  8203. bill_entity.bankac = GetPostString("bankac");
  8204. bill_entity.address = GetPostString("address");
  8205. bill_entity.phone = GetPostString("phone");
  8206. bill_entity.price = GetPostString("price");
  8207. bill_entity.productId = GetPostInt("ProductName");
  8208. bill_entity.num = GetPostInt("num");
  8209. bill_entity.unit = GetPostString("unit");
  8210. bill_entity.type = GetPostString("type");
  8211. bill_entity.sendType = GetPostString("SendType");
  8212. bill_entity.email = GetPostString("email");
  8213. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8214. bill_entity.shopName = GetPostString("ShopName");
  8215. bill_entity.applymemo = GetPostString("applymemo");
  8216. bill_entity.modifyTime = DateTime.Now;
  8217. bill_entity.createTime = DateTime.Now;
  8218. bill_entity.state = 0;
  8219. bill_entity.Update();
  8220. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8221. returnSuccessMsg("发票修改成功!");
  8222. return;
  8223. }
  8224. returnErrorMsg("找不到对应记录");
  8225. }
  8226. }
  8227. public void set_erp_invoicing()
  8228. {
  8229. if (UrlPostParmsCheck("id"))
  8230. {
  8231. try
  8232. {
  8233. string eid = GetPostString("id");
  8234. CeErpBill bill_entity = null;
  8235. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8236. if (bill_entity != null)
  8237. {
  8238. int ComId = GetPostInt("ComId");
  8239. //string memo = GetPostString("Memo");
  8240. int allInfo = GetPostInt("allinfo");
  8241. string clert = CurrentUser.User.Name;
  8242. //string detailValue = GetPostString("detailvalue");
  8243. string billId = bill_entity.billOrderId;
  8244. string[] billIdList = billId.Split(',');
  8245. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8246. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8247. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8248. {
  8249. billCount += 1;
  8250. }
  8251. if (billId.Length <= 0 || billIdList.Length != billCount)
  8252. {
  8253. bill_entity.billOrderId = "";
  8254. string prebill = "ltb";
  8255. for (int idx = 1; idx <= billCount; idx++)
  8256. {
  8257. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8258. string billoid = prebill + idx + dtstr;
  8259. bill_entity.billOrderId += billoid;
  8260. if (idx < billCount)
  8261. {
  8262. bill_entity.billOrderId += ",";
  8263. }
  8264. }
  8265. }
  8266. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8267. if (bill_entity.state == 5)
  8268. {
  8269. string errMsg = bill_entity.failerror;
  8270. string[] errlist = errMsg.Split('|');
  8271. string[] errTags = new string[errlist.Length];
  8272. for (int itag = 0; itag < errlist.Length; itag++)
  8273. {
  8274. if (errlist[itag].Length <= 0) continue;
  8275. errTags[itag] = errlist[itag].Split('&')[0];
  8276. }
  8277. for (int iii = 0; iii < errTags.Length; iii++)
  8278. {
  8279. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8280. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8281. if (billOrderList.Length >= erroBillOrderTag)
  8282. {
  8283. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8284. if (needModifyBillId.Length <= 19)
  8285. {
  8286. needModifyBillId = needModifyBillId + "1";
  8287. }
  8288. else
  8289. {
  8290. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8291. last = last + 1;
  8292. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8293. }
  8294. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8295. }
  8296. }
  8297. }
  8298. bool isHaveBillSucces = false;
  8299. string totalRes = "";
  8300. bill_entity.failerror = "";
  8301. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8302. {
  8303. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8304. totalRes += res;
  8305. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8306. {
  8307. isHaveBillSucces = true;
  8308. bill_entity.comId = ComId;
  8309. bill_entity.state = 1;
  8310. bill_entity.executeTime = DateTime.Now;
  8311. bill_entity.executeUser = clert;
  8312. }
  8313. else
  8314. {
  8315. bill_entity.state = 5;
  8316. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8317. }
  8318. }
  8319. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8320. bill_entity.Update();
  8321. if (isHaveBillSucces)
  8322. {
  8323. StringBuilder sql = new StringBuilder();
  8324. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8325. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8326. }
  8327. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8328. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8329. {
  8330. returnErrorMsg("开票失败");
  8331. }
  8332. else
  8333. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8334. return;
  8335. }
  8336. returnErrorMsg("找不到对应记录");
  8337. }
  8338. catch (Exception ex)
  8339. {
  8340. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8341. returnErrorMsg("操作失败");
  8342. }
  8343. }
  8344. }
  8345. public void get_erp_invoicing_back()
  8346. {
  8347. if (UrlPostParmsCheck("id"))
  8348. {
  8349. try
  8350. {
  8351. string id = GetPostString("id");
  8352. CeErpBill entiy = CeErpBill.Get(id);
  8353. if (entiy != null)
  8354. {
  8355. if (entiy.state == 0)
  8356. {
  8357. returnErrorMsg("发票还未开具");
  8358. return;
  8359. }
  8360. string[] billOrderList = entiy.billOrderId.Split(',');
  8361. int iTag = 0;
  8362. entiy.fplsh = "";
  8363. entiy.fpdm = "";
  8364. entiy.fphm = "";
  8365. foreach (string billOrderId in billOrderList)
  8366. {
  8367. iTag++;
  8368. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8369. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8370. {
  8371. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8372. try
  8373. {
  8374. Invoicing_get_response_Obj iObj = null;
  8375. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8376. if (iObj != null)
  8377. {
  8378. entiy.state = 2;
  8379. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8380. entiy.fpdm += iObj.list[0].c_fpdm;
  8381. entiy.fphm += iObj.list[0].c_fphm;
  8382. if (iTag < billOrderList.Length)
  8383. {
  8384. entiy.fplsh += ",";
  8385. entiy.fpdm += ",";
  8386. entiy.fphm += ",";
  8387. }
  8388. entiy.Update();
  8389. }
  8390. StringBuilder sql = new StringBuilder();
  8391. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8392. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8393. returnSuccessMsg("开票成功");
  8394. }
  8395. catch (Exception ex)
  8396. {
  8397. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8398. }
  8399. return;
  8400. }
  8401. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8402. {
  8403. var res_obj = new
  8404. {
  8405. data = "开票中"
  8406. };
  8407. string ro_json = JsonConvert.SerializeObject(res_obj);
  8408. returnSuccess(ro_json);
  8409. return;
  8410. }
  8411. else
  8412. {
  8413. int eidx = res.IndexOf("c_resultmsg");
  8414. int lidx = res.IndexOf("c_status");
  8415. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8416. entiy.state = 5;
  8417. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8418. entiy.Update();
  8419. returnErrorMsg("开票失败");
  8420. return;
  8421. }
  8422. }
  8423. }
  8424. }
  8425. catch (Exception ex)
  8426. {
  8427. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8428. }
  8429. return;
  8430. }
  8431. }
  8432. public void get_erp_invoicing()
  8433. {
  8434. if (UrlPostParmsCheck("id"))
  8435. {
  8436. try
  8437. {
  8438. string id = GetPostString("id");
  8439. CeErpBill entiy = CeErpBill.Get(id);
  8440. if (entiy != null)
  8441. {
  8442. if (entiy.state == 0)
  8443. {
  8444. returnErrorMsg("发票还未开具");
  8445. return;
  8446. }
  8447. if (entiy.sendType == "纸质发票")
  8448. {
  8449. if (entiy.img.Length <= 0)
  8450. {
  8451. returnErrorMsg("查无纸质发票");
  8452. return;
  8453. }
  8454. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8455. returnSuccess(returnres);
  8456. return;
  8457. }
  8458. string[] billOrderList = entiy.billOrderId.Split(',');
  8459. int iTag = 0;
  8460. string fpUrl = "";
  8461. entiy.fplsh = "";
  8462. entiy.fpdm = "";
  8463. entiy.fphm = "";
  8464. foreach (string billOrderId in billOrderList)
  8465. {
  8466. iTag++;
  8467. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8468. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8469. {
  8470. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8471. Invoicing_get_response_Obj iObj = null;
  8472. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8473. if (iObj != null)
  8474. {
  8475. //entiy.state = 2;
  8476. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8477. entiy.fpdm += iObj.list[0].c_fpdm;
  8478. entiy.fphm += iObj.list[0].c_fphm;
  8479. if (iTag < billOrderList.Length)
  8480. {
  8481. entiy.fplsh += ",";
  8482. entiy.fpdm += ",";
  8483. entiy.fphm += ",";
  8484. }
  8485. entiy.Update();
  8486. fpUrl += iObj.list[0].c_url + ",";
  8487. }
  8488. //returnSuccess(res);
  8489. StringBuilder sql = new StringBuilder();
  8490. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8491. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8492. }
  8493. else
  8494. {
  8495. int eidx = res.IndexOf("c_resultmsg");
  8496. //int lidx = res.IndexOf("c_status");
  8497. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8498. //开票失败
  8499. entiy.state = 5;
  8500. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8501. entiy.Update();
  8502. returnErrorMsg("开票失败");
  8503. return;
  8504. }
  8505. }
  8506. var returnObj = new
  8507. {
  8508. data = fpUrl
  8509. };
  8510. string ro_json = JsonConvert.SerializeObject(returnObj);
  8511. returnSuccess(ro_json);
  8512. }
  8513. }
  8514. catch (Exception ex)
  8515. {
  8516. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8517. }
  8518. return;
  8519. }
  8520. }
  8521. public void save_erp_billimg()
  8522. {
  8523. if (UrlPostParmsCheck("id"))
  8524. {
  8525. string eid = GetPostString("id");
  8526. CeErpBill bill_entity = null;
  8527. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8528. if (bill_entity != null)
  8529. {
  8530. bill_entity.img = GetPostString("img");
  8531. bill_entity.executeTime = DateTime.Now;
  8532. bill_entity.state = 2;
  8533. bill_entity.Update();
  8534. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8535. returnSuccessMsg("保存成功");
  8536. }
  8537. return;
  8538. }
  8539. }
  8540. public void upd_erp_billreturnback()
  8541. {
  8542. if (UrlPostParmsCheck("id"))
  8543. {
  8544. int eid = GetPostInt("id");
  8545. CeErpBill bill_entity = null;
  8546. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8547. if (bill_entity != null)
  8548. {
  8549. bill_entity.state = 3;
  8550. bill_entity.returnReason = GetPostString("reason");
  8551. bill_entity.Update();
  8552. returnSuccessMsg("驳回成功!");
  8553. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8554. }
  8555. return;
  8556. }
  8557. }
  8558. public void cancel_erp_bill()
  8559. {
  8560. if (UrlPostParmsCheck("id"))
  8561. {
  8562. int eid = GetPostInt("id");
  8563. int detailValue = GetPostInt("detailvalue");
  8564. CeErpBill bill_entity = null;
  8565. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8566. string cres = "";
  8567. string gres = "";
  8568. if (bill_entity != null)
  8569. {
  8570. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8571. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8572. {
  8573. int iTag = 0;
  8574. bill_entity.fplsh = "";
  8575. bill_entity.fpdm = "";
  8576. bill_entity.fphm = "";
  8577. foreach (string billOrderId in billOrderList)
  8578. {
  8579. iTag++;
  8580. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8581. if (gres.IndexOf("success") != -1)
  8582. {
  8583. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8584. Invoicing_get_response_Obj iObj = null;
  8585. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8586. if (iObj != null)
  8587. {
  8588. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8589. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8590. bill_entity.fphm += iObj.list[0].c_fphm;
  8591. if (iTag < billOrderList.Length)
  8592. {
  8593. bill_entity.fplsh += ",";
  8594. bill_entity.fpdm += ",";
  8595. bill_entity.fphm += ",";
  8596. }
  8597. bill_entity.Update();
  8598. }
  8599. }
  8600. else
  8601. {
  8602. returnErrorMsg(gres);
  8603. return;
  8604. }
  8605. }
  8606. }
  8607. if (bill_entity.sendType == "纸质发票")
  8608. {
  8609. //作废
  8610. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8611. //if (DateTime.Now.Month == extime.Month)
  8612. //{
  8613. //cres = taobaoHelper.cancel_invoicing(eid);
  8614. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8615. //{
  8616. bill_entity.state = 4;//已作废
  8617. bill_entity.Update();
  8618. returnSuccessMsg("发票已作废");
  8619. return;
  8620. //}
  8621. //else
  8622. //{
  8623. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8624. // bill_entity.Update();
  8625. // returnErrorMsg(cres);
  8626. // return;
  8627. //}
  8628. //}
  8629. //else
  8630. //{
  8631. // returnErrorMsg("纸质发票只能作废本月的发票");
  8632. // return;
  8633. //}
  8634. }
  8635. //红冲
  8636. int redTag = 0;
  8637. string[] fpdmList = bill_entity.fpdm.Split(',');
  8638. string[] fphmList = bill_entity.fphm.Split(',');
  8639. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8640. {
  8641. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8642. return;
  8643. }
  8644. foreach (string billOrderId in billOrderList)
  8645. {
  8646. redTag++;
  8647. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8648. cres += onecres;
  8649. cres += ",";
  8650. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8651. {
  8652. bill_entity.state = 4;//已作废
  8653. //bill_entity.Update();
  8654. //returnSuccessMsg("发票已红冲");
  8655. }
  8656. else if (onecres.IndexOf("重复冲红") != -1)
  8657. {
  8658. bill_entity.state = 4;//已作废
  8659. //bill_entity.Update();
  8660. //returnSuccessMsg("发票已红冲");
  8661. }
  8662. else
  8663. {
  8664. string errmsg = commonHelper.KeepChinese(onecres);
  8665. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8666. }
  8667. }
  8668. bill_entity.Update();
  8669. if (cres.IndexOf("失败") != -1)
  8670. returnErrorMsg("红冲失败");
  8671. else
  8672. returnSuccessMsg("发票已红冲");
  8673. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8674. return;
  8675. }
  8676. return;
  8677. }
  8678. }
  8679. public void del_erp_billorder()
  8680. {
  8681. if (UrlPostParmsCheck("id"))
  8682. {
  8683. string eid = GetPostString("id");
  8684. CeErpBill.Del(eid);
  8685. CeErpBill bill = CeErpBill.Get(eid);
  8686. if (bill != null)
  8687. {
  8688. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8689. }
  8690. returnSuccessMsg("删除成功");
  8691. }
  8692. }
  8693. public void finish_erp_bill()
  8694. {
  8695. if (UrlPostParmsCheck("ids"))
  8696. {
  8697. string eids = GetPostString("ids");
  8698. string[] list = eids.Split(',');
  8699. foreach (string eid in list)
  8700. {
  8701. CeErpBill bill = CeErpBill.Get(eid);
  8702. if (bill != null)
  8703. {
  8704. bill.state = 2;
  8705. bill.Update();
  8706. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8707. }
  8708. }
  8709. returnSuccessMsg("操作成功");
  8710. }
  8711. }
  8712. public void get_erp_returncash()
  8713. {
  8714. DataStruct dStruct = GetPostStruct();
  8715. List<string> lw = new List<string>();
  8716. string tid = GetPostString("tid");
  8717. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8718. string shopname = GetPostString("shopname");
  8719. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8720. string buyernick = GetPostString("buyer_nick");
  8721. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8722. string customer = GetPostString("customer");
  8723. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8724. string returndate1 = GetPostString("returndate1");
  8725. string returndate2 = GetPostString("returndate2");
  8726. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8727. if (dw.Length > 0) lw.Add(dw);
  8728. string finishDate1 = GetPostString("finishdate1");
  8729. string finishDate2 = GetPostString("finishdate2");
  8730. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8731. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8732. string returntype = GetPostString("returntype");
  8733. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8734. string returnvstate = GetPostString("returnvstate");
  8735. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8736. dStruct.Order = "created desc";
  8737. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8738. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8739. writeGridDataTableJson(dStruct.TotalCount, dt);
  8740. }
  8741. public void get_erp_staygoods()
  8742. {
  8743. DataStruct dStruct = GetPostStruct();
  8744. List<string> lw = new List<string>();
  8745. string tid = GetPostString("tid");
  8746. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8747. string shopname = GetPostString("shopname");
  8748. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8749. string wangwang = GetPostString("wangwang");
  8750. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8751. string customer = GetPostString("customer");
  8752. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8753. string returndate1 = GetPostString("returndate1");
  8754. string returndate2 = GetPostString("returndate2");
  8755. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8756. if (dw.Length > 0) lw.Add(dw);
  8757. string finishDate1 = GetPostString("finishdate1");
  8758. string finishDate2 = GetPostString("finishdate2");
  8759. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8760. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8761. string returnvstate = GetPostString("returnvstate");
  8762. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8763. string persuadetype = GetPostString("persuadetype");
  8764. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8765. string customerOrg = GetPostString("customerOrg");
  8766. if (customerOrg.Length > 0)
  8767. {
  8768. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8769. }
  8770. dStruct.Order = "creata_time desc";
  8771. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8772. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8773. writeGridDataTableJson(dStruct.TotalCount, dt);
  8774. }
  8775. public void upd_erp_staygoods()
  8776. {
  8777. if (UrlPostParmsCheck("id"))
  8778. {
  8779. int eid = GetPostInt("id");
  8780. CeErpStayGoods entity = null;
  8781. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8782. if (entity != null)
  8783. {
  8784. entity.audit_type = 1;
  8785. entity.audit_time = DateTime.Now;
  8786. entity.audit_u_id = CurrentUser.UserID;
  8787. entity.audit_u_name = CurrentUser.UserName;
  8788. entity.Update();
  8789. returnSuccessMsg("审核成功!");
  8790. return;
  8791. }
  8792. returnErrorMsg("找不到订单记录");
  8793. }
  8794. }
  8795. public void upd_erp_stayGoodsback()
  8796. {
  8797. if (UrlPostParmsCheck("id"))
  8798. {
  8799. int eid = GetPostInt("id");
  8800. CeErpStayGoods entity = null;
  8801. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8802. if (entity != null)
  8803. {
  8804. entity.audit_text = GetPostString("reason");
  8805. entity.audit_type = 2;
  8806. entity.audit_time = DateTime.Now;
  8807. entity.audit_u_id = CurrentUser.UserID;
  8808. entity.audit_u_name = CurrentUser.UserName;
  8809. entity.Update();
  8810. returnSuccessMsg("退回成功!");
  8811. return;
  8812. }
  8813. returnErrorMsg("找不到订单记录");
  8814. }
  8815. }
  8816. public void upd_erp_returncashverify()
  8817. {
  8818. if (UrlPostParmsCheck("ID"))
  8819. {
  8820. int eid = GetPostInt("ID");
  8821. CeErpReturnCash entity = null;
  8822. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8823. if (entity != null)
  8824. {
  8825. entity.cashstate = 1;
  8826. entity.verifytime = DateTime.Now;
  8827. entity.verifyuserid = CurrentUser.UserID;
  8828. entity.Update();
  8829. returnSuccessMsg("审核成功!");
  8830. return;
  8831. }
  8832. returnErrorMsg("找不到订单记录");
  8833. }
  8834. }
  8835. public void upd_all_erp_returncashverify()
  8836. {
  8837. if (UrlPostParmsCheck("ID"))
  8838. {
  8839. String[] list = GetPostString("ID").Split(',');
  8840. CeErpReturnCash entity = null;
  8841. for (int i = 0; i < list.Length; i++)
  8842. {
  8843. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8844. if (entity != null)
  8845. {
  8846. if (entity.cashstate == 1)
  8847. {
  8848. returnErrorMsg("已审核过的订单不需要在审核!");
  8849. return;
  8850. }
  8851. entity.cashstate = 1;
  8852. entity.verifytime = DateTime.Now;
  8853. entity.verifyuserid = CurrentUser.UserID;
  8854. entity.Update();
  8855. }
  8856. }
  8857. returnSuccessMsg("审核成功!");
  8858. return;
  8859. }
  8860. }
  8861. public void upd_erp_returncashback()
  8862. {
  8863. if (UrlPostParmsCheck("ID"))
  8864. {
  8865. int eid = GetPostInt("ID");
  8866. CeErpReturnCash entity = null;
  8867. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8868. if (entity != null)
  8869. {
  8870. entity.backreason = GetPostString("reason");
  8871. entity.cashstate = 2;
  8872. entity.verifytime = DateTime.Now;
  8873. entity.verifyuserid = CurrentUser.UserID;
  8874. entity.Update();
  8875. returnSuccessMsg("退回成功!");
  8876. return;
  8877. }
  8878. returnErrorMsg("找不到订单记录");
  8879. }
  8880. }
  8881. public void upd_erp_returnprice()
  8882. {
  8883. if (UrlPostParmsCheck("ID"))
  8884. {
  8885. int eid = GetPostInt("ID");
  8886. CeErpReturnCash entity = null;
  8887. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8888. if (entity != null)
  8889. {
  8890. if (entity.cashstate == 1)
  8891. {
  8892. returnErrorMsg("审核通过了不能改");
  8893. return;
  8894. }
  8895. entity.returnprice = GetPostDouble("returnprice");
  8896. entity.Update();
  8897. returnSuccessMsg("修改成功!");
  8898. return;
  8899. }
  8900. returnErrorMsg("找不到订单记录");
  8901. }
  8902. }
  8903. public void del_erp_returncash()
  8904. {
  8905. if (UrlPostParmsCheck("ID"))
  8906. {
  8907. int eid = GetPostInt("ID");
  8908. CeErpReturnCash.Del(eid);
  8909. returnSuccessMsg("操作成功");
  8910. return;
  8911. }
  8912. }
  8913. public void test_for_do_sql()
  8914. {
  8915. string sql = GetPostString("sqlstr");
  8916. if (sql.Length > 0)
  8917. {
  8918. try
  8919. {
  8920. DbHelper.DbConn.ExecuteNonQuery(sql);
  8921. var res_obj = new
  8922. {
  8923. data = "成功",
  8924. };
  8925. string ro_json = JsonConvert.SerializeObject(res_obj);
  8926. returnSuccess(ro_json);
  8927. }
  8928. catch (Exception ex)
  8929. {
  8930. var res_obj = new
  8931. {
  8932. data = ex.Message,
  8933. };
  8934. string ro_json = JsonConvert.SerializeObject(res_obj);
  8935. returnSuccess(ro_json);
  8936. }
  8937. }
  8938. }
  8939. public void get_user_info()
  8940. {
  8941. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8942. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8943. }
  8944. public void get_total_data()
  8945. {
  8946. int userId = CurrentUser.UserID;
  8947. string sql = "";
  8948. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8949. {
  8950. 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);
  8951. }
  8952. else
  8953. {
  8954. 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 " +
  8955. "(select ID from CE_ErpUser where ID = {0}) d " +
  8956. "left join " +
  8957. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8958. ") a on d.ID = a.id left join " +
  8959. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8960. ") b on a.id = b.id1 left join" +
  8961. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8962. ") c on a.id = c.id2;", userId);
  8963. }
  8964. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8965. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8966. }
  8967. public void get_date_area_total_data2()
  8968. {
  8969. int userId = CurrentUser.UserID;
  8970. string date_type = GetPostString("timetype");
  8971. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8972. string sql = "";
  8973. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8974. {
  8975. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8976. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8977. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8978. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8979. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8980. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8981. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8982. ") a on e.ID = a.id left join " +
  8983. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8984. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8985. ") b on a.id = b.id1 " +
  8986. "left join " +
  8987. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8988. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8989. ") c on a.id = c.id2 " +
  8990. "left join " +
  8991. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8992. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8993. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8994. }
  8995. else
  8996. {
  8997. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8998. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8999. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  9000. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  9001. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  9002. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  9003. ") a on e.ID = a.id left join " +
  9004. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  9005. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  9006. ") c on a.id = c.id2 " +
  9007. "left join " +
  9008. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  9009. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  9010. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  9011. }
  9012. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9013. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9014. }
  9015. public void get_date_area_total_data()
  9016. {
  9017. int userId = CurrentUser.UserID;
  9018. string date_type = GetPostString("timetype");
  9019. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9020. string date1 = searchDT[0].ToString();
  9021. string date2 = searchDT[1].ToString();
  9022. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  9023. {
  9024. SqlParameter[] sqlParameter ={
  9025. new SqlParameter("@userId", SqlDbType.Int,4),
  9026. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9027. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9028. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9029. };
  9030. sqlParameter[0].Value = userId;
  9031. sqlParameter[1].Value = date1;
  9032. sqlParameter[2].Value = date2;
  9033. sqlParameter[3].Direction = ParameterDirection.Output;
  9034. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  9035. string res = sqlParameter[3].Value.ToString();
  9036. var res_obj = new
  9037. {
  9038. data = res
  9039. };
  9040. string ro_json = JsonConvert.SerializeObject(res_obj);
  9041. returnSuccess(ro_json);
  9042. }
  9043. else
  9044. {
  9045. SqlParameter[] sqlParameter ={
  9046. new SqlParameter("@userId", SqlDbType.Int,4),
  9047. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  9048. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  9049. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  9050. };
  9051. sqlParameter[0].Value = userId;
  9052. sqlParameter[1].Value = date1;
  9053. sqlParameter[2].Value = date2;
  9054. sqlParameter[3].Direction = ParameterDirection.Output;
  9055. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  9056. string res = sqlParameter[3].Value.ToString();
  9057. var res_obj = new
  9058. {
  9059. data = res
  9060. };
  9061. string ro_json = JsonConvert.SerializeObject(res_obj);
  9062. returnSuccess(ro_json);
  9063. }
  9064. //writeGridDataViewJson(dt.Rows.Count, dv);
  9065. }
  9066. public void get_order_list()
  9067. {
  9068. string strFields = GetPostString("paraFields");
  9069. string strOrder = GetPostString("paraOrder");
  9070. string strWhere = GetPostString("paraWhere");
  9071. string strPageSize = GetPostString("paraPageSize");
  9072. DataStruct dStruct = GetPostStruct();
  9073. dStruct.PageSize = int.Parse(strPageSize);
  9074. dStruct.Fileds = strFields;
  9075. dStruct.Order = strOrder;
  9076. dStruct.MainWhere = strWhere;
  9077. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9078. writeGridDataTableJson(dStruct.TotalCount, dt);
  9079. }
  9080. ////获取待开始订单列表
  9081. //public void get_wait_design_order_list()
  9082. //{
  9083. // string date_type = GetPostString("date_type");
  9084. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9085. // DataStruct dStruct = GetPostStruct();
  9086. // dStruct.PageSize = 1000;
  9087. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  9088. // List<string> lw = new List<string>();
  9089. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  9090. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9091. // dStruct.Order = "WaitDesignTime asc";
  9092. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9093. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9094. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9095. //}
  9096. //获取完成单量排名
  9097. public void get_finish_order_count_ranking()
  9098. {
  9099. /* string date_type = GetPostString("date_type");
  9100. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9101. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9102. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9103. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9104. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9105. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9106. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9107. writeGridDataTableJson(0, new DataTable());
  9108. }
  9109. public void get_finish_order_amount_ranking()
  9110. {
  9111. /*string date_type = GetPostString("date_type");
  9112. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9113. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9114. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9115. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9116. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9117. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9118. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9119. writeGridDataTableJson(0, new DataTable());
  9120. }
  9121. public void get_finish_refund_count_ranking()
  9122. {
  9123. string date_type = GetPostString("date_type");
  9124. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9125. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9126. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9127. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9128. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9129. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9130. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9131. writeGridDataTableJson(dt.Rows.Count, dt);
  9132. }
  9133. public void get_finish_refund_amount_ranking()
  9134. {
  9135. string date_type = GetPostString("date_type");
  9136. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9137. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9138. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9139. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9140. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9141. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9142. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9143. writeGridDataTableJson(dt.Rows.Count, dt);
  9144. }
  9145. public void set_erp_finishorder_director()
  9146. {
  9147. if (UrlPostParmsCheck("ctid"))
  9148. {
  9149. string eid = GetPostString("ctid");
  9150. CeErpTradeCell entity = null;
  9151. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9152. if (entity != null)
  9153. {
  9154. entity.OrderState = 8;
  9155. entity.Update();
  9156. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9157. returnSuccessMsg("操作成功!");
  9158. return;
  9159. }
  9160. returnErrorMsg("找不到记录");
  9161. }
  9162. }
  9163. public void get_erp_placeregistlist()
  9164. {
  9165. DataStruct dStruct = GetPostStruct();
  9166. List<string> lw = new List<string>();
  9167. string outsid = GetPostString("outsid");
  9168. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9169. string memo = GetPostString("memo");
  9170. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9171. string filename = GetPostString("filename");
  9172. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9173. string islate = GetPostString("islate");
  9174. if (islate.Length > 0)
  9175. {
  9176. if (islate == "1")
  9177. lw.Add(string.Format("OutLate>0"));
  9178. else
  9179. lw.Add(string.Format("OutLate=0"));
  9180. }
  9181. string placedate1 = GetPostString("placedate1");
  9182. string placedate2 = GetPostString("placedate2");
  9183. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9184. if (dw.Length > 0) lw.Add(dw);
  9185. string deliveryDate1 = GetPostString("deliverydate1");
  9186. string deliveryDate2 = GetPostString("deliverydate2");
  9187. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9188. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9189. dStruct.Order = "ID desc";
  9190. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9191. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9192. writeGridDataTableJson(dStruct.TotalCount, dt);
  9193. }
  9194. public void ins_erp_placeregist()
  9195. {
  9196. if (UrlPostParmsCheck("id"))
  9197. {
  9198. string eid = GetPostString("id");
  9199. CeErpPlaceRegister entity = null;
  9200. if (eid == "0")//新增
  9201. {
  9202. entity = new CeErpPlaceRegister();
  9203. string xdTime = GetPostString("placeTime");
  9204. if (xdTime.Length > 0)
  9205. {
  9206. entity.PlactTime = Convert.ToDateTime(xdTime);
  9207. }
  9208. string fhTime = GetPostString("deliveryTime");
  9209. if (fhTime.Length > 0)
  9210. {
  9211. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9212. }
  9213. string preTime = GetPostString("preOutTime");
  9214. if (preTime.Length > 0)
  9215. {
  9216. entity.PreOutTime = Convert.ToDateTime(preTime);
  9217. }
  9218. entity.DeliveryCount = GetPostInt("deliveryCount");
  9219. entity.ReceiveCount = GetPostInt("receiveCount");
  9220. entity.OutSid = GetPostString("outSid");
  9221. entity.FileName = GetPostString("fileName");
  9222. entity.Memo = GetPostString("memo");
  9223. entity.AddUserId = CurrentUser.UserID;
  9224. entity.CreateTime = DateTime.Now;
  9225. entity.Img = GetPostString("img");
  9226. entity.Supplier = GetPostInt("supplier");
  9227. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9228. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9229. {
  9230. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9231. DateTime dt2 = (DateTime)entity.PreOutTime;
  9232. TimeSpan span = dt1.Subtract(dt2);
  9233. if (span.Days > 0)
  9234. {
  9235. entity.OutLate = span.Days;
  9236. }
  9237. }
  9238. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9239. entity.Create();
  9240. returnSuccessMsg("添加成功!");
  9241. return;
  9242. }
  9243. else //修改
  9244. {
  9245. entity = CeErpPlaceRegister.Get(eid);
  9246. if (entity != null)
  9247. {
  9248. string xdTime = GetPostString("placeTime");
  9249. if (xdTime.Length > 0)
  9250. {
  9251. entity.PlactTime = Convert.ToDateTime(xdTime);
  9252. }
  9253. string fhTime = GetPostString("deliveryTime");
  9254. if (fhTime.Length > 0)
  9255. {
  9256. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9257. }
  9258. string preTime = GetPostString("preOutTime");
  9259. if (preTime.Length > 0)
  9260. {
  9261. entity.PreOutTime = Convert.ToDateTime(preTime);
  9262. }
  9263. entity.DeliveryCount = GetPostInt("deliveryCount");
  9264. entity.ReceiveCount = GetPostInt("receiveCount");
  9265. if (entity.DeliveryCount == entity.ReceiveCount)
  9266. {
  9267. entity.CurState = "已完成";
  9268. }
  9269. else
  9270. {
  9271. entity.CurState = "未完成";
  9272. }
  9273. entity.OutSid = GetPostString("outSid");
  9274. entity.FileName = GetPostString("fileName");
  9275. entity.Memo = GetPostString("memo");
  9276. entity.Img = GetPostString("img");
  9277. entity.Supplier = GetPostInt("supplier");
  9278. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9279. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9280. {
  9281. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9282. DateTime dt2 = (DateTime)entity.PreOutTime;
  9283. TimeSpan span = dt1.Subtract(dt2);
  9284. if (span.Days > 0)
  9285. {
  9286. entity.OutLate = span.Days;
  9287. }
  9288. }
  9289. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9290. entity.Update();
  9291. returnSuccessMsg("修改成功");
  9292. return;
  9293. }
  9294. returnErrorMsg("找不到对应的记录");
  9295. return;
  9296. }
  9297. }
  9298. returnErrorMsg("缺少必要参数");
  9299. }
  9300. public void del_erp_placeregist()
  9301. {
  9302. string eid = GetPostString("id");
  9303. CeErpPlaceRegister.Del(eid);
  9304. returnSuccessMsg("删除成功!");
  9305. return;
  9306. }
  9307. public void ins_erp_placeregistbyorder()
  9308. {
  9309. string ctid = GetPostString("ctid");
  9310. if (ctid.Length > 0)
  9311. {
  9312. StringBuilder sql = new StringBuilder();
  9313. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9314. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9315. if (dt.Rows.Count > 0)
  9316. {
  9317. foreach (DataRow dr in dt.Rows)
  9318. {
  9319. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9320. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9321. entity.AddUserId = CurrentUser.UserID;
  9322. entity.tid = dr["tid"].ToString();
  9323. entity.Did = Convert.ToString(dr["ctid"]);
  9324. entity.splitTag = dr["SplitTag"].ToString();
  9325. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9326. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9327. if (pre_ctid.Length > 0)
  9328. {
  9329. sellmemo = sellmemo.Replace(pre_ctid, "");
  9330. }
  9331. sellmemo = sellmemo.Replace("[", "");
  9332. sellmemo = sellmemo.Replace("]", "");
  9333. entity.FileName = sellmemo;
  9334. string count = dr["ProductCount"].ToString();
  9335. int usecount = commonHelper.getIntCountFromString(count);
  9336. entity.DeliveryCount = usecount;
  9337. entity.CurState = "未完成";
  9338. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9339. {
  9340. entity.Supplier = 24;//dl手提袋定制
  9341. }
  9342. else
  9343. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9344. entity.CreateTime = DateTime.Now;
  9345. entity.Create();
  9346. }
  9347. returnSuccessMsg("操作成功");
  9348. return;
  9349. }
  9350. returnErrorMsg("没有找到对应订单");
  9351. return;
  9352. }
  9353. returnErrorMsg("缺少订单编号");
  9354. return;
  9355. }
  9356. public void get_erp_persuadelist()
  9357. {
  9358. DataStruct dStruct = GetPostStruct();
  9359. List<string> lw = new List<string>();
  9360. string ctid = GetPostString("ctid");
  9361. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9362. string shopname = GetPostString("shopname");
  9363. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9364. string buyernick = GetPostString("buyer_nick");
  9365. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9366. string customer = GetPostString("customer");
  9367. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9368. string returndate1 = GetPostString("returndate1");
  9369. string returndate2 = GetPostString("returndate2");
  9370. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9371. if (dw.Length > 0) lw.Add(dw);
  9372. string finishDate1 = GetPostString("finishdate1");
  9373. string finishDate2 = GetPostString("finishdate2");
  9374. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9375. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9376. string persuadetype = GetPostString("persuadetype");
  9377. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9378. string returnvstate = GetPostString("returnvstate");
  9379. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9380. dStruct.Order = "created desc";
  9381. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9382. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9383. writeGridDataTableJson(dStruct.TotalCount, dt);
  9384. }
  9385. public void upd_erp_returnpersuadeback()
  9386. {
  9387. if (UrlPostParmsCheck("ID"))
  9388. {
  9389. int eid = GetPostInt("ID");
  9390. CeErpPersuade entity = null;
  9391. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9392. if (entity != null)
  9393. {
  9394. entity.backreason = GetPostString("reason");
  9395. entity.pstate = 2;
  9396. entity.verifytime = DateTime.Now;
  9397. entity.verifyuserid = CurrentUser.UserID;
  9398. entity.Update();
  9399. returnSuccessMsg("退回成功!");
  9400. return;
  9401. }
  9402. returnErrorMsg("找不到订单记录");
  9403. }
  9404. }
  9405. public void upd_erp_returnpersuadeverify()
  9406. {
  9407. if (UrlPostParmsCheck("ID"))
  9408. {
  9409. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9410. {
  9411. returnErrorMsg("暂无权限审核");
  9412. return;
  9413. }
  9414. int eid = GetPostInt("ID");
  9415. CeErpPersuade entity = null;
  9416. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9417. if (entity != null)
  9418. {
  9419. entity.pstate = 1;
  9420. entity.verifytime = DateTime.Now;
  9421. entity.verifyuserid = CurrentUser.UserID;
  9422. entity.Update();
  9423. returnSuccessMsg("审核成功!");
  9424. return;
  9425. }
  9426. returnErrorMsg("找不到订单记录");
  9427. }
  9428. }
  9429. public void del_erp_persuade()
  9430. {
  9431. if (UrlPostParmsCheck("ID"))
  9432. {
  9433. int eid = GetPostInt("ID");
  9434. CeErpPersuade.Del(eid);
  9435. returnSuccessMsg("操作成功");
  9436. return;
  9437. }
  9438. }
  9439. public void get_erp_oldcustoupload()
  9440. {
  9441. DataStruct dStruct = GetPostStruct();
  9442. List<string> lw = new List<string>();
  9443. string buyernick = GetPostString("buyer_nick");
  9444. if (buyernick.Length > 0)
  9445. {
  9446. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9447. }
  9448. else
  9449. return;
  9450. dStruct.Order = "pay_time desc";
  9451. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9452. DataTable dt = null;
  9453. dt = WebCache.GetData("view_erptradecell", dStruct);
  9454. writeGridDataTableJson(dStruct.TotalCount, dt);
  9455. }
  9456. public void get_erp_checkorderlist()
  9457. {
  9458. DataStruct dStruct = GetPostStruct();
  9459. List<string> lw = new List<string>();
  9460. string tid = GetPostString("ctid");
  9461. if (tid.Length > 0)
  9462. {
  9463. string select_tid = getTidByCtid(tid);
  9464. lw.Add(string.Format("tid='{0}'", select_tid));
  9465. }
  9466. string shopname = GetPostString("shopname");
  9467. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9468. string buyernick = GetPostString("buyer_nick");
  9469. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9470. string customer = GetPostString("customer");
  9471. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9472. string design = GetPostString("design");
  9473. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9474. string orderState = GetPostString("orderState");
  9475. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9476. string address = GetPostString("address");
  9477. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9478. string sellermemo = GetPostString("seller_memo");
  9479. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9480. string supplier = GetPostString("supplier");
  9481. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9482. {
  9483. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9484. }
  9485. else
  9486. {
  9487. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9488. }
  9489. string date1 = GetPostString("date1");
  9490. string date2 = GetPostString("date2");
  9491. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9492. if (dw.Length > 0) lw.Add(dw);
  9493. string placedate1 = GetPostString("placedate1");
  9494. string placedate2 = GetPostString("placedate2");
  9495. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9496. if (fdw.Length > 0) lw.Add(fdw);
  9497. string price1 = GetPostString("price1");
  9498. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9499. string price2 = GetPostString("price2");
  9500. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9501. string checkst = GetPostString("checkstate");
  9502. if (checkst.Length > 0 && "10".Equals(checkst))
  9503. {
  9504. lw.Add(string.Format("CheckOut>0"));
  9505. }
  9506. else
  9507. {
  9508. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9509. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9510. }
  9511. if (CurrentUser.UserPost.Post.Code == "AfterSale")
  9512. {
  9513. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  9514. }
  9515. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9516. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9517. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9518. writeGridDataTableJson(dStruct.TotalCount, dt);
  9519. }
  9520. public void ins_erp_startCheck()
  9521. {
  9522. if (UrlPostParmsCheck("ctid"))
  9523. {
  9524. string eid = GetPostString("ctid");
  9525. CeErpTradeCell entity = null;
  9526. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9527. if (entity != null)
  9528. {
  9529. entity.MemoOpt = 4;
  9530. entity.UpdateTime = DateTime.Now;
  9531. entity.Update();
  9532. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9533. CeErpSukuraData.createInfo(entity.ctid, 6);
  9534. returnSuccessMsg("操作成功!");
  9535. return;
  9536. }
  9537. returnErrorMsg("找不到记录");
  9538. }
  9539. }
  9540. public void upd_erp_sendXlw()
  9541. {
  9542. if (UrlPostParmsCheck("ctid"))
  9543. {
  9544. string eid = GetPostString("ctid");
  9545. CeErpTradeCell entity = null;
  9546. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9547. if (entity != null)
  9548. {
  9549. if (entity.IsSendGift == 1)
  9550. {
  9551. returnErrorMsg("请勿重复标记");
  9552. return;
  9553. }
  9554. entity.IsSendGift = 1;
  9555. entity.Update();
  9556. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9557. returnSuccessMsg("操作成功!");
  9558. return;
  9559. }
  9560. returnErrorMsg("找不到记录");
  9561. }
  9562. }
  9563. public void cancel_sendXlw()
  9564. {
  9565. if (UrlPostParmsCheck("ctid"))
  9566. {
  9567. string eid = GetPostString("ctid");
  9568. CeErpTradeCell entity = null;
  9569. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9570. if (entity != null)
  9571. {
  9572. if (entity.IsSendGift == 0)
  9573. {
  9574. returnErrorMsg("未标记小礼物");
  9575. return;
  9576. }
  9577. entity.IsSendGift = 0;
  9578. entity.Update();
  9579. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9580. returnSuccessMsg("操作成功!");
  9581. return;
  9582. }
  9583. returnErrorMsg("找不到记录");
  9584. }
  9585. }
  9586. public void get_erp_designbill()
  9587. {
  9588. DataStruct dStruct = GetPostStruct();
  9589. List<string> lw = new List<string>();
  9590. int isMy = GetInt("my");
  9591. if (isMy == 1)
  9592. {
  9593. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9594. }
  9595. string tid = GetPostString("tid");
  9596. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9597. string userName = GetPostString("design");
  9598. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9599. string price1 = GetPostString("price1");
  9600. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9601. string price2 = GetPostString("price2");
  9602. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9603. string rePrice1 = GetPostString("rePrice1");
  9604. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9605. string rePrice2 = GetPostString("rePrice2");
  9606. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9607. string designerType = GetPostString("designerType");
  9608. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9609. string orderState = GetPostString("orderState");
  9610. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9611. string endTime1 = GetPostString("endTime1");
  9612. string endTime2 = GetPostString("endTime2");
  9613. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9614. if (dw.Length > 0) lw.Add(dw);
  9615. string isDk = GetPostString("isDk");
  9616. if (isDk == "1")
  9617. {
  9618. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9619. }
  9620. else if (isDk == "0")
  9621. {
  9622. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9623. }
  9624. dStruct.Order = "oid, create_time desc";
  9625. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9626. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9627. writeGridDataTableJson(dStruct.TotalCount, dt);
  9628. }
  9629. public void upd_erp_designerbill()
  9630. {
  9631. if (UrlPostParmsCheck("ID"))
  9632. {
  9633. string eid = GetPostString("ID");
  9634. CeErpDesignerBill entity = null;
  9635. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9636. if (entity != null)
  9637. {
  9638. if (GetPostDouble("designerpirce") > 0)
  9639. {
  9640. entity.realPrice = GetPostDouble("designerpirce");
  9641. entity.update_time = DateTime.Now;
  9642. entity.update_u_id = CurrentUser.UserID;
  9643. entity.update_u_name = CurrentUser.UserName;
  9644. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9645. entity.Update();
  9646. returnSuccessMsg("操作成功!");
  9647. return;
  9648. }
  9649. else
  9650. {
  9651. entity.price = GetPostDouble("price");
  9652. entity.update_time = DateTime.Now;
  9653. entity.update_u_id = CurrentUser.UserID;
  9654. entity.update_u_name = CurrentUser.UserName;
  9655. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9656. entity.Update();
  9657. returnSuccessMsg("操作成功!");
  9658. return;
  9659. }
  9660. }
  9661. returnErrorMsg("找不到记录");
  9662. }
  9663. }
  9664. public void audit_erp_designerbill()
  9665. {
  9666. if (UrlPostParmsCheck("ID"))
  9667. {
  9668. string eid = GetPostString("ID");
  9669. CeErpDesignerBill entity = null;
  9670. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9671. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9672. if (entity != null)
  9673. {
  9674. entity.realPrice = GetPostDouble("designerpirce");
  9675. entity.update_time = DateTime.Now;
  9676. entity.update_u_id = CurrentUser.UserID;
  9677. entity.update_u_name = CurrentUser.UserName;
  9678. entity.isAudit = 1;
  9679. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9680. entity.Update();
  9681. if (orderEntity != null)
  9682. {
  9683. orderEntity.IsReadTag = 3;
  9684. orderEntity.Update();
  9685. }
  9686. returnSuccessMsg("操作成功!");
  9687. return;
  9688. }
  9689. returnErrorMsg("找不到记录");
  9690. }
  9691. }
  9692. public void all_audit_erp_designerbill()
  9693. {
  9694. if (UrlPostParmsCheck("idList"))
  9695. {
  9696. string[] list = GetPostString("idList").Split(',');
  9697. CeErpDesignerBill entity = null;
  9698. for (int i = 0; i < list.Length; i++)
  9699. {
  9700. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9701. if (entity == null) return;
  9702. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9703. if (orderEntity == null) return;
  9704. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9705. entity.update_time = DateTime.Now;
  9706. entity.update_u_id = CurrentUser.UserID;
  9707. entity.update_u_name = CurrentUser.UserName;
  9708. entity.isAudit = 1;
  9709. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9710. entity.Update();
  9711. orderEntity.IsReadTag = 3;
  9712. orderEntity.Update();
  9713. }
  9714. returnSuccessMsg("操作成功!");
  9715. return;
  9716. }
  9717. }
  9718. public void get_erp_sameorders()
  9719. {
  9720. if (UrlPostParmsCheck("ctid"))
  9721. {
  9722. string eid = GetPostString("ctid");
  9723. CeErpTradeCell entity = null;
  9724. entity = CeErpTradeCell.GetByCtid(eid);
  9725. if (entity != null)
  9726. {
  9727. StringBuilder sql = new StringBuilder();
  9728. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9729. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9730. var res = new
  9731. {
  9732. data = dt.Rows.Count
  9733. };
  9734. string ro_jsond = JsonConvert.SerializeObject(res);
  9735. returnSuccess(ro_jsond);
  9736. return;
  9737. }
  9738. returnErrorMsg("未找到订单");
  9739. return;
  9740. }
  9741. returnErrorMsg("缺少必要的参数");
  9742. }
  9743. public void get_erp_islasthavesameorder()
  9744. {
  9745. if (UrlPostParmsCheck("ctid"))
  9746. {
  9747. string eid = GetPostString("ctid");
  9748. string[] ctidList = eid.Split(',');
  9749. StringBuilder sql = new StringBuilder();
  9750. string tisCtid = "";
  9751. foreach (string ctid in ctidList)
  9752. {
  9753. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9754. if (entity != null)
  9755. {
  9756. sql = new StringBuilder();
  9757. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9758. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9759. if (dth.Rows.Count > 0)
  9760. {
  9761. tisCtid += entity.ctid;
  9762. tisCtid += ",";
  9763. }
  9764. }
  9765. }
  9766. if (tisCtid.Length > 0)
  9767. {
  9768. var res = new
  9769. {
  9770. data = tisCtid
  9771. };
  9772. string ro_jsond = JsonConvert.SerializeObject(res);
  9773. returnSuccess(ro_jsond);
  9774. }
  9775. else
  9776. {
  9777. var res = new
  9778. {
  9779. data = ""
  9780. };
  9781. string ro_jsond = JsonConvert.SerializeObject(res);
  9782. returnSuccess(ro_jsond);
  9783. }
  9784. return;
  9785. }
  9786. returnErrorMsg("缺少必要的参数");
  9787. }
  9788. public void file_client_down_url()
  9789. {
  9790. if (!UrlPostParmsCheck("userId"))
  9791. {
  9792. returnErrorMsg("缺少必要的参数");
  9793. }
  9794. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9795. }
  9796. public void checkout_form_data()
  9797. {
  9798. if (!UrlPostParmsCheck("tid"))
  9799. {
  9800. returnErrorMsg("缺少必要的参数");
  9801. }
  9802. string tid = GetPostString("tid");
  9803. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9804. if (ceErpOrderFormData != null)
  9805. {
  9806. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9807. returnSuccess(ro_jsond);
  9808. return;
  9809. }
  9810. returnErrorMsg("尚未有文件!");
  9811. }
  9812. public void back_supplier_audit()
  9813. {
  9814. int userId = CurrentUser.UserID;
  9815. StringBuilder sql = new StringBuilder();
  9816. 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);
  9817. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9818. if (dt.Rows.Count > 0)
  9819. {
  9820. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9821. }
  9822. else
  9823. {
  9824. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9825. }
  9826. }
  9827. public void back_supplier_query()
  9828. {
  9829. string eid = GetPostString("ctid");
  9830. if (eid != "")
  9831. {
  9832. StringBuilder sql = new StringBuilder();
  9833. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9834. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9835. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9836. }
  9837. else
  9838. {
  9839. returnErrorMsg("找不到订单记录");
  9840. return;
  9841. }
  9842. }
  9843. public void verified_to_order()
  9844. {
  9845. int userId = CurrentUser.UserID;
  9846. StringBuilder sql = new StringBuilder();
  9847. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9848. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9849. if (dt.Rows.Count > 0)
  9850. {
  9851. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9852. }
  9853. else
  9854. {
  9855. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9856. }
  9857. }
  9858. public void upd_supplier_audit()
  9859. {
  9860. if (UrlPostParmsCheck("ctid"))
  9861. {
  9862. string eid = GetPostString("ctid");
  9863. string reason = GetPostString("returnreason");
  9864. CeErpTradeCell entity = null;
  9865. CeWithdraw withdraw = null;
  9866. withdraw = CeWithdraw.GetByTid(eid);
  9867. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9868. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9869. {
  9870. if (withdraw != null)
  9871. {
  9872. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9873. {
  9874. returnSuccessMsg("您没有权限操作!");
  9875. return;
  9876. }
  9877. else
  9878. {
  9879. if (reason.Equals("1"))
  9880. {
  9881. if (entity.OrderState == -1)
  9882. {
  9883. if (entity.FinishPlaceTime == null)
  9884. {
  9885. entity.OrderState = 2;
  9886. }
  9887. else
  9888. {
  9889. entity.OrderState = 6;
  9890. }
  9891. }
  9892. entity.Update();
  9893. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9894. if (withdraw != null)
  9895. {
  9896. withdraw.status = int.Parse(reason);
  9897. withdraw.Update();
  9898. }
  9899. returnSuccessMsg("操作成功!");
  9900. return;
  9901. }
  9902. else
  9903. {
  9904. withdraw.status = int.Parse(reason);
  9905. withdraw.acknowledgingtime = DateTime.Now;
  9906. withdraw.Update();
  9907. returnSuccessMsg("查看详细请点击线下订单查询");
  9908. return;
  9909. }
  9910. }
  9911. }
  9912. // 第一个字符是 'N'
  9913. }
  9914. if (eid[0] != 'N')
  9915. {
  9916. }
  9917. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9918. {
  9919. entity.IsVerifyToSupplier = false;
  9920. entity.IsReturn = 1;
  9921. entity.ReturnTime = DateTime.Now;
  9922. entity.ReturnReason = reason;
  9923. if (entity.OrderState == 6)
  9924. {
  9925. entity.OrderState = 5;
  9926. }
  9927. entity.Update();
  9928. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9929. if (withdraw != null)
  9930. {
  9931. withdraw.status = int.Parse(reason);
  9932. withdraw.Update();
  9933. }
  9934. returnSuccessMsg("操作成功!");
  9935. return;
  9936. }
  9937. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9938. {
  9939. ;
  9940. if (withdraw != null)
  9941. {
  9942. withdraw.status = int.Parse(reason);
  9943. withdraw.acknowledgingtime = DateTime.Now;
  9944. withdraw.Update();
  9945. returnSuccessMsg("供应商取消撤回!");
  9946. return;
  9947. }
  9948. }
  9949. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9950. {
  9951. if (entity.OrderState == -1)
  9952. {
  9953. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  9954. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9955. if (!string.IsNullOrEmpty(ceErpTrade.receiver_state) && ceErpTrade.receiver_state.Contains("台湾") && string.IsNullOrEmpty(ceErpTrade.receiver_zip))
  9956. {
  9957. returnErrorMsg("台湾客户需填写身份证!");
  9958. return;
  9959. }
  9960. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9961. {
  9962. returnErrorMsg("订单spu没有确认无法通过审核!");
  9963. return;
  9964. }
  9965. if (entity.FinishPlaceTime == null)
  9966. {
  9967. entity.OrderState = 2;
  9968. }
  9969. else
  9970. {
  9971. entity.OrderState = 3;
  9972. }
  9973. commonHelper.getCytPrice(entity);
  9974. }
  9975. entity.Update();
  9976. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9977. if (withdraw != null)
  9978. {
  9979. withdraw.status = int.Parse(reason);
  9980. withdraw.Update();
  9981. }
  9982. returnSuccessMsg("操作成功!");
  9983. return;
  9984. }
  9985. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9986. {
  9987. if (withdraw == null)
  9988. {
  9989. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9990. return;
  9991. }
  9992. }
  9993. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9994. {
  9995. if (withdraw != null)
  9996. {
  9997. withdraw.status = int.Parse(reason);
  9998. withdraw.acknowledgingtime = DateTime.Now;
  9999. withdraw.Update();
  10000. returnSuccessMsg("查看详细请点击线下订单查询");
  10001. return;
  10002. }
  10003. }
  10004. return;
  10005. }
  10006. }
  10007. //校验报价
  10008. public void refund_order_tip()
  10009. {
  10010. int userid = CurrentUser.UserID;
  10011. int sectionId = CurrentUser.UserPost.OrgID;
  10012. StringBuilder sql = new StringBuilder();
  10013. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  10014. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10015. List<string> ids = new List<string>();
  10016. if (dth.Rows.Count > 0)
  10017. {
  10018. foreach (DataRow dr in dth.Rows)
  10019. {
  10020. ids.Add(dr["ID"].ToString());
  10021. }
  10022. try
  10023. {
  10024. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  10025. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  10026. }
  10027. catch (Exception ex)
  10028. {
  10029. }
  10030. }
  10031. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10032. }
  10033. public void refund_order_Design()
  10034. {
  10035. int userid = CurrentUser.UserID;
  10036. int sectionId = CurrentUser.UserPost.OrgID;
  10037. StringBuilder sql = new StringBuilder();
  10038. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  10039. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10040. List<string> ids = new List<string>();
  10041. if (dth.Rows.Count > 0)
  10042. {
  10043. foreach (DataRow dr in dth.Rows)
  10044. {
  10045. ids.Add(dr["ID"].ToString());
  10046. }
  10047. try
  10048. {
  10049. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  10050. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10051. }
  10052. catch (Exception ex)
  10053. {
  10054. }
  10055. }
  10056. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  10057. }
  10058. public void change_order_info()
  10059. {
  10060. int userid = CurrentUser.UserID;
  10061. StringBuilder sql = new StringBuilder();
  10062. 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);
  10063. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10064. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  10065. }
  10066. public void change_win_mome()
  10067. {
  10068. if (UrlPostParmsCheck("id,ctid"))
  10069. {
  10070. string id = GetPostString("id");
  10071. string ctid = GetPostString("ctid");
  10072. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  10073. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  10074. if (ce == null || ceErpMessageTip == null)
  10075. {
  10076. returnSuccessMsg("未找到对应的订单!");
  10077. return;
  10078. }
  10079. if (ce.OrderState >= 5)
  10080. {
  10081. returnSuccessMsg("已上传文件无法修改!");
  10082. return;
  10083. }
  10084. int type = GetPostInt("type");
  10085. string content = GetPostString("content");
  10086. if (type == 0)
  10087. {
  10088. content = content.Replace("(", "(");
  10089. content = content.Replace(")", ")");
  10090. string check = MidStrEx(content, "(", ")").Trim();
  10091. if (string.IsNullOrEmpty(check))
  10092. {
  10093. returnSuccessMsg("文件名格式不正确");
  10094. return;
  10095. }
  10096. }
  10097. ce.seller_memo = content;
  10098. ce.Update();
  10099. ceErpMessageTip.isVisit = true;
  10100. ceErpMessageTip.Update();
  10101. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10102. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10103. ApiVo apiVo = new ApiVo();
  10104. apiVo.orderNumber = ce.ctid;
  10105. apiVo.actionName = "demandDesign";
  10106. apiVo.orderRemarks = content;
  10107. apiVo.demandExamine = type + 1;
  10108. designHelper.API_WorkCore(apiVo);//demandDesign
  10109. returnSuccessMsg("修改成功!");
  10110. }
  10111. }
  10112. public static string MidStrEx(string sourse, string startstr, string endstr)
  10113. {
  10114. string result = string.Empty;
  10115. int startindex, endindex;
  10116. try
  10117. {
  10118. startindex = sourse.IndexOf(startstr);
  10119. if (startindex == -1)
  10120. return result;
  10121. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10122. endindex = tmpstr.IndexOf(endstr);
  10123. if (endindex == -1)
  10124. return result;
  10125. result = tmpstr.Remove(endindex);
  10126. }
  10127. catch (Exception ex)
  10128. {
  10129. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10130. }
  10131. return result;
  10132. }
  10133. public void refund_order_list()
  10134. {
  10135. int userid = CurrentUser.UserID;
  10136. int sectionId = CurrentUser.UserPost.OrgID;
  10137. StringBuilder sql = new StringBuilder();
  10138. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10139. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10140. DataStruct dStruct = GetPostStruct();
  10141. DataTable dt = null;
  10142. List<string> ids = new List<string>();
  10143. List<string> tids = new List<string>();
  10144. if (dth.Rows.Count > 0)
  10145. {
  10146. foreach (DataRow dr in dth.Rows)
  10147. {
  10148. tids.Add("'" + dr["tid"].ToString() + "'");
  10149. ids.Add(dr["id"].ToString());
  10150. }
  10151. try
  10152. {
  10153. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10154. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10155. List<string> lw = new List<string>();
  10156. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10157. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10158. dt = WebCache.GetData("view_orderlist", dStruct);
  10159. }
  10160. catch (Exception ex)
  10161. {
  10162. }
  10163. }
  10164. writeGridDataTableJson(dStruct.TotalCount, dt);
  10165. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10166. }
  10167. //新增
  10168. public void order_batch_downloads()
  10169. {
  10170. string ceid = GetPostString("tid");
  10171. String[] tid = ceid.Split(',');
  10172. order_batch_caiyingtong(tid);
  10173. /* (string success, string errors) = UploadFiles(tid);
  10174. returnSuccessMsg(success + errors);*/
  10175. return;
  10176. }
  10177. //报价接口
  10178. public void Get_To_Quote()
  10179. {
  10180. string ceid = GetPostString("ctid");
  10181. if (ceid != null)
  10182. {
  10183. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10184. if (entity != null)
  10185. {
  10186. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10187. {
  10188. return;
  10189. }
  10190. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10191. double price = 0;
  10192. if (cp == null)
  10193. {
  10194. JObject jsonObject12 = new JObject
  10195. {
  10196. { "UserId", "77886" },
  10197. { "Pwd", "lt666888" },
  10198. { "Filename", entity.seller_memo }
  10199. };
  10200. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10201. JObject jsonObjects1 = JObject.Parse(response1);
  10202. string ms1g = (string)jsonObjects1["msg"];
  10203. if (ms1g == "报价成功")
  10204. {
  10205. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10206. string data = (string)jsonObject1["price"];
  10207. 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 + "');";
  10208. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10209. returnSuccessMsg("获取报价成功:" + data);
  10210. price = Convert.ToDouble(data);
  10211. }
  10212. else
  10213. {
  10214. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10215. return;
  10216. }
  10217. }
  10218. String[] beizhu = entity.seller_memo.Split('-');
  10219. String chanp = "";
  10220. if (beizhu.Length > 0)
  10221. {
  10222. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10223. }
  10224. else
  10225. {
  10226. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10227. }
  10228. JObject jsonObject = new JObject
  10229. {
  10230. { "UserId", "77886" },
  10231. { "Pwd", "lt666888" },
  10232. { "Filename", chanp }
  10233. };
  10234. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10235. JObject jsonObjects = JObject.Parse(response);
  10236. string msg = (string)jsonObjects["msg"];
  10237. if (msg == "报价成功")
  10238. {
  10239. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10240. string data = (string)jsonObject1["price"];
  10241. 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 + "');";
  10242. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10243. returnSuccessMsg("获取报价成功:" + data);
  10244. price = Convert.ToDouble(data);
  10245. }
  10246. else
  10247. {
  10248. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10249. return;
  10250. }
  10251. if (price > 0)
  10252. {
  10253. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10254. if (ceErpTradeCellExtend == null)
  10255. {
  10256. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10257. ceErpTradeCellExtend.ctid = entity.ctid;
  10258. ceErpTradeCellExtend.payment_cyt = price;
  10259. ceErpTradeCellExtend.Create();
  10260. }
  10261. else
  10262. {
  10263. ceErpTradeCellExtend.payment_cyt = price;
  10264. ceErpTradeCellExtend.Update();
  10265. }
  10266. }
  10267. return;
  10268. }
  10269. }
  10270. else
  10271. {
  10272. returnErrorMsg("请至少选择一条数据");
  10273. return;
  10274. }
  10275. }
  10276. //新增
  10277. public void order_To_Supplier()
  10278. {
  10279. string ceid = GetPostString("tid");
  10280. String[] tid = ceid.Split(',');
  10281. if (tid.Length > 0)
  10282. {
  10283. try
  10284. {
  10285. for (int i = 0; i < tid.Length; i++)
  10286. {
  10287. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10288. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10289. entity.SupplierId = suid;
  10290. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10291. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10292. entity.Update();
  10293. }
  10294. }
  10295. catch (Exception ex)
  10296. {
  10297. returnErrorMsg("自动匹配供应商失败");
  10298. return;
  10299. }
  10300. }
  10301. else
  10302. {
  10303. returnErrorMsg("请至少选择一条数据");
  10304. return;
  10305. }
  10306. returnSuccessMsg("自动匹配供应商成功");
  10307. return;
  10308. }
  10309. public (string, string) UploadFiles(string[] urls)
  10310. {
  10311. string success = "";
  10312. string errors = "";
  10313. int userid = CurrentUser.UserID;
  10314. foreach (string url in urls)
  10315. {
  10316. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10317. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10318. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10319. {
  10320. JObject jsonObject = new JObject
  10321. {
  10322. { "Userid", "77886" },
  10323. { "pwd", "cyt86435015" },
  10324. { "content", base64FileContent },
  10325. { "ext", Path.GetExtension(fileName) }
  10326. };
  10327. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10328. JObject jsonObjects = JObject.Parse(response);
  10329. string msg = (string)jsonObjects["msg"];
  10330. if (msg.Equals("上传成功"))
  10331. {
  10332. success += url + " 上传成功";
  10333. }
  10334. else
  10335. {
  10336. errors += url + " 上传失败";
  10337. }
  10338. }
  10339. else
  10340. {
  10341. errors += url + " 格式出现问题";
  10342. }
  10343. }
  10344. if (urls.Length == 0)
  10345. {
  10346. return (success, errors);
  10347. }
  10348. return (success, errors);
  10349. }
  10350. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10351. {
  10352. return true; //总是接受
  10353. }
  10354. public static string HttpPost(string url, string param = null)
  10355. {
  10356. HttpWebRequest request;
  10357. //如果是发送HTTPS请求
  10358. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10359. {
  10360. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10361. request = WebRequest.Create(url) as HttpWebRequest;
  10362. request.ProtocolVersion = HttpVersion.Version10;
  10363. }
  10364. else
  10365. {
  10366. request = WebRequest.Create(url) as HttpWebRequest;
  10367. }
  10368. request.Method = "POST";
  10369. request.ContentType = "application/json";
  10370. request.Accept = "*/*";
  10371. request.Timeout = 120000;
  10372. request.AllowAutoRedirect = false;
  10373. StreamWriter requestStream = null;
  10374. WebResponse response = null;
  10375. string responseStr = null;
  10376. try
  10377. {
  10378. requestStream = new StreamWriter(request.GetRequestStream());
  10379. requestStream.Write(param);
  10380. requestStream.Close();
  10381. response = request.GetResponse();
  10382. if (response != null)
  10383. {
  10384. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10385. responseStr = reader.ReadToEnd();
  10386. reader.Close();
  10387. }
  10388. }
  10389. catch (Exception ex)
  10390. {
  10391. return ex.Message;
  10392. }
  10393. finally
  10394. {
  10395. request = null;
  10396. requestStream = null;
  10397. response = null;
  10398. }
  10399. return responseStr;
  10400. }
  10401. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10402. {
  10403. string base64FileContent;
  10404. string fileName;
  10405. using (WebClient webClient = new WebClient())
  10406. {
  10407. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10408. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10409. {
  10410. using (Stream stream = response.GetResponseStream())
  10411. {
  10412. using (MemoryStream memoryStream = new MemoryStream())
  10413. {
  10414. stream.CopyTo(memoryStream);
  10415. byte[] fileBytes = memoryStream.ToArray();
  10416. base64FileContent = Convert.ToBase64String(fileBytes);
  10417. fileName = response.Headers["Content-Disposition"];
  10418. if (!string.IsNullOrEmpty(fileName))
  10419. {
  10420. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10421. if (index >= 0)
  10422. {
  10423. fileName = fileName.Substring(index + 9).Trim('\"');
  10424. }
  10425. }
  10426. else
  10427. {
  10428. fileName = Path.GetFileName(downloadUrl);
  10429. }
  10430. }
  10431. }
  10432. }
  10433. }
  10434. return (fileName, base64FileContent);
  10435. }
  10436. //新增
  10437. public void order_batch_caiyingtong(string[] downloadUrls)
  10438. {
  10439. try
  10440. {
  10441. //遍历文件
  10442. DataStruct dStruct = GetPostStruct();
  10443. DataTable dt = null;
  10444. int userid = CurrentUser.UserID;
  10445. List<string> ids = new List<string>();//失败组
  10446. List<string> tids = new List<string>();
  10447. using (WebClient webClient = new WebClient())
  10448. {
  10449. foreach (var url in downloadUrls)
  10450. {
  10451. try
  10452. {
  10453. tids.Add("'" + url + "'");
  10454. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10455. if (entity != null)
  10456. {
  10457. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10458. if (cp == null)
  10459. {
  10460. JObject jsonObject = new JObject
  10461. {
  10462. { "Userid", "77886" },
  10463. { "pwd", "lt666888" },
  10464. { "Filename",entity.seller_memo }
  10465. };
  10466. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10467. JObject jsonObjects = JObject.Parse(response);
  10468. string msg = (string)jsonObjects["msg"];
  10469. if (msg == "报价成功")
  10470. {
  10471. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10472. DownloadAndConvertToBase64(url1);
  10473. }
  10474. else
  10475. {
  10476. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10477. }
  10478. }
  10479. else
  10480. {
  10481. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10482. JObject jsonObject = new JObject
  10483. {
  10484. { "Userid", "77886" },
  10485. { "pwd", "lt666888" },
  10486. { "Filename",chanp }
  10487. };
  10488. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10489. JObject jsonObjects = JObject.Parse(response);
  10490. string msg = (string)jsonObjects["msg"];
  10491. if (msg == "报价成功")
  10492. {
  10493. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10494. DownloadAndConvertToBase64(url1);
  10495. }
  10496. else
  10497. {
  10498. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10499. }
  10500. }
  10501. }
  10502. // 上传文件到FTP
  10503. }
  10504. catch (Exception ex)
  10505. {
  10506. Console.WriteLine($"An error occurred: {ex.Message}");
  10507. }
  10508. }
  10509. List<string> lw = new List<string>();
  10510. lw.Add(string.Format("( OrderState < 6 )"));
  10511. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10512. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10513. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10514. if (dt.Rows.Count > 0)
  10515. {
  10516. foreach (DataRow dr in dt.Rows)
  10517. {
  10518. ids.Add(dr["ctid"].ToString());
  10519. }
  10520. }
  10521. String ErrorMsgs = "";
  10522. foreach (String id in ids)
  10523. {
  10524. ErrorMsgs += id + ",";
  10525. }
  10526. if (ErrorMsgs.Length > 1)
  10527. {
  10528. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10529. }
  10530. if (ErrorMsgs.Length < 1)
  10531. {
  10532. ErrorMsgs = "上传成功";
  10533. returnSuccessMsg(ErrorMsgs);
  10534. }
  10535. else
  10536. {
  10537. returnErrorMsg("以下订单" + ErrorMsgs);
  10538. }
  10539. }
  10540. // 删除文件夹及其内容
  10541. /* Directory.Delete(localDirectory, true);*/
  10542. }
  10543. catch { }
  10544. }
  10545. public void get_center_data()
  10546. {
  10547. int userId = CurrentUser.UserID;
  10548. string postCode = CurrentUser.UserPost.Post.Code;
  10549. List<string> lw = new List<string>();
  10550. List<string> ww = new List<string>();
  10551. DateTime currentTime = DateTime.Now;
  10552. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10553. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10554. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10555. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10556. string sql = " SELECT ";
  10557. string startTime = "2023-10-01 11:22:31";
  10558. //设计
  10559. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10560. {
  10561. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10562. 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));
  10563. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10564. 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));
  10565. }
  10566. //客服
  10567. else if (postCode == "CustomerService" || postCode == "Director")
  10568. {
  10569. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10570. 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));
  10571. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10572. 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));
  10573. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10574. 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));
  10575. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10576. 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));
  10577. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10578. 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));
  10579. }
  10580. //售后
  10581. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10582. {
  10583. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10584. 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));
  10585. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10586. 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));
  10587. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10588. 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));
  10589. }
  10590. //下单部
  10591. else if (postCode == "Place" || postCode == "PlaceMr")
  10592. {
  10593. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10594. 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));
  10595. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10596. 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));
  10597. }
  10598. //车间
  10599. else if (postCode == "Supplier")
  10600. {
  10601. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10602. 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));
  10603. }
  10604. DataTable dt = new DataTable();
  10605. if (lw.Count > 0)
  10606. {
  10607. sql += string.Join(" , ", lw);
  10608. sql += " FROM ";
  10609. sql += string.Join(" , ", ww);
  10610. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10611. }
  10612. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10613. }
  10614. public void get_center_data_list()
  10615. {
  10616. int userId = CurrentUser.UserID;
  10617. string postCode = CurrentUser.UserPost.Post.Code;
  10618. string shopIds = CurrentUser.User.pemShop;
  10619. DataStruct dStruct = GetPostStruct();
  10620. List<string> lw = new List<string>();
  10621. DateTime currentTime = DateTime.Now;
  10622. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10623. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10624. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10625. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10626. string startTime = "2023-10-01 11:22:31";
  10627. int order_type = GetPostInt("order_type");
  10628. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10629. {
  10630. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10631. if (order_type == 0)
  10632. {
  10633. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10634. }
  10635. else if (order_type == 3)
  10636. {
  10637. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10638. }
  10639. else
  10640. {
  10641. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10642. }
  10643. }
  10644. //客服
  10645. if (postCode == "CustomerService" || postCode == "Director")
  10646. {
  10647. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10648. if (order_type == 0)
  10649. {
  10650. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10651. }
  10652. else if (order_type == 1)
  10653. {
  10654. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10655. }
  10656. else if (order_type == 2)
  10657. {
  10658. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10659. }
  10660. else if (order_type == 3)
  10661. {
  10662. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10663. }
  10664. else if (order_type == 4)
  10665. {
  10666. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10667. }
  10668. else
  10669. {
  10670. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10671. }
  10672. }
  10673. //售后
  10674. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10675. {
  10676. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10677. if (shopIds != "")
  10678. {
  10679. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10680. }
  10681. if (order_type == 2)
  10682. {
  10683. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10684. }
  10685. else if (order_type == 4)
  10686. {
  10687. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10688. }
  10689. else if (order_type == 5)
  10690. {
  10691. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10692. }
  10693. else
  10694. {
  10695. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10696. }
  10697. }
  10698. //下单部
  10699. if (postCode == "Place" || postCode == "PlaceMr")
  10700. {
  10701. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10702. if (shopIds != "")
  10703. {
  10704. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10705. }
  10706. else if (order_type == 1)
  10707. {
  10708. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10709. }
  10710. else if (order_type == 2)
  10711. {
  10712. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10713. }
  10714. else
  10715. {
  10716. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10717. }
  10718. }
  10719. //车间
  10720. if (postCode == "Supplier")
  10721. {
  10722. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10723. if (order_type == 5)
  10724. {
  10725. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10726. }
  10727. else
  10728. {
  10729. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10730. }
  10731. }
  10732. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10733. dStruct.Fileds = "tid,ctid";
  10734. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10735. writeGridDataTableJson(dStruct.TotalCount, dt);
  10736. }
  10737. public void aftersale_audit_master()
  10738. {
  10739. if (UrlPostParmsCheck("ctid"))
  10740. {
  10741. string ctid = GetPostString("ctid");
  10742. if (ctid.Length > 0)
  10743. {
  10744. bool result = aftersale_data_change(ctid);
  10745. if (result)
  10746. {
  10747. returnSuccessMsg("修改成功!");
  10748. return;
  10749. }
  10750. }
  10751. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10752. }
  10753. }
  10754. public void aftersale_batch_audit_master()
  10755. {
  10756. if (UrlPostParmsCheck("ctids"))
  10757. {
  10758. string ctids = GetPostString("ctids");
  10759. if (ctids.Length > 0)
  10760. {
  10761. List<string> list = new List<string>();
  10762. string[] ctid_list = ctids.Split(',');
  10763. foreach (var item in ctid_list)
  10764. {
  10765. bool result = aftersale_data_change(item);
  10766. if (!result)
  10767. {
  10768. list.Add(item);
  10769. }
  10770. }
  10771. if (list.Count > 0)
  10772. {
  10773. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10774. return;
  10775. }
  10776. returnSuccessMsg("修改成功!");
  10777. return;
  10778. }
  10779. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10780. }
  10781. }
  10782. public bool aftersale_data_change(string ctid)
  10783. {
  10784. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10785. if (ceErpTradeCell != null)
  10786. {
  10787. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10788. ceErpTradeCell.AfterSaleSupplierState = 0;
  10789. StringBuilder sql = new StringBuilder();
  10790. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10791. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10792. CeErpTradeResponsible.DelByTid(ctid, 0);
  10793. 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 == "不理赔")
  10794. {
  10795. CeErpTradeResponsible.DelByTid(ctid, 1);
  10796. ceErpTradeCell.AfterSaleSupplierState = 1;
  10797. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10798. ceErpTradeCell.AfterSaleState = 4;
  10799. }
  10800. else
  10801. {
  10802. ceErpTradeCell.AfterSaleState = 3;
  10803. }
  10804. bool needCyt = false;
  10805. if (dt != null)
  10806. {
  10807. if (dt.Rows.Count == 1)
  10808. {
  10809. bool isEnd = false;
  10810. foreach (DataRow dr in dt.Rows)
  10811. {
  10812. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10813. {
  10814. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10815. isEnd = true;
  10816. }
  10817. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10818. {
  10819. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10820. isEnd = true;
  10821. }
  10822. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10823. {
  10824. needCyt = true;
  10825. }
  10826. }
  10827. if (isEnd)
  10828. {
  10829. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10830. ceErpTradeCell.AfterSaleState = 4;
  10831. ceErpTradeCell.AfterSaleSupplierState = 1;
  10832. }
  10833. }
  10834. else
  10835. {
  10836. bool isAll = true;
  10837. foreach (DataRow dr in dt.Rows)
  10838. {
  10839. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10840. {
  10841. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10842. continue;
  10843. }
  10844. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10845. {
  10846. string path = "";
  10847. int OrgID = 0;
  10848. if (!Convert.IsDBNull(dr["OrgPath"]))
  10849. {
  10850. path = dr["OrgPath"].ToString();
  10851. }
  10852. if (!Convert.IsDBNull(dr["OrgID"]))
  10853. {
  10854. OrgID = Convert.ToInt32(dr["OrgID"]);
  10855. }
  10856. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10857. {
  10858. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10859. continue;
  10860. }
  10861. }
  10862. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && (Convert.ToInt32(dr["UserId"]) == 64 || Convert.ToInt32(dr["UserId"]) == 80))
  10863. {
  10864. needCyt = true;
  10865. }
  10866. isAll = false;
  10867. }
  10868. if (isAll)
  10869. {
  10870. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10871. ceErpTradeCell.AfterSaleState = 4;
  10872. ceErpTradeCell.AfterSaleSupplierState = 1;
  10873. }
  10874. }
  10875. }
  10876. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10877. {
  10878. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10879. }
  10880. if (ceErpTradeCell.AfterSaleState == 4)
  10881. {
  10882. ApiVo apiVo = new ApiVo();
  10883. apiVo.orderNumber = ceErpTradeCell.ctid;
  10884. apiVo.actionName = "afterOver";
  10885. designHelper.API_WorkCore(apiVo); //afterOver
  10886. }
  10887. ceErpTradeCell.Update();
  10888. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10889. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10890. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10891. return true;
  10892. }
  10893. return false;
  10894. }
  10895. public void get_erp_wechatorder()
  10896. {
  10897. DataStruct dStruct = GetPostStruct();
  10898. List<string> lw = new List<string>();
  10899. string tid = GetPostString("tid");
  10900. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10901. string shopname = GetPostString("shopname");
  10902. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10903. string buyernick = GetPostString("buyer_nick");
  10904. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10905. string customer = GetPostString("customer");
  10906. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10907. string returndate1 = GetPostString("returndate1");
  10908. string returndate2 = GetPostString("returndate2");
  10909. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10910. if (dw.Length > 0) lw.Add(dw);
  10911. string finishDate1 = GetPostString("finishdate1");
  10912. string finishDate2 = GetPostString("finishdate2");
  10913. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10914. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10915. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10916. dStruct.Order = "created desc";
  10917. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10918. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10919. writeGridDataTableJson(dStruct.TotalCount, dt);
  10920. }
  10921. public void get_erp_wechatlist_sumprice()
  10922. {
  10923. DataStruct dStruct = GetPostStruct();
  10924. List<string> lw = new List<string>();
  10925. string tid = GetPostString("tid");
  10926. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10927. string shopname = GetPostString("shopname");
  10928. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10929. string buyernick = GetPostString("buyer_nick");
  10930. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10931. string customer = GetPostString("customer");
  10932. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10933. string returndate1 = GetPostString("returndate1");
  10934. string returndate2 = GetPostString("returndate2");
  10935. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10936. if (dw.Length > 0) lw.Add(dw);
  10937. string finishDate1 = GetPostString("finishdate1");
  10938. string finishDate2 = GetPostString("finishdate2");
  10939. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10940. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10941. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10942. string mainWhere = string.Join(" and ", lw.ToArray());
  10943. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10944. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10945. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10946. decimal total = 0;
  10947. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10948. {
  10949. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10950. }
  10951. var res = new
  10952. {
  10953. data = total
  10954. };
  10955. string ro_jsond = JsonConvert.SerializeObject(res);
  10956. returnSuccess(ro_jsond);
  10957. return;
  10958. }
  10959. public void get_erp_qr_waitdeliverylist()
  10960. {
  10961. DataStruct dStruct = GetPostStruct();
  10962. List<string> lw = new List<string>();
  10963. string tid = GetPostString("ctid");
  10964. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10965. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10966. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10967. var res_objz = new
  10968. {
  10969. restype = 1,
  10970. data = dt
  10971. };
  10972. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10973. returnSuccess(ro_jsonz);
  10974. }
  10975. public void get_erp_yield_list()
  10976. {
  10977. DataStruct dStruct = GetPostStruct();
  10978. List<string> lw = new List<string>();
  10979. string tid = GetPostString("ctid");
  10980. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10981. string shopname = GetPostString("shopname");
  10982. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10983. string buyernick = GetPostString("buyer_nick");
  10984. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10985. //if (tid.Length == 0 && buyernick.Length == 0)
  10986. //{
  10987. // lw.Add(string.Format("IsRefund<={0}", 1));
  10988. //}
  10989. string customer = GetPostString("customer");
  10990. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10991. string design = GetPostString("design");
  10992. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10993. string orderState = GetPostString("orderState");
  10994. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10995. string address = GetPostString("address");
  10996. 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));
  10997. string sellermemo = GetPostString("seller_memo");
  10998. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10999. string supplier = GetPostString("supplier");
  11000. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11001. string OrderArea = GetPostString("order_area");
  11002. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  11003. string placedate1 = GetPostString("placedate1");
  11004. string placedate2 = GetPostString("placedate2");
  11005. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  11006. if (fdw.Length > 0) lw.Add(fdw);
  11007. string price1 = GetPostString("price1");
  11008. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  11009. string price2 = GetPostString("price2");
  11010. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  11011. string unusualCon = GetPostString("unusualcon");
  11012. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  11013. string posTag = CurrentUser.UserPost.Post.Code;
  11014. if (posTag == "Supplier")
  11015. {
  11016. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  11017. }
  11018. lw.Add(string.Format("OrderState = 6 "));
  11019. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  11020. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  11021. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11022. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  11023. writeGridDataTableJson(dStruct.TotalCount, dt);
  11024. }
  11025. public void change_erp_sup_state()
  11026. {
  11027. if (UrlPostParmsCheck("ctid"))
  11028. {
  11029. string ctid = GetPostString("ctid");
  11030. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11031. if (ceErpTradeCell != null)
  11032. {
  11033. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11034. if (ceErpTradeCellExtend == null)
  11035. {
  11036. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11037. ceErpTradeCellExtend.ctid = ctid;
  11038. ceErpTradeCellExtend.SupState = 1;
  11039. ceErpTradeCellExtend.Create();
  11040. }
  11041. else
  11042. {
  11043. ceErpTradeCellExtend.SupState = 1;
  11044. ceErpTradeCellExtend.Update();
  11045. }
  11046. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  11047. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  11048. return;
  11049. }
  11050. returnErrorMsg("找不到订单");
  11051. }
  11052. }
  11053. public void supplier_all_downs()
  11054. {
  11055. if (UrlPostParmsCheck("tids"))
  11056. {
  11057. string tids = GetPostString("tids");
  11058. if (tids != null && tids.Length > 0)
  11059. {
  11060. StringBuilder sql = new StringBuilder();
  11061. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  11062. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11063. sql = new StringBuilder();
  11064. 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, "下载设计文件");
  11065. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11066. string[] list = tids.Split(',');
  11067. foreach (string ctid in list)
  11068. {
  11069. CeErpSukuraData.createInfo(ctid, 3);
  11070. }
  11071. designHelper.api_approveDesign(tids); //approveDesign
  11072. returnSuccessMsg("下载成功!");
  11073. return;
  11074. }
  11075. returnErrorMsg("下载订单更新失败");
  11076. }
  11077. }
  11078. public void uploaderFileSuccess()
  11079. {
  11080. if (UrlPostParmsCheck("fileName"))
  11081. {
  11082. string fileName = GetPostString("fileName");
  11083. ApiVo apiVo = new ApiVo();
  11084. apiVo.orderNumber = fileName;
  11085. apiVo.actionName = "finishDesign";
  11086. designHelper.API_WorkCore(apiVo);//finishDesign
  11087. returnSuccessMsg("");
  11088. }
  11089. }
  11090. public void get_sample2_order()
  11091. {
  11092. if (UrlPostParmsCheck("ctid"))
  11093. {
  11094. string ctid = GetPostString("ctid");
  11095. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11096. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11097. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  11098. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  11099. double total = 0.0;
  11100. double order_price = 0.0;
  11101. if (dt_bu.Rows.Count > 0)
  11102. {
  11103. foreach (DataRow dr in dt_bu.Rows)
  11104. {
  11105. total += Convert.ToDouble(dr["payment"]);
  11106. }
  11107. }
  11108. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11109. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11110. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11111. string tid = ctid.Replace("S_", "");
  11112. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11113. double paymant = 0.0;
  11114. if (entity != null)
  11115. {
  11116. paymant = entity.payment;
  11117. }
  11118. string return_reason = "";
  11119. if (dt_after != null && dt_after.Rows.Count > 0)
  11120. {
  11121. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11122. }
  11123. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11124. }
  11125. }
  11126. public void get_erp_design_status()
  11127. {
  11128. string designName = GetPostString("designName");
  11129. DataStruct dStruct = GetPostStruct();
  11130. if (designName.Length > 0)
  11131. {
  11132. 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";
  11133. sql_user += " and Name like '%" + designName + "%'";
  11134. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11135. List<string> ids_list = new List<string>();
  11136. if (user_table.Rows.Count > 0)
  11137. {
  11138. foreach (DataRow item in user_table.Rows)
  11139. {
  11140. ids_list.Add(item["id"].ToString());
  11141. string ids_s = item["TeamIds"].ToString();
  11142. if (ids_s.Length > 0)
  11143. {
  11144. ids_list.AddRange(ids_s.Split(','));
  11145. }
  11146. }
  11147. }
  11148. HashSet<string> set = new HashSet<string>(ids_list);
  11149. ids_list = set.ToList();
  11150. if (ids_list.Count > 0)
  11151. {
  11152. 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));
  11153. dStruct.MainWhere = sql;
  11154. DataTable dt = null;
  11155. dt = WebCache.GetData("view_ErpUser", dStruct);
  11156. writeGridDataTableJson(dStruct.TotalCount, dt);
  11157. }
  11158. }
  11159. }
  11160. public void change_erp_order_price()
  11161. {
  11162. string ctid = GetPostString("ctid");
  11163. double price = GetPostDouble("price");
  11164. if (ctid.Length > 0)
  11165. {
  11166. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11167. if (ceErpTradeCellExtend == null)
  11168. {
  11169. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11170. ceErpTradeCellExtend.ctid = ctid;
  11171. ceErpTradeCellExtend.payment_cyt = price;
  11172. ceErpTradeCellExtend.Create();
  11173. }
  11174. else
  11175. {
  11176. ceErpTradeCellExtend.payment_cyt = price;
  11177. ceErpTradeCellExtend.Update();
  11178. }
  11179. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11180. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11181. {
  11182. ceErpDataSendOrderInfo.isSync = false;
  11183. ceErpDataSendOrderInfo.Update();
  11184. }
  11185. if (ceErpDataSendOrderInfo == null)
  11186. {
  11187. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11188. ceErpDataSendOrderInfo.isSync = false;
  11189. ceErpDataSendOrderInfo.ctid = ctid;
  11190. ceErpDataSendOrderInfo.Create();
  11191. }
  11192. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11193. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11194. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11195. if (dth != null && dth.Rows.Count > 0)
  11196. {
  11197. dataSendOrderBean dataSendOrderBean = null;
  11198. foreach (DataRow item in dth.Rows)
  11199. {
  11200. try
  11201. {
  11202. dataSendOrderBean = new dataSendOrderBean();
  11203. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11204. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11205. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11206. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11207. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11208. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11209. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11210. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11211. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11212. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11213. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11214. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11215. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11216. if (result != null)
  11217. {
  11218. if ("0".Equals(result.errcode))
  11219. {
  11220. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11221. }
  11222. else
  11223. {
  11224. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11225. }
  11226. }
  11227. }
  11228. catch (Exception ex)
  11229. {
  11230. }
  11231. }
  11232. }
  11233. returnSuccessMsg("修改成功!");
  11234. return;
  11235. }
  11236. returnErrorMsg("找不到订单");
  11237. }
  11238. public void find_he_together()
  11239. {
  11240. string ctid = GetPostString("ctid");
  11241. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11242. List<string> list = new List<string>();
  11243. if (ceErpTradeCell != null)
  11244. {
  11245. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11246. {
  11247. 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);
  11248. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11249. if (table != null && table.Rows.Count > 0)
  11250. {
  11251. foreach (TableRow row in table.Rows)
  11252. {
  11253. }
  11254. }
  11255. }
  11256. }
  11257. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11258. }
  11259. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11260. {
  11261. //chy----19
  11262. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11263. //GD-CYT-----64
  11264. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11265. //ZHX----3
  11266. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11267. //JK----97
  11268. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11269. //ZT----70
  11270. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11271. //LHCY-----98
  11272. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11273. //XD-----90
  11274. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11275. //CYCY-----14
  11276. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11277. };
  11278. //其他改名
  11279. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11280. {
  11281. {15,"滴塑" }, {119,"数码" }, {121,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11282. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11283. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11284. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11285. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11286. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11287. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11288. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11289. };
  11290. //不统计
  11291. List<int> no_suppliers = new List<int>()
  11292. {
  11293. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11294. };
  11295. //配件单
  11296. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11297. {
  11298. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11299. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11300. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11301. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11302. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11303. {"旗杆",new List<string>(){ "班旗" } },
  11304. {"牙签",new List<string>(){ "不干胶" } }
  11305. };
  11306. public void get_place_order_data()
  11307. {
  11308. string date1 = GetPostString("date1");
  11309. string date2 = GetPostString("date2");
  11310. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11311. DateTime start = DateTime.Parse(starttime);
  11312. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11313. DateTime end = DateTime.Parse(endtime);
  11314. if (date1 != null && date1.Length > 0)
  11315. {
  11316. DateTime dateTime = DateTime.Parse(date1);
  11317. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11318. start = DateTime.Parse(starttime);
  11319. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11320. end = DateTime.Parse(endtime);
  11321. }
  11322. if (date2 != null && date2.Length > 0)
  11323. {
  11324. DateTime dateTime = DateTime.Parse(date2);
  11325. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11326. end = DateTime.Parse(endtime);
  11327. }
  11328. string sql = string.Format("select SupplierId,ProductId,seller_memo,ProductCount,ProductName,payment,SupplierName,UnusualTime,FinishPlaceTime,OrderState,FinishDeliveryTime from view_ErpTradeCell where ( ( FinishPlaceTime BETWEEN '{0}' AND '{1}' ) OR ( OrderState = 6 AND UnusualTag = 5 AND IsRefund <= 1 ) ) AND IsSample = 0 and SupplierName is not null ", starttime, endtime);
  11329. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11330. //不干胶-----1,卡片-----29
  11331. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11332. foreach (DataRow row in data.Rows)
  11333. {
  11334. int productId = Convert.ToInt32(row["ProductId"]);
  11335. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11336. if (no_suppliers.Contains(supplierId))
  11337. {
  11338. continue;
  11339. }
  11340. string seller_memo = row["seller_memo"].ToString();
  11341. bool ispj = false;//是否配件单
  11342. bool isfirst = true;//第一个配
  11343. maps.Keys.ForEach(key =>
  11344. {
  11345. //备注包含配件
  11346. if (seller_memo.Contains(key) && isfirst)
  11347. {
  11348. List<string> list = maps[key];
  11349. ispj = true;
  11350. isfirst = false;
  11351. for (int i = 0; i < list.Count; i++)
  11352. {
  11353. if (seller_memo.Contains(list[i]))
  11354. {
  11355. ispj = false;
  11356. break;
  11357. }
  11358. }
  11359. }
  11360. });
  11361. if (ispj)
  11362. {
  11363. continue;
  11364. }
  11365. seller_memo = seller_memo.Replace("UV", "uv");
  11366. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11367. //吊牌归到卡片
  11368. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11369. seller_memo = seller_memo.Replace("卡套", "卡片");
  11370. seller_memo = seller_memo.Replace("封套", "卡片");
  11371. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11372. seller_memo = seller_memo.Replace("腰封", "卡片");
  11373. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11374. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11375. seller_memo = seller_memo.Replace("横幅", "条幅");
  11376. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11377. string map_key = "";
  11378. string type = "";
  11379. if (supplierMap.ContainsKey(supplierId))
  11380. {
  11381. foreach (var kvp in supplierMap[supplierId])
  11382. {
  11383. if (seller_memo.Contains(kvp.Key))
  11384. {
  11385. map_key = kvp.Value;
  11386. type = kvp.Value;
  11387. break;
  11388. }
  11389. }
  11390. }
  11391. if (map_key == "")
  11392. {
  11393. type = "其他";
  11394. map_key = "其他";
  11395. }
  11396. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11397. {
  11398. map_key = suppliers[supplierId];
  11399. }
  11400. if (supplierId == 70)
  11401. {
  11402. supplierId = 70;
  11403. }
  11404. map_key += "_" + row["SupplierName"].ToString();
  11405. Dictionary<string, int> map = null;
  11406. if (other_map.ContainsKey(map_key))
  11407. {
  11408. other_map.TryGetValue(map_key, out map);
  11409. }
  11410. else
  11411. {
  11412. map = new Dictionary<string, int>();
  11413. map.Add("dayDev", 0);//当天出货
  11414. map.Add("dayTotal", 0);//下单总数
  11415. map.Add("payTotal", 0);//500以上
  11416. map.Add("today", 0);//当天出货数量
  11417. map.Add("unusua", 0);//异常数
  11418. other_map.Add(map_key, map);
  11419. other_map.TryGetValue(map_key, out map);
  11420. }
  11421. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11422. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11423. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11424. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11425. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11426. {
  11427. map["dayTotal"]++;
  11428. if (supplierId == 97)
  11429. {
  11430. supplierId = 97;
  11431. }
  11432. }
  11433. if (Convert.ToDecimal(row["payment"]) >= 500)
  11434. {
  11435. map["payTotal"]++;
  11436. }
  11437. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11438. {
  11439. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11440. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11441. {
  11442. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11443. {
  11444. map["today"]++;
  11445. }
  11446. }
  11447. else
  11448. {
  11449. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11450. {
  11451. map["today"]++;
  11452. }
  11453. else
  11454. {
  11455. if (supplierId == 119)
  11456. {
  11457. Debug.WriteLine(row["seller_memo"].ToString());
  11458. }
  11459. }
  11460. }
  11461. }
  11462. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11463. {
  11464. map["unusua"]++;
  11465. }
  11466. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11467. //GD-CYT-----64
  11468. DateTime two = palceTimeStart.AddHours(14);
  11469. DateTime three = palceTimeStart.AddHours(15);
  11470. DateTime four = palceTimeStart.AddHours(16);
  11471. DateTime six = palceTimeStart.AddHours(18);
  11472. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11473. {
  11474. //下午四点前 500-1000
  11475. string count = row["ProductCount"].ToString();
  11476. if (count != null && count.Length > 0)
  11477. {
  11478. int productCount = commonHelper.getPlaceProductCount(count);
  11479. if (productCount >= 500 && productCount <= 1000)
  11480. {
  11481. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11482. {
  11483. map["dayDev"]++;
  11484. }
  11485. }
  11486. }
  11487. }
  11488. //UV
  11489. else if ("uv".Equals(type))
  11490. {
  11491. //ZT----70
  11492. //ZHX----3
  11493. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11494. {
  11495. map["dayDev"]++;
  11496. }
  11497. //JK----97
  11498. //HZX----105
  11499. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11500. {
  11501. map["dayDev"]++;
  11502. }
  11503. }
  11504. //帆布---52|条幅---27
  11505. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11506. {
  11507. //LHCY-----98
  11508. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11509. {
  11510. map["dayDev"]++;
  11511. }
  11512. }
  11513. //条幅
  11514. else if ("条幅".Equals(type))
  11515. {
  11516. //XD-----90
  11517. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11518. {
  11519. map["dayDev"]++;
  11520. }
  11521. }
  11522. //桌布
  11523. else if ("桌布".Equals(type))
  11524. {
  11525. //XD-----90
  11526. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11527. {
  11528. map["dayDev"]++;
  11529. }
  11530. }
  11531. //DL---10
  11532. //AYTW---119
  11533. //FS-CYT-DY ----80
  11534. //JK----97
  11535. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11536. {
  11537. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11538. {
  11539. map["dayDev"]++;
  11540. }
  11541. }
  11542. // QC---121
  11543. else if (supplierId == 121)
  11544. {
  11545. if (DateTime.Compare(FinishPlaceTime, six) < 0)
  11546. {
  11547. map["dayDev"]++;
  11548. }
  11549. }
  11550. }
  11551. DataTable dt = new DataTable();
  11552. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11553. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11554. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11555. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11556. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11557. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11558. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11559. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11560. other_map.Keys.ForEach(key =>
  11561. {
  11562. DataRow dr = dt.NewRow();
  11563. Dictionary<string, int> map = other_map[key];
  11564. string[] key_list = key.Split('_');
  11565. dr[0] = key_list[0];
  11566. dr[1] = key_list[1];
  11567. if (key_list.Length > 2)
  11568. {
  11569. dr[1] += "(" + key_list[2] + ")";
  11570. }
  11571. dr[2] = map["dayTotal"];
  11572. dr[3] = map["payTotal"];
  11573. dr[4] = map["today"];
  11574. dr[5] = map["unusua"];
  11575. dr[6] = map["dayDev"];
  11576. double rate = 0.00;
  11577. if (map["dayDev"] > 0)
  11578. {
  11579. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11580. }
  11581. dr[7] = rate.ToString();
  11582. dt.Rows.Add(dr);
  11583. });
  11584. DataView dv = new DataView(dt);
  11585. dv.Sort = "SupplierName";
  11586. //dv.Sort = "AllOrder desc";
  11587. DataTable dtNew = dv.ToTable();
  11588. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11589. }
  11590. public void check_order_desing_info()
  11591. {
  11592. string ctid = GetPostString("ctid");
  11593. if (!string.IsNullOrEmpty(ctid))
  11594. {
  11595. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11596. if (ceErpTradeCell != null)
  11597. {
  11598. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11599. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11600. return;
  11601. }
  11602. returnErrorMsg("找不到订单");
  11603. return;
  11604. }
  11605. returnErrorMsg("找不到订单");
  11606. }
  11607. public void get_timeout_detail()
  11608. {
  11609. string poscode = CurrentUser.UserPost.Post.Code;
  11610. DataStruct dStruct = GetPostStruct();
  11611. List<string> lw = new List<string>();
  11612. string id = GetPostString("id");
  11613. string pay_date1 = GetPostString("pay_date1");
  11614. string pay_date2 = GetPostString("pay_date2");
  11615. int type = GetPostInt("type");
  11616. if (type == 0)
  11617. {
  11618. if (pay_date1.Length > 0)
  11619. {
  11620. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11621. }
  11622. if (pay_date2.Length > 0)
  11623. {
  11624. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11625. }
  11626. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11627. }
  11628. if (type == 1)
  11629. {
  11630. if (pay_date1.Length > 0)
  11631. {
  11632. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11633. }
  11634. if (pay_date2.Length > 0)
  11635. {
  11636. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11637. }
  11638. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11639. }
  11640. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11641. DataTable dt = null;
  11642. dt = WebCache.GetData("view_orderlist", dStruct);
  11643. writeGridDataTableJson(dStruct.TotalCount, dt);
  11644. }
  11645. public void saveUrgentChargePrice()
  11646. {
  11647. string ctid = GetPostString("ctid");
  11648. if (!string.IsNullOrEmpty(ctid))
  11649. {
  11650. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11651. if (ceErpTradeCell != null)
  11652. {
  11653. double prices = commonHelper.calculationPrice(ceErpTradeCell);
  11654. if (prices <= 100)
  11655. {
  11656. returnErrorMsg("此订单金额不足100元,无法加急。");
  11657. return;
  11658. }
  11659. double price = GetPostDouble("price");
  11660. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11661. if (ceErpTradeCellExtend == null)
  11662. {
  11663. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11664. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11665. }
  11666. ceErpTradeCellExtend.urgentCharge = price;
  11667. if (ceErpTradeCellExtend.ID > 0)
  11668. {
  11669. ceErpTradeCellExtend.Update();
  11670. }
  11671. else
  11672. {
  11673. ceErpTradeCellExtend.Save();
  11674. }
  11675. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "手动订单加急", 0, 1);
  11676. returnSuccessMsg("修改成功!");
  11677. return;
  11678. }
  11679. returnErrorMsg("找不到订单");
  11680. return;
  11681. }
  11682. returnErrorMsg("找不到订单");
  11683. }
  11684. public void finish_erp_order()
  11685. {
  11686. string ctid = GetPostString("ctid");
  11687. if (!string.IsNullOrEmpty(ctid))
  11688. {
  11689. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11690. {
  11691. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11692. if (ceErpTradeCell != null)
  11693. {
  11694. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11695. ceErpTradeCell.Update();
  11696. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11697. returnSuccessMsg("修改成功!");
  11698. return;
  11699. }
  11700. }
  11701. }
  11702. returnErrorMsg("找不到订单");
  11703. }
  11704. public void get_trade_order_list()
  11705. {
  11706. string tid = GetPostString("tid");
  11707. if (!string.IsNullOrEmpty(tid))
  11708. {
  11709. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11710. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11711. writeGridDataTableJson(data.Rows.Count, data);
  11712. return;
  11713. }
  11714. returnErrorMsg("找不到订单");
  11715. }
  11716. public void save_cell_spu()
  11717. {
  11718. string ctid = GetPostString("ctid");
  11719. string spu_id = GetPostString("spu_id");
  11720. if (!string.IsNullOrEmpty(ctid))
  11721. {
  11722. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11723. if (ceErpTradeCellExtend == null)
  11724. {
  11725. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11726. ceErpTradeCellExtend.ctid = ctid;
  11727. }
  11728. ceErpTradeCellExtend.spu_id = spu_id;
  11729. if (!string.IsNullOrEmpty(spu_id))
  11730. {
  11731. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11732. ceErpTradeCellExtend = commonHelper.sendSpuData(ceErpTradeCell, ceErpTradeCellExtend);
  11733. }
  11734. if (ceErpTradeCellExtend.ID == 0)
  11735. {
  11736. ceErpTradeCellExtend.Create();
  11737. }
  11738. else
  11739. {
  11740. ceErpTradeCellExtend.Update();
  11741. }
  11742. returnSuccessMsg("修改成功!");
  11743. return;
  11744. }
  11745. returnErrorMsg("找不到订单");
  11746. }
  11747. public void change_express_info()
  11748. {
  11749. string ctid = GetPostString("ctid");
  11750. string transNo = GetPostString("transNo");
  11751. string transCom = GetPostString("transCom");
  11752. if (!string.IsNullOrEmpty(ctid))
  11753. {
  11754. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11755. if (ceErpTradeCellExtend == null)
  11756. {
  11757. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11758. ceErpTradeCellExtend.ctid = ctid;
  11759. }
  11760. ceErpTradeCellExtend.modExpressNo = transNo;
  11761. ceErpTradeCellExtend.modExpressCom = transCom;
  11762. ceErpTradeCellExtend.readMod = 2;
  11763. if (ceErpTradeCellExtend.ID == 0)
  11764. {
  11765. ceErpTradeCellExtend.Create();
  11766. }
  11767. else
  11768. {
  11769. ceErpTradeCellExtend.Update();
  11770. }
  11771. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11772. returnSuccessMsg("修改成功!");
  11773. return;
  11774. }
  11775. returnErrorMsg("找不到订单");
  11776. }
  11777. public void get_change_express_list()
  11778. {
  11779. DataStruct dStruct = GetPostStruct();
  11780. List<string> lw = new List<string>();
  11781. int st = 2;
  11782. string tid = GetPostString("ctid");
  11783. if (tid.Length > 0)
  11784. {
  11785. string select_tid = getTidByCtid(tid);
  11786. lw.Add(string.Format("tid='{0}'", select_tid));
  11787. }
  11788. string shopname = GetPostString("shopname");
  11789. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11790. string buyernick = GetPostString("buyer_nick");
  11791. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11792. string sellermemo = GetPostString("seller_memo");
  11793. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11794. string supplier = GetPostString("supplier");
  11795. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11796. string customer = GetPostString("customer");
  11797. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11798. string design = GetPostString("design");
  11799. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11800. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11801. string poscode = CurrentUser.UserPost.Post.Code;
  11802. if (poscode != "SysAdmin")
  11803. {
  11804. string shopid = CurrentUser.User.pemShop;
  11805. lw.Add(string.Format("shopId in ({0})", shopid));
  11806. }
  11807. lw.Add("readMod = 2");
  11808. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11809. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11810. writeGridDataTableJson(dStruct.TotalCount, dt);
  11811. }
  11812. public void deal_express_complete()
  11813. {
  11814. string ctid = GetPostString("ctid");
  11815. if (!string.IsNullOrEmpty(ctid))
  11816. {
  11817. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11818. if (ceErpTradeCellExtend == null)
  11819. {
  11820. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11821. ceErpTradeCellExtend.ctid = ctid;
  11822. }
  11823. ceErpTradeCellExtend.readMod = 1;
  11824. if (ceErpTradeCellExtend.ID == 0)
  11825. {
  11826. ceErpTradeCellExtend.Create();
  11827. }
  11828. else
  11829. {
  11830. ceErpTradeCellExtend.Update();
  11831. }
  11832. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11833. returnSuccessMsg("修改成功!");
  11834. return;
  11835. }
  11836. returnErrorMsg("找不到订单");
  11837. }
  11838. public void aftersale_return_visit()
  11839. {
  11840. string ctid = GetPostString("ctid");
  11841. if (!string.IsNullOrEmpty(ctid))
  11842. {
  11843. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11844. if (ceErpTradeCellExtend == null)
  11845. {
  11846. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11847. ceErpTradeCellExtend.ctid = ctid;
  11848. }
  11849. ceErpTradeCellExtend.returnVisit = 1;
  11850. if (ceErpTradeCellExtend.ID == 0)
  11851. {
  11852. ceErpTradeCellExtend.Create();
  11853. }
  11854. else
  11855. {
  11856. ceErpTradeCellExtend.Update();
  11857. }
  11858. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11859. if (ceErpTradeAfterSaleExtend != null)
  11860. {
  11861. ceErpTradeAfterSaleExtend.TextResult = "";
  11862. ceErpTradeAfterSaleExtend.Update();
  11863. }
  11864. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11865. returnSuccessMsg("修改成功!");
  11866. return;
  11867. }
  11868. returnErrorMsg("找不到订单");
  11869. }
  11870. public void orderPlaceInfo()
  11871. {
  11872. string ctids = GetPostString("ctids");
  11873. string[] list = ctids.Split(',');
  11874. foreach (string ctid in list)
  11875. {
  11876. CeErpSukuraData.createInfo(ctid, 3);
  11877. }
  11878. StringBuilder sql = new StringBuilder();
  11879. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11880. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11881. designHelper.api_approveDesign(ctids); //approveDesign
  11882. returnSuccessMsg("");
  11883. }
  11884. public void get_issue_list()
  11885. {
  11886. DataStruct dStruct = GetPostStruct();
  11887. List<string> lw = new List<string>();
  11888. int st = 2;
  11889. string tid = GetPostString("ctid");
  11890. if (tid.Length > 0)
  11891. {
  11892. string select_tid = getTidByCtid(tid);
  11893. lw.Add(string.Format("tid='{0}'", select_tid));
  11894. }
  11895. string shopname = GetPostString("shopname");
  11896. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11897. string buyernick = GetPostString("buyer_nick");
  11898. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11899. string sellermemo = GetPostString("seller_memo");
  11900. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11901. string supplier = GetPostString("supplier");
  11902. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11903. string customer = GetPostString("customer");
  11904. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11905. string design = GetPostString("design");
  11906. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11907. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11908. string poscode = CurrentUser.UserPost.Post.Code;
  11909. if (poscode != "SysAdmin")
  11910. {
  11911. string shopid = CurrentUser.User.pemShop;
  11912. lw.Add(string.Format("shopId in ({0})", shopid));
  11913. }
  11914. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode) || "CustomerMr".Equals(poscode))
  11915. {
  11916. lw.Add("IssueState = 1");
  11917. }
  11918. lw.Add("IssueState > 0");
  11919. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11920. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11921. writeGridDataTableJson(dStruct.TotalCount, dt);
  11922. }
  11923. public void saveIssueContent()
  11924. {
  11925. string ctid = GetPostString("ctid");
  11926. if (!string.IsNullOrEmpty(ctid))
  11927. {
  11928. string content = GetPostString("content");
  11929. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11930. if (ceErpTradeAfterSaleExtend == null)
  11931. {
  11932. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11933. ceErpTradeAfterSaleExtend.tid = ctid;
  11934. }
  11935. ceErpTradeAfterSaleExtend.IssueContent = content;
  11936. ceErpTradeAfterSaleExtend.IssueState = 1;
  11937. if (ceErpTradeAfterSaleExtend.ID > 0)
  11938. {
  11939. ceErpTradeAfterSaleExtend.Update();
  11940. }
  11941. else
  11942. {
  11943. ceErpTradeAfterSaleExtend.Create();
  11944. }
  11945. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11946. returnSuccessMsg("添加成功!");
  11947. return;
  11948. }
  11949. returnErrorMsg("找不到订单");
  11950. }
  11951. public void dealIssueContent()
  11952. {
  11953. string ctid = GetPostString("ctid");
  11954. if (!string.IsNullOrEmpty(ctid))
  11955. {
  11956. string content = GetPostString("content");
  11957. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11958. if (ceErpTradeAfterSaleExtend != null)
  11959. {
  11960. ceErpTradeAfterSaleExtend.IssueState = 2;
  11961. ceErpTradeAfterSaleExtend.Update();
  11962. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11963. returnSuccessMsg("修改完成!");
  11964. return;
  11965. }
  11966. }
  11967. returnErrorMsg("找不到订单");
  11968. }
  11969. public void set_tid_attachments()
  11970. {
  11971. string tid = GetPostString("tid");
  11972. string atta = GetPostString("atta");
  11973. if (!string.IsNullOrEmpty(tid))
  11974. {
  11975. if (string.IsNullOrEmpty(atta))
  11976. {
  11977. returnErrorMsg("文件地址为空");
  11978. return;
  11979. }
  11980. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11981. if (ceErpTradeCell != null)
  11982. {
  11983. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11984. if (ceErpTrade == null)
  11985. {
  11986. returnErrorMsg("找不到订单");
  11987. return;
  11988. }
  11989. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11990. bool isSend = false;
  11991. if (dt != null && dt.Rows.Count > 0)
  11992. {
  11993. foreach (DataRow row in dt.Rows)
  11994. {
  11995. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11996. {
  11997. isSend = true;
  11998. }
  11999. }
  12000. if (isSend)
  12001. {
  12002. returnErrorMsg("已发货无法修改");
  12003. return;
  12004. }
  12005. ceErpTrade.Attachments = atta;
  12006. ceErpTrade.Update();
  12007. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址:" + atta, 6);
  12008. returnSuccessMsg("上传成功!");
  12009. return;
  12010. }
  12011. }
  12012. }
  12013. returnErrorMsg("找不到订单");
  12014. }
  12015. public void get_tid_attachments()
  12016. {
  12017. string tid = GetPostString("tid");
  12018. if (!string.IsNullOrEmpty(tid))
  12019. {
  12020. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  12021. if (ceErpTradeCell != null)
  12022. {
  12023. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  12024. if (ceErpTrade == null)
  12025. {
  12026. returnErrorMsg("找不到订单");
  12027. return;
  12028. }
  12029. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  12030. return;
  12031. }
  12032. }
  12033. returnErrorMsg("找不到订单");
  12034. }
  12035. public void check_erp_sameorders()
  12036. {
  12037. if (UrlPostParmsCheck("ctid"))
  12038. {
  12039. string eid = GetPostString("ctid");
  12040. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12041. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12042. if (entity != null && ceErpTrade != null)
  12043. {
  12044. if (entity.OrderState > 6)
  12045. {
  12046. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12047. return;
  12048. }
  12049. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12050. List<string> ids = new List<string>();
  12051. if (dt != null && dt.Rows.Count > 1)
  12052. {
  12053. bool needhe = true;
  12054. foreach (DataRow dr in dt.Rows)
  12055. {
  12056. ids.Add("'" + dr["ctid"] + "'");
  12057. /* //备注有合包
  12058. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  12059. {
  12060. needhe = true;
  12061. }
  12062. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  12063. {
  12064. needhe = true;
  12065. }
  12066. //顺丰快递
  12067. if (Convert.ToInt32(dr["IsSF"]) > 0)
  12068. {
  12069. needhe = true;
  12070. }*/
  12071. }
  12072. if (!needhe)
  12073. {
  12074. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12075. return;
  12076. }
  12077. StringBuilder sql = new StringBuilder();
  12078. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12079. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  12080. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  12081. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12082. foreach (DataRow dr in dt.Rows)
  12083. {
  12084. dr["dstate"] = 0;
  12085. dr["dnumber"] = 0;
  12086. foreach (DataRow row in dt1.Rows)
  12087. {
  12088. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  12089. {
  12090. dr["dstate"] = 2;
  12091. dr["default"] = 1;
  12092. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  12093. }
  12094. }
  12095. if (eid.Equals(dr["ctid"].ToString()))
  12096. {
  12097. dr["dstate"] = 1;
  12098. dr["default"] = 1;
  12099. }
  12100. }
  12101. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12102. return;
  12103. }
  12104. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12105. return;
  12106. }
  12107. returnErrorMsg("未找到订单");
  12108. return;
  12109. }
  12110. returnErrorMsg("缺少必要的参数");
  12111. }
  12112. public void get_mark_number()
  12113. {
  12114. string eid = GetPostString("ctid");
  12115. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12116. if (entity != null)
  12117. {
  12118. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12119. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12120. int current = 1;
  12121. if (ceErpDeliverMark == null)
  12122. {
  12123. DataTable dt = commonHelper.getSameOrderList(entity, ceErpTrade);
  12124. List<string> ids = new List<string>();
  12125. if (dt != null && dt.Rows.Count > 1)
  12126. {
  12127. foreach (DataRow dr in dt.Rows)
  12128. {
  12129. ids.Add("'" + dr["ctid"] + "'");
  12130. }
  12131. //查询已有的编号
  12132. StringBuilder sql = new StringBuilder();
  12133. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12134. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12135. if (dt1 == null || dt1.Rows.Count == 0)
  12136. {
  12137. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12138. List<int> list_number = new List<int>();
  12139. foreach (DataRow row in numbers.Rows)
  12140. {
  12141. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12142. }
  12143. //查询空余编号
  12144. for (int i = 0; i < list_number.Count + 2; i++)
  12145. {
  12146. if (!list_number.Contains(current))
  12147. {
  12148. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12149. //防止查询过程中有新数据生成
  12150. if (ceErpDeliverMark1 == null)
  12151. {
  12152. break;
  12153. }
  12154. }
  12155. current++;
  12156. }
  12157. }
  12158. else
  12159. {
  12160. foreach (DataRow row in dt1.Rows)
  12161. {
  12162. current = Convert.ToInt32(row["markNumber"]);
  12163. }
  12164. }
  12165. ceErpDeliverMark = new CeErpDeliverMark();
  12166. ceErpDeliverMark.ctid = eid;
  12167. ceErpDeliverMark.createtime = DateTime.Now;
  12168. if (ceErpTrade != null)
  12169. {
  12170. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12171. }
  12172. ceErpDeliverMark.markNumber = current;
  12173. ceErpDeliverMark.Create();
  12174. }
  12175. }
  12176. else
  12177. {
  12178. current = ceErpDeliverMark.markNumber;
  12179. }
  12180. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12181. return;
  12182. }
  12183. }
  12184. public void aftersaleCytSend()
  12185. {
  12186. string ctid = GetPostString("ctid");
  12187. if (!string.IsNullOrEmpty(ctid))
  12188. {
  12189. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12190. if (ceErpTradeCell != null)
  12191. {
  12192. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12193. }
  12194. returnSuccessMsg("推送成功");
  12195. return;
  12196. }
  12197. returnErrorMsg("缺少必要的参数");
  12198. }
  12199. public void packOrderInfo()
  12200. {
  12201. string ctids = GetPostString("ctids");
  12202. if (!string.IsNullOrEmpty(ctids))
  12203. {
  12204. string[] ctid_list = ctids.Split(',');
  12205. if (ctid_list.Length > 20)
  12206. {
  12207. returnErrorMsg("单次下载次数不能超过20个");
  12208. return;
  12209. }
  12210. string textCtids = "'" + ctids.Replace(",", "','") + "'";
  12211. StringBuilder sql = new StringBuilder();
  12212. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", textCtids);
  12213. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12214. int supplierId = 0;
  12215. StringBuilder insterSql = new StringBuilder();
  12216. for (int i = 0; i < dt.Rows.Count; i++)
  12217. {
  12218. DataRow row = dt.Rows[i];
  12219. if (i == 0)
  12220. {
  12221. supplierId = Convert.ToInt32(row["SupplierId"]);
  12222. }
  12223. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12224. {
  12225. returnErrorMsg("同车间的订单才能一起打包");
  12226. return;
  12227. }
  12228. int orderState = Convert.ToInt32(row["OrderState"]);
  12229. if (orderState != 5)
  12230. {
  12231. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12232. return;
  12233. }
  12234. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12235. }
  12236. CeErpPackData ceErpPackData = new CeErpPackData();
  12237. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12238. ceErpPackData.supplierId = supplierId;
  12239. ceErpPackData.createtime = DateTime.Now;
  12240. ceErpPackData.createBy = CurrentUser.UserID;
  12241. ceErpPackData.createName = CurrentUser.UserName;
  12242. ceErpPackData.Create();
  12243. if (ceErpPackData.ID > 0)
  12244. {
  12245. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12246. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12247. }
  12248. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpTradeCell set OrderState=6,IsVerifyToSupplier=0 where ctid in ({0}) and OrderState=5 and IsVerifyToSupplier=1", textCtids));
  12249. returnSuccessMsg("打包成功");
  12250. return;
  12251. }
  12252. returnErrorMsg("缺少必要的参数");
  12253. }
  12254. public void rePackOrderInfo()
  12255. {
  12256. string id = GetPostString("id");
  12257. if (!string.IsNullOrEmpty(id))
  12258. {
  12259. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12260. if (ceErpPackData == null)
  12261. {
  12262. returnSuccessMsg("查无数据");
  12263. return;
  12264. }
  12265. ceErpPackData.upStatus = 0;
  12266. ceErpPackData.message = "";
  12267. ceErpPackData.Update();
  12268. returnSuccessMsg("打包成功");
  12269. return;
  12270. }
  12271. returnErrorMsg("缺少必要的参数");
  12272. }
  12273. public void backPackOrderInfo()
  12274. {
  12275. string id = GetPostString("id");
  12276. if (!string.IsNullOrEmpty(id))
  12277. {
  12278. CeErpPackData ceErpPackData = CeErpPackData.Get(id);
  12279. if (ceErpPackData == null)
  12280. {
  12281. returnSuccessMsg("查无数据");
  12282. return;
  12283. }
  12284. ceErpPackData.upStatus = 4;
  12285. ceErpPackData.Update();
  12286. List<string> list = new List<string>();
  12287. StringBuilder sql = new StringBuilder();
  12288. sql.AppendFormat("select * from CE_ErpPackDataItem where packId = {0}", ceErpPackData.ID);
  12289. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12290. for (int i = 0; i < dt.Rows.Count; i++)
  12291. {
  12292. DataRow row = dt.Rows[i];
  12293. list.Add("'" + row["ctid"].ToString() + "'");
  12294. }
  12295. string textCtids = string.Join(",", list);
  12296. 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));
  12297. 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, "无法打包退回"));
  12298. returnSuccessMsg("退回成功");
  12299. return;
  12300. }
  12301. returnErrorMsg("缺少必要的参数");
  12302. }
  12303. public void addPackDownNum()
  12304. {
  12305. string id = GetPostString("id");
  12306. if (!string.IsNullOrEmpty(id))
  12307. {
  12308. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpPackData set downNum+=1 where id= {0}", id));
  12309. returnSuccessMsg("下载成功");
  12310. return;
  12311. }
  12312. returnErrorMsg("缺少必要的参数");
  12313. }
  12314. public void get_pack_list()
  12315. {
  12316. DataStruct dStruct = GetPostStruct();
  12317. List<string> lw = new List<string>();
  12318. string supplier = GetPostString("supplier");
  12319. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12320. string posTag = CurrentUser.UserPost.Post.Code;
  12321. if (posTag == "Supplier")
  12322. {
  12323. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12324. }
  12325. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12326. dStruct.Order = "createtime desc";
  12327. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12328. writeGridDataTableJson(dStruct.TotalCount, dt);
  12329. }
  12330. public void get_pack_order_list()
  12331. {
  12332. string packId = GetPostString("packId");
  12333. if (string.IsNullOrEmpty(packId))
  12334. {
  12335. returnErrorMsg("缺少必要的参数");
  12336. return;
  12337. }
  12338. StringBuilder sql = new StringBuilder();
  12339. 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);
  12340. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12341. if (dt == null || dt.Rows.Count == 0)
  12342. {
  12343. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12344. return;
  12345. }
  12346. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12347. return;
  12348. }
  12349. public void get_supplier_product_time_list()
  12350. {
  12351. DataStruct dStruct = GetPostStruct();
  12352. List<string> lw = new List<string>();
  12353. string supplier = GetPostString("supplier");
  12354. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12355. string posTag = CurrentUser.UserPost.Post.Code;
  12356. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12357. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12358. writeGridDataTableJson(dStruct.TotalCount, dt);
  12359. }
  12360. public void saveSupplierProductTime()
  12361. {
  12362. string productId = GetPostString("productId");
  12363. if (string.IsNullOrEmpty(productId))
  12364. {
  12365. returnErrorMsg("缺少必要的参数");
  12366. return;
  12367. }
  12368. string productName = GetPostString("productName");
  12369. int supplierId = GetPostInt("supplierId");
  12370. if (supplierId == 0)
  12371. {
  12372. returnErrorMsg("缺少必要的参数");
  12373. return;
  12374. }
  12375. int quantity = GetPostInt("quantity");
  12376. int sendDay = GetPostInt("sendTime");
  12377. string supplierName = GetPostString("supplierName");
  12378. string craft = GetPostString("craft");
  12379. string deadLine = GetPostString("deadLine");
  12380. string dayDeadLine = GetPostString("dayDeadLine");
  12381. try
  12382. {
  12383. int eid = GetPostInt("eid");
  12384. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12385. if (ceErpSupplierProductTime == null)
  12386. {
  12387. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12388. }
  12389. ceErpSupplierProductTime.productId = productId;
  12390. ceErpSupplierProductTime.productName = productName;
  12391. ceErpSupplierProductTime.supplierId = supplierId;
  12392. ceErpSupplierProductTime.supplierName = supplierName;
  12393. ceErpSupplierProductTime.craft = craft;
  12394. ceErpSupplierProductTime.sendDay = sendDay;
  12395. ceErpSupplierProductTime.quantity = quantity;
  12396. if (!string.IsNullOrEmpty(deadLine))
  12397. {
  12398. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12399. }
  12400. if (!string.IsNullOrEmpty(dayDeadLine))
  12401. {
  12402. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12403. }
  12404. if (ceErpSupplierProductTime.ID == 0)
  12405. {
  12406. ceErpSupplierProductTime.Save();
  12407. }
  12408. else
  12409. {
  12410. ceErpSupplierProductTime.Update();
  12411. }
  12412. }
  12413. catch (Exception e)
  12414. {
  12415. }
  12416. returnSuccessMsg("保存成功");
  12417. return;
  12418. }
  12419. public void delSupplierProductTime()
  12420. {
  12421. int eid = GetPostInt("eid");
  12422. if (eid > 0)
  12423. {
  12424. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12425. if (ceErpSupplierProductTime == null)
  12426. {
  12427. returnErrorMsg("查无数据");
  12428. return;
  12429. }
  12430. ceErpSupplierProductTime.Delete();
  12431. returnSuccessMsg("保存成功");
  12432. return;
  12433. }
  12434. returnErrorMsg("缺少必要的参数");
  12435. }
  12436. public void getExpressInfo()
  12437. {
  12438. string ctid = GetPostString("ctid");
  12439. if (!string.IsNullOrEmpty(ctid))
  12440. {
  12441. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12442. if (ceErpTradeCell != null)
  12443. {
  12444. string outSid = ceErpTradeCell.OutSid;
  12445. if (outSid.Length > 0)
  12446. {
  12447. 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);
  12448. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12449. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12450. return;
  12451. }
  12452. }
  12453. returnErrorMsg("查无记录");
  12454. return;
  12455. }
  12456. returnErrorMsg("缺少必要的参数");
  12457. }
  12458. public void getExpressPostData()
  12459. {
  12460. string express = GetPostString("express");
  12461. if (!string.IsNullOrEmpty(express))
  12462. {
  12463. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12464. if (ceErpExpressInfo != null)
  12465. {
  12466. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12467. return;
  12468. }
  12469. }
  12470. returnErrorMsg("缺少必要的参数");
  12471. }
  12472. public void checkSupplierOrder()
  12473. {
  12474. string ctids = GetPostString("ctids");
  12475. if (ctids != null)
  12476. {
  12477. List<string> list = new List<string>();
  12478. string sql = string.Format("SELECT ctid,seller_memo,OrderState,IsVerifyToSupplier FROM [dbo].[CE_ErpTradeCell] WHERE ctid in ({0});", "'" + ctids.Replace(",", "','") + "'");
  12479. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12480. for (int i = 0; i < dt.Rows.Count; i++)
  12481. {
  12482. DataRow row = dt.Rows[i];
  12483. if (Convert.ToInt16(row["OrderState"]) == 6 && Convert.ToInt16(row["IsVerifyToSupplier"]) == 1)
  12484. {
  12485. continue;
  12486. }
  12487. list.Add(row["seller_memo"].ToString());
  12488. }
  12489. if (list.Count > 0)
  12490. {
  12491. ReturnSuccess("{" + string.Format("\"data\":{0}", JsonConvert.SerializeObject(list)) + "}");
  12492. return;
  12493. }
  12494. }
  12495. ReturnSuccess("{" + string.Format("\"data\":{0}", "[]") + "}");
  12496. return;
  12497. }
  12498. public void addPersonId()
  12499. {
  12500. string tid = GetPostString("tid");
  12501. string personId = GetPostString("personId");
  12502. CeErpTrade ceErpTrade = CeErpTrade.Get(tid);
  12503. if (ceErpTrade != null)
  12504. {
  12505. ceErpTrade.receiver_zip = personId;
  12506. ceErpTrade.Update();
  12507. returnSuccessMsg("保存成功");
  12508. return;
  12509. }
  12510. returnErrorMsg("缺少必要的参数");
  12511. }
  12512. }
  12513. }