sync.order.cs 634 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717
  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. namespace SiteCore.Handler
  48. {
  49. public partial class sync
  50. {
  51. public void get_erp_orderlist()
  52. {
  53. string poscode = CurrentUser.UserPost.Post.Code;
  54. DataStruct dStruct = GetPostStruct();
  55. //jiemiUtils.ossFileDecrypt("C:\\Users\\231010\\Downloads\\CE_ErpProduct(2).xlsx");
  56. //apiHelper.Api_SyncOrderByTime("598825");
  57. //apiHelper.API_GetWaybill("ZTO-CAINIAO-TZJK", "4233447147588233939");
  58. //apiHelper.Api_SyacOrder("2460143282114312263", "yujia");
  59. //apiHelper.API_LogisticsOnlineSend("2460807662231834875", "yujia", "YTO-GDCYT", "YT7524607355919");
  60. //banniuApiHelper.sendLogisticsInfo(null);
  61. //commonHelper.setOrderDummyDelivery("4055992920657411904");
  62. //commonHelper.checkOrderListDesignInfo("1111122222333338841");
  63. //CeErpTradeCell entity = CeErpTradeCell.GetByCtid("2484048723252587257");
  64. //int sid = commonHelper.autoDistributeToSupplier(entity);
  65. // string a = apiHelper.API_GetPrintData("YT8951457355085");
  66. //tmcHelper.Api_TmcTradeMsg("{\r\n \"content\": {\r\n \"businessType\": \"GUARANTEE\",\r\n \"buyerMemo\": \"\",\r\n \"consolidateType\": \"\",\r\n \"createTime\": 1744882656361,\r\n \"deliveryType\": \"OFFLINE\",\r\n \"discountFee\": 0.0,\r\n \"flag\": \"NONE\",\r\n \"latestDeliveryTime\": 1744882656361,\r\n \"lines\": [\r\n {\r\n \"mark2\": [],\r\n \"num\": 4,\r\n \"outerId\": \"\",\r\n \"payment\": 60.0,\r\n \"picUrl\": \"https://img.alicdn.com/bao/uploaded/i4/2209226402185/O1CN011Zh53V1S0mQKgHJyF_!!4611686018427382153-0-item_pic.jpg\",\r\n \"platServiceFee\": 0.0,\r\n \"price\": 10.0,\r\n \"refOlId\": \"1111122222333338942\",\r\n \"refSkuId\": \"0\",\r\n \"refSpuId\": \"908453435193\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellPrice\": 10.0,\r\n \"singleFee\": 10.0,\r\n \"standards\": \"测试内部\",\r\n \"status\": \"NOT_SHIPPED\",\r\n \"title\": \"【老客户订单2】测试老客户订单内部\",\r\n \"totalFee\": 60.0,\r\n \"totalPrice\": 60.0,\r\n \"totalSellPrice\": 60.0\r\n }\r\n ],\r\n \"logisticsOrderNo\": \"\",\r\n \"mark2\": [],\r\n \"modifyTime\": 1744882656361,\r\n \"openBuyerId\": \"AAG1RHraABkUZRPgSx3g7Eam\",\r\n \"openBuyerNick\": \"0**\",\r\n \"openSellerNick\": \"海角七旗舰店\",\r\n \"orderSource\": \"SYNC\",\r\n \"orderTime\": 1744882656361,\r\n \"payTime\": 1744882656361,\r\n \"payment\": 100.0,\r\n \"platServiceFee\": 0.0,\r\n \"posCode\": \"HJQ\",\r\n \"posId\": 663281,\r\n \"postFee\": 0.0,\r\n \"props\": {\r\n \"payType\": \"ALI_PAY\",\r\n \"govSubsidyAmount\": 0\r\n },\r\n \"receivedPayment\": 0.0,\r\n \"receiverCity\": \"龙岩市\",\r\n \"receiverCountry\": \"中国\",\r\n \"receiverDistrict\": \"新罗区\",\r\n \"receiverId\": \"d1b65912ef886228ac4ada4b65055e52$\",\r\n \"receiverState\": \"福建省\",\r\n \"receiverTown\": \"西陂街道\",\r\n \"refOid\": \"1111122222333338942\",\r\n \"refType\": \"TB\",\r\n \"refundStatus\": \"NO_REFUND\",\r\n \"sellerMemo\": \"\",\r\n \"serviceFee\": 0.0,\r\n \"status\": \"NOT_SHIPPED\",\r\n \"totalFee\": 100.0,\r\n \"totalPrice\": 100.0,\r\n \"totalSellPrice\": 100.0,\r\n \"type\": \"SALE\"\r\n }\r\n}");
  67. //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}}");
  68. //string result = designHelper.API_CheckOrderTo("12123123123132", "456456465465");
  69. List<string> lw = new List<string>();
  70. string tid = GetPostString("ctid");
  71. string date1 = GetPostString("date1");
  72. //12-1 修改
  73. string urgent = GetPostString("urgent");
  74. string back = GetPostString("back");
  75. string offlineSearch = GetPostString("offlineSearch");
  76. int paramsCount = 0;
  77. if (!string.IsNullOrWhiteSpace(urgent))
  78. {
  79. if (urgent.Equals("true"))
  80. {
  81. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  82. }
  83. }
  84. if (!string.IsNullOrWhiteSpace(back))
  85. {
  86. if (back.Equals("true"))
  87. {
  88. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  89. }
  90. }
  91. if (!string.IsNullOrWhiteSpace(offlineSearch))
  92. {
  93. if (offlineSearch.Equals("true"))
  94. {
  95. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  96. }
  97. }
  98. //end
  99. string date2 = GetPostString("date2");
  100. string buyernick = GetPostString("buyer_nick");
  101. if (poscode == "wxDesigner" || poscode == "Designer" || poscode == "DesignerMr" || poscode == "wxDesignerMr")
  102. {
  103. if (tid.Length <= 0 && buyernick.Length <= 0)
  104. {
  105. return;
  106. }
  107. }
  108. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  109. {
  110. if (tid.Length > 0)
  111. {
  112. string select_tid = getTidByCtid(tid);
  113. lw.Add(string.Format("tid='{0}'", select_tid));
  114. }
  115. if (buyernick.Length > 0)
  116. {
  117. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  118. }
  119. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  120. if (dw.Length > 0)
  121. {
  122. lw.Add(dw);
  123. }
  124. if (poscode != "wxDesigner" && poscode != "Designer" && poscode != "DesignerMr" && poscode != "wxDesignerMr" && poscode != "SysAdmin")
  125. {
  126. string usershop = CurrentUser.User.pemShop;
  127. lw.Add(string.Format("ShopId in ({0})", usershop));
  128. }
  129. }
  130. else
  131. {
  132. if (ex_psize == 0)
  133. {
  134. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  135. }
  136. if (PKey != "admin")
  137. {
  138. string usershop = CurrentUser.User.pemShop;
  139. lw.Add(string.Format("ShopId in ({0})", usershop));
  140. paramsCount++;
  141. }
  142. }
  143. string uploaddate1 = GetPostString("uploaddate1");
  144. string uploaddate2 = GetPostString("uploaddate2");
  145. string update = GetDateMinuteWhere("FinishDesignTime", uploaddate1, uploaddate2);
  146. if (update.Length > 0) lw.Add(update);
  147. string deliverydate1 = GetPostString("deliverydate1");
  148. string deliverydate2 = GetPostString("deliverydate2");
  149. string deliverydate = GetDateMinuteWhere("FinishDeliveryTime", deliverydate1, deliverydate2);
  150. if (deliverydate.Length > 0)
  151. {
  152. lw.Add(string.Format("( delivery_time BETWEEN '{0}' AND '{1}' ) ", deliverydate1, deliverydate2));
  153. };
  154. string shopname = GetPostString("shopname");
  155. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  156. string addwechat = GetPostString("addwechat");
  157. if (addwechat.Length > 0)
  158. {
  159. int addWt = Convert.ToInt32(addwechat);
  160. if (addWt == 1) lw.Add(string.Format("IsAddWechat>={0}", addWt));
  161. else lw.Add(string.Format("IsAddWechat={0}", addWt));
  162. }
  163. string customer = GetPostString("customer");
  164. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  165. string design = GetPostString("design");
  166. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  167. string orderState = GetPostString("orderState");
  168. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  169. string address = GetPostString("address");
  170. 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));
  171. string sellermemo = GetPostString("seller_memo");
  172. if (sellermemo.Length > 0)
  173. {
  174. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  175. }
  176. string backReason = GetPostString("backReason");
  177. if (backReason.Length > 0)
  178. {
  179. lw.Add(string.Format("ReturnReason like '%{0}%'", backReason));
  180. }
  181. string apdate1 = GetPostString("apdate1");
  182. string apdate2 = GetPostString("apdate2");
  183. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  184. if (dwap.Length > 0) lw.Add(dwap);
  185. string price1 = GetPostString("price1");
  186. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  187. string price2 = GetPostString("price2");
  188. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  189. string isoldcustomer = GetPostString("isoldcus");
  190. string spudata = GetPostString("spudata");
  191. if ("0".Equals(spudata))
  192. {
  193. lw.Add(string.Format("(spu_id = '' or spu_id is null)"));
  194. }
  195. if ("1".Equals(spudata))
  196. {
  197. lw.Add(string.Format("spu_id <> ''"));
  198. }
  199. string finishdate1 = GetPostString("finishdate1");
  200. string finishdate2 = GetPostString("finishdate2");
  201. string finishdate = GetDateMinuteWhere("end_time", finishdate1, finishdate2);
  202. bool isFinish = false;
  203. if (finishdate.Length > 0)
  204. {
  205. lw.Add(finishdate);
  206. isFinish = true;
  207. paramsCount++;
  208. }
  209. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  210. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  211. if (ex_psize > 0)
  212. {
  213. int UserID = CurrentUser.UserID;
  214. if (UserID == 220 || UserID == 222 || UserID == 654 || UserID == 655 || UserID == 497 ||
  215. UserID == 221 || UserID == 498 || UserID == 217 || UserID == 218) //这几个人只能到处现货礼物
  216. {
  217. lw.Add(string.Format("seller_memo like '%{0}%'", "礼物"));
  218. }
  219. dStruct.Order = "pay_time desc";
  220. }
  221. string isNew = GetPostString("isNew");
  222. if (isNew == "true")
  223. {
  224. lw.Add(string.Format("IsNew = {0}", 1));
  225. }
  226. string overtime = GetPostString("overtime");
  227. if (overtime == "1")
  228. {
  229. lw.Add(string.Format("StartDesignTime IS NOT NULL and FinishDesignTime IS NULL and datediff(hh,StartDesignTime,getdate())>=48"));
  230. }
  231. String usePost = CurrentUser.UserPost.Post.Code;
  232. if (usePost.Equals("Operation") == true)
  233. {
  234. dStruct.Order = "IsSendGift desc,isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  235. }
  236. else
  237. {
  238. dStruct.Order = "isRefund desc,IsUrgency desc,IsReturn desc,pay_time desc";
  239. }
  240. //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";
  241. if (dStruct.PageSize == 100000)
  242. {
  243. dStruct.Order = "";
  244. }
  245. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  246. DataTable dt = null;
  247. string tablename = "view_orderlist";
  248. if (isFinish)
  249. {
  250. tablename = "view_orderlist_end";
  251. }
  252. dt = WebCache.GetData(tablename, dStruct);
  253. if (dt != null && dt.Rows.Count > 0)
  254. {
  255. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  256. foreach (DataRow dr in dt.Rows)
  257. {
  258. try
  259. {
  260. if (dr["refund_fees"] != null)
  261. {
  262. decimal total_fee = decimal.Parse(dr["total_fee"].ToString()); //原订单总金额
  263. decimal refund_fees = decimal.Parse(dr["refund_fees"].ToString()); //原订单退款金额
  264. decimal payment = decimal.Parse(dr["payment"].ToString()); //该订单金额
  265. if (payment == refund_fees)
  266. {
  267. dr["refund_fees"] = Math.Round(refund_fees, 2);
  268. }
  269. else if (refund_fees == total_fee)
  270. {
  271. dr["refund_fees"] = payment;
  272. }
  273. else
  274. {
  275. decimal result1 = Math.Round(refund_fees / total_fee, 2);//退款占总金额的百分比
  276. decimal result2 = Math.Round(payment / total_fee, 2);//该订单占总金额的百分比
  277. dr["refund_fees"] = Math.Round(refund_fees * result2, 2);
  278. }
  279. }
  280. // 对象操作
  281. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  282. ceErpTradeCell.ctid = dr["ctid"].ToString();
  283. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  284. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  285. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  286. if (dStruct.PageSize != 100000)
  287. {
  288. if (dr["DispatchSort"].ToString() == "2")
  289. {
  290. dr["gongchuang"] = 200;
  291. }
  292. else if ("外协".Equals(dr["ToType"].ToString()))
  293. {
  294. dr["gongchuang"] = 200;
  295. }
  296. else if ("内部".Equals(dr["ToType"].ToString()))
  297. {
  298. dr["gongchuang"] = -1;
  299. }
  300. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  301. {
  302. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  303. dr["gongchuang"] = response.code;
  304. }
  305. }
  306. }
  307. catch (NullReferenceException ex)
  308. {
  309. // 处理空引用异常
  310. dr["refund_fees"] = "0.00";
  311. }
  312. }
  313. }
  314. writeGridDataTableJson(dStruct.TotalCount, dt);
  315. }
  316. public void get_erp_orderlist_sumprice()
  317. {
  318. returnSuccess(JsonConvert.SerializeObject(new { data = 0 }));
  319. return;
  320. List<string> lw = new List<string>();
  321. string tid = GetPostString("ctid");
  322. string date1 = GetPostString("date1");
  323. string date2 = GetPostString("date2");
  324. if (tid.Length > 0 || date1.Length > 0)
  325. {
  326. lw.Add(string.Format("ctid like '%{0}%'", tid));
  327. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  328. if (dw.Length > 0) lw.Add(dw);
  329. }
  330. else
  331. {
  332. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  333. }
  334. string shopname = GetPostString("shopname");
  335. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  336. string buyernick = GetPostString("buyer_nick");
  337. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  338. string customer = GetPostString("customer");
  339. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  340. string design = GetPostString("design");
  341. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  342. string orderState = GetPostString("orderState");
  343. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  344. string address = GetPostString("address");
  345. 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));
  346. string sellermemo = GetPostString("seller_memo");
  347. if (sellermemo.Length > 0)
  348. {
  349. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  350. }
  351. string apdate1 = GetPostString("apdate1");
  352. string apdate2 = GetPostString("apdate2");
  353. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  354. if (dwap.Length > 0) lw.Add(dwap);
  355. string price1 = GetPostString("price1");
  356. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  357. string price2 = GetPostString("price2");
  358. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  359. string isoldcustomer = GetPostString("isoldcus");
  360. if (isoldcustomer.Length > 0) lw.Add(string.Format("IsOldCustomer={0}", isoldcustomer));
  361. if (ex_psize == 0 && tid.Length <= 0 && buyernick.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  362. if (PKey != "admin")
  363. {
  364. string usershop = CurrentUser.User.pemShop == "" ? "''" : CurrentUser.User.pemShop;
  365. lw.Add(string.Format("shopId in ({0})", usershop));
  366. }
  367. //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";
  368. string mainWhere = string.Join(" and ", lw.ToArray());
  369. string sql = "select sum(payment) as sumpayment from view_erptradecell where " + mainWhere;
  370. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  371. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  372. decimal total = 0;
  373. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  374. {
  375. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  376. }
  377. var res = new
  378. {
  379. data = total
  380. };
  381. string ro_jsond = JsonConvert.SerializeObject(res);
  382. returnSuccess(ro_jsond);
  383. return;
  384. }
  385. public void get_erp_CustomerServiceGather()
  386. {
  387. string userWhere = "", orderWhere = "";
  388. List<string> lw = new List<string>();
  389. string customer = GetPostString("customer");
  390. if (customer.Length > 0) userWhere = string.Format(" where name like '%{0}%'", customer);
  391. string shopname = GetPostString("shopname");
  392. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  393. string date1 = GetPostString("date1");
  394. string date2 = GetPostString("date2");
  395. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  396. if (dw.Length > 0) lw.Add(dw);
  397. orderWhere = string.Join(" and ", lw.ToArray());
  398. 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 " +
  399. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  400. "left join " +
  401. "( " +
  402. " select CustomerUserId, sum(payment) as Amount, count(CustomerUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by CustomerUserId " +
  403. ") as b on a.ID = b.CustomerUserId " +
  404. "left join " +
  405. "( " +
  406. " select CustomerUserId, count(CustomerUserId) as WaitRelease from View_ErpTradeCell where OrderState = 1 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  407. ") as d on a.ID = d.CustomerUserId " +
  408. "left join " +
  409. "( " +
  410. " select CustomerUserId, count(CustomerUserId) as WaitRob from View_ErpTradeCell where OrderState = 2 " + (orderWhere == "" ? "" : "and ") + "{1} group by CustomerUserId " +
  411. ") as e on a.ID = e.CustomerUserId " +
  412. "left join " +
  413. "( " +
  414. " select CustomerUserId, RefundCount, RefundSum from " +
  415. " ( " +
  416. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  417. " from CE_ErpTradeRefund a " +
  418. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  419. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  420. " group by CustomerUserId " +
  421. " ) as a " +
  422. ") as f on a.ID = f.CustomerUserId " +
  423. "where a.PostCode = 'CustomerService'",
  424. userWhere, orderWhere);
  425. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  426. writeGridDataTableJson(dt.Rows.Count, dt);
  427. //writeGridDataTableJson(dt.Rows.Count, dt);
  428. }
  429. //设计汇总
  430. public void get_erp_DesignerGather()
  431. {
  432. string userWhere = "", orderWhere = "";
  433. List<string> lw = new List<string>();
  434. string Designer = GetPostString("designer");
  435. int org = GetPostInt("org");
  436. if (Designer.Length > 0)
  437. {
  438. userWhere = string.Format(" where Name like '%{0}%'", Designer);
  439. if (org > 0) userWhere = string.Format(" where Name like '%{0}%' and OrgID={1}", Designer, org);
  440. }
  441. else if (org > 0)
  442. {
  443. userWhere = string.Format(" where OrgID ={0}", org);
  444. }
  445. string shopname = GetPostString("shopname");
  446. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  447. string state = GetPostString("state");
  448. if (state.Length > 0) lw.Add(string.Format("status = {0}", state));
  449. string OrderArea = GetPostString("order_area");
  450. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  451. string date1 = GetPostString("date1");
  452. string date2 = GetPostString("date2");
  453. string dw = GetDateMinuteWhere("WaitDesignTime", date1, date2);
  454. if (dw.Length > 0) lw.Add(dw);
  455. string UpDate1 = GetPostString("UpDate1");
  456. string UpDate2 = GetPostString("UpDate2");
  457. dw = GetDateMinuteWhere("FinishDesignTime", UpDate1, UpDate2);
  458. if (dw.Length > 0) lw.Add(dw);
  459. orderWhere = string.Join(" and ", lw.ToArray());
  460. 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 (" +
  461. "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 " +
  462. "from(select ID, name, PostCode from view_ErpUser {0}) as a " +
  463. "left join " +
  464. "( " +
  465. " select DesignUserId, sum(payment) as Amount, count(DesignUserId) as AllOrder from View_ErpTradeCell " + (orderWhere == "" ? "" : "where ") + " {1} group by DesignUserId " +
  466. ") as b on a.ID = b.DesignUserId " +
  467. "left join " +
  468. "( " +
  469. " select DesignUserId, count(DesignUserId) as WaitDesign from View_ErpTradeCell where OrderState = 3 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  470. ") as d on a.ID = d.DesignUserId " +
  471. "left join " +
  472. "( " +
  473. " select DesignUserId, count(DesignUserId) as Designing from View_ErpTradeCell where OrderState = 4 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  474. ") as e on a.ID = e.DesignUserId " +
  475. "left join " +
  476. "( " +
  477. " select DesignUserId, count(DesignUserId) as DesignFinish from View_ErpTradeCell where OrderState > 5 " + (orderWhere == "" ? "" : "and ") + "{1} group by DesignUserId " +
  478. ") as g on a.ID = g.DesignUserId " +
  479. "left join " +
  480. "( " +
  481. " select CustomerUserId, RefundCount, RefundSum from " +
  482. " ( " +
  483. " select b.CustomerUserId, COUNT(a.tid) as RefundCount, SUM(cast(a.refund_fee as float)) as RefundSum " +
  484. " from CE_ErpTradeRefund a " +
  485. " inner join [view_ErpTradeCell] b on a.tid = b.tid " +
  486. " where b.status = 'TRADE_CLOSED' " + (orderWhere == "" ? "" : "and ") + "{1}" +
  487. " group by CustomerUserId " +
  488. " ) as a " +
  489. ") as f on a.ID = f.CustomerUserId " +
  490. "where a.PostCode = 'Designer') as z",
  491. userWhere, orderWhere);
  492. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  493. writeGridDataTableJson(dt.Rows.Count, dt);
  494. }
  495. //删除tradecell的订单
  496. public void del_erp_cellorder()
  497. {
  498. if (UrlPostParmsCheck("ctid"))
  499. {
  500. string eid = GetPostString("ctid");
  501. CeErpTradeCell.DelByCtid(eid);
  502. LogHelper.addLog(eid, CurrentUser.UserID, "订单删除", 0, 1);
  503. returnSuccessMsg("删除成功");
  504. }
  505. }
  506. public void clear_erp_refundstate()
  507. {
  508. if (UrlPostParmsCheck("ids"))
  509. {
  510. string eids = GetPostString("ids");
  511. string[] ctidList = eids.Split(',');
  512. foreach (string ctid in ctidList)
  513. {
  514. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  515. if (entity != null)
  516. {
  517. entity.IsRefund = 0;
  518. entity.Update();
  519. LogHelper.addLog(ctid, CurrentUser.UserID, "清除退款状态", 0, 1);
  520. }
  521. else
  522. continue;
  523. }
  524. returnSuccessMsg("操作成功");
  525. return;
  526. }
  527. returnErrorMsg("缺少必要参数");
  528. }
  529. public void set_erp_urgency()
  530. {
  531. if (UrlPostParmsCheck("ctid"))
  532. {
  533. string eid = GetPostString("ctid");
  534. CeErpTradeCell entity = null;
  535. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  536. if (entity != null)
  537. {
  538. string utime = GetPostString("urgencytime");
  539. if (utime.Length > 0)
  540. {
  541. entity.UrgencyTime = Convert.ToDateTime(utime);
  542. }
  543. else
  544. {
  545. returnErrorMsg("请选择加急时间");
  546. return;
  547. }
  548. if (entity.OrderState <= 4)
  549. {
  550. //entity.seller_memo = entity.seller_memo + "-加急";
  551. string smemo = entity.seller_memo;
  552. int kindex = smemo.IndexOf(")");
  553. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  554. if (lastoneStr != "-")
  555. {
  556. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  557. }
  558. string prememo = smemo.Substring(0, kindex + 2);
  559. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  560. int lastkindex = lastmemo.IndexOf("(");
  561. DateTime urgtime = Convert.ToDateTime(utime);
  562. string newlastmemo = "";
  563. if (lastkindex == 0)
  564. {
  565. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  566. newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
  567. }
  568. else
  569. {
  570. newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
  571. }
  572. entity.seller_memo = prememo + newlastmemo;
  573. }
  574. entity.IsUrgency = true;
  575. entity.UpdateTime = DateTime.Now;
  576. entity.Update();
  577. ApiVo apiVo = new ApiVo();
  578. apiVo.orderNumber = entity.ctid;
  579. apiVo.actionName = "changeDesign";
  580. apiVo.orderRemarks = entity.seller_memo;
  581. apiVo.remarkSign = 3;
  582. designHelper.API_WorkCore(apiVo); //changeDesign
  583. CeErpSukuraData.createInfo(entity.ctid, 7);
  584. LogHelper.addLog(eid, CurrentUser.UserID, "手动订单加急", 0, 1);
  585. returnSuccessMsg("设置成功!");
  586. return;
  587. }
  588. returnErrorMsg("找不到记录");
  589. }
  590. }
  591. public void set_erp_reset()
  592. {
  593. if (UrlPostParmsCheck("ctid"))
  594. {
  595. string eid = GetPostString("ctid");
  596. CeErpTradeCell entity = null;
  597. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  598. if (entity != null)
  599. {
  600. if ((entity.OrderState >= 5 && entity.IsXianHuo == 0) || (entity.OrderState > 6 && entity.IsXianHuo == 1))
  601. {
  602. if (CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserID != 353)
  603. {
  604. returnErrorMsg("财务要求已下单已发货无法重置");
  605. return;
  606. }
  607. }
  608. entity.IsUrgency = false;
  609. entity.seller_memo = "";
  610. entity.OtherMemo = "";
  611. entity.OrderState = 0;
  612. entity.IsReturn = 0;
  613. //entity.IsRefund = 0;
  614. entity.MemoOpt = 0;
  615. entity.AfterSaleState = 0;
  616. entity.AfterSaleResponsible = "";
  617. entity.AfterSaleUserId = 0;
  618. entity.IsNeedBill = 0;
  619. entity.CustomerUserId = 0;
  620. entity.DesignUserId = 0;
  621. entity.SupplierId = 0;
  622. entity.PlaceUserId = 0;
  623. entity.ptid = "";
  624. entity.IsSample = 0;
  625. entity.IsXianHuo = 0;
  626. entity.isDianziOrder = 0;
  627. entity.DispatchSort = 0;
  628. entity.FinishPlaceTime = null;
  629. entity.Update();
  630. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  631. if (trade != null)
  632. {
  633. trade.seller_memo = "";
  634. trade.Update();
  635. }
  636. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "订单重置", entity.OrderState, 1);
  637. returnSuccessMsg("重置成功!");
  638. CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(entity.tid);
  639. if (desginBill != null)
  640. {
  641. desginBill.isDel = 1;
  642. desginBill.Update();
  643. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "订单重置", CurrentUser.UserName, 0);
  644. }
  645. ApiVo apiVo = new ApiVo();
  646. apiVo.orderNumber = entity.ctid;
  647. apiVo.actionName = "resetDesign";
  648. designHelper.API_WorkCore(apiVo);//resetDesign
  649. return;
  650. }
  651. returnErrorMsg("找不到记录");
  652. }
  653. }
  654. public void save_erp_sellermemo()
  655. {
  656. if (UrlPostParmsCheck("ctid"))
  657. {
  658. string ctid = GetPostString("ctid");
  659. CeErpTradeCell entity = null;
  660. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  661. if (entity != null)
  662. {
  663. string memo = GetPostString("seller_memo");
  664. memo = memo.Replace(" ", "");
  665. if (memo.Contains("补差"))
  666. {
  667. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  668. return;
  669. }
  670. List<string> bitList = new List<string>
  671. {
  672. "\\","/",":","*","?", "\"","<" ,">","|"
  673. };
  674. bool isIn = false;
  675. foreach (string bit in bitList)
  676. {
  677. if (memo.Contains(bit))
  678. {
  679. isIn = true;
  680. }
  681. }
  682. if (isIn)
  683. {
  684. returnErrorMsg("不能使用 一些符合作为文件名");
  685. return;
  686. }
  687. if (entity.seller_memo != memo)
  688. {
  689. if (entity.IsSample == 2)
  690. {
  691. returnErrorMsg("补差价单不能修改备注,它只能是补差价单,别乱改");
  692. return;
  693. }
  694. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  695. {
  696. if (entity.OrderState >= 5 && entity.seller_memo.IndexOf("礼物") == -1 && entity.seller_memo.IndexOf("现货") == -1 && entity.IsXianHuo == 0 && entity.IsOffLineOrder == 0)
  697. {
  698. returnErrorMsg("无法修改备注,设计稿已使用原备注,修改后下载文件会无法对应");
  699. return;
  700. }
  701. /*if (CurrentUser.UserPost.Post.Code != "Place")
  702. {
  703. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  704. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  705. {
  706. returnErrorMsg("售前系统订单无法再此修改!");
  707. return;
  708. }
  709. }*/
  710. }
  711. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统修改为:" + memo, entity.OrderState, 1);
  712. }
  713. commonHelper.getCytPrice(entity);
  714. int memoopt = GetPostInt("MemoOpt");
  715. Boolean ismemoopt = false;
  716. if (memoopt > 0)
  717. {
  718. string stropt = "";
  719. if (memoopt == 1)
  720. {
  721. stropt = "“改稿”";
  722. ismemoopt = true;
  723. }
  724. else if (memoopt == 2)
  725. {
  726. stropt = "“定稿”";
  727. }
  728. else if (memoopt == 3)
  729. {
  730. stropt = "“查货”";
  731. CeErpSukuraData.createInfo(entity.ctid, 6);
  732. }
  733. entity.MemoOpt = Convert.ToInt32(memoopt);
  734. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "系统标记:" + stropt, entity.OrderState, 1);
  735. }
  736. if (entity.OrderState < 5)
  737. {
  738. memo = memo.Replace("(", "(");
  739. memo = memo.Replace(")", ")");
  740. }
  741. if (entity.OrderState < 3)
  742. {
  743. entity.DispatchSort = 0;
  744. }
  745. entity.seller_memo = memo;
  746. entity.UpdateTime = DateTime.Now;
  747. entity.Update();
  748. ApiVo apiVo = new ApiVo();
  749. apiVo.orderNumber = entity.ctid;
  750. apiVo.actionName = memoopt > 0 ? "changeDesign" : "orderRemarks";
  751. apiVo.orderRemarks = memo;
  752. apiVo.remarkSign = memoopt;
  753. designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks
  754. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, memo, ismemoopt, false);
  755. returnSuccessMsg("保存成功!");
  756. return;
  757. }
  758. returnErrorMsg("找不到记录");
  759. }
  760. }
  761. public void ins_erp_checkorder()
  762. {
  763. if (UrlPostParmsCheck("ctid"))
  764. {
  765. string ctid = GetPostString("ctid");
  766. CeErpTradeCell entity = null;
  767. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  768. if (entity != null)
  769. {
  770. if (entity.OrderState < 6)
  771. {
  772. returnErrorMsg("下单完成后才可查货");
  773. return;
  774. }
  775. /*if (entity.OrderState > 6)
  776. {
  777. returnErrorMsg("订单已发货");
  778. return;
  779. }*/
  780. if (entity.FinishPlaceTime != null)
  781. {
  782. if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
  783. {
  784. returnErrorMsg("下单时间不足,无法查货");
  785. return;
  786. }
  787. }
  788. entity.MemoOpt = 3;
  789. entity.CheckOrderTime = DateTime.Now;
  790. entity.UpdateTime = DateTime.Now;
  791. entity.Update();
  792. CeErpSukuraData.createInfo(entity.ctid, 6);
  793. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记:查货", entity.OrderState, 1);
  794. returnSuccessMsg("操作成功!");
  795. return;
  796. }
  797. returnErrorMsg("找不到记录");
  798. }
  799. }
  800. public void save_erp_othermemo()
  801. {
  802. if (UrlPostParmsCheck("ctid"))
  803. {
  804. string ctid = GetPostString("ctid");
  805. CeErpTradeCell entity = null;
  806. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  807. if (entity != null)
  808. {
  809. entity.OtherMemo = GetPostString("otherMemo");
  810. if (entity.OtherMemo.Contains("寄样客户") && entity.OrderState < 6)
  811. {
  812. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  813. StringBuilder sql = new StringBuilder();
  814. sql.AppendFormat("select * from view_ErpTradeCell where buyer_nick = '{0}' and IsSample=3;", ceErpTrade.buyer_nick);
  815. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  816. if (dt != null && dt.Rows.Count > 0)
  817. {
  818. foreach (DataRow dr in dt.Rows)
  819. {
  820. if (entity.ProductId > 0 && Convert.ToInt32(dr["ProductId"]) > 0 && entity.ProductId == Convert.ToInt32(dr["ProductId"]))
  821. {
  822. //品类一直
  823. entity.SupplierId = Convert.ToInt32(dr["SupplierId"]);
  824. CeErpSampleCustomer ceErpSampleCustomer = CeErpSampleCustomer.GetByNick(ceErpTrade.buyer_nick);
  825. if (ceErpSampleCustomer == null)
  826. {
  827. ceErpSampleCustomer = new CeErpSampleCustomer();
  828. ceErpSampleCustomer.buyer_nick = ceErpTrade.buyer_nick;
  829. ceErpSampleCustomer.phone = dr["receiver_mobile"].ToString();
  830. ceErpSampleCustomer.address = dr["receiver_state"].ToString() + dr["receiver_city"].ToString() + dr["receiver_town"].ToString() + dr["receiver_district"].ToString();
  831. ceErpSampleCustomer.seller_nick = dr["seller_nick"].ToString();
  832. ceErpSampleCustomer.shopId = entity.ShopId;
  833. }
  834. ceErpSampleCustomer.lastbuy_time = entity.pay_time;
  835. ceErpSampleCustomer.lastTid = entity.tid;
  836. if (ceErpSampleCustomer.ID > 0)
  837. {
  838. ceErpSampleCustomer.Update();
  839. }
  840. else
  841. {
  842. ceErpSampleCustomer.Create();
  843. }
  844. }
  845. }
  846. }
  847. }
  848. //if (entity.IsOldCustomer == 1)
  849. //{
  850. //if(entity.ShopId == Convert.ToInt32(webConfig.HhOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZsOrgId) || entity.ShopId == Convert.ToInt32(webConfig.ZfOrgId))
  851. //{
  852. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  853. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:林晨", entity.OrderState);
  854. //}
  855. //if (CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.OrgId) || CurrentUser.UserPost.OrgID == Convert.ToInt32(webConfig.PlaceOrgId))
  856. //{
  857. // if(entity.DesignUserId == Convert.ToInt32(webConfig.PlaceOldCusId))
  858. // {
  859. // if (entity.OtherMemo.IndexOf("改稿") > -1)
  860. // {
  861. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceChangeId);
  862. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户改稿自动指派:林永康", entity.OrderState);
  863. // }
  864. // else if (entity.OtherMemo.IndexOf("重新设计") > -1)
  865. // {
  866. // entity.OrderState = 2;
  867. // entity.DesignUserId = 0;
  868. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户重新设计状态切换为待抢单", entity.OrderState);
  869. // }
  870. // else
  871. // {
  872. // entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); ;
  873. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "老客户自动指派:下单员", entity.OrderState);
  874. // }
  875. // }
  876. //}
  877. //}
  878. entity.UpdateTime = DateTime.Now;
  879. entity.Update();
  880. returnSuccessMsg("保存成功!");
  881. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "额外:" + entity.OtherMemo, entity.OrderState);
  882. return;
  883. }
  884. returnErrorMsg("找不到记录");
  885. }
  886. }
  887. public void save_erp_customermemo()
  888. {
  889. if (UrlPostParmsCheck("ctid"))
  890. {
  891. string ctid = GetPostString("ctid");
  892. CeErpTradeCell entity = null;
  893. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  894. if (entity != null)
  895. {
  896. entity.UpdateTime = DateTime.Now;
  897. entity.CustomerMemo = GetPostString("CustomerMemo");
  898. entity.Update();
  899. ApiVo apiVo = new ApiVo();
  900. apiVo.orderNumber = entity.ctid;
  901. apiVo.actionName = "followRemarks";
  902. apiVo.orderRemarks = entity.CustomerMemo;
  903. designHelper.API_WorkCore(apiVo);//followRemarks
  904. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "跟单备注:" + entity.CustomerMemo, entity.OrderState);
  905. returnSuccessMsg("保存成功!");
  906. return;
  907. }
  908. returnErrorMsg("找不到记录");
  909. }
  910. }
  911. public void upd_erp_addmemotag()
  912. {
  913. if (UrlPostParmsCheck("ctid"))
  914. {
  915. ;
  916. string eid = GetPostString("ctid");
  917. string sfTagstr = GetPostString("memotag");
  918. CeErpTradeCell entity = null;
  919. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  920. if (entity != null)
  921. {
  922. ApiVo apiVo = new ApiVo();
  923. if (entity.OrderState == 0)
  924. {
  925. returnErrorMsg("请先领单");
  926. return;
  927. }
  928. //撤销顺丰
  929. if (sfTagstr == "撤销顺丰")
  930. {
  931. entity.IsSF = 0;
  932. string reMsg = "";
  933. string oldmemo = entity.seller_memo;
  934. if (entity.OrderState < 5)
  935. {
  936. oldmemo = oldmemo.Replace("顺丰到付", "");
  937. oldmemo = oldmemo.Replace("顺丰寄付", "");
  938. entity.seller_memo = oldmemo;
  939. }
  940. else
  941. {
  942. if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
  943. {
  944. reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
  945. }
  946. }
  947. entity.Update();
  948. apiVo.orderNumber = entity.ctid;
  949. apiVo.actionName = "orderRemarks";
  950. apiVo.orderRemarks = entity.seller_memo;
  951. apiVo.isSf = entity.IsSF.ToString();
  952. designHelper.API_WorkCore(apiVo);//orderRemarks
  953. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "撤销标记顺丰", entity.OrderState, 1);
  954. returnSuccessMsg("撤销成功!" + reMsg);
  955. return;
  956. }
  957. if (entity.OrderState < 5 || entity.IsXianHuo == 1)
  958. {
  959. //string oldmemo = entity.seller_memo;
  960. //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
  961. string sfStr = GetPostString("memotag");
  962. string smemo = entity.seller_memo;
  963. int kindex = smemo.IndexOf(")");
  964. string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
  965. if (lastoneStr != "-")
  966. {
  967. smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
  968. }
  969. string prememo = smemo.Substring(0, kindex + 2);
  970. string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
  971. int lastkindex = lastmemo.IndexOf("(");
  972. string newlastmemo = "";
  973. if (lastkindex == 0)
  974. {
  975. string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
  976. newlastmemo = "(" + sfStr + "." + useLastmemo;
  977. }
  978. else
  979. {
  980. newlastmemo = "(" + sfStr + ")-" + lastmemo;
  981. }
  982. entity.seller_memo = prememo + newlastmemo;
  983. }
  984. string sfTagMSg = "";
  985. if (sfTagstr == "顺丰寄付")
  986. {
  987. entity.IsSF = 1;
  988. sfTagMSg = "顺丰寄付";
  989. }
  990. else if (sfTagstr == "顺丰到付")
  991. {
  992. entity.IsSF = 2;
  993. sfTagMSg = "顺丰到付";
  994. }
  995. entity.Update();
  996. apiVo = new ApiVo();
  997. apiVo.orderNumber = entity.ctid;
  998. apiVo.actionName = "orderRemarks";
  999. apiVo.orderRemarks = entity.seller_memo;
  1000. apiVo.isSf = entity.IsSF.ToString();
  1001. designHelper.API_WorkCore(apiVo);//orderRemarks
  1002. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "右键标记:" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
  1003. returnSuccessMsg("标记成功!");
  1004. return;
  1005. }
  1006. returnErrorMsg("找不到记录");
  1007. }
  1008. }
  1009. public void upd_erp_ordertag()
  1010. {
  1011. if (UrlPostParmsCheck("ctid"))
  1012. {
  1013. string eid = GetPostString("ctid");
  1014. CeErpTradeCell entity = null;
  1015. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1016. if (entity != null)
  1017. {
  1018. int tag = GetPostInt("wechattag");
  1019. //if(tag==4 && entity.IsSample == 2)
  1020. //{
  1021. // returnErrorMsg("补差价单不能标记微信单");
  1022. // return;
  1023. //}
  1024. entity.wechatTag = tag;
  1025. entity.Update();
  1026. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  1027. if (tag == 1)
  1028. {
  1029. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1030. if (cash == null)
  1031. {
  1032. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1033. cash = new CeErpReturnCash();
  1034. cash.tid = entity.tid;
  1035. cash.seller_nick = main.seller_nick;
  1036. cash.payment = trade.payment;
  1037. cash.buyer_nick = main.buyer_nick;
  1038. cash.cashstate = 0;
  1039. cash.rtype = "微信返现";
  1040. cash.returnprice = 0;
  1041. cash.created = DateTime.Now;
  1042. cash.con = "订单标记微信单";
  1043. cash.img = "";
  1044. cash.applyuserid = CurrentUser.UserID;
  1045. cash.Create();
  1046. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:微信返现");
  1047. }
  1048. else
  1049. {
  1050. cash.cashstate = 0;
  1051. cash.Update();
  1052. }
  1053. CeErpSukuraData.createInfo(entity.ctid, 9);
  1054. }
  1055. else if (tag == 2)
  1056. {
  1057. CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
  1058. if (cash == null)
  1059. {
  1060. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1061. cash = new CeErpReturnCash();
  1062. cash.tid = entity.tid;
  1063. cash.seller_nick = main.seller_nick;
  1064. cash.payment = trade.payment;
  1065. cash.buyer_nick = main.buyer_nick;
  1066. cash.cashstate = 0;
  1067. cash.rtype = "推购返现";
  1068. cash.returnprice = 5;
  1069. cash.created = DateTime.Now;
  1070. cash.con = "订单标记推购单";
  1071. cash.img = "";
  1072. cash.applyuserid = CurrentUser.UserID;
  1073. cash.Create();
  1074. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推购返现");
  1075. }
  1076. else
  1077. {
  1078. cash.cashstate = 0;
  1079. cash.Update();
  1080. }
  1081. CeErpSukuraData.createInfo(entity.ctid, 9);
  1082. }
  1083. else if (tag == 3)
  1084. {
  1085. CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
  1086. if (pers == null)
  1087. {
  1088. pers = new CeErpPersuade();
  1089. pers.ctid = entity.ctid;
  1090. pers.pstate = 0;
  1091. pers.created = DateTime.Now;
  1092. pers.applyuserid = CurrentUser.UserID;
  1093. pers.Create();
  1094. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:挽回推多");
  1095. }
  1096. else
  1097. {
  1098. pers.pstate = 0;
  1099. pers.Update();
  1100. }
  1101. }
  1102. else if (tag == 4 || tag == 5)
  1103. {
  1104. CeErpTrade main = CeErpTrade.Get(entity.tid);
  1105. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1106. if (pers == null)
  1107. {
  1108. pers = new CeErpStayGoods();
  1109. pers.t_id = entity.tid;
  1110. pers.status = "待审核";
  1111. pers.audit_type = 0;
  1112. if (tag == 4)
  1113. {
  1114. pers.stay_type = "微信推购";
  1115. }
  1116. else
  1117. {
  1118. pers.stay_type = "旺旺推购";
  1119. }
  1120. if (entity.IsXianHuo == 0)
  1121. {
  1122. pers.product_id = entity.ProductId;
  1123. }
  1124. pers.wangwang = main.buyer_nick;
  1125. pers.shop_name = main.seller_nick;
  1126. pers.creata_time = DateTime.Now;
  1127. pers.create_u_id = CurrentUser.UserID;
  1128. pers.create_u_name = CurrentUser.UserName;
  1129. pers.Create();
  1130. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "添加:推多推购");
  1131. }
  1132. else
  1133. {
  1134. pers.audit_type = 0;
  1135. pers.Update();
  1136. }
  1137. CeErpSukuraData.createInfo(entity.ctid, 10);
  1138. }
  1139. //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
  1140. returnSuccessMsg("标记成功!");
  1141. return;
  1142. }
  1143. returnErrorMsg("找不到记录");
  1144. }
  1145. }
  1146. public void upd_erp_ordertag_cancel()
  1147. {
  1148. if (UrlPostParmsCheck("ctid"))
  1149. {
  1150. string eid = GetPostString("ctid");
  1151. CeErpTradeCell entity = null;
  1152. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1153. if (entity != null)
  1154. {
  1155. entity.wechatTag = 0;
  1156. entity.Update();
  1157. CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
  1158. if (pers != null)
  1159. {
  1160. pers.status = "取消推购";
  1161. pers.audit_type = 3;
  1162. pers.Update();
  1163. }
  1164. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消:推多推购");
  1165. returnSuccessMsg("标记成功!");
  1166. return;
  1167. }
  1168. returnErrorMsg("找不到记录");
  1169. }
  1170. }
  1171. public void upd_erp_addweichattag()
  1172. {
  1173. if (UrlPostParmsCheck("ctid"))
  1174. {
  1175. ;
  1176. string eid = GetPostString("ctid");
  1177. CeErpTradeCell entity = null;
  1178. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1179. if (entity != null)
  1180. {
  1181. if (entity.IsAddWechat > 0)
  1182. {
  1183. returnErrorMsg("此单已经标记过了");
  1184. return;
  1185. }
  1186. 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);
  1187. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1188. if (dt.Rows.Count > 0)
  1189. {
  1190. entity.IsAddWechat = 2;
  1191. }
  1192. else
  1193. {
  1194. entity.IsAddWechat = 1;
  1195. }
  1196. entity.Update();
  1197. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记已添加微信", entity.OrderState, 1);
  1198. returnSuccessMsg("标记成功!");
  1199. return;
  1200. }
  1201. returnErrorMsg("找不到记录");
  1202. }
  1203. }
  1204. public void upd_erp_getmyorder()
  1205. {
  1206. if (UrlPostParmsCheck("ctid"))
  1207. {
  1208. ;
  1209. string eid = GetPostString("ctid");
  1210. CeErpTradeCell entity = null;
  1211. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1212. if (entity != null)
  1213. {
  1214. if (entity.ctid.IndexOf("C") != -1)
  1215. {
  1216. StringBuilder sql = new StringBuilder();
  1217. sql.AppendFormat("select * from view_ErpTradeCell where tid='{0}';", entity.tid);
  1218. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1219. if (dt.Rows.Count > 0)
  1220. {
  1221. decimal total = 0;
  1222. foreach (DataRow dr in dt.Rows)
  1223. {
  1224. total += Convert.ToDecimal(dr["payment"]);
  1225. }
  1226. decimal main_payment = Convert.ToDecimal(dt.Rows[0]["main_payment"]);
  1227. if (Math.Abs(main_payment - total) > Convert.ToDecimal(0.01))
  1228. {
  1229. returnErrorMsg("拆分金额跟原单金额不一致,无法领单!");
  1230. return;
  1231. }
  1232. }
  1233. }
  1234. if (entity.OrderState == -1)
  1235. {
  1236. returnErrorMsg("待审核订单无法领取!");
  1237. return;
  1238. }
  1239. entity.CustomerUserId = CurrentUser.UserID;
  1240. if (entity.OrderState < 2)
  1241. {
  1242. entity.OrderState = 2;
  1243. if (entity.ShopId != 0)
  1244. {
  1245. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1246. }
  1247. }
  1248. entity.UpdateTime = DateTime.Now;
  1249. entity.Update();
  1250. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动领单", entity.OrderState, 1);
  1251. returnSuccessMsg("领单成功!");
  1252. return;
  1253. }
  1254. returnErrorMsg("找不到记录");
  1255. }
  1256. }
  1257. public void getmyorder_from_init()
  1258. {
  1259. if (UrlPostParmsCheck("ctid"))
  1260. {
  1261. string eid = GetPostString("ctid");
  1262. CeErpTradeCell entity = null;
  1263. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1264. if (entity != null)
  1265. {
  1266. string sellerMemo = GetPostString("sellerMemo");
  1267. if (sellerMemo.Length > 0)
  1268. {
  1269. entity.seller_memo = sellerMemo;
  1270. }
  1271. string oterhMemo = GetPostString("otherMemo");
  1272. if (oterhMemo.Length > 0)
  1273. {
  1274. entity.OtherMemo = oterhMemo;
  1275. }
  1276. int urg = GetPostInt("urgency");
  1277. entity.IsUrgency = (urg == 1 ? true : false);
  1278. int wechat = GetPostInt("wechat");
  1279. int command = GetPostInt("command");
  1280. if (wechat == 1)
  1281. {
  1282. entity.wechatTag = 1;
  1283. }
  1284. if (command == 1)
  1285. {
  1286. entity.wechatTag = 2;
  1287. }
  1288. string pPro = GetPostString("pprofession");
  1289. if (pPro.Length > 0)
  1290. {
  1291. entity.ParentProfessionId = Convert.ToInt32(pPro);
  1292. string spro = GetPostString("profession");
  1293. if (spro.Length > 0)
  1294. {
  1295. entity.ProfessionId = Convert.ToInt32(spro);
  1296. }
  1297. }
  1298. string proId = GetPostString("productId");
  1299. if (proId.Length > 0)
  1300. {
  1301. entity.ProductId = Convert.ToInt32(proId);
  1302. }
  1303. entity.Material = GetPostString("material");
  1304. entity.Craft = GetPostString("craft");
  1305. entity.CustomerUserId = CurrentUser.UserID;
  1306. if (entity.OrderState < 2)
  1307. {
  1308. entity.OrderState = 2;
  1309. if (entity.ShopId != 0)
  1310. {
  1311. entity.OrderState = tmcHelper.orderAudit(entity.ShopId);
  1312. }
  1313. }
  1314. entity.Update();
  1315. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "选择型手动领单", entity.OrderState, 1);
  1316. returnSuccessMsg("领单成功!");
  1317. return;
  1318. }
  1319. returnErrorMsg("找不到记录");
  1320. }
  1321. }
  1322. public void upd_erp_setrelationorder()
  1323. {
  1324. if (UrlPostParmsCheck("ctid"))
  1325. {
  1326. ;
  1327. string eid = GetPostString("ctid");
  1328. string ftid = GetPostString("ftid");
  1329. CeErpTradeCell entity = null;
  1330. CeErpTradeCell fentity = null;
  1331. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1332. if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
  1333. if (fentity == null)
  1334. {
  1335. returnErrorMsg("找不到关联的主订单");
  1336. return;
  1337. }
  1338. if (entity != null)
  1339. {
  1340. if (entity.OrderState >= 5)
  1341. {
  1342. returnErrorMsg("本单已经设计完成无法关联");
  1343. return;
  1344. }
  1345. if ((eid.Contains("N_") || ftid.Contains("N_")) && (fentity.OrderState == -1 || entity.OrderState == -1))
  1346. {
  1347. returnErrorMsg("线下单续审核后才能关联!");
  1348. return;
  1349. }
  1350. entity.ptid = ftid;
  1351. entity.OrderState = fentity.OrderState;
  1352. //entity.status = fentity.status;
  1353. entity.CustomerUserId = fentity.CustomerUserId;
  1354. entity.DesignUserId = fentity.DesignUserId;
  1355. entity.seller_memo = "补差价单:" + ftid;
  1356. entity.IsSample = 2;
  1357. entity.Update();
  1358. ApiVo apiVo = new ApiVo();
  1359. apiVo.orderNumber = ftid;
  1360. apiVo.payment = entity.payment;
  1361. apiVo.actionName = "repairDesign";
  1362. designHelper.API_WorkCore(apiVo);//repairDesign
  1363. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "手动关联补差价", entity.OrderState, 1);
  1364. returnSuccessMsg("关联成功!");
  1365. return;
  1366. }
  1367. else
  1368. returnErrorMsg("找不到记录");
  1369. }
  1370. }
  1371. public void download_erp_neworder()
  1372. {
  1373. string seller = GetPostString("seller_nick");
  1374. string tid = GetPostString("tid");
  1375. if (seller.Length <= 0 || tid.Length <= 0)
  1376. {
  1377. returnErrorMsg("数据错误");
  1378. }
  1379. //if (taobaoHelper.ShopKeyDics.ContainsKey(seller) == false)
  1380. //{
  1381. // returnErrorMsg("找不到店铺Sessionkey");
  1382. //}
  1383. //string sessionkey = taobaoHelper.ShopKeyDics[seller];
  1384. //string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid);
  1385. string res = apiHelper.API_TradeFullinfoGet(tid, "", "");
  1386. if (res.IndexOf("refOid") == -1)
  1387. {
  1388. returnErrorMsg("下载订单数据失败");
  1389. return;
  1390. }
  1391. tmcHelper.Api_Tmc_CreateNewOrder(res);
  1392. returnSuccessMsg("下载完成");
  1393. //tmcHelper.createNewOrder(res);
  1394. //CeErpTrade entr = null;
  1395. //entr = CeErpTrade.Get(tid);
  1396. //if (entr != null)
  1397. //{
  1398. // returnSuccess("下载成功");
  1399. // //下载成功之后,Cell表生成对应的订单;
  1400. // tmcHelper.createCellOrder(entr,entr.tid,entr.seller_memo,entr.buyer_nick,true);//最后加上true跳过阻止直接拆分创建cell子单
  1401. //}
  1402. //else
  1403. //{
  1404. // returnErrorMsg("下载失败或者创建订单失败");
  1405. //}
  1406. }
  1407. public void set_erp_atersale()
  1408. {
  1409. if (UrlPostParmsCheck("ctid"))
  1410. {
  1411. string eid = GetPostString("ctid");
  1412. string reason = GetPostString("AfterSaleReason");
  1413. CeErpTradeCell entity = null;
  1414. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1415. if (entity != null)
  1416. {
  1417. if (CurrentUser.UserPost.Post.Code != "AfterSale" && CurrentUser.UserPost.Post.Code != "SysAdmin" && entity.AfterSaleState > 0 && CurrentUser.UserPost.Post.Code != "AfterSaleMaster")
  1418. {
  1419. returnErrorMsg("此订单已经在售后");
  1420. return;
  1421. }
  1422. entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
  1423. entity.UpdateTime = DateTime.Now; //entity.AfterSaleReason = reason;
  1424. entity.AfterSaleTime = DateTime.Now;
  1425. entity.Update();
  1426. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记售后-" + reason, entity.OrderState, 1);
  1427. returnSuccessMsg("转售后成功!");
  1428. return;
  1429. }
  1430. returnErrorMsg("找不到记录");
  1431. }
  1432. }
  1433. public void set_erp_withdraw()
  1434. {
  1435. if (UrlPostParmsCheck("ctid"))
  1436. {
  1437. try
  1438. {
  1439. string eid = GetPostString("ctid");//商品id
  1440. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(eid);
  1441. CeWithdraw ceWithdrawSelect = null;
  1442. ceWithdrawSelect = CeWithdraw.GetByTid(eid);
  1443. if (ceWithdrawSelect != null)
  1444. {
  1445. if (ceWithdrawSelect.status == 2 && ceWithdrawSelect.providerid.Equals("-1"))
  1446. {
  1447. ceWithdrawSelect.status = -1;
  1448. ceWithdrawSelect.Update();
  1449. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "重新发起审核成功,待车间确认", ceErpTradeCell.OrderState);
  1450. returnSuccessMsg("重新发起审核成功");
  1451. return;
  1452. }
  1453. else
  1454. {
  1455. returnSuccessMsg("请勿重复申请!");
  1456. return;
  1457. }
  1458. }
  1459. else
  1460. {
  1461. string CustomerUserId = GetPostString("CustomerUserId");//供应商id
  1462. if (string.IsNullOrEmpty(CustomerUserId))
  1463. {
  1464. CustomerUserId = "-1";
  1465. }
  1466. int Userid = CurrentUser.UserID;//用户id
  1467. CeWithdraw ceWithdraw = new CeWithdraw();
  1468. ceWithdraw.tid = eid;
  1469. ceWithdraw.userid = Userid;
  1470. ceWithdraw.providerid = CustomerUserId;
  1471. ceWithdraw.status = 3;
  1472. ceWithdraw.creationtime = DateTime.Now;
  1473. ceWithdraw.Create();
  1474. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "申请撤回订单成功,待车间确认", ceErpTradeCell.OrderState);
  1475. returnSuccessMsg("申请撤回订单成功,待车间确认");
  1476. return;
  1477. }
  1478. }
  1479. catch
  1480. {
  1481. returnErrorMsg("申请撤回订单失败");
  1482. return;
  1483. }
  1484. }
  1485. }
  1486. public void ins_erp_billinfo()
  1487. {
  1488. if (UrlPostParmsCheck("ctid"))
  1489. {
  1490. string eid = GetPostString("ctid");
  1491. CeErpTradeCell entity = null;
  1492. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1493. if (entity != null)
  1494. {
  1495. CeErpBill bill = CeErpBill.GetByTid(eid);
  1496. bool isHave = false;
  1497. if (bill != null)
  1498. {
  1499. isHave = true;
  1500. if (bill.state != 4)
  1501. {
  1502. returnErrorMsg("此单已经申请过发票了");
  1503. return;
  1504. }
  1505. }
  1506. if (entity.IsNeedBill == 0)
  1507. {
  1508. entity.IsNeedBill = 1;
  1509. }
  1510. entity.Update();
  1511. string errjson = "";
  1512. try
  1513. {
  1514. CeErpBill bill_entity = new CeErpBill();
  1515. bill_entity.tid = entity.tid;
  1516. bill_entity.title = GetPostString("title");
  1517. string taxstr = GetPostString("tax");
  1518. taxstr = taxstr.Replace(" ", "");
  1519. bill_entity.tax = taxstr;
  1520. bill_entity.bank = GetPostString("bank");
  1521. string bankacstr = GetPostString("bankac");
  1522. bankacstr = bankacstr.Replace(" ", "");
  1523. bill_entity.bankac = bankacstr;
  1524. bill_entity.address = GetPostString("address");
  1525. bill_entity.phone = GetPostString("phone");
  1526. bill_entity.price = GetPostString("price");
  1527. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
  1528. if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
  1529. {
  1530. billCount += 1;
  1531. }
  1532. string prebill = "ltb";
  1533. for (int idx = 1; idx <= billCount; idx++)
  1534. {
  1535. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  1536. string billoid = prebill + idx + dtstr;
  1537. bill_entity.billOrderId += billoid;
  1538. if (idx < billCount)
  1539. {
  1540. bill_entity.billOrderId += ",";
  1541. }
  1542. }
  1543. bill_entity.productId = GetPostInt("ProductName");
  1544. bill_entity.num = GetPostInt("num");
  1545. bill_entity.unit = GetPostString("unit");
  1546. bill_entity.type = GetPostString("type");
  1547. bill_entity.sendType = GetPostString("SendType");
  1548. bill_entity.email = GetPostString("email");
  1549. bill_entity.buyer_nick = GetPostString("buyer_nick");
  1550. bill_entity.shopName = GetPostString("ShopName");
  1551. bill_entity.applymemo = GetPostString("applyMemo");
  1552. bill_entity.createTime = DateTime.Now;
  1553. bill_entity.state = 0;
  1554. bill_entity.userId = CurrentUser.UserID;
  1555. errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
  1556. bill_entity.Create();
  1557. }
  1558. catch (Exception ex)
  1559. {
  1560. XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
  1561. returnErrorMsg("创建发票出错!");
  1562. return;
  1563. }
  1564. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
  1565. returnSuccessMsg("发票申请成功!");
  1566. return;
  1567. }
  1568. returnErrorMsg("找不到记录");
  1569. }
  1570. }
  1571. public void ins_erp_neworder()
  1572. {
  1573. if (UrlPostParmsCheck("receiver_name"))
  1574. {
  1575. CeErpTrade entity = new CeErpTrade();
  1576. string plat_form = GetPostString("platform");
  1577. string preStr = "N_";
  1578. if (plat_form == "拼多多")
  1579. {
  1580. preStr = "P_";
  1581. }
  1582. else if (plat_form == "阿里巴巴")
  1583. {
  1584. preStr = "A_";
  1585. }
  1586. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1587. entity.seller_nick = GetPostString("seller_nick");
  1588. entity.buyer_nick = GetPostString("buyer_nick");
  1589. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1590. entity.total_fee = entity.payment;
  1591. entity.pay_time = DateTime.Now;
  1592. entity.status = "NOT_SHIPPED";
  1593. entity.receiver_name = GetPostString("receiver_name");
  1594. entity.receiver_mobile = GetPostString("receiver_mobile");
  1595. entity.receiver_state = GetPostString("receiver_state");
  1596. entity.receiver_city = GetPostString("receiver_city");
  1597. entity.receiver_district = GetPostString("receiver_district");
  1598. entity.receiver_address = GetPostString("receiver_address");
  1599. if (entity.receiver_state == "" || entity.receiver_city == "")
  1600. {
  1601. returnErrorMsg("收件地址不能为空");
  1602. return;
  1603. }
  1604. int shopId = 0;
  1605. CeErpShop nShop = CeErpShop.GetShopIdByName(entity.seller_nick);
  1606. if (nShop != null)
  1607. {
  1608. shopId = nShop.ID;
  1609. }
  1610. if (shopId != 34 && entity.payment == 0)
  1611. {
  1612. returnErrorMsg("公司自用的单金额才能为0");
  1613. return;
  1614. }
  1615. entity.Create();
  1616. CeErpTradeCell entitycell = new CeErpTradeCell();
  1617. entitycell.ctid = entity.tid;
  1618. entitycell.tid = entity.tid;
  1619. entitycell.ShopId = shopId;
  1620. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1621. entitycell.OrderState = 0;
  1622. entitycell.pay_time = entity.pay_time;
  1623. entitycell.IsOffLineOrder = 1;
  1624. entitycell.Create();
  1625. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1626. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增订单", 0, 0);
  1627. return;
  1628. }
  1629. }
  1630. public void ins_erp_neworder2()
  1631. {
  1632. if (UrlPostParmsCheck("receiver_name"))
  1633. {
  1634. //string plat_form = GetPostString("platform");
  1635. string preStr = "X_";
  1636. string memo = GetPostString("memo");
  1637. string productId = GetPostString("productId");
  1638. string primg = GetPostString("proofimg");
  1639. string sellerNick = GetPostString("seller_nick");
  1640. string addFrom = GetPostString("addfrom");
  1641. if (addFrom == "1")
  1642. {
  1643. preStr = "N_";
  1644. }
  1645. int shopId = 0;
  1646. CeErpShop nShop = CeErpShop.GetShopIdByName(sellerNick);
  1647. if (nShop != null)
  1648. {
  1649. shopId = nShop.ID;
  1650. }
  1651. else
  1652. {
  1653. returnErrorMsg("找不到对应店铺");
  1654. return;
  1655. }
  1656. if ((shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114) && primg.Length <= 0)//公司自用店铺ID
  1657. {
  1658. returnErrorMsg("必须上传付款凭证");
  1659. return;
  1660. }
  1661. CeErpTrade entity = new CeErpTrade();
  1662. entity.tid = (preStr + DateTime.Now.ToString("yyyyMMddHHmmss"));
  1663. entity.seller_nick = sellerNick;
  1664. entity.buyer_nick = GetPostString("buyer_nick");
  1665. entity.payment = Convert.ToDouble(GetPostString("payment"));
  1666. entity.total_fee = entity.payment;
  1667. entity.pay_time = DateTime.Now;
  1668. entity.status = "NOT_SHIPPED";
  1669. entity.receiver_name = GetPostString("receiver_name");
  1670. entity.receiver_mobile = GetPostString("receiver_mobile");
  1671. entity.receiver_state = GetPostString("receiver_state");
  1672. entity.receiver_city = GetPostString("receiver_city");
  1673. entity.receiver_district = GetPostString("receiver_district");
  1674. entity.receiver_address = GetPostString("receiver_address");
  1675. entity.seller_memo = memo;
  1676. entity.orderFrom = 20;
  1677. entity.orderType = 15;
  1678. if (entity.receiver_state == "" || entity.receiver_city == "")
  1679. {
  1680. returnErrorMsg("收件地址不能为空");
  1681. return;
  1682. }
  1683. if ((shopId != 34 && shopId != 94 && shopId != 96 && shopId != 95 && shopId != 114) && entity.payment == 0)
  1684. {
  1685. returnErrorMsg("公司自用的单金额才能为0");
  1686. return;
  1687. }
  1688. entity.Create();
  1689. string toWhere = GetPostString("towhere");
  1690. CeErpTradeCell entitycell = new CeErpTradeCell();
  1691. entitycell.ctid = entity.tid;
  1692. //唯一标识
  1693. entitycell.OrderSn = entity.tid;
  1694. string orderSn = dataHelper.getSaleOrderSn();
  1695. if (orderSn != "")
  1696. {
  1697. entitycell.OrderSn = orderSn;
  1698. }
  1699. entitycell.tid = entity.tid;
  1700. //if (preStr == "X_")
  1701. //{
  1702. entitycell.IsOffLineOrder = 1;
  1703. //}
  1704. entitycell.CustomerUserId = CurrentUser.UserID;
  1705. entitycell.PayProofImg = primg;
  1706. entitycell.seller_memo = "(" + entitycell.OrderSn + ")-" + memo;
  1707. entitycell.ProductId = Convert.ToInt32(productId);
  1708. entitycell.ShopId = shopId;
  1709. entitycell.UpdateTime = DateTime.Now;
  1710. entitycell.payment = Convert.ToDouble(GetPostString("payment"));
  1711. if (entity.buyer_nick == "现货手提袋" || memo.IndexOf("现货手提袋") != -1)
  1712. {
  1713. entitycell.IsXianHuo = 1;
  1714. }
  1715. entitycell.pay_time = entity.pay_time;
  1716. if (toWhere == "1")
  1717. {
  1718. entitycell.OrderState = 2;
  1719. }
  1720. else
  1721. {
  1722. entitycell.OrderState = 6;
  1723. entitycell.FinishPlaceTime = entitycell.pay_time;
  1724. }
  1725. if (shopId == 94)
  1726. {
  1727. entitycell.OrderState = 4;
  1728. entitycell.WaitDesignTime = entitycell.pay_time;
  1729. entitycell.StartDesignTime = entitycell.pay_time;
  1730. entitycell.DesignUserId = 218;
  1731. }
  1732. if (addFrom == "1" && (shopId != 34 && shopId != 96 && shopId != 95 && shopId != 94 && shopId != 114))
  1733. {
  1734. entitycell.OrderState = -1;//修改12-5
  1735. CeWithdraw ceWithdraw = new CeWithdraw();
  1736. ceWithdraw.tid = entity.tid;
  1737. ceWithdraw.providerid = "-1";
  1738. ceWithdraw.status = -1;
  1739. ceWithdraw.creationtime = DateTime.Now;
  1740. ceWithdraw.userid = 1337;
  1741. ceWithdraw.Create();
  1742. }
  1743. entitycell.Create();
  1744. CeErpTradeCellExtend.createInfo(entitycell.ctid, 15, 20);
  1745. if (shopId == 34 && entity.buyer_nick == "现货手提袋")
  1746. {
  1747. addPlaceRegist(entitycell, CurrentUser.UserID);
  1748. }
  1749. returnSuccessMsg("订单已生成!单号:" + entity.tid);
  1750. LogHelper.addLog(entitycell.ctid, CurrentUser.UserID, "新增线下订单", 0, 0);
  1751. return;
  1752. }
  1753. }
  1754. public void addPlaceRegist(CeErpTradeCell tradecell, int userid)
  1755. {
  1756. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  1757. entity.PlactTime = tradecell.pay_time;
  1758. entity.AddUserId = userid;
  1759. entity.FileName = tradecell.seller_memo;
  1760. entity.Supplier = 24;
  1761. entity.CreateTime = DateTime.Now;
  1762. entity.Did = tradecell.ctid;
  1763. entity.tid = tradecell.tid;
  1764. entity.splitTag = tradecell.SplitTag;
  1765. entity.CurState = "未完成";
  1766. entity.Create();
  1767. }
  1768. public void get_erp_offlinelist()
  1769. {
  1770. DataStruct dStruct = GetPostStruct();
  1771. List<string> lw = new List<string>();
  1772. string tid = GetPostString("ctid");
  1773. string date1 = GetPostString("date1");
  1774. string date2 = GetPostString("date2");
  1775. if (tid.Length > 0 || date1.Length > 0)
  1776. {
  1777. lw.Add(string.Format("ctid like '%{0}%'", tid));
  1778. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1779. if (dw.Length > 0) lw.Add(dw);
  1780. }
  1781. else
  1782. {
  1783. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  1784. }
  1785. string shopname = GetPostString("shopname");
  1786. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1787. string buyernick = GetPostString("buyer_nick");
  1788. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1789. string customer = GetPostString("customer");
  1790. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  1791. string design = GetPostString("design");
  1792. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  1793. string orderState = GetPostString("orderState");
  1794. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  1795. string address = GetPostString("address");
  1796. 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));
  1797. string sellermemo = GetPostString("seller_memo");
  1798. if (sellermemo.Length > 0)
  1799. {
  1800. lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1801. }
  1802. string price1 = GetPostString("price1");
  1803. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1804. string price2 = GetPostString("price2");
  1805. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1806. //if (PKey != "admin")
  1807. //{
  1808. // string usershop = CurrentUser.User.pemShop;
  1809. // lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  1810. //}
  1811. //if (ex_psize > 0)
  1812. //{
  1813. dStruct.Order = "pay_time desc";
  1814. //}
  1815. //else
  1816. // dStruct.Order = "isRefund desc,IsUrgency desc,pay_time desc";
  1817. lw.Add(string.Format("IsOffLineOrder=1"));
  1818. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1819. DataTable dt = null;
  1820. dt = WebCache.GetData("view_erptradecell", dStruct);
  1821. writeGridDataTableJson(dStruct.TotalCount, dt);
  1822. }
  1823. public void get_erp_returncashrecord()
  1824. {
  1825. DataStruct dStruct = GetPostStruct();
  1826. List<string> lw = new List<string>();
  1827. string tid = GetPostString("ctid");
  1828. if (tid.Length > 0)
  1829. {
  1830. lw.Add(string.Format("tid like '%{0}%'", tid));
  1831. dStruct.Order = "id desc";
  1832. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1833. DataTable dt = WebCache.GetData("view_erpreturncash", dStruct);
  1834. //writeGridDataTableJson(dStruct.TotalCount, dt);
  1835. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  1836. return;
  1837. }
  1838. returnErrorMsg("id数据错误!");
  1839. }
  1840. public void ins_erp_returncashrecord()
  1841. {
  1842. if (UrlPostParmsCheck("tid"))
  1843. {
  1844. string tid = GetPostString("tid");
  1845. string retype = GetPostString("type");
  1846. StringBuilder sql = new StringBuilder();
  1847. sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
  1848. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  1849. if (dt.Rows.Count > 0)
  1850. {
  1851. returnErrorMsg("相同返现类型记录已存在");
  1852. return;
  1853. }
  1854. CeErpReturnCash entity = new CeErpReturnCash();
  1855. entity.tid = tid;
  1856. entity.seller_nick = GetPostString("seller_nick");
  1857. string pment = GetPostString("payment");
  1858. if (pment.Length > 0)
  1859. {
  1860. entity.payment = Convert.ToDouble(pment);
  1861. }
  1862. entity.buyer_nick = GetPostString("buyer_nick");
  1863. entity.cashstate = 0;
  1864. entity.rtype = retype;
  1865. string rPrice = GetPostString("returnprice");
  1866. if (rPrice.Length > 0)
  1867. {
  1868. entity.returnprice = Convert.ToDouble(rPrice);
  1869. }
  1870. entity.created = DateTime.Now;
  1871. entity.con = GetPostString("con");
  1872. entity.img = GetPostString("img");
  1873. entity.applyuserid = CurrentUser.UserID;
  1874. entity.Create();
  1875. LogHelper.addLog(entity.tid, CurrentUser.UserID, "添加:" + entity.rtype);
  1876. returnSuccessMsg("操作成功!");
  1877. return;
  1878. }
  1879. }
  1880. public void set_erp_predelivery()
  1881. {
  1882. if (UrlPostParmsCheck("ctid"))
  1883. {
  1884. string eid = GetPostString("ctid");
  1885. CeErpTradeCell entity = null;
  1886. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1887. if (entity != null)
  1888. {
  1889. //CeErpTrade mainTd = CeErpTrade.Get(entity.tid);
  1890. //if (mainTd != null && mainTd.status== "WAIT_BUYER_CONFIRM_GOODS")
  1891. //{
  1892. // returnErrorMsg("此单淘宝状态为已发货,无需重复发货");
  1893. // return;
  1894. //}
  1895. entity.IsPreDelivery = 1;
  1896. entity.Update();
  1897. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1898. returnSuccessMsg("预发货成功!");
  1899. return;
  1900. //string shop = GetPostString("seller_nick");
  1901. ////string sessionkey = taobaoHelper.ShopKeyDics[shop];
  1902. //string comName = GetPostString("comName");
  1903. //string comCode = GetPostString("comCode");
  1904. //string outSid = GetPostString("outSid");//运单号
  1905. //string deliveryType = GetPostString("deliveryType");//发货类型 物流 还是虚拟
  1906. //string deliveryMemo = GetPostString("deliveryMemo"); //发货备注
  1907. ////string res = taobaoHelper.LogisticsOnlineSend(sessionkey, entity.tid, comCode, outSid);
  1908. //string apires = "";
  1909. //if (deliveryType == "虚拟发货")
  1910. //{
  1911. // apires = apiHelper.API_LogisticsDummySend(entity.tid, mainTd.posCode);
  1912. //}
  1913. //else
  1914. //{
  1915. // apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainTd.posCode, comCode, outSid);
  1916. //}
  1917. ////if (res.IndexOf("is_success") != -1 && res.IndexOf("true") != -1)
  1918. ////{
  1919. //if (apires.IndexOf("发货成功") != -1)
  1920. //{
  1921. // if (deliveryType != "虚拟发货")
  1922. // {
  1923. // //还要插入快递信息到 快递信息表
  1924. // CeErpExpressInfo exinfo = new CeErpExpressInfo();
  1925. // exinfo.tid = eid;
  1926. // exinfo.out_sid = outSid;
  1927. // exinfo.company_code = comCode;
  1928. // exinfo.company_name = comName;
  1929. // exinfo.delivery_memo = deliveryMemo;
  1930. // exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  1931. // exinfo.deliveryType = deliveryType;
  1932. // exinfo.Create();
  1933. // }
  1934. // returnSuccessMsg("发货成功!");
  1935. // LogHelper.addLog(entity.ctid, CurrentUser.UserID, "预发货", entity.OrderState);
  1936. //}
  1937. //else
  1938. //{
  1939. // returnErrorMsg("淘宝发货失败!!");
  1940. //}
  1941. //return;
  1942. }
  1943. returnErrorMsg("找不到订单记录");
  1944. }
  1945. }
  1946. public void get_erp_unusuallist()
  1947. {
  1948. DataStruct dStruct = GetPostStruct();
  1949. List<string> lw = new List<string>();
  1950. string tid = GetPostString("ctid");
  1951. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  1952. string shopname = GetPostString("shopname");
  1953. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  1954. string buyernick = GetPostString("buyer_nick");
  1955. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  1956. string ResponsibleMan = GetPostString("responsible");
  1957. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  1958. string date1 = GetPostString("date1");
  1959. string date2 = GetPostString("date2");
  1960. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  1961. if (dw.Length > 0) lw.Add(dw);
  1962. string price1 = GetPostString("price1");
  1963. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  1964. string price2 = GetPostString("price2");
  1965. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  1966. string orderState = GetPostString("orderState");
  1967. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  1968. string sellermemo = GetPostString("seller_memo");
  1969. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  1970. lw.Add(string.Format("UnusualTag > 0"));
  1971. lw.Add(string.Format("IsRefund<={0}", 1));
  1972. dStruct.Order = "pay_time desc";
  1973. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1974. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  1975. writeGridDataTableJson(dStruct.TotalCount, dt);
  1976. }
  1977. public void set_erp_unusualtonomal()
  1978. {
  1979. if (UrlPostParmsCheck("ctid"))
  1980. {
  1981. string eid = GetPostString("ctid");
  1982. CeErpTradeCell entity = null;
  1983. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  1984. if (entity != null)
  1985. {
  1986. entity.UnusualTag = -1;
  1987. entity.Update();
  1988. returnSuccessMsg("忽略成功!");
  1989. return;
  1990. }
  1991. returnErrorMsg("找不到记录");
  1992. }
  1993. }
  1994. public void ins_erp_unusualreason()
  1995. {
  1996. if (UrlPostParmsCheck("ctid"))
  1997. {
  1998. string eid = GetPostString("ctid");
  1999. CeErpTradeCell entity = null;
  2000. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2001. if (entity != null)
  2002. {
  2003. entity.MemoOpt = 4;
  2004. entity.UnusualCon = GetPostString("con");
  2005. entity.Update();
  2006. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  2007. if (trade != null)
  2008. {
  2009. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  2010. }
  2011. //查货是否超时
  2012. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  2013. if (ceErpTradeCellExtend == null)
  2014. {
  2015. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  2016. ceErpTradeCellExtend.ctid = entity.ctid;
  2017. }
  2018. if (ceErpTradeCellExtend.CheckTime == null && DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.CheckOrderTime) >= 0)
  2019. {
  2020. ceErpTradeCellExtend.CheckOut += 1;
  2021. }
  2022. ceErpTradeCellExtend.CheckTime = DateTime.Now;
  2023. if (ceErpTradeCellExtend.ID > 0)
  2024. {
  2025. ceErpTradeCellExtend.Update();
  2026. }
  2027. else
  2028. {
  2029. ceErpTradeCellExtend.Create();
  2030. }
  2031. CeErpTradeLog.AddLog(eid, 6, CurrentUser.UserID, "异常解释:" + entity.UnusualCon);
  2032. returnSuccessMsg("操作成功!");
  2033. return;
  2034. }
  2035. returnErrorMsg("找不到记录");
  2036. }
  2037. }
  2038. public void upd_erp_sampleorder()
  2039. {
  2040. if (UrlPostParmsCheck("ctid"))
  2041. {
  2042. string eid = GetPostString("ctid");
  2043. string[] eArr = eid.Split(',');
  2044. if (eArr.Length > 1)
  2045. {
  2046. List<string> eLst = new List<string>();
  2047. for (int i = 0; i < eArr.Length; i++)
  2048. {
  2049. eLst.Add("'" + eArr[i] + "'");
  2050. }
  2051. eid = string.Join(",", eLst.ToArray());
  2052. }
  2053. else
  2054. {
  2055. eid = "'" + eid + "'";
  2056. }
  2057. StringBuilder sql = new StringBuilder();
  2058. sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
  2059. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2060. int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
  2061. if (dt.Rows.Count > 0)
  2062. {
  2063. string errmsg = "";
  2064. foreach (DataRow dr in dt.Rows)
  2065. {
  2066. StringBuilder sqlsb = new StringBuilder();
  2067. sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
  2068. sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), CurrentUser.UserID);
  2069. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  2070. //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
  2071. string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
  2072. if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
  2073. {
  2074. continue;
  2075. }
  2076. else
  2077. {
  2078. string emsg = commonHelper.KeepChinese(apires);
  2079. errmsg += emsg;
  2080. }
  2081. }
  2082. if (errmsg.Length > 0)
  2083. {
  2084. returnErrorMsg(errmsg);
  2085. return;
  2086. }
  2087. returnSuccessMsg("操作成功");
  2088. return;
  2089. }
  2090. returnErrorMsg("找不到记录");
  2091. }
  2092. }
  2093. public void upd_erp_transcustomer()
  2094. {
  2095. if (UrlPostParmsCheck("ctid"))
  2096. {
  2097. string eid = GetPostString("ctid");
  2098. int userid = GetPostInt("CustomerUserId");
  2099. CeErpTradeCell entity = null;
  2100. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2101. if (entity != null)
  2102. {
  2103. //string[] mlist = entity.seller_memo.Split('-');
  2104. //string sql = "select * from view_erpuser where id=" + userid;
  2105. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2106. //if (dt != null && dt.Rows.Count > 0)
  2107. //{
  2108. // string nmemo = "";
  2109. // for(int i = 0; i < mlist.Length - 1; i++)
  2110. // {
  2111. // nmemo += mlist[i];
  2112. // nmemo += "-";
  2113. // }
  2114. // nmemo+= dt.Rows[0]["Tb"].ToString();
  2115. // entity.seller_memo = nmemo;
  2116. //}
  2117. entity.CustomerUserId = userid;
  2118. entity.Update();
  2119. returnSuccessMsg("操作成功!");
  2120. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他客服" + userid, entity.OrderState);
  2121. return;
  2122. }
  2123. returnErrorMsg("找不到记录");
  2124. }
  2125. }
  2126. public void upd_erp_transdesigner()
  2127. {
  2128. if (UrlPostParmsCheck("ctid"))
  2129. {
  2130. string eids = GetPostString("ctid");
  2131. string[] ctidList = eids.Split(',');
  2132. int userid = GetPostInt("DesignUserId");
  2133. foreach (string ctid in ctidList)
  2134. {
  2135. CeErpTradeCell entity = null;
  2136. CeErpDesignerBill entitys = null;
  2137. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2138. entitys = CeErpDesignerBill.GetByTid(ctid);
  2139. if (entity != null)
  2140. {
  2141. if (entity.OrderState > 4)
  2142. {
  2143. continue;
  2144. }
  2145. //存在退款不能流转
  2146. if (entity.IsRefund > 0)
  2147. {
  2148. continue;
  2149. }
  2150. entity.DesignUserId = userid;
  2151. entity.WaitDesignTime = DateTime.Now;
  2152. entity.Update();
  2153. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "转单给其他设计师" + userid, entity.OrderState);
  2154. }
  2155. }
  2156. returnSuccessMsg("操作成功!");
  2157. }
  2158. }
  2159. public void upd_erp_distributedesigner()
  2160. {
  2161. if (UrlPostParmsCheck("ctid"))
  2162. {
  2163. string eid = GetPostString("ctid");
  2164. int userid = GetPostInt("DesignUserId");
  2165. string[] idlist = eid.Split(',');
  2166. if (idlist.Length <= 0)
  2167. {
  2168. returnErrorMsg("订单不能为空");
  2169. return;
  2170. }
  2171. foreach (string ctid in idlist)
  2172. {
  2173. CeErpTradeCell entity = null;
  2174. CeErpDesignerBill entitys = null;
  2175. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  2176. else continue;
  2177. if (entity != null)
  2178. {
  2179. if (userid == 2125 || userid == 3542)
  2180. { }
  2181. if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.ShopId != 96 && entity.isAfterSaleOrder != 1) //公司自用可以为0
  2182. {
  2183. returnErrorMsg("金额错误的订单无法指派");
  2184. return;
  2185. }
  2186. if (entity.OrderState >= 5)
  2187. {
  2188. returnErrorMsg("已经设计完成无法指派");
  2189. return;
  2190. }
  2191. if (entity.OrderState == -1)
  2192. {
  2193. returnErrorMsg("审核中的订单无法指派");
  2194. return;
  2195. }
  2196. if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
  2197. {
  2198. returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
  2199. return;
  2200. }
  2201. //157赖橙帆 159林晨 73 静之颖
  2202. 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)
  2203. {
  2204. returnErrorMsg("指派设计共创无法再次指派!");
  2205. return;
  2206. }
  2207. entity.OrderState = 3;
  2208. if (entity.SupplierId == 0)
  2209. {
  2210. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2211. entity.SupplierId = suid;
  2212. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2213. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2214. }
  2215. if (userid == 2125 && entity.seller_memo != "")
  2216. {
  2217. apiDesign.API_GetPrintData_CreateOrder(entity);
  2218. }
  2219. if (userid == 3542 && entity.seller_memo != "")
  2220. {
  2221. string userPost = CurrentUser.UserPost.Post.Code;
  2222. if (CurrentUser.UserID == 73)
  2223. {
  2224. userPost = "SysAdmin";
  2225. }
  2226. designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, userPost);
  2227. LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
  2228. if (response.msg != "设计共创:成功")
  2229. {
  2230. returnErrorMsg(response.msg);
  2231. return;
  2232. }
  2233. entity.DispatchSort = 2;
  2234. }
  2235. else
  2236. {
  2237. if (entity.DispatchSort == 2)
  2238. {
  2239. ApiVo apiVo = new ApiVo();
  2240. apiVo.actionName = "closeDesign";
  2241. apiVo.orderNumber = entity.ctid;
  2242. designHelper.API_WorkCore(apiVo);//closeDesign
  2243. }
  2244. entity.DispatchSort = 0;
  2245. }
  2246. entity.DesignUserId = userid;
  2247. entity.WaitDesignTime = DateTime.Now;
  2248. entity.UpdateTime = DateTime.Now;
  2249. entity.Update();
  2250. string name = commonHelper.getUserNameById(userid);
  2251. commonHelper.UpdateRelationOrder(entity.ctid);
  2252. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派设计师" + name + userid, entity.OrderState);
  2253. }
  2254. }
  2255. returnSuccessMsg("操作成功!");
  2256. return;
  2257. }
  2258. }
  2259. public string getTidByCtid(string ctid)
  2260. {
  2261. string tid = "";
  2262. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2263. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2264. if (dataTable != null && dataTable.Rows.Count > 0)
  2265. {
  2266. tid = dataTable.Rows[0]["tid"].ToString();
  2267. }
  2268. return tid;
  2269. }
  2270. public List<string> getTidByCtidLike(string ctid)
  2271. {
  2272. string sql = string.Format("select tid from CE_ErpTradeCell where (ctid='{0}' or tid='{0}' or orderSn='{0}')", ctid);
  2273. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2274. List<string> list = new List<string>();
  2275. if (dataTable != null && dataTable.Rows.Count > 0)
  2276. {
  2277. foreach (DataRow item in dataTable.Rows)
  2278. {
  2279. list.Add("'" + item["tid"].ToString() + "'");
  2280. }
  2281. }
  2282. return list;
  2283. }
  2284. public List<string> getReceiverIdByCtidLike(List<string> tids)
  2285. {
  2286. string sql = string.Format("select receiverId from CE_ErpTrade where tid in ({0})", string.Join(",", tids));
  2287. DataTable dataTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2288. List<string> list = new List<string>();
  2289. if (dataTable != null && dataTable.Rows.Count > 0)
  2290. {
  2291. foreach (DataRow item in dataTable.Rows)
  2292. {
  2293. if (string.IsNullOrEmpty(item["receiverId"].ToString()))
  2294. {
  2295. continue;
  2296. }
  2297. list.Add("'" + item["receiverId"].ToString() + "'");
  2298. }
  2299. }
  2300. return list;
  2301. }
  2302. public void get_erp_myorderlist()
  2303. {
  2304. DataStruct dStruct = GetPostStruct();
  2305. List<string> lw = new List<string>();
  2306. string tid = GetPostString("ctid");
  2307. if (tid.Length > 0)
  2308. {
  2309. string select_tid = getTidByCtid(tid);
  2310. lw.Add(string.Format("tid='{0}'", select_tid));
  2311. }
  2312. else
  2313. {
  2314. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2315. }
  2316. //12-1 修改
  2317. string urgent = GetPostString("urgent");
  2318. string back = GetPostString("back");
  2319. string offlineSearch = GetPostString("offlineSearch");
  2320. if (!string.IsNullOrWhiteSpace(urgent))
  2321. {
  2322. if (urgent.Equals("true"))
  2323. {
  2324. lw.Add(string.Format("(IsUrgency='{0}' )", 1));
  2325. }
  2326. }
  2327. if (!string.IsNullOrWhiteSpace(back))
  2328. {
  2329. if (back.Equals("true"))
  2330. {
  2331. lw.Add(string.Format("(IsReturn='{0}' )", 1));
  2332. }
  2333. }
  2334. if (!string.IsNullOrWhiteSpace(offlineSearch))
  2335. {
  2336. if (offlineSearch.Equals("true"))
  2337. {
  2338. lw.Add(string.Format("(ctid like '{0}%')", "N"));
  2339. }
  2340. }
  2341. //end
  2342. string shopname = GetPostString("shopname");
  2343. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2344. string buyernick = GetPostString("buyer_nick");
  2345. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2346. string design = GetPostString("design");
  2347. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2348. string orderState = GetPostString("orderState");
  2349. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2350. string sellermemo = GetPostString("seller_memo");
  2351. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2352. string date1 = GetPostString("date1");
  2353. string date2 = GetPostString("date2");
  2354. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2355. if (dw.Length > 0) lw.Add(dw);
  2356. string price1 = GetPostString("price1");
  2357. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2358. string price2 = GetPostString("price2");
  2359. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2360. string urgency = GetPostString("urgency");
  2361. if (urgency.Length > 0) lw.Add(string.Format("IsUrgency = {0}", 1));
  2362. string after = GetPostString("after");
  2363. if (after.Length > 0) lw.Add(string.Format("AfterSaleState > {0}", 0));
  2364. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2365. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2366. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2367. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2368. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2369. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2370. if (dt != null && dt.Rows.Count > 0)
  2371. {
  2372. foreach (DataRow dr in dt.Rows)
  2373. {
  2374. try
  2375. {
  2376. // 对象操作
  2377. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2378. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2379. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2380. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2381. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2382. if (dStruct.PageSize != 100000)
  2383. {
  2384. if (dr["DispatchSort"].ToString() == "2")
  2385. {
  2386. dr["gongchuang"] = 200;
  2387. }
  2388. else if ("外协".Equals(dr["ToType"].ToString()))
  2389. {
  2390. dr["gongchuang"] = 200;
  2391. }
  2392. else if ("内部".Equals(dr["ToType"].ToString()))
  2393. {
  2394. dr["gongchuang"] = -1;
  2395. }
  2396. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2397. {
  2398. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2399. dr["gongchuang"] = response.code;
  2400. }
  2401. }
  2402. }
  2403. catch (NullReferenceException ex)
  2404. {
  2405. }
  2406. }
  2407. }
  2408. writeGridDataTableJson(dStruct.TotalCount, dt);
  2409. }
  2410. public void get_erp_myreturnorderlist()
  2411. {
  2412. DataStruct dStruct = GetPostStruct();
  2413. List<string> lw = new List<string>();
  2414. string tid = GetPostString("ctid");
  2415. if (tid.Length > 0)
  2416. {
  2417. string select_tid = getTidByCtid(tid);
  2418. lw.Add(string.Format("tid='{0}'", select_tid));
  2419. }
  2420. else
  2421. {
  2422. lw.Add(string.Format("datediff(d,pay_time,getdate())<=91 "));
  2423. }
  2424. string shopname = GetPostString("shopname");
  2425. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2426. string buyernick = GetPostString("buyer_nick");
  2427. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2428. string design = GetPostString("design");
  2429. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2430. string orderState = GetPostString("orderState");
  2431. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  2432. string sellermemo = GetPostString("seller_memo");
  2433. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2434. string date1 = GetPostString("date1");
  2435. string date2 = GetPostString("date2");
  2436. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2437. if (dw.Length > 0) lw.Add(dw);
  2438. string price1 = GetPostString("price1");
  2439. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2440. string price2 = GetPostString("price2");
  2441. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2442. if (CurrentUser.UserPost.Post.Code == "Director" || CurrentUser.UserPost.Post.Code == "CustomerMr")
  2443. {
  2444. lw.Add(string.Format("ShopId in ({0})", CurrentUser.User.pemShop));
  2445. }
  2446. else
  2447. {
  2448. lw.Add(string.Format("CustomerUserId = {0}", CurrentUser.UserID));
  2449. }
  2450. lw.Add(string.Format(" IsReturn>0 and OrderState=0"));
  2451. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2452. dStruct.Order = "IsReturn desc,isRefund desc,IsUrgency desc, pay_time desc";
  2453. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2454. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2455. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2456. if (dt != null && dt.Rows.Count > 0)
  2457. {
  2458. foreach (DataRow dr in dt.Rows)
  2459. {
  2460. try
  2461. {
  2462. // 对象操作
  2463. if (dStruct.PageSize != 100000)
  2464. {
  2465. if (dr["DispatchSort"].ToString() == "2")
  2466. {
  2467. dr["gongchuang"] = 200;
  2468. }
  2469. else if ("外协".Equals(dr["ToType"].ToString()))
  2470. {
  2471. dr["gongchuang"] = 200;
  2472. }
  2473. else if ("内部".Equals(dr["ToType"].ToString()))
  2474. {
  2475. dr["gongchuang"] = -1;
  2476. }
  2477. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(dr["seller_memo"].ToString()))
  2478. {
  2479. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2480. dr["gongchuang"] = response.code;
  2481. }
  2482. }
  2483. }
  2484. catch (NullReferenceException ex)
  2485. {
  2486. // 处理空引用异常
  2487. }
  2488. }
  2489. }
  2490. writeGridDataTableJson(dStruct.TotalCount, dt);
  2491. }
  2492. public void get_erp_myorderlist_pregather()
  2493. {
  2494. string date1 = GetPostString("date1");
  2495. string date2 = GetPostString("date2");
  2496. int userId = CurrentUser.UserID; //客服id
  2497. string orderWhere = "";
  2498. List<string> lw = new List<string>();
  2499. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2500. if (dw.Length > 0) lw.Add(dw);
  2501. lw.Add(string.Format("CustomerUserId={0}", userId));
  2502. lw.Add(string.Format("OrderState<9"));
  2503. orderWhere = string.Join(" and ", lw.ToArray());
  2504. string orderWhere2 = "";
  2505. List<string> lw2 = new List<string>();
  2506. string dw2 = GetDateMinuteWhere("pay_time", date1, date2);
  2507. if (dw2.Length > 0) lw2.Add(dw2);
  2508. lw2.Add(string.Format("CustomerUserId={0}", userId));
  2509. orderWhere2 = string.Join(" and ", lw2.ToArray());
  2510. string sql = string.Format("select *" +
  2511. "from(select CustomerUserId, sum(payment) as Amount, count(ctid) as Count from View_ErpTradeCell where " + orderWhere + " group by CustomerUserId) a " +
  2512. "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 " +
  2513. "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 " +
  2514. "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");
  2515. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  2516. //writeGridDataTableJson(dt.Rows.Count, dt);
  2517. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2518. }
  2519. public void upd_erp_publishorder()
  2520. {
  2521. if (UrlPostParmsCheck("ctid"))
  2522. {
  2523. string eid = GetPostString("ctid");
  2524. CeErpTradeCell entity = null;
  2525. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2526. if (entity != null)
  2527. {
  2528. entity.OrderState = 0; //发布后,变为待抢单
  2529. entity.Update();
  2530. commonHelper.UpdateRelationOrder(entity.ctid);
  2531. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发布订单", entity.OrderState);
  2532. returnSuccessMsg("发布成功!");
  2533. return;
  2534. }
  2535. returnErrorMsg("找不到记录");
  2536. }
  2537. }
  2538. public void get_erp_my_tiporder()
  2539. {
  2540. StringBuilder sql = new StringBuilder();
  2541. int userId = 0;
  2542. if (CurrentUser != null) userId = CurrentUser.UserID;
  2543. string posCode = CurrentUser.UserPost.Post.Code;
  2544. string isTipedAfterSaleVerify = GetPostString("af");
  2545. DataTable dt = new DataTable();
  2546. if (posCode != "Supplier")
  2547. {
  2548. if (posCode == "CustomerService" || posCode == "Director")
  2549. {
  2550. sql.AppendFormat("select * from ce_erptradecell where CustomerUserId={0} and OrderState=0 and IsReadTag>0 ", userId);
  2551. }
  2552. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  2553. {
  2554. sql.AppendFormat("select * from ce_erptradecell where AfterSaleUserId={0} and IsReadTag>0 ", userId);
  2555. }
  2556. else
  2557. {
  2558. string teamIds = CurrentUser.User.TeamIds;
  2559. if (teamIds == "")
  2560. {
  2561. teamIds = "0";
  2562. }
  2563. 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);
  2564. }
  2565. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2566. }
  2567. if (dt.Rows.Count <= 0)
  2568. {
  2569. string key = "aftersale_order_" + userId;
  2570. if (RedisHelper.HasKey(key))
  2571. {
  2572. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2573. dt.Columns.Add("ctid", typeof(string));
  2574. dt.Columns.Add("IsReadTag", typeof(int));
  2575. foreach (var i in list)
  2576. {
  2577. DataRow data = dt.NewRow();
  2578. data["ctid"] = i;
  2579. data["IsReadTag"] = 4;
  2580. dt.Rows.Add(data);
  2581. }
  2582. RedisHelper.StringDelete(key);
  2583. }
  2584. }
  2585. if (dt.Rows.Count <= 0)
  2586. {
  2587. sql = new StringBuilder();
  2588. sql.AppendFormat("select * from CE_ErpTradeResponsible where UserId={0} and VerifyState=3 and type = 0 ", userId);
  2589. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2590. }
  2591. if (posCode == "Supplier")
  2592. {
  2593. string ids = CurrentUser.User.pemVend;
  2594. if (ids != null && ids.Length > 0)
  2595. {
  2596. string[] ids_list = ids.Split(',');
  2597. foreach (var item in ids_list)
  2598. {
  2599. string key = "return_order_" + item;
  2600. if (RedisHelper.HasKey(key))
  2601. {
  2602. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  2603. dt.Columns.Add("ctid", typeof(string));
  2604. dt.Columns.Add("IsReadTag", typeof(int));
  2605. foreach (var i in list)
  2606. {
  2607. DataRow data = dt.NewRow();
  2608. data["ctid"] = i;
  2609. data["IsReadTag"] = 1;
  2610. dt.Rows.Add(data);
  2611. }
  2612. RedisHelper.StringDelete(key);
  2613. }
  2614. }
  2615. }
  2616. if (dt.Rows.Count <= 0)
  2617. {
  2618. sql = new StringBuilder();
  2619. 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);
  2620. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  2621. }
  2622. }
  2623. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  2624. }
  2625. public void reset_erp_tiporder()
  2626. {
  2627. string ids = GetPostString("ids");
  2628. string[] ctidList = ids.Split(',');
  2629. foreach (string ctid in ctidList)
  2630. {
  2631. CeErpTradeCell enty = CeErpTradeCell.GetByCtid(ctid);
  2632. if (enty != null)
  2633. {
  2634. enty.IsReadTag = 0;
  2635. enty.Update();
  2636. }
  2637. }
  2638. returnSuccessMsg("成功!");
  2639. return;
  2640. }
  2641. public void get_erp_designlist()
  2642. {
  2643. DataStruct dStruct = GetPostStruct();
  2644. List<string> lw = new List<string>();
  2645. string tid = GetPostString("ctid");
  2646. if (tid.Length > 0)
  2647. {
  2648. string select_tid = getTidByCtid(tid);
  2649. lw.Add(string.Format("tid='{0}'", select_tid));
  2650. }
  2651. string shopname = GetPostString("shopname");
  2652. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  2653. string buyernick = GetPostString("buyer_nick");
  2654. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  2655. string customer = GetPostString("customer");
  2656. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2657. string design = GetPostString("design");
  2658. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  2659. string orderState = GetPostString("orderState");
  2660. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2661. lw.Add(string.Format("OrderState<6"));
  2662. string address = GetPostString("address");
  2663. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  2664. string sellermemo = GetPostString("seller_memo");
  2665. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2666. string date1 = GetPostString("date1");
  2667. string date2 = GetPostString("date2");
  2668. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  2669. if (dw.Length > 0) lw.Add(dw);
  2670. string apdate1 = GetPostString("apdate1");
  2671. string apdate2 = GetPostString("apdate2");
  2672. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2673. if (dwap.Length > 0) lw.Add(dwap);
  2674. string price1 = GetPostString("price1");
  2675. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2676. string price2 = GetPostString("price2");
  2677. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2678. string designTime = GetPostString("designtime");
  2679. if (designTime.Length > 0)
  2680. {
  2681. lw.Add(string.Format("FinishDesignTime > '{0}' or FinishDesignTime = ''", designTime));
  2682. }
  2683. string usershop = CurrentUser.User.pemShop;
  2684. if (usershop.Length > 0)
  2685. {
  2686. lw.Add(string.Format("shopId in ({0})", usershop));
  2687. }
  2688. int myOrgid = CurrentUser.UserPost.OrgID;
  2689. string myOrgCode = CurrentUser.UserPost.Post.Code;
  2690. if (myOrgCode.IndexOf("Designer") != -1)
  2691. {
  2692. if (CurrentUser.User.ManageOrgIds.Length > 0)
  2693. {
  2694. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  2695. }
  2696. else
  2697. {
  2698. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  2699. }
  2700. }
  2701. else
  2702. {
  2703. string orgId = GetPostString("designerhd");
  2704. if (orgId.Length > 0) lw.Add(string.Format("DesOrgID = '{0}'", orgId));
  2705. }
  2706. if (tid.Length > 0 || buyernick.Length > 0)
  2707. {
  2708. lw.Add(string.Format("OrderState >= 3"));
  2709. }
  2710. else
  2711. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2712. if (tid.Length <= 0) lw.Add(string.Format("IsRefund<={0}", 1));
  2713. dStruct.Order = "IsReturn desc,MemoOpt desc, pay_time desc";
  2714. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2715. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2716. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2717. if (dt != null && dt.Rows.Count > 0)
  2718. {
  2719. foreach (DataRow dr in dt.Rows)
  2720. {
  2721. try
  2722. {
  2723. // 对象操作
  2724. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2725. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2726. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2727. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2728. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2729. if (dStruct.PageSize != 100000)
  2730. {
  2731. if (dr["DispatchSort"].ToString() == "2")
  2732. {
  2733. dr["gongchuang"] = 200;
  2734. }
  2735. else if ("外协".Equals(dr["ToType"].ToString()))
  2736. {
  2737. dr["gongchuang"] = 200;
  2738. }
  2739. else if ("内部".Equals(dr["ToType"].ToString()))
  2740. {
  2741. dr["gongchuang"] = -1;
  2742. }
  2743. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2744. {
  2745. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2746. dr["gongchuang"] = response.code;
  2747. }
  2748. }
  2749. }
  2750. catch (NullReferenceException ex)
  2751. {
  2752. }
  2753. }
  2754. }
  2755. writeGridDataTableJson(dStruct.TotalCount, dt);
  2756. }
  2757. public void get_erp_mydesignlist()
  2758. {
  2759. DataStruct dStruct = GetPostStruct();
  2760. List<string> lw = new List<string>();
  2761. string tid = GetPostString("ctid");
  2762. if (tid.Length > 0)
  2763. {
  2764. string select_tid = getTidByCtid(tid);
  2765. lw.Add(string.Format("tid='{0}'", select_tid));
  2766. }
  2767. string shopname = GetPostString("shopname");
  2768. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  2769. string buyernick = GetPostString("buyer_nick");
  2770. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  2771. string customer = GetPostString("customer");
  2772. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  2773. string orderState = GetPostString("orderState");
  2774. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", orderState));
  2775. //lw.Add(string.Format("OrderState<6"));
  2776. string date1 = GetPostString("date1");
  2777. string date2 = GetPostString("date2");
  2778. string dw = GetDateWhere("pay_time", date1, date2);
  2779. if (dw.Length > 0) lw.Add(dw);
  2780. string apdate1 = GetPostString("apdate1");
  2781. string apdate2 = GetPostString("apdate2");
  2782. string dwap = GetDateMinuteWhere("WaitDesignTime", apdate1, apdate2);
  2783. if (dwap.Length > 0) lw.Add(dwap);
  2784. string price1 = GetPostString("price1");
  2785. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  2786. string price2 = GetPostString("price2");
  2787. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  2788. string olddownload = GetPostString("olddown");
  2789. if (olddownload == "1")
  2790. {
  2791. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')>=0", "2021-08-01 00:00:00"));
  2792. }
  2793. else if (olddownload == "2")
  2794. {
  2795. lw.Add(string.Format("datediff(d, OldCustomerTime,'{0}')<0", "2021-08-01 00:00:00"));
  2796. }
  2797. string sellermemo = GetPostString("seller_memo");
  2798. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  2799. lw.Add(string.Format("OrderState >= 3 and OrderState <= 5"));
  2800. if (CurrentUser.UserPost.Post.Code != "SysAdmin")
  2801. {
  2802. if (CurrentUser.User.TeamIds.Length > 0)
  2803. {
  2804. if (CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr")
  2805. lw.Add(string.Format("(DesignUserId = {0} or DesignUserId in ({1}) )", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2806. else
  2807. lw.Add(string.Format("(DesignUserId = {0} or ((IsReturn>0 or MemoOpt>0) and DesignUserId in ({1})))", CurrentUser.UserID, CurrentUser.User.TeamIds));
  2808. }
  2809. else
  2810. {
  2811. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  2812. }
  2813. }
  2814. if (tid.Length <= 0)
  2815. {
  2816. lw.Add(string.Format("IsRefund<={0} and datediff(d,WaitDesignTime,getdate())<=92", 1));
  2817. }
  2818. lw.Add(string.Format("IsReturn!=3"));
  2819. dStruct.Order = "IsReturn desc,OrderState asc,MemoOpt desc,pay_time desc";
  2820. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  2821. string teamids = CurrentUser.User.TeamIds.ToString();
  2822. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  2823. dt.Columns.Add(new DataColumn("gongchuang", typeof(string)));
  2824. if (dt != null && dt.Rows.Count > 0)
  2825. {
  2826. foreach (DataRow dr in dt.Rows)
  2827. {
  2828. try
  2829. {
  2830. // 对象操作
  2831. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  2832. ceErpTradeCell.ctid = dr["ctid"].ToString();
  2833. ceErpTradeCell.seller_memo = dr["seller_memo"].ToString();
  2834. ceErpTradeCell.ShopId = Convert.ToInt32(dr["ShopId"]);
  2835. ceErpTradeCell.ProductId = Convert.ToInt32(dr["ProductId"]);
  2836. if (dStruct.PageSize != 100000)
  2837. {
  2838. if (dr["DispatchSort"].ToString() == "2")
  2839. {
  2840. dr["gongchuang"] = 200;
  2841. }
  2842. else if ("外协".Equals(dr["ToType"].ToString()))
  2843. {
  2844. dr["gongchuang"] = 200;
  2845. }
  2846. else if ("内部".Equals(dr["ToType"].ToString()))
  2847. {
  2848. dr["gongchuang"] = -1;
  2849. }
  2850. else if (Convert.ToInt16(dr["OrderState"]) < 4 && !string.IsNullOrEmpty(ceErpTradeCell.seller_memo))
  2851. {
  2852. designApiResponseVo response = commonHelper.checkOrderListDesignInfo(dr["tid"].ToString(), dr["ctid"].ToString());
  2853. dr["gongchuang"] = response.code;
  2854. }
  2855. }
  2856. }
  2857. catch (NullReferenceException ex)
  2858. {
  2859. }
  2860. }
  2861. }
  2862. writeGridDataTableJson(dStruct.TotalCount, dt);
  2863. }
  2864. public void set_erp_startdesign()
  2865. {
  2866. if (UrlPostParmsCheck("ctid"))
  2867. {
  2868. string eid = GetPostString("ctid");
  2869. CeErpTradeCell entity = null;
  2870. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2871. if (entity != null)
  2872. {
  2873. if (entity.OrderState != 3)
  2874. {
  2875. returnErrorMsg("请刷新,订单已经设计了");
  2876. return;
  2877. }
  2878. entity.StartDesignTime = DateTime.Now;
  2879. entity.OrderState = 4;
  2880. if (entity.ctid.IndexOf("S_") == -1 && entity.SupplierId == 0)
  2881. {
  2882. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  2883. entity.SupplierId = suid;
  2884. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2885. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2886. }
  2887. entity.UpdateTime = DateTime.Now;
  2888. //entity.MakeSupplier = suname;
  2889. entity.Update();
  2890. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2891. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2892. commonHelper.DeleteOriginalOrderIfIsSplitOrder(entity.tid, entity.SplitTag);
  2893. commonHelper.getCytPrice(entity);
  2894. returnSuccessMsg("操作成功!");
  2895. return;
  2896. }
  2897. returnErrorMsg("找不到记录");
  2898. }
  2899. }
  2900. public void ins_erp_designselfmemo()
  2901. {
  2902. if (UrlPostParmsCheck("ctid"))
  2903. {
  2904. string eid = GetPostString("ctid");
  2905. string con = GetPostString("con");
  2906. CeErpTradeCell entity = null;
  2907. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2908. if (entity != null)
  2909. {
  2910. entity.DesignSelfMemo = con;
  2911. entity.Update();
  2912. returnSuccessMsg("操作成功!");
  2913. return;
  2914. }
  2915. returnErrorMsg("找不到记录");
  2916. }
  2917. }
  2918. public void ins_erp_designprice()
  2919. {
  2920. if (UrlPostParmsCheck("ctid"))
  2921. {
  2922. string eid = GetPostString("ctid");
  2923. int uid = CurrentUser.UserID;
  2924. string userName = CurrentUser.UserName;
  2925. CeErpTradeCell entity = null;
  2926. CeErpDesignerBill entitys = CeErpDesignerBill.GetByTid("ctid");
  2927. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  2928. if (entitys == null)
  2929. {
  2930. entitys = new CeErpDesignerBill();
  2931. }
  2932. if (entity != null)
  2933. {
  2934. entity.DesignPrice = Convert.ToDouble(GetPostString("price"));
  2935. //entity.Number = Convert.ToInt32(GetPostString("number"));
  2936. entity.StartDesignTime = DateTime.Now;
  2937. entity.OrderState = 4;
  2938. string suname = "";
  2939. if (entity.SupplierId == 0)
  2940. {
  2941. int sid = commonHelper.autoDistributeToSupplier(entity);
  2942. entity.SupplierId = sid;
  2943. suname = commonHelper.getSupplierNameById(entity.SupplierId);
  2944. }
  2945. entity.Update();
  2946. CeErpUserPost ceErpUserPost = CeErpUserPost.GetByUserID(CurrentUser.UserID);
  2947. if (ceErpUserPost != null)
  2948. {
  2949. CeErpPost ceErpPost = CeErpPost.Get(ceErpUserPost.PostID);
  2950. if (ceErpPost != null)
  2951. {
  2952. if (eid.IndexOf("S") != 0 || !ceErpPost.Name.Equals("设计师P0"))
  2953. {
  2954. entitys.tid = entity.ctid;
  2955. entitys.oid = entity.tid;
  2956. entitys.uid = uid;
  2957. entitys.userName = userName;
  2958. entitys.designerType = 1;
  2959. entitys.designerTypeText = "内部设计师";
  2960. entitys.price = Convert.ToDouble(GetPostString("price"));
  2961. entitys.designNum = GetPostInt("designNum");
  2962. entitys.modifyNum = GetPostInt("modifyNum");
  2963. entitys.designSize = GetPostString("designSize");
  2964. entitys.modifySize = GetPostString("modifySize");
  2965. if (CeErpDesignerBill.GetByTid("ctid") == null)
  2966. {
  2967. entitys.create_time = DateTime.Now;
  2968. entitys.create_u_id = uid;
  2969. entitys.create_u_name = userName;
  2970. entitys.Save();
  2971. }
  2972. else
  2973. {
  2974. entitys.update_time = DateTime.Now;
  2975. entitys.update_u_id = uid;
  2976. entitys.update_u_name = userName;
  2977. entitys.Update();
  2978. }
  2979. }
  2980. }
  2981. }
  2982. commonHelper.UpdateRelationOrder(entity.ctid); //更新补差价单
  2983. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始设计", entity.OrderState);
  2984. LogHelper.addDesignerBillLog(entity.ctid, CurrentUser.UserID, "评估设计费", CurrentUser.UserName, 0);
  2985. if (suname != "")
  2986. {
  2987. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  2988. }
  2989. commonHelper.getCytPrice(entity);
  2990. returnSuccessMsg("操作成功!");
  2991. return;
  2992. }
  2993. returnErrorMsg("找不到记录");
  2994. }
  2995. }
  2996. public void upload_erp_filecomplete()
  2997. {
  2998. if (UrlPostParmsCheck("ctid"))
  2999. {
  3000. string eid = GetPostString("ctid");
  3001. CeErpTradeCell entity = null;
  3002. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3003. if (entity != null)
  3004. {
  3005. entity.OrderState = 5; //设计完成
  3006. entity.Update();
  3007. returnSuccessMsg(eid + "上传成功,设计完成!");
  3008. return;
  3009. }
  3010. returnErrorMsg("找不到订单记录");
  3011. }
  3012. }
  3013. public void get_erp_designovertimelist()
  3014. {
  3015. DataStruct dStruct = GetPostStruct();
  3016. List<string> lw = new List<string>();
  3017. string tid = GetPostString("ctid");
  3018. if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}' or orderSn='{0}')", tid));
  3019. string shopname = GetPostString("shopname");
  3020. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  3021. string buyernick = GetPostString("buyer_nick");
  3022. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  3023. string ResponsibleMan = GetPostString("responsible");
  3024. if (ResponsibleMan.Length > 0) lw.Add(string.Format("ResponsibleMan like '%{0}%'", ResponsibleMan));
  3025. string date1 = GetPostString("date1");
  3026. string date2 = GetPostString("date2");
  3027. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3028. if (dw.Length > 0) lw.Add(dw);
  3029. string price1 = GetPostString("price1");
  3030. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3031. string price2 = GetPostString("price2");
  3032. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3033. string orderState = GetPostString("orderState");
  3034. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3035. string sellermemo = GetPostString("seller_memo");
  3036. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3037. lw.Add(string.Format("UnusualTag=3"));
  3038. lw.Add(string.Format("IsRefund<={0}", 1));
  3039. dStruct.Order = "WaitDesignTime desc";
  3040. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3041. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3042. writeGridDataTableJson(dStruct.TotalCount, dt);
  3043. }
  3044. //设计管理 获取抢单大厅列表
  3045. public void get_erp_grabinglist()
  3046. {
  3047. int maxPrice = CurrentUser.UserPost.Post.OrderAmountLimit;
  3048. DataTable org = CeErpOrganization.Get(CurrentUser.UserPost.OrgID);
  3049. bool oldOrder = false;
  3050. if (org != null)
  3051. {
  3052. oldOrder = Convert.ToBoolean(org.Rows[0]["OldOrder"]);
  3053. }
  3054. string sql = string.Format("select * from view_cell where OrderState = 2 and IsSample <> 2 and IsRefund<=0 and DesignUserId = 0");
  3055. sql += !oldOrder ? " and IsOldCustomer != 1 " : "";
  3056. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3057. Dictionary<string, Dictionary<string, int>> map = new Dictionary<string, Dictionary<string, int>>();
  3058. //先处理订单数据
  3059. if (dt.Rows.Count > 0)
  3060. {
  3061. Dictionary<string, int> design = null;
  3062. int count = 0;
  3063. foreach (DataRow row in dt.Rows)
  3064. {
  3065. if (map.ContainsKey(row["ShopId"].ToString()))
  3066. {
  3067. map.TryGetValue(row["ShopId"].ToString(), out design);
  3068. }
  3069. else
  3070. {
  3071. design = new Dictionary<string, int>();
  3072. }
  3073. if (design.ContainsKey(row["ProductId"].ToString()))
  3074. {
  3075. design.TryGetValue(row["ProductId"].ToString(), out count);
  3076. }
  3077. count++;
  3078. design[row["ProductId"].ToString()] = count;
  3079. map[row["ShopId"].ToString()] = design;
  3080. }
  3081. }
  3082. sql = string.Format("select * from Ce_ErpDesignInfo where type=1 and tarId={0}", CurrentUser.User.ID);
  3083. DataTable design_dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3084. //把店铺排序和技能排序分类
  3085. Dictionary<string, List<string>> shop_orders = new Dictionary<string, List<string>>();
  3086. Dictionary<string, Dictionary<string, string>> design_orders = new Dictionary<string, Dictionary<string, string>>();
  3087. if (design_dt.Rows.Count > 0)
  3088. {
  3089. Dictionary<string, string> design = null;
  3090. List<string> shopIds = null;
  3091. foreach (DataRow row in design_dt.Rows)
  3092. {
  3093. if ("0".Equals(row["designId"].ToString()))
  3094. {
  3095. if (shop_orders.ContainsKey(row["orders"].ToString()))
  3096. {
  3097. shop_orders.TryGetValue(row["orders"].ToString(), out shopIds);
  3098. }
  3099. else
  3100. {
  3101. shopIds = new List<string>();
  3102. }
  3103. shopIds.Add(row["shopId"].ToString());
  3104. shop_orders[row["orders"].ToString()] = shopIds;
  3105. }
  3106. else
  3107. {
  3108. if (design_orders.ContainsKey(row["shopId"].ToString()))
  3109. {
  3110. design_orders.TryGetValue(row["shopId"].ToString(), out design);
  3111. }
  3112. else
  3113. {
  3114. design = new Dictionary<string, string>();
  3115. }
  3116. design[row["orders"].ToString()] = row["designId"].ToString();
  3117. design_orders[row["shopId"].ToString()] = design;
  3118. }
  3119. }
  3120. //处理成key value后根据key排序
  3121. shop_orders = shop_orders.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3122. foreach (List<string> val in shop_orders.Values)
  3123. {
  3124. if (val != null)
  3125. {
  3126. foreach (string key in val)
  3127. {
  3128. if (design_orders.ContainsKey(key.ToString()))
  3129. {
  3130. design_orders[key] = design_orders[key].OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  3131. }
  3132. }
  3133. }
  3134. }
  3135. }
  3136. //校验哪个优先级有订单
  3137. Dictionary<string, string> designIds = new Dictionary<string, string>();
  3138. foreach (string key in shop_orders.Keys)
  3139. {
  3140. List<string> ids = null;
  3141. shop_orders.TryGetValue(key, out ids);
  3142. //id为shopid
  3143. foreach (string id in ids)
  3144. {
  3145. Dictionary<string, int> list = null;
  3146. Dictionary<string, string> desing = null;
  3147. map.TryGetValue(id, out list);
  3148. design_orders.TryGetValue(id, out desing);
  3149. if (list != null && desing != null)
  3150. {
  3151. foreach (var item in desing)
  3152. {
  3153. int count = 0;
  3154. if (list.ContainsKey(item.Value))
  3155. {
  3156. list.TryGetValue(item.Value, out count);
  3157. if (count > 0)
  3158. {
  3159. designIds[id] = item.Value;
  3160. break;
  3161. }
  3162. }
  3163. }
  3164. }
  3165. }
  3166. if (designIds.Count > 0)
  3167. {
  3168. break;
  3169. }
  3170. }
  3171. DataTable table = new DataTable();
  3172. table.Columns.Add("tid", typeof(string));
  3173. table.Columns.Add("ctid", typeof(string));
  3174. table.Columns.Add("seller_nick", typeof(string));
  3175. table.Columns.Add("productName", typeof(string));
  3176. table.Columns.Add("pay_time", typeof(string));
  3177. table.Columns.Add("seller_memo", typeof(string));
  3178. if (designIds.Count > 0)
  3179. {
  3180. string shopId = "";
  3181. string productId = "";
  3182. foreach (var designInfo in designIds)
  3183. {
  3184. shopId = designInfo.Key;
  3185. productId = designInfo.Value;
  3186. CeErpShop ceErpShop = CeErpShop.Get(shopId);
  3187. CeErpProduct ceErpProduct = CeErpProduct.Get(productId);
  3188. if (dt.Rows.Count > 0)
  3189. {
  3190. foreach (DataRow row in dt.Rows)
  3191. {
  3192. if (shopId.Equals(row["shopId"].ToString()) && productId.Equals(row["productId"].ToString()))
  3193. {
  3194. DataRow data = table.NewRow();
  3195. data["ctid"] = row["ctid"].ToString();
  3196. data["tid"] = row["tid"].ToString();
  3197. data["seller_nick"] = ceErpShop.ShopName;
  3198. data["pay_time"] = row["pay_time"].ToString();
  3199. data["seller_memo"] = row["seller_memo"].ToString();
  3200. data["productName"] = ceErpProduct.PType;
  3201. table.Rows.Add(data);
  3202. }
  3203. }
  3204. }
  3205. }
  3206. }
  3207. writeGridDataTableJson(table.Rows.Count, table);
  3208. }
  3209. private object rushLockObject = new object();
  3210. public void set_erp_grabingorder()
  3211. {
  3212. if (UrlPostParmsCheck("ctid"))
  3213. {
  3214. int total = CurrentUser.User.Person.Total;
  3215. int userId = CurrentUser.User.ID;
  3216. int noFinish = CurrentUser.User.Person.NoFinish;
  3217. int finalization = CurrentUser.User.Person.Finalization;
  3218. string eids = GetPostString("ctid");
  3219. string key = "RushKey_" + userId;
  3220. int count = 0;
  3221. if (erpRedis.RedisHelper.KeyExists(key))
  3222. {
  3223. string redisCount = erpRedis.RedisHelper.StringGet(key);
  3224. if (redisCount != null)
  3225. {
  3226. count = Convert.ToInt32(redisCount);
  3227. }
  3228. }
  3229. if (count >= total)
  3230. {
  3231. returnErrorMsg("半小时内已经抢" + total + "单");
  3232. return;
  3233. }
  3234. string[] ctidlist = eids.Split(',');
  3235. if (count + ctidlist.Length > total)
  3236. {
  3237. returnErrorMsg("选择单数超过半小时可抢数量," + "已抢:" + count + "单");
  3238. return;
  3239. }
  3240. int itag = 0;
  3241. lock (rushLockObject)
  3242. {
  3243. if (ctidlist.Length > 0)
  3244. {
  3245. string[] dtList = new string[ctidlist.Length];
  3246. for (int i = 0; i < ctidlist.Length; i++)
  3247. {
  3248. dtList[i] = "'" + ctidlist[i] + "'";
  3249. }
  3250. 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"));
  3251. DataTable dt_user = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  3252. if (dt_user.Rows.Count > 0)
  3253. {
  3254. int doing = 0;//未定稿
  3255. int finish = 0;//已完成
  3256. foreach (DataRow dr in dt_user.Rows)
  3257. {
  3258. if (Convert.ToInt32(dr["OrderState"]) == 3 || Convert.ToInt32(dr["OrderState"]) == 4)
  3259. {
  3260. doing++;
  3261. }
  3262. else
  3263. {
  3264. finish++;
  3265. }
  3266. }
  3267. if (doing >= noFinish)
  3268. {
  3269. returnErrorMsg(doing + "未定稿数量,无法继续抢单");
  3270. return;
  3271. }
  3272. if (doing + finish >= total && finalization > 0 && ((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) < finalization)
  3273. {
  3274. returnErrorMsg(((Convert.ToDecimal(finish) / Convert.ToDecimal(dt_user.Rows.Count)) * 100) + "未定稿率,无法继续抢单");
  3275. return;
  3276. }
  3277. }
  3278. //校验选择单子状态
  3279. string sql = string.Format("select ctid,OrderState from CE_ErpTradeCell where ctid in (" + string.Join(",", dtList) + ")");
  3280. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  3281. if (dt.Rows.Count > 0)
  3282. {
  3283. List<string> list = new List<string>();
  3284. foreach (DataRow dr in dt.Rows)
  3285. {
  3286. if (Convert.ToInt32(dr["OrderState"]) != 2)
  3287. {
  3288. list.Add(dr["ctid"].ToString());
  3289. }
  3290. }
  3291. if (list.Count > 0)
  3292. {
  3293. returnErrorMsg(string.Join(",", list) + "状态不可抢单,请重新选择!");
  3294. return;
  3295. }
  3296. }
  3297. foreach (string ctid in ctidlist)
  3298. {
  3299. CeErpTradeCell entity = null;
  3300. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3301. if (entity != null)
  3302. {
  3303. entity.OrderState = 3;
  3304. entity.DesignUserId = CurrentUser.UserID;
  3305. entity.WaitDesignTime = DateTime.Now;
  3306. entity.StartDesignTime = DateTime.Now;
  3307. entity.Update();
  3308. commonHelper.UpdateRelationOrder(entity.ctid);
  3309. commonHelper.UpdateSameOrderToDesigner(entity, CurrentUser.UserID);
  3310. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "抢单成功", entity.OrderState);
  3311. itag++;
  3312. }
  3313. }
  3314. }
  3315. }
  3316. count += ctidlist.Length;
  3317. erpRedis.RedisHelper.StringSet(key, count.ToString(), TimeSpan.FromMinutes(30));
  3318. if (itag == 0)
  3319. returnErrorMsg("没有找到相关订单");
  3320. else
  3321. returnSuccessMsg("抢单成功!");
  3322. return;
  3323. }
  3324. }
  3325. public void get_erp_waitorderlist()
  3326. {
  3327. DataStruct dStruct = GetPostStruct();
  3328. List<string> lw = new List<string>();
  3329. string tid = GetPostString("ctid");
  3330. if (tid.Length > 0)
  3331. {
  3332. string select_tid = getTidByCtid(tid);
  3333. lw.Add(string.Format("tid='{0}'", select_tid));
  3334. }
  3335. string shopname = GetPostString("shopname");
  3336. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3337. string buyernick = GetPostString("buyer_nick");
  3338. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3339. string customer = GetPostString("customer");
  3340. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3341. string design = GetPostString("design");
  3342. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3343. string orderState = GetPostString("orderState");
  3344. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3345. string supplier = GetPostString("supplier");
  3346. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  3347. string sellermemo = GetPostString("seller_memo");
  3348. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3349. string otherMemo = GetPostString("otherMemo");
  3350. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  3351. string address = GetPostString("address");
  3352. 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));
  3353. string date1 = GetPostString("date1");
  3354. string date2 = GetPostString("date2");
  3355. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3356. if (dw.Length > 0) lw.Add(dw);
  3357. string price1 = GetPostString("price1");
  3358. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  3359. string price2 = GetPostString("price2");
  3360. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  3361. lw.Add(string.Format("IsVerifyToSupplier=0"));//审核给供应商的不显示
  3362. lw.Add(string.Format("IsSample != 2 "));
  3363. lw.Add(string.Format("OrderState = 5 "));
  3364. lw.Add(string.Format("IsRefund<={0}", 1));
  3365. dStruct.Order = "IsReturn desc,IsUrgency desc,FinishDesignTime asc";
  3366. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3367. string pagesize = GetPostString("pagesize");
  3368. if (pagesize != null)
  3369. {
  3370. dStruct.PageSize = 200;
  3371. }
  3372. DataTable dt = WebCache.GetData("view_Waitorderlist", dStruct);
  3373. if (dt != null)
  3374. {
  3375. foreach (DataRow dr in dt.Rows)
  3376. {
  3377. 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();
  3378. if (Convert.IsDBNull(dr["SupplierId"]) || Convert.ToInt32(dr["SupplierId"]) == 0)
  3379. {
  3380. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(dr["ctid"].ToString());
  3381. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  3382. entity.SupplierId = suid;
  3383. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  3384. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  3385. entity.Update();
  3386. }
  3387. }
  3388. }
  3389. writeGridDataTableJson(dStruct.TotalCount, dt);
  3390. }
  3391. public void get_erp_supplierwaitorderlist()
  3392. {
  3393. DataStruct dStruct = GetPostStruct();
  3394. List<string> lw = new List<string>();
  3395. string tid = GetPostString("ctid");
  3396. if (tid.Length > 0)
  3397. {
  3398. string select_tid = getTidByCtid(tid);
  3399. lw.Add(string.Format("tid='{0}'", select_tid));
  3400. }
  3401. string shopname = GetPostString("shopname");
  3402. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3403. string sellermemo = GetPostString("seller_memo");
  3404. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3405. string date1 = GetPostString("date1");
  3406. string date2 = GetPostString("date2");
  3407. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  3408. if (dw.Length > 0) lw.Add(dw);
  3409. lw.Add(string.Format("OrderState = 5 "));
  3410. lw.Add(string.Format("IsVerifyToSupplier=1"));
  3411. if (PKey != "admin" && CurrentUser.UserPost.Post.Code != "SysAdmin" && CurrentUser.UserPost.Post.Code != "Place" && CurrentUser.UserPost.Post.Code != "PlaceMr")
  3412. {
  3413. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  3414. }
  3415. string supplier = GetPostString("supplier");
  3416. if ((PKey == "admin" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserPost.Post.Code == "Place" || CurrentUser.UserPost.Post.Code == "PlaceMr") && supplier.Length > 0)
  3417. {
  3418. lw.Add(string.Format("SupplierName = '{0}'", supplier));
  3419. }
  3420. lw.Add(string.Format("IsRefund<={0}", 1));
  3421. dStruct.Order = "FinishDesignTime desc";
  3422. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  3423. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  3424. if (dt != null)
  3425. {
  3426. foreach (DataRow dr in dt.Rows)
  3427. {
  3428. 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();
  3429. }
  3430. }
  3431. writeGridDataTableJson(dStruct.TotalCount, dt);
  3432. }
  3433. public void upd_erp_verifytosupplier()
  3434. {
  3435. if (UrlPostParmsCheck("ctid"))
  3436. {
  3437. string eids = GetPostString("ctid");
  3438. CeErpTradeCell entity = null;
  3439. string[] eidsList = eids.Split(',');
  3440. if (eidsList.Length <= 0)
  3441. {
  3442. returnErrorMsg("订单号不能空");
  3443. return;
  3444. }
  3445. List<string> tLst = new List<string>();
  3446. foreach (string ctidstr in eidsList)
  3447. {
  3448. tLst.Add("'" + ctidstr + "'");
  3449. CeErpDataSendOrderInfo.createObject(ctidstr);
  3450. }
  3451. string needtids = string.Join(",", tLst.ToArray());
  3452. StringBuilder sql = new StringBuilder();
  3453. //sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1 where SupplierId!=0 and ctid in ({0});", needtids);
  3454. sql.AppendFormat("update ce_erptradecell set IsVerifyToSupplier=1,IsReturn=0,FinishPlaceTime=GETDATE(),PlaceUserId={1} where SupplierId!=0 and ctid in ({0});", needtids, CurrentUser.UserID);
  3455. sql.AppendFormat("insert into CE_ErpTradeLog(tid,UserId,Con,OperateTime) select ctid,{1},'审核给供应商',getdate() from ce_erptradecell where ctid in({0});", needtids, CurrentUser.UserID);
  3456. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3457. returnSuccessMsg("操作成功!");
  3458. return;
  3459. /**foreach (string ctidstr in eidsList)
  3460. {
  3461. entity = CeErpTradeCell.GetByCtid(ctidstr);
  3462. if (entity != null)
  3463. {
  3464. if (entity.SupplierId == 0)
  3465. {
  3466. continue;
  3467. }
  3468. entity.IsVerifyToSupplier = true;
  3469. if (entity.IsReturn == 1) //1是供应商打回
  3470. {
  3471. entity.IsReturn = 0;
  3472. }
  3473. entity.FinishPlaceTime = DateTime.Now;
  3474. entity.PlaceUserId = CurrentUser.UserID;
  3475. entity.Update();
  3476. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核给供应商", entity.OrderState);
  3477. }
  3478. }
  3479. returnSuccessMsg("操作成功!");
  3480. return;**/
  3481. }
  3482. }
  3483. public void upd_erp_supplierback()
  3484. {
  3485. if (UrlPostParmsCheck("ctid"))
  3486. {
  3487. string eid = GetPostString("ctid");
  3488. string reason = GetPostString("returnreason");
  3489. CeErpTradeCell entity = null;
  3490. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3491. if (entity != null)
  3492. {
  3493. if (CurrentUser.UserPost.Post.Code != "Supplier")//不是供应商打回
  3494. {
  3495. string key = "return_order_" + entity.SupplierId;
  3496. List<string> list = new List<string>();
  3497. if (RedisHelper.HasKey(key))
  3498. {
  3499. object data = RedisHelper.StringGet(key);
  3500. list = Convert.ToString(data).Split(',').ToList();
  3501. }
  3502. list.Add(eid);
  3503. RedisHelper.StringSet(key, string.Join(",", list));
  3504. }
  3505. entity.IsVerifyToSupplier = false;
  3506. entity.IsReturn = 1;
  3507. entity.ReturnTime = DateTime.Now;
  3508. entity.ReturnReason = reason;
  3509. if (entity.OrderState == 6)
  3510. {
  3511. entity.OrderState = 5;
  3512. }
  3513. entity.Update();
  3514. CeErpSukuraData.createInfo(entity.ctid, 5);
  3515. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  3516. returnSuccessMsg("操作成功!");
  3517. return;
  3518. }
  3519. returnErrorMsg("找不到订单记录");
  3520. }
  3521. }
  3522. public void upd_erp_toaftersaleorder()
  3523. {
  3524. if (UrlPostParmsCheck("ctid"))
  3525. {
  3526. string eid = GetPostString("ctid");
  3527. string reason = GetPostString("returnreason");
  3528. CeErpTradeCell entity = null;
  3529. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3530. if (entity != null)
  3531. {
  3532. if (entity.isAfterSaleOrder != 1)
  3533. {
  3534. returnErrorMsg("带S的售后单才能打回给售后");
  3535. return;
  3536. }
  3537. if (entity.OrderState >= 5)
  3538. {
  3539. returnErrorMsg("已经设计完成了不能打回给售后");
  3540. return;
  3541. }
  3542. entity.OrderState = 0;
  3543. entity.IsReturn = 3;
  3544. entity.ReturnTime = DateTime.Now;
  3545. entity.UpdateTime = DateTime.Now;
  3546. entity.ReturnReason = reason;
  3547. entity.Update();
  3548. CeErpSukuraData.createInfo(entity.ctid, 5);
  3549. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从待设计打回到售后", entity.OrderState);
  3550. returnSuccessMsg("操作成功!");
  3551. return;
  3552. }
  3553. returnErrorMsg("找不到订单记录");
  3554. }
  3555. }
  3556. public void upd_erp_aftersaletodesign()
  3557. {
  3558. if (UrlPostParmsCheck("ctid"))
  3559. {
  3560. string eid = GetPostString("ctid");
  3561. CeErpTradeCell entity = null;
  3562. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3563. if (entity != null)
  3564. {
  3565. entity.OrderState = 3;
  3566. entity.IsReturn = 0;
  3567. entity.UpdateTime = DateTime.Now;
  3568. entity.Update();
  3569. CeErpSukuraData.createInfo(entity.ctid, 5);
  3570. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后单从打回售后恢复到设计", entity.OrderState);
  3571. returnSuccessMsg("操作成功!");
  3572. return;
  3573. }
  3574. returnErrorMsg("找不到订单记录");
  3575. }
  3576. }
  3577. public void assign_erp_supplier()
  3578. {
  3579. if (UrlPostParmsCheck("ctid"))
  3580. {
  3581. string eids = GetPostString("ctid");
  3582. int sid = GetPostInt("SupplierName");
  3583. string fromTag = GetPostString("tag");
  3584. string[] eidList = eids.Split(',');
  3585. if (eidList.Length <= 0)
  3586. {
  3587. returnErrorMsg("指派不能为空");
  3588. return;
  3589. }
  3590. string errMsg = "";
  3591. string suname = commonHelper.getSupplierNameById(sid);
  3592. foreach (string ctid in eidList)
  3593. {
  3594. CeErpTradeCell entity = null;
  3595. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3596. if (entity != null)
  3597. {
  3598. if (fromTag == "waitingorder" && entity.OrderState >= 6)
  3599. {
  3600. errMsg += (ctid + "指派失败!!!");
  3601. continue;
  3602. }
  3603. entity.SupplierId = sid;
  3604. entity.Update();
  3605. commonHelper.UpdateRelationOrder(entity.ctid);
  3606. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "指派供应商:" + suname, entity.OrderState);
  3607. if (entity.OrderState >= 6)
  3608. {
  3609. //if (entity.MakeSupplier.IndexOf(",") != -1)
  3610. //{
  3611. // string msl = entity.MakeSupplier;
  3612. // string[] mslist = msl.Split(',');
  3613. // 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);
  3614. // DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3615. //}
  3616. //else
  3617. //{
  3618. StringBuilder sql = new StringBuilder();
  3619. 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);
  3620. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  3621. //}
  3622. }
  3623. }
  3624. else
  3625. {
  3626. continue;
  3627. }
  3628. }
  3629. if (errMsg.Length > 0)
  3630. {
  3631. returnErrorMsg(errMsg);
  3632. return;
  3633. }
  3634. returnSuccessMsg("操作成功!");
  3635. return;
  3636. }
  3637. }
  3638. public void assign_erp_makesupplier()
  3639. {
  3640. if (UrlPostParmsCheck("ctid"))
  3641. {
  3642. string eids = GetPostString("ctid");
  3643. string sname = GetPostString("SupplierName");
  3644. string[] eidList = eids.Split(',');
  3645. if (eidList.Length <= 0)
  3646. {
  3647. returnErrorMsg("指派不能为空");
  3648. return;
  3649. }
  3650. List<string> tLst = new List<string>();
  3651. foreach (string ctid in eidList)
  3652. {
  3653. CeErpTradeCell entity = null;
  3654. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3655. if (entity != null)
  3656. {
  3657. entity.MakeSupplier = sname;
  3658. entity.Update();
  3659. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "设置制作供应商:" + sname, entity.OrderState);
  3660. tLst.Add("'" + ctid + "'");
  3661. }
  3662. else
  3663. {
  3664. continue;
  3665. }
  3666. }
  3667. string ctids = string.Join(",", tLst.ToArray());
  3668. StringBuilder sql2 = new StringBuilder();
  3669. sql2.AppendFormat("update ce_erptradecell2 set MakeSupplier='{0}' where ctid in ({1}) ", sname, ctids);
  3670. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3671. returnSuccessMsg("操作成功!");
  3672. return;
  3673. }
  3674. }
  3675. public void ins_erp_returnreason()
  3676. {
  3677. if (UrlPostParmsCheck("ctid"))
  3678. {
  3679. string eid = GetPostString("ctid");
  3680. CeErpTradeCell entity = null;
  3681. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3682. string userpost = CurrentUser.UserPost.Post.Code;
  3683. if (entity != null)
  3684. {
  3685. bool isPlace = false;
  3686. if (entity.OrderState > 6)
  3687. {
  3688. returnErrorMsg("已发货无法打回!");
  3689. return;
  3690. }
  3691. if (entity.OrderState == 6)
  3692. {
  3693. isPlace = true;
  3694. }
  3695. bool isNeedUpdateCell2 = false;
  3696. if (entity.OrderState >= 6)
  3697. {
  3698. isNeedUpdateCell2 = true;
  3699. }
  3700. int returnTag = 2;
  3701. if (userpost == "Supplier")
  3702. {
  3703. returnTag = 1;
  3704. }
  3705. int toType = GetPostInt("totype");
  3706. string fromType = "3";
  3707. if (entity.OrderState < 5)
  3708. {
  3709. fromType = "3";
  3710. }
  3711. else
  3712. {
  3713. fromType = "4";
  3714. }
  3715. if (entity.IsXianHuo == 0)
  3716. {
  3717. if (returnTag == 2)
  3718. {
  3719. if (toType == 1)
  3720. {
  3721. entity.OrderState = 0;
  3722. entity.ReturnUserType = 1;
  3723. string clearman = GetPostString("clearman");
  3724. if (!string.IsNullOrEmpty(clearman))
  3725. {
  3726. entity.DesignUserId = 0;
  3727. }
  3728. }
  3729. else
  3730. {
  3731. entity.OrderState = 3;
  3732. entity.ReturnUserType = 2;
  3733. }
  3734. entity.IsReadTag = 1;
  3735. }
  3736. else if (returnTag == 1)
  3737. {
  3738. entity.OrderState = 5;
  3739. }
  3740. entity.IsVerifyToSupplier = false;
  3741. }
  3742. if (entity.IsXianHuo == 1)
  3743. {
  3744. entity.OrderState = 5;
  3745. }
  3746. entity.UnusualTag = 0;
  3747. entity.UnusualTime = null;
  3748. entity.UnusualCon = "";
  3749. entity.IsReturn = returnTag;
  3750. entity.ReturnTime = DateTime.Now;
  3751. entity.UpdateTime = DateTime.Now;
  3752. entity.ReturnReason = GetPostString("returnreason");
  3753. entity.Update();
  3754. if (entity.OrderState == 3)
  3755. {
  3756. ApiVo apiVo = new ApiVo();
  3757. apiVo.orderNumber = entity.ctid;
  3758. apiVo.actionName = "rebutDesign";
  3759. apiVo.orderRemarks = entity.ReturnReason;
  3760. designHelper.API_WorkCore(apiVo);//rebutDesign
  3761. }
  3762. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  3763. if (ceErpTradeCellExtend != null && ceErpTradeCellExtend.orderFrom == 30)
  3764. {
  3765. dataHelper.api_orderBack(entity.ctid, fromType, entity.ReturnReason);
  3766. }
  3767. CeErpSukuraData.createInfo(entity.ctid, 5);
  3768. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3769. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3770. if (isPlace)
  3771. {
  3772. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", entity.ctid);
  3773. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  3774. if (dth != null && dth.Rows.Count > 0)
  3775. {
  3776. dataSendOrderBean dataSendOrderBean = null;
  3777. foreach (DataRow item in dth.Rows)
  3778. {
  3779. try
  3780. {
  3781. dataSendOrderBean = new dataSendOrderBean();
  3782. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  3783. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  3784. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  3785. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  3786. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  3787. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  3788. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  3789. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  3790. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  3791. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  3792. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  3793. dataSendOrderBean.Radio1723534706288 = "打回";
  3794. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  3795. if (result != null)
  3796. {
  3797. if ("0".Equals(result.errcode))
  3798. {
  3799. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  3800. }
  3801. else
  3802. {
  3803. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  3804. }
  3805. }
  3806. }
  3807. catch (Exception ex)
  3808. {
  3809. }
  3810. }
  3811. }
  3812. }
  3813. if (isNeedUpdateCell2)
  3814. {
  3815. if (entity.MakeSupplier.IndexOf(",") != -1)
  3816. {
  3817. StringBuilder sql2 = new StringBuilder();
  3818. 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);
  3819. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3820. }
  3821. else
  3822. {
  3823. StringBuilder sql2 = new StringBuilder();
  3824. 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);
  3825. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3826. }
  3827. }
  3828. returnSuccessMsg("操作成功!");
  3829. return;
  3830. }
  3831. returnErrorMsg("找不到订单记录");
  3832. }
  3833. }
  3834. public void cyt_erp_returnreason()
  3835. {
  3836. if (UrlPostParmsCheck("ctid"))
  3837. {
  3838. string eid = GetPostString("ctid");
  3839. CeErpTradeCell entity = null;
  3840. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  3841. string userpost = CurrentUser.UserPost.Post.Code;
  3842. if (entity != null)
  3843. {
  3844. if (entity.OrderState > 6)
  3845. {
  3846. returnErrorMsg("已发货无法打回!");
  3847. return;
  3848. }
  3849. JObject jsonObject = new JObject
  3850. {
  3851. { "Userid", "77886" },
  3852. { "Pwd", "lt666888" },
  3853. { "LTOrderId",eid }
  3854. };
  3855. string response = HttpPost(" http://www.kiy.cn/m-mobile/autobaojia/LTCancelOrder", jsonObject.ToString());
  3856. JObject jsonObjects = JObject.Parse(response);
  3857. string msg = (string)jsonObjects["msg"];
  3858. if (msg != "取消成功")
  3859. {
  3860. returnErrorMsg(msg);
  3861. return;
  3862. }
  3863. bool isNeedUpdateCell2 = false;
  3864. if (entity.OrderState >= 6)
  3865. {
  3866. isNeedUpdateCell2 = true;
  3867. }
  3868. int returnTag = 2;
  3869. if (userpost == "Supplier")
  3870. {
  3871. returnTag = 1;
  3872. }
  3873. if (entity.IsXianHuo == 0)
  3874. {
  3875. if (returnTag == 2)
  3876. {
  3877. int toType = GetPostInt("totype");
  3878. if (toType == 1)
  3879. {
  3880. entity.OrderState = 0;
  3881. entity.ReturnUserType = 1;
  3882. }
  3883. else
  3884. {
  3885. entity.OrderState = 4;
  3886. entity.ReturnUserType = 2;
  3887. }
  3888. entity.IsReadTag = 1;
  3889. }
  3890. else if (returnTag == 1)
  3891. {
  3892. entity.OrderState = 5;
  3893. }
  3894. entity.IsVerifyToSupplier = false;
  3895. }
  3896. entity.UnusualTag = 0;
  3897. entity.UnusualTime = null;
  3898. entity.UnusualCon = "";
  3899. entity.IsReturn = returnTag;
  3900. entity.ReturnTime = DateTime.Now;
  3901. entity.ReturnReason = GetPostString("returnreason");
  3902. entity.Update();
  3903. if (entity.OrderState == 4)
  3904. {
  3905. ApiVo apiVo = new ApiVo();
  3906. apiVo.orderNumber = entity.ctid;
  3907. apiVo.actionName = "rebutDesign";
  3908. apiVo.orderRemarks = entity.ReturnReason;
  3909. designHelper.API_WorkCore(apiVo);//rebutDesign
  3910. }
  3911. CeErpSukuraData.createInfo(entity.ctid, 5);
  3912. apiDesign.API_GetPrintData_ModifyOrder(entity.ctid, entity.seller_memo, false, true, entity.ReturnReason);
  3913. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退单:" + entity.ReturnReason, entity.OrderState);
  3914. if (isNeedUpdateCell2)
  3915. {
  3916. if (entity.MakeSupplier.IndexOf(",") != -1)
  3917. {
  3918. StringBuilder sql2 = new StringBuilder();
  3919. 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);
  3920. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3921. }
  3922. else
  3923. {
  3924. StringBuilder sql2 = new StringBuilder();
  3925. 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);
  3926. DbHelper.DbConn.ExecuteNonQuery(sql2.ToString());
  3927. }
  3928. }
  3929. returnSuccessMsg("操作成功!");
  3930. return;
  3931. }
  3932. returnErrorMsg("找不到订单记录");
  3933. }
  3934. }
  3935. public void upd_erp_xianhuoreturntag()
  3936. {
  3937. if (UrlPostParmsCheck("ctid"))
  3938. {
  3939. string eids = GetPostString("ctid");
  3940. string[] ctids = eids.Split(',');
  3941. foreach (string ctid in ctids)
  3942. {
  3943. CeErpTradeCell entity = null;
  3944. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  3945. if (entity != null)
  3946. {
  3947. entity.IsReturn = 0;
  3948. entity.Update();
  3949. CeErpSukuraData.createInfo(entity.ctid, 5);
  3950. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "打回现货恢复到待发货", entity.OrderState);
  3951. }
  3952. }
  3953. returnSuccessMsg("操作成功!");
  3954. return;
  3955. }
  3956. }
  3957. public void get_erp_waitdeliverylist()
  3958. {
  3959. DataStruct dStruct = GetPostStruct();
  3960. List<string> lw = new List<string>();
  3961. string tid = GetPostString("ctid");
  3962. if (tid.Length > 0)
  3963. {
  3964. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  3965. if (tid.Length > 5)
  3966. {
  3967. List<string> tids = getTidByCtidLike(tid);
  3968. if (tids.Count > 0 && tids.Count < 10)
  3969. {
  3970. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  3971. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  3972. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  3973. {
  3974. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  3975. }
  3976. }
  3977. }
  3978. lw.Add(tid_sql);
  3979. }
  3980. string shopname = GetPostString("shopname");
  3981. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  3982. string buyernick = GetPostString("buyer_nick");
  3983. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  3984. //if (tid.Length == 0 && buyernick.Length == 0)
  3985. //{
  3986. // lw.Add(string.Format("IsRefund<={0}", 1));
  3987. //}
  3988. string customer = GetPostString("customer");
  3989. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  3990. string design = GetPostString("design");
  3991. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  3992. string orderState = GetPostString("orderState");
  3993. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  3994. string address = GetPostString("address");
  3995. 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));
  3996. string sellermemo = GetPostString("seller_memo");
  3997. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  3998. string supplier = GetPostString("supplier");
  3999. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4000. string OrderArea = GetPostString("order_area");
  4001. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4002. string placedate1 = GetPostString("placedate1");
  4003. string placedate2 = GetPostString("placedate2");
  4004. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4005. if (fdw.Length > 0) lw.Add(fdw);
  4006. string price1 = GetPostString("price1");
  4007. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4008. string price2 = GetPostString("price2");
  4009. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4010. string unusualCon = GetPostString("unusualcon");
  4011. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4012. string otherMemo = GetPostString("otherMemo");
  4013. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4014. string posTag = CurrentUser.UserPost.Post.Code;
  4015. if (posTag == "Supplier")
  4016. {
  4017. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4018. }
  4019. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) = '' or attachments is null)"));
  4020. lw.Add(string.Format("type != 'PDD' "));
  4021. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4022. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4023. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4024. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4025. writeGridDataTableJson(dStruct.TotalCount, dt);
  4026. }
  4027. public void get_erp_changedeliverylist()
  4028. {
  4029. DataStruct dStruct = GetPostStruct();
  4030. List<string> lw = new List<string>();
  4031. string tid = GetPostString("ctid");
  4032. if (tid.Length > 0)
  4033. {
  4034. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4035. if (tid.Length > 5)
  4036. {
  4037. List<string> tids = getTidByCtidLike(tid);
  4038. if (tids.Count > 0 && tids.Count < 10)
  4039. {
  4040. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4041. }
  4042. }
  4043. lw.Add(tid_sql);
  4044. }
  4045. string shopname = GetPostString("shopname");
  4046. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4047. string buyernick = GetPostString("buyer_nick");
  4048. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4049. //if (tid.Length == 0 && buyernick.Length == 0)
  4050. //{
  4051. // lw.Add(string.Format("IsRefund<={0}", 1));
  4052. //}
  4053. string customer = GetPostString("customer");
  4054. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4055. string design = GetPostString("design");
  4056. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4057. string orderState = GetPostString("orderState");
  4058. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4059. string address = GetPostString("address");
  4060. 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));
  4061. string sellermemo = GetPostString("seller_memo");
  4062. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4063. string supplier = GetPostString("supplier");
  4064. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4065. string OrderArea = GetPostString("order_area");
  4066. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4067. string placedate1 = GetPostString("placedate1");
  4068. string placedate2 = GetPostString("placedate2");
  4069. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4070. if (fdw.Length > 0) lw.Add(fdw);
  4071. string price1 = GetPostString("price1");
  4072. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4073. string price2 = GetPostString("price2");
  4074. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4075. string unusualCon = GetPostString("unusualcon");
  4076. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4077. string otherMemo = GetPostString("otherMemo");
  4078. if (otherMemo.Length > 0) lw.Add(string.Format("otherMemo like '%{0}%'", otherMemo));
  4079. string posTag = CurrentUser.UserPost.Post.Code;
  4080. if (posTag == "Supplier")
  4081. {
  4082. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4083. }
  4084. lw.Add(string.Format("OrderState = 6 and (CONVERT(VARCHAR,attachments) != '' and attachments is not null) "));
  4085. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4086. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4087. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4088. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4089. /*if (tid.Length > 0)
  4090. {
  4091. List<string> tids = new List<string>();
  4092. if (dt != null && dt.Rows.Count > 0)
  4093. {
  4094. foreach (DataRow item in dt.Rows)
  4095. {
  4096. tids.Add("'" + item["tid"] + "'");
  4097. }
  4098. }
  4099. if (tids.Count > 0)
  4100. {
  4101. lw.RemoveAt(0);
  4102. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4103. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4104. dt = WebCache.GetData("view_erptradecell", dStruct);
  4105. }
  4106. }*/
  4107. writeGridDataTableJson(dStruct.TotalCount, dt);
  4108. }
  4109. public void get_erp_pddderiving()
  4110. {
  4111. DataStruct dStruct = GetPostStruct();
  4112. List<string> lw = new List<string>();
  4113. string tid = GetPostString("ctid");
  4114. if (tid.Length > 0)
  4115. {
  4116. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4117. if (tid.Length > 5)
  4118. {
  4119. List<string> tids = getTidByCtidLike(tid);
  4120. if (tids.Count > 0 && tids.Count < 10)
  4121. {
  4122. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4123. List<string> receiverIds = getReceiverIdByCtidLike(tids);
  4124. if (receiverIds.Count > 0 && receiverIds.Count < 10)
  4125. {
  4126. tid_sql = string.Format("(tid in ({0}) or receiverId in ({1})) ", string.Join(",", tids), string.Join(",", receiverIds));
  4127. }
  4128. }
  4129. }
  4130. lw.Add(tid_sql);
  4131. }
  4132. string shopname = GetPostString("shopname");
  4133. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4134. string buyernick = GetPostString("buyer_nick");
  4135. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4136. //if (tid.Length == 0 && buyernick.Length == 0)
  4137. //{
  4138. // lw.Add(string.Format("IsRefund<={0}", 1));
  4139. //}
  4140. string customer = GetPostString("customer");
  4141. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4142. string design = GetPostString("design");
  4143. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4144. string orderState = GetPostString("orderState");
  4145. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4146. string address = GetPostString("address");
  4147. 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));
  4148. string sellermemo = GetPostString("seller_memo");
  4149. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4150. string supplier = GetPostString("supplier");
  4151. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4152. string OrderArea = GetPostString("order_area");
  4153. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4154. string placedate1 = GetPostString("placedate1");
  4155. string placedate2 = GetPostString("placedate2");
  4156. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4157. if (fdw.Length > 0) lw.Add(fdw);
  4158. string price1 = GetPostString("price1");
  4159. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4160. string price2 = GetPostString("price2");
  4161. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4162. string unusualCon = GetPostString("unusualcon");
  4163. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  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) = '' or attachments is null)"));
  4170. lw.Add(string.Format("type = 'PDD' "));
  4171. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4172. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4173. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4174. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4175. /*if (tid.Length > 0)
  4176. {
  4177. List<string> tids = new List<string>();
  4178. if (dt != null && dt.Rows.Count > 0)
  4179. {
  4180. foreach (DataRow item in dt.Rows)
  4181. {
  4182. tids.Add("'" + item["tid"] + "'");
  4183. }
  4184. }
  4185. if (tids.Count > 0)
  4186. {
  4187. lw.RemoveAt(0);
  4188. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4189. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4190. dt = WebCache.GetData("view_erptradecell", dStruct);
  4191. }
  4192. }*/
  4193. writeGridDataTableJson(dStruct.TotalCount, dt);
  4194. }
  4195. public void get_erp_jdderiving()
  4196. {
  4197. DataStruct dStruct = GetPostStruct();
  4198. List<string> lw = new List<string>();
  4199. string tid = GetPostString("ctid");
  4200. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%' ", tid));
  4201. string shopname = GetPostString("shopname");
  4202. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4203. string buyernick = GetPostString("buyer_nick");
  4204. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4205. //if (tid.Length == 0 && buyernick.Length == 0)
  4206. //{
  4207. // lw.Add(string.Format("IsRefund<={0}", 1));
  4208. //}
  4209. string customer = GetPostString("customer");
  4210. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4211. string design = GetPostString("design");
  4212. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4213. string orderState = GetPostString("orderState");
  4214. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4215. string address = GetPostString("address");
  4216. 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));
  4217. string sellermemo = GetPostString("seller_memo");
  4218. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4219. string supplier = GetPostString("supplier");
  4220. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4221. string OrderArea = GetPostString("order_area");
  4222. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4223. string placedate1 = GetPostString("placedate1");
  4224. string placedate2 = GetPostString("placedate2");
  4225. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4226. if (fdw.Length > 0) lw.Add(fdw);
  4227. string price1 = GetPostString("price1");
  4228. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4229. string price2 = GetPostString("price2");
  4230. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4231. string unusualCon = GetPostString("unusualcon");
  4232. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4233. string posTag = CurrentUser.UserPost.Post.Code;
  4234. if (posTag == "Supplier")
  4235. {
  4236. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4237. }
  4238. lw.Add(string.Format("OrderState = 6 "));
  4239. lw.Add(string.Format("type = 'JD' "));
  4240. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  4241. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  4242. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4243. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4244. writeGridDataTableJson(dStruct.TotalCount, dt);
  4245. }
  4246. public void get_erp_demoorderlist()
  4247. {
  4248. DataStruct dStruct = GetPostStruct();
  4249. List<string> lw = new List<string>();
  4250. string tid = GetPostString("ctid");
  4251. if (tid.Length > 0)
  4252. {
  4253. string select_tid = getTidByCtid(tid);
  4254. lw.Add(string.Format("tid='{0}'", select_tid));
  4255. }
  4256. string shopname = GetPostString("shopname");
  4257. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4258. string buyernick = GetPostString("buyer_nick");
  4259. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4260. string customer = GetPostString("customer");
  4261. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4262. string design = GetPostString("design");
  4263. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4264. string orderState = GetPostString("orderState");
  4265. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4266. string address = GetPostString("address");
  4267. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4268. string sellermemo = GetPostString("seller_memo");
  4269. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4270. string supplier = GetPostString("supplier");
  4271. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4272. string OrderArea = GetPostString("order_area");
  4273. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4274. string date1 = GetPostString("date1");
  4275. string date2 = GetPostString("date2");
  4276. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4277. if (dw.Length > 0) lw.Add(dw);
  4278. string price1 = GetPostString("price1");
  4279. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4280. string price2 = GetPostString("price2");
  4281. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4282. string posTag = CurrentUser.UserPost.Post.Code;
  4283. if (posTag == "Supplier")
  4284. {
  4285. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4286. }
  4287. //lw.Add(string.Format("OrderState = 6 "));
  4288. lw.Add(string.Format("IsSample={0}", 3));
  4289. lw.Add(string.Format("IsRefund<={0}", 1));
  4290. dStruct.Order = "pay_time desc";
  4291. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4292. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4293. writeGridDataTableJson(dStruct.TotalCount, dt);
  4294. }
  4295. public void save_erp_checkmemo()
  4296. {
  4297. if (UrlPostParmsCheck("ctid"))
  4298. {
  4299. string ctid = GetPostString("ctid");
  4300. CeErpTradeCell entity = null;
  4301. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  4302. if (entity != null)
  4303. {
  4304. entity.CheckMemo = GetPostString("CheckMemo");
  4305. entity.Update();
  4306. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  4307. if (trade != null)
  4308. {
  4309. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.CheckMemo);
  4310. }
  4311. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改查单备注-" + entity.CheckMemo, entity.OrderState);
  4312. returnSuccessMsg("保存成功!");
  4313. return;
  4314. }
  4315. returnErrorMsg("找不到记录");
  4316. }
  4317. }
  4318. public void get_erp_returnlist()
  4319. {
  4320. DataStruct dStruct = GetPostStruct();
  4321. List<string> lw = new List<string>();
  4322. string tid = GetPostString("ctid");
  4323. if (tid.Length > 0)
  4324. {
  4325. string select_tid = getTidByCtid(tid);
  4326. lw.Add(string.Format("tid='{0}'", select_tid));
  4327. }
  4328. string shopname = GetPostString("shopname");
  4329. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4330. string buyernick = GetPostString("buyer_nick");
  4331. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4332. string customer = GetPostString("customer");
  4333. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4334. string design = GetPostString("design");
  4335. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4336. string orderState = GetPostString("orderState");
  4337. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4338. string address = GetPostString("address");
  4339. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4340. string sellermemo = GetPostString("seller_memo");
  4341. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4342. string supplier = GetPostString("supplier");
  4343. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4344. string date1 = GetPostString("date1");
  4345. string date2 = GetPostString("date2");
  4346. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4347. if (dw.Length > 0) lw.Add(dw);
  4348. string bdate1 = GetPostString("backdate1");
  4349. string bdate2 = GetPostString("backdate2");
  4350. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4351. if (dw_back.Length > 0) lw.Add(dw_back);
  4352. string price1 = GetPostString("price1");
  4353. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4354. string price2 = GetPostString("price2");
  4355. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4356. lw.Add(string.Format("IsReturn>0"));
  4357. lw.Add(string.Format("IsXianHuo=0"));
  4358. lw.Add(string.Format("IsReturn!=3"));
  4359. string backtype = GetPostString("backtype");
  4360. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4361. dStruct.Order = "FinishDesignTime desc";
  4362. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4363. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4364. writeGridDataTableJson(dStruct.TotalCount, dt);
  4365. }
  4366. public void get_erp_today_sumreturn()
  4367. {
  4368. DataStruct dStruct = GetPostStruct();
  4369. List<string> lw = new List<string>();
  4370. string bdate1 = GetPostString("returnTimeS");
  4371. string bdate2 = GetPostString("returnTimeE");
  4372. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4373. if (dw_back.Length > 0) lw.Add(dw_back);
  4374. lw.Add(string.Format("IsReturn=0"));
  4375. lw.Add(string.Format("IsXianHuo=0"));
  4376. string mainWhere = string.Join(" and ", lw.ToArray());
  4377. string sql = "";
  4378. if (dw_back.Length > 0)
  4379. {
  4380. sql = "select count(0) as total,(select count(0) from view_erptradecell where " + mainWhere + ") as today_finish from view_erptradecell where " + dw_back;
  4381. }
  4382. else
  4383. {
  4384. 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 + "'";
  4385. }
  4386. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  4387. decimal total = 0, today_finish = 0;
  4388. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["total"]) != "")
  4389. {
  4390. total = Convert.ToDecimal(dt.Rows[0]["total"]);
  4391. }
  4392. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["today_finish"]) != "")
  4393. {
  4394. today_finish = Convert.ToDecimal(dt.Rows[0]["today_finish"]);
  4395. }
  4396. var res = new
  4397. {
  4398. data = total,
  4399. data1 = today_finish,
  4400. };
  4401. string ro_jsond = JsonConvert.SerializeObject(res);
  4402. returnSuccess(ro_jsond);
  4403. return;
  4404. }
  4405. public void get_erp_allreturnlist()
  4406. {
  4407. DataStruct dStruct = GetPostStruct();
  4408. List<string> lw = new List<string>();
  4409. string tid = GetPostString("ctid");
  4410. if (tid.Length > 0)
  4411. {
  4412. string select_tid = getTidByCtid(tid);
  4413. lw.Add(string.Format("tid='{0}'", select_tid));
  4414. }
  4415. string shopname = GetPostString("shopname");
  4416. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4417. string buyernick = GetPostString("buyer_nick");
  4418. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4419. string customer = GetPostString("customer");
  4420. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4421. string design = GetPostString("design");
  4422. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4423. string orderState = GetPostString("orderState");
  4424. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4425. string address = GetPostString("address");
  4426. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4427. string sellermemo = GetPostString("seller_memo");
  4428. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4429. string supplier = GetPostString("supplier");
  4430. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4431. string date1 = GetPostString("date1");
  4432. string date2 = GetPostString("date2");
  4433. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4434. if (dw.Length > 0) lw.Add(dw);
  4435. string bdate1 = GetPostString("backdate1");
  4436. string bdate2 = GetPostString("backdate2");
  4437. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4438. if (dw_back.Length > 0) lw.Add(dw_back);
  4439. string price1 = GetPostString("price1");
  4440. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4441. string price2 = GetPostString("price2");
  4442. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4443. string backreason = GetPostString("backreason");
  4444. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4445. lw.Add(string.Format("IsXianHuo=0"));
  4446. lw.Add(string.Format("ReturnTime != ''"));
  4447. string backtype = GetPostString("backtype");
  4448. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4449. dStruct.Order = "FinishDesignTime desc";
  4450. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4451. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4452. writeGridDataTableJson(dStruct.TotalCount, dt);
  4453. }
  4454. public void get_erp_aftersalereturnlist()
  4455. {
  4456. DataStruct dStruct = GetPostStruct();
  4457. List<string> lw = new List<string>();
  4458. string tid = GetPostString("ctid");
  4459. if (tid.Length > 0)
  4460. {
  4461. string select_tid = getTidByCtid(tid);
  4462. lw.Add(string.Format("tid='{0}'", select_tid));
  4463. }
  4464. string shopname = GetPostString("shopname");
  4465. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4466. string buyernick = GetPostString("buyer_nick");
  4467. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4468. string customer = GetPostString("customer");
  4469. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4470. string design = GetPostString("design");
  4471. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4472. string orderState = GetPostString("orderState");
  4473. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4474. string address = GetPostString("address");
  4475. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4476. string sellermemo = GetPostString("seller_memo");
  4477. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4478. string supplier = GetPostString("supplier");
  4479. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4480. string date1 = GetPostString("date1");
  4481. string date2 = GetPostString("date2");
  4482. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4483. if (dw.Length > 0) lw.Add(dw);
  4484. string bdate1 = GetPostString("backdate1");
  4485. string bdate2 = GetPostString("backdate2");
  4486. string dw_back = GetDateMinuteWhere("ReturnTime", bdate1, bdate2);
  4487. if (dw_back.Length > 0) lw.Add(dw_back);
  4488. string price1 = GetPostString("price1");
  4489. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4490. string price2 = GetPostString("price2");
  4491. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4492. lw.Add(string.Format("IsReturn=3"));
  4493. string backtype = GetPostString("backtype");
  4494. if (backtype.Length > 0) lw.Add(string.Format("IsReturn={0}", Convert.ToInt32(backtype)));
  4495. string backreason = GetPostString("backreason");
  4496. if (backreason.Length > 0) lw.Add(string.Format("ReturnReason like '%{0}%'", backreason));
  4497. dStruct.Order = "ReturnTime desc";
  4498. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4499. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4500. writeGridDataTableJson(dStruct.TotalCount, dt);
  4501. }
  4502. public void get_erp_xianhuoreturnlist()
  4503. {
  4504. DataStruct dStruct = GetPostStruct();
  4505. List<string> lw = new List<string>();
  4506. string tid = GetPostString("ctid");
  4507. if (tid.Length > 0)
  4508. {
  4509. string select_tid = getTidByCtid(tid);
  4510. lw.Add(string.Format("tid='{0}'", select_tid));
  4511. }
  4512. string shopname = GetPostString("shopname");
  4513. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4514. string buyernick = GetPostString("buyer_nick");
  4515. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4516. string customer = GetPostString("customer");
  4517. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4518. string design = GetPostString("design");
  4519. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4520. string orderState = GetPostString("orderState");
  4521. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  4522. string address = GetPostString("address");
  4523. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  4524. string sellermemo = GetPostString("seller_memo");
  4525. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4526. string supplier = GetPostString("supplier");
  4527. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4528. string OrderArea = GetPostString("order_area");
  4529. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  4530. string date1 = GetPostString("date1");
  4531. string date2 = GetPostString("date2");
  4532. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4533. if (dw.Length > 0) lw.Add(dw);
  4534. string price1 = GetPostString("price1");
  4535. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4536. string price2 = GetPostString("price2");
  4537. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4538. string posTag = CurrentUser.UserPost.Post.Code;
  4539. if (posTag == "Supplier")
  4540. {
  4541. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4542. }
  4543. lw.Add(string.Format("OrderState=6 "));
  4544. lw.Add(string.Format("IsXianHuo=1 "));
  4545. lw.Add(string.Format("IsReturn>0 "));
  4546. lw.Add(string.Format("IsReturn!=3"));
  4547. lw.Add(string.Format("IsRefund<={0}", 1));
  4548. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc";
  4549. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4550. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4551. writeGridDataTableJson(dStruct.TotalCount, dt);
  4552. }
  4553. public void set_erp_orderdelivery()
  4554. {
  4555. if (UrlPostParmsCheck("ctid"))
  4556. {
  4557. string eid = GetPostString("ctid");
  4558. CeErpTradeCell entity = null;
  4559. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4560. if (entity != null)
  4561. {
  4562. if (entity.OrderState >= 7)
  4563. {
  4564. returnErrorMsg("此单已发货,无需重复发货");
  4565. return;
  4566. }
  4567. if (entity.OrderState != 6)
  4568. {
  4569. returnErrorMsg("此单状态为非【下单完成】,无法发货");
  4570. return;
  4571. }
  4572. string shop = GetPostString("seller_nick");
  4573. //string sessionkey = taobaoHelper.ShopKeyDics[shop];
  4574. string comName = GetPostString("comName");
  4575. string comCode = GetPostString("comCode");
  4576. string outSid = GetPostString("outSid");
  4577. string deliveryType = GetPostString("deliveryType");
  4578. string deliveryMemo = GetPostString("deliveryMemo");
  4579. outSid = outSid.Trim();
  4580. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  4581. if (mainEn == null)
  4582. {
  4583. returnErrorMsg("找不到原始订单记录");
  4584. return;
  4585. }
  4586. bool isInitOrderDeliv = false;
  4587. if (mainEn.status == "SHIPPED" || mainEn.status == "COMPLETE")
  4588. {
  4589. isInitOrderDeliv = true;
  4590. }
  4591. string apires = "";
  4592. string dcomcode = commonHelper.GetD3ComCode(comCode, comCode);
  4593. 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)
  4594. {
  4595. apires = "发货成功true";
  4596. }
  4597. else
  4598. {
  4599. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  4600. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4601. }
  4602. if ((apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1) || isInitOrderDeliv)
  4603. {
  4604. entity.OrderState = 7;//发货后订单已发货
  4605. entity.OutSid = outSid;
  4606. entity.MemoOpt = 0;
  4607. entity.UpdateTime = DateTime.Now;
  4608. entity.FinishDeliveryTime = DateTime.Now;
  4609. entity.Update();
  4610. commonHelper.aftersaleSend(entity.ctid, comName, outSid);
  4611. commonHelper.UpdateRelationOrder(entity.ctid);
  4612. //还要插入快递信息到 快递信息表
  4613. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  4614. exinfo.tid = eid;
  4615. exinfo.out_sid = outSid;
  4616. exinfo.company_code = comCode;
  4617. exinfo.company_name = comName;
  4618. exinfo.delivery_memo = deliveryMemo;
  4619. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  4620. exinfo.deliveryType = deliveryType;
  4621. exinfo.Create();
  4622. returnSuccessMsg("发货操作成功!");
  4623. commonHelper.UpdateRelationOrder(entity.ctid);
  4624. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, dcomcode, outSid);
  4625. CeErpSukuraData.createInfo(entity.ctid, 4);
  4626. if (entity.SupplierId == 64)
  4627. {
  4628. commonHelper.sendCytExpress(exinfo);
  4629. }
  4630. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  4631. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "发货-" + comName + "-" + outSid, entity.OrderState);
  4632. }
  4633. else
  4634. {
  4635. string errmsg = commonHelper.KeepChinese(apires);
  4636. returnErrorMsg("淘宝发货失败!" + errmsg + "----物流编码:" + dcomcode);
  4637. XLog.SaveLog(0, "发货接口失败," + entity.tid + apires + "----物流编码:" + dcomcode);
  4638. }
  4639. return;
  4640. }
  4641. returnErrorMsg("找不到订单记录");
  4642. }
  4643. }
  4644. public void set_erp_multidelivery()
  4645. {
  4646. string eids = GetPostString("tids");
  4647. string[] eidList = eids.Split(',');
  4648. if (eidList.Length <= 0)
  4649. {
  4650. returnErrorMsg("发货不能为空");
  4651. return;
  4652. }
  4653. foreach (string ctid in eidList)
  4654. {
  4655. if (ctid.Length <= 0) continue;
  4656. CeErpExpressInfo expInfo = CeErpExpressInfo.GetByCtid(ctid);
  4657. if (expInfo != null)
  4658. {
  4659. StringBuilder sql = new StringBuilder();
  4660. sql.AppendFormat("select * from view_ErpTradeCell where ctid='{0}';", ctid);
  4661. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  4662. if (dt.Rows.Count > 0)
  4663. {
  4664. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) >= 7)
  4665. {
  4666. expInfo.delivery_memo = "此单状态为【已发货】,无需重复发货";
  4667. expInfo.state = "异常";
  4668. expInfo.isMultiDelivery = 1;
  4669. expInfo.Update();
  4670. continue;
  4671. }
  4672. if (Convert.ToInt32(dt.Rows[0]["OrderState"]) != 6)
  4673. {
  4674. expInfo.delivery_memo = "此单状态为非【下单完成】,无法发货";
  4675. expInfo.state = "异常";
  4676. expInfo.Update();
  4677. continue;
  4678. }
  4679. //string sessionkey = taobaoHelper.ShopKeyDics[dt.Rows[0]["seller_nick"].ToString()];
  4680. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey, dt.Rows[0]["tid"].ToString(), expInfo.company_code, expInfo.out_sid);
  4681. bool isInitOrderDeliv = false;
  4682. if (dt.Rows[0]["status"].ToString() == "SHIPPED" || dt.Rows[0]["status"].ToString() == "COMPLETE")
  4683. {
  4684. isInitOrderDeliv = true;
  4685. expInfo.isMultiDelivery = 1;
  4686. }
  4687. if (ctid.IndexOf("N") != -1)
  4688. {
  4689. StringBuilder sqlbucha = new StringBuilder();
  4690. sqlbucha.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, dt.Rows[0]["tid"].ToString());
  4691. CeErpTradeCell.ExecuteNonQuery(sqlbucha.ToString());
  4692. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4693. commonHelper.UpdateRelationOrder(ctid);
  4694. expInfo.delivery_memo = "发货成功";
  4695. expInfo.state = "发货成功";
  4696. expInfo.isMultiDelivery = 1;
  4697. expInfo.Update();
  4698. }
  4699. else
  4700. {
  4701. string dcomcode = commonHelper.GetD3ComCode(expInfo.company_code, expInfo.company_name);
  4702. string apires = apiHelper.API_LogisticsOnlineSend(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4703. if (apires.IndexOf("发货成功") != -1 && apires.IndexOf("true") != -1 || isInitOrderDeliv)
  4704. {
  4705. expInfo.delivery_memo = "发货成功";
  4706. expInfo.state = "发货成功";
  4707. expInfo.isMultiDelivery = 1;
  4708. expInfo.Update();
  4709. commonHelper.UpdateRelationOrder(ctid);
  4710. CeErpSukuraData.createInfo(ctid, 4);
  4711. commonHelper.insertToBuchaForDelivery(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["posCode"].ToString(), dcomcode, expInfo.out_sid);
  4712. LogHelper.addLog(ctid, CurrentUser.UserID, "批量发货-" + expInfo.company_code + "-" + expInfo.out_sid);
  4713. }
  4714. else
  4715. {
  4716. expInfo.delivery_memo = apires + "---物流编码:" + dcomcode;
  4717. expInfo.state = "异常";
  4718. expInfo.Update();
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. returnSuccessMsg("操作完成");
  4725. }
  4726. public void reset_erp_memoopt()
  4727. {
  4728. if (UrlPostParmsCheck("ctid"))
  4729. {
  4730. string eid = GetPostString("ctid");
  4731. CeErpTradeCell entity = null;
  4732. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  4733. if (entity != null)
  4734. {
  4735. string stropt = "";
  4736. if (entity.MemoOpt == 1)
  4737. {
  4738. stropt = "“改稿”";
  4739. }
  4740. else if (entity.MemoOpt == 2)
  4741. {
  4742. stropt = "“定稿”";
  4743. }
  4744. else if (entity.MemoOpt == 3)
  4745. {
  4746. stropt = "“完成查货”";
  4747. CeErpSukuraData.createInfo(entity.ctid, 6);
  4748. }
  4749. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "已确认:" + stropt, entity.OrderState, 1);
  4750. entity.UpdateTime = DateTime.Now;
  4751. entity.MemoOpt = 0;
  4752. entity.Update();
  4753. returnSuccessMsg("操作成功!");
  4754. return;
  4755. }
  4756. returnErrorMsg("找不到记录");
  4757. }
  4758. }
  4759. public void get_erp_deliveryunusual()
  4760. {
  4761. DataStruct dStruct = GetPostStruct();
  4762. List<string> lw = new List<string>();
  4763. string tid = GetPostString("ctid");
  4764. if (tid.Length > 0)
  4765. {
  4766. string select_tid = getTidByCtid(tid);
  4767. lw.Add(string.Format("tid='{0}'", select_tid));
  4768. }
  4769. string shopname = GetPostString("shopname");
  4770. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  4771. string buyernick = GetPostString("buyer_nick");
  4772. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  4773. string customer = GetPostString("customer");
  4774. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4775. string design = GetPostString("design");
  4776. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4777. string sellermemo = GetPostString("seller_memo");
  4778. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4779. string supplier = GetPostString("supplier");
  4780. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4781. string date1 = GetPostString("date1");
  4782. string date2 = GetPostString("date2");
  4783. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4784. if (dw.Length > 0) lw.Add(dw);
  4785. string placedate1 = GetPostString("placedate1");
  4786. string placedate2 = GetPostString("placedate2");
  4787. string dw_place = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4788. if (dw_place.Length > 0) lw.Add(dw_place);
  4789. string price1 = GetPostString("price1");
  4790. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4791. string price2 = GetPostString("price2");
  4792. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4793. string unusualCon = GetPostString("unusualcon");
  4794. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  4795. string posTag = CurrentUser.UserPost.Post.Code;
  4796. if (posTag == "Supplier")
  4797. {
  4798. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4799. }
  4800. lw.Add(string.Format("OrderState = 6"));
  4801. lw.Add(string.Format("UnusualTag = 5"));
  4802. lw.Add(string.Format("IsRefund<={0}", 1));
  4803. dStruct.Order = "FinishPlaceTime desc";
  4804. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4805. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4806. writeGridDataTableJson(dStruct.TotalCount, dt);
  4807. }
  4808. public void get_erp_deliveryedlist()
  4809. {
  4810. DataStruct dStruct = GetPostStruct();
  4811. List<string> lw = new List<string>();
  4812. string tid = GetPostString("ctid");
  4813. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4814. string shopname = GetPostString("shopname");
  4815. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4816. string buyernick = GetPostString("buyer_nick");
  4817. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4818. string customer = GetPostString("customer");
  4819. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4820. string design = GetPostString("design");
  4821. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4822. string sellermemo = GetPostString("seller_memo");
  4823. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4824. string logistics = GetPostString("logistics");
  4825. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4826. string date1 = GetPostString("date1");
  4827. string date2 = GetPostString("date2");
  4828. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4829. //if (dw.Length > 0) lw.Add(dw);
  4830. string placedate1 = GetPostString("placedate1");
  4831. string placedate2 = GetPostString("placedate2");
  4832. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4833. if (fdw.Length > 0) lw.Add(fdw);
  4834. string devdate1 = GetPostString("deliverydate1");
  4835. string devdate2 = GetPostString("deliverydate2");
  4836. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4837. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4838. string price1 = GetPostString("price1");
  4839. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4840. string price2 = GetPostString("price2");
  4841. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4842. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4843. {
  4844. if (tid.Length > 0)
  4845. {
  4846. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4847. if (tid.Length > 5)
  4848. {
  4849. List<string> tids = getTidByCtidLike(tid);
  4850. if (tids.Count > 0 && tids.Count < 10)
  4851. {
  4852. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4853. }
  4854. }
  4855. lw.Add(tid_sql);
  4856. }
  4857. if (buyernick.Length > 0)
  4858. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4859. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4860. if (dw.Length > 0) lw.Add(dw);
  4861. }
  4862. else
  4863. {
  4864. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  4865. }
  4866. string posTag = CurrentUser.UserPost.Post.Code;
  4867. if (posTag == "Supplier")
  4868. {
  4869. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4870. }
  4871. else
  4872. {
  4873. string supplier = GetPostString("supplier");
  4874. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4875. }
  4876. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4877. lw.Add(string.Format("type != 'PDD' "));
  4878. lw.Add(string.Format("IsRefund!={0}", 2));
  4879. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4880. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4881. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4882. /*if (tid.Length > 0)
  4883. {
  4884. List<string> tids = new List<string>();
  4885. if (dt != null && dt.Rows.Count > 0)
  4886. {
  4887. foreach (DataRow item in dt.Rows)
  4888. {
  4889. tids.Add("'" + item["tid"] + "'");
  4890. }
  4891. }
  4892. if (tids.Count > 0)
  4893. {
  4894. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4895. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4896. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4897. dt = WebCache.GetData("view_erptradecell", dStruct);
  4898. }
  4899. }*/
  4900. if (dt != null)
  4901. {
  4902. foreach (DataRow dr in dt.Rows)
  4903. {
  4904. 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();
  4905. }
  4906. }
  4907. writeGridDataTableJson(dStruct.TotalCount, dt);
  4908. }
  4909. public void get_erp_pdddeliveryed()
  4910. {
  4911. DataStruct dStruct = GetPostStruct();
  4912. List<string> lw = new List<string>();
  4913. string tid = GetPostString("ctid");
  4914. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  4915. string shopname = GetPostString("shopname");
  4916. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  4917. string buyernick = GetPostString("buyer_nick");
  4918. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4919. string customer = GetPostString("customer");
  4920. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  4921. string design = GetPostString("design");
  4922. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  4923. string sellermemo = GetPostString("seller_memo");
  4924. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  4925. string logistics = GetPostString("logistics");
  4926. if (logistics.Length > 0) lw.Add(string.Format("(OutSid like '{0}%')", logistics));
  4927. string date1 = GetPostString("date1");
  4928. string date2 = GetPostString("date2");
  4929. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4930. //if (dw.Length > 0) lw.Add(dw);
  4931. string placedate1 = GetPostString("placedate1");
  4932. string placedate2 = GetPostString("placedate2");
  4933. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  4934. if (fdw.Length > 0) lw.Add(fdw);
  4935. string devdate1 = GetPostString("deliverydate1");
  4936. string devdate2 = GetPostString("deliverydate2");
  4937. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  4938. if (dw_dev.Length > 0) lw.Add(dw_dev);
  4939. string price1 = GetPostString("price1");
  4940. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  4941. string price2 = GetPostString("price2");
  4942. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  4943. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  4944. {
  4945. if (tid.Length > 0)
  4946. {
  4947. string tid_sql = string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%') ", tid);
  4948. if (tid.Length > 5)
  4949. {
  4950. List<string> tids = getTidByCtidLike(tid);
  4951. if (tids.Count > 0 && tids.Count < 10)
  4952. {
  4953. tid_sql = string.Format("tid in ({0}) ", string.Join(",", tids));
  4954. }
  4955. }
  4956. lw.Add(tid_sql);
  4957. }
  4958. if (buyernick.Length > 0)
  4959. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  4960. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  4961. if (dw.Length > 0) lw.Add(dw);
  4962. }
  4963. else
  4964. {
  4965. lw.Add(string.Format("datediff(d,pay_time,getdate())<=61 "));
  4966. }
  4967. string posTag = CurrentUser.UserPost.Post.Code;
  4968. if (posTag == "Supplier")
  4969. {
  4970. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  4971. }
  4972. else
  4973. {
  4974. string supplier = GetPostString("supplier");
  4975. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  4976. }
  4977. lw.Add(string.Format("(OrderState = 7 or OrderState=8)"));
  4978. lw.Add(string.Format("type = 'PDD' "));
  4979. lw.Add(string.Format("IsRefund!={0}", 2));
  4980. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  4981. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4982. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  4983. /* if (tid.Length > 0)
  4984. {
  4985. List<string> tids = new List<string>();
  4986. if (dt != null && dt.Rows.Count > 0)
  4987. {
  4988. foreach (DataRow item in dt.Rows)
  4989. {
  4990. tids.Add("'" + item["tid"] + "'");
  4991. }
  4992. }
  4993. if (tids.Count > 0)
  4994. {
  4995. lw.Remove(string.Format("(ctid like '%{0}%' or OrderSn like '%{0}%')", tid));
  4996. lw.Add(string.Format("tid in ({0})", string.Join(", ", tids)));
  4997. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  4998. dt = WebCache.GetData("view_erptradecell", dStruct);
  4999. }
  5000. }*/
  5001. foreach (DataRow dr in dt.Rows)
  5002. {
  5003. 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();
  5004. }
  5005. writeGridDataTableJson(dStruct.TotalCount, dt);
  5006. }
  5007. public void get_erp_jddeliveryed()
  5008. {
  5009. DataStruct dStruct = GetPostStruct();
  5010. List<string> lw = new List<string>();
  5011. string tid = GetPostString("ctid");
  5012. //if (tid.Length > 0) lw.Add(string.Format("(ctid='{0}' or tid='{0}')", tid));
  5013. string shopname = GetPostString("shopname");
  5014. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5015. string buyernick = GetPostString("buyer_nick");
  5016. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5017. string customer = GetPostString("customer");
  5018. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5019. string design = GetPostString("design");
  5020. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5021. string sellermemo = GetPostString("seller_memo");
  5022. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5023. string date1 = GetPostString("date1");
  5024. string date2 = GetPostString("date2");
  5025. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5026. //if (dw.Length > 0) lw.Add(dw);
  5027. string placedate1 = GetPostString("placedate1");
  5028. string placedate2 = GetPostString("placedate2");
  5029. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  5030. if (fdw.Length > 0) lw.Add(fdw);
  5031. string devdate1 = GetPostString("deliverydate1");
  5032. string devdate2 = GetPostString("deliverydate2");
  5033. string dw_dev = GetDateMinuteWhere("delivery_time", devdate1, devdate2);
  5034. if (dw_dev.Length > 0) lw.Add(dw_dev);
  5035. string price1 = GetPostString("price1");
  5036. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5037. string price2 = GetPostString("price2");
  5038. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5039. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0)
  5040. {
  5041. if (tid.Length > 0)
  5042. lw.Add(string.Format("ctid like '%{0}%'", tid));
  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())<=92 "));
  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 = 'JD' "));
  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. foreach (DataRow dr in dt.Rows)
  5069. {
  5070. 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();
  5071. }
  5072. writeGridDataTableJson(dStruct.TotalCount, dt);
  5073. }
  5074. public void get_erp_allplacelist()
  5075. {
  5076. DataStruct dStruct = GetPostStruct();
  5077. List<string> lw = new List<string>();
  5078. string tid = GetPostString("ctid");
  5079. //if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  5080. string shopname = GetPostString("shopname");
  5081. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5082. string buyernick = GetPostString("buyer_nick");
  5083. //if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5084. string customer = GetPostString("customer");
  5085. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5086. string design = GetPostString("design");
  5087. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5088. string sellermemo = GetPostString("seller_memo");
  5089. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5090. string supplier = GetPostString("supplier");
  5091. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  5092. string date1 = GetPostString("date1");
  5093. string date2 = GetPostString("date2");
  5094. string pldate1 = GetPostString("placedate1");
  5095. string pldate2 = GetPostString("placedate2");
  5096. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5097. //if (dw.Length > 0) lw.Add(dw);
  5098. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5099. {
  5100. if (tid.Length > 0)
  5101. {
  5102. string select_tid = getTidByCtid(tid);
  5103. lw.Add(string.Format("tid='{0}'", select_tid));
  5104. }
  5105. if (buyernick.Length > 0)
  5106. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5107. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5108. if (dw.Length > 0) lw.Add(dw);
  5109. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5110. if (dw_place.Length > 0) lw.Add(dw_place);
  5111. }
  5112. else
  5113. {
  5114. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5115. {
  5116. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5117. }
  5118. }
  5119. string price1 = GetPostString("price1");
  5120. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5121. string price2 = GetPostString("price2");
  5122. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5123. string posTag = CurrentUser.UserPost.Post.Code;
  5124. if (posTag == "Supplier")
  5125. {
  5126. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5127. }
  5128. lw.Add(string.Format("OrderState >= 6"));
  5129. lw.Add(string.Format("IsSample != 2 "));
  5130. //lw.Add(string.Format("isDianziOrder = 0 "));
  5131. lw.Add(string.Format("SupplierId > 0 "));
  5132. //lw.Add(string.Format("IsRefund<={0}", 1));
  5133. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5134. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5135. DataTable dt = WebCache.GetData("view_ErpAllPlace", dStruct);
  5136. foreach (DataRow dr in dt.Rows)
  5137. {
  5138. 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();
  5139. }
  5140. writeGridDataTableJson(dStruct.TotalCount, dt);
  5141. }
  5142. public void get_erp_financeallplacelist()
  5143. {
  5144. DataStruct dStruct = GetPostStruct();
  5145. List<string> lw = new List<string>();
  5146. string tid = GetPostString("ctid");
  5147. string shopname = GetPostString("shopname");
  5148. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  5149. string buyernick = GetPostString("buyer_nick");
  5150. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5151. string customer = GetPostString("customer");
  5152. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5153. string design = GetPostString("design");
  5154. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5155. string sellermemo = GetPostString("seller_memo");
  5156. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5157. string supplier = GetPostString("supplier");
  5158. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5159. string date1 = GetPostString("date1");
  5160. string date2 = GetPostString("date2");
  5161. string pldate1 = GetPostString("placedate1");
  5162. string pldate2 = GetPostString("placedate2");
  5163. if (tid.Length > 0 || date1.Length > 0 || buyernick.Length > 0 || pldate1.Length > 0)
  5164. {
  5165. if (tid.Length > 0)
  5166. {
  5167. string select_tid = getTidByCtid(tid);
  5168. lw.Add(string.Format("tid='{0}'", select_tid));
  5169. }
  5170. if (buyernick.Length > 0)
  5171. lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  5172. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5173. if (dw.Length > 0) lw.Add(dw);
  5174. string dw_place = GetDateMinuteWhere("FinishPlaceTime", pldate1, pldate2);
  5175. if (dw_place.Length > 0) lw.Add(dw_place);
  5176. }
  5177. else
  5178. {
  5179. if (ex_psize <= 0) //非导出的时候 显示3个月数据
  5180. {
  5181. lw.Add(string.Format("datediff(d,pay_time,getdate())<=92 "));
  5182. }
  5183. }
  5184. string price1 = GetPostString("price1");
  5185. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5186. string price2 = GetPostString("price2");
  5187. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5188. string posTag = CurrentUser.UserPost.Post.Code;
  5189. if (posTag == "Supplier")
  5190. {
  5191. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5192. }
  5193. //lw.Add(string.Format("OrderState >= 6"));
  5194. lw.Add(string.Format("IsSample != 2 "));
  5195. lw.Add(string.Format("isDianziOrder = 0 "));
  5196. //lw.Add(string.Format("IsRefund<={0}", 1));
  5197. dStruct.Order = "MemoOpt desc, FinishPlaceTime desc";
  5198. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5199. DataTable dt = WebCache.GetData("view_erptradecell2", dStruct);
  5200. foreach (DataRow dr in dt.Rows)
  5201. {
  5202. 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();
  5203. }
  5204. writeGridDataTableJson(dStruct.TotalCount, dt);
  5205. }
  5206. public void get_erp_expresslist()
  5207. {
  5208. int listtype = GetInt("ltype");
  5209. DataStruct dStruct = GetPostStruct();
  5210. List<string> lw = new List<string>();
  5211. string tid = GetPostString("tid");
  5212. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  5213. string outsid = GetPostString("out_sid");
  5214. if (outsid.Length > 0) lw.Add(string.Format("out_sid like '%{0}%'", outsid));
  5215. string importer = GetPostString("ImportUserName");
  5216. if (importer.Length > 0) lw.Add(string.Format("ImportUserName like '%{0}%'", importer));
  5217. string file = GetPostString("import_file");
  5218. if (file.Length > 0) lw.Add(string.Format("import_file like '%{0}%'", file));
  5219. string printman = GetPostString("printman");
  5220. if (printman.Length > 0) lw.Add(string.Format("printUser like '%{0}%'", printman));
  5221. string date1 = GetPostString("date1");
  5222. string date2 = GetPostString("date2");
  5223. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5224. if (dw.Length > 0) lw.Add(dw);
  5225. string fdate1 = GetPostString("finishdate1");
  5226. string fdate2 = GetPostString("finishdate2");
  5227. string fdw = GetDateMinuteWhere("print_time", fdate1, fdate2);
  5228. if (fdw.Length > 0) lw.Add(fdw);
  5229. string supplierId = GetPostString("supplierId");
  5230. if (supplierId.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplierId));
  5231. if (listtype == 1)
  5232. {
  5233. lw.Add(string.Format("importUserId !=0"));
  5234. }
  5235. string posTag = CurrentUser.UserPost.Post.Code;
  5236. if (posTag == "Supplier")
  5237. {
  5238. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  5239. }
  5240. if (dStruct.PageSize != 100000)
  5241. {
  5242. dStruct.Order = "isMultiDelivery asc, import_time desc";
  5243. }
  5244. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5245. DataTable dt = WebCache.GetData("view_ErpExpressInfo", dStruct);
  5246. writeGridDataTableJson(dStruct.TotalCount, dt);
  5247. }
  5248. public void set_erp_buchaorderdelivery()
  5249. {
  5250. if (UrlPostParmsCheck("ctid"))
  5251. {
  5252. string eid = GetPostString("ctid");
  5253. CeErpTradeCell entity = null;
  5254. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5255. if (entity != null)
  5256. {
  5257. if (entity.IsSample != 2)
  5258. {
  5259. returnErrorMsg("补差价单才能标记为已发货");
  5260. return;
  5261. }
  5262. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记为已发货", entity.OrderState, 1);
  5263. entity.OrderState = 7;
  5264. entity.Update();
  5265. returnSuccessMsg("操作成功!");
  5266. return;
  5267. }
  5268. returnErrorMsg("找不到记录");
  5269. }
  5270. }
  5271. public void get_stdtemplates()
  5272. {
  5273. //string res = taobaoHelper.CainiaoCloudprintStdtemplatesGet(seller_nick);
  5274. //string res = taobaoHelper.test();
  5275. string res = apiHelper.API_PrintTemplate();
  5276. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5277. if (res.IndexOf("error_message") != -1 && res.IndexOf("false") != -1)
  5278. {
  5279. int sidx = res.IndexOf("error_code");
  5280. int eidx = res.IndexOf("success");
  5281. string msg = res.Substring(sidx, eidx - sidx);
  5282. returnErrorMsg(msg);
  5283. return;
  5284. }
  5285. if (res.Length <= 0)
  5286. {
  5287. returnErrorMsg("模板数据为空!");
  5288. return;
  5289. }
  5290. ReturnSuccess(res);
  5291. }
  5292. public void cancel_print_order()
  5293. {
  5294. if (UrlPostParmsCheck("ctid"))
  5295. {
  5296. string ctid = GetPostString("ctid");
  5297. CeErpTradeCell entity = null;
  5298. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5299. if (entity != null)
  5300. {
  5301. string res = "";
  5302. string code = entity.LastBillWaybillCode;
  5303. if (code == "")
  5304. {
  5305. code = entity.OutSid;
  5306. }
  5307. res = apiHelper.API_CancelPrint(entity.LastBillWaybillCode);
  5308. XLog.SaveLog(0, "取消面单" + res);
  5309. }
  5310. }
  5311. }
  5312. public void set_erp_printwaybill()
  5313. {
  5314. if (UrlPostParmsCheck("ctid"))
  5315. {
  5316. string ctid = GetPostString("ctid");
  5317. string cpCode = GetPostString("cpcode"); //"code":"YTO","id":1,"cpCode":"YTO-CAINIAO",
  5318. string cpName = GetPostString("cpname");
  5319. string isTogether = GetPostString("together");
  5320. //var res_obj = new
  5321. //{
  5322. // restype = 1,
  5323. // 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\"}"
  5324. //};
  5325. //string ro_json = JsonConvert.SerializeObject(res_obj);
  5326. //ReturnSuccess(ro_json);
  5327. //return;
  5328. bool isUseLastWayBillCode = false;
  5329. CeErpTradeCell entity = null;
  5330. if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
  5331. if (entity != null)
  5332. {
  5333. if ((entity.OrderState == 7 || entity.OrderState == 6) && entity.LastBillCpCode == cpCode && entity.LastBillWaybillCode != "")
  5334. {
  5335. isUseLastWayBillCode = true;
  5336. }
  5337. if (entity.OrderState == 7 && "2".Equals(isTogether))
  5338. {
  5339. ReturnSuccess(JsonConvert.SerializeObject(new { restype = 2, data = "" }));
  5340. return;
  5341. }
  5342. if (entity.IsSF > 0 && cpCode.IndexOf("SF") == -1)
  5343. {
  5344. returnErrorMsg("此单标记使用顺丰发货,不能使用其他快递");
  5345. return;
  5346. }
  5347. if (entity.IsSF == 0 && cpCode.IndexOf("SF") > -1)
  5348. {
  5349. returnErrorMsg("此单未标记使用顺丰发货,不能使用其他快递");
  5350. return;
  5351. }
  5352. }
  5353. string res = "";
  5354. Api_waybill_code_response_Obj fullObj = null;
  5355. string pData_str = "";
  5356. string curUseWayBillCode = "";
  5357. if (isUseLastWayBillCode == false)
  5358. {
  5359. res = apiHelper.API_GetWaybill(cpCode, ctid);
  5360. //string res = "{"response":{"data":{"content":[{"outerCode":"1909374336748825642","result":true,"waybillCode":"YT5608401979200"}]},"success":true}}";
  5361. if (res.IndexOf("failure") != -1)
  5362. {
  5363. //int idx = res.IndexOf("sub_message");
  5364. //int idx2 = res.IndexOf("flag");
  5365. //string emsg = res.Substring(idx + 14, idx2 - idx - 17);
  5366. string errMsgNeed = commonHelper.KeepChinese(res);
  5367. var res_objd = new
  5368. {
  5369. restype = 0,
  5370. data = "获取面单失败" + errMsgNeed
  5371. };
  5372. string ro_jsond = JsonConvert.SerializeObject(res_objd);
  5373. returnSuccess(ro_jsond);
  5374. if (res.IndexOf("停发") != -1)
  5375. {
  5376. entity.UnusualCon = "物流停发";
  5377. entity.Update();
  5378. }
  5379. //returnErrorMsg("获取面单失败,"+emsg);
  5380. XLog.SaveLog(0, "获取面单失败" + cpCode + ":" + res);
  5381. return;
  5382. }
  5383. else if (res.IndexOf("errorMsg") != -1)
  5384. {
  5385. //int idx = res.IndexOf("errorMsg");
  5386. //int idx2 = res.IndexOf("}]}");
  5387. //string emsg = res.Substring(idx + 11, idx2 - idx - 12);
  5388. string errMsgNeed = commonHelper.KeepChinese(res);
  5389. var res_objf = new
  5390. {
  5391. restype = 0,
  5392. data = "获取面单失败2" + errMsgNeed
  5393. };
  5394. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5395. if (res.IndexOf("停发") != -1)
  5396. {
  5397. entity.UnusualCon = "物流停发";
  5398. entity.Update();
  5399. CeErpTrade trade = CeErpTrade.Get(entity.tid);
  5400. if (trade != null)
  5401. {
  5402. string apires = apiHelper.API_TradeMemoUpdate(trade.tid, trade.posCode, "", trade.seller_memo + "-" + entity.UnusualCon);
  5403. }
  5404. }
  5405. returnSuccess(ro_jsonf);
  5406. //returnErrorMsg("获取面单失败," + emsg);
  5407. XLog.SaveLog(0, "获取面单失败2" + cpCode + ":" + res);
  5408. return;
  5409. }
  5410. try
  5411. {
  5412. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5413. //res = res.Replace(" ", "");
  5414. fullObj = JsonConvert.DeserializeObject<Api_waybill_code_response_Obj>(res);
  5415. }
  5416. catch (Exception ex)
  5417. {
  5418. XLog.SaveLog(0, "生成fullObj" + res);
  5419. var res_objf = new
  5420. {
  5421. restype = 0,
  5422. data = "生成fullObj发生错误" + ex.Message
  5423. };
  5424. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5425. returnSuccess(ro_jsonf);
  5426. return;
  5427. }
  5428. if (fullObj.response.data.content.Count > 0)
  5429. {
  5430. ContentItem codeObj = fullObj.response.data.content[0];
  5431. if (cpCode.IndexOf("SFFQ-") != -1)
  5432. {
  5433. pData_str = apiHelper.API_GetPrintData_SF(codeObj.waybillCode);
  5434. }
  5435. else
  5436. pData_str = apiHelper.API_GetPrintData(codeObj.waybillCode);
  5437. curUseWayBillCode = codeObj.waybillCode;
  5438. }
  5439. else
  5440. {
  5441. XLog.SaveLog(0, "生成fullObj找不到快递单号waybillCode" + res);
  5442. var res_objf = new
  5443. {
  5444. restype = 0,
  5445. data = "生成fullObj找不到快递单号waybillCode"
  5446. };
  5447. string ro_jsonf = JsonConvert.SerializeObject(res_objf);
  5448. returnSuccess(ro_jsonf);
  5449. return;
  5450. }
  5451. }
  5452. else
  5453. {
  5454. //使用上次打印的快递单号
  5455. if (cpCode == "SFFQ-LY")
  5456. {
  5457. pData_str = apiHelper.API_GetPrintData_SF(entity.LastBillWaybillCode);
  5458. }
  5459. else
  5460. pData_str = apiHelper.API_GetPrintData(entity.LastBillWaybillCode);
  5461. curUseWayBillCode = entity.LastBillWaybillCode;
  5462. }
  5463. if (pData_str.IndexOf("props") == -1 && pData_str.IndexOf("printData") == -1)
  5464. {
  5465. var res_obje = new
  5466. {
  5467. restype = 0,
  5468. data = "获取加密打印数据失败"
  5469. };
  5470. string ro_jsone = JsonConvert.SerializeObject(res_obje);
  5471. returnSuccess(ro_jsone);
  5472. entity.LastBillCpCode = cpCode;
  5473. entity.LastBillWaybillCode = curUseWayBillCode;
  5474. entity.Update();
  5475. XLog.SaveLog(0, "获取加密打印数据失败" + curUseWayBillCode + pData_str);
  5476. //returnErrorMsg("获取加密打印数据失败");
  5477. return;
  5478. }
  5479. //string pageUrl = apiHelper.API_GetPrintPage(codeObj.waybillCode,tempId,ctid);
  5480. //string msg = "{\"data\":\""+pageUrl+"\"}";
  5481. string btnType = "";
  5482. string errorMsg = "";
  5483. if (entity != null)
  5484. {
  5485. CeErpTrade mainEn = CeErpTrade.Get(entity.tid);
  5486. //string res = taobaoHelper.LogisticsOnlineSend(sessionkey,entity.tid,comCode,outSid);
  5487. //cpcode是 YTO-CAINIAO
  5488. //string comCode = cpCode.Split('-')[0].ToString();
  5489. string apires = "";
  5490. string supplierName = commonHelper.getSupplierNameById(entity.SupplierId);
  5491. //isTogether=2是新的合包弹窗
  5492. if ((!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 1) || (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 0) || string.IsNullOrEmpty(isTogether))
  5493. {
  5494. if (ctid.IndexOf("N") != -1)
  5495. {
  5496. apires = "发货成功";
  5497. }
  5498. else
  5499. {
  5500. apires = apiHelper.API_LogisticsOnlineSend(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5501. }
  5502. //string apires = apiHelper.API_LogisticsOnlineSend(entity.tid, mainEn.posCode, cpCode, codeObj.waybillCode);
  5503. //打单后发货
  5504. if (mainEn != null && entity.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5505. {
  5506. try
  5507. {
  5508. btnType = "待发货";
  5509. entity.OutSid = curUseWayBillCode;
  5510. entity.OrderState = 7;
  5511. entity.IsUrgency = false;
  5512. entity.LastBillCpCode = "";
  5513. entity.LastBillWaybillCode = "";
  5514. entity.FinishDeliveryTime = DateTime.Now;
  5515. entity.IsReturn = 0;
  5516. entity.MemoOpt = 0;
  5517. entity.UpdateTime = DateTime.Now;
  5518. entity.Update();
  5519. commonHelper.aftersaleSend(entity.ctid, cpCode, curUseWayBillCode);
  5520. //还要插入快递信息到 快递信息表
  5521. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5522. exinfo.tid = entity.ctid;
  5523. exinfo.out_sid = curUseWayBillCode;
  5524. exinfo.company_code = cpCode;
  5525. exinfo.company_name = cpName;
  5526. exinfo.supplierUserName = supplierName;
  5527. exinfo.deliveryType = "发货成功";
  5528. exinfo.print_time = DateTime.Now;
  5529. exinfo.printUser = CurrentUser.UserName;
  5530. exinfo.postData = pData_str;
  5531. exinfo.Create();
  5532. commonHelper.UpdateRelationOrder(entity.ctid);
  5533. CeErpSukuraData.createInfo(ctid, 4);
  5534. commonHelper.insertToBuchaForDelivery(mainEn.tid, mainEn.posCode, cpCode, curUseWayBillCode);
  5535. if (entity.SupplierId == 64)
  5536. {
  5537. commonHelper.sendCytExpress(exinfo);
  5538. }
  5539. LogHelper.addLog(ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5540. if (!string.IsNullOrEmpty(isTogether))
  5541. {
  5542. if (Convert.ToInt32(isTogether) > 0)
  5543. {
  5544. StringBuilder sqlsb = new StringBuilder();
  5545. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}' where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5546. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5547. }
  5548. }
  5549. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5550. }
  5551. catch (Exception ex)
  5552. {
  5553. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5554. }
  5555. }
  5556. else if (mainEn.status == "SHIPPED" || mainEn.status == "PART_SHIPPED" || entity.OrderState >= 7) //已发货的不处理直接返回面单
  5557. {
  5558. entity.OutSid = (entity.OutSid + "," + curUseWayBillCode);
  5559. if (entity.OrderState == 6)
  5560. {
  5561. entity.OrderState = 7;
  5562. }
  5563. entity.UpdateTime = DateTime.Now;
  5564. entity.FinishDeliveryTime = DateTime.Now;
  5565. btnType = "已发货";
  5566. entity.Update();
  5567. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5568. exinfo.tid = entity.ctid;
  5569. exinfo.out_sid = curUseWayBillCode;
  5570. exinfo.company_code = cpCode;
  5571. exinfo.company_name = cpName;
  5572. exinfo.supplierUserName = supplierName;
  5573. exinfo.deliveryType = "发货成功";
  5574. exinfo.print_time = DateTime.Now;
  5575. exinfo.printUser = CurrentUser.UserName;
  5576. exinfo.postData = pData_str;
  5577. exinfo.Create();
  5578. commonHelper.UpdateRelationOrder(entity.ctid);
  5579. CeErpSukuraData.createInfo(entity.ctid, 4);
  5580. if (entity.SupplierId == 64)
  5581. {
  5582. commonHelper.sendCytExpress(exinfo);
  5583. }
  5584. if (!string.IsNullOrEmpty(isTogether))
  5585. {
  5586. if (Convert.ToInt32(isTogether) > 0)
  5587. {
  5588. StringBuilder sqlsb = new StringBuilder();
  5589. sqlsb.AppendFormat("update ce_erptradecell with(rowlock) set OrderState=7,OutSid='{2}',FinishDeliveryTime=GETDATE(),UpdateTime=GETDATE() where tid='{0}' and OrderState=6 and SupplierId={1}", entity.tid, entity.SupplierId, curUseWayBillCode);
  5590. DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
  5591. }
  5592. }
  5593. //不处理
  5594. }
  5595. else
  5596. {
  5597. entity.UpdateTime = DateTime.Now;
  5598. entity.LastBillCpCode = cpCode;
  5599. entity.LastBillWaybillCode = curUseWayBillCode;
  5600. entity.Update();
  5601. string errmsg = commonHelper.KeepChinese(apires);
  5602. var res_objz = new
  5603. {
  5604. restype = 0,
  5605. data = "打单后发货失败"
  5606. };
  5607. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5608. returnSuccess(ro_jsonz);
  5609. //returnErrorMsg("同步淘宝发货失败!"+ errmsg);
  5610. XLog.SaveLog(0, "打单后发货失败," + entity.tid + "," + curUseWayBillCode + "," + apires);
  5611. return;
  5612. }
  5613. }
  5614. else if (!string.IsNullOrEmpty(isTogether) && Convert.ToInt32(isTogether) == 2)
  5615. {
  5616. DataTable dt = getSameOrderList(entity, mainEn);
  5617. List<string> list = new List<string>();
  5618. List<string> send_list = new List<string>();
  5619. CeErpTradeCell ceErpTradeCell = new CeErpTradeCell();
  5620. CeErpTrade ceErpTrade = new CeErpTrade();
  5621. //可合包的合并一起发货
  5622. if (dt == null)
  5623. {
  5624. var res_objz = new
  5625. {
  5626. restype = 0,
  5627. data = "打单后发货失败"
  5628. };
  5629. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5630. returnSuccess(ro_jsonz);
  5631. return;
  5632. }
  5633. foreach (DataRow row in dt.Rows)
  5634. {
  5635. list.Add("'" + row["ctid"] + "'");
  5636. ceErpTradeCell = CeErpTradeCell.GetByCtid(row["ctid"].ToString());
  5637. ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  5638. if (ctid.IndexOf("N") != -1)
  5639. {
  5640. apires = "发货成功";
  5641. }
  5642. else
  5643. {
  5644. if (!send_list.Contains(ceErpTrade.tid))
  5645. {
  5646. apires = apiHelper.API_LogisticsOnlineSend(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5647. }
  5648. else
  5649. {
  5650. apires = "发货成功";
  5651. }
  5652. }
  5653. if (ceErpTrade != null && ceErpTradeCell.OrderState == 6 && apires.IndexOf("发货成功") != -1)
  5654. {
  5655. send_list.Add(ceErpTrade.tid);
  5656. try
  5657. {
  5658. btnType = "待发货";
  5659. ceErpTradeCell.OutSid = curUseWayBillCode;
  5660. ceErpTradeCell.OrderState = 7;
  5661. ceErpTradeCell.IsUrgency = false;
  5662. ceErpTradeCell.LastBillCpCode = "";
  5663. ceErpTradeCell.LastBillWaybillCode = "";
  5664. ceErpTradeCell.FinishDeliveryTime = DateTime.Now;
  5665. ceErpTradeCell.IsReturn = 0;
  5666. ceErpTradeCell.MemoOpt = 0;
  5667. ceErpTradeCell.UpdateTime = DateTime.Now;
  5668. ceErpTradeCell.Update();
  5669. commonHelper.aftersaleSend(ceErpTradeCell.ctid, cpCode, curUseWayBillCode);
  5670. //还要插入快递信息到 快递信息表
  5671. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5672. exinfo.tid = ceErpTradeCell.ctid;
  5673. exinfo.out_sid = curUseWayBillCode;
  5674. exinfo.company_code = cpCode;
  5675. exinfo.company_name = cpName;
  5676. exinfo.supplierUserName = supplierName;
  5677. exinfo.deliveryType = "发货成功";
  5678. exinfo.print_time = DateTime.Now;
  5679. exinfo.printUser = CurrentUser.UserName;
  5680. exinfo.postData = pData_str;
  5681. exinfo.Create();
  5682. commonHelper.UpdateRelationOrder(ceErpTradeCell.ctid);
  5683. CeErpSukuraData.createInfo(ctid, 4);
  5684. commonHelper.insertToBuchaForDelivery(ceErpTrade.tid, ceErpTrade.posCode, cpCode, curUseWayBillCode);
  5685. if (ceErpTradeCell.SupplierId == 64)
  5686. {
  5687. commonHelper.sendCytExpress(exinfo);
  5688. }
  5689. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "发货成功-" + cpCode + "-" + curUseWayBillCode);
  5690. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5691. }
  5692. catch (Exception ex)
  5693. {
  5694. XLog.SaveLog(0, "发货成功后更新数据失败," + ex.Message);
  5695. }
  5696. }
  5697. else
  5698. {
  5699. ceErpTradeCell.UpdateTime = DateTime.Now;
  5700. ceErpTradeCell.LastBillCpCode = cpCode;
  5701. ceErpTradeCell.LastBillWaybillCode = curUseWayBillCode;
  5702. ceErpTradeCell.Update();
  5703. string errmsg = commonHelper.KeepChinese(apires);
  5704. XLog.SaveLog(0, "打单后发货失败," + ceErpTradeCell.tid + "," + curUseWayBillCode + "," + apires);
  5705. errorMsg += ceErpTradeCell.tid + ":" + apires + ";";
  5706. }
  5707. }
  5708. DbHelper.DbConn.ExecuteNonQuery(string.Format("update CE_ErpDeliverMark with(rowlock) set isDel=1 where ctid in ({0})", string.Join(",", list)));
  5709. }
  5710. }
  5711. LogHelper.addLog(ctid, CurrentUser.UserID, btnType + "打单-" + cpCode + "-" + curUseWayBillCode);
  5712. var res_obj = new
  5713. {
  5714. restype = 1,
  5715. data = pData_str,
  5716. errorMsg
  5717. };
  5718. string ro_json = JsonConvert.SerializeObject(res_obj);
  5719. ReturnSuccess(ro_json);
  5720. return;
  5721. }
  5722. }
  5723. private string GetUTF8String(byte[] vs)
  5724. {
  5725. throw new NotImplementedException();
  5726. }
  5727. public void set_erp_printwaybill_cn()
  5728. {
  5729. if (UrlPostParmsCheck("ctid"))
  5730. {
  5731. string ctid = GetPostString("ctid");
  5732. string cpCode = GetPostString("cpcode");
  5733. string cpName = GetPostString("cpname");
  5734. string tempUrl = GetPostString("tempurl");
  5735. //string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5736. string res = cainiaoLink.TMS_WAYBILL_GET(cpCode, cpName, tempUrl, ctid);
  5737. //string res = taobaoHelper.test();
  5738. res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5739. if (res.IndexOf("false") != -1 && res.IndexOf("errorCode") != -1)
  5740. {
  5741. int sidx = res.IndexOf("errorMsg");
  5742. int eidx = res.IndexOf("}");
  5743. string msg = res.Substring(sidx + 11, eidx - 12 - sidx);
  5744. var res_objzxx = new
  5745. {
  5746. restype = 0,
  5747. data = msg
  5748. };
  5749. string ro_jsonzxx = JsonConvert.SerializeObject(res_objzxx);
  5750. returnSuccess(ro_jsonzxx);
  5751. //returnErrorMsg(msg);
  5752. return;
  5753. }
  5754. int idx = res.IndexOf("waybillCode");
  5755. int idx2 = res.IndexOf("printData");
  5756. string outsid = res.Substring(idx + 14, idx2 - idx - 17);
  5757. string eid = GetPostString("ctid");
  5758. CeErpTradeCell entity = null;
  5759. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5760. if (entity != null)
  5761. {
  5762. string osid = entity.OutSid;
  5763. entity.OutSid = osid + "," + outsid;
  5764. entity.FinishDeliveryTime = DateTime.Now;
  5765. entity.OrderState = 7;
  5766. entity.UpdateTime = DateTime.Now;
  5767. entity.IsReturn = 0;
  5768. entity.Update();
  5769. CeErpExpressInfo exinfo = new CeErpExpressInfo();
  5770. exinfo.tid = entity.ctid;
  5771. exinfo.out_sid = outsid;
  5772. exinfo.company_code = cpCode;
  5773. exinfo.company_name = cpName;
  5774. exinfo.supplierUserName = commonHelper.getSupplierNameById(entity.SupplierId);
  5775. exinfo.deliveryType = "发货成功";
  5776. exinfo.print_time = DateTime.Now;
  5777. exinfo.printUser = CurrentUser.UserName;
  5778. exinfo.Create();
  5779. if (entity.SupplierId == 64)
  5780. {
  5781. commonHelper.sendCytExpress(exinfo);
  5782. }
  5783. //CeErpDataSendOrderInfo.createObject(entity.ctid);
  5784. }
  5785. LogHelper.addLog(ctid, CurrentUser.UserID, "菜鸟打单-" + cpCode + "-" + outsid);
  5786. var res_objz = new
  5787. {
  5788. restype = 1,
  5789. data = res
  5790. };
  5791. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  5792. returnSuccess(ro_jsonz);
  5793. //ReturnSuccess(res);
  5794. }
  5795. }
  5796. ////打单,打印面单 获取面单号
  5797. //public void set_erp_printwaybill()
  5798. //{
  5799. // if (UrlPostParmsCheck("ctid"))
  5800. // {
  5801. // string ctid = GetPostString("ctid");
  5802. // string cpCode = GetPostString("cpcode");
  5803. // string tempUrl = GetPostString("tempurl");
  5804. // string res = taobaoHelper.CainiaoWaybillIiGet(cpCode, tempUrl, ctid);
  5805. // //string res = taobaoHelper.test();
  5806. // res = tmcHelper.GetUTF8String(Encoding.UTF8.GetBytes(res));
  5807. // if (res.IndexOf("error_response") != -1)
  5808. // {
  5809. // int sidx = res.IndexOf("sub_msg");
  5810. // int eidx = res.IndexOf("request_id");
  5811. // string msg = res.Substring(sidx + 10, eidx - 13 - sidx);
  5812. // returnErrorMsg(msg);
  5813. // return;
  5814. // }
  5815. // int idx = res.IndexOf("waybill_code");
  5816. // int idx2 = res.IndexOf("}]}");
  5817. // string outsid = res.Substring(idx + 16, idx2 - idx - 17);
  5818. // LogHelper.addLog(ctid, CurrentUser.UserID, "打单-" + cpCode + "-" + outsid);
  5819. // ReturnSuccess(res);
  5820. // }
  5821. //}
  5822. public void cancel_erp_aftersale()
  5823. {
  5824. if (UrlPostParmsCheck("ctid"))
  5825. {
  5826. string eid = GetPostString("ctid");
  5827. CeErpTradeCell entity = null;
  5828. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  5829. if (entity != null)
  5830. {
  5831. //有过处理的售后,取消也不能删除 售 字,保留
  5832. if (entity.AfterSaleUserId > 0 || entity.AfterSaleMethod.Length > 0 || entity.HandleTime != null)
  5833. {
  5834. entity.AfterSaleState = 4;
  5835. }
  5836. else
  5837. entity.AfterSaleState = 0;
  5838. entity.UpdateTime = DateTime.Now;
  5839. entity.Update();
  5840. returnSuccessMsg("操作成功!");
  5841. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消售后移出", entity.OrderState, 1);
  5842. return;
  5843. }
  5844. returnErrorMsg("找不到订单记录");
  5845. }
  5846. }
  5847. public void get_erp_aftersalelist()
  5848. {
  5849. DataStruct dStruct = GetPostStruct();
  5850. List<string> lw = new List<string>();
  5851. int st = GetInt("st");
  5852. string tid = GetPostString("ctid");
  5853. if (st == 3)
  5854. {
  5855. if (tid.Length > 0)
  5856. {
  5857. string select_tid = getTidByCtid(tid);
  5858. lw.Add(string.Format("tid='{0}'", select_tid));
  5859. }
  5860. }
  5861. else
  5862. {
  5863. if (tid.Length > 0)
  5864. {
  5865. string select_tid = getTidByCtid(tid);
  5866. lw.Add(string.Format("tid='{0}'", select_tid));
  5867. }
  5868. }
  5869. string shopname = GetPostString("shopname");
  5870. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  5871. string buyernick = GetPostString("buyer_nick");
  5872. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick = '{0}'", buyernick));
  5873. string sellermemo = GetPostString("seller_memo");
  5874. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  5875. string orderState = GetPostString("orderState");
  5876. if (orderState.Length > 0) lw.Add(string.Format("OrderState = '{0}'", orderState));
  5877. string afterState = GetPostString("afterstate");
  5878. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  5879. string date1 = GetPostString("date1");
  5880. string date2 = GetPostString("date2");
  5881. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  5882. if (dw.Length > 0) lw.Add(dw);
  5883. string price1 = GetPostString("price1");
  5884. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  5885. string price2 = GetPostString("price2");
  5886. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  5887. //lw.Add(string.Format("IsRefund!={0}", 1));
  5888. string reason = GetPostString("reason");
  5889. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  5890. string method = GetPostString("method");
  5891. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  5892. string handler = GetPostString("handler");
  5893. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  5894. string handledate1 = GetPostString("handledate1");
  5895. string handledate2 = GetPostString("handledate2");
  5896. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  5897. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  5898. string finish1 = GetPostString("finishdate1");
  5899. string finish2 = GetPostString("finishdate2");
  5900. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  5901. if (dwfinish.Length > 0) lw.Add(dwfinish);
  5902. string afterdate1 = GetPostString("afterdate1");
  5903. string afterdate2 = GetPostString("afterdate2");
  5904. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  5905. if (afterDate.Length > 0) lw.Add(afterDate);
  5906. string supplier = GetPostString("supplier");
  5907. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  5908. string responsible = GetPostString("responsibleman");
  5909. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  5910. string customer = GetPostString("customer");
  5911. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  5912. string design = GetPostString("design");
  5913. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  5914. string afterMemoType = GetPostString("aftermemotype");
  5915. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  5916. string posCode = CurrentUser.UserPost.Post.Code;
  5917. //if (st == 3) //3待审核,到售后责任人表里面获取自己的审核列表
  5918. //{
  5919. // string vstate = GetPostString("vstate");
  5920. // if (vstate.Length > 0)
  5921. // {
  5922. // lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  5923. // }
  5924. // if (posCode == "Supplier")
  5925. // {
  5926. // lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  5927. // lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  5928. // dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  5929. // }
  5930. // else
  5931. // {
  5932. // lw.Add(string.Format("AfterSaleState = {0}", st));
  5933. // if (posCode != "Director" && posCode != "SysAdmin" && posCode != "AfterSaleMaster" && posCode != "DesignerMr" && posCode != "AfterSale"
  5934. // && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr")
  5935. // {
  5936. // lw.Add(string.Format("UserId = {0}", CurrentUser.UserID));
  5937. // }
  5938. // else if (CurrentUser.UserPost.Post.Code == "DesignerMr")
  5939. // {
  5940. // int orgid = CurrentUser.UserPost.OrgID;
  5941. // lw.Add(string.Format("( (OrgID={0} and IsArbitrate=1) or UserId={1})", orgid, CurrentUser.UserID));
  5942. // }
  5943. // else if (CurrentUser.UserPost.Post.Code == "Director")
  5944. // {
  5945. // string shopid = CurrentUser.User.pemShop;
  5946. // lw.Add(string.Format("shopId in ({0})", shopid));
  5947. // }
  5948. // //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  5949. // //{
  5950. // // int org_id = CurrentUser.UserPost.OrgID;
  5951. // // lw.Add(string.Format("OrgID={0}", org_id));
  5952. // //}
  5953. // dStruct.Order = "IsArbitrate desc, createdTime desc";
  5954. // }
  5955. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  5956. // DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  5957. // writeGridDataTableJson(dStruct.TotalCount, dt);
  5958. //}
  5959. if (st == 5)
  5960. {
  5961. if (posCode != "SysAdmin" && posCode != "Summarize" && posCode != "Finance" && posCode != "PlaceMr") //管理员 组织部 财务部看全部,不需要进来加条件
  5962. {
  5963. if (posCode == "Director" || posCode == "AfterSaleMaster" || posCode == "AfterSale" || posCode == "CustomerMr")//店长、售后 关联店铺
  5964. {
  5965. string shopid = CurrentUser.User.pemShop;
  5966. lw.Add(string.Format("shopId in ({0})", shopid));
  5967. }
  5968. else if (posCode == "DesignerMr" || posCode == "wxDesignerMr") //设计主管、下单主管同部门
  5969. {
  5970. int mrOrgid = CurrentUser.UserPost.OrgID;
  5971. lw.Add(string.Format("DesOrgID={0}", mrOrgid));
  5972. lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", "设计"));
  5973. }
  5974. //else if (posCode == "PlaceMr") //设计主管、下单主管同部门
  5975. //{
  5976. // int mrOrgid = CurrentUser.UserPost.OrgID;
  5977. // lw.Add(string.Format("PlaceOrgID={0}", mrOrgid));
  5978. //}
  5979. else
  5980. {
  5981. string userIdStr = "";
  5982. if (posCode == "CustomerService")
  5983. {
  5984. userIdStr = CurrentUser.UserID + "_k";
  5985. }
  5986. else if (posCode == "Designer" || posCode == "wxDesigner")
  5987. {
  5988. userIdStr = CurrentUser.UserID + "_s";
  5989. }
  5990. else if (posCode == "Place")
  5991. {
  5992. userIdStr = CurrentUser.UserID + "_x";
  5993. }
  5994. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + userIdStr));
  5995. }
  5996. }
  5997. string placedate1 = GetPostString("placedate1");
  5998. string placedate2 = GetPostString("placedate2");
  5999. string dwplace = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  6000. if (dwplace.Length > 0) lw.Add(dwplace);
  6001. string supState = GetPostString("supState");
  6002. if (supState.Length > 0) lw.Add(string.Format("AfterSaleSupplierState='{0}'", supState));
  6003. string searchType = GetPostString("searchType");
  6004. if (searchType.Length > 0 && "moreBack".Equals(searchType))
  6005. {
  6006. lw.Add(string.Format("BackNum>1"));
  6007. }
  6008. lw.Add(string.Format("AfterSaleState>0"));
  6009. if (ex_psize > 0)
  6010. {
  6011. if (CurrentUser.UserPost.Post.Code == "Finance")
  6012. dStruct.Order = "pay_time desc";
  6013. else
  6014. dStruct.Order = "HandleTime desc";
  6015. }
  6016. else
  6017. dStruct.Order = "HandleTime desc";
  6018. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6019. DataTable dt = WebCache.GetData("view_test", dStruct);
  6020. writeGridDataTableJson(dStruct.TotalCount, dt);
  6021. }
  6022. //else if (st == 4)//已完成的售后(客服设计师要看自己已完成的售后)
  6023. //{
  6024. // lw.Add(string.Format("AfterSaleState=4"));
  6025. // string code = CurrentUser.UserPost.Post.Code;
  6026. // if (code == "CustomerService")
  6027. // {
  6028. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  6029. // }
  6030. // else if (code == "Designer" || code == "DesignerMr")
  6031. // {
  6032. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  6033. // }
  6034. // else if (code == "Place" || code == "PlaceMr")
  6035. // {
  6036. // lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  6037. // }
  6038. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6039. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6040. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6041. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6042. //}
  6043. //else //处理中的售后,待处理和处理中合并
  6044. //{
  6045. // if (afterState.Length <= 0)
  6046. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6047. // dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6048. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6049. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6050. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6051. //}
  6052. }
  6053. public void get_erp_disagreeftersalelist()
  6054. {
  6055. DataStruct dStruct = GetPostStruct();
  6056. List<string> lw = new List<string>();
  6057. int st = 2;
  6058. string tid = GetPostString("ctid");
  6059. if (tid.Length > 0)
  6060. {
  6061. string select_tid = getTidByCtid(tid);
  6062. lw.Add(string.Format("tid='{0}'", select_tid));
  6063. }
  6064. string shopname = GetPostString("shopname");
  6065. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6066. string buyernick = GetPostString("buyer_nick");
  6067. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6068. string sellermemo = GetPostString("seller_memo");
  6069. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6070. string orderState = GetPostString("orderState");
  6071. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6072. string afterState = GetPostString("afterstate");
  6073. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6074. string date1 = GetPostString("date1");
  6075. string date2 = GetPostString("date2");
  6076. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6077. if (dw.Length > 0) lw.Add(dw);
  6078. string price1 = GetPostString("price1");
  6079. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6080. string price2 = GetPostString("price2");
  6081. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6082. //lw.Add(string.Format("IsRefund!={0}", 1));
  6083. string reason = GetPostString("reason");
  6084. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6085. string method = GetPostString("method");
  6086. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6087. string handler = GetPostString("handler");
  6088. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6089. string handledate1 = GetPostString("handledate1");
  6090. string handledate2 = GetPostString("handledate2");
  6091. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6092. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6093. string afterdate1 = GetPostString("afterdate1");
  6094. string afterdate2 = GetPostString("afterdate2");
  6095. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6096. if (afterDate.Length > 0) lw.Add(afterDate);
  6097. string backdate1 = GetPostString("backdate1");
  6098. string backdate2 = GetPostString("backdate2");
  6099. string backDate = GetDateMinuteWhere("DisagreeTime", backdate1, backdate2);
  6100. if (backDate.Length > 0) lw.Add(backDate);
  6101. string supplier = GetPostString("supplier");
  6102. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  6103. string responsible = GetPostString("responsibleman");
  6104. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6105. string customer = GetPostString("customer");
  6106. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6107. string design = GetPostString("design");
  6108. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6109. string afterSaleMemo = GetPostString("afterSaleMemo");
  6110. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6111. string afterMemoType = GetPostString("aftermemotype");
  6112. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6113. string aftersakereason = GetPostString("aftersakereason");
  6114. if (aftersakereason.Length > 0)
  6115. {
  6116. if (aftersakereason == "1")
  6117. {
  6118. lw.Add(string.Format("AfterSaleResSupId > 0"));
  6119. }
  6120. if (aftersakereason == "2")
  6121. {
  6122. lw.Add(string.Format("AfterSaleResSupId = 0"));
  6123. }
  6124. }
  6125. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6126. string poscode = CurrentUser.UserPost.Post.Code;
  6127. if (poscode != "SysAdmin")
  6128. {
  6129. string shopid = CurrentUser.User.pemShop;
  6130. lw.Add(string.Format("shopId in ({0})", shopid));
  6131. }
  6132. string searchType = GetPostString("searchType");
  6133. if (searchType == "wait")
  6134. {
  6135. lw.Add(string.Format("HandleTime is null"));
  6136. }
  6137. if (searchType == "handling")
  6138. {
  6139. lw.Add(string.Format("HandleTime is not null "));
  6140. }
  6141. if (searchType == "back" || searchType == "puBack")
  6142. {
  6143. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6144. }
  6145. if (searchType == "reBack")
  6146. {
  6147. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6148. }
  6149. if (searchType == "moreBack")
  6150. {
  6151. lw.Add(string.Format("backNum > 1"));
  6152. }
  6153. lw.Add(string.Format("(AfterSaleState=5)"));
  6154. dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime asc";
  6155. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6156. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6157. writeGridDataTableJson(dStruct.TotalCount, dt);
  6158. }
  6159. public void get_erp_handlingaftersalelist()
  6160. {
  6161. DataStruct dStruct = GetPostStruct();
  6162. List<string> lw = new List<string>();
  6163. int st = 2;
  6164. string tid = GetPostString("ctid");
  6165. if (tid.Length > 0)
  6166. {
  6167. string select_tid = getTidByCtid(tid);
  6168. lw.Add(string.Format("tid='{0}'", select_tid));
  6169. }
  6170. string shopname = GetPostString("shopname");
  6171. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6172. string buyernick = GetPostString("buyer_nick");
  6173. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6174. string sellermemo = GetPostString("seller_memo");
  6175. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6176. string orderState = GetPostString("orderState");
  6177. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6178. string afterState = GetPostString("afterstate");
  6179. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6180. string date1 = GetPostString("date1");
  6181. string date2 = GetPostString("date2");
  6182. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6183. if (dw.Length > 0) lw.Add(dw);
  6184. string price1 = GetPostString("price1");
  6185. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6186. string price2 = GetPostString("price2");
  6187. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6188. //lw.Add(string.Format("IsRefund!={0}", 1));
  6189. string reason = GetPostString("reason");
  6190. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6191. string method = GetPostString("method");
  6192. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6193. string handler = GetPostString("handler");
  6194. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6195. string handledate1 = GetPostString("handledate1");
  6196. string handledate2 = GetPostString("handledate2");
  6197. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6198. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6199. string afterdate1 = GetPostString("afterdate1");
  6200. string afterdate2 = GetPostString("afterdate2");
  6201. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6202. if (afterDate.Length > 0) lw.Add(afterDate);
  6203. string supplier = GetPostString("supplier");
  6204. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6205. string responsible = GetPostString("responsibleman");
  6206. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6207. string customer = GetPostString("customer");
  6208. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6209. string design = GetPostString("design");
  6210. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6211. string afterSaleMemo = GetPostString("afterSaleMemo");
  6212. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  6213. string afterMemoType = GetPostString("aftermemotype");
  6214. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6215. string afterresult = GetPostString("afterresult");
  6216. if (afterresult.Length > 0) lw.Add(string.Format("TextResult='{0}'", afterresult));
  6217. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  6218. string poscode = CurrentUser.UserPost.Post.Code;
  6219. if (poscode != "SysAdmin")
  6220. {
  6221. string shopid = CurrentUser.User.pemShop;
  6222. lw.Add(string.Format("shopId in ({0})", shopid));
  6223. }
  6224. string searchType = GetPostString("searchType");
  6225. if (searchType == "wait")
  6226. {
  6227. lw.Add(string.Format("HandleTime is null"));
  6228. }
  6229. if (searchType == "documentary")
  6230. {
  6231. lw.Add(string.Format("HandleTime is not null and TextResult in ('重印-转设计师','重印-转下单员') AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' "));
  6232. }
  6233. if (searchType == "handling")
  6234. {
  6235. lw.Add(string.Format("HandleTime is not null AND AfterSaleBackReason = '' AND AfterSaleSupplierMemo = '' and TextResult in ('','联系不上客户','无需售后','退差价','退款','加购','包邮顺丰','退款+退快递费','下单后退款,重拍+包邮顺丰','下单后退款,重拍','待处理','催发货/改快递/改地址','退差价+包邮顺丰')"));
  6236. }
  6237. if (searchType == "back" || searchType == "puBack")
  6238. {
  6239. lw.Add(string.Format("AfterSaleBackReason != ''"));
  6240. }
  6241. if (searchType == "reBack")
  6242. {
  6243. lw.Add(string.Format("AfterSaleSupplierMemo != ''"));
  6244. }
  6245. if (afterState.Length <= 0)
  6246. {
  6247. lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6248. }
  6249. dStruct.Order = "returnVisit desc,case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6250. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6251. DataTable dt = WebCache.GetData("view_AfterSaleList", dStruct);
  6252. writeGridDataTableJson(dStruct.TotalCount, dt);
  6253. }
  6254. //获取退回的处理中的售后列表(朱莉叶、蓝金花用)
  6255. //public void get_erp_back_handlingaftersalelist()
  6256. //{
  6257. // DataStruct dStruct = GetPostStruct();
  6258. // List<string> lw = new List<string>();
  6259. // string tid = GetPostString("ctid");
  6260. // if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  6261. // string shopname = GetPostString("shopname");
  6262. // if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6263. // string buyernick = GetPostString("buyer_nick");
  6264. // if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6265. // string sellermemo = GetPostString("seller_memo");
  6266. // if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6267. // string orderState = GetPostString("orderState");
  6268. // if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6269. // string afterState = GetPostString("afterstate");
  6270. // if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  6271. // string date1 = GetPostString("date1");
  6272. // string date2 = GetPostString("date2");
  6273. // string dw = GetDateMinuteWhere("pay_time", date1, date2);
  6274. // if (dw.Length > 0) lw.Add(dw);
  6275. // string price1 = GetPostString("price1");
  6276. // if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  6277. // string price2 = GetPostString("price2");
  6278. // if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  6279. // //lw.Add(string.Format("IsRefund!={0}", 1));
  6280. // string reason = GetPostString("reason");
  6281. // if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6282. // string method = GetPostString("method");
  6283. // if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6284. // string handler = GetPostString("handler");
  6285. // if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6286. // string handledate1 = GetPostString("handledate1");
  6287. // string handledate2 = GetPostString("handledate2");
  6288. // string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6289. // if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6290. // string afterdate1 = GetPostString("afterdate1");
  6291. // string afterdate2 = GetPostString("afterdate2");
  6292. // string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  6293. // if (afterDate.Length > 0) lw.Add(afterDate);
  6294. // string supplier = GetPostString("supplier");
  6295. // if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6296. // string responsible = GetPostString("responsibleman");
  6297. // if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6298. // string customer = GetPostString("customer");
  6299. // if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  6300. // string design = GetPostString("design");
  6301. // if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  6302. // string afterMemoType = GetPostString("aftermemotype");
  6303. // if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  6304. // lw.Add(string.Format("IsArbitrate = '{0}'", 2));
  6305. // if (afterState.Length <= 0)
  6306. // lw.Add(string.Format("(AfterSaleState=1 or AfterSaleState=2)"));
  6307. // dStruct.Order = "case when AfterSaleSupplierState = 2 then 1 when AfterSaleSupplierState = 0 then 2 when AfterSaleSupplierState = 1 then 3 end asc, AfterSaleTime desc";
  6308. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6309. // DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  6310. // writeGridDataTableJson(dStruct.TotalCount, dt);
  6311. //}
  6312. public void get_erp_aftersaleverifylist()
  6313. {
  6314. DataStruct dStruct = GetPostStruct();
  6315. List<string> lw = new List<string>();
  6316. string tid = GetPostString("ctid");
  6317. if (tid.Length > 0)
  6318. {
  6319. string select_tid = getTidByCtid(tid);
  6320. lw.Add(string.Format("tid='{0}'", select_tid));
  6321. }
  6322. string shopname = GetPostString("shopname");
  6323. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6324. string buyernick = GetPostString("buyer_nick");
  6325. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6326. string sellermemo = GetPostString("seller_memo");
  6327. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  6328. string orderState = GetPostString("orderState");
  6329. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  6330. //lw.Add(string.Format("IsRefund!={0}", 1));
  6331. string reason = GetPostString("reason");
  6332. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6333. string method = GetPostString("method");
  6334. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6335. string handler = GetPostString("handler");
  6336. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6337. string handledate1 = GetPostString("handledate1");
  6338. string handledate2 = GetPostString("handledate2");
  6339. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6340. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6341. string finish1 = GetPostString("finishdate1");
  6342. string finish2 = GetPostString("finishdate2");
  6343. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6344. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6345. string supplier = GetPostString("supplier");
  6346. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6347. string responsible = GetPostString("responsibleman");
  6348. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6349. string posCode = CurrentUser.UserPost.Post.Code;
  6350. string vstate = GetPostString("vstate");
  6351. if (vstate.Length > 0)
  6352. {
  6353. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6354. }
  6355. if (posCode == "Supplier")
  6356. {
  6357. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6358. lw.Add(string.Format("VerifyState = 0"));
  6359. lw.Add("type = 1");
  6360. lw.Add(string.Format("AfterSaleState={0}", 3));
  6361. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6362. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6363. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6364. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6365. writeGridDataTableJson(dStruct.TotalCount, dt);
  6366. }
  6367. else if (posCode == "logistics")
  6368. {
  6369. lw.Add(string.Format("UserId in ({0})", CurrentUser.User.pemLogistics));
  6370. lw.Add(string.Format("VerifyState = 0"));
  6371. lw.Add("type = 2");
  6372. lw.Add(string.Format("AfterSaleState={0}", 3));
  6373. dStruct.Order = "AfterSaleState asc,HandleTime desc";
  6374. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6375. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6376. writeGridDataTableJson(dStruct.TotalCount, dt);
  6377. }
  6378. else
  6379. {
  6380. lw.Add(string.Format("(AfterSaleState = 3)"));
  6381. string reasonState = GetPostString("reasonState");
  6382. lw.Add("type = 0");
  6383. if (posCode == "SysAdmin" || posCode == "AfterSaleMaster" || posCode == "AfterSale"
  6384. || posCode == "Summarize" || posCode == "Finance")
  6385. {
  6386. if (reasonState == "2")
  6387. {
  6388. lw.Add("VerifyState = 3");
  6389. }
  6390. else if (reasonState == "1")
  6391. {
  6392. lw.Add("VerifyState = 0 and AfterSaleSupplierMemo != ''");
  6393. }
  6394. else
  6395. {
  6396. lw.Add("VerifyState in (0,3)");
  6397. }
  6398. //不加条件,可以看全部
  6399. }
  6400. 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")
  6401. {
  6402. int orgid = CurrentUser.UserPost.OrgID;
  6403. string manageOrgId = CurrentUser.User.ManageOrgIds;
  6404. if (string.IsNullOrEmpty(manageOrgId))
  6405. {
  6406. lw.Add(string.Format("(( OrgID = {0} AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", orgid, CurrentUser.UserID));
  6407. }
  6408. else
  6409. {
  6410. lw.Add(string.Format("(( OrgID in ({0}) AND VerifyState = 0 ) OR ( UserId = {1} AND VerifyState IN ( 0, 3 ) ))", manageOrgId, CurrentUser.UserID));
  6411. }
  6412. if (reasonState == "1")
  6413. {
  6414. lw.Add("VerifyState = 3");
  6415. }
  6416. else if (reasonState == "2")
  6417. {
  6418. lw.Add("VerifyState = 1 and AfterSaleSupplierMemo != ''");
  6419. }
  6420. else
  6421. {
  6422. }
  6423. }
  6424. else
  6425. {
  6426. lw.Add(string.Format("UserId = {0} and VerifyState = 3", CurrentUser.UserID));
  6427. }
  6428. //else if (CurrentUser.UserPost.Post.Code == "PlaceMr")
  6429. //{
  6430. // int org_id = CurrentUser.UserPost.OrgID;
  6431. // lw.Add(string.Format("OrgID={0}", org_id));
  6432. //}
  6433. dStruct.Order = "AfterSaleState asc,IsArbitrate desc, createdTime desc";
  6434. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6435. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6436. writeGridDataTableJson(dStruct.TotalCount, dt);
  6437. }
  6438. }
  6439. public void get_erp_finishaftersalelist()
  6440. {
  6441. DataStruct dStruct = GetPostStruct();
  6442. List<string> lw = new List<string>();
  6443. int st = 4;
  6444. string tid = GetPostString("ctid");
  6445. if (tid.Length > 0)
  6446. {
  6447. string select_tid = getTidByCtid(tid);
  6448. lw.Add(string.Format("tid='{0}'", select_tid));
  6449. }
  6450. string shopname = GetPostString("shopname");
  6451. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  6452. //lw.Add(string.Format("IsRefund!={0}", 1));
  6453. string reason = GetPostString("reason");
  6454. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  6455. string method = GetPostString("method");
  6456. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  6457. string buyernick = GetPostString("buyer_nick");
  6458. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  6459. string handler = GetPostString("handler");
  6460. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  6461. string handledate1 = GetPostString("handledate1");
  6462. string handledate2 = GetPostString("handledate2");
  6463. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  6464. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  6465. string finish1 = GetPostString("finishdate1");
  6466. string finish2 = GetPostString("finishdate2");
  6467. string dwfinish = GetDateMinuteWhere("FinishAfterSaleTime", finish1, finish2);
  6468. if (dwfinish.Length > 0) lw.Add(dwfinish);
  6469. string supplier = GetPostString("supplier");
  6470. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  6471. string responsible = GetPostString("responsibleman");
  6472. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  6473. string vstate = GetPostString("vstate");
  6474. if (vstate.Length > 0)
  6475. {
  6476. if ("3".Equals(vstate))
  6477. {
  6478. lw.Add(string.Format("IsTem=1"));
  6479. }
  6480. else
  6481. {
  6482. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  6483. }
  6484. }
  6485. lw.Add(string.Format("AfterSaleState=4"));
  6486. string code = CurrentUser.UserPost.Post.Code;
  6487. if (code == "SysAdmin" || code == "AfterSaleMaster" || code == "AfterSale" || code == "Summarize" || code == "Finance")
  6488. {
  6489. //不加条件,可以看全部
  6490. }
  6491. else if (code == "Supplier")
  6492. {
  6493. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  6494. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  6495. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6496. }
  6497. else if (code == "logistics")
  6498. {
  6499. lw.Add(string.Format("userId in ({0})", CurrentUser.User.pemLogistics));
  6500. lw.Add("type = 2");
  6501. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  6502. }
  6503. 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")
  6504. {
  6505. int orgid = CurrentUser.UserPost.OrgID;
  6506. string manageOrgIds = CurrentUser.User.ManageOrgIds;
  6507. if (string.IsNullOrEmpty(manageOrgIds))
  6508. {
  6509. lw.Add(string.Format("(( OrgID = {0} ) OR ( UserId = {1} ))", orgid, CurrentUser.UserID));
  6510. }
  6511. else
  6512. {
  6513. lw.Add(string.Format("(( OrgID in ({0}) ) OR ( UserId = {1} ))", manageOrgIds, CurrentUser.UserID));
  6514. }
  6515. }
  6516. else
  6517. {
  6518. lw.Add(string.Format("UserId = {0} ", CurrentUser.UserID));
  6519. }
  6520. dStruct.Order = "HandleTime desc,AfterSaleTime desc";
  6521. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  6522. DataTable dt = WebCache.GetData("view_ErpTradeResponsible", dStruct);
  6523. writeGridDataTableJson(dStruct.TotalCount, dt);
  6524. }
  6525. public void handle_erp_aftersale()
  6526. {
  6527. if (UrlPostParmsCheck("ctid"))
  6528. {
  6529. string eid = GetPostString("ctid");
  6530. string responStr = GetPostString("AfterSaleResponsible");
  6531. if (responStr.Length <= 0)
  6532. {
  6533. returnErrorMsg("售后责任人不能为空");
  6534. return;
  6535. }
  6536. bool isDesign = false;
  6537. double designFree = 0.00;
  6538. int responsibleId = 0;
  6539. CeErpTradeCell entity = null;
  6540. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6541. if (entity != null)
  6542. {
  6543. int isNeedNewOrder = GetPostInt("IsNewOrder");
  6544. string afterMethod = GetPostString("AfterSaleMethod");
  6545. if (isNeedNewOrder == 1)
  6546. {
  6547. CeErpTradeCell newentity = CeErpTradeCell.GetByCtid("S_" + entity.ctid);
  6548. bool ishav = true;
  6549. if (newentity == null)
  6550. {
  6551. newentity = entity.Clone() as CeErpTradeCell;
  6552. ishav = false;
  6553. newentity.ctid = "S_" + entity.ctid;
  6554. newentity.OrderState = 0;
  6555. //唯一标识
  6556. newentity.OrderSn = newentity.ctid;
  6557. string orderSn = dataHelper.getSaleOrderSn();
  6558. if (orderSn != "")
  6559. {
  6560. newentity.OrderSn = orderSn;
  6561. }
  6562. }
  6563. newentity.UpdateTime = DateTime.Now;
  6564. newentity.AfterSaleState = 0;
  6565. newentity.AfterSaleMethod = afterMethod;
  6566. if (!ishav)
  6567. {
  6568. string memo_str = newentity.seller_memo;
  6569. memo_str = memo_str.Replace("(", "(");
  6570. memo_str = memo_str.Replace(")", ")");
  6571. int sIndex = memo_str.IndexOf("(");
  6572. int eIndex = memo_str.IndexOf(")");
  6573. if (sIndex == -1 || eIndex == -1)
  6574. {
  6575. returnErrorMsg("原订单备注中找不到订单号(到“订单列表”查看原单,看备注里面订单号是否被删掉)");
  6576. return;
  6577. }
  6578. string first = memo_str.Substring(0, sIndex + 1);
  6579. string memoCtid = newentity.OrderSn;
  6580. //if (memoCtid.IndexOf("C") != -1)
  6581. //{
  6582. //string CIdx = commonHelper.MidStrEx(memo_str, "[", "]"); //C1
  6583. //if (CIdx.IndexOf("+") != -1)
  6584. //{
  6585. //CIdx = "C" + CIdx.Split('+')[1];
  6586. //}
  6587. //memoCtid = memoCtid.Replace(CIdx + "_", ""); //去掉C1
  6588. //}
  6589. string last = memo_str.Substring(eIndex, memo_str.Length - eIndex);
  6590. //string second = memo_str.Substring(sIndex+1,memo_str.Length-sIndex-1);
  6591. string newMemo = first + memoCtid + last;
  6592. newentity.seller_memo = newMemo;
  6593. newentity.FinishPlaceTime = null;
  6594. newentity.UnusualTag = 0;
  6595. newentity.UnusualCon = "";
  6596. newentity.UnusualTime = null;
  6597. newentity.AfterSaleMemo = "";
  6598. newentity.AfterSaleMethod = afterMethod;
  6599. newentity.AfterSalePreTime = null;
  6600. newentity.AfterSaleReason = "";
  6601. newentity.AfterSaleResponsible = "";
  6602. newentity.AfterSaleState = 0;
  6603. newentity.AfterSaleTime = null;
  6604. newentity.AfterSaleUserId = 0;
  6605. newentity.AfterSaleSupplierState = 0;
  6606. newentity.LastBillWaybillCode = "";
  6607. newentity.LastBillCpCode = "";
  6608. newentity.FinishAfterSaleTime = null;
  6609. newentity.HandleTime = null;
  6610. newentity.IsSF = 0;
  6611. newentity.IsOldCustomer = 0;
  6612. newentity.UrgencyTime = null;
  6613. newentity.ResponsibleUserId = "";
  6614. newentity.IsVerifyToSupplier = false;
  6615. newentity.payment = 0;
  6616. newentity.CheckMemo = "";
  6617. newentity.OutSid = "";
  6618. newentity.CheckOrderTime = null;
  6619. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后处理生成:" + newMemo, entity.OrderState, 1);
  6620. }
  6621. newentity.isAfterSaleOrder = 1;
  6622. newentity.IsRefund = 0;
  6623. string receiveMobile = GetPostString("receiver_mobile");
  6624. if (receiveMobile.Length > 0)
  6625. {
  6626. CeErpTrade trade = CeErpTrade.Get(newentity.tid);
  6627. if (trade != null)
  6628. {
  6629. trade.receiver_name = GetPostString("receiver_name");
  6630. trade.receiver_mobile = receiveMobile;
  6631. trade.receiver_state = GetPostString("receiver_state");
  6632. trade.receiver_city = GetPostString("receiver_city");
  6633. trade.receiver_district = GetPostString("receiver_district");
  6634. trade.receiver_address = GetPostString("receiver_address");
  6635. newentity.IsOffLineOrder = 1;
  6636. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改地址", entity.OrderState, 1);
  6637. }
  6638. }
  6639. string st = GetPostString("ToState");
  6640. if (st.Length > 0)
  6641. {
  6642. if (newentity.OrderState <= 3)
  6643. {
  6644. newentity.WaitDesignTime = DateTime.Now;
  6645. newentity.StartDesignTime = null;
  6646. newentity.FinishDesignTime = null;
  6647. newentity.OrderState = 3;
  6648. if (st == "下单员")
  6649. {
  6650. newentity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单部设计师林春鸿
  6651. if (newentity.seller_memo.IndexOf("封酒贴") != -1)//封酒贴的售后单直接指派给得力
  6652. {
  6653. newentity.SupplierId = commonHelper.getSupplierIDByName("得力");
  6654. }
  6655. }
  6656. else
  6657. {
  6658. newentity.WaitDesignTime = DateTime.Now;
  6659. string sql1 = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE ID = {0}", entity.DesignUserId);
  6660. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  6661. if (dt1 != null && dt1.Rows.Count > 0 && !string.IsNullOrEmpty(dt1.Rows[0]["OrgID"].ToString()))
  6662. {
  6663. DataRow user = dt1.Rows[0];
  6664. //找主管
  6665. string sql = string.Format("SELECT * FROM [dbo].[view_ErpUser] WHERE OrgId={0} and PostCode in ('wxDesignerhd','wxDesignerMr','DesignerMr','Designerhd') and isOpen = 1", user["OrgID"]);
  6666. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  6667. if (dt != null && dt.Rows.Count > 0)
  6668. {
  6669. int designMr = Convert.ToInt32(dt.Rows[0]["ID"]);
  6670. newentity.DesignUserId = designMr;
  6671. string key = "aftersale_order_" + designMr;
  6672. if (RedisHelper.HasKey(key))
  6673. {
  6674. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6675. list.Add(newentity.ctid);
  6676. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6677. }
  6678. }
  6679. //账号正常
  6680. if (user["State"].ToString() == "0")
  6681. {
  6682. newentity.DesignUserId = entity.DesignUserId;
  6683. string key = "aftersale_order_" + entity.DesignUserId;
  6684. if (RedisHelper.HasKey(key))
  6685. {
  6686. List<string> list = Convert.ToString(RedisHelper.StringGet(key)).Split(',').ToList();
  6687. list.Add(newentity.ctid);
  6688. RedisHelper.StringSet(key, string.Join(",", list.Distinct().ToList()));
  6689. }
  6690. }
  6691. }
  6692. }
  6693. }
  6694. if (entity.IsXianHuo == 1)
  6695. {
  6696. newentity.OrderState = 6;
  6697. entity.FinishPlaceTime = DateTime.Now;
  6698. }
  6699. }
  6700. if (ishav)
  6701. {
  6702. newentity.Update();
  6703. }
  6704. else
  6705. {
  6706. newentity.Create();
  6707. CeErpTradeCellExtend newCellExtend = new CeErpTradeCellExtend();
  6708. newCellExtend.ctid = newentity.ctid;
  6709. newCellExtend.orderFrom = 20;
  6710. newCellExtend.orderType = 30;
  6711. if (st == "下单员")
  6712. {
  6713. }
  6714. else
  6715. {
  6716. newCellExtend.ReprintTime = DateTime.Now;
  6717. }
  6718. newCellExtend.Create();
  6719. }
  6720. if (st != "下单员")
  6721. {
  6722. if (entity.DispatchSort == 2)
  6723. {
  6724. designApiResponseVo response = designHelper.API_GetPrintData_CreateAfterOrder(newentity);
  6725. LogHelper.addLog(newentity.ctid, CurrentUser.UserID, "售后单生成指派:" + response.msg, newentity.OrderState, 1);
  6726. }
  6727. }
  6728. }
  6729. //处理售后扩展
  6730. string resIdStr = GetPostString("ResponsibleUserId");
  6731. string refundFees = GetPostString("refundFrees");
  6732. int IsComplain = GetPostInt("isComplain");
  6733. int IsBad = GetPostInt("isBad");
  6734. string IsOriginal = GetPostString("isOriginal");
  6735. double diffResultPrice = GetPostDouble("diffResultPrice");
  6736. string textResult = GetPostString("textResult");
  6737. string supplierResponsible = GetPostString("supplierResponsible");
  6738. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(eid);
  6739. if (ceErpTradeAfterSaleExtend == null)
  6740. {
  6741. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  6742. ceErpTradeAfterSaleExtend.tid = eid;
  6743. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6744. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6745. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6746. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6747. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6748. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6749. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6750. ceErpTradeAfterSaleExtend.Create();
  6751. }
  6752. else
  6753. {
  6754. if (!entity.ResponsibleUserId.Equals(resIdStr) && entity.AfterSaleSupplierState > 0)
  6755. {
  6756. ceErpTradeAfterSaleExtend.ChangeNum += 1;
  6757. }
  6758. ceErpTradeAfterSaleExtend.RefundFees = refundFees;
  6759. ceErpTradeAfterSaleExtend.IsComplain = IsComplain;
  6760. ceErpTradeAfterSaleExtend.TextResult = textResult;
  6761. ceErpTradeAfterSaleExtend.diffResultPrice = diffResultPrice;
  6762. ceErpTradeAfterSaleExtend.supplierResponsible = supplierResponsible;
  6763. ceErpTradeAfterSaleExtend.IsOriginal = Convert.ToBoolean(IsOriginal);
  6764. ceErpTradeAfterSaleExtend.IsBad = IsBad;
  6765. ceErpTradeAfterSaleExtend.Update();
  6766. }
  6767. int gysid = GetPostInt("ResponsibleSupId");
  6768. if (entity.AfterSaleUserId == 0)
  6769. {
  6770. entity.AfterSaleUserId = CurrentUser.UserID;
  6771. }
  6772. entity.ResponsibleUserId = resIdStr;
  6773. entity.AfterSaleResponsible = GetPostString("AfterSaleResponsible");
  6774. entity.AfterSaleResSupId = GetPostInt("ResponsibleSupId");
  6775. if (entity.ResponsibleUserId.Length > 0 && entity.AfterSaleResponsible.Length > 0)
  6776. {
  6777. CeErpTradeResponsible.DelByTid(eid, -1);
  6778. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  6779. int backNum = 0;
  6780. if (number != null)
  6781. {
  6782. backNum = number.BackNum;
  6783. }
  6784. char[] separator = { ',' };
  6785. string[] sArray = resIdStr.Split(separator);
  6786. string[] refundFreeList = { };
  6787. if (refundFees.Length > 0)
  6788. {
  6789. refundFreeList = refundFees.Split(separator);
  6790. }
  6791. int index = -1;
  6792. foreach (string i in sArray)
  6793. {
  6794. index++;
  6795. if (i.Length <= 0) continue;
  6796. char[] separator2 = { '_' };
  6797. string idstr = i.Split(separator2)[0];
  6798. string idtype = i.Split(separator2)[1];
  6799. double refudFree = 0;
  6800. if (refundFreeList.Length > 0)
  6801. {
  6802. refudFree = Convert.ToDouble(refundFreeList[index] == "" ? "0" : refundFreeList[index]);
  6803. }
  6804. if (idtype == "s")
  6805. {
  6806. isDesign = true;
  6807. designFree = refudFree;
  6808. }
  6809. int userId = Convert.ToInt32(idstr);
  6810. int type = 0;
  6811. if (idtype == "g")
  6812. {
  6813. type = 1;
  6814. }
  6815. if (idtype == "w")
  6816. {
  6817. type = 2;
  6818. }
  6819. if (idtype == "t")
  6820. {
  6821. type = 3;
  6822. }
  6823. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetByUserIdType(eid, userId, type);
  6824. if (ceErpTradeResponsible == null)
  6825. {
  6826. ceErpTradeResponsible = new CeErpTradeResponsible();
  6827. ceErpTradeResponsible.tid = eid;
  6828. ceErpTradeResponsible.UserId = userId;
  6829. ceErpTradeResponsible.createdTime = DateTime.Now;
  6830. ceErpTradeResponsible.type = type;
  6831. if (type == 1)
  6832. {
  6833. ceErpTradeResponsible.IsSup = 1;
  6834. }
  6835. if (type == 2)
  6836. {
  6837. ceErpTradeResponsible.IsFlow = 1;
  6838. }
  6839. }
  6840. ceErpTradeResponsible.RefundFee = refudFree;
  6841. ceErpTradeResponsible.VerifyState = 0;
  6842. if (userId == 2125 || idtype == "w")
  6843. {
  6844. ceErpTradeResponsible.VerifyState = 1;
  6845. }
  6846. if (idtype == "w" && userId == 101)
  6847. {
  6848. ceErpTradeResponsible.VerifyState = 0;
  6849. }
  6850. if (ceErpTradeResponsible.ID > 0)
  6851. {
  6852. ceErpTradeResponsible.Update();
  6853. }
  6854. else
  6855. {
  6856. ceErpTradeResponsible.Create();
  6857. }
  6858. if (isDesign)
  6859. {
  6860. responsibleId = ceErpTradeResponsible.ID;
  6861. }
  6862. }
  6863. CeErpTradeResponsible.NumByTid(backNum, eid);
  6864. }
  6865. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  6866. if (ceErpTradeCellExtend != null)
  6867. {
  6868. ceErpTradeCellExtend.returnVisit = 0;
  6869. ceErpTradeCellExtend.Update();
  6870. }
  6871. if (entity.HandleTime != null)
  6872. {
  6873. if (entity.AfterSaleState == 1)
  6874. {
  6875. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后", entity.OrderState, 1);
  6876. }
  6877. else
  6878. {
  6879. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "修改售后信息" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 2);
  6880. }
  6881. }
  6882. else
  6883. {
  6884. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "开始处理售后:" + GetPostString("AfterSaleResponsible") + resIdStr, entity.OrderState, 1);
  6885. entity.HandleTime = DateTime.Now;
  6886. }
  6887. bool isCompale = false;
  6888. if (entity.AfterSaleState == 5)
  6889. {
  6890. isCompale = true;
  6891. entity.AfterSaleState = 3;
  6892. }
  6893. entity.AfterSaleSupplierState = 0;
  6894. if (entity.AfterSaleResponsible.IndexOf("供应商") != -1)
  6895. {
  6896. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后处理:" + entity.AfterSaleResponsible + ",id:" + entity.AfterSaleResSupId, entity.OrderState, 2);
  6897. }
  6898. string sImgs = GetPostString("img");
  6899. entity.AfterSaleSupplierImg = sImgs;
  6900. entity.supRefundType = GetPostString("supRefundType");
  6901. entity.AfterSaleReason = GetPostString("AfterSaleReason");
  6902. entity.AfterSaleMethod = GetPostString("AfterSaleMethod");
  6903. entity.AfterSaleMemo = GetPostString("AfterSaleMemo");
  6904. entity.AfterSaleMemoType = GetPostString("MemoType");
  6905. if (entity.supRefundType == "正常损耗" || entity.supRefundType == "无需扣款" || entity.supRefundType == "不理赔" || entity.supRefundType == "不售后")
  6906. {
  6907. //entity.AfterSaleSupplierState = 2;
  6908. }
  6909. string df = GetPostString("DeductFee");
  6910. if (df == "")
  6911. {
  6912. df = "0";
  6913. }
  6914. string rf = GetPostString("RefundFee");
  6915. if (rf == "")
  6916. {
  6917. rf = "0";
  6918. }
  6919. string pm = GetPostString("AfterSalePayment");
  6920. if (pm == "")
  6921. {
  6922. pm = "0";
  6923. }
  6924. entity.AfterSalePayment = Convert.ToDouble(pm);
  6925. entity.DeductFee = Convert.ToDouble(df);
  6926. entity.RefundFee = Convert.ToDouble(rf);
  6927. entity.UpdateTime = DateTime.Now;
  6928. entity.Update();
  6929. string toState = GetPostString("ToState");
  6930. string original = GetPostString("isOriginal");
  6931. ApiVo apiVo = new ApiVo();
  6932. apiVo.orderNumber = entity.ctid;
  6933. apiVo.actionName = "afterDesign";
  6934. apiVo.orderRemarks = entity.AfterSaleMethod;
  6935. apiVo.reasonRemarks = entity.AfterSaleReason;
  6936. apiVo.isDesign = isDesign;
  6937. apiVo.designFree = designFree;
  6938. apiVo.responsibleId = responsibleId;
  6939. apiVo.afterFiles = entity.AfterSaleSupplierImg;
  6940. if (toState == "设计师")
  6941. {
  6942. apiVo.isOriginal = Convert.ToBoolean(original);
  6943. }
  6944. designHelper.API_WorkCore(apiVo);//afterDesign
  6945. CeErpMethod methodSql = new CeErpMethod();
  6946. methodSql.con = entity.AfterSaleMethod;
  6947. methodSql.addTime = DateTime.Now;
  6948. methodSql.Create();
  6949. string delsql = "delete from ce_erpmethod where id not in (select top 50 id from ce_erpmethod order by id desc);";
  6950. CeErpMethod.ExecuteNonQuery(delsql);
  6951. if (isCompale)
  6952. {
  6953. aftersale_data_change(entity.ctid);
  6954. }
  6955. returnSuccessMsg("操作成功!");
  6956. return;
  6957. }
  6958. returnErrorMsg("找不到订单记录");
  6959. }
  6960. }
  6961. public void ins_erp_toresponsible()
  6962. {
  6963. if (UrlPostParmsCheck("ctid"))
  6964. {
  6965. string eid = GetPostString("ctid");
  6966. CeErpTradeCell entity = null;
  6967. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  6968. if (entity != null)
  6969. {
  6970. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  6971. if (ceErpTradeAfterSaleExtend == null || string.IsNullOrEmpty(ceErpTradeAfterSaleExtend.TextResult) || ceErpTradeAfterSaleExtend.TextResult == "待处理")
  6972. {
  6973. returnErrorMsg("客户售后结果不能为空或不能为待处理!");
  6974. return;
  6975. }
  6976. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", entity.ctid);
  6977. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  6978. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  6979. if (entity.AfterSalePreTime == null)
  6980. {
  6981. if (DateTime.Compare(DateTime.Now.AddHours(-24), (DateTime)entity.AfterSaleTime) >= 0)
  6982. {
  6983. ceErpTradeAfterSaleExtend.PreTimeOut += 1;
  6984. }
  6985. }
  6986. entity.AfterSalePreTime = DateTime.Now;
  6987. //预完成给售后主管审核客户问题直接完成
  6988. if (entity.AfterSaleState == 1 && ceErpTradeAfterSaleExtend.DisagreeTime != null && num <= 1)
  6989. {
  6990. if (DateTime.Compare(DateTime.Now.AddHours(-48), (DateTime)ceErpTradeAfterSaleExtend.DisagreeTime) >= 0)
  6991. {
  6992. ceErpTradeAfterSaleExtend.DisagreeTimeOut += 1;
  6993. }
  6994. }
  6995. ceErpTradeAfterSaleExtend.Update();
  6996. entity.AfterSaleState = 2;
  6997. entity.UpdateTime = DateTime.Now;
  6998. entity.Update();
  6999. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "售后‘预完成’给售后主管审核", entity.OrderState, 2);
  7000. aftersale_data_change(entity.ctid);
  7001. returnSuccessMsg("操作成功!");
  7002. return;
  7003. }
  7004. returnErrorMsg("找不到订单记录");
  7005. }
  7006. }
  7007. public void cancel_erp_aftersaleanddelnew()
  7008. {
  7009. if (UrlPostParmsCheck("ctid"))
  7010. {
  7011. string eid = GetPostString("ctid");
  7012. CeErpTradeCell entity = null;
  7013. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7014. if (entity != null)
  7015. {
  7016. entity.AfterSaleState = 0;
  7017. entity.AfterSaleReason = "";
  7018. entity.AfterSaleMethod = "";
  7019. entity.AfterSaleMemo = "";
  7020. entity.AfterSaleResponsible = "";
  7021. entity.ResponsibleUserId = "";
  7022. entity.DeductFee = 0;
  7023. entity.RefundFee = 0;
  7024. entity.IsArbitrate = 0;
  7025. CeErpTradeResponsible.DelByTid(eid, -1);
  7026. entity.Update();
  7027. CeErpTradeCell after = CeErpTradeCell.GetByCtid("S_" + eid);
  7028. if (after != null)
  7029. {
  7030. if (after.OrderState < 5)
  7031. CeErpTradeCell.DelByCtid("S_" + eid);
  7032. }
  7033. returnSuccessMsg("操作成功!");
  7034. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "取消删除售后", entity.OrderState, 2);
  7035. return;
  7036. }
  7037. returnErrorMsg("找不到订单记录");
  7038. }
  7039. }
  7040. public void get_erp_aftersale_pregather()
  7041. {
  7042. List<string> lw = new List<string>();
  7043. int st = GetInt("st");
  7044. string tid = GetPostString("ctid");
  7045. if (tid.Length > 0)
  7046. {
  7047. string select_tid = getTidByCtid(tid);
  7048. lw.Add(string.Format("tid='{0}'", select_tid));
  7049. }
  7050. string shopname = GetPostString("shopname");
  7051. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7052. string buyernick = GetPostString("buyer_nick");
  7053. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7054. string sellermemo = GetPostString("seller_memo");
  7055. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7056. string orderState = GetPostString("orderState");
  7057. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7058. string reason = GetPostString("reason");
  7059. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7060. string method = GetPostString("method");
  7061. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7062. string handler = GetPostString("handler");
  7063. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7064. string handledate1 = GetPostString("handledate1");
  7065. string handledate2 = GetPostString("handledate2");
  7066. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7067. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7068. string supplier = GetPostString("supplier");
  7069. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  7070. string responsible = GetPostString("responsibleman");
  7071. if (responsible.Length > 0) lw.Add(string.Format("AfterSaleResponsible like '%{0}%'", responsible));
  7072. string customer = GetPostString("customer");
  7073. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7074. string design = GetPostString("design");
  7075. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7076. string afterMemoType = GetPostString("aftermemotype");
  7077. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7078. string afterSaleMemo = GetPostString("afterSaleMemo");
  7079. if (afterSaleMemo.Length > 0) lw.Add(string.Format("afterSaleMemo like '%{0}%'", afterSaleMemo));
  7080. string afterresult = GetPostString("afterresult");
  7081. if (afterresult.Length > 0) lw.Add(string.Format("TextResult = '{0}'", afterresult));
  7082. string poscode = CurrentUser.UserPost.Post.Code;
  7083. if (poscode != "SysAdmin" && poscode != "AfterSaleMaster")
  7084. {
  7085. string shopid = CurrentUser.User.pemShop;
  7086. lw.Add(string.Format("shopId in ({0})", shopid));
  7087. }
  7088. var mainwhere = string.Join(" and ", lw.ToArray());
  7089. string ro_json = "";
  7090. string type = GetPostString("gather_type");
  7091. int number = 0;
  7092. if (poscode == "AfterSale")
  7093. {
  7094. //处理中
  7095. if (type == "Handling")
  7096. {
  7097. 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) : ""));
  7098. DataTable dt = null;
  7099. try
  7100. {
  7101. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7102. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7103. }
  7104. catch (Exception e)
  7105. {
  7106. dt = new DataTable();
  7107. }
  7108. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7109. return;
  7110. }
  7111. if (type == "Wait")
  7112. {
  7113. //待处理
  7114. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7115. DataTable dt1 = null;
  7116. try
  7117. {
  7118. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7119. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7120. }
  7121. catch (Exception e)
  7122. {
  7123. dt1 = new DataTable();
  7124. }
  7125. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7126. return;
  7127. }
  7128. if (type == "back")
  7129. {
  7130. //打回
  7131. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != '' " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7132. DataTable dt2 = null;
  7133. try
  7134. {
  7135. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7136. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7137. }
  7138. catch (Exception e)
  7139. {
  7140. dt2 = new DataTable();
  7141. }
  7142. returnSuccess(JsonConvert.SerializeObject(new { back = number }));
  7143. return;
  7144. }
  7145. if (type == "preCompletion")
  7146. {
  7147. //预完成
  7148. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7149. DataTable dt3 = null;
  7150. try
  7151. {
  7152. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7153. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7154. }
  7155. catch (Exception e)
  7156. {
  7157. dt3 = new DataTable();
  7158. }
  7159. returnSuccess(JsonConvert.SerializeObject(new { preCompletion = number }));
  7160. return;
  7161. }
  7162. if (type == "documentary")
  7163. {
  7164. //跟单中
  7165. 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) : ""));
  7166. DataTable dt4 = null;
  7167. try
  7168. {
  7169. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7170. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7171. }
  7172. catch (Exception e)
  7173. {
  7174. dt4 = new DataTable();
  7175. }
  7176. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7177. return;
  7178. }
  7179. if (type == "reBack")
  7180. {
  7181. //被打回
  7182. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7183. DataTable dt1 = null;
  7184. try
  7185. {
  7186. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7187. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7188. }
  7189. catch (Exception e)
  7190. {
  7191. dt1 = new DataTable();
  7192. }
  7193. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7194. return;
  7195. }
  7196. }
  7197. if (poscode == "SysAdmin" || poscode == "AfterSaleMaster")
  7198. {
  7199. if (type == "puBack")
  7200. {
  7201. //退回
  7202. string sql = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleBackReason != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7203. DataTable dt = null;
  7204. try
  7205. {
  7206. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7207. number = Convert.ToInt32(dt.Rows[0]["number"]);
  7208. }
  7209. catch (Exception e)
  7210. {
  7211. dt = new DataTable();
  7212. }
  7213. returnSuccess(JsonConvert.SerializeObject(new { puBack = number }));
  7214. return;
  7215. }
  7216. if (type == "reBack")
  7217. {
  7218. //打回
  7219. string sql1 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and AfterSaleSupplierMemo != ''" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7220. DataTable dt1 = null;
  7221. try
  7222. {
  7223. dt1 = DbHelper.DbConn.ExecuteDataset(sql1).Tables[0];
  7224. number = Convert.ToInt32(dt1.Rows[0]["number"]);
  7225. }
  7226. catch (Exception e)
  7227. {
  7228. dt1 = new DataTable();
  7229. }
  7230. returnSuccess(JsonConvert.SerializeObject(new { reBack = number }));
  7231. return;
  7232. }
  7233. if (type == "examEd")
  7234. {
  7235. //已审核
  7236. string sql2 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=3 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7237. DataTable dt2 = null;
  7238. try
  7239. {
  7240. dt2 = DbHelper.DbConn.ExecuteDataset(sql2).Tables[0];
  7241. number = Convert.ToInt32(dt2.Rows[0]["number"]);
  7242. }
  7243. catch (Exception e)
  7244. {
  7245. dt2 = new DataTable();
  7246. }
  7247. returnSuccess(JsonConvert.SerializeObject(new { examEd = number }));
  7248. return;
  7249. }
  7250. if (type == "waitExam")
  7251. {
  7252. //待审核
  7253. string sql3 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=2 " + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7254. DataTable dt3 = null;
  7255. try
  7256. {
  7257. dt3 = DbHelper.DbConn.ExecuteDataset(sql3).Tables[0];
  7258. number = Convert.ToInt32(dt3.Rows[0]["number"]);
  7259. }
  7260. catch (Exception e)
  7261. {
  7262. dt3 = new DataTable();
  7263. }
  7264. returnSuccess(JsonConvert.SerializeObject(new { waitExam = number }));
  7265. return;
  7266. }
  7267. if (type == "Handling")
  7268. {
  7269. //处理中
  7270. 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) : ""));
  7271. DataTable dt4 = null;
  7272. try
  7273. {
  7274. dt4 = DbHelper.DbConn.ExecuteDataset(sql4).Tables[0];
  7275. number = Convert.ToInt32(dt4.Rows[0]["number"]);
  7276. }
  7277. catch (Exception e)
  7278. {
  7279. dt4 = new DataTable();
  7280. }
  7281. returnSuccess(JsonConvert.SerializeObject(new { Handling = number }));
  7282. return;
  7283. }
  7284. if (type == "Wait")
  7285. {
  7286. //待处理
  7287. string sql5 = string.Format("select count(*) as number from view_AfterSaleList where aftersalestate=1 and HandleTime is null" + (mainwhere.Length > 0 ? (" and " + mainwhere) : ""));
  7288. DataTable dt5 = null;
  7289. try
  7290. {
  7291. dt5 = DbHelper.DbConn.ExecuteDataset(sql5).Tables[0];
  7292. number = Convert.ToInt32(dt5.Rows[0]["number"]);
  7293. }
  7294. catch (Exception e)
  7295. {
  7296. dt5 = new DataTable();
  7297. }
  7298. returnSuccess(JsonConvert.SerializeObject(new { Wait = number }));
  7299. return;
  7300. }
  7301. if (type == "documentary")
  7302. {
  7303. //跟单中
  7304. 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) : ""));
  7305. DataTable dt6 = null;
  7306. try
  7307. {
  7308. dt6 = DbHelper.DbConn.ExecuteDataset(sql6).Tables[0];
  7309. number = Convert.ToInt32(dt6.Rows[0]["number"]);
  7310. }
  7311. catch (Exception e)
  7312. {
  7313. dt6 = new DataTable();
  7314. }
  7315. returnSuccess(JsonConvert.SerializeObject(new { documentary = number }));
  7316. return;
  7317. }
  7318. }
  7319. returnSuccess(ro_json);
  7320. }
  7321. public void end_erp_aftersale()
  7322. {
  7323. if (UrlPostParmsCheck("ctid"))
  7324. {
  7325. string eid = GetPostString("ctid");
  7326. CeErpTradeCell entity = null;
  7327. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7328. if (entity != null)
  7329. {
  7330. string stype = GetPostString("stype");
  7331. string typeStr = stype;
  7332. entity.AfterSaleState = 4;
  7333. entity.FinishAfterSaleTime = DateTime.Now;
  7334. entity.AfterSaleMethod = (entity.AfterSaleMethod + "-" + typeStr);
  7335. entity.Update();
  7336. ApiVo apiVo = new ApiVo();
  7337. apiVo.orderNumber = entity.ctid;
  7338. apiVo.actionName = "afterOver";
  7339. designHelper.API_WorkCore(apiVo); //afterOver
  7340. string sqlupd = "update ce_erptraderesponsible WITH(ROWLOCK) set VerifyState=1,VerifyTime=getdate(),IsTem=1 where VerifyState > -1 and tid='" + entity.ctid + "'";
  7341. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7342. CeErpSukuraData.createInfo(entity.ctid, 8);
  7343. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "点击售后终止,此单售后完成", 0, 3);
  7344. returnSuccessMsg("操作成功!");
  7345. return;
  7346. }
  7347. returnErrorMsg("找不到订单记录");
  7348. }
  7349. }
  7350. public void ins_erp_finishaftersale()
  7351. {
  7352. if (UrlPostParmsCheck("id"))
  7353. {
  7354. string eid = GetPostString("id");
  7355. CeErpTradeResponsible entity = null;
  7356. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7357. if (entity != null)
  7358. {
  7359. entity.VerifyState = 1;
  7360. entity.VerifyTime = DateTime.Now;
  7361. entity.Update();
  7362. LogHelper.addLog(entity.tid, CurrentUser.UserID, "责任人完成审核", 0, 3);
  7363. string sql = "select * from ce_erptraderesponsible where tid='" + entity.tid + "' and VerifyState=0";
  7364. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  7365. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(entity.tid);
  7366. if (dt.Rows.Count <= 0)
  7367. {
  7368. string sqlupd = "update ce_erptradecell WITH(ROWLOCK) set AfterSaleState=4,FinishAfterSaleTime=getdate(),UpdateTime=getdate() where ctid='" + entity.tid + "'";
  7369. DbHelper.DbConn.ExecuteNonQuery(sqlupd);
  7370. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7371. CeErpSukuraData.createInfo(entity.tid, 8);
  7372. if (ceErpTradeCell.AfterSaleReason.IndexOf("设计") > 0 || ceErpTradeCell.AfterSalePayment > 0)
  7373. {
  7374. CeErpDesignerBill.Del(entity.tid);
  7375. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7376. }
  7377. }
  7378. returnSuccessMsg("操作成功!");
  7379. return;
  7380. }
  7381. returnErrorMsg("找不到订单记录");
  7382. }
  7383. }
  7384. public void upd_erp_arbitrateaftersale()
  7385. {
  7386. if (UrlPostParmsCheck("id"))
  7387. {
  7388. string eid = GetPostString("id");
  7389. CeErpTradeResponsible entity = null;
  7390. if (eid != "") entity = CeErpTradeResponsible.Get(eid);
  7391. if (entity != null)
  7392. {
  7393. entity.IsArbitrate = 1;
  7394. entity.ArbitradeMemo = GetPostString("reason");
  7395. entity.VerifyState = 2;
  7396. entity.Update();
  7397. CeErpTradeCell tradecell = CeErpTradeCell.GetByCtid(entity.tid);
  7398. if (tradecell != null)
  7399. {
  7400. tradecell.AfterSaleSupplierMemo = "申请仲裁:" + entity.ArbitradeMemo;
  7401. tradecell.IsArbitrate = 1;
  7402. tradecell.Update();
  7403. }
  7404. LogHelper.addLog(entity.tid, CurrentUser.UserID, "申请仲裁", 0, 3);
  7405. returnSuccessMsg("操作成功!");
  7406. return;
  7407. }
  7408. returnErrorMsg("找不到订单记录");
  7409. }
  7410. }
  7411. public void upd_erp_backaftersale()
  7412. {
  7413. if (UrlPostParmsCheck("tid"))
  7414. {
  7415. string eid = GetPostString("tid");
  7416. CeErpTradeResponsible number = CeErpTradeResponsible.GetByCtid(eid);
  7417. int backNum = 0;
  7418. if (number != null)
  7419. {
  7420. backNum = number.BackNum;
  7421. }
  7422. CeErpTradeResponsible.NumByTid(backNum + 1, eid);
  7423. CeErpTradeCell entity = null;
  7424. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7425. if (entity != null)
  7426. {
  7427. entity.AfterSaleBackReason = GetPostString("backreason");
  7428. entity.AfterSaleState = 1;
  7429. entity.AfterSaleSupplierState = 0;
  7430. entity.UpdateTime = DateTime.Now;
  7431. entity.Update();
  7432. returnSuccessMsg("操作成功!");
  7433. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "退回到售后中", 0, 0);
  7434. return;
  7435. }
  7436. returnErrorMsg("找不到订单记录");
  7437. }
  7438. }
  7439. public void get_erp_supplieraftersalelist()
  7440. {
  7441. DataStruct dStruct = GetPostStruct();
  7442. List<string> lw = new List<string>();
  7443. string tid = GetPostString("ctid");
  7444. if (tid.Length > 0) lw.Add(string.Format("ctid like '%{0}%'", tid));
  7445. string shopname = GetPostString("shopname");
  7446. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7447. string buyernick = GetPostString("buyer_nick");
  7448. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7449. string sellermemo = GetPostString("seller_memo");
  7450. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7451. string orderState = GetPostString("orderState");
  7452. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  7453. string afterState = GetPostString("afterstate");
  7454. if (afterState.Length > 0) lw.Add(string.Format("AfterSaleState={0}", afterState));
  7455. string date1 = GetPostString("date1");
  7456. string date2 = GetPostString("date2");
  7457. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7458. if (dw.Length > 0) lw.Add(dw);
  7459. string price1 = GetPostString("price1");
  7460. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7461. string price2 = GetPostString("price2");
  7462. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7463. string reason = GetPostString("reason");
  7464. if (reason.Length > 0) lw.Add(string.Format("AfterSaleReason like '%{0}%'", reason));
  7465. string method = GetPostString("method");
  7466. if (method.Length > 0) lw.Add(string.Format("AfterSaleMethod like '%{0}%'", method));
  7467. string handledate1 = GetPostString("handledate1");
  7468. string handledate2 = GetPostString("handledate2");
  7469. string dwhandledate = GetDateMinuteWhere("HandleTime", handledate1, handledate2);
  7470. if (dwhandledate.Length > 0) lw.Add(dwhandledate);
  7471. string handler = GetPostString("handler");
  7472. if (handler.Length > 0) lw.Add(string.Format("AfterSaleName='{0}'", handler));
  7473. string afterdate1 = GetPostString("afterdate1");
  7474. string afterdate2 = GetPostString("afterdate2");
  7475. string afterDate = GetDateMinuteWhere("AfterSaleTime", afterdate1, afterdate2);
  7476. if (afterDate.Length > 0) lw.Add(afterDate);
  7477. string customer = GetPostString("customer");
  7478. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7479. string design = GetPostString("design");
  7480. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7481. string afterMemoType = GetPostString("aftermemotype");
  7482. if (afterMemoType.Length > 0) lw.Add(string.Format("AfterSaleMemoType='{0}'", afterMemoType));
  7483. string vstate = GetPostString("vstate");
  7484. if (vstate.Length > 0)
  7485. {
  7486. lw.Add(string.Format("AfterSaleSupplierState={0}", Convert.ToInt32(vstate)));
  7487. }
  7488. lw.Add(string.Format("AfterSaleState>={0}", 2));
  7489. string supplier = GetPostString("supplier");
  7490. int supid = commonHelper.getSupplierIDByName(supplier);
  7491. if (supplier.Length > 0) lw.Add(string.Format("AfterSaleResSupId={0}", supid));
  7492. string posCode = CurrentUser.UserPost.Post.Code;
  7493. if (posCode == "Supplier")
  7494. {
  7495. lw.Add(string.Format("AfterSaleResSupId in ({0})", CurrentUser.User.pemVend));
  7496. }
  7497. else if (posCode == "AfterSale" || posCode == "AfterSaleMaster")
  7498. {
  7499. lw.Add(string.Format("AfterSaleUserId={0}", CurrentUser.UserID));
  7500. }
  7501. else
  7502. {
  7503. lw.Add(string.Format("AfterSaleResSupId != 0"));
  7504. }
  7505. lw.Add(string.Format("IsSupNeedAfterSale=1")); //特定的供应商才需要供应商审核;
  7506. dStruct.Order = "AfterSaleSupplierState asc,HandleTime desc";
  7507. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7508. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  7509. writeGridDataTableJson(dStruct.TotalCount, dt);
  7510. }
  7511. public void upd_erp_supverifyaftersale()
  7512. {
  7513. if (UrlPostParmsCheck("id"))
  7514. {
  7515. string id = GetPostString("id");
  7516. int st = GetPostInt("afterstate");
  7517. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7518. CeErpTradeCell entity = null;
  7519. if (ceErpTradeResponsible != null)
  7520. {
  7521. entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7522. }
  7523. string afmemo = GetPostString("supmemo");
  7524. string image = GetPostString("image");
  7525. if (entity != null)
  7526. {
  7527. entity.AfterSaleSupplierState = st;
  7528. entity.AfterSaleSupplierMemo = afmemo;
  7529. if (st == 1)
  7530. {
  7531. ceErpTradeResponsible.VerifyState = 1;
  7532. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7533. ceErpTradeResponsible.Update();
  7534. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7535. if (isAll)
  7536. {
  7537. entity.AfterSaleState = 4;
  7538. entity.FinishAfterSaleTime = DateTime.Now;
  7539. }
  7540. }
  7541. else
  7542. {
  7543. CeErpTradeResponsible.dateByTid(entity.ctid);
  7544. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7545. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7546. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7547. if (num <= 1)
  7548. {
  7549. entity.AfterSaleState = 1;
  7550. }
  7551. else
  7552. {
  7553. entity.AfterSaleState = 5;
  7554. }
  7555. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7556. if (ceErpTradeAfterSaleExtend != null)
  7557. {
  7558. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7559. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7560. ceErpTradeAfterSaleExtend.Update();
  7561. }
  7562. else
  7563. {
  7564. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7565. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7566. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7567. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7568. ceErpTradeAfterSaleExtend.Create();
  7569. }
  7570. }
  7571. if (entity.AfterSaleState == 4)
  7572. {
  7573. LogHelper.addLog(entity.tid, CurrentUser.UserID, "完成售后", 0, 3);
  7574. if (entity.AfterSaleReason.IndexOf("设计") > 0 || entity.AfterSalePayment > 0)
  7575. {
  7576. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "售后取消设计费", CurrentUser.UserName, 1);
  7577. }
  7578. ApiVo apiVo = new ApiVo();
  7579. apiVo.orderNumber = entity.ctid;
  7580. apiVo.actionName = "afterOver";
  7581. designHelper.API_WorkCore(apiVo); //afterOver
  7582. }
  7583. entity.UpdateTime = DateTime.Now;
  7584. entity.Update();
  7585. returnSuccessMsg("操作成功!");
  7586. CeErpSukuraData.createInfo(entity.ctid, 8);
  7587. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7588. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "供应商" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7589. return;
  7590. }
  7591. returnErrorMsg("找不到订单记录");
  7592. }
  7593. }
  7594. public void upd_erp_masteraftersale()
  7595. {
  7596. if (UrlPostParmsCheck("id"))
  7597. {
  7598. string id = GetPostString("id");
  7599. int st = GetPostInt("afterstate");
  7600. string afmemo = GetPostString("supmemo");
  7601. string image = GetPostString("image");
  7602. string textResult = GetPostString("textResult");
  7603. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7604. if (ceErpTradeResponsible != null)
  7605. {
  7606. ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
  7607. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7608. ceErpTradeResponsible.Update();
  7609. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7610. if (entity != null)
  7611. {
  7612. entity.AfterSaleSupplierState = st;
  7613. entity.AfterSaleSupplierMemo = afmemo;
  7614. if (st == 1)
  7615. {
  7616. }
  7617. else
  7618. {
  7619. CeErpTradeResponsible.dateByTid(entity.ctid);
  7620. //退回到售后
  7621. string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
  7622. DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
  7623. int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
  7624. if (num <= 1)
  7625. {
  7626. entity.AfterSaleState = 1;
  7627. }
  7628. else
  7629. {
  7630. entity.AfterSaleState = 5;
  7631. }
  7632. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7633. if (ceErpTradeAfterSaleExtend != null)
  7634. {
  7635. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7636. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7637. ceErpTradeAfterSaleExtend.Update();
  7638. }
  7639. else
  7640. {
  7641. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7642. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7643. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7644. ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
  7645. ceErpTradeAfterSaleExtend.Create();
  7646. }
  7647. }
  7648. entity.UpdateTime = DateTime.Now;
  7649. entity.Update();
  7650. returnSuccessMsg("操作成功!");
  7651. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7652. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7653. return;
  7654. }
  7655. }
  7656. returnErrorMsg("找不到订单记录");
  7657. }
  7658. }
  7659. public void upd_erp_personaftersale()
  7660. {
  7661. if (UrlPostParmsCheck("id"))
  7662. {
  7663. //林小连
  7664. if (CurrentUser.UserID == 36 || CurrentUser.UserID == 1760 || CurrentUser.UserID == 33)
  7665. {
  7666. upd_erp_masteraftersale();
  7667. return;
  7668. }
  7669. string id = GetPostString("id");
  7670. int st = GetPostInt("afterstate");
  7671. string afmemo = GetPostString("supmemo");
  7672. string image = GetPostString("image");
  7673. CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
  7674. if (ceErpTradeResponsible != null)
  7675. {
  7676. ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
  7677. ceErpTradeResponsible.VerifyTime = DateTime.Now;
  7678. ceErpTradeResponsible.Update();
  7679. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
  7680. if (entity != null)
  7681. {
  7682. entity.AfterSaleSupplierMemo = afmemo;
  7683. entity.AfterSaleSupplierState = st;
  7684. if (st == 1)
  7685. {
  7686. bool isAll = commonHelper.tradeResponsibleAll(entity);
  7687. if (isAll)
  7688. {
  7689. entity.AfterSaleState = 4;
  7690. entity.FinishAfterSaleTime = DateTime.Now;
  7691. }
  7692. }
  7693. else
  7694. {
  7695. CeErpTradeResponsible.dateByTid(entity.ctid);
  7696. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
  7697. if (ceErpTradeAfterSaleExtend != null)
  7698. {
  7699. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7700. ceErpTradeAfterSaleExtend.Update();
  7701. }
  7702. else
  7703. {
  7704. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  7705. ceErpTradeAfterSaleExtend.tid = entity.ctid;
  7706. ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
  7707. ceErpTradeAfterSaleExtend.Create();
  7708. }
  7709. //退回到主管
  7710. //entity.AfterSaleState = 2;
  7711. }
  7712. if (entity.AfterSaleState == 4)
  7713. {
  7714. ApiVo apiVo = new ApiVo();
  7715. apiVo.orderNumber = entity.ctid;
  7716. apiVo.actionName = "afterOver";
  7717. designHelper.API_WorkCore(apiVo); //afterOver
  7718. }
  7719. entity.UpdateTime = DateTime.Now;
  7720. entity.Update();
  7721. returnSuccessMsg("操作成功!");
  7722. CeErpSukuraData.createInfo(entity.ctid, 8);
  7723. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
  7724. LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), CurrentUser.UserID, st == 1 ? 0 : 1, afmemo, image);
  7725. return;
  7726. }
  7727. }
  7728. returnErrorMsg("找不到订单记录");
  7729. }
  7730. }
  7731. public void set_erp_supplierrefundtag()
  7732. {
  7733. if (UrlPostParmsCheck("ctid"))
  7734. {
  7735. string eid = GetPostString("ctid");
  7736. CeErpTradeCell entity = null;
  7737. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  7738. if (entity != null)
  7739. {
  7740. entity.IsSupplierRefund = GetPostInt("tag");
  7741. entity.Update();
  7742. returnSuccessMsg("操作成功!");
  7743. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记供应商是否退款" + entity.IsSupplierRefund, 0, 3);
  7744. return;
  7745. }
  7746. returnErrorMsg("找不到订单记录");
  7747. }
  7748. }
  7749. public void get_erp_refundlist()
  7750. {
  7751. DataStruct dStruct = GetPostStruct();
  7752. List<string> lw = new List<string>();
  7753. string tid = GetPostString("tid");
  7754. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7755. //string rid = GetPostString("refund_id");
  7756. //if (rid.Length > 0) lw.Add(string.Format("refund_id like '%{0}%'", rid));
  7757. string shopname = GetPostString("shopname");
  7758. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7759. string buyernick = GetPostString("buyer_nick");
  7760. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7761. string customer = GetPostString("customer");
  7762. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7763. string design = GetPostString("design");
  7764. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7765. string sellermemo = GetPostString("seller_memo");
  7766. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7767. //string date1 = GetPostString("date1");
  7768. //string date2 = GetPostString("date2");
  7769. //string dateType = GetPostString("dateType");
  7770. //if (dateType.Length > 0)
  7771. //{
  7772. // if (dateType == "1001") dateType = "0";
  7773. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(dateType);
  7774. // if (searchDT.Count == 2)
  7775. // {
  7776. // date1 = searchDT[0].ToString();
  7777. // date2 = searchDT[1].ToString();
  7778. // }
  7779. //}
  7780. //string dw = GetDateMinuteWhere("pay_time", date1, date2);
  7781. //if (dw.Length > 0) lw.Add(dw);
  7782. string redate1 = GetPostString("refunddate1");
  7783. string redate2 = GetPostString("refunddate2");
  7784. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7785. if (dwdate.Length > 0) lw.Add(dwdate);
  7786. string price1 = GetPostString("price1");
  7787. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7788. string price2 = GetPostString("price2");
  7789. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7790. string ispartrefund = GetPostString("ispartrefund");
  7791. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7792. string refundState = GetPostString("refundvstate");
  7793. if (refundState.Length > 0) lw.Add(string.Format("RefundState={0}", refundState));
  7794. int st = GetInt("st");
  7795. if (st == 2) //待确认列表中,把state=3已确认的也显示
  7796. {
  7797. string responsible = GetPostString("responsibleman");
  7798. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7799. lw.Add(string.Format("RefundState>={0}", st));
  7800. string code = CurrentUser.UserPost.Post.Code;
  7801. if (code == "CustomerService")
  7802. {
  7803. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_k"));
  7804. }
  7805. else if (code == "Designer" || code == "DesignerMr" || code == "wxDesignerMr")
  7806. {
  7807. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_s"));
  7808. }
  7809. else if (code == "Place" || code == "PlaceMr")
  7810. {
  7811. lw.Add(string.Format("','+ResponsibleUserId+',' like '%{0}%'", "," + CurrentUser.UserID.ToString() + "_x"));
  7812. }
  7813. dStruct.Order = "RefundState asc,created desc";
  7814. }
  7815. else if (st == 10)
  7816. {
  7817. string responsible = GetPostString("responsibleman");
  7818. if (responsible == "空白")
  7819. {
  7820. lw.Add(string.Format("ResponsibleUserName = ''"));
  7821. }
  7822. else if (responsible.Length > 0)
  7823. {
  7824. lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7825. }
  7826. lw.Add(string.Format("RefundState>=0"));
  7827. dStruct.Order = "created desc";
  7828. }
  7829. else
  7830. {
  7831. string responsible = GetPostString("responsibleman");
  7832. if (responsible.Length > 0) lw.Add(string.Format("ResponsibleUserName like '%{0}%'", responsible));
  7833. lw.Add(string.Format("RefundState={0}", st));
  7834. dStruct.Order = "created desc";
  7835. }
  7836. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7837. DataTable dt = WebCache.GetData("view_ErpTradeRefund", dStruct);
  7838. dt.Columns.Add("refund_fees");
  7839. foreach (DataRow dr in dt.Rows)
  7840. {
  7841. String status = dr["status"].ToString();
  7842. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7843. {
  7844. dr["refund_fees"] = dr["refund_fee"];
  7845. }
  7846. else
  7847. {
  7848. dr["refund_fees"] = "0.0";
  7849. }
  7850. }
  7851. writeGridDataTableJson(dStruct.TotalCount, dt);
  7852. }
  7853. public void get_erp_refunddesignlist()
  7854. {
  7855. DataStruct dStruct = GetPostStruct();
  7856. List<string> lw = new List<string>();
  7857. string tid = GetPostString("tid");
  7858. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  7859. string shopname = GetPostString("shopname");
  7860. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  7861. string buyernick = GetPostString("buyer_nick");
  7862. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  7863. string customer = GetPostString("customer");
  7864. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  7865. string design = GetPostString("design");
  7866. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  7867. string sellermemo = GetPostString("seller_memo");
  7868. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  7869. string redate1 = GetPostString("refunddate1");
  7870. string redate2 = GetPostString("refunddate2");
  7871. string dwdate = GetDateMinuteWhere("created", redate1, redate2);
  7872. if (dwdate.Length > 0) lw.Add(dwdate);
  7873. string price1 = GetPostString("price1");
  7874. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  7875. string price2 = GetPostString("price2");
  7876. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  7877. string ispartrefund = GetPostString("ispartrefund");
  7878. if (ispartrefund.Length > 0) lw.Add(string.Format("IsPartRefund={0}", ispartrefund));
  7879. string designerorg = GetPostString("designerorg");
  7880. if (designerorg.Length > 0) lw.Add(string.Format("DesOrgID={0}", designerorg));
  7881. string refundState = GetPostString("refundState");
  7882. if (refundState.Length > 0) lw.Add(string.Format("restatus='{0}'", refundState));
  7883. int myOrgid = CurrentUser.UserPost.OrgID;
  7884. string myOrgCode = CurrentUser.UserPost.Post.Code;
  7885. if ("Designer".Equals(myOrgCode))//设计师能看到的
  7886. {
  7887. if (CurrentUser.User.TeamIds.Length > 0)
  7888. {
  7889. lw.Add(string.Format(" DesignUserId in ({1})", CurrentUser.UserID, CurrentUser.User.TeamIds));
  7890. }
  7891. else
  7892. {
  7893. lw.Add(string.Format("DesignUserId = {0} ", CurrentUser.UserID));
  7894. }
  7895. }
  7896. else if ("SysAdmin".Equals(myOrgCode))
  7897. {
  7898. }
  7899. else
  7900. {
  7901. if (CurrentUser.User.ManageOrgIds.Length > 0)
  7902. {
  7903. lw.Add(string.Format("DesOrgID in ({0})", CurrentUser.User.ManageOrgIds));
  7904. }
  7905. else
  7906. {
  7907. lw.Add(string.Format("DesOrgID = {0}", myOrgid));
  7908. }
  7909. }
  7910. lw.Add("OrderState in (3,4,5,9) and CONVERT ( numeric, refund_fee ) > 0");
  7911. dStruct.Order = "created desc";
  7912. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  7913. DataTable dt = WebCache.GetData("view_ErpTradeCellRefund", dStruct);
  7914. dt.Columns.Add("refund_fees");
  7915. foreach (DataRow dr in dt.Rows)
  7916. {
  7917. String status = dr["status"].ToString();
  7918. if (status.Equals("SUCCESS") || status.Equals("REFUNDED"))
  7919. {
  7920. dr["refund_fees"] = dr["refund_fee"];
  7921. }
  7922. else
  7923. {
  7924. dr["refund_fees"] = "0.0";
  7925. }
  7926. }
  7927. writeGridDataTableJson(dStruct.TotalCount, dt);
  7928. }
  7929. public void handle_erp_refundtag()
  7930. {
  7931. if (UrlPostParmsCheck("refund_id"))
  7932. {
  7933. string eid = GetPostString("refund_id");
  7934. string respMan = GetPostString("ResponsibleName");
  7935. if (respMan.Length <= 0)
  7936. {
  7937. returnErrorMsg("责任人不能为空");
  7938. return;
  7939. }
  7940. CeErpTradeRefund entity = null;
  7941. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  7942. if (entity != null)
  7943. {
  7944. entity.ResponsibleUserName = respMan;
  7945. string userid = GetPostString("ResponsibleUserId");
  7946. if (userid.Length > 0)
  7947. {
  7948. entity.ResponsibleUserId = userid;
  7949. }
  7950. entity.Memo = GetPostString("Memo");
  7951. if (respMan.IndexOf("客服") != -1 ||
  7952. respMan.IndexOf("设计师") != -1 ||
  7953. respMan.IndexOf("下单员") != -1)
  7954. {
  7955. entity.RefundState = 2;
  7956. }
  7957. else
  7958. {
  7959. entity.RefundState = 3;
  7960. }
  7961. entity.modified = DateTime.Now;
  7962. entity.Update();
  7963. LogHelper.addLog(entity.tid, CurrentUser.UserID, "标记退款责任人");
  7964. returnSuccessMsg("操作成功!");
  7965. return;
  7966. }
  7967. returnErrorMsg("找不到订单记录");
  7968. }
  7969. }
  7970. public void handle_erp_designrefundtag()
  7971. {
  7972. if (UrlPostParmsCheck("refund_id"))
  7973. {
  7974. string eid = GetPostString("refund_id");
  7975. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(eid);
  7976. if (ceErpTradeCellExtend == null)
  7977. {
  7978. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  7979. ceErpTradeCellExtend.ctid = eid;
  7980. }
  7981. ceErpTradeCellExtend.RefundMemo = GetPostString("Memo");
  7982. if (ceErpTradeCellExtend.ID > 0)
  7983. {
  7984. ceErpTradeCellExtend.Update();
  7985. }
  7986. else
  7987. {
  7988. ceErpTradeCellExtend.Create();
  7989. }
  7990. LogHelper.addLog(ceErpTradeCellExtend.ctid, CurrentUser.UserID, "退款标记:" + ceErpTradeCellExtend.RefundMemo);
  7991. returnSuccessMsg("操作成功!");
  7992. return;
  7993. }
  7994. returnErrorMsg("找不到订单记录");
  7995. }
  7996. public void upd_erp_refundverify()
  7997. {
  7998. if (UrlPostParmsCheck("refund_id"))
  7999. {
  8000. string eid = GetPostString("refund_id");
  8001. CeErpTradeRefund entity = null;
  8002. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8003. if (entity != null)
  8004. {
  8005. if (entity.ResponsibleUserName.IndexOf("客服") != -1 ||
  8006. entity.ResponsibleUserName.IndexOf("设计师") != -1 ||
  8007. entity.ResponsibleUserName.IndexOf("下单员") != -1)
  8008. {
  8009. entity.RefundState = 2;
  8010. }
  8011. else
  8012. {
  8013. entity.RefundState = 3;
  8014. }
  8015. entity.Update();
  8016. LogHelper.addLog(entity.tid, CurrentUser.UserID, "处理标记退款责任人");
  8017. returnSuccessMsg("操作成功!");
  8018. return;
  8019. }
  8020. returnErrorMsg("找不到订单记录");
  8021. }
  8022. }
  8023. public void upd_erp_refundapprove()
  8024. {
  8025. if (UrlPostParmsCheck("refund_id"))
  8026. {
  8027. string eid = GetPostString("refund_id");
  8028. CeErpTradeRefund entity = null;
  8029. if (eid != "") entity = CeErpTradeRefund.Get(eid);
  8030. if (entity != null)
  8031. {
  8032. int apr = GetPostInt("approve");
  8033. if (apr == 0)
  8034. {
  8035. entity.RefundState = 1;
  8036. LogHelper.addLog(entity.tid, CurrentUser.UserID, "不认可责任");
  8037. }
  8038. else if (apr == 1)
  8039. {
  8040. entity.RefundState = 3;
  8041. LogHelper.addLog(entity.tid, CurrentUser.UserID, "认可责任");
  8042. }
  8043. entity.modified = DateTime.Now;
  8044. entity.Update();
  8045. returnSuccessMsg("操作成功!");
  8046. return;
  8047. }
  8048. returnErrorMsg("找不到订单记录");
  8049. }
  8050. }
  8051. public void get_erp_billlist()
  8052. {
  8053. DataStruct dStruct = GetPostStruct();
  8054. List<string> lw = new List<string>();
  8055. string title = GetPostString("title");
  8056. if (title.Length > 0) lw.Add(string.Format("title like '%{0}%'", title));
  8057. string tid = GetPostString("tid");
  8058. string tids = GetPostString("tids");
  8059. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8060. if (tids.Length > 0)
  8061. {
  8062. tids = "'" + tids + "'";
  8063. tids = tids.Replace(",", "','");
  8064. lw.Add(string.Format("tid in ({0})", tids));
  8065. }
  8066. string shopname = GetPostString("shopname");
  8067. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8068. string buyernick = GetPostString("buyer_nick");
  8069. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8070. string customer = GetPostString("customer");
  8071. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  8072. string date1 = GetPostString("date1");
  8073. string date2 = GetPostString("date2");
  8074. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  8075. if (dw.Length > 0) lw.Add(dw);
  8076. string price1 = GetPostString("price1");
  8077. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  8078. string price2 = GetPostString("price2");
  8079. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  8080. string returndate1 = GetPostString("returndate1");
  8081. string returndate2 = GetPostString("returndate2");
  8082. string dw1 = GetDateMinuteWhere("createTime", returndate1, returndate2);
  8083. if (dw1.Length > 0) lw.Add(dw1);
  8084. string billtype = GetPostString("billtype");
  8085. if (billtype.Length > 0) lw.Add(string.Format("sendType = '{0}'", billtype));
  8086. string billstate = GetPostString("billstate");
  8087. if (billstate.Length > 0) lw.Add(string.Format("state = {0}", Convert.ToInt32(billstate)));
  8088. string usershop = CurrentUser.User.pemShop;
  8089. lw.Add(string.Format("seller_nick in (select shopname from ce_erpshop where id in ({0}))", usershop));
  8090. dStruct.Order = "createTime desc";
  8091. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8092. DataTable dt = WebCache.GetData("view_ErpBill", dStruct);
  8093. //foreach (DataRow dr in dt.Rows)
  8094. //{
  8095. // dr["title"] = dr["title"].ToString() + "|" + dr["tax"].ToString() + "|" + dr["ProductName"].ToString() + "|" + dr["bank"].ToString() + "|" + dr["bankac"].ToString() + "|" + dr["address"].ToString();
  8096. //}
  8097. writeGridDataTableJson(dStruct.TotalCount, dt);
  8098. }
  8099. public void modify_erp_billinfo()
  8100. {
  8101. if (UrlPostParmsCheck("ID"))
  8102. {
  8103. string eid = GetPostString("ID");
  8104. CeErpBill bill_entity = null;
  8105. if (eid != "") bill_entity = CeErpBill.Get(eid);
  8106. if (bill_entity != null)
  8107. {
  8108. bill_entity.tid = GetPostString("tid");
  8109. bill_entity.title = GetPostString("title");
  8110. bill_entity.tax = GetPostString("tax");
  8111. bill_entity.bank = GetPostString("bank");
  8112. bill_entity.bankac = GetPostString("bankac");
  8113. bill_entity.address = GetPostString("address");
  8114. bill_entity.phone = GetPostString("phone");
  8115. bill_entity.price = GetPostString("price");
  8116. bill_entity.productId = GetPostInt("ProductName");
  8117. bill_entity.num = GetPostInt("num");
  8118. bill_entity.unit = GetPostString("unit");
  8119. bill_entity.type = GetPostString("type");
  8120. bill_entity.sendType = GetPostString("SendType");
  8121. bill_entity.email = GetPostString("email");
  8122. bill_entity.buyer_nick = GetPostString("buyer_nick");
  8123. bill_entity.shopName = GetPostString("ShopName");
  8124. bill_entity.applymemo = GetPostString("applymemo");
  8125. bill_entity.modifyTime = DateTime.Now;
  8126. bill_entity.createTime = DateTime.Now;
  8127. bill_entity.state = 0;
  8128. bill_entity.Update();
  8129. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "修改发票", 0, 1);
  8130. returnSuccessMsg("发票修改成功!");
  8131. return;
  8132. }
  8133. returnErrorMsg("找不到对应记录");
  8134. }
  8135. }
  8136. public void set_erp_invoicing()
  8137. {
  8138. if (UrlPostParmsCheck("id"))
  8139. {
  8140. try
  8141. {
  8142. string eid = GetPostString("id");
  8143. CeErpBill bill_entity = null;
  8144. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8145. if (bill_entity != null)
  8146. {
  8147. int ComId = GetPostInt("ComId");
  8148. //string memo = GetPostString("Memo");
  8149. int allInfo = GetPostInt("allinfo");
  8150. string clert = CurrentUser.User.Name;
  8151. //string detailValue = GetPostString("detailvalue");
  8152. string billId = bill_entity.billOrderId;
  8153. string[] billIdList = billId.Split(',');
  8154. CeErpInvoicingInfo comInfo = CeErpInvoicingInfo.Get(ComId);
  8155. int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / Convert.ToDouble(comInfo.LimitPrice));
  8156. if (Convert.ToDouble(bill_entity.price) % Convert.ToDouble(comInfo.LimitPrice) > 0.00001)
  8157. {
  8158. billCount += 1;
  8159. }
  8160. if (billId.Length <= 0 || billIdList.Length != billCount)
  8161. {
  8162. bill_entity.billOrderId = "";
  8163. string prebill = "ltb";
  8164. for (int idx = 1; idx <= billCount; idx++)
  8165. {
  8166. string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
  8167. string billoid = prebill + idx + dtstr;
  8168. bill_entity.billOrderId += billoid;
  8169. if (idx < billCount)
  8170. {
  8171. bill_entity.billOrderId += ",";
  8172. }
  8173. }
  8174. }
  8175. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8176. if (bill_entity.state == 5)
  8177. {
  8178. string errMsg = bill_entity.failerror;
  8179. string[] errlist = errMsg.Split('|');
  8180. string[] errTags = new string[errlist.Length];
  8181. for (int itag = 0; itag < errlist.Length; itag++)
  8182. {
  8183. if (errlist[itag].Length <= 0) continue;
  8184. errTags[itag] = errlist[itag].Split('&')[0];
  8185. }
  8186. for (int iii = 0; iii < errTags.Length; iii++)
  8187. {
  8188. if (errTags[iii] == null || errTags[iii].Length <= 0) continue;
  8189. int erroBillOrderTag = Convert.ToInt32(errTags[iii]);
  8190. if (billOrderList.Length >= erroBillOrderTag)
  8191. {
  8192. string needModifyBillId = billOrderList[erroBillOrderTag - 1];
  8193. if (needModifyBillId.Length <= 19)
  8194. {
  8195. needModifyBillId = needModifyBillId + "1";
  8196. }
  8197. else
  8198. {
  8199. int last = Convert.ToInt32(needModifyBillId.Substring(needModifyBillId.Length - 1, 1));
  8200. last = last + 1;
  8201. needModifyBillId = needModifyBillId.Substring(0, needModifyBillId.Length - 1) + Convert.ToString(last);
  8202. }
  8203. billOrderList[erroBillOrderTag - 1] = needModifyBillId;
  8204. }
  8205. }
  8206. }
  8207. bool isHaveBillSucces = false;
  8208. string totalRes = "";
  8209. bill_entity.failerror = "";
  8210. for (int ii = 1; ii <= billOrderList.Length; ii++)
  8211. {
  8212. string res = taobaoHelper.invoicing(eid, ComId, clert, billOrderList[ii - 1], ii - 1, billOrderList.Length, allInfo);
  8213. totalRes += res;
  8214. if (res.IndexOf("同步成功") != -1 && res.IndexOf("0000") != -1 && res.IndexOf("失败") == -1 && res.IndexOf("null") == -1)
  8215. {
  8216. isHaveBillSucces = true;
  8217. bill_entity.comId = ComId;
  8218. bill_entity.state = 1;
  8219. bill_entity.executeTime = DateTime.Now;
  8220. bill_entity.executeUser = clert;
  8221. }
  8222. else
  8223. {
  8224. bill_entity.state = 5;
  8225. bill_entity.failerror = bill_entity.failerror + (ii + "&" + commonHelper.KeepChinese(res) + "|");
  8226. }
  8227. }
  8228. bill_entity.billOrderId = string.Join(",", billOrderList.ToArray());
  8229. bill_entity.Update();
  8230. if (isHaveBillSucces)
  8231. {
  8232. StringBuilder sql = new StringBuilder();
  8233. sql.AppendFormat("insert into S_BuChaJia(ctid,addtime,dotype) values('{0}',getdate(),'billres'); ", eid);
  8234. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8235. }
  8236. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "开具发票", 0, 1);
  8237. if (totalRes.IndexOf("失败") != -1 || totalRes.IndexOf("null") != -1)
  8238. {
  8239. returnErrorMsg("开票失败");
  8240. }
  8241. else
  8242. returnSuccessMsg("发票开具中,稍后刷新查看!");
  8243. return;
  8244. }
  8245. returnErrorMsg("找不到对应记录");
  8246. }
  8247. catch (Exception ex)
  8248. {
  8249. XLog.SaveLog(0, "开票失败,发生错误," + ex.Message);
  8250. returnErrorMsg("操作失败");
  8251. }
  8252. }
  8253. }
  8254. public void get_erp_invoicing_back()
  8255. {
  8256. if (UrlPostParmsCheck("id"))
  8257. {
  8258. try
  8259. {
  8260. string id = GetPostString("id");
  8261. CeErpBill entiy = CeErpBill.Get(id);
  8262. if (entiy != null)
  8263. {
  8264. if (entiy.state == 0)
  8265. {
  8266. returnErrorMsg("发票还未开具");
  8267. return;
  8268. }
  8269. string[] billOrderList = entiy.billOrderId.Split(',');
  8270. int iTag = 0;
  8271. entiy.fplsh = "";
  8272. entiy.fpdm = "";
  8273. entiy.fphm = "";
  8274. foreach (string billOrderId in billOrderList)
  8275. {
  8276. iTag++;
  8277. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8278. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8279. {
  8280. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8281. try
  8282. {
  8283. Invoicing_get_response_Obj iObj = null;
  8284. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8285. if (iObj != null)
  8286. {
  8287. entiy.state = 2;
  8288. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8289. entiy.fpdm += iObj.list[0].c_fpdm;
  8290. entiy.fphm += iObj.list[0].c_fphm;
  8291. if (iTag < billOrderList.Length)
  8292. {
  8293. entiy.fplsh += ",";
  8294. entiy.fpdm += ",";
  8295. entiy.fphm += ",";
  8296. }
  8297. entiy.Update();
  8298. }
  8299. StringBuilder sql = new StringBuilder();
  8300. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8301. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8302. returnSuccessMsg("开票成功");
  8303. }
  8304. catch (Exception ex)
  8305. {
  8306. XLog.SaveLog(0, "查看开票结果,更新状态失败" + ex.Message + res);
  8307. }
  8308. return;
  8309. }
  8310. else if (res.IndexOf("success") != -1 && res.IndexOf("开票中") != -1)
  8311. {
  8312. var res_obj = new
  8313. {
  8314. data = "开票中"
  8315. };
  8316. string ro_json = JsonConvert.SerializeObject(res_obj);
  8317. returnSuccess(ro_json);
  8318. return;
  8319. }
  8320. else
  8321. {
  8322. int eidx = res.IndexOf("c_resultmsg");
  8323. int lidx = res.IndexOf("c_status");
  8324. string emsg = commonHelper.KeepChinese(res.Substring(eidx, lidx - eidx));
  8325. entiy.state = 5;
  8326. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8327. entiy.Update();
  8328. returnErrorMsg("开票失败");
  8329. return;
  8330. }
  8331. }
  8332. }
  8333. }
  8334. catch (Exception ex)
  8335. {
  8336. XLog.SaveLog(0, "查看发票发生错误," + ex.Message);
  8337. }
  8338. return;
  8339. }
  8340. }
  8341. public void get_erp_invoicing()
  8342. {
  8343. if (UrlPostParmsCheck("id"))
  8344. {
  8345. try
  8346. {
  8347. string id = GetPostString("id");
  8348. CeErpBill entiy = CeErpBill.Get(id);
  8349. if (entiy != null)
  8350. {
  8351. if (entiy.state == 0)
  8352. {
  8353. returnErrorMsg("发票还未开具");
  8354. return;
  8355. }
  8356. if (entiy.sendType == "纸质发票")
  8357. {
  8358. if (entiy.img.Length <= 0)
  8359. {
  8360. returnErrorMsg("查无纸质发票");
  8361. return;
  8362. }
  8363. string returnres = "{\"result\":\"success\",\"list\":[{\"c_url\":\"" + entiy.img.ToString() + "\"}]}";
  8364. returnSuccess(returnres);
  8365. return;
  8366. }
  8367. string[] billOrderList = entiy.billOrderId.Split(',');
  8368. int iTag = 0;
  8369. string fpUrl = "";
  8370. entiy.fplsh = "";
  8371. entiy.fpdm = "";
  8372. entiy.fphm = "";
  8373. foreach (string billOrderId in billOrderList)
  8374. {
  8375. iTag++;
  8376. string res = taobaoHelper.get_invoicing(id, billOrderId);
  8377. if (res.IndexOf("success") != -1 && (res.IndexOf("开票成功") != -1 || res.IndexOf("开票完成") != -1))
  8378. {
  8379. //res = GetUTF8String2(Encoding.UTF8.GetBytes(res));
  8380. Invoicing_get_response_Obj iObj = null;
  8381. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(res);
  8382. if (iObj != null)
  8383. {
  8384. //entiy.state = 2;
  8385. entiy.fplsh += iObj.list[0].c_fpqqlsh;
  8386. entiy.fpdm += iObj.list[0].c_fpdm;
  8387. entiy.fphm += iObj.list[0].c_fphm;
  8388. if (iTag < billOrderList.Length)
  8389. {
  8390. entiy.fplsh += ",";
  8391. entiy.fpdm += ",";
  8392. entiy.fphm += ",";
  8393. }
  8394. entiy.Update();
  8395. fpUrl += iObj.list[0].c_url + ",";
  8396. }
  8397. //returnSuccess(res);
  8398. StringBuilder sql = new StringBuilder();
  8399. sql.AppendFormat("update CE_ErpTradeCell set IsNeedBill=2 where tid='{0}';", entiy.tid);
  8400. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  8401. }
  8402. else
  8403. {
  8404. int eidx = res.IndexOf("c_resultmsg");
  8405. //int lidx = res.IndexOf("c_status");
  8406. string emsg = commonHelper.KeepChinese(res.Substring(eidx, res.Length - eidx));
  8407. //开票失败
  8408. entiy.state = 5;
  8409. entiy.failerror = entiy.failerror + (iTag + "&" + emsg + "|");
  8410. entiy.Update();
  8411. returnErrorMsg("开票失败");
  8412. return;
  8413. }
  8414. }
  8415. var returnObj = new
  8416. {
  8417. data = fpUrl
  8418. };
  8419. string ro_json = JsonConvert.SerializeObject(returnObj);
  8420. returnSuccess(ro_json);
  8421. }
  8422. }
  8423. catch (Exception ex)
  8424. {
  8425. XLog.SaveLog(0, "下载查看发票发生错误," + ex.Message);
  8426. }
  8427. return;
  8428. }
  8429. }
  8430. public void save_erp_billimg()
  8431. {
  8432. if (UrlPostParmsCheck("id"))
  8433. {
  8434. string eid = GetPostString("id");
  8435. CeErpBill bill_entity = null;
  8436. if (eid.Length > 0) bill_entity = CeErpBill.Get(eid);
  8437. if (bill_entity != null)
  8438. {
  8439. bill_entity.img = GetPostString("img");
  8440. bill_entity.executeTime = DateTime.Now;
  8441. bill_entity.state = 2;
  8442. bill_entity.Update();
  8443. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "上传纸质发票", 0, 1);
  8444. returnSuccessMsg("保存成功");
  8445. }
  8446. return;
  8447. }
  8448. }
  8449. public void upd_erp_billreturnback()
  8450. {
  8451. if (UrlPostParmsCheck("id"))
  8452. {
  8453. int eid = GetPostInt("id");
  8454. CeErpBill bill_entity = null;
  8455. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8456. if (bill_entity != null)
  8457. {
  8458. bill_entity.state = 3;
  8459. bill_entity.returnReason = GetPostString("reason");
  8460. bill_entity.Update();
  8461. returnSuccessMsg("驳回成功!");
  8462. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票驳回", 0, 1);
  8463. }
  8464. return;
  8465. }
  8466. }
  8467. public void cancel_erp_bill()
  8468. {
  8469. if (UrlPostParmsCheck("id"))
  8470. {
  8471. int eid = GetPostInt("id");
  8472. int detailValue = GetPostInt("detailvalue");
  8473. CeErpBill bill_entity = null;
  8474. if (eid != 0) bill_entity = CeErpBill.Get(eid);
  8475. string cres = "";
  8476. string gres = "";
  8477. if (bill_entity != null)
  8478. {
  8479. string[] billOrderList = bill_entity.billOrderId.Split(',');
  8480. if (bill_entity.fpdm == "" && bill_entity.sendType == "电子发票")
  8481. {
  8482. int iTag = 0;
  8483. bill_entity.fplsh = "";
  8484. bill_entity.fpdm = "";
  8485. bill_entity.fphm = "";
  8486. foreach (string billOrderId in billOrderList)
  8487. {
  8488. iTag++;
  8489. gres = taobaoHelper.get_invoicing(bill_entity.ID.ToString(), billOrderId);
  8490. if (gres.IndexOf("success") != -1)
  8491. {
  8492. //gres = GetUTF8String2(Encoding.UTF8.GetBytes(gres));
  8493. Invoicing_get_response_Obj iObj = null;
  8494. iObj = JsonConvert.DeserializeObject<Invoicing_get_response_Obj>(gres);
  8495. if (iObj != null)
  8496. {
  8497. bill_entity.fplsh += iObj.list[0].c_fpqqlsh;
  8498. bill_entity.fpdm += iObj.list[0].c_fpdm;
  8499. bill_entity.fphm += iObj.list[0].c_fphm;
  8500. if (iTag < billOrderList.Length)
  8501. {
  8502. bill_entity.fplsh += ",";
  8503. bill_entity.fpdm += ",";
  8504. bill_entity.fphm += ",";
  8505. }
  8506. bill_entity.Update();
  8507. }
  8508. }
  8509. else
  8510. {
  8511. returnErrorMsg(gres);
  8512. return;
  8513. }
  8514. }
  8515. }
  8516. if (bill_entity.sendType == "纸质发票")
  8517. {
  8518. //作废
  8519. //DateTime extime = DateTime.Parse(bill_entity.executeTime.ToString());
  8520. //if (DateTime.Now.Month == extime.Month)
  8521. //{
  8522. //cres = taobaoHelper.cancel_invoicing(eid);
  8523. //if (cres.IndexOf("同步成功") != -1 && cres.IndexOf("0000") != -1 && cres.IndexOf("失败") == -1)
  8524. //{
  8525. bill_entity.state = 4;//已作废
  8526. bill_entity.Update();
  8527. returnSuccessMsg("发票已作废");
  8528. return;
  8529. //}
  8530. //else
  8531. //{
  8532. // bill_entity.failerror = bill_entity.failerror + "##||##" + cres;
  8533. // bill_entity.Update();
  8534. // returnErrorMsg(cres);
  8535. // return;
  8536. //}
  8537. //}
  8538. //else
  8539. //{
  8540. // returnErrorMsg("纸质发票只能作废本月的发票");
  8541. // return;
  8542. //}
  8543. }
  8544. //红冲
  8545. int redTag = 0;
  8546. string[] fpdmList = bill_entity.fpdm.Split(',');
  8547. string[] fphmList = bill_entity.fphm.Split(',');
  8548. if (fpdmList.Length != billOrderList.Length || fphmList.Length != billOrderList.Length)
  8549. {
  8550. returnErrorMsg("发票代码、号码个数跟发票订单ID数不一致");
  8551. return;
  8552. }
  8553. foreach (string billOrderId in billOrderList)
  8554. {
  8555. redTag++;
  8556. string onecres = taobaoHelper.invoicing_red(bill_entity.ID, CurrentUser.User.Name, billOrderId, fpdmList[redTag - 1], fphmList[redTag - 1], redTag - 1, billOrderList.Length);
  8557. cres += onecres;
  8558. cres += ",";
  8559. if (onecres.IndexOf("同步成功") != -1 && onecres.IndexOf("失败") == -1)
  8560. {
  8561. bill_entity.state = 4;//已作废
  8562. //bill_entity.Update();
  8563. //returnSuccessMsg("发票已红冲");
  8564. }
  8565. else if (onecres.IndexOf("重复冲红") != -1)
  8566. {
  8567. bill_entity.state = 4;//已作废
  8568. //bill_entity.Update();
  8569. //returnSuccessMsg("发票已红冲");
  8570. }
  8571. else
  8572. {
  8573. string errmsg = commonHelper.KeepChinese(onecres);
  8574. bill_entity.failerror += redTag + "&" + errmsg + "|";
  8575. }
  8576. }
  8577. bill_entity.Update();
  8578. if (cres.IndexOf("失败") != -1)
  8579. returnErrorMsg("红冲失败");
  8580. else
  8581. returnSuccessMsg("发票已红冲");
  8582. LogHelper.addLog(bill_entity.tid, CurrentUser.UserID, "发票红冲", 0, 1);
  8583. return;
  8584. }
  8585. return;
  8586. }
  8587. }
  8588. public void del_erp_billorder()
  8589. {
  8590. if (UrlPostParmsCheck("id"))
  8591. {
  8592. string eid = GetPostString("id");
  8593. CeErpBill.Del(eid);
  8594. CeErpBill bill = CeErpBill.Get(eid);
  8595. if (bill != null)
  8596. {
  8597. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票删除", 0, 1);
  8598. }
  8599. returnSuccessMsg("删除成功");
  8600. }
  8601. }
  8602. public void finish_erp_bill()
  8603. {
  8604. if (UrlPostParmsCheck("ids"))
  8605. {
  8606. string eids = GetPostString("ids");
  8607. string[] list = eids.Split(',');
  8608. foreach (string eid in list)
  8609. {
  8610. CeErpBill bill = CeErpBill.Get(eid);
  8611. if (bill != null)
  8612. {
  8613. bill.state = 2;
  8614. bill.Update();
  8615. LogHelper.addLog(bill.tid, CurrentUser.UserID, "发票标记成“已完成”", 0, 1);
  8616. }
  8617. }
  8618. returnSuccessMsg("操作成功");
  8619. }
  8620. }
  8621. public void get_erp_returncash()
  8622. {
  8623. DataStruct dStruct = GetPostStruct();
  8624. List<string> lw = new List<string>();
  8625. string tid = GetPostString("tid");
  8626. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8627. string shopname = GetPostString("shopname");
  8628. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  8629. string buyernick = GetPostString("buyer_nick");
  8630. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  8631. string customer = GetPostString("customer");
  8632. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  8633. string returndate1 = GetPostString("returndate1");
  8634. string returndate2 = GetPostString("returndate2");
  8635. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  8636. if (dw.Length > 0) lw.Add(dw);
  8637. string finishDate1 = GetPostString("finishdate1");
  8638. string finishDate2 = GetPostString("finishdate2");
  8639. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  8640. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8641. string returntype = GetPostString("returntype");
  8642. if (returntype.Length > 0) lw.Add(string.Format("rtype = '{0}'", returntype));
  8643. string returnvstate = GetPostString("returnvstate");
  8644. if (returnvstate.Length > 0) lw.Add(string.Format("cashstate = {0}", Convert.ToInt32(returnvstate)));
  8645. dStruct.Order = "created desc";
  8646. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8647. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  8648. writeGridDataTableJson(dStruct.TotalCount, dt);
  8649. }
  8650. public void get_erp_staygoods()
  8651. {
  8652. DataStruct dStruct = GetPostStruct();
  8653. List<string> lw = new List<string>();
  8654. string tid = GetPostString("tid");
  8655. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  8656. string shopname = GetPostString("shopname");
  8657. if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname));
  8658. string wangwang = GetPostString("wangwang");
  8659. if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang));
  8660. string customer = GetPostString("customer");
  8661. if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer));
  8662. string returndate1 = GetPostString("returndate1");
  8663. string returndate2 = GetPostString("returndate2");
  8664. string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2);
  8665. if (dw.Length > 0) lw.Add(dw);
  8666. string finishDate1 = GetPostString("finishdate1");
  8667. string finishDate2 = GetPostString("finishdate2");
  8668. string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2);
  8669. if (dw_finish.Length > 0) lw.Add(dw_finish);
  8670. string returnvstate = GetPostString("returnvstate");
  8671. if (returnvstate.Length > 0) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate)));
  8672. string persuadetype = GetPostString("persuadetype");
  8673. if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype));
  8674. string customerOrg = GetPostString("customerOrg");
  8675. if (customerOrg.Length > 0)
  8676. {
  8677. lw.Add(string.Format("OrgID = {0}", customerOrg));
  8678. }
  8679. dStruct.Order = "creata_time desc";
  8680. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  8681. DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct);
  8682. writeGridDataTableJson(dStruct.TotalCount, dt);
  8683. }
  8684. public void upd_erp_staygoods()
  8685. {
  8686. if (UrlPostParmsCheck("id"))
  8687. {
  8688. int eid = GetPostInt("id");
  8689. CeErpStayGoods entity = null;
  8690. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8691. if (entity != null)
  8692. {
  8693. entity.audit_type = 1;
  8694. entity.audit_time = DateTime.Now;
  8695. entity.audit_u_id = CurrentUser.UserID;
  8696. entity.audit_u_name = CurrentUser.UserName;
  8697. entity.Update();
  8698. returnSuccessMsg("审核成功!");
  8699. return;
  8700. }
  8701. returnErrorMsg("找不到订单记录");
  8702. }
  8703. }
  8704. public void upd_erp_stayGoodsback()
  8705. {
  8706. if (UrlPostParmsCheck("id"))
  8707. {
  8708. int eid = GetPostInt("id");
  8709. CeErpStayGoods entity = null;
  8710. if (eid != 0) entity = CeErpStayGoods.GetStayId(eid);
  8711. if (entity != null)
  8712. {
  8713. entity.audit_text = GetPostString("reason");
  8714. entity.audit_type = 2;
  8715. entity.audit_time = DateTime.Now;
  8716. entity.audit_u_id = CurrentUser.UserID;
  8717. entity.audit_u_name = CurrentUser.UserName;
  8718. entity.Update();
  8719. returnSuccessMsg("退回成功!");
  8720. return;
  8721. }
  8722. returnErrorMsg("找不到订单记录");
  8723. }
  8724. }
  8725. public void upd_erp_returncashverify()
  8726. {
  8727. if (UrlPostParmsCheck("ID"))
  8728. {
  8729. int eid = GetPostInt("ID");
  8730. CeErpReturnCash entity = null;
  8731. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8732. if (entity != null)
  8733. {
  8734. entity.cashstate = 1;
  8735. entity.verifytime = DateTime.Now;
  8736. entity.verifyuserid = CurrentUser.UserID;
  8737. entity.Update();
  8738. returnSuccessMsg("审核成功!");
  8739. return;
  8740. }
  8741. returnErrorMsg("找不到订单记录");
  8742. }
  8743. }
  8744. public void upd_all_erp_returncashverify()
  8745. {
  8746. if (UrlPostParmsCheck("ID"))
  8747. {
  8748. String[] list = GetPostString("ID").Split(',');
  8749. CeErpReturnCash entity = null;
  8750. for (int i = 0; i < list.Length; i++)
  8751. {
  8752. if (list[i] != "") entity = CeErpReturnCash.Get(list[i]);
  8753. if (entity != null)
  8754. {
  8755. if (entity.cashstate == 1)
  8756. {
  8757. returnErrorMsg("已审核过的订单不需要在审核!");
  8758. return;
  8759. }
  8760. entity.cashstate = 1;
  8761. entity.verifytime = DateTime.Now;
  8762. entity.verifyuserid = CurrentUser.UserID;
  8763. entity.Update();
  8764. }
  8765. }
  8766. returnSuccessMsg("审核成功!");
  8767. return;
  8768. }
  8769. }
  8770. public void upd_erp_returncashback()
  8771. {
  8772. if (UrlPostParmsCheck("ID"))
  8773. {
  8774. int eid = GetPostInt("ID");
  8775. CeErpReturnCash entity = null;
  8776. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8777. if (entity != null)
  8778. {
  8779. entity.backreason = GetPostString("reason");
  8780. entity.cashstate = 2;
  8781. entity.verifytime = DateTime.Now;
  8782. entity.verifyuserid = CurrentUser.UserID;
  8783. entity.Update();
  8784. returnSuccessMsg("退回成功!");
  8785. return;
  8786. }
  8787. returnErrorMsg("找不到订单记录");
  8788. }
  8789. }
  8790. public void upd_erp_returnprice()
  8791. {
  8792. if (UrlPostParmsCheck("ID"))
  8793. {
  8794. int eid = GetPostInt("ID");
  8795. CeErpReturnCash entity = null;
  8796. if (eid != 0) entity = CeErpReturnCash.Get(eid);
  8797. if (entity != null)
  8798. {
  8799. if (entity.cashstate == 1)
  8800. {
  8801. returnErrorMsg("审核通过了不能改");
  8802. return;
  8803. }
  8804. entity.returnprice = GetPostDouble("returnprice");
  8805. entity.Update();
  8806. returnSuccessMsg("修改成功!");
  8807. return;
  8808. }
  8809. returnErrorMsg("找不到订单记录");
  8810. }
  8811. }
  8812. public void del_erp_returncash()
  8813. {
  8814. if (UrlPostParmsCheck("ID"))
  8815. {
  8816. int eid = GetPostInt("ID");
  8817. CeErpReturnCash.Del(eid);
  8818. returnSuccessMsg("操作成功");
  8819. return;
  8820. }
  8821. }
  8822. public void test_for_do_sql()
  8823. {
  8824. string sql = GetPostString("sqlstr");
  8825. if (sql.Length > 0)
  8826. {
  8827. try
  8828. {
  8829. DbHelper.DbConn.ExecuteNonQuery(sql);
  8830. var res_obj = new
  8831. {
  8832. data = "成功",
  8833. };
  8834. string ro_json = JsonConvert.SerializeObject(res_obj);
  8835. returnSuccess(ro_json);
  8836. }
  8837. catch (Exception ex)
  8838. {
  8839. var res_obj = new
  8840. {
  8841. data = ex.Message,
  8842. };
  8843. string ro_json = JsonConvert.SerializeObject(res_obj);
  8844. returnSuccess(ro_json);
  8845. }
  8846. }
  8847. }
  8848. public void get_user_info()
  8849. {
  8850. DataTable dtUser = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_ErpUser where id={0};", CurrentUser.UserID)).Tables[0];
  8851. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dtUser));
  8852. }
  8853. public void get_total_data()
  8854. {
  8855. int userId = CurrentUser.UserID;
  8856. string sql = "";
  8857. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8858. {
  8859. 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);
  8860. }
  8861. else
  8862. {
  8863. 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 " +
  8864. "(select ID from CE_ErpUser where ID = {0}) d " +
  8865. "left join " +
  8866. "(select CustomerUserId as id, count(CustomerUserId) as orderCount, SUM(payment) as orderAmount from[view_ErpTradeCell] where OrderState = 8 group by CustomerUserId " +
  8867. ") a on d.ID = a.id left join " +
  8868. "(select CustomerUserId as id1, count(CustomerUserId) as refundCount, SUM(payment) as refundAmount from[view_ErpTradeCell] where IsRefund > 1 group by CustomerUserId " +
  8869. ") b on a.id = b.id1 left join" +
  8870. "(select CustomerUserId as id2, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from[view_ErpTradeCell] where AfterSaleState>0 group by CustomerUserId " +
  8871. ") c on a.id = c.id2;", userId);
  8872. }
  8873. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8874. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8875. }
  8876. public void get_date_area_total_data2()
  8877. {
  8878. int userId = CurrentUser.UserID;
  8879. string date_type = GetPostString("timetype");
  8880. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8881. string sql = "";
  8882. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8883. {
  8884. sql = string.Format("select e.id, isnull(a.unBeginCount, 0) as unBeginCount,isnull(a.unBeginAmount, 0) as unBeginAmount, " +
  8885. "isnull(b.unFinishCount, 0) as unFinishCount, isnull(b.unFinishAmount, 0) as unFinishAmount, " +
  8886. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8887. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8888. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8889. "(select DesignUserId as id, count(DesignUserId) as unBeginCount, SUM(payment) as unBeginAmount from [view_ErpTradeCell] " +
  8890. " where OrderState = 3 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8891. ") a on e.ID = a.id left join " +
  8892. "(select DesignUserId as id1, count(DesignUserId) as unFinishCount, SUM(payment) as unFinishAmount from [view_ErpTradeCell] " +
  8893. " where OrderState = 4 and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8894. ") b on a.id = b.id1 " +
  8895. "left join " +
  8896. "(select DesignUserId as id2, count(DesignUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8897. " where WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}' group by DesignUserId " +
  8898. ") c on a.id = c.id2 " +
  8899. "left join " +
  8900. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8901. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8902. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,' ; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8903. }
  8904. else
  8905. {
  8906. sql = string.Format("select e.id, isnull(a.afterCount, 0) as afterCount,isnull(a.afterAmount, 0) as afterAmount, " +
  8907. "isnull(c.totalCount, 0) as totalCount, isnull(c.totalAmount, 0) as totalAmount, " +
  8908. "isnull(d.refundCount, 0) as refundCount, isnull(d.refundAmount, 0) as refundAmount from " +
  8909. "(select ID from CE_ErpUser where ID = {0}) e left join " +
  8910. "(select CustomerUserId as id, count(CustomerUserId) as afterCount, SUM(payment) as afterAmount from [view_ErpTradeCell] " +
  8911. " where AfterSaleState>0 and AfterSaleTime >= '{1}' and AfterSaleTime <= '{2}' group by CustomerUserId " +
  8912. ") a on e.ID = a.id left join " +
  8913. "(select CustomerUserId as id2, count(CustomerUserId) as totalCount, SUM(payment) as totalAmount from [view_ErpTradeCell] " +
  8914. " where pay_time >= '{1}' and pay_time <= '{2}' group by CustomerUserId " +
  8915. ") c on a.id = c.id2 " +
  8916. "left join " +
  8917. "(select ResponsibleUserId as id3, count(ResponsibleUserId) as refundCount, SUM(cast(refund_fee as numeric(8,2))) as refundAmount from [CE_ErpTradeRefund] " +
  8918. " where created >= '{1}' and created <= '{2}' group by ResponsibleUserId " +
  8919. ") d on ','+d.id3+',' like ','+CONVERT(nvarchar , a.id)+'_s,'; ", userId, searchDT[0].ToString(), searchDT[1].ToString());
  8920. }
  8921. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  8922. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  8923. }
  8924. public void get_date_area_total_data()
  8925. {
  8926. int userId = CurrentUser.UserID;
  8927. string date_type = GetPostString("timetype");
  8928. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8929. string date1 = searchDT[0].ToString();
  8930. string date2 = searchDT[1].ToString();
  8931. if (CurrentUser.UserPost.Post.Code == "Designer" || CurrentUser.UserPost.Post.Code == "DesignerMr")
  8932. {
  8933. SqlParameter[] sqlParameter ={
  8934. new SqlParameter("@userId", SqlDbType.Int,4),
  8935. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8936. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8937. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8938. };
  8939. sqlParameter[0].Value = userId;
  8940. sqlParameter[1].Value = date1;
  8941. sqlParameter[2].Value = date2;
  8942. sqlParameter[3].Direction = ParameterDirection.Output;
  8943. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_des", sqlParameter);
  8944. string res = sqlParameter[3].Value.ToString();
  8945. var res_obj = new
  8946. {
  8947. data = res
  8948. };
  8949. string ro_json = JsonConvert.SerializeObject(res_obj);
  8950. returnSuccess(ro_json);
  8951. }
  8952. else
  8953. {
  8954. SqlParameter[] sqlParameter ={
  8955. new SqlParameter("@userId", SqlDbType.Int,4),
  8956. new SqlParameter("@sDisDate", SqlDbType.DateTime, 20),
  8957. new SqlParameter("@eDisDate", SqlDbType.DateTime, 20),
  8958. new SqlParameter("@res", SqlDbType.VarChar, 4000)
  8959. };
  8960. sqlParameter[0].Value = userId;
  8961. sqlParameter[1].Value = date1;
  8962. sqlParameter[2].Value = date2;
  8963. sqlParameter[3].Direction = ParameterDirection.Output;
  8964. DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_get_center_cus", sqlParameter);
  8965. string res = sqlParameter[3].Value.ToString();
  8966. var res_obj = new
  8967. {
  8968. data = res
  8969. };
  8970. string ro_json = JsonConvert.SerializeObject(res_obj);
  8971. returnSuccess(ro_json);
  8972. }
  8973. //writeGridDataViewJson(dt.Rows.Count, dv);
  8974. }
  8975. public void get_order_list()
  8976. {
  8977. string strFields = GetPostString("paraFields");
  8978. string strOrder = GetPostString("paraOrder");
  8979. string strWhere = GetPostString("paraWhere");
  8980. string strPageSize = GetPostString("paraPageSize");
  8981. DataStruct dStruct = GetPostStruct();
  8982. dStruct.PageSize = int.Parse(strPageSize);
  8983. dStruct.Fileds = strFields;
  8984. dStruct.Order = strOrder;
  8985. dStruct.MainWhere = strWhere;
  8986. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  8987. writeGridDataTableJson(dStruct.TotalCount, dt);
  8988. }
  8989. ////获取待开始订单列表
  8990. //public void get_wait_design_order_list()
  8991. //{
  8992. // string date_type = GetPostString("date_type");
  8993. // List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  8994. // DataStruct dStruct = GetPostStruct();
  8995. // dStruct.PageSize = 1000;
  8996. // dStruct.Fileds = "ctid, WaitDesignTime,payment,IsAutoDispatch";
  8997. // List<string> lw = new List<string>();
  8998. // lw.Add(string.Format("OrderState = 3 and DesignUserId = {0} and WaitDesignTime >= '{1}' and WaitDesignTime <= '{2}'",
  8999. // CurrentUser.UserID, searchDT[0].ToString(), searchDT[1].ToString()));
  9000. // dStruct.Order = "WaitDesignTime asc";
  9001. // dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9002. // DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  9003. // writeGridDataTableJson(dStruct.TotalCount, dt);
  9004. //}
  9005. //获取完成单量排名
  9006. public void get_finish_order_count_ranking()
  9007. {
  9008. /* string date_type = GetPostString("date_type");
  9009. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9010. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9011. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9012. "left join(select DesignUserId, COUNT(tid) as orderCount from view_ErpTradeCell " +
  9013. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9014. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9015. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9016. writeGridDataTableJson(0, new DataTable());
  9017. }
  9018. public void get_finish_order_amount_ranking()
  9019. {
  9020. /*string date_type = GetPostString("date_type");
  9021. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9022. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9023. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9024. "left join(select DesignUserId, SUM(payment) as orderAmount from view_ErpTradeCell " +
  9025. "where OrderState > 6 and OrderState < 9 and FinishDesignTime >= '{0}' and FinishDesignTime <= '{1}' group by DesignUserId) b on a.ID = b.DesignUserId " +
  9026. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9027. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];*/
  9028. writeGridDataTableJson(0, new DataTable());
  9029. }
  9030. public void get_finish_refund_count_ranking()
  9031. {
  9032. string date_type = GetPostString("date_type");
  9033. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9034. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderCount, 0) as orderCount " +
  9035. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9036. "left join(select ResponsibleUserId, COUNT(cast(refund_fee as numeric(8,2))) as orderCount from CE_ErpTradeRefund " +
  9037. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9038. "order by orderCount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9039. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9040. writeGridDataTableJson(dt.Rows.Count, dt);
  9041. }
  9042. public void get_finish_refund_amount_ranking()
  9043. {
  9044. string date_type = GetPostString("date_type");
  9045. List<DateTime> searchDT = WebHelper.GetStartEndDateTime(date_type);
  9046. string sql = string.Format("select a.Name,a.OrgName,ISNULL(b.orderAmount, 0) as orderAmount " +
  9047. "from(select * from view_ErpUser where PostCode = 'Designer' or PostCode='DesignerMr') a " +
  9048. "left join(select ResponsibleUserId, sum(cast(refund_fee as numeric(8,2))) as orderAmount from CE_ErpTradeRefund " +
  9049. "where created >= '{0}' and created <= '{1}' group by ResponsibleUserId) b on ','+b.ResponsibleUserId+',' like ','+CONVERT(nvarchar , a.ID)+'_s,' " +
  9050. "order by orderAmount desc", searchDT[0].ToString(), searchDT[1].ToString());
  9051. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  9052. writeGridDataTableJson(dt.Rows.Count, dt);
  9053. }
  9054. public void set_erp_finishorder_director()
  9055. {
  9056. if (UrlPostParmsCheck("ctid"))
  9057. {
  9058. string eid = GetPostString("ctid");
  9059. CeErpTradeCell entity = null;
  9060. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9061. if (entity != null)
  9062. {
  9063. entity.OrderState = 8;
  9064. entity.Update();
  9065. LogHelper.addLog(eid, CurrentUser.UserID, "电子稿直接完成设计到已完成", 4, 0);
  9066. returnSuccessMsg("操作成功!");
  9067. return;
  9068. }
  9069. returnErrorMsg("找不到记录");
  9070. }
  9071. }
  9072. public void get_erp_placeregistlist()
  9073. {
  9074. DataStruct dStruct = GetPostStruct();
  9075. List<string> lw = new List<string>();
  9076. string outsid = GetPostString("outsid");
  9077. if (outsid.Length > 0) lw.Add(string.Format("OutSid like '%{0}%'", outsid));
  9078. string memo = GetPostString("memo");
  9079. if (memo.Length > 0) lw.Add(string.Format("Memo like '%{0}%'", memo));
  9080. string filename = GetPostString("filename");
  9081. if (filename.Length > 0) lw.Add(string.Format("FileName like '%{0}%'", filename));
  9082. string islate = GetPostString("islate");
  9083. if (islate.Length > 0)
  9084. {
  9085. if (islate == "1")
  9086. lw.Add(string.Format("OutLate>0"));
  9087. else
  9088. lw.Add(string.Format("OutLate=0"));
  9089. }
  9090. string placedate1 = GetPostString("placedate1");
  9091. string placedate2 = GetPostString("placedate2");
  9092. string dw = GetDateMinuteWhere("PlactTime", placedate1, placedate2);
  9093. if (dw.Length > 0) lw.Add(dw);
  9094. string deliveryDate1 = GetPostString("deliverydate1");
  9095. string deliveryDate2 = GetPostString("deliverydate2");
  9096. string dw_deli = GetDateMinuteWhere("DeliveryTime", deliveryDate1, deliveryDate2);
  9097. if (dw_deli.Length > 0) lw.Add(dw_deli);
  9098. dStruct.Order = "ID desc";
  9099. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9100. DataTable dt = WebCache.GetData("View_ErpPlaceRegister", dStruct);
  9101. writeGridDataTableJson(dStruct.TotalCount, dt);
  9102. }
  9103. public void ins_erp_placeregist()
  9104. {
  9105. if (UrlPostParmsCheck("id"))
  9106. {
  9107. string eid = GetPostString("id");
  9108. CeErpPlaceRegister entity = null;
  9109. if (eid == "0")//新增
  9110. {
  9111. entity = new CeErpPlaceRegister();
  9112. string xdTime = GetPostString("placeTime");
  9113. if (xdTime.Length > 0)
  9114. {
  9115. entity.PlactTime = Convert.ToDateTime(xdTime);
  9116. }
  9117. string fhTime = GetPostString("deliveryTime");
  9118. if (fhTime.Length > 0)
  9119. {
  9120. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9121. }
  9122. string preTime = GetPostString("preOutTime");
  9123. if (preTime.Length > 0)
  9124. {
  9125. entity.PreOutTime = Convert.ToDateTime(preTime);
  9126. }
  9127. entity.DeliveryCount = GetPostInt("deliveryCount");
  9128. entity.ReceiveCount = GetPostInt("receiveCount");
  9129. entity.OutSid = GetPostString("outSid");
  9130. entity.FileName = GetPostString("fileName");
  9131. entity.Memo = GetPostString("memo");
  9132. entity.AddUserId = CurrentUser.UserID;
  9133. entity.CreateTime = DateTime.Now;
  9134. entity.Img = GetPostString("img");
  9135. entity.Supplier = GetPostInt("supplier");
  9136. entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9137. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9138. {
  9139. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9140. DateTime dt2 = (DateTime)entity.PreOutTime;
  9141. TimeSpan span = dt1.Subtract(dt2);
  9142. if (span.Days > 0)
  9143. {
  9144. entity.OutLate = span.Days;
  9145. }
  9146. }
  9147. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9148. entity.Create();
  9149. returnSuccessMsg("添加成功!");
  9150. return;
  9151. }
  9152. else //修改
  9153. {
  9154. entity = CeErpPlaceRegister.Get(eid);
  9155. if (entity != null)
  9156. {
  9157. string xdTime = GetPostString("placeTime");
  9158. if (xdTime.Length > 0)
  9159. {
  9160. entity.PlactTime = Convert.ToDateTime(xdTime);
  9161. }
  9162. string fhTime = GetPostString("deliveryTime");
  9163. if (fhTime.Length > 0)
  9164. {
  9165. entity.DeliveryTime = Convert.ToDateTime(fhTime);
  9166. }
  9167. string preTime = GetPostString("preOutTime");
  9168. if (preTime.Length > 0)
  9169. {
  9170. entity.PreOutTime = Convert.ToDateTime(preTime);
  9171. }
  9172. entity.DeliveryCount = GetPostInt("deliveryCount");
  9173. entity.ReceiveCount = GetPostInt("receiveCount");
  9174. if (entity.DeliveryCount == entity.ReceiveCount)
  9175. {
  9176. entity.CurState = "已完成";
  9177. }
  9178. else
  9179. {
  9180. entity.CurState = "未完成";
  9181. }
  9182. entity.OutSid = GetPostString("outSid");
  9183. entity.FileName = GetPostString("fileName");
  9184. entity.Memo = GetPostString("memo");
  9185. entity.Img = GetPostString("img");
  9186. entity.Supplier = GetPostInt("supplier");
  9187. //entity.Did = DateTime.Now.ToString("yyyyMMddHHmmss");
  9188. if (entity.PreOutTime != null && entity.DeliveryTime != null)
  9189. {
  9190. DateTime dt1 = (DateTime)entity.DeliveryTime;
  9191. DateTime dt2 = (DateTime)entity.PreOutTime;
  9192. TimeSpan span = dt1.Subtract(dt2);
  9193. if (span.Days > 0)
  9194. {
  9195. entity.OutLate = span.Days;
  9196. }
  9197. }
  9198. entity.Surplus = entity.DeliveryCount - entity.ReceiveCount;
  9199. entity.Update();
  9200. returnSuccessMsg("修改成功");
  9201. return;
  9202. }
  9203. returnErrorMsg("找不到对应的记录");
  9204. return;
  9205. }
  9206. }
  9207. returnErrorMsg("缺少必要参数");
  9208. }
  9209. public void del_erp_placeregist()
  9210. {
  9211. string eid = GetPostString("id");
  9212. CeErpPlaceRegister.Del(eid);
  9213. returnSuccessMsg("删除成功!");
  9214. return;
  9215. }
  9216. public void ins_erp_placeregistbyorder()
  9217. {
  9218. string ctid = GetPostString("ctid");
  9219. if (ctid.Length > 0)
  9220. {
  9221. StringBuilder sql = new StringBuilder();
  9222. sql.AppendFormat("select * from view_erptradecell where (ctid='{0}' or tid='{0}') and isAfterSaleOrder=0;", ctid);
  9223. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9224. if (dt.Rows.Count > 0)
  9225. {
  9226. foreach (DataRow dr in dt.Rows)
  9227. {
  9228. CeErpPlaceRegister entity = new CeErpPlaceRegister();
  9229. entity.PlactTime = Convert.ToDateTime(dr["pay_time"]);
  9230. entity.AddUserId = CurrentUser.UserID;
  9231. entity.tid = dr["tid"].ToString();
  9232. entity.Did = Convert.ToString(dr["ctid"]);
  9233. entity.splitTag = dr["SplitTag"].ToString();
  9234. string sellmemo = Convert.ToString(dr["seller_memo"]);
  9235. string pre_ctid = commonHelper.MidStrEx(sellmemo, "[", "]"); //C1
  9236. if (pre_ctid.Length > 0)
  9237. {
  9238. sellmemo = sellmemo.Replace(pre_ctid, "");
  9239. }
  9240. sellmemo = sellmemo.Replace("[", "");
  9241. sellmemo = sellmemo.Replace("]", "");
  9242. entity.FileName = sellmemo;
  9243. string count = dr["ProductCount"].ToString();
  9244. int usecount = commonHelper.getIntCountFromString(count);
  9245. entity.DeliveryCount = usecount;
  9246. entity.CurState = "未完成";
  9247. if (Convert.ToInt32(dr["SupplierId"]) == 0)
  9248. {
  9249. entity.Supplier = 24;//dl手提袋定制
  9250. }
  9251. else
  9252. entity.Supplier = Convert.ToInt32(dr["SupplierId"]);
  9253. entity.CreateTime = DateTime.Now;
  9254. entity.Create();
  9255. }
  9256. returnSuccessMsg("操作成功");
  9257. return;
  9258. }
  9259. returnErrorMsg("没有找到对应订单");
  9260. return;
  9261. }
  9262. returnErrorMsg("缺少订单编号");
  9263. return;
  9264. }
  9265. public void get_erp_persuadelist()
  9266. {
  9267. DataStruct dStruct = GetPostStruct();
  9268. List<string> lw = new List<string>();
  9269. string ctid = GetPostString("ctid");
  9270. if (ctid.Length > 0) lw.Add(string.Format("(ctid like '%{0}%' or orderSn like '%{0}%')", ctid));
  9271. string shopname = GetPostString("shopname");
  9272. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9273. string buyernick = GetPostString("buyer_nick");
  9274. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9275. string customer = GetPostString("customer");
  9276. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  9277. string returndate1 = GetPostString("returndate1");
  9278. string returndate2 = GetPostString("returndate2");
  9279. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  9280. if (dw.Length > 0) lw.Add(dw);
  9281. string finishDate1 = GetPostString("finishdate1");
  9282. string finishDate2 = GetPostString("finishdate2");
  9283. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  9284. if (dw_finish.Length > 0) lw.Add(dw_finish);
  9285. string persuadetype = GetPostString("persuadetype");
  9286. if (persuadetype.Length > 0) lw.Add(string.Format("wechatTag={0}", Convert.ToInt32(persuadetype)));
  9287. string returnvstate = GetPostString("returnvstate");
  9288. if (returnvstate.Length > 0) lw.Add(string.Format("pstate = {0}", Convert.ToInt32(returnvstate)));
  9289. dStruct.Order = "created desc";
  9290. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9291. DataTable dt = WebCache.GetData("view_Erppersuade", dStruct);
  9292. writeGridDataTableJson(dStruct.TotalCount, dt);
  9293. }
  9294. public void upd_erp_returnpersuadeback()
  9295. {
  9296. if (UrlPostParmsCheck("ID"))
  9297. {
  9298. int eid = GetPostInt("ID");
  9299. CeErpPersuade entity = null;
  9300. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9301. if (entity != null)
  9302. {
  9303. entity.backreason = GetPostString("reason");
  9304. entity.pstate = 2;
  9305. entity.verifytime = DateTime.Now;
  9306. entity.verifyuserid = CurrentUser.UserID;
  9307. entity.Update();
  9308. returnSuccessMsg("退回成功!");
  9309. return;
  9310. }
  9311. returnErrorMsg("找不到订单记录");
  9312. }
  9313. }
  9314. public void upd_erp_returnpersuadeverify()
  9315. {
  9316. if (UrlPostParmsCheck("ID"))
  9317. {
  9318. if (CurrentUser.UserPost.Post.Code != "Summarize")
  9319. {
  9320. returnErrorMsg("暂无权限审核");
  9321. return;
  9322. }
  9323. int eid = GetPostInt("ID");
  9324. CeErpPersuade entity = null;
  9325. if (eid != 0) entity = CeErpPersuade.Get(eid);
  9326. if (entity != null)
  9327. {
  9328. entity.pstate = 1;
  9329. entity.verifytime = DateTime.Now;
  9330. entity.verifyuserid = CurrentUser.UserID;
  9331. entity.Update();
  9332. returnSuccessMsg("审核成功!");
  9333. return;
  9334. }
  9335. returnErrorMsg("找不到订单记录");
  9336. }
  9337. }
  9338. public void del_erp_persuade()
  9339. {
  9340. if (UrlPostParmsCheck("ID"))
  9341. {
  9342. int eid = GetPostInt("ID");
  9343. CeErpPersuade.Del(eid);
  9344. returnSuccessMsg("操作成功");
  9345. return;
  9346. }
  9347. }
  9348. public void get_erp_oldcustoupload()
  9349. {
  9350. DataStruct dStruct = GetPostStruct();
  9351. List<string> lw = new List<string>();
  9352. string buyernick = GetPostString("buyer_nick");
  9353. if (buyernick.Length > 0)
  9354. {
  9355. lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  9356. }
  9357. else
  9358. return;
  9359. dStruct.Order = "pay_time desc";
  9360. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9361. DataTable dt = null;
  9362. dt = WebCache.GetData("view_erptradecell", dStruct);
  9363. writeGridDataTableJson(dStruct.TotalCount, dt);
  9364. }
  9365. public void get_erp_checkorderlist()
  9366. {
  9367. DataStruct dStruct = GetPostStruct();
  9368. List<string> lw = new List<string>();
  9369. string tid = GetPostString("ctid");
  9370. if (tid.Length > 0)
  9371. {
  9372. string select_tid = getTidByCtid(tid);
  9373. lw.Add(string.Format("tid='{0}'", select_tid));
  9374. }
  9375. string shopname = GetPostString("shopname");
  9376. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  9377. string buyernick = GetPostString("buyer_nick");
  9378. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  9379. string customer = GetPostString("customer");
  9380. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  9381. string design = GetPostString("design");
  9382. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  9383. string orderState = GetPostString("orderState");
  9384. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  9385. string address = GetPostString("address");
  9386. if (address.Length > 0) lw.Add(string.Format("address like '%{0}%'", address));
  9387. string sellermemo = GetPostString("seller_memo");
  9388. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  9389. string supplier = GetPostString("supplier");
  9390. if (CurrentUser.UserPost.Post.Code == "Supplier")
  9391. {
  9392. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  9393. }
  9394. else
  9395. {
  9396. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  9397. }
  9398. string date1 = GetPostString("date1");
  9399. string date2 = GetPostString("date2");
  9400. string dw = GetDateMinuteWhere("pay_time", date1, date2);
  9401. if (dw.Length > 0) lw.Add(dw);
  9402. string placedate1 = GetPostString("placedate1");
  9403. string placedate2 = GetPostString("placedate2");
  9404. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  9405. if (fdw.Length > 0) lw.Add(fdw);
  9406. string price1 = GetPostString("price1");
  9407. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  9408. string price2 = GetPostString("price2");
  9409. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  9410. string checkst = GetPostString("checkstate");
  9411. if (checkst.Length > 0 && "10".Equals(checkst))
  9412. {
  9413. lw.Add(string.Format("CheckOut>0"));
  9414. }
  9415. else
  9416. {
  9417. if (checkst.Length > 0) lw.Add(string.Format("MemoOpt={0}", checkst));
  9418. lw.Add(string.Format("(MemoOpt=3 or MemoOpt=4)"));
  9419. }
  9420. dStruct.Order = "MemoOpt, CheckOrderTime desc, pay_time desc";
  9421. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9422. DataTable dt = WebCache.GetData("view_ErpCheckOrder", dStruct);
  9423. writeGridDataTableJson(dStruct.TotalCount, dt);
  9424. }
  9425. public void ins_erp_startCheck()
  9426. {
  9427. if (UrlPostParmsCheck("ctid"))
  9428. {
  9429. string eid = GetPostString("ctid");
  9430. CeErpTradeCell entity = null;
  9431. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9432. if (entity != null)
  9433. {
  9434. entity.MemoOpt = 4;
  9435. entity.UpdateTime = DateTime.Now;
  9436. entity.Update();
  9437. LogHelper.addLog(eid, CurrentUser.UserID, "开始查货", 4, 0);
  9438. CeErpSukuraData.createInfo(entity.ctid, 6);
  9439. returnSuccessMsg("操作成功!");
  9440. return;
  9441. }
  9442. returnErrorMsg("找不到记录");
  9443. }
  9444. }
  9445. public void upd_erp_sendXlw()
  9446. {
  9447. if (UrlPostParmsCheck("ctid"))
  9448. {
  9449. string eid = GetPostString("ctid");
  9450. CeErpTradeCell entity = null;
  9451. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9452. if (entity != null)
  9453. {
  9454. if (entity.IsSendGift == 1)
  9455. {
  9456. returnErrorMsg("请勿重复标记");
  9457. return;
  9458. }
  9459. entity.IsSendGift = 1;
  9460. entity.Update();
  9461. LogHelper.addLog(eid, CurrentUser.UserID, "送小礼物");
  9462. returnSuccessMsg("操作成功!");
  9463. return;
  9464. }
  9465. returnErrorMsg("找不到记录");
  9466. }
  9467. }
  9468. public void cancel_sendXlw()
  9469. {
  9470. if (UrlPostParmsCheck("ctid"))
  9471. {
  9472. string eid = GetPostString("ctid");
  9473. CeErpTradeCell entity = null;
  9474. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9475. if (entity != null)
  9476. {
  9477. if (entity.IsSendGift == 0)
  9478. {
  9479. returnErrorMsg("未标记小礼物");
  9480. return;
  9481. }
  9482. entity.IsSendGift = 0;
  9483. entity.Update();
  9484. LogHelper.addLog(eid, CurrentUser.UserID, "取消小礼物标记");
  9485. returnSuccessMsg("操作成功!");
  9486. return;
  9487. }
  9488. returnErrorMsg("找不到记录");
  9489. }
  9490. }
  9491. public void get_erp_designbill()
  9492. {
  9493. DataStruct dStruct = GetPostStruct();
  9494. List<string> lw = new List<string>();
  9495. int isMy = GetInt("my");
  9496. if (isMy == 1)
  9497. {
  9498. lw.Add(string.Format("uid = '{0}'", CurrentUser.UserID));
  9499. }
  9500. string tid = GetPostString("tid");
  9501. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  9502. string userName = GetPostString("design");
  9503. if (userName.Length > 0) lw.Add(string.Format("userName like '%{0}%'", userName));
  9504. string price1 = GetPostString("price1");
  9505. if (price1.Length > 0) lw.Add(string.Format("price >= '{0}'", price1));
  9506. string price2 = GetPostString("price2");
  9507. if (price2.Length > 0) lw.Add(string.Format("price <= '{0}'", price2));
  9508. string rePrice1 = GetPostString("rePrice1");
  9509. if (rePrice1.Length > 0) lw.Add(string.Format("rePrice >= '{0}'", rePrice1));
  9510. string rePrice2 = GetPostString("rePrice2");
  9511. if (rePrice2.Length > 0) lw.Add(string.Format("rePrice <= '{0}'", rePrice2));
  9512. string designerType = GetPostString("designerType");
  9513. if (designerType.Length > 0) lw.Add(string.Format("designerType = '{0}'", designerType));
  9514. string orderState = GetPostString("orderState");
  9515. if (orderState.Length > 0) lw.Add(string.Format("OrderState = {0}", Convert.ToInt32(orderState)));
  9516. string endTime1 = GetPostString("endTime1");
  9517. string endTime2 = GetPostString("endTime2");
  9518. string dw = GetDateMinuteWhere("end_time", endTime1, endTime2);
  9519. if (dw.Length > 0) lw.Add(dw);
  9520. string isDk = GetPostString("isDk");
  9521. if (isDk == "1")
  9522. {
  9523. lw.Add(string.Format("(designNum > {0} or modifyNum > {0} or (designNum = 1 and modifyNum = 1))", 1));
  9524. }
  9525. else if (isDk == "0")
  9526. {
  9527. lw.Add(string.Format("((designNum = {0} and modifyNum = {1}) or (modifyNum = {0} and designNum = {1}))", 1, 0));
  9528. }
  9529. dStruct.Order = "oid, create_time desc";
  9530. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  9531. DataTable dt = WebCache.GetData("view_erpdesignerbill", dStruct);
  9532. writeGridDataTableJson(dStruct.TotalCount, dt);
  9533. }
  9534. public void upd_erp_designerbill()
  9535. {
  9536. if (UrlPostParmsCheck("ID"))
  9537. {
  9538. string eid = GetPostString("ID");
  9539. CeErpDesignerBill entity = null;
  9540. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9541. if (entity != null)
  9542. {
  9543. if (GetPostDouble("designerpirce") > 0)
  9544. {
  9545. entity.realPrice = GetPostDouble("designerpirce");
  9546. entity.update_time = DateTime.Now;
  9547. entity.update_u_id = CurrentUser.UserID;
  9548. entity.update_u_name = CurrentUser.UserName;
  9549. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改实际金额", CurrentUser.UserName, 1);
  9550. entity.Update();
  9551. returnSuccessMsg("操作成功!");
  9552. return;
  9553. }
  9554. else
  9555. {
  9556. entity.price = GetPostDouble("price");
  9557. entity.update_time = DateTime.Now;
  9558. entity.update_u_id = CurrentUser.UserID;
  9559. entity.update_u_name = CurrentUser.UserName;
  9560. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "修改预估金额", CurrentUser.UserName, 1);
  9561. entity.Update();
  9562. returnSuccessMsg("操作成功!");
  9563. return;
  9564. }
  9565. }
  9566. returnErrorMsg("找不到记录");
  9567. }
  9568. }
  9569. public void audit_erp_designerbill()
  9570. {
  9571. if (UrlPostParmsCheck("ID"))
  9572. {
  9573. string eid = GetPostString("ID");
  9574. CeErpDesignerBill entity = null;
  9575. if (eid != "") entity = CeErpDesignerBill.Get(eid);
  9576. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(eid);
  9577. if (entity != null)
  9578. {
  9579. entity.realPrice = GetPostDouble("designerpirce");
  9580. entity.update_time = DateTime.Now;
  9581. entity.update_u_id = CurrentUser.UserID;
  9582. entity.update_u_name = CurrentUser.UserName;
  9583. entity.isAudit = 1;
  9584. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9585. entity.Update();
  9586. if (orderEntity != null)
  9587. {
  9588. orderEntity.IsReadTag = 3;
  9589. orderEntity.Update();
  9590. }
  9591. returnSuccessMsg("操作成功!");
  9592. return;
  9593. }
  9594. returnErrorMsg("找不到记录");
  9595. }
  9596. }
  9597. public void all_audit_erp_designerbill()
  9598. {
  9599. if (UrlPostParmsCheck("idList"))
  9600. {
  9601. string[] list = GetPostString("idList").Split(',');
  9602. CeErpDesignerBill entity = null;
  9603. for (int i = 0; i < list.Length; i++)
  9604. {
  9605. if (list[i] != "") entity = CeErpDesignerBill.Get(list[i]);
  9606. if (entity == null) return;
  9607. CeErpTradeCell orderEntity = CeErpTradeCell.GetByCtid(entity.tid);
  9608. if (orderEntity == null) return;
  9609. if (entity.realPrice == 0) entity.realPrice = entity.price;
  9610. entity.update_time = DateTime.Now;
  9611. entity.update_u_id = CurrentUser.UserID;
  9612. entity.update_u_name = CurrentUser.UserName;
  9613. entity.isAudit = 1;
  9614. LogHelper.addDesignerBillLog(entity.tid, CurrentUser.UserID, "审批设计费", CurrentUser.UserName, 1);
  9615. entity.Update();
  9616. orderEntity.IsReadTag = 3;
  9617. orderEntity.Update();
  9618. }
  9619. returnSuccessMsg("操作成功!");
  9620. return;
  9621. }
  9622. }
  9623. public void get_erp_sameorders()
  9624. {
  9625. if (UrlPostParmsCheck("ctid"))
  9626. {
  9627. string eid = GetPostString("ctid");
  9628. CeErpTradeCell entity = null;
  9629. entity = CeErpTradeCell.GetByCtid(eid);
  9630. if (entity != null)
  9631. {
  9632. StringBuilder sql = new StringBuilder();
  9633. sql.AppendFormat("select * from ce_erptradecell where SupplierId={0} and orderstate=6 and tid='{1}';", entity.SupplierId, entity.tid);
  9634. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9635. var res = new
  9636. {
  9637. data = dt.Rows.Count
  9638. };
  9639. string ro_jsond = JsonConvert.SerializeObject(res);
  9640. returnSuccess(ro_jsond);
  9641. return;
  9642. }
  9643. returnErrorMsg("未找到订单");
  9644. return;
  9645. }
  9646. returnErrorMsg("缺少必要的参数");
  9647. }
  9648. public void get_erp_islasthavesameorder()
  9649. {
  9650. if (UrlPostParmsCheck("ctid"))
  9651. {
  9652. string eid = GetPostString("ctid");
  9653. string[] ctidList = eid.Split(',');
  9654. StringBuilder sql = new StringBuilder();
  9655. string tisCtid = "";
  9656. foreach (string ctid in ctidList)
  9657. {
  9658. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
  9659. if (entity != null)
  9660. {
  9661. sql = new StringBuilder();
  9662. sql.AppendFormat("select * from ce_erptradecell where orderstate=6 and tid='{0}' and SupplierId!={1};", entity.tid, entity.SupplierId);
  9663. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9664. if (dth.Rows.Count > 0)
  9665. {
  9666. tisCtid += entity.ctid;
  9667. tisCtid += ",";
  9668. }
  9669. }
  9670. }
  9671. if (tisCtid.Length > 0)
  9672. {
  9673. var res = new
  9674. {
  9675. data = tisCtid
  9676. };
  9677. string ro_jsond = JsonConvert.SerializeObject(res);
  9678. returnSuccess(ro_jsond);
  9679. }
  9680. else
  9681. {
  9682. var res = new
  9683. {
  9684. data = ""
  9685. };
  9686. string ro_jsond = JsonConvert.SerializeObject(res);
  9687. returnSuccess(ro_jsond);
  9688. }
  9689. return;
  9690. }
  9691. returnErrorMsg("缺少必要的参数");
  9692. }
  9693. public void file_client_down_url()
  9694. {
  9695. if (!UrlPostParmsCheck("userId"))
  9696. {
  9697. returnErrorMsg("缺少必要的参数");
  9698. }
  9699. returnSuccess("\"" + webConfig.ltDownLoadUrl + "\"");
  9700. }
  9701. public void checkout_form_data()
  9702. {
  9703. if (!UrlPostParmsCheck("tid"))
  9704. {
  9705. returnErrorMsg("缺少必要的参数");
  9706. }
  9707. string tid = GetPostString("tid");
  9708. CeErpOrderFormData ceErpOrderFormData = CeErpOrderFormData.GetByTid(tid);
  9709. if (ceErpOrderFormData != null)
  9710. {
  9711. string ro_jsond = JsonConvert.SerializeObject(ceErpOrderFormData);
  9712. returnSuccess(ro_jsond);
  9713. return;
  9714. }
  9715. returnErrorMsg("尚未有文件!");
  9716. }
  9717. public void back_supplier_audit()
  9718. {
  9719. int userId = CurrentUser.UserID;
  9720. StringBuilder sql = new StringBuilder();
  9721. 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);
  9722. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9723. if (dt.Rows.Count > 0)
  9724. {
  9725. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9726. }
  9727. else
  9728. {
  9729. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9730. }
  9731. }
  9732. public void back_supplier_query()
  9733. {
  9734. string eid = GetPostString("ctid");
  9735. if (eid != "")
  9736. {
  9737. StringBuilder sql = new StringBuilder();
  9738. sql.AppendFormat("select * from CE_ErpTradeCell WHERE ctid= '{0}';", eid);
  9739. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9740. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9741. }
  9742. else
  9743. {
  9744. returnErrorMsg("找不到订单记录");
  9745. return;
  9746. }
  9747. }
  9748. public void verified_to_order()
  9749. {
  9750. int userId = CurrentUser.UserID;
  9751. StringBuilder sql = new StringBuilder();
  9752. sql.AppendFormat("SELECT tid FROM CE_Withdraw WHERE userid ='{0}' and status = -1;", userId);
  9753. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9754. if (dt.Rows.Count > 0)
  9755. {
  9756. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9757. }
  9758. else
  9759. {
  9760. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  9761. }
  9762. }
  9763. public void upd_supplier_audit()
  9764. {
  9765. if (UrlPostParmsCheck("ctid"))
  9766. {
  9767. string eid = GetPostString("ctid");
  9768. string reason = GetPostString("returnreason");
  9769. CeErpTradeCell entity = null;
  9770. CeWithdraw withdraw = null;
  9771. withdraw = CeWithdraw.GetByTid(eid);
  9772. if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
  9773. if (!string.IsNullOrEmpty(eid) && eid[0] == 'N')
  9774. {
  9775. if (withdraw != null)
  9776. {
  9777. if (!withdraw.userid.Equals(CurrentUser.UserID))
  9778. {
  9779. returnSuccessMsg("您没有权限操作!");
  9780. return;
  9781. }
  9782. else
  9783. {
  9784. if (reason.Equals("1"))
  9785. {
  9786. if (entity.OrderState == -1)
  9787. {
  9788. if (entity.FinishPlaceTime == null)
  9789. {
  9790. entity.OrderState = 2;
  9791. }
  9792. else
  9793. {
  9794. entity.OrderState = 6;
  9795. }
  9796. }
  9797. entity.Update();
  9798. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9799. if (withdraw != null)
  9800. {
  9801. withdraw.status = int.Parse(reason);
  9802. withdraw.Update();
  9803. }
  9804. returnSuccessMsg("操作成功!");
  9805. return;
  9806. }
  9807. else
  9808. {
  9809. withdraw.status = int.Parse(reason);
  9810. withdraw.acknowledgingtime = DateTime.Now;
  9811. withdraw.Update();
  9812. returnSuccessMsg("查看详细请点击线下订单查询");
  9813. return;
  9814. }
  9815. }
  9816. }
  9817. // 第一个字符是 'N'
  9818. }
  9819. if (eid[0] != 'N')
  9820. {
  9821. }
  9822. if (entity != null && int.Parse(reason) == 1 && entity.OrderState > 4)
  9823. {
  9824. entity.IsVerifyToSupplier = false;
  9825. entity.IsReturn = 1;
  9826. entity.ReturnTime = DateTime.Now;
  9827. entity.ReturnReason = reason;
  9828. if (entity.OrderState == 6)
  9829. {
  9830. entity.OrderState = 5;
  9831. }
  9832. entity.Update();
  9833. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "供应商退回下单:" + reason, entity.OrderState);
  9834. if (withdraw != null)
  9835. {
  9836. withdraw.status = int.Parse(reason);
  9837. withdraw.Update();
  9838. }
  9839. returnSuccessMsg("操作成功!");
  9840. return;
  9841. }
  9842. else if (int.Parse(reason) == 2 && entity.OrderState > 2)
  9843. {
  9844. ;
  9845. if (withdraw != null)
  9846. {
  9847. withdraw.status = int.Parse(reason);
  9848. withdraw.acknowledgingtime = DateTime.Now;
  9849. withdraw.Update();
  9850. returnSuccessMsg("供应商取消撤回!");
  9851. return;
  9852. }
  9853. }
  9854. else if (entity != null && int.Parse(reason) == 1 && entity.OrderState < 0)
  9855. {
  9856. if (entity.OrderState == -1)
  9857. {
  9858. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  9859. if (string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id) && !entity.ctid.Contains("N_") && !entity.ctid.Contains("S_"))
  9860. {
  9861. returnErrorMsg("订单spu没有确认无法通过审核!");
  9862. return;
  9863. }
  9864. if (entity.FinishPlaceTime == null)
  9865. {
  9866. entity.OrderState = 2;
  9867. }
  9868. else
  9869. {
  9870. entity.OrderState = 3;
  9871. }
  9872. commonHelper.getCytPrice(entity);
  9873. }
  9874. entity.Update();
  9875. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "审核通过", entity.OrderState);
  9876. if (withdraw != null)
  9877. {
  9878. withdraw.status = int.Parse(reason);
  9879. withdraw.Update();
  9880. }
  9881. returnSuccessMsg("操作成功!");
  9882. return;
  9883. }
  9884. else if (int.Parse(reason) == 2 && entity.OrderState < 0)
  9885. {
  9886. if (withdraw == null)
  9887. {
  9888. returnSuccessMsg("驳回操作成功!可重新发起审核!");
  9889. return;
  9890. }
  9891. }
  9892. else if (int.Parse(reason) == 4 && entity.OrderState < 0)
  9893. {
  9894. if (withdraw != null)
  9895. {
  9896. withdraw.status = int.Parse(reason);
  9897. withdraw.acknowledgingtime = DateTime.Now;
  9898. withdraw.Update();
  9899. returnSuccessMsg("查看详细请点击线下订单查询");
  9900. return;
  9901. }
  9902. }
  9903. return;
  9904. }
  9905. }
  9906. //校验报价
  9907. public void refund_order_tip()
  9908. {
  9909. int userid = CurrentUser.UserID;
  9910. int sectionId = CurrentUser.UserPost.OrgID;
  9911. StringBuilder sql = new StringBuilder();
  9912. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' or sectionId = '{1}') and isVisit = 0 and type = 1;", userid, sectionId);
  9913. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9914. List<string> ids = new List<string>();
  9915. if (dth.Rows.Count > 0)
  9916. {
  9917. foreach (DataRow dr in dth.Rows)
  9918. {
  9919. ids.Add(dr["ID"].ToString());
  9920. }
  9921. try
  9922. {
  9923. /*string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '"+ userid + "'";
  9924. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());*/
  9925. }
  9926. catch (Exception ex)
  9927. {
  9928. }
  9929. }
  9930. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9931. }
  9932. public void refund_order_Design()
  9933. {
  9934. int userid = CurrentUser.UserID;
  9935. int sectionId = CurrentUser.UserPost.OrgID;
  9936. StringBuilder sql = new StringBuilder();
  9937. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}' ) and isVisit = 0 and type = 1;", userid);
  9938. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9939. List<string> ids = new List<string>();
  9940. if (dth.Rows.Count > 0)
  9941. {
  9942. foreach (DataRow dr in dth.Rows)
  9943. {
  9944. ids.Add(dr["ID"].ToString());
  9945. }
  9946. try
  9947. {
  9948. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where ID in ('" + string.Join(",", ids) + "');";
  9949. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  9950. }
  9951. catch (Exception ex)
  9952. {
  9953. }
  9954. }
  9955. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));
  9956. }
  9957. public void change_order_info()
  9958. {
  9959. int userid = CurrentUser.UserID;
  9960. StringBuilder sql = new StringBuilder();
  9961. 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);
  9962. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  9963. returnSuccess(JsonString.DataTable2MiniAjaxJson(dth));
  9964. }
  9965. public void change_win_mome()
  9966. {
  9967. if (UrlPostParmsCheck("id,ctid"))
  9968. {
  9969. string id = GetPostString("id");
  9970. string ctid = GetPostString("ctid");
  9971. CeErpMessageTip ceErpMessageTip = CeErpMessageTip.Get(id);
  9972. CeErpTradeCell ce = CeErpTradeCell.GetByCtid(ctid);
  9973. if (ce == null || ceErpMessageTip == null)
  9974. {
  9975. returnSuccessMsg("未找到对应的订单!");
  9976. return;
  9977. }
  9978. if (ce.OrderState >= 5)
  9979. {
  9980. returnSuccessMsg("已上传文件无法修改!");
  9981. return;
  9982. }
  9983. int type = GetPostInt("type");
  9984. string content = GetPostString("content");
  9985. if (type == 0)
  9986. {
  9987. content = content.Replace("(", "(");
  9988. content = content.Replace(")", ")");
  9989. string check = MidStrEx(content, "(", ")").Trim();
  9990. if (string.IsNullOrEmpty(check))
  9991. {
  9992. returnSuccessMsg("文件名格式不正确");
  9993. return;
  9994. }
  9995. }
  9996. ce.seller_memo = content;
  9997. ce.Update();
  9998. ceErpMessageTip.isVisit = true;
  9999. ceErpMessageTip.Update();
  10000. string text = type == 0 ? "同意修改:" + content : "不同意修改";
  10001. LogHelper.addLog(ce.ctid, CurrentUser.UserID, text, ce.OrderState, 1);
  10002. ApiVo apiVo = new ApiVo();
  10003. apiVo.orderNumber = ce.ctid;
  10004. apiVo.actionName = "demandDesign";
  10005. apiVo.orderRemarks = content;
  10006. apiVo.demandExamine = type + 1;
  10007. designHelper.API_WorkCore(apiVo);//demandDesign
  10008. returnSuccessMsg("修改成功!");
  10009. }
  10010. }
  10011. public static string MidStrEx(string sourse, string startstr, string endstr)
  10012. {
  10013. string result = string.Empty;
  10014. int startindex, endindex;
  10015. try
  10016. {
  10017. startindex = sourse.IndexOf(startstr);
  10018. if (startindex == -1)
  10019. return result;
  10020. string tmpstr = sourse.Substring(startindex + startstr.Length);
  10021. endindex = tmpstr.IndexOf(endstr);
  10022. if (endindex == -1)
  10023. return result;
  10024. result = tmpstr.Remove(endindex);
  10025. }
  10026. catch (Exception ex)
  10027. {
  10028. Console.WriteLine("MidStrEx Err:" + ex.Message);
  10029. }
  10030. return result;
  10031. }
  10032. public void refund_order_list()
  10033. {
  10034. int userid = CurrentUser.UserID;
  10035. int sectionId = CurrentUser.UserPost.OrgID;
  10036. StringBuilder sql = new StringBuilder();
  10037. sql.AppendFormat("select * from CE_ErpMessageTip where (userId = '{0}') and isVisit = 0;", userid, sectionId);
  10038. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10039. DataStruct dStruct = GetPostStruct();
  10040. DataTable dt = null;
  10041. List<string> ids = new List<string>();
  10042. List<string> tids = new List<string>();
  10043. if (dth.Rows.Count > 0)
  10044. {
  10045. foreach (DataRow dr in dth.Rows)
  10046. {
  10047. tids.Add("'" + dr["tid"].ToString() + "'");
  10048. ids.Add(dr["id"].ToString());
  10049. }
  10050. try
  10051. {
  10052. string sql_pay = "update CE_ErpMessageTip set isVisit=1 where userId = '" + userid + "';";
  10053. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10054. List<string> lw = new List<string>();
  10055. lw.Add(string.Format("( tid in ({0}) )", string.Join(",", tids)));
  10056. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10057. dt = WebCache.GetData("view_orderlist", dStruct);
  10058. }
  10059. catch (Exception ex)
  10060. {
  10061. }
  10062. }
  10063. writeGridDataTableJson(dStruct.TotalCount, dt);
  10064. /*returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dth));*/
  10065. }
  10066. //新增
  10067. public void order_batch_downloads()
  10068. {
  10069. string ceid = GetPostString("tid");
  10070. String[] tid = ceid.Split(',');
  10071. order_batch_caiyingtong(tid);
  10072. /* (string success, string errors) = UploadFiles(tid);
  10073. returnSuccessMsg(success + errors);*/
  10074. return;
  10075. }
  10076. //报价接口
  10077. public void Get_To_Quote()
  10078. {
  10079. string ceid = GetPostString("ctid");
  10080. if (ceid != null)
  10081. {
  10082. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceid);
  10083. if (entity != null)
  10084. {
  10085. if (entity.seller_memo.IndexOf("种子纸") > -1)
  10086. {
  10087. return;
  10088. }
  10089. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10090. double price = 0;
  10091. if (cp == null)
  10092. {
  10093. JObject jsonObject12 = new JObject
  10094. {
  10095. { "UserId", "77886" },
  10096. { "Pwd", "lt666888" },
  10097. { "Filename", entity.seller_memo }
  10098. };
  10099. string response1 = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject12.ToString());
  10100. JObject jsonObjects1 = JObject.Parse(response1);
  10101. string ms1g = (string)jsonObjects1["msg"];
  10102. if (ms1g == "报价成功")
  10103. {
  10104. JObject jsonObject1 = (JObject)jsonObjects1["data"];
  10105. string data = (string)jsonObject1["price"];
  10106. 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 + "');";
  10107. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10108. returnSuccessMsg("获取报价成功:" + data);
  10109. price = Convert.ToDouble(data);
  10110. }
  10111. else
  10112. {
  10113. returnErrorMsg("获取报价失败,检查备注格式" + ms1g);
  10114. return;
  10115. }
  10116. }
  10117. String[] beizhu = entity.seller_memo.Split('-');
  10118. String chanp = "";
  10119. if (beizhu.Length > 0)
  10120. {
  10121. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft + "-备注:" + beizhu[1];
  10122. }
  10123. else
  10124. {
  10125. chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10126. }
  10127. JObject jsonObject = new JObject
  10128. {
  10129. { "UserId", "77886" },
  10130. { "Pwd", "lt666888" },
  10131. { "Filename", chanp }
  10132. };
  10133. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10134. JObject jsonObjects = JObject.Parse(response);
  10135. string msg = (string)jsonObjects["msg"];
  10136. if (msg == "报价成功")
  10137. {
  10138. JObject jsonObject1 = (JObject)jsonObjects["data"];
  10139. string data = (string)jsonObject1["price"];
  10140. 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 + "');";
  10141. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  10142. returnSuccessMsg("获取报价成功:" + data);
  10143. price = Convert.ToDouble(data);
  10144. }
  10145. else
  10146. {
  10147. returnErrorMsg("获取报价失败,检查备注格式" + msg);
  10148. return;
  10149. }
  10150. if (price > 0)
  10151. {
  10152. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
  10153. if (ceErpTradeCellExtend == null)
  10154. {
  10155. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10156. ceErpTradeCellExtend.ctid = entity.ctid;
  10157. ceErpTradeCellExtend.payment_cyt = price;
  10158. ceErpTradeCellExtend.Create();
  10159. }
  10160. else
  10161. {
  10162. ceErpTradeCellExtend.payment_cyt = price;
  10163. ceErpTradeCellExtend.Update();
  10164. }
  10165. }
  10166. return;
  10167. }
  10168. }
  10169. else
  10170. {
  10171. returnErrorMsg("请至少选择一条数据");
  10172. return;
  10173. }
  10174. }
  10175. //新增
  10176. public void order_To_Supplier()
  10177. {
  10178. string ceid = GetPostString("tid");
  10179. String[] tid = ceid.Split(',');
  10180. if (tid.Length > 0)
  10181. {
  10182. try
  10183. {
  10184. for (int i = 0; i < tid.Length; i++)
  10185. {
  10186. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid[i]);
  10187. int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
  10188. entity.SupplierId = suid;
  10189. string suname = commonHelper.getSupplierNameById(entity.SupplierId);
  10190. LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
  10191. entity.Update();
  10192. }
  10193. }
  10194. catch (Exception ex)
  10195. {
  10196. returnErrorMsg("自动匹配供应商失败");
  10197. return;
  10198. }
  10199. }
  10200. else
  10201. {
  10202. returnErrorMsg("请至少选择一条数据");
  10203. return;
  10204. }
  10205. returnSuccessMsg("自动匹配供应商成功");
  10206. return;
  10207. }
  10208. public (string, string) UploadFiles(string[] urls)
  10209. {
  10210. string success = "";
  10211. string errors = "";
  10212. int userid = CurrentUser.UserID;
  10213. foreach (string url in urls)
  10214. {
  10215. String url1 = "http://183.250.143.56:8088/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid;
  10216. (string fileName, string base64FileContent) = DownloadAndConvertToBase64(url1);
  10217. if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(base64FileContent))
  10218. {
  10219. JObject jsonObject = new JObject
  10220. {
  10221. { "Userid", "77886" },
  10222. { "pwd", "cyt86435015" },
  10223. { "content", base64FileContent },
  10224. { "ext", Path.GetExtension(fileName) }
  10225. };
  10226. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/NewUploadFiles", jsonObject.ToString());
  10227. JObject jsonObjects = JObject.Parse(response);
  10228. string msg = (string)jsonObjects["msg"];
  10229. if (msg.Equals("上传成功"))
  10230. {
  10231. success += url + " 上传成功";
  10232. }
  10233. else
  10234. {
  10235. errors += url + " 上传失败";
  10236. }
  10237. }
  10238. else
  10239. {
  10240. errors += url + " 格式出现问题";
  10241. }
  10242. }
  10243. if (urls.Length == 0)
  10244. {
  10245. return (success, errors);
  10246. }
  10247. return (success, errors);
  10248. }
  10249. private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
  10250. {
  10251. return true; //总是接受
  10252. }
  10253. public static string HttpPost(string url, string param = null)
  10254. {
  10255. HttpWebRequest request;
  10256. //如果是发送HTTPS请求
  10257. if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
  10258. {
  10259. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
  10260. request = WebRequest.Create(url) as HttpWebRequest;
  10261. request.ProtocolVersion = HttpVersion.Version10;
  10262. }
  10263. else
  10264. {
  10265. request = WebRequest.Create(url) as HttpWebRequest;
  10266. }
  10267. request.Method = "POST";
  10268. request.ContentType = "application/json";
  10269. request.Accept = "*/*";
  10270. request.Timeout = 120000;
  10271. request.AllowAutoRedirect = false;
  10272. StreamWriter requestStream = null;
  10273. WebResponse response = null;
  10274. string responseStr = null;
  10275. try
  10276. {
  10277. requestStream = new StreamWriter(request.GetRequestStream());
  10278. requestStream.Write(param);
  10279. requestStream.Close();
  10280. response = request.GetResponse();
  10281. if (response != null)
  10282. {
  10283. StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
  10284. responseStr = reader.ReadToEnd();
  10285. reader.Close();
  10286. }
  10287. }
  10288. catch (Exception ex)
  10289. {
  10290. return ex.Message;
  10291. }
  10292. finally
  10293. {
  10294. request = null;
  10295. requestStream = null;
  10296. response = null;
  10297. }
  10298. return responseStr;
  10299. }
  10300. public (string, string) DownloadAndConvertToBase64(string downloadUrl)
  10301. {
  10302. string base64FileContent;
  10303. string fileName;
  10304. using (WebClient webClient = new WebClient())
  10305. {
  10306. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadUrl);
  10307. using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  10308. {
  10309. using (Stream stream = response.GetResponseStream())
  10310. {
  10311. using (MemoryStream memoryStream = new MemoryStream())
  10312. {
  10313. stream.CopyTo(memoryStream);
  10314. byte[] fileBytes = memoryStream.ToArray();
  10315. base64FileContent = Convert.ToBase64String(fileBytes);
  10316. fileName = response.Headers["Content-Disposition"];
  10317. if (!string.IsNullOrEmpty(fileName))
  10318. {
  10319. int index = fileName.IndexOf("filename=", StringComparison.OrdinalIgnoreCase);
  10320. if (index >= 0)
  10321. {
  10322. fileName = fileName.Substring(index + 9).Trim('\"');
  10323. }
  10324. }
  10325. else
  10326. {
  10327. fileName = Path.GetFileName(downloadUrl);
  10328. }
  10329. }
  10330. }
  10331. }
  10332. }
  10333. return (fileName, base64FileContent);
  10334. }
  10335. //新增
  10336. public void order_batch_caiyingtong(string[] downloadUrls)
  10337. {
  10338. try
  10339. {
  10340. //遍历文件
  10341. DataStruct dStruct = GetPostStruct();
  10342. DataTable dt = null;
  10343. int userid = CurrentUser.UserID;
  10344. List<string> ids = new List<string>();//失败组
  10345. List<string> tids = new List<string>();
  10346. using (WebClient webClient = new WebClient())
  10347. {
  10348. foreach (var url in downloadUrls)
  10349. {
  10350. try
  10351. {
  10352. tids.Add("'" + url + "'");
  10353. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(url);
  10354. if (entity != null)
  10355. {
  10356. CeErpProduct cp = CeErpProduct.GetById(entity.ProductId);
  10357. if (cp == null)
  10358. {
  10359. JObject jsonObject = new JObject
  10360. {
  10361. { "Userid", "77886" },
  10362. { "pwd", "lt666888" },
  10363. { "Filename",entity.seller_memo }
  10364. };
  10365. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10366. JObject jsonObjects = JObject.Parse(response);
  10367. string msg = (string)jsonObjects["msg"];
  10368. if (msg == "报价成功")
  10369. {
  10370. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10371. DownloadAndConvertToBase64(url1);
  10372. }
  10373. else
  10374. {
  10375. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10376. }
  10377. }
  10378. else
  10379. {
  10380. String chanp = "(" + entity.ctid + ")-" + entity.ProductSize + "-" + entity.ProductCount + "-" + entity.Material + cp.PSupType + entity.Craft;
  10381. JObject jsonObject = new JObject
  10382. {
  10383. { "Userid", "77886" },
  10384. { "pwd", "lt666888" },
  10385. { "Filename",chanp }
  10386. };
  10387. string response = HttpPost("http://www.kiy.cn/m-mobile/autobaojia/LTBaojia", jsonObject.ToString());
  10388. JObject jsonObjects = JObject.Parse(response);
  10389. string msg = (string)jsonObjects["msg"];
  10390. if (msg == "报价成功")
  10391. {
  10392. String url1 = "http://localhost:54673/download.aspx?hexdata=" + url + "&onlyfile=1&userid=" + userid + "&cyt=1";
  10393. DownloadAndConvertToBase64(url1);
  10394. }
  10395. else
  10396. {
  10397. LogHelper.addLog(entity.ctid, CurrentUser.UserID, "上传彩印通接口失败,原因:" + msg, entity.OrderState);
  10398. }
  10399. }
  10400. }
  10401. // 上传文件到FTP
  10402. }
  10403. catch (Exception ex)
  10404. {
  10405. Console.WriteLine($"An error occurred: {ex.Message}");
  10406. }
  10407. }
  10408. List<string> lw = new List<string>();
  10409. lw.Add(string.Format("( OrderState < 6 )"));
  10410. lw.Add(string.Format("( ctid in ({0}) )", string.Join(",", tids)));
  10411. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10412. dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  10413. if (dt.Rows.Count > 0)
  10414. {
  10415. foreach (DataRow dr in dt.Rows)
  10416. {
  10417. ids.Add(dr["ctid"].ToString());
  10418. }
  10419. }
  10420. String ErrorMsgs = "";
  10421. foreach (String id in ids)
  10422. {
  10423. ErrorMsgs += id + ",";
  10424. }
  10425. if (ErrorMsgs.Length > 1)
  10426. {
  10427. ErrorMsgs += "上传失败,请检查备注或者是否存在附件!";
  10428. }
  10429. if (ErrorMsgs.Length < 1)
  10430. {
  10431. ErrorMsgs = "上传成功";
  10432. returnSuccessMsg(ErrorMsgs);
  10433. }
  10434. else
  10435. {
  10436. returnErrorMsg("以下订单" + ErrorMsgs);
  10437. }
  10438. }
  10439. // 删除文件夹及其内容
  10440. /* Directory.Delete(localDirectory, true);*/
  10441. }
  10442. catch { }
  10443. }
  10444. public void get_center_data()
  10445. {
  10446. int userId = CurrentUser.UserID;
  10447. string postCode = CurrentUser.UserPost.Post.Code;
  10448. List<string> lw = new List<string>();
  10449. List<string> ww = new List<string>();
  10450. DateTime currentTime = DateTime.Now;
  10451. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10452. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10453. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10454. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10455. string sql = " SELECT ";
  10456. string startTime = "2023-10-01 11:22:31";
  10457. //设计
  10458. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10459. {
  10460. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10461. 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));
  10462. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10463. 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));
  10464. }
  10465. //客服
  10466. else if (postCode == "CustomerService" || postCode == "Director")
  10467. {
  10468. lw.Add(string.Format("COALESCE ( dc.designCount, 0 ) AS designCount"));
  10469. 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));
  10470. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10471. 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));
  10472. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10473. 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));
  10474. lw.Add(string.Format("COALESCE ( bc.backCount, 0 ) AS backCount"));
  10475. 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));
  10476. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10477. 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));
  10478. }
  10479. //售后
  10480. else if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10481. {
  10482. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10483. 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));
  10484. lw.Add(string.Format("COALESCE ( rc.refundCount, 0 ) AS refundCount "));
  10485. 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));
  10486. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10487. 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));
  10488. }
  10489. //下单部
  10490. else if (postCode == "Place" || postCode == "PlaceMr")
  10491. {
  10492. lw.Add(string.Format("COALESCE ( oc.orderCount, 0 ) AS orderCount"));
  10493. 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));
  10494. lw.Add(string.Format("COALESCE ( sc.sendCount, 0 ) AS sendCount"));
  10495. 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));
  10496. }
  10497. //车间
  10498. else if (postCode == "Supplier")
  10499. {
  10500. lw.Add(string.Format("COALESCE ( cc.checkCount, 0 ) AS checkCount "));
  10501. 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));
  10502. }
  10503. DataTable dt = new DataTable();
  10504. if (lw.Count > 0)
  10505. {
  10506. sql += string.Join(" , ", lw);
  10507. sql += " FROM ";
  10508. sql += string.Join(" , ", ww);
  10509. dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  10510. }
  10511. returnSuccess(Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  10512. }
  10513. public void get_center_data_list()
  10514. {
  10515. int userId = CurrentUser.UserID;
  10516. string postCode = CurrentUser.UserPost.Post.Code;
  10517. string shopIds = CurrentUser.User.pemShop;
  10518. DataStruct dStruct = GetPostStruct();
  10519. List<string> lw = new List<string>();
  10520. DateTime currentTime = DateTime.Now;
  10521. string payTime = currentTime.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
  10522. string finishDesignTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10523. string finishPlaceTime = currentTime.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
  10524. string checkOrderTime = currentTime.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss");
  10525. string startTime = "2023-10-01 11:22:31";
  10526. int order_type = GetPostInt("order_type");
  10527. if (postCode == "Designer" || postCode == "Designerhd" || postCode == "DesignerMr" || postCode == "wxDesigner" || postCode == "wxDesignerMr")
  10528. {
  10529. lw.Add(string.Format("pay_time > '{0}' and DesignUserId = {1}", startTime, userId));
  10530. if (order_type == 0)
  10531. {
  10532. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10533. }
  10534. else if (order_type == 3)
  10535. {
  10536. lw.Add(string.Format("OrderState = 4 AND ReturnTime IS NOT NULL"));
  10537. }
  10538. else
  10539. {
  10540. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10541. }
  10542. }
  10543. //客服
  10544. if (postCode == "CustomerService" || postCode == "Director")
  10545. {
  10546. lw.Add(string.Format("pay_time > '{0}' and CustomerUserId = {1}", startTime, userId));
  10547. if (order_type == 0)
  10548. {
  10549. lw.Add(string.Format("pay_time < '{0}' AND OrderState < 5 AND IsReturn = 0", payTime));
  10550. }
  10551. else if (order_type == 1)
  10552. {
  10553. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10554. }
  10555. else if (order_type == 2)
  10556. {
  10557. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10558. }
  10559. else if (order_type == 3)
  10560. {
  10561. lw.Add(string.Format("OrderState = 0 AND ReturnTime IS NOT NULL"));
  10562. }
  10563. else if (order_type == 4)
  10564. {
  10565. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10566. }
  10567. else
  10568. {
  10569. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10570. }
  10571. }
  10572. //售后
  10573. if (postCode == "AfterSale" || postCode == "AfterSaleMaster")
  10574. {
  10575. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10576. if (shopIds != "")
  10577. {
  10578. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10579. }
  10580. if (order_type == 2)
  10581. {
  10582. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10583. }
  10584. else if (order_type == 4)
  10585. {
  10586. lw.Add(string.Format("IsRefund > 0 AND OrderState NOT IN ( 8, 9 )"));
  10587. }
  10588. else if (order_type == 5)
  10589. {
  10590. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) ", checkOrderTime));
  10591. }
  10592. else
  10593. {
  10594. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10595. }
  10596. }
  10597. //下单部
  10598. if (postCode == "Place" || postCode == "PlaceMr")
  10599. {
  10600. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10601. if (shopIds != "")
  10602. {
  10603. lw.Add(string.Format("ShopId in ({0})", shopIds));
  10604. }
  10605. else if (order_type == 1)
  10606. {
  10607. lw.Add(string.Format("FinishDesignTime < '{0}' AND OrderState = 5 AND IsReturn = 0", finishDesignTime));
  10608. }
  10609. else if (order_type == 2)
  10610. {
  10611. lw.Add(string.Format("FinishPlaceTime < '{0}' AND OrderState = 6 AND IsReturn = 0", finishPlaceTime));
  10612. }
  10613. else
  10614. {
  10615. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10616. }
  10617. }
  10618. //车间
  10619. if (postCode == "Supplier")
  10620. {
  10621. lw.Add(string.Format("pay_time > '{0}' ", startTime));
  10622. if (order_type == 5)
  10623. {
  10624. lw.Add(string.Format("CheckOrderTime < '{0}' AND (CheckMemo IS NULL OR CheckMemo = '') AND (MemoOpt=3 or MemoOpt=4) AND SupplierId = {1}", checkOrderTime, userId));
  10625. }
  10626. else
  10627. {
  10628. writeGridDataTableJson(dStruct.TotalCount, new DataTable());
  10629. }
  10630. }
  10631. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10632. dStruct.Fileds = "tid,ctid";
  10633. DataTable dt = WebCache.GetData("CE_ErpTradeCell", dStruct);
  10634. writeGridDataTableJson(dStruct.TotalCount, dt);
  10635. }
  10636. public void aftersale_audit_master()
  10637. {
  10638. if (UrlPostParmsCheck("ctid"))
  10639. {
  10640. string ctid = GetPostString("ctid");
  10641. if (ctid.Length > 0)
  10642. {
  10643. bool result = aftersale_data_change(ctid);
  10644. if (result)
  10645. {
  10646. returnSuccessMsg("修改成功!");
  10647. return;
  10648. }
  10649. }
  10650. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10651. }
  10652. }
  10653. public void aftersale_batch_audit_master()
  10654. {
  10655. if (UrlPostParmsCheck("ctids"))
  10656. {
  10657. string ctids = GetPostString("ctids");
  10658. if (ctids.Length > 0)
  10659. {
  10660. List<string> list = new List<string>();
  10661. string[] ctid_list = ctids.Split(',');
  10662. foreach (var item in ctid_list)
  10663. {
  10664. bool result = aftersale_data_change(item);
  10665. if (!result)
  10666. {
  10667. list.Add(item);
  10668. }
  10669. }
  10670. if (list.Count > 0)
  10671. {
  10672. returnSuccessMsg(list.Count + "个订单修改失败!" + string.Join(",", list));
  10673. return;
  10674. }
  10675. returnSuccessMsg("修改成功!");
  10676. return;
  10677. }
  10678. returnErrorMsg("找不到指定售后单对应的原始订单!");
  10679. }
  10680. }
  10681. public bool aftersale_data_change(string ctid)
  10682. {
  10683. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10684. if (ceErpTradeCell != null)
  10685. {
  10686. ceErpTradeCell.AfterSaleSupplierMemo = "";//重置不认同
  10687. ceErpTradeCell.AfterSaleSupplierState = 0;
  10688. StringBuilder sql = new StringBuilder();
  10689. sql.AppendFormat("select type,UserId,ID,OrgPath,OrgID from view_ErpTradeResponsible where tid='{0}' and VerifyState > -1", ctid);
  10690. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  10691. CeErpTradeResponsible.DelByTid(ctid, 0);
  10692. 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 == "不理赔")
  10693. {
  10694. CeErpTradeResponsible.DelByTid(ctid, 1);
  10695. ceErpTradeCell.AfterSaleSupplierState = 1;
  10696. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10697. ceErpTradeCell.AfterSaleState = 4;
  10698. }
  10699. else
  10700. {
  10701. ceErpTradeCell.AfterSaleState = 3;
  10702. }
  10703. bool needCyt = false;
  10704. if (dt != null)
  10705. {
  10706. if (dt.Rows.Count == 1)
  10707. {
  10708. bool isEnd = false;
  10709. foreach (DataRow dr in dt.Rows)
  10710. {
  10711. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10712. {
  10713. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10714. isEnd = true;
  10715. }
  10716. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0 && Convert.ToInt32(dr["UserId"]) == 2125)//设计系统
  10717. {
  10718. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10719. isEnd = true;
  10720. }
  10721. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10722. {
  10723. needCyt = true;
  10724. }
  10725. }
  10726. if (isEnd)
  10727. {
  10728. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10729. ceErpTradeCell.AfterSaleState = 4;
  10730. ceErpTradeCell.AfterSaleSupplierState = 1;
  10731. }
  10732. }
  10733. else
  10734. {
  10735. bool isAll = true;
  10736. foreach (DataRow dr in dt.Rows)
  10737. {
  10738. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 2 && Convert.ToInt32(dr["UserId"]) != 101)//物流
  10739. {
  10740. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10741. continue;
  10742. }
  10743. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 0)
  10744. {
  10745. string path = "";
  10746. int OrgID = 0;
  10747. if (!Convert.IsDBNull(dr["OrgPath"]))
  10748. {
  10749. path = dr["OrgPath"].ToString();
  10750. }
  10751. if (!Convert.IsDBNull(dr["OrgID"]))
  10752. {
  10753. OrgID = Convert.ToInt32(dr["OrgID"]);
  10754. }
  10755. if (!path.Contains("|2|") && OrgID != 2 && !path.Contains("|3|") && OrgID != 3 && !path.Contains("|4|") && OrgID != 4)//客服、设计、下单
  10756. {
  10757. CeErpTradeResponsible.DelById(dr["ID"], 1);
  10758. continue;
  10759. }
  10760. }
  10761. if (!Convert.IsDBNull(dr["type"]) && Convert.ToInt32(dr["type"]) == 1 && Convert.ToInt32(dr["UserId"]) == 64)
  10762. {
  10763. needCyt = true;
  10764. }
  10765. isAll = false;
  10766. }
  10767. if (isAll)
  10768. {
  10769. ceErpTradeCell.FinishAfterSaleTime = DateTime.Now;
  10770. ceErpTradeCell.AfterSaleState = 4;
  10771. ceErpTradeCell.AfterSaleSupplierState = 1;
  10772. }
  10773. }
  10774. }
  10775. if (needCyt && ceErpTradeCell.AfterSaleState != 4)
  10776. {
  10777. commonHelper.sendCytAfterSale(ceErpTradeCell);
  10778. }
  10779. if (ceErpTradeCell.AfterSaleState == 4)
  10780. {
  10781. ApiVo apiVo = new ApiVo();
  10782. apiVo.orderNumber = ceErpTradeCell.ctid;
  10783. apiVo.actionName = "afterOver";
  10784. designHelper.API_WorkCore(apiVo); //afterOver
  10785. }
  10786. ceErpTradeCell.Update();
  10787. CeErpTradeResponsible.dateByTid(ceErpTradeCell.ctid);
  10788. CeErpSukuraData.createInfo(ceErpTradeCell.ctid, 8);
  10789. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "通过售后单", ceErpTradeCell.OrderState, ceErpTradeCell.AfterSaleState);
  10790. return true;
  10791. }
  10792. return false;
  10793. }
  10794. public void get_erp_wechatorder()
  10795. {
  10796. DataStruct dStruct = GetPostStruct();
  10797. List<string> lw = new List<string>();
  10798. string tid = GetPostString("tid");
  10799. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10800. string shopname = GetPostString("shopname");
  10801. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10802. string buyernick = GetPostString("buyer_nick");
  10803. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10804. string customer = GetPostString("customer");
  10805. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10806. string returndate1 = GetPostString("returndate1");
  10807. string returndate2 = GetPostString("returndate2");
  10808. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10809. if (dw.Length > 0) lw.Add(dw);
  10810. string finishDate1 = GetPostString("finishdate1");
  10811. string finishDate2 = GetPostString("finishdate2");
  10812. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10813. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10814. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10815. dStruct.Order = "created desc";
  10816. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10817. DataTable dt = WebCache.GetData("view_ErpReturnCash", dStruct);
  10818. writeGridDataTableJson(dStruct.TotalCount, dt);
  10819. }
  10820. public void get_erp_wechatlist_sumprice()
  10821. {
  10822. DataStruct dStruct = GetPostStruct();
  10823. List<string> lw = new List<string>();
  10824. string tid = GetPostString("tid");
  10825. if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid));
  10826. string shopname = GetPostString("shopname");
  10827. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  10828. string buyernick = GetPostString("buyer_nick");
  10829. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  10830. string customer = GetPostString("customer");
  10831. if (customer.Length > 0) lw.Add(string.Format("applyUserName like '%{0}%'", customer));
  10832. string returndate1 = GetPostString("returndate1");
  10833. string returndate2 = GetPostString("returndate2");
  10834. string dw = GetDateMinuteWhere("created", returndate1, returndate2);
  10835. if (dw.Length > 0) lw.Add(dw);
  10836. string finishDate1 = GetPostString("finishdate1");
  10837. string finishDate2 = GetPostString("finishdate2");
  10838. string dw_finish = GetDateMinuteWhere("verifytime", finishDate1, finishDate2);
  10839. if (dw_finish.Length > 0) lw.Add(dw_finish);
  10840. lw.Add(string.Format("rtype = '{0}'", "微信返现"));
  10841. string mainWhere = string.Join(" and ", lw.ToArray());
  10842. string sql = "select sum(payment) as sumpayment from view_ErpReturnCash where " + mainWhere;
  10843. DataSet dataSet = DbHelper.DbConn.ExecuteDataset(sql);
  10844. DataTable dt = dataSet == null ? new DataTable() : dataSet.Tables[0];
  10845. decimal total = 0;
  10846. if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["sumpayment"]) != "")
  10847. {
  10848. total = Convert.ToDecimal(dt.Rows[0]["sumpayment"]);
  10849. }
  10850. var res = new
  10851. {
  10852. data = total
  10853. };
  10854. string ro_jsond = JsonConvert.SerializeObject(res);
  10855. returnSuccess(ro_jsond);
  10856. return;
  10857. }
  10858. public void get_erp_qr_waitdeliverylist()
  10859. {
  10860. DataStruct dStruct = GetPostStruct();
  10861. List<string> lw = new List<string>();
  10862. string tid = GetPostString("ctid");
  10863. if (tid.Length > 0) lw.Add(string.Format("ctid = '{0}' ", tid));
  10864. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10865. DataTable dt = WebCache.GetData("view_erptradecell", dStruct);
  10866. var res_objz = new
  10867. {
  10868. restype = 1,
  10869. data = dt
  10870. };
  10871. string ro_jsonz = JsonConvert.SerializeObject(res_objz);
  10872. returnSuccess(ro_jsonz);
  10873. }
  10874. public void get_erp_yield_list()
  10875. {
  10876. DataStruct dStruct = GetPostStruct();
  10877. List<string> lw = new List<string>();
  10878. string tid = GetPostString("ctid");
  10879. if (tid.Length > 0) lw.Add(string.Format("tid = '{0}' ", tid));
  10880. string shopname = GetPostString("shopname");
  10881. if (shopname.Length > 0) lw.Add(string.Format("seller_nick='{0}'", shopname));
  10882. string buyernick = GetPostString("buyer_nick");
  10883. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick='{0}'", buyernick));
  10884. //if (tid.Length == 0 && buyernick.Length == 0)
  10885. //{
  10886. // lw.Add(string.Format("IsRefund<={0}", 1));
  10887. //}
  10888. string customer = GetPostString("customer");
  10889. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  10890. string design = GetPostString("design");
  10891. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  10892. string orderState = GetPostString("orderState");
  10893. if (orderState.Length > 0) lw.Add(string.Format("OrderState like '%{0}%'", orderState));
  10894. string address = GetPostString("address");
  10895. 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));
  10896. string sellermemo = GetPostString("seller_memo");
  10897. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  10898. string supplier = GetPostString("supplier");
  10899. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  10900. string OrderArea = GetPostString("order_area");
  10901. if (OrderArea.Length > 0) lw.Add(string.Format("IsSample = {0}", OrderArea));
  10902. string placedate1 = GetPostString("placedate1");
  10903. string placedate2 = GetPostString("placedate2");
  10904. string fdw = GetDateMinuteWhere("FinishPlaceTime", placedate1, placedate2);
  10905. if (fdw.Length > 0) lw.Add(fdw);
  10906. string price1 = GetPostString("price1");
  10907. if (price1.Length > 0) lw.Add(string.Format("payment >= '{0}'", price1));
  10908. string price2 = GetPostString("price2");
  10909. if (price2.Length > 0) lw.Add(string.Format("payment <= '{0}'", price2));
  10910. string unusualCon = GetPostString("unusualcon");
  10911. if (unusualCon.Length > 0) lw.Add(string.Format("UnusualCon like '%{0}%'", unusualCon));
  10912. string posTag = CurrentUser.UserPost.Post.Code;
  10913. if (posTag == "Supplier")
  10914. {
  10915. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  10916. }
  10917. lw.Add(string.Format("OrderState = 6 "));
  10918. lw.Add(string.Format("(IsXianHuo=0 or (IsXianHuo=1 and IsReturn=0)) "));
  10919. dStruct.Order = "MemoOpt desc,IsSF desc, FinishPlaceTime desc, ctid desc";
  10920. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  10921. DataTable dt = WebCache.GetData("view_supYield", dStruct);
  10922. writeGridDataTableJson(dStruct.TotalCount, dt);
  10923. }
  10924. public void change_erp_sup_state()
  10925. {
  10926. if (UrlPostParmsCheck("ctid"))
  10927. {
  10928. string ctid = GetPostString("ctid");
  10929. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10930. if (ceErpTradeCell != null)
  10931. {
  10932. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  10933. if (ceErpTradeCellExtend == null)
  10934. {
  10935. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  10936. ceErpTradeCellExtend.ctid = ctid;
  10937. ceErpTradeCellExtend.SupState = 1;
  10938. ceErpTradeCellExtend.Create();
  10939. }
  10940. else
  10941. {
  10942. ceErpTradeCellExtend.SupState = 1;
  10943. ceErpTradeCellExtend.Update();
  10944. }
  10945. LogHelper.addLog(ctid, CurrentUser.UserID, "标记已生产", 6);
  10946. returnSuccess(JsonConvert.SerializeObject(new { tid = ceErpTradeCell.tid }));
  10947. return;
  10948. }
  10949. returnErrorMsg("找不到订单");
  10950. }
  10951. }
  10952. public void supplier_all_downs()
  10953. {
  10954. if (UrlPostParmsCheck("tids"))
  10955. {
  10956. string tids = GetPostString("tids");
  10957. if (tids != null && tids.Length > 0)
  10958. {
  10959. StringBuilder sql = new StringBuilder();
  10960. sql.AppendFormat("update CE_ErpTradeCell set OrderState = 6,UpdateTime=getdate() where ctid in ({0}) ;", ("'" + tids.Replace(",", "','") + "'"));
  10961. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10962. sql = new StringBuilder();
  10963. 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, "下载设计文件");
  10964. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  10965. string[] list = tids.Split(',');
  10966. foreach (string ctid in list)
  10967. {
  10968. CeErpSukuraData.createInfo(ctid, 3);
  10969. }
  10970. designHelper.api_approveDesign(tids); //approveDesign
  10971. returnSuccessMsg("下载成功!");
  10972. return;
  10973. }
  10974. returnErrorMsg("下载订单更新失败");
  10975. }
  10976. }
  10977. public void uploaderFileSuccess()
  10978. {
  10979. if (UrlPostParmsCheck("fileName"))
  10980. {
  10981. string fileName = GetPostString("fileName");
  10982. ApiVo apiVo = new ApiVo();
  10983. apiVo.orderNumber = fileName;
  10984. apiVo.actionName = "finishDesign";
  10985. designHelper.API_WorkCore(apiVo);//finishDesign
  10986. returnSuccessMsg("");
  10987. }
  10988. }
  10989. public void get_sample2_order()
  10990. {
  10991. if (UrlPostParmsCheck("ctid"))
  10992. {
  10993. string ctid = GetPostString("ctid");
  10994. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  10995. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  10996. string sql = "select payment from ce_erptradecell where IsSample = 2 and IsRefund = 0 and ptid='" + ceErpTradeCell.tid + "'";
  10997. DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
  10998. double total = 0.0;
  10999. double order_price = 0.0;
  11000. if (dt_bu.Rows.Count > 0)
  11001. {
  11002. foreach (DataRow dr in dt_bu.Rows)
  11003. {
  11004. total += Convert.ToDouble(dr["payment"]);
  11005. }
  11006. }
  11007. order_price = Convert.ToDouble(Math.Round(ceErpTradeCell.payment / ceErpTrade.payment * total, 2));
  11008. string after_sql = "select top 1 ReturnReason from ce_erptradecell where IsReturn=3 and ctid='" + "S_" + ceErpTradeCell.ctid + "'";
  11009. DataTable dt_after = CeErpTradeCell.ExecuteDataset(after_sql).Tables[0];
  11010. string tid = ctid.Replace("S_", "");
  11011. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(tid);
  11012. double paymant = 0.0;
  11013. if (entity != null)
  11014. {
  11015. paymant = entity.payment;
  11016. }
  11017. string return_reason = "";
  11018. if (dt_after != null && dt_after.Rows.Count > 0)
  11019. {
  11020. return_reason = dt_after.Rows[0]["ReturnReason"].ToString();
  11021. }
  11022. returnSuccess(JsonConvert.SerializeObject(new { total, order_price, total_order = ceErpTradeCell.payment, return_reason, paymant }));
  11023. }
  11024. }
  11025. public void get_erp_design_status()
  11026. {
  11027. string designName = GetPostString("designName");
  11028. DataStruct dStruct = GetPostStruct();
  11029. if (designName.Length > 0)
  11030. {
  11031. 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";
  11032. sql_user += " and Name like '%" + designName + "%'";
  11033. DataTable user_table = DbHelper.DbConn.ExecuteDataset(sql_user).Tables[0];
  11034. List<string> ids_list = new List<string>();
  11035. if (user_table.Rows.Count > 0)
  11036. {
  11037. foreach (DataRow item in user_table.Rows)
  11038. {
  11039. ids_list.Add(item["id"].ToString());
  11040. string ids_s = item["TeamIds"].ToString();
  11041. if (ids_s.Length > 0)
  11042. {
  11043. ids_list.AddRange(ids_s.Split(','));
  11044. }
  11045. }
  11046. }
  11047. HashSet<string> set = new HashSet<string>(ids_list);
  11048. ids_list = set.ToList();
  11049. if (ids_list.Count > 0)
  11050. {
  11051. 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));
  11052. dStruct.MainWhere = sql;
  11053. DataTable dt = null;
  11054. dt = WebCache.GetData("view_ErpUser", dStruct);
  11055. writeGridDataTableJson(dStruct.TotalCount, dt);
  11056. }
  11057. }
  11058. }
  11059. public void change_erp_order_price()
  11060. {
  11061. string ctid = GetPostString("ctid");
  11062. double price = GetPostDouble("price");
  11063. if (ctid.Length > 0)
  11064. {
  11065. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11066. if (ceErpTradeCellExtend == null)
  11067. {
  11068. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11069. ceErpTradeCellExtend.ctid = ctid;
  11070. ceErpTradeCellExtend.payment_cyt = price;
  11071. ceErpTradeCellExtend.Create();
  11072. }
  11073. else
  11074. {
  11075. ceErpTradeCellExtend.payment_cyt = price;
  11076. ceErpTradeCellExtend.Update();
  11077. }
  11078. CeErpDataSendOrderInfo ceErpDataSendOrderInfo = CeErpDataSendOrderInfo.GetByCtid(ctid);
  11079. if (ceErpDataSendOrderInfo != null && ceErpDataSendOrderInfo.ID > 0)
  11080. {
  11081. ceErpDataSendOrderInfo.isSync = false;
  11082. ceErpDataSendOrderInfo.Update();
  11083. }
  11084. if (ceErpDataSendOrderInfo == null)
  11085. {
  11086. ceErpDataSendOrderInfo = new CeErpDataSendOrderInfo();
  11087. ceErpDataSendOrderInfo.isSync = false;
  11088. ceErpDataSendOrderInfo.ctid = ctid;
  11089. ceErpDataSendOrderInfo.Create();
  11090. }
  11091. LogHelper.addLog(ctid, CurrentUser.UserID, "修改order_price成功", 6);
  11092. string sql = string.Format("select * from view_dataSendOrderInfo where ctid='{0}'", ctid);
  11093. DataTable dth = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11094. if (dth != null && dth.Rows.Count > 0)
  11095. {
  11096. dataSendOrderBean dataSendOrderBean = null;
  11097. foreach (DataRow item in dth.Rows)
  11098. {
  11099. try
  11100. {
  11101. dataSendOrderBean = new dataSendOrderBean();
  11102. dataSendOrderBean.Date1723191218572 = item["pay_time"].ToString();
  11103. dataSendOrderBean.RelevanceForm1723191634028 = item["SupplierId"].ToString();
  11104. dataSendOrderBean.RelevanceForm1723191239149 = item["ShopId"].ToString();
  11105. dataSendOrderBean.Date1723193880305 = item["FinishDeliveryTime"].ToString();
  11106. dataSendOrderBean.Date1723193870660 = item["FinishPlaceTime"].ToString();
  11107. dataSendOrderBean.LongText1723542734262 = item["seller_memo"].ToString();
  11108. dataSendOrderBean.ShortText1723542735637 = item["OtherMemo"].ToString();
  11109. dataSendOrderBean.ShortText1723542736542 = item["address"].ToString();
  11110. dataSendOrderBean.ShortText1723193907492 = item["OutSid"].ToString();
  11111. dataSendOrderBean.Number1723193919446 = item["payment_cyt"].ToString();
  11112. dataSendOrderBean.ShortText1723707899761 = item["ctid"].ToString();
  11113. dataSendOrderBean.Radio1723534706288 = item["IsReturn"].ToString() == "0" ? "未结算" : "打回";
  11114. dataResponseVo result = dataHelper.CreateBoFahuo(dataSendOrderBean);
  11115. if (result != null)
  11116. {
  11117. if ("0".Equals(result.errcode))
  11118. {
  11119. CeErpDataSendOrderInfo.updateAsync(item["ctid"].ToString(), JsonConvert.SerializeObject(dataSendOrderBean));
  11120. }
  11121. else
  11122. {
  11123. CeErpDataSendOrderInfo.updateError(item["ctid"].ToString(), result.errmsg, JsonConvert.SerializeObject(dataSendOrderBean));
  11124. }
  11125. }
  11126. }
  11127. catch (Exception ex)
  11128. {
  11129. }
  11130. }
  11131. }
  11132. returnSuccessMsg("修改成功!");
  11133. return;
  11134. }
  11135. returnErrorMsg("找不到订单");
  11136. }
  11137. public void find_he_together()
  11138. {
  11139. string ctid = GetPostString("ctid");
  11140. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11141. List<string> list = new List<string>();
  11142. if (ceErpTradeCell != null)
  11143. {
  11144. if (ceErpTradeCell.seller_memo.Contains("合包"))//有合包标识
  11145. {
  11146. 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);
  11147. DataTable table = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11148. if (table != null && table.Rows.Count > 0)
  11149. {
  11150. foreach (TableRow row in table.Rows)
  11151. {
  11152. }
  11153. }
  11154. }
  11155. }
  11156. returnSuccess(JsonConvert.SerializeObject(new { list }));
  11157. }
  11158. Dictionary<int, Dictionary<string, string>> supplierMap = new Dictionary<int, Dictionary<string, string>>()
  11159. {
  11160. //chy----19
  11161. {19, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, { "宣传单", "宣传单" }, { "手提袋", "手提袋" } }},
  11162. //GD-CYT-----64
  11163. {64, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"杯套", "杯套"}}},
  11164. //ZHX----3
  11165. {3, new Dictionary<string, string> {{"不干胶", "不干胶"}, {"卡片", "卡片"}, {"插卡", "插卡"}, {"uv", "uv"}, { "班旗", "班旗" }}},
  11166. //JK----97
  11167. {97, new Dictionary<string, string> {{"uv", "uv"}}},
  11168. //ZT----70
  11169. {70, new Dictionary<string, string> {{"uv", "uv"}}},
  11170. //LHCY-----98
  11171. {98, new Dictionary<string, string> {{"条幅", "条幅"}, {"帆布", "帆布"}, { "贡缎布", "贡缎布" }, { "纱幔", "纱幔" }, { "班旗", "班旗" } }},
  11172. //XD-----90
  11173. {90, new Dictionary<string, string> {{"条幅", "条幅"}, {"桌布", "桌布"}, { "班旗", "班旗" } }},
  11174. //CYCY-----14
  11175. {14, new Dictionary<string, string> {{"卡片", "卡片"}, {"宣传单", "宣传单"}, {"杯套", "杯套"}}}
  11176. };
  11177. //其他改名
  11178. Dictionary<int, string> suppliers = new Dictionary<int, string>()
  11179. {
  11180. {15,"滴塑" }, {119,"数码" }, {110,"刮刮卡" }, {10,"数码" },
  11181. {5,"海报" }, {80,"数码" }, {96,"数码" }, {9,"金属标" },
  11182. {7,"综合" }, {116,"棉卡" }, {59,"海报" }, {37,"不干胶" },
  11183. {81,"金属标" }, {30,"卡片" }, {111,"种子纸" }, {72,"金属标" },
  11184. {13,"数码" }, {45,"卷标" }, {31,"联单" }, {118,"海报" },
  11185. {71,"数码" }, {70,"uv" },{93,"金属标" },{105,"uv" },{97,"数码" },
  11186. {49,"暖心贴" }, {117,"手提袋" },{108,"写真布" },{44,"PVC" },{32,"扇子" },
  11187. {4,"不干胶" },{106,"不干胶" },{94,"纸杯" },{100,"暖心贴" },{114,"定制衫" }
  11188. };
  11189. //不统计
  11190. List<int> no_suppliers = new List<int>()
  11191. {
  11192. 84,33,48,25,50,2,56,109,12,8,16,12,8,35,87
  11193. };
  11194. //配件单
  11195. Dictionary<string, List<string>> maps = new Dictionary<string, List<string>>()
  11196. {
  11197. {"绳子",new List<string>(){"帆布", "卡片", "吊牌", "旗帜布" } },
  11198. {"棉绳",new List<string>(){ "卡片", "吊牌" } },
  11199. {"别针",new List<string>(){ "卡片", "吊牌" } },
  11200. {"刮刮膜",new List<string>(){ "卡片", "刮刮卡" } },
  11201. {"流苏",new List<string>(){ "卡片", "吊牌" } },
  11202. {"旗杆",new List<string>(){ "班旗" } },
  11203. {"牙签",new List<string>(){ "不干胶" } }
  11204. };
  11205. public void get_place_order_data()
  11206. {
  11207. string date1 = GetPostString("date1");
  11208. string date2 = GetPostString("date2");
  11209. string starttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
  11210. DateTime start = DateTime.Parse(starttime);
  11211. string endtime = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
  11212. DateTime end = DateTime.Parse(endtime);
  11213. if (date1 != null && date1.Length > 0)
  11214. {
  11215. DateTime dateTime = DateTime.Parse(date1);
  11216. starttime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11217. start = DateTime.Parse(starttime);
  11218. endtime = dateTime.ToString("yyyy-MM-dd 23:59:59");
  11219. end = DateTime.Parse(endtime);
  11220. }
  11221. if (date2 != null && date2.Length > 0)
  11222. {
  11223. DateTime dateTime = DateTime.Parse(date2);
  11224. endtime = dateTime.ToString("yyyy-MM-dd 00:00:00");
  11225. end = DateTime.Parse(endtime);
  11226. }
  11227. 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);
  11228. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11229. //不干胶-----1,卡片-----29
  11230. Dictionary<string, Dictionary<string, int>> other_map = new Dictionary<string, Dictionary<string, int>>();
  11231. foreach (DataRow row in data.Rows)
  11232. {
  11233. int productId = Convert.ToInt32(row["ProductId"]);
  11234. int supplierId = Convert.ToInt32(row["SupplierId"]);
  11235. if (no_suppliers.Contains(supplierId))
  11236. {
  11237. continue;
  11238. }
  11239. string seller_memo = row["seller_memo"].ToString();
  11240. bool ispj = false;//是否配件单
  11241. bool isfirst = true;//第一个配
  11242. maps.Keys.ForEach(key =>
  11243. {
  11244. //备注包含配件
  11245. if (seller_memo.Contains(key) && isfirst)
  11246. {
  11247. List<string> list = maps[key];
  11248. ispj = true;
  11249. isfirst = false;
  11250. for (int i = 0; i < list.Count; i++)
  11251. {
  11252. if (seller_memo.Contains(list[i]))
  11253. {
  11254. ispj = false;
  11255. break;
  11256. }
  11257. }
  11258. }
  11259. });
  11260. if (ispj)
  11261. {
  11262. continue;
  11263. }
  11264. seller_memo = seller_memo.Replace("UV", "uv");
  11265. seller_memo = seller_memo.Replace("贡锻布", "贡缎布");
  11266. //吊牌归到卡片
  11267. seller_memo = seller_memo.Replace("吊牌", "卡片");
  11268. seller_memo = seller_memo.Replace("卡套", "卡片");
  11269. seller_memo = seller_memo.Replace("封套", "卡片");
  11270. seller_memo = seller_memo.Replace("吸管套", "卡片");
  11271. seller_memo = seller_memo.Replace("腰封", "卡片");
  11272. seller_memo = seller_memo.Replace("旗帜布", "条幅");
  11273. seller_memo = seller_memo.Replace("手拉旗", "条幅");
  11274. seller_memo = seller_memo.Replace("横幅", "条幅");
  11275. seller_memo = seller_memo.Replace("锦旗", "条幅");
  11276. string map_key = "";
  11277. string type = "";
  11278. if (supplierMap.ContainsKey(supplierId))
  11279. {
  11280. foreach (var kvp in supplierMap[supplierId])
  11281. {
  11282. if (seller_memo.Contains(kvp.Key))
  11283. {
  11284. map_key = kvp.Value;
  11285. type = kvp.Value;
  11286. break;
  11287. }
  11288. }
  11289. }
  11290. if (map_key == "")
  11291. {
  11292. type = "其他";
  11293. map_key = "其他";
  11294. }
  11295. if ("其他".Equals(map_key) && suppliers.ContainsKey(supplierId))
  11296. {
  11297. map_key = suppliers[supplierId];
  11298. }
  11299. if (supplierId == 70)
  11300. {
  11301. supplierId = 70;
  11302. }
  11303. map_key += "_" + row["SupplierName"].ToString();
  11304. Dictionary<string, int> map = null;
  11305. if (other_map.ContainsKey(map_key))
  11306. {
  11307. other_map.TryGetValue(map_key, out map);
  11308. }
  11309. else
  11310. {
  11311. map = new Dictionary<string, int>();
  11312. map.Add("dayDev", 0);//当天出货
  11313. map.Add("dayTotal", 0);//下单总数
  11314. map.Add("payTotal", 0);//500以上
  11315. map.Add("today", 0);//当天出货数量
  11316. map.Add("unusua", 0);//异常数
  11317. other_map.Add(map_key, map);
  11318. other_map.TryGetValue(map_key, out map);
  11319. }
  11320. DateTime palceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11321. DateTime palceTimeStart = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 00:00:00"));
  11322. DateTime palceTimeEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59"));
  11323. DateTime palceTimeTwoEnd = DateTime.Parse(palceTime.ToString("yyyy-MM-dd 23:59:59")).AddHours(2);
  11324. if (DateTime.Compare(start, palceTime) < 0 && DateTime.Compare(end, palceTime) > 0)
  11325. {
  11326. map["dayTotal"]++;
  11327. if (supplierId == 97)
  11328. {
  11329. supplierId = 97;
  11330. }
  11331. }
  11332. if (Convert.ToDecimal(row["payment"]) >= 500)
  11333. {
  11334. map["payTotal"]++;
  11335. }
  11336. if (row["FinishDeliveryTime"].ToString() != null && row["FinishDeliveryTime"].ToString().Length > 0)
  11337. {
  11338. DateTime FinishDeliveryTime = DateTime.Parse(row["FinishDeliveryTime"].ToString());
  11339. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11340. {
  11341. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeTwoEnd, FinishDeliveryTime) > 0)//当天发货
  11342. {
  11343. map["today"]++;
  11344. }
  11345. }
  11346. else
  11347. {
  11348. if (DateTime.Compare(palceTimeStart, FinishDeliveryTime) < 0 && DateTime.Compare(palceTimeEnd, FinishDeliveryTime) > 0)//当天发货
  11349. {
  11350. map["today"]++;
  11351. }
  11352. else
  11353. {
  11354. if (supplierId == 119)
  11355. {
  11356. Debug.WriteLine(row["seller_memo"].ToString());
  11357. }
  11358. }
  11359. }
  11360. }
  11361. if (row["UnusualTime"].ToString() != null && row["UnusualTime"].ToString().Length > 0)
  11362. {
  11363. map["unusua"]++;
  11364. }
  11365. DateTime FinishPlaceTime = DateTime.Parse(row["FinishPlaceTime"].ToString());
  11366. //GD-CYT-----64
  11367. DateTime two = palceTimeStart.AddHours(14);
  11368. DateTime three = palceTimeStart.AddHours(15);
  11369. DateTime four = palceTimeStart.AddHours(16);
  11370. if (supplierId == 64 && "不干胶".Equals(type) && !seller_memo.Contains("牙签"))
  11371. {
  11372. //下午四点前 500-1000
  11373. string count = row["ProductCount"].ToString();
  11374. if (count != null && count.Length > 0)
  11375. {
  11376. int productCount = commonHelper.getPlaceProductCount(count);
  11377. if (productCount >= 500 && productCount <= 1000)
  11378. {
  11379. if (DateTime.Compare(FinishPlaceTime, four) < 0)
  11380. {
  11381. map["dayDev"]++;
  11382. }
  11383. }
  11384. }
  11385. }
  11386. //UV
  11387. else if ("uv".Equals(type))
  11388. {
  11389. //ZT----70
  11390. //ZHX----3
  11391. if (DateTime.Compare(FinishPlaceTime, four) < 0 && (supplierId == 70 || supplierId == 3))
  11392. {
  11393. map["dayDev"]++;
  11394. }
  11395. //JK----97
  11396. //HZX----105
  11397. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 97 || supplierId == 105))
  11398. {
  11399. map["dayDev"]++;
  11400. if (supplierId == 97)
  11401. {
  11402. supplierId = 97;
  11403. }
  11404. }
  11405. }
  11406. //帆布---52|条幅---27
  11407. else if ("帆布".Equals(type) || "条幅".Equals(type))
  11408. {
  11409. //LHCY-----98
  11410. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 98))
  11411. {
  11412. map["dayDev"]++;
  11413. }
  11414. }
  11415. //条幅
  11416. else if ("条幅".Equals(type))
  11417. {
  11418. //XD-----90
  11419. if (DateTime.Compare(FinishPlaceTime, two) < 0 && (supplierId == 90))
  11420. {
  11421. map["dayDev"]++;
  11422. }
  11423. }
  11424. //桌布
  11425. else if ("桌布".Equals(type))
  11426. {
  11427. //XD-----90
  11428. if (DateTime.Compare(FinishPlaceTime, three) < 0 && (supplierId == 90))
  11429. {
  11430. map["dayDev"]++;
  11431. }
  11432. }
  11433. //DL---10
  11434. //AYTW---119
  11435. //FS-CYT-DY ----80
  11436. //JK----97
  11437. else if (supplierId == 10 || supplierId == 119 || supplierId == 80 || supplierId == 97)
  11438. {
  11439. if (DateTime.Compare(FinishPlaceTime, three) < 0)
  11440. {
  11441. map["dayDev"]++;
  11442. }
  11443. }
  11444. }
  11445. DataTable dt = new DataTable();
  11446. dt.Columns.Add(new DataColumn("ProductName", typeof(string)));
  11447. dt.Columns.Add(new DataColumn("SupplierName", typeof(string)));
  11448. dt.Columns.Add(new DataColumn("dayTotal", typeof(string)));
  11449. dt.Columns.Add(new DataColumn("payTotal", typeof(string)));
  11450. dt.Columns.Add(new DataColumn("today", typeof(string)));
  11451. dt.Columns.Add(new DataColumn("unusua", typeof(string)));
  11452. dt.Columns.Add(new DataColumn("dayDev", typeof(string)));
  11453. dt.Columns.Add(new DataColumn("dayRate", typeof(string)));
  11454. other_map.Keys.ForEach(key =>
  11455. {
  11456. DataRow dr = dt.NewRow();
  11457. Dictionary<string, int> map = other_map[key];
  11458. string[] key_list = key.Split('_');
  11459. dr[0] = key_list[0];
  11460. dr[1] = key_list[1];
  11461. if (key_list.Length > 2)
  11462. {
  11463. dr[1] += "(" + key_list[2] + ")";
  11464. }
  11465. dr[2] = map["dayTotal"];
  11466. dr[3] = map["payTotal"];
  11467. dr[4] = map["today"];
  11468. dr[5] = map["unusua"];
  11469. dr[6] = map["dayDev"];
  11470. double rate = 0.00;
  11471. if (map["dayDev"] > 0)
  11472. {
  11473. rate = Math.Round((Convert.ToDouble(map["today"]) / Convert.ToDouble(map["dayDev"])), 2);
  11474. }
  11475. dr[7] = rate.ToString();
  11476. dt.Rows.Add(dr);
  11477. });
  11478. DataView dv = new DataView(dt);
  11479. dv.Sort = "SupplierName";
  11480. //dv.Sort = "AllOrder desc";
  11481. DataTable dtNew = dv.ToTable();
  11482. writeGridDataTableJson(dtNew.Rows.Count, dtNew);
  11483. }
  11484. public void check_order_desing_info()
  11485. {
  11486. string ctid = GetPostString("ctid");
  11487. if (!string.IsNullOrEmpty(ctid))
  11488. {
  11489. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11490. if (ceErpTradeCell != null)
  11491. {
  11492. designApiResponseVo response = commonHelper.checkOrderDesignInfo(ceErpTradeCell);
  11493. returnSuccess(JsonConvert.SerializeObject(new { response }));
  11494. return;
  11495. }
  11496. returnErrorMsg("找不到订单");
  11497. return;
  11498. }
  11499. returnErrorMsg("找不到订单");
  11500. }
  11501. public void get_timeout_detail()
  11502. {
  11503. string poscode = CurrentUser.UserPost.Post.Code;
  11504. DataStruct dStruct = GetPostStruct();
  11505. List<string> lw = new List<string>();
  11506. string id = GetPostString("id");
  11507. string pay_date1 = GetPostString("pay_date1");
  11508. string pay_date2 = GetPostString("pay_date2");
  11509. int type = GetPostInt("type");
  11510. if (type == 0)
  11511. {
  11512. if (pay_date1.Length > 0)
  11513. {
  11514. lw.Add(string.Format(" pay_time >= '{0}' ", pay_date1));
  11515. }
  11516. if (pay_date2.Length > 0)
  11517. {
  11518. lw.Add(string.Format(" pay_time < '{0}'", pay_date2));
  11519. }
  11520. lw.Add(string.Format(" CustomerUserId = {0} AND create_time > 0 AND pay_time > 0 AND datediff( HOUR, pay_time,create_time ) > 1 ", id));
  11521. }
  11522. if (type == 1)
  11523. {
  11524. if (pay_date1.Length > 0)
  11525. {
  11526. lw.Add(string.Format(" WaitDesignTime >= '{0}' ", pay_date1));
  11527. }
  11528. if (pay_date2.Length > 0)
  11529. {
  11530. lw.Add(string.Format(" WaitDesignTime < '{0}'", pay_date2));
  11531. }
  11532. lw.Add(string.Format(" DesignUserId = {0} AND WaitDesignTime > 0 AND FinishDesignTime > 0 AND datediff( HOUR, WaitDesignTime, FinishDesignTime ) > 24 ", id));
  11533. }
  11534. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11535. DataTable dt = null;
  11536. dt = WebCache.GetData("view_orderlist", dStruct);
  11537. writeGridDataTableJson(dStruct.TotalCount, dt);
  11538. }
  11539. public void saveUrgentChargePrice()
  11540. {
  11541. string ctid = GetPostString("ctid");
  11542. if (!string.IsNullOrEmpty(ctid))
  11543. {
  11544. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11545. if (ceErpTradeCell != null)
  11546. {
  11547. double price = GetPostDouble("price");
  11548. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ceErpTradeCell.ctid);
  11549. if (ceErpTradeCellExtend == null)
  11550. {
  11551. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11552. ceErpTradeCellExtend.ctid = ceErpTradeCell.ctid;
  11553. }
  11554. ceErpTradeCellExtend.urgentCharge = price;
  11555. if (ceErpTradeCellExtend.ID > 0)
  11556. {
  11557. ceErpTradeCellExtend.Update();
  11558. }
  11559. else
  11560. {
  11561. ceErpTradeCellExtend.Save();
  11562. }
  11563. returnSuccessMsg("修改成功!");
  11564. return;
  11565. }
  11566. returnErrorMsg("找不到订单");
  11567. return;
  11568. }
  11569. returnErrorMsg("找不到订单");
  11570. }
  11571. public void finish_erp_order()
  11572. {
  11573. string ctid = GetPostString("ctid");
  11574. if (!string.IsNullOrEmpty(ctid))
  11575. {
  11576. if (CurrentUser.UserPost.Post.Code == "AfterSaleMaster" || CurrentUser.UserPost.Post.Code == "AfterSale" || CurrentUser.UserPost.Post.Code == "SysAdmin" || CurrentUser.UserID == 82 || CurrentUser.UserID == 2846)
  11577. {
  11578. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11579. if (ceErpTradeCell != null)
  11580. {
  11581. ceErpTradeCell.OrderState = ((int)OrderState.交易关闭);
  11582. ceErpTradeCell.Update();
  11583. LogHelper.addLog(ceErpTradeCell.ctid, CurrentUser.UserID, "关闭订单", ceErpTradeCell.OrderState);
  11584. returnSuccessMsg("修改成功!");
  11585. return;
  11586. }
  11587. }
  11588. }
  11589. returnErrorMsg("找不到订单");
  11590. }
  11591. public void get_trade_order_list()
  11592. {
  11593. string tid = GetPostString("tid");
  11594. if (!string.IsNullOrEmpty(tid))
  11595. {
  11596. string sql = string.Format("select * from CE_ErpTradeOrder where tid = '{0}'", tid);
  11597. DataTable data = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  11598. writeGridDataTableJson(data.Rows.Count, data);
  11599. return;
  11600. }
  11601. returnErrorMsg("找不到订单");
  11602. }
  11603. public void save_cell_spu()
  11604. {
  11605. string ctid = GetPostString("ctid");
  11606. string spu_id = GetPostString("spu_id");
  11607. if (!string.IsNullOrEmpty(ctid))
  11608. {
  11609. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11610. if (ceErpTradeCellExtend == null)
  11611. {
  11612. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11613. ceErpTradeCellExtend.ctid = ctid;
  11614. }
  11615. ceErpTradeCellExtend.spu_id = spu_id;
  11616. if (!string.IsNullOrEmpty(spu_id))
  11617. {
  11618. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  11619. string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, ceErpTradeCell.ShopId);
  11620. ceErpTradeCellExtend.ToType = result;
  11621. List<int> products = new List<int>() { 4, 13, 19, 24, 28, 32, 40, 51, 57, 1971, 2319, 2377, 2521, 2524, 2533, 2538, 2542, 2554, 2556, 2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2568, 2569, 2570, 2571, 2572, 2619, 2625, 2634, 2636, 2637, 2638, 2645, 2646 };
  11622. if (products.Contains(ceErpTradeCell.ProductId) || ceErpTradeCell.seller_memo.IndexOf("手绘") > -1 || ceErpTradeCell.seller_memo.IndexOf("电子稿") > -1 || ceErpTradeCell.isDianziOrder > 0)
  11623. {
  11624. ceErpTradeCellExtend.ToType = "外协";
  11625. }
  11626. if (ceErpTradeCell.seller_memo.Contains("改稿") || ceErpTradeCell.OtherMemo.Contains("改稿"))
  11627. {
  11628. ceErpTradeCellExtend.ToType = "内部";
  11629. }
  11630. if ("外协".Equals(ceErpTradeCellExtend.ToType))
  11631. {
  11632. string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ctid + "';";
  11633. CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
  11634. }
  11635. }
  11636. if (ceErpTradeCellExtend.ID == 0)
  11637. {
  11638. ceErpTradeCellExtend.Create();
  11639. }
  11640. else
  11641. {
  11642. ceErpTradeCellExtend.Update();
  11643. }
  11644. returnSuccessMsg("修改成功!");
  11645. return;
  11646. }
  11647. returnErrorMsg("找不到订单");
  11648. }
  11649. public void change_express_info()
  11650. {
  11651. string ctid = GetPostString("ctid");
  11652. string transNo = GetPostString("transNo");
  11653. string transCom = GetPostString("transCom");
  11654. if (!string.IsNullOrEmpty(ctid))
  11655. {
  11656. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11657. if (ceErpTradeCellExtend == null)
  11658. {
  11659. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11660. ceErpTradeCellExtend.ctid = ctid;
  11661. }
  11662. ceErpTradeCellExtend.modExpressNo = transNo;
  11663. ceErpTradeCellExtend.modExpressCom = transCom;
  11664. ceErpTradeCellExtend.readMod = 2;
  11665. if (ceErpTradeCellExtend.ID == 0)
  11666. {
  11667. ceErpTradeCellExtend.Create();
  11668. }
  11669. else
  11670. {
  11671. ceErpTradeCellExtend.Update();
  11672. }
  11673. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息:" + transNo + "_" + transCom, 6);
  11674. returnSuccessMsg("修改成功!");
  11675. return;
  11676. }
  11677. returnErrorMsg("找不到订单");
  11678. }
  11679. public void get_change_express_list()
  11680. {
  11681. DataStruct dStruct = GetPostStruct();
  11682. List<string> lw = new List<string>();
  11683. int st = 2;
  11684. string tid = GetPostString("ctid");
  11685. if (tid.Length > 0)
  11686. {
  11687. string select_tid = getTidByCtid(tid);
  11688. lw.Add(string.Format("tid='{0}'", select_tid));
  11689. }
  11690. string shopname = GetPostString("shopname");
  11691. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11692. string buyernick = GetPostString("buyer_nick");
  11693. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11694. string sellermemo = GetPostString("seller_memo");
  11695. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11696. string supplier = GetPostString("supplier");
  11697. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11698. string customer = GetPostString("customer");
  11699. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11700. string design = GetPostString("design");
  11701. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11702. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11703. string poscode = CurrentUser.UserPost.Post.Code;
  11704. if (poscode != "SysAdmin")
  11705. {
  11706. string shopid = CurrentUser.User.pemShop;
  11707. lw.Add(string.Format("shopId in ({0})", shopid));
  11708. }
  11709. lw.Add("readMod = 2");
  11710. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11711. DataTable dt = WebCache.GetData("view_ErpTradeCell", dStruct);
  11712. writeGridDataTableJson(dStruct.TotalCount, dt);
  11713. }
  11714. public void deal_express_complete()
  11715. {
  11716. string ctid = GetPostString("ctid");
  11717. if (!string.IsNullOrEmpty(ctid))
  11718. {
  11719. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11720. if (ceErpTradeCellExtend == null)
  11721. {
  11722. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11723. ceErpTradeCellExtend.ctid = ctid;
  11724. }
  11725. ceErpTradeCellExtend.readMod = 1;
  11726. if (ceErpTradeCellExtend.ID == 0)
  11727. {
  11728. ceErpTradeCellExtend.Create();
  11729. }
  11730. else
  11731. {
  11732. ceErpTradeCellExtend.Update();
  11733. }
  11734. LogHelper.addLog(ctid, CurrentUser.UserID, "修改物流信息处理完成", 6);
  11735. returnSuccessMsg("修改成功!");
  11736. return;
  11737. }
  11738. returnErrorMsg("找不到订单");
  11739. }
  11740. public void aftersale_return_visit()
  11741. {
  11742. string ctid = GetPostString("ctid");
  11743. if (!string.IsNullOrEmpty(ctid))
  11744. {
  11745. CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid);
  11746. if (ceErpTradeCellExtend == null)
  11747. {
  11748. ceErpTradeCellExtend = new CeErpTradeCellExtend();
  11749. ceErpTradeCellExtend.ctid = ctid;
  11750. }
  11751. ceErpTradeCellExtend.returnVisit = 1;
  11752. if (ceErpTradeCellExtend.ID == 0)
  11753. {
  11754. ceErpTradeCellExtend.Create();
  11755. }
  11756. else
  11757. {
  11758. ceErpTradeCellExtend.Update();
  11759. }
  11760. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11761. if (ceErpTradeAfterSaleExtend != null)
  11762. {
  11763. ceErpTradeAfterSaleExtend.TextResult = "";
  11764. ceErpTradeAfterSaleExtend.Update();
  11765. }
  11766. LogHelper.addLog(ctid, CurrentUser.UserID, "添加客户回访信息", 6);
  11767. returnSuccessMsg("修改成功!");
  11768. return;
  11769. }
  11770. returnErrorMsg("找不到订单");
  11771. }
  11772. public void orderPlaceInfo()
  11773. {
  11774. string ctids = GetPostString("ctids");
  11775. string[] list = ctids.Split(',');
  11776. foreach (string ctid in list)
  11777. {
  11778. CeErpSukuraData.createInfo(ctid, 3);
  11779. }
  11780. StringBuilder sql = new StringBuilder();
  11781. sql.AppendFormat("update CE_ErpTradeCell set UpdateTime=getdate() where ctid in ({0}) ;", ("'" + ctids.Replace(",", "','") + "'"));
  11782. CeErpTradeCell.ExecuteNonQuery(sql.ToString());
  11783. designHelper.api_approveDesign(ctids); //approveDesign
  11784. returnSuccessMsg("");
  11785. }
  11786. public void get_issue_list()
  11787. {
  11788. DataStruct dStruct = GetPostStruct();
  11789. List<string> lw = new List<string>();
  11790. int st = 2;
  11791. string tid = GetPostString("ctid");
  11792. if (tid.Length > 0)
  11793. {
  11794. string select_tid = getTidByCtid(tid);
  11795. lw.Add(string.Format("tid='{0}'", select_tid));
  11796. }
  11797. string shopname = GetPostString("shopname");
  11798. if (shopname.Length > 0) lw.Add(string.Format("seller_nick = '{0}'", shopname));
  11799. string buyernick = GetPostString("buyer_nick");
  11800. if (buyernick.Length > 0) lw.Add(string.Format("buyer_nick like '%{0}%'", buyernick));
  11801. string sellermemo = GetPostString("seller_memo");
  11802. if (sellermemo.Length > 0) lw.Add(string.Format("seller_memo like '%{0}%'", sellermemo));
  11803. string supplier = GetPostString("supplier");
  11804. if (supplier.Length > 0) lw.Add(string.Format("SupplierName like '%{0}%'", supplier));
  11805. string customer = GetPostString("customer");
  11806. if (customer.Length > 0) lw.Add(string.Format("CustomerTb like '%{0}%'", customer));
  11807. string design = GetPostString("design");
  11808. if (design.Length > 0) lw.Add(string.Format("DesignUserName like '%{0}%'", design));
  11809. //lw.Add(string.Format("IsArbitrate != '{0}'", 2));
  11810. string poscode = CurrentUser.UserPost.Post.Code;
  11811. if (poscode != "SysAdmin")
  11812. {
  11813. string shopid = CurrentUser.User.pemShop;
  11814. lw.Add(string.Format("shopId in ({0})", shopid));
  11815. }
  11816. if ("AfterSale".Equals(poscode) || "AfterSaleMaster".Equals(poscode))
  11817. {
  11818. lw.Add("IssueState = 1");
  11819. }
  11820. lw.Add("IssueState > 0");
  11821. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  11822. DataTable dt = WebCache.GetData("view_ErpTradeCellIssue", dStruct);
  11823. writeGridDataTableJson(dStruct.TotalCount, dt);
  11824. }
  11825. public void saveIssueContent()
  11826. {
  11827. string ctid = GetPostString("ctid");
  11828. if (!string.IsNullOrEmpty(ctid))
  11829. {
  11830. string content = GetPostString("content");
  11831. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11832. if (ceErpTradeAfterSaleExtend == null)
  11833. {
  11834. ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
  11835. ceErpTradeAfterSaleExtend.tid = ctid;
  11836. }
  11837. ceErpTradeAfterSaleExtend.IssueContent = content;
  11838. ceErpTradeAfterSaleExtend.IssueState = 1;
  11839. if (ceErpTradeAfterSaleExtend.ID > 0)
  11840. {
  11841. ceErpTradeAfterSaleExtend.Update();
  11842. }
  11843. else
  11844. {
  11845. ceErpTradeAfterSaleExtend.Create();
  11846. }
  11847. LogHelper.addLog(ctid, CurrentUser.UserID, "添加问题反馈信息:" + content, 6);
  11848. returnSuccessMsg("添加成功!");
  11849. return;
  11850. }
  11851. returnErrorMsg("找不到订单");
  11852. }
  11853. public void dealIssueContent()
  11854. {
  11855. string ctid = GetPostString("ctid");
  11856. if (!string.IsNullOrEmpty(ctid))
  11857. {
  11858. string content = GetPostString("content");
  11859. CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid);
  11860. if (ceErpTradeAfterSaleExtend != null)
  11861. {
  11862. ceErpTradeAfterSaleExtend.IssueState = 2;
  11863. ceErpTradeAfterSaleExtend.Update();
  11864. LogHelper.addLog(ctid, CurrentUser.UserID, "处理问题反馈信息", 6);
  11865. returnSuccessMsg("修改完成!");
  11866. return;
  11867. }
  11868. }
  11869. returnErrorMsg("找不到订单");
  11870. }
  11871. public void set_tid_attachments()
  11872. {
  11873. string tid = GetPostString("tid");
  11874. string atta = GetPostString("atta");
  11875. if (!string.IsNullOrEmpty(tid))
  11876. {
  11877. if (string.IsNullOrEmpty(atta))
  11878. {
  11879. returnErrorMsg("文件地址为空");
  11880. return;
  11881. }
  11882. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11883. if (ceErpTradeCell != null)
  11884. {
  11885. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11886. if (ceErpTrade == null)
  11887. {
  11888. returnErrorMsg("找不到订单");
  11889. return;
  11890. }
  11891. DataTable dt = DbHelper.DbConn.ExecuteDataset(string.Format("select OrderState from ce_erptradecell where tid = '{0}'", ceErpTradeCell.tid)).Tables[0];
  11892. bool isSend = false;
  11893. if (dt != null && dt.Rows.Count > 0)
  11894. {
  11895. foreach (DataRow row in dt.Rows)
  11896. {
  11897. if (Convert.ToInt16(row["OrderState"]) > 6 && tid.IndexOf("S_") == -1)
  11898. {
  11899. isSend = true;
  11900. }
  11901. }
  11902. if (isSend)
  11903. {
  11904. returnErrorMsg("已发货无法修改");
  11905. return;
  11906. }
  11907. ceErpTrade.Attachments = atta;
  11908. ceErpTrade.Update();
  11909. LogHelper.addLog(tid, CurrentUser.UserID, "上传文件地址", 6);
  11910. returnSuccessMsg("上传成功!");
  11911. return;
  11912. }
  11913. }
  11914. }
  11915. returnErrorMsg("找不到订单");
  11916. }
  11917. public void get_tid_attachments()
  11918. {
  11919. string tid = GetPostString("tid");
  11920. if (!string.IsNullOrEmpty(tid))
  11921. {
  11922. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(tid);
  11923. if (ceErpTradeCell != null)
  11924. {
  11925. CeErpTrade ceErpTrade = CeErpTrade.Get(ceErpTradeCell.tid);
  11926. if (ceErpTrade == null)
  11927. {
  11928. returnErrorMsg("找不到订单");
  11929. return;
  11930. }
  11931. returnSuccess(JsonConvert.SerializeObject(new { url = ceErpTrade.Attachments }));
  11932. return;
  11933. }
  11934. }
  11935. returnErrorMsg("找不到订单");
  11936. }
  11937. public void check_erp_sameorders()
  11938. {
  11939. if (UrlPostParmsCheck("ctid"))
  11940. {
  11941. string eid = GetPostString("ctid");
  11942. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  11943. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  11944. if (entity != null && ceErpTrade != null)
  11945. {
  11946. if (entity.OrderState > 6)
  11947. {
  11948. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11949. return;
  11950. }
  11951. DataTable dt = getSameOrderList(entity, ceErpTrade);
  11952. List<string> ids = new List<string>();
  11953. if (dt != null && dt.Rows.Count > 1)
  11954. {
  11955. bool needhe = true;
  11956. foreach (DataRow dr in dt.Rows)
  11957. {
  11958. ids.Add("'" + dr["ctid"] + "'");
  11959. /* //备注有合包
  11960. if (dr["seller_memo"].ToString().IndexOf("合包") > -1)
  11961. {
  11962. needhe = true;
  11963. }
  11964. if (dr["OtherMemo"].ToString().IndexOf("合包") > -1)
  11965. {
  11966. needhe = true;
  11967. }
  11968. //顺丰快递
  11969. if (Convert.ToInt32(dr["IsSF"]) > 0)
  11970. {
  11971. needhe = true;
  11972. }*/
  11973. }
  11974. if (!needhe)
  11975. {
  11976. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  11977. return;
  11978. }
  11979. StringBuilder sql = new StringBuilder();
  11980. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  11981. dt.Columns.Add(new DataColumn("dstate", typeof(int)));
  11982. dt.Columns.Add(new DataColumn("dnumber", typeof(int)));
  11983. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  11984. foreach (DataRow dr in dt.Rows)
  11985. {
  11986. dr["dstate"] = 0;
  11987. dr["dnumber"] = 0;
  11988. foreach (DataRow row in dt1.Rows)
  11989. {
  11990. if (dr["ctid"].ToString().Equals(row["ctid"].ToString()))
  11991. {
  11992. dr["dstate"] = 2;
  11993. dr["dnumber"] = Convert.ToInt32(row["markNumber"]);
  11994. }
  11995. }
  11996. if (eid.Equals(dr["ctid"].ToString()))
  11997. {
  11998. dr["dstate"] = 1;
  11999. }
  12000. }
  12001. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12002. return;
  12003. }
  12004. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(new DataTable())) + "}");
  12005. return;
  12006. }
  12007. returnErrorMsg("未找到订单");
  12008. return;
  12009. }
  12010. returnErrorMsg("缺少必要的参数");
  12011. }
  12012. private DataTable getSameOrderList(CeErpTradeCell entity, CeErpTrade ceErpTrade)
  12013. {
  12014. StringBuilder sql = new StringBuilder();
  12015. sql.AppendFormat("select ctid,IsSF,seller_memo,OtherMemo,productId,FinishPlaceTime,ProductCount from view_ErpTradeCell where SupplierId={0} and orderstate=6", entity.SupplierId);
  12016. if (string.IsNullOrEmpty(ceErpTrade.receiverId))
  12017. {
  12018. sql.AppendFormat(" and (tid='{0}');", entity.tid);
  12019. }
  12020. else
  12021. {
  12022. sql.AppendFormat(" and (tid='{0}' or (receiverId = '{1}' and IsSF = '{2}'));", entity.tid, ceErpTrade.receiverId, entity.IsSF);
  12023. }
  12024. DataTable dt = null;
  12025. try
  12026. {
  12027. dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12028. StringBuilder timerSql = new StringBuilder();
  12029. timerSql.AppendFormat("SELECT * FROM CE_ErpSupplierProductTime WHERE supplierId={0}", entity.SupplierId);
  12030. DataTable timerTable = DbHelper.DbConn.ExecuteDataset(timerSql.ToString()).Tables[0];
  12031. //没有设置时间则不判断
  12032. if (timerTable == null || timerTable.Rows.Count == 0)
  12033. {
  12034. return dt;
  12035. }
  12036. foreach (DataRow dr in dt.Rows)
  12037. {
  12038. //当前订单
  12039. if (entity.ctid.Equals(dr["ctid"]))
  12040. {
  12041. continue;
  12042. }
  12043. //已经标记过发货
  12044. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(dr["ctid"].ToString());
  12045. if (ceErpDeliverMark != null)
  12046. {
  12047. continue;
  12048. }
  12049. string[] productIds = null;
  12050. string productId = dr["productId"].ToString();
  12051. string finishPlaceTime = dr["FinishPlaceTime"].ToString();
  12052. string sellmer_mome = dr["seller_memo"].ToString();
  12053. string txtCount = dr["ProductCount"].ToString();
  12054. DateTime placeTime = DateTime.Now;
  12055. //没有品类
  12056. if (string.IsNullOrEmpty(productId) || "0".Equals(productId))
  12057. {
  12058. dr.Delete();//标记删除
  12059. continue;
  12060. }
  12061. if (string.IsNullOrEmpty(finishPlaceTime))
  12062. {
  12063. dr.Delete();//标记删除
  12064. continue;
  12065. }
  12066. placeTime = DateTime.Parse(finishPlaceTime);
  12067. foreach (DataRow row in timerTable.Rows)
  12068. {
  12069. string txtIds = row["productId"].ToString();
  12070. string[] crafts = { };
  12071. int count = Convert.ToUInt16(row["quantity"]);
  12072. if (string.IsNullOrEmpty(txtIds))
  12073. {
  12074. continue;
  12075. }
  12076. if (count > 0)
  12077. {
  12078. int quantity = commonHelper.handleProductCount(txtCount, true);
  12079. //订单数量大于写入的数量则跳过
  12080. if (quantity > count)
  12081. {
  12082. continue;
  12083. }
  12084. }
  12085. productIds = txtIds.Split(',');
  12086. if (productIds.Contains(productId))
  12087. {
  12088. string textCraft = row["craft"].ToString();
  12089. textCraft = textCraft.Replace(",", ",");//统一格式
  12090. if (!string.IsNullOrEmpty(textCraft))
  12091. {
  12092. crafts = textCraft.Split(',');
  12093. }
  12094. if (crafts.Length > 0)
  12095. {
  12096. bool isinCraft = false;
  12097. for (int i = 0; i < crafts.Length; i++)
  12098. {
  12099. if (sellmer_mome.IndexOf(crafts[i]) >= 0)
  12100. {
  12101. isinCraft = true;
  12102. break;
  12103. }
  12104. }
  12105. //有写工艺并且备注中没匹配中则跳过
  12106. if (!isinCraft)
  12107. {
  12108. continue;
  12109. }
  12110. }
  12111. DateTime deadLine = DateTime.Parse(row["deadLine"].ToString());
  12112. DateTime dayDeadLine = DateTime.Parse(row["dayDeadLine"].ToString());
  12113. int sendDay = Convert.ToInt16(row["sendDay"]);
  12114. //下单时间小于当日发货时间则不用判断
  12115. if (dayDeadLine.Hour > 0 && dayDeadLine.Hour > placeTime.Hour)
  12116. {
  12117. break;
  12118. }
  12119. //在截稿时间之前下单的可以减去一天时间
  12120. if (deadLine.Hour > 0 && deadLine.Hour > placeTime.Hour)
  12121. {
  12122. sendDay = Math.Max(1, sendDay - 1);
  12123. }
  12124. DateTime sendtime = placeTime.AddDays(sendDay);
  12125. //判断有没有到发货日期
  12126. if (DateTime.Compare(sendtime.Date, DateTime.Now.Date) > 0)
  12127. {
  12128. dr.Delete();//标记删除
  12129. break;
  12130. }
  12131. }
  12132. }
  12133. }
  12134. dt.AcceptChanges();//把标记的都删除
  12135. }
  12136. catch (Exception ex)
  12137. {
  12138. }
  12139. return dt;
  12140. }
  12141. public void get_mark_number()
  12142. {
  12143. string eid = GetPostString("ctid");
  12144. CeErpTradeCell entity = CeErpTradeCell.GetByCtid(eid);
  12145. if (entity != null)
  12146. {
  12147. CeErpTrade ceErpTrade = CeErpTrade.Get(entity.tid);
  12148. CeErpDeliverMark ceErpDeliverMark = CeErpDeliverMark.GetByCtid(eid);
  12149. int current = 1;
  12150. if (ceErpDeliverMark == null)
  12151. {
  12152. DataTable dt = getSameOrderList(entity, ceErpTrade);
  12153. List<string> ids = new List<string>();
  12154. if (dt != null && dt.Rows.Count > 1)
  12155. {
  12156. foreach (DataRow dr in dt.Rows)
  12157. {
  12158. ids.Add("'" + dr["ctid"] + "'");
  12159. }
  12160. //查询已有的编号
  12161. StringBuilder sql = new StringBuilder();
  12162. sql.AppendFormat("select * from CE_ErpDeliverMark where isDel = 0 and ctid in ({0});", string.Join(",", ids));
  12163. DataTable dt1 = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12164. if (dt1 == null || dt1.Rows.Count == 0)
  12165. {
  12166. DataTable numbers = DbHelper.DbConn.ExecuteDataset(string.Format("select markNumber from CE_ErpDeliverMark where isDel = 0 group by markNumber")).Tables[0];
  12167. List<int> list_number = new List<int>();
  12168. foreach (DataRow row in numbers.Rows)
  12169. {
  12170. list_number.Add(Convert.ToInt32(row["markNumber"]));
  12171. }
  12172. //查询空余编号
  12173. for (int i = 0; i < list_number.Count + 2; i++)
  12174. {
  12175. if (!list_number.Contains(current))
  12176. {
  12177. CeErpDeliverMark ceErpDeliverMark1 = CeErpDeliverMark.GetByNumber(current);
  12178. //防止查询过程中有新数据生成
  12179. if (ceErpDeliverMark1 == null)
  12180. {
  12181. break;
  12182. }
  12183. }
  12184. current++;
  12185. }
  12186. }
  12187. else
  12188. {
  12189. foreach (DataRow row in dt1.Rows)
  12190. {
  12191. current = Convert.ToInt32(row["markNumber"]);
  12192. }
  12193. }
  12194. ceErpDeliverMark = new CeErpDeliverMark();
  12195. ceErpDeliverMark.ctid = eid;
  12196. ceErpDeliverMark.createtime = DateTime.Now;
  12197. if (ceErpTrade != null)
  12198. {
  12199. ceErpDeliverMark.nickName = ceErpTrade.buyer_nick;
  12200. }
  12201. ceErpDeliverMark.markNumber = current;
  12202. ceErpDeliverMark.Create();
  12203. }
  12204. }
  12205. else
  12206. {
  12207. current = ceErpDeliverMark.markNumber;
  12208. }
  12209. ReturnSuccess(JsonConvert.SerializeObject(new { markNumber = current }));
  12210. return;
  12211. }
  12212. }
  12213. public void aftersaleCytSend()
  12214. {
  12215. string ctid = GetPostString("ctid");
  12216. if (!string.IsNullOrEmpty(ctid))
  12217. {
  12218. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12219. if (ceErpTradeCell != null)
  12220. {
  12221. commonHelper.sendCytAfterSale(ceErpTradeCell);
  12222. }
  12223. returnSuccessMsg("推送成功");
  12224. return;
  12225. }
  12226. returnErrorMsg("缺少必要的参数");
  12227. }
  12228. public void packOrderInfo()
  12229. {
  12230. string ctids = GetPostString("ctids");
  12231. if (!string.IsNullOrEmpty(ctids))
  12232. {
  12233. string[] ctid_list = ctids.Split(',');
  12234. if (ctid_list.Length > 20)
  12235. {
  12236. returnErrorMsg("单次下载次数不能超过20个");
  12237. return;
  12238. }
  12239. StringBuilder sql = new StringBuilder();
  12240. sql.AppendFormat("select ctid,OrderState,SupplierId from CE_ErpTradeCell where ctid in ({0})", "'" + ctids.Replace(",", "','") + "'");
  12241. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  12242. int supplierId = 0;
  12243. StringBuilder insterSql = new StringBuilder();
  12244. for (int i = 0; i < dt.Rows.Count; i++)
  12245. {
  12246. DataRow row = dt.Rows[i];
  12247. if (i == 0)
  12248. {
  12249. supplierId = Convert.ToInt32(row["SupplierId"]);
  12250. }
  12251. if (supplierId > 0 && supplierId != Convert.ToInt32(row["SupplierId"]))
  12252. {
  12253. returnErrorMsg("同车间的订单才能一起打包");
  12254. return;
  12255. }
  12256. int orderState = Convert.ToInt32(row["OrderState"]);
  12257. if (orderState != 5)
  12258. {
  12259. returnErrorMsg(row["ctid"].ToString() + "订单状态不对无法打包。");
  12260. return;
  12261. }
  12262. insterSql.AppendLine("INSERT INTO [CE_ErpPackDataItem] ([ctid], [packId]) VALUES ( '" + row["ctid"].ToString() + "', {0});");
  12263. }
  12264. CeErpPackData ceErpPackData = new CeErpPackData();
  12265. ceErpPackData.fileName = supplierId + "LT_" + DateTime.Now.ToString("yyyyMMddhhMmss") + ".zip";
  12266. ceErpPackData.supplierId = supplierId;
  12267. ceErpPackData.createtime = DateTime.Now;
  12268. ceErpPackData.createBy = CurrentUser.UserID;
  12269. ceErpPackData.createName = CurrentUser.UserName;
  12270. ceErpPackData.Create();
  12271. if (ceErpPackData.ID > 0)
  12272. {
  12273. string inSql = string.Format(insterSql.ToString(), ceErpPackData.ID);
  12274. DbHelper.DbConn.ExecuteNonQuery(inSql);
  12275. }
  12276. returnSuccessMsg("打包成功");
  12277. return;
  12278. }
  12279. returnErrorMsg("缺少必要的参数");
  12280. }
  12281. public void get_pack_list()
  12282. {
  12283. DataStruct dStruct = GetPostStruct();
  12284. List<string> lw = new List<string>();
  12285. string supplier = GetPostString("supplier");
  12286. if (supplier.Length > 0) lw.Add(string.Format("SupplierName = '{0}'", supplier));
  12287. string posTag = CurrentUser.UserPost.Post.Code;
  12288. if (posTag == "Supplier")
  12289. {
  12290. lw.Add(string.Format("SupplierId in ({0})", CurrentUser.User.pemVend));
  12291. }
  12292. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12293. DataTable dt = WebCache.GetData("view_packCenter", dStruct);
  12294. writeGridDataTableJson(dStruct.TotalCount, dt);
  12295. }
  12296. public void get_supplier_product_time_list()
  12297. {
  12298. DataStruct dStruct = GetPostStruct();
  12299. List<string> lw = new List<string>();
  12300. string supplier = GetPostString("supplier");
  12301. if (supplier.Length > 0) lw.Add(string.Format("supplierName = '{0}'", supplier));
  12302. string posTag = CurrentUser.UserPost.Post.Code;
  12303. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  12304. DataTable dt = WebCache.GetData("CE_ErpSupplierProductTime", dStruct);
  12305. writeGridDataTableJson(dStruct.TotalCount, dt);
  12306. }
  12307. public void saveSupplierProductTime()
  12308. {
  12309. string productId = GetPostString("productId");
  12310. if (string.IsNullOrEmpty(productId))
  12311. {
  12312. returnErrorMsg("缺少必要的参数");
  12313. return;
  12314. }
  12315. string productName = GetPostString("productName");
  12316. int supplierId = GetPostInt("supplierId");
  12317. if (supplierId == 0)
  12318. {
  12319. returnErrorMsg("缺少必要的参数");
  12320. return;
  12321. }
  12322. int quantity = GetPostInt("quantity");
  12323. int sendDay = GetPostInt("sendTime");
  12324. string supplierName = GetPostString("supplierName");
  12325. string craft = GetPostString("craft");
  12326. string deadLine = GetPostString("deadLine");
  12327. string dayDeadLine = GetPostString("dayDeadLine");
  12328. try
  12329. {
  12330. int eid = GetPostInt("eid");
  12331. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12332. if (ceErpSupplierProductTime == null)
  12333. {
  12334. ceErpSupplierProductTime = new CeErpSupplierProductTime();
  12335. }
  12336. ceErpSupplierProductTime.productId = productId;
  12337. ceErpSupplierProductTime.productName = productName;
  12338. ceErpSupplierProductTime.supplierId = supplierId;
  12339. ceErpSupplierProductTime.supplierName = supplierName;
  12340. ceErpSupplierProductTime.craft = craft;
  12341. ceErpSupplierProductTime.sendDay = sendDay;
  12342. ceErpSupplierProductTime.quantity = quantity;
  12343. if (!string.IsNullOrEmpty(deadLine))
  12344. {
  12345. ceErpSupplierProductTime.deadLine = TimeSpan.Parse(deadLine).ToString();
  12346. }
  12347. if (!string.IsNullOrEmpty(dayDeadLine))
  12348. {
  12349. ceErpSupplierProductTime.dayDeadLine = TimeSpan.Parse(dayDeadLine).ToString();
  12350. }
  12351. if (ceErpSupplierProductTime.ID == 0)
  12352. {
  12353. ceErpSupplierProductTime.Save();
  12354. }
  12355. else
  12356. {
  12357. ceErpSupplierProductTime.Update();
  12358. }
  12359. }
  12360. catch (Exception e)
  12361. {
  12362. }
  12363. returnSuccessMsg("保存成功");
  12364. return;
  12365. }
  12366. public void delSupplierProductTime()
  12367. {
  12368. int eid = GetPostInt("eid");
  12369. if (eid > 0)
  12370. {
  12371. CeErpSupplierProductTime ceErpSupplierProductTime = CeErpSupplierProductTime.Get(eid);
  12372. if (ceErpSupplierProductTime == null)
  12373. {
  12374. returnErrorMsg("查无数据");
  12375. return;
  12376. }
  12377. ceErpSupplierProductTime.Delete();
  12378. returnSuccessMsg("保存成功");
  12379. return;
  12380. }
  12381. returnErrorMsg("缺少必要的参数");
  12382. }
  12383. public void getExpressInfo()
  12384. {
  12385. string ctid = GetPostString("ctid");
  12386. if (!string.IsNullOrEmpty(ctid))
  12387. {
  12388. CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(ctid);
  12389. if (ceErpTradeCell != null)
  12390. {
  12391. string outSid = ceErpTradeCell.OutSid;
  12392. if (outSid.Length > 0)
  12393. {
  12394. 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);
  12395. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  12396. ReturnSuccess("{" + string.Format("\"data\":{0}", Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}");
  12397. return;
  12398. }
  12399. }
  12400. returnErrorMsg("查无记录");
  12401. return;
  12402. }
  12403. returnErrorMsg("缺少必要的参数");
  12404. }
  12405. public void getExpressPostData()
  12406. {
  12407. string express = GetPostString("express");
  12408. if (!string.IsNullOrEmpty(express))
  12409. {
  12410. CeErpExpressInfo ceErpExpressInfo = CeErpExpressInfo.GetByExpress(express);
  12411. if (ceErpExpressInfo != null)
  12412. {
  12413. ReturnSuccess("{" + string.Format("\"data\":{0}", ceErpExpressInfo.postData) + "}");
  12414. return;
  12415. }
  12416. }
  12417. returnErrorMsg("缺少必要的参数");
  12418. }
  12419. }
  12420. }